From f27bee3d2192000feeb6b7ae4a8abe23c072caef Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 15 Aug 2009 19:28:28 +0000 Subject: [PATCH 01/73] had support for single triangular brush commented when it works ok. thanks to j michaelson for pointing out. --- release/scripts/export_map.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release/scripts/export_map.py b/release/scripts/export_map.py index aca02288c7a..2262ae3b89b 100644 --- a/release/scripts/export_map.py +++ b/release/scripts/export_map.py @@ -197,7 +197,7 @@ def is_tricyl_facegroup(faces): is the face group a tri cylinder Returens a bool, true if the faces make an extruded tri solid ''' - return False + # cube must have 5 faces if len(faces) != 5: print '1' From 71cc934c6fb0037c6f0cd87f5f984250645ad42f Mon Sep 17 00:00:00 2001 From: Peter Schlaile Date: Sun, 16 Aug 2009 14:43:30 +0000 Subject: [PATCH 02/73] == Sequencer == Make coverity scan happy and check for input strip on speed control map rebuild. --- source/blender/src/seqeffects.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/blender/src/seqeffects.c b/source/blender/src/seqeffects.c index 2e339f433c3..1aab9a00506 100644 --- a/source/blender/src/seqeffects.c +++ b/source/blender/src/seqeffects.c @@ -2791,6 +2791,10 @@ void sequence_effect_speed_rebuild_map(struct Sequence * seq, int force) if (!(force || seq->len != v->length || !v->frameMap)) { return; } + if (!seq->seq1) { /* make coverity happy and check for + input strip ... */ + return; + } if (!v->frameMap || v->length != seq->len) { if (v->frameMap) MEM_freeN(v->frameMap); @@ -2807,7 +2811,7 @@ void sequence_effect_speed_rebuild_map(struct Sequence * seq, int force) strip */ if ((!seq->ipo || !seq->ipo->curve.first) && - seq->seq1 && seq->seq1->enddisp != seq->seq1->start + seq->seq1->enddisp != seq->seq1->start && seq->seq1->len != 0) { fallback_fac = (float) seq->seq1->len / (float) (seq->seq1->enddisp - seq->seq1->start); From c73bad7bddb3a5368b28d061bdc3b2c86b05a53d Mon Sep 17 00:00:00 2001 From: Peter Schlaile Date: Sun, 16 Aug 2009 14:52:05 +0000 Subject: [PATCH 03/73] == Sequencer == Forgot coverity id: CID 598 --- source/blender/src/seqeffects.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/src/seqeffects.c b/source/blender/src/seqeffects.c index 1aab9a00506..731bbaea9f4 100644 --- a/source/blender/src/seqeffects.c +++ b/source/blender/src/seqeffects.c @@ -2791,7 +2791,7 @@ void sequence_effect_speed_rebuild_map(struct Sequence * seq, int force) if (!(force || seq->len != v->length || !v->frameMap)) { return; } - if (!seq->seq1) { /* make coverity happy and check for + if (!seq->seq1) { /* make coverity happy and check for (CID 598) input strip ... */ return; } From c3041ae7cda20c78040e7deea17530fe5f41029d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 19 Aug 2009 10:26:43 +0000 Subject: [PATCH 04/73] - fix for BGE warnings - when C++ uses guardedalloc SYS_DeleteSystem was called after MEM_printmemlist(), making it look like there was a leak. --- intern/string/STR_String.h | 10 +++++++ .../windowmanager/intern/wm_init_exit.c | 5 ++-- .../Converter/BL_ArmatureObject.cpp | 2 +- .../gameengine/Converter/BL_ShapeDeformer.cpp | 4 +-- .../KX_BlenderScalarInterpolator.cpp | 2 +- .../Converter/KX_BlenderScalarInterpolator.h | 2 +- .../Converter/KX_BlenderSceneConverter.cpp | 2 +- source/gameengine/Converter/KX_IpoConvert.cpp | 2 +- .../gameengine/Ketsji/KX_CameraActuator.cpp | 12 -------- source/gameengine/Ketsji/KX_GameObject.cpp | 12 ++++---- source/gameengine/Ketsji/KX_IpoActuator.cpp | 28 +++++++++---------- source/gameengine/Ketsji/KX_IpoActuator.h | 14 +++++----- source/gameengine/Ketsji/KX_PythonInit.cpp | 14 +++++----- .../gameengine/Ketsji/KX_PythonInitTypes.cpp | 3 -- source/gameengine/Ketsji/KX_PythonSeq.cpp | 2 +- .../Ketsji/KX_SCA_ReplaceMeshActuator.h | 2 +- .../Physics/Bullet/CcdPhysicsController.cpp | 2 -- .../Rasterizer/RAS_IPolygonMaterial.cpp | 4 +-- source/gameengine/VideoTexture/ImageBase.cpp | 8 ++++-- 19 files changed, 62 insertions(+), 68 deletions(-) diff --git a/intern/string/STR_String.h b/intern/string/STR_String.h index 941430fd976..a5e7a0721ec 100644 --- a/intern/string/STR_String.h +++ b/intern/string/STR_String.h @@ -50,6 +50,9 @@ using namespace std; +#ifdef WITH_CXX_GUARDEDALLOC +#include "MEM_guardedalloc.h" +#endif class STR_String; @@ -191,6 +194,13 @@ protected: char *pData; // -> STR_String data int Len; // Data length int Max; // Space in data buffer + + +#ifdef WITH_CXX_GUARDEDALLOC +public: + void *operator new( unsigned int num_bytes) { return MEM_mallocN(num_bytes, "CXX:STR_String"); } + void operator delete( void *mem ) { MEM_freeN(mem); } +#endif }; inline STR_String operator+(rcSTR_String lhs, rcSTR_String rhs) { return STR_String(lhs.ReadPtr(), lhs.Length(), rhs.ReadPtr(), rhs.Length()); } diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index ee826d5f57e..9a268f8be17 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -266,6 +266,8 @@ void WM_exit(bContext *C) CTX_free(C); + SYS_DeleteSystem(SYS_GetSystem()); + if(MEM_get_memory_blocks_in_use()!=0) { printf("Error Totblock: %d\n", MEM_get_memory_blocks_in_use()); MEM_printmemlist(); @@ -282,9 +284,6 @@ void WM_exit(bContext *C) } #endif - - SYS_DeleteSystem(SYS_GetSystem()); - exit(G.afbreek==1); } diff --git a/source/gameengine/Converter/BL_ArmatureObject.cpp b/source/gameengine/Converter/BL_ArmatureObject.cpp index f8a9b1b637f..cfd90813a16 100644 --- a/source/gameengine/Converter/BL_ArmatureObject.cpp +++ b/source/gameengine/Converter/BL_ArmatureObject.cpp @@ -54,8 +54,8 @@ BL_ArmatureObject::BL_ArmatureObject( : KX_GameObject(sgReplicationInfo,callbacks), m_objArma(armature), - m_scene(scene), // maybe remove later. needed for where_is_pose m_framePose(NULL), + m_scene(scene), // maybe remove later. needed for where_is_pose m_lastframe(0.0), m_activeAct(NULL), m_activePriority(999), diff --git a/source/gameengine/Converter/BL_ShapeDeformer.cpp b/source/gameengine/Converter/BL_ShapeDeformer.cpp index d39917b0e5c..20ca7f07f2b 100644 --- a/source/gameengine/Converter/BL_ShapeDeformer.cpp +++ b/source/gameengine/Converter/BL_ShapeDeformer.cpp @@ -109,8 +109,8 @@ bool BL_ShapeDeformer::ExecuteShapeDrivers(void) { if (!m_shapeDrivers.empty() && PoseUpdated()) { vector::iterator it; - void *poin; - int type; +// void *poin; +// int type; // the shape drivers use the bone matrix as input. Must // update the matrix now diff --git a/source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp b/source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp index c3264a2bc37..24910422176 100644 --- a/source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp +++ b/source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp @@ -62,7 +62,7 @@ BL_InterpolatorList::~BL_InterpolatorList() { } } -KX_IScalarInterpolator *BL_InterpolatorList::GetScalarInterpolator(char *rna_path, int array_index) { +KX_IScalarInterpolator *BL_InterpolatorList::GetScalarInterpolator(const char *rna_path, int array_index) { for(BL_InterpolatorList::iterator i = begin(); (i != end()) ; i++ ) { FCurve *fcu= (static_cast(*i))->GetFCurve(); diff --git a/source/gameengine/Converter/KX_BlenderScalarInterpolator.h b/source/gameengine/Converter/KX_BlenderScalarInterpolator.h index eb15cee8ff9..e7fbb8083e4 100644 --- a/source/gameengine/Converter/KX_BlenderScalarInterpolator.h +++ b/source/gameengine/Converter/KX_BlenderScalarInterpolator.h @@ -64,7 +64,7 @@ public: BL_InterpolatorList(struct AnimData *adt); ~BL_InterpolatorList(); - KX_IScalarInterpolator *GetScalarInterpolator(char *rna_path, int array_index); + KX_IScalarInterpolator *GetScalarInterpolator(const char *rna_path, int array_index); #ifdef WITH_CXX_GUARDEDALLOC diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index ebabaa55e21..3220672c392 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -795,6 +795,7 @@ void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber) Object* blenderObject = gameObj->GetBlenderObject(); if (blenderObject && blenderObject->ipo) { +#if 0 const MT_Point3& position = gameObj->NodeGetWorldPosition(); //const MT_Vector3& scale = gameObj->NodeGetWorldScaling(); const MT_Matrix3x3& orn = gameObj->NodeGetWorldOrientation(); @@ -804,7 +805,6 @@ void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber) float tmat[3][3]; // XXX animato -#if 0 Ipo* ipo = blenderObject->ipo; //create the curves, if not existing, set linear if new diff --git a/source/gameengine/Converter/KX_IpoConvert.cpp b/source/gameengine/Converter/KX_IpoConvert.cpp index d3a2e1a9ba4..848fcfcdaa0 100644 --- a/source/gameengine/Converter/KX_IpoConvert.cpp +++ b/source/gameengine/Converter/KX_IpoConvert.cpp @@ -175,7 +175,7 @@ void BL_ConvertIpos(struct Object* blenderobject,KX_GameObject* gameobj,KX_Blend KX_ObColorIpoSGController* ipocontr_obcol=NULL; for(int i=0; i<4; i++) { - if (interp = adtList->GetScalarInterpolator("color", i)) { + if ((interp = adtList->GetScalarInterpolator("color", i))) { if (!ipocontr_obcol) { ipocontr_obcol = new KX_ObColorIpoSGController(); gameobj->GetSGNode()->AddSGController(ipocontr_obcol); diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index faf0ca50407..b5a0a63cf68 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -38,9 +38,6 @@ #include "PyObjectPlus.h" -STR_String KX_CameraActuator::X_AXIS_STRING = "x"; -STR_String KX_CameraActuator::Y_AXIS_STRING = "y"; - #ifdef HAVE_CONFIG_H #include #endif @@ -353,15 +350,6 @@ CValue *KX_CameraActuator::findObject(char *obName) return NULL; } -bool KX_CameraActuator::string2axischoice(const char *axisString) -{ - bool res = true; - - res = !(axisString == Y_AXIS_STRING); - - return res; -} - /* ------------------------------------------------------------------------- */ /* Python functions */ /* ------------------------------------------------------------------------- */ diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 146b83abd17..a5217273b17 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -464,7 +464,7 @@ void KX_GameObject::AddMeshUser() double* fl = GetOpenGLMatrixPtr()->getPointer(); SG_QList::iterator mit(m_meshSlots); - RAS_MeshSlot* ms; +// RAS_MeshSlot* ms; for(mit.begin(); !mit.end(); ++mit) { (*mit)->m_OpenGLMatrix = fl; @@ -1817,10 +1817,10 @@ int KX_GameObject::pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *at PyObject* KX_GameObject::pyattr_get_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { - KX_GameObject* self= static_cast(self_v); #ifdef USE_MATHUTILS return newVectorObject_cb((PyObject *)self_v, 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_POS_GLOBAL); #else + KX_GameObject* self= static_cast(self_v); return PyObjectFrom(self->NodeGetWorldPosition()); #endif } @@ -1839,10 +1839,10 @@ int KX_GameObject::pyattr_set_worldPosition(void *self_v, const KX_PYATTRIBUTE_D PyObject* KX_GameObject::pyattr_get_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { - KX_GameObject* self= static_cast(self_v); #ifdef USE_MATHUTILS return newVectorObject_cb((PyObject *)self_v, 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_POS_LOCAL); #else + KX_GameObject* self= static_cast(self_v); return PyObjectFrom(self->NodeGetLocalPosition()); #endif } @@ -1861,10 +1861,10 @@ int KX_GameObject::pyattr_set_localPosition(void *self_v, const KX_PYATTRIBUTE_D PyObject* KX_GameObject::pyattr_get_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { - KX_GameObject* self= static_cast(self_v); #ifdef USE_MATHUTILS return newVectorObject_cb((PyObject *)self_v, 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_INERTIA_LOCAL); #else + KX_GameObject* self= static_cast(self_v); if (self->GetPhysicsController()) return PyObjectFrom(self->GetPhysicsController()->GetLocalInertia()); return Py_BuildValue("fff", 0.0f, 0.0f, 0.0f); @@ -1922,20 +1922,20 @@ int KX_GameObject::pyattr_set_localOrientation(void *self_v, const KX_PYATTRIBUT PyObject* KX_GameObject::pyattr_get_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { - KX_GameObject* self= static_cast(self_v); #ifdef USE_MATHUTILS return newVectorObject_cb((PyObject *)self_v, 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_SCALE_GLOBAL); #else + KX_GameObject* self= static_cast(self_v); return PyObjectFrom(self->NodeGetWorldScaling()); #endif } PyObject* KX_GameObject::pyattr_get_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { - KX_GameObject* self= static_cast(self_v); #ifdef USE_MATHUTILS return newVectorObject_cb((PyObject *)self_v, 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_SCALE_LOCAL); #else + KX_GameObject* self= static_cast(self_v); return PyObjectFrom(self->NodeGetLocalScaling()); #endif } diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index e4eaff4f401..3f241e90836 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -49,13 +49,13 @@ /* Type strings */ /* ------------------------------------------------------------------------- */ -STR_String KX_IpoActuator::S_KX_ACT_IPO_PLAY_STRING = "Play"; -STR_String KX_IpoActuator::S_KX_ACT_IPO_PINGPONG_STRING = "PingPong"; -STR_String KX_IpoActuator::S_KX_ACT_IPO_FLIPPER_STRING = "Flipper"; -STR_String KX_IpoActuator::S_KX_ACT_IPO_LOOPSTOP_STRING = "LoopStop"; -STR_String KX_IpoActuator::S_KX_ACT_IPO_LOOPEND_STRING = "LoopEnd"; -STR_String KX_IpoActuator::S_KX_ACT_IPO_KEY2KEY_STRING = "Key2key"; -STR_String KX_IpoActuator::S_KX_ACT_IPO_FROM_PROP_STRING = "FromProp"; +const char *KX_IpoActuator::S_KX_ACT_IPO_PLAY_STRING = "Play"; +const char *KX_IpoActuator::S_KX_ACT_IPO_PINGPONG_STRING = "PingPong"; +const char *KX_IpoActuator::S_KX_ACT_IPO_FLIPPER_STRING = "Flipper"; +const char *KX_IpoActuator::S_KX_ACT_IPO_LOOPSTOP_STRING = "LoopStop"; +const char *KX_IpoActuator::S_KX_ACT_IPO_LOOPEND_STRING = "LoopEnd"; +const char *KX_IpoActuator::S_KX_ACT_IPO_KEY2KEY_STRING = "Key2key"; +const char *KX_IpoActuator::S_KX_ACT_IPO_FROM_PROP_STRING = "FromProp"; /* ------------------------------------------------------------------------- */ /* Native functions */ @@ -385,19 +385,19 @@ bool KX_IpoActuator::Update(double curtime, bool frame) int KX_IpoActuator::string2mode(char* modename) { IpoActType res = KX_ACT_IPO_NODEF; - if (modename == S_KX_ACT_IPO_PLAY_STRING) { + if (strcmp(modename, S_KX_ACT_IPO_PLAY_STRING)==0) { res = KX_ACT_IPO_PLAY; - } else if (modename == S_KX_ACT_IPO_PINGPONG_STRING) { + } else if (strcmp(modename, S_KX_ACT_IPO_PINGPONG_STRING)==0) { res = KX_ACT_IPO_PINGPONG; - } else if (modename == S_KX_ACT_IPO_FLIPPER_STRING) { + } else if (strcmp(modename, S_KX_ACT_IPO_FLIPPER_STRING)==0) { res = KX_ACT_IPO_FLIPPER; - } else if (modename == S_KX_ACT_IPO_LOOPSTOP_STRING) { + } else if (strcmp(modename, S_KX_ACT_IPO_LOOPSTOP_STRING)==0) { res = KX_ACT_IPO_LOOPSTOP; - } else if (modename == S_KX_ACT_IPO_LOOPEND_STRING) { + } else if (strcmp(modename, S_KX_ACT_IPO_LOOPEND_STRING)==0) { res = KX_ACT_IPO_LOOPEND; - } else if (modename == S_KX_ACT_IPO_KEY2KEY_STRING) { + } else if (strcmp(modename, S_KX_ACT_IPO_KEY2KEY_STRING)==0) { res = KX_ACT_IPO_KEY2KEY; - } else if (modename == S_KX_ACT_IPO_FROM_PROP_STRING) { + } else if (strcmp(modename, S_KX_ACT_IPO_FROM_PROP_STRING)==0) { res = KX_ACT_IPO_FROM_PROP; } diff --git a/source/gameengine/Ketsji/KX_IpoActuator.h b/source/gameengine/Ketsji/KX_IpoActuator.h index 01051ca82dc..0581d1644ee 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.h +++ b/source/gameengine/Ketsji/KX_IpoActuator.h @@ -100,13 +100,13 @@ public: KX_ACT_IPO_MAX }; - static STR_String S_KX_ACT_IPO_PLAY_STRING; - static STR_String S_KX_ACT_IPO_PINGPONG_STRING; - static STR_String S_KX_ACT_IPO_FLIPPER_STRING; - static STR_String S_KX_ACT_IPO_LOOPSTOP_STRING; - static STR_String S_KX_ACT_IPO_LOOPEND_STRING; - static STR_String S_KX_ACT_IPO_KEY2KEY_STRING; - static STR_String S_KX_ACT_IPO_FROM_PROP_STRING; + static const char *S_KX_ACT_IPO_PLAY_STRING; + static const char *S_KX_ACT_IPO_PINGPONG_STRING; + static const char *S_KX_ACT_IPO_FLIPPER_STRING; + static const char *S_KX_ACT_IPO_LOOPSTOP_STRING; + static const char *S_KX_ACT_IPO_LOOPEND_STRING; + static const char *S_KX_ACT_IPO_KEY2KEY_STRING; + static const char *S_KX_ACT_IPO_FROM_PROP_STRING; int string2mode(char* modename); diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index de3dcd0ebf8..49cf895af17 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -142,7 +142,7 @@ void KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,cons // List of methods defined in the module static PyObject* ErrorObject; -STR_String gPyGetRandomFloat_doc="getRandomFloat returns a random floating point value in the range [0..1)"; +static const char *gPyGetRandomFloat_doc="getRandomFloat returns a random floating point value in the range [0..1]"; static PyObject* gPyGetRandomFloat(PyObject*) { @@ -346,7 +346,7 @@ static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args) return list; } -static STR_String gPyGetCurrentScene_doc = +static const char *gPyGetCurrentScene_doc = "getCurrentScene()\n" "Gets a reference to the current scene.\n"; static PyObject* gPyGetCurrentScene(PyObject* self) @@ -354,7 +354,7 @@ static PyObject* gPyGetCurrentScene(PyObject* self) return gp_KetsjiScene->GetProxy(); } -static STR_String gPyGetSceneList_doc = +static const char *gPyGetSceneList_doc = "getSceneList()\n" "Return a list of converted scenes.\n"; static PyObject* gPyGetSceneList(PyObject* self) @@ -479,15 +479,15 @@ static struct PyMethodDef game_methods[] = { {"sendMessage", (PyCFunction)gPySendMessage, METH_VARARGS, (const char *)gPySendMessage_doc}, {"getCurrentController", (PyCFunction) SCA_PythonController::sPyGetCurrentController, - METH_NOARGS, (const char *)SCA_PythonController::sPyGetCurrentController__doc__}, + METH_NOARGS, SCA_PythonController::sPyGetCurrentController__doc__}, {"getCurrentScene", (PyCFunction) gPyGetCurrentScene, - METH_NOARGS, (const char *)gPyGetCurrentScene_doc.Ptr()}, + METH_NOARGS, gPyGetCurrentScene_doc}, {"getSceneList", (PyCFunction) gPyGetSceneList, - METH_NOARGS, (const char *)gPyGetSceneList_doc.Ptr()}, + METH_NOARGS, (const char *)gPyGetSceneList_doc}, {"addActiveActuator",(PyCFunction) SCA_PythonController::sPyAddActiveActuator, METH_VARARGS, (const char *)SCA_PythonController::sPyAddActiveActuator__doc__}, {"getRandomFloat",(PyCFunction) gPyGetRandomFloat, - METH_NOARGS, (const char *)gPyGetRandomFloat_doc.Ptr()}, + METH_NOARGS, (const char *)gPyGetRandomFloat_doc}, {"setGravity",(PyCFunction) gPySetGravity, METH_O, (const char *)"set Gravitation"}, {"getSpectrum",(PyCFunction) gPyGetSpectrum, METH_NOARGS, (const char *)"get audio spectrum"}, {"stopDSP",(PyCFunction) gPyStopDSP, METH_VARARGS, (const char *)"stop using the audio dsp (for performance reasons)"}, diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp index 5260c0bb01a..61e563791c3 100644 --- a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp +++ b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp @@ -123,9 +123,6 @@ static void PyType_Ready_ADD(PyObject *dict, PyTypeObject *tp, PyAttributeDef *a memset(attr_getset, 0, sizeof(PyGetSetDef)); } } else { - - PyObject *item; - PyType_Ready(tp); PyDict_SetItemString(dict, tp->tp_name, reinterpret_cast(tp)); } diff --git a/source/gameengine/Ketsji/KX_PythonSeq.cpp b/source/gameengine/Ketsji/KX_PythonSeq.cpp index 4fc5252de60..1098dc03b62 100644 --- a/source/gameengine/Ketsji/KX_PythonSeq.cpp +++ b/source/gameengine/Ketsji/KX_PythonSeq.cpp @@ -375,7 +375,7 @@ PyTypeObject KX_PythonSeq_Type = { NULL, /* getattrfunc tp_getattr; */ NULL, /* setattrfunc tp_setattr; */ /* TODO, richcmp */ - NULL, /* ( cmpfunc ) KX_PythonSeq_compare, /* cmpfunc tp_compare; */ + NULL, /* ( cmpfunc ) KX_PythonSeq_compare, // cmpfunc tp_compare; */ ( reprfunc ) KX_PythonSeq_repr, /* reprfunc tp_repr; */ /* Method suites for standard classes */ diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h index ae2c0d2d6ce..1e258420836 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h @@ -50,8 +50,8 @@ class KX_SCA_ReplaceMeshActuator : public SCA_IActuator // mesh reference (mesh to replace) RAS_MeshObject* m_mesh; SCA_IScene* m_scene; - bool m_use_phys; bool m_use_gfx; + bool m_use_phys; public: KX_SCA_ReplaceMeshActuator( diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index 20e830c9dc3..12562e34583 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -1829,8 +1829,6 @@ bool CcdShapeConstructionInfo::UpdateMesh(class KX_GameObject* gameobj, class RA } for(mf= mface, i=0; i < numpolys; mf++, i++) { - unsigned int *fv = &mf->v1; - if(mf->v4) { fv_pt= quad_verts; *poly_index_pt++ = *poly_index_pt++ = index[i]; diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp index cb5c5a12397..033daabc48f 100644 --- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp +++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp @@ -70,7 +70,6 @@ void RAS_IPolyMaterial::Initialize( RAS_IPolyMaterial::RAS_IPolyMaterial() : m_texturename("__Dummy_Texture_Name__"), m_materialname("__Dummy_Material_Name__"), - m_materialindex(0), m_tile(0), m_tilexrep(0), m_tileyrep(0), @@ -78,6 +77,7 @@ RAS_IPolyMaterial::RAS_IPolyMaterial() m_transp(0), m_alpha(false), m_zsort(false), + m_materialindex(0), m_polymatid(0), m_flag(0), m_multimode(0) @@ -100,7 +100,6 @@ RAS_IPolyMaterial::RAS_IPolyMaterial(const STR_String& texname, bool zsort) : m_texturename(texname), m_materialname(matname), - m_materialindex(materialindex), m_tile(tile), m_tilexrep(tilexrep), m_tileyrep(tileyrep), @@ -108,6 +107,7 @@ RAS_IPolyMaterial::RAS_IPolyMaterial(const STR_String& texname, m_transp(transp), m_alpha(alpha), m_zsort(zsort), + m_materialindex(materialindex), m_polymatid(m_newpolymatid++), m_flag(0), m_multimode(0) diff --git a/source/gameengine/VideoTexture/ImageBase.cpp b/source/gameengine/VideoTexture/ImageBase.cpp index 5e2841271a6..0740afed2c6 100644 --- a/source/gameengine/VideoTexture/ImageBase.cpp +++ b/source/gameengine/VideoTexture/ImageBase.cpp @@ -219,15 +219,17 @@ bool ImageBase::checkSourceSizes (void) // get size of current source short * curSize = (*it)->getSize(); // if size is available and is not empty - if (curSize[0] != 0 && curSize[1] != 0) + if (curSize[0] != 0 && curSize[1] != 0) { // if reference size is not set - if (refSize == NULL) + if (refSize == NULL) { // set current size as reference refSize = curSize; // otherwise check with current size - else if (curSize[0] != refSize[0] || curSize[1] != refSize[1]) + } else if (curSize[0] != refSize[0] || curSize[1] != refSize[1]) { // if they don't match, report it return false; + } + } } // all sizes match return true; From aace6ef551183a3d09635c3103a8e4cba4f9117a Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 19 Aug 2009 12:35:40 +0000 Subject: [PATCH 05/73] 2.5: Restored statistics in the info header. Implementation: * NC_SCENE or NC_OBJECT cause scene->stats to be cleared. * NC_INFO is sent to tag info headers for redraw. * In UI scene.statistics() creates scene->stats if it is NULLd, and then returns the string. --- release/ui/space_info.py | 5 +- source/blender/blenkernel/intern/scene.c | 4 + source/blender/blenloader/intern/readfile.c | 1 + source/blender/editors/include/ED_info.h | 32 ++ .../editors/interface/interface_widgets.c | 8 +- .../blender/editors/space_info/info_stats.c | 434 ++++++++++++++++++ .../blender/editors/space_info/space_info.c | 6 +- source/blender/makesdna/DNA_scene_types.h | 2 +- source/blender/makesrna/intern/rna_scene.c | 7 + source/blender/windowmanager/WM_types.h | 1 + .../windowmanager/intern/wm_event_system.c | 11 +- 11 files changed, 503 insertions(+), 8 deletions(-) create mode 100644 source/blender/editors/include/ED_info.h create mode 100644 source/blender/editors/space_info/info_stats.c diff --git a/release/ui/space_info.py b/release/ui/space_info.py index 770387498a2..1a3f9a321ac 100644 --- a/release/ui/space_info.py +++ b/release/ui/space_info.py @@ -8,7 +8,8 @@ class INFO_HT_header(bpy.types.Header): layout = self.layout st = context.space_data - rd = context.scene.render_data + scene = context.scene + rd = scene.render_data row = layout.row(align=True) row.template_header() @@ -33,6 +34,8 @@ class INFO_HT_header(bpy.types.Header): layout.template_operator_search() layout.template_running_jobs() + + layout.itemL(text=scene.statistics()) class INFO_MT_file(bpy.types.Menu): __space_type__ = "INFO" diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 2a8fd765386..6dd362d15a8 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -155,6 +155,7 @@ Scene *copy_scene(Main *bmain, Scene *sce, int type) scen->theDag= NULL; scen->obedit= NULL; scen->toolsettings= MEM_dupallocN(sce->toolsettings); + scen->stats= NULL; ts= scen->toolsettings; if(ts) { @@ -299,6 +300,9 @@ void free_scene(Scene *sce) ntreeFreeTree(sce->nodetree); MEM_freeN(sce->nodetree); } + + if(sce->stats) + MEM_freeN(sce->stats); } Scene *add_scene(char *name) diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 779a898bd6a..db811b22460 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4134,6 +4134,7 @@ static void direct_link_scene(FileData *fd, Scene *sce) sce->theDag = NULL; sce->dagisvalid = 0; sce->obedit= NULL; + sce->stats= 0; memset(&sce->sound_handles, 0, sizeof(sce->sound_handles)); diff --git a/source/blender/editors/include/ED_info.h b/source/blender/editors/include/ED_info.h new file mode 100644 index 00000000000..d09e174d71d --- /dev/null +++ b/source/blender/editors/include/ED_info.h @@ -0,0 +1,32 @@ +/** + * $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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009, Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef ED_INFO_H +#define ED_INFO_H + +/* info_stats.c */ +void ED_info_stats_clear(struct Scene *scene); +char *ED_info_stats_string(struct Scene *scene); + +#endif /* ED_INFO_H */ diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index a70fbab1aa4..48de2343c97 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -835,9 +835,11 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b // else transopts= ui_translate_buttons(); /* cut string in 2 parts - only for menu entries */ - if(ELEM5(but->type, SLI, NUM, TEX, NUMSLI, NUMABS)==0) { - cpoin= strchr(but->drawstr, '|'); - if(cpoin) *cpoin= 0; + if((but->block->flag & UI_BLOCK_LOOP)) { + if(ELEM5(but->type, SLI, NUM, TEX, NUMSLI, NUMABS)==0) { + cpoin= strchr(but->drawstr, '|'); + if(cpoin) *cpoin= 0; + } } glColor3ubv((unsigned char*)wcol->text); diff --git a/source/blender/editors/space_info/info_stats.c b/source/blender/editors/space_info/info_stats.c new file mode 100644 index 00000000000..2d14fbc515e --- /dev/null +++ b/source/blender/editors/space_info/info_stats.c @@ -0,0 +1,434 @@ +/** + * $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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include +#include + +#include "MEM_guardedalloc.h" + +#include "DNA_action_types.h" +#include "DNA_armature_types.h" +#include "DNA_curve_types.h" +#include "DNA_group_types.h" +#include "DNA_lattice_types.h" +#include "DNA_mesh_types.h" +#include "DNA_meta_types.h" +#include "DNA_object_types.h" +#include "DNA_particle_types.h" +#include "DNA_scene_types.h" + +#include "BKE_anim.h" +#include "BKE_context.h" +#include "BKE_displist.h" +#include "BKE_DerivedMesh.h" +#include "BKE_key.h" +#include "BKE_mesh.h" +#include "BKE_particle.h" +#include "BKE_utildefines.h" + +#include "ED_armature.h" +#include "ED_mesh.h" + +#include "BLI_editVert.h" + +typedef struct SceneStats { + int totvert, totvertsel; + int totedge, totedgesel; + int totface, totfacesel; + int totbone, totbonesel; + int totobj, totobjsel; + int totmesh, totlamp, totcurve; + + char infostr[512]; +} SceneStats; + +static void stats_object(Object *ob, int sel, int totob, SceneStats *stats) +{ + switch(ob->type) { + case OB_MESH: { + /* we assume derivedmesh is already built, this strictly does stats now. */ + DerivedMesh *dm= ob->derivedFinal; + int totvert, totedge, totface; + + stats->totmesh +=totob; + + if(dm) { + totvert = dm->getNumVerts(dm); + totedge = dm->getNumEdges(dm); + totface = dm->getNumFaces(dm); + + stats->totvert += totvert*totob; + stats->totedge += totedge*totob; + stats->totface += totface*totob; + + if(sel) { + stats->totvertsel += totvert; + stats->totfacesel += totface; + } + } + break; + } + case OB_LAMP: + stats->totlamp += totob; + break; + case OB_SURF: + case OB_CURVE: + case OB_FONT: { + Curve *cu= ob->data; + int tot= 0, totf= 0; + + stats->totcurve += totob; + + if(cu->disp.first) + count_displist(&cu->disp, &tot, &totf); + + tot *= totob; + totf *= totob; + + stats->totvert+= tot; + stats->totface+= totf; + + if(sel) { + stats->totvertsel += tot; + stats->totfacesel += totf; + } + break; + } + case OB_MBALL: { + int tot= 0, totf= 0; + + count_displist(&ob->disp, &tot, &totf); + + tot *= totob; + totf *= totob; + + stats->totvert += tot; + stats->totface += totf; + + if(sel) { + stats->totvertsel += tot; + stats->totfacesel += totf; + } + break; + } + } +} + +static void stats_object_edit(Object *obedit, SceneStats *stats) +{ + if(obedit->type==OB_MESH) { + /* Mesh Edit */ + EditMesh *em= BKE_mesh_get_editmesh(obedit->data); + EditVert *eve; + EditEdge *eed; + EditFace *efa; + + for(eve= em->verts.first; eve; eve=eve->next) { + stats->totvert++; + if(eve->f & SELECT) stats->totvertsel++; + } + for(eed= em->edges.first; eed; eed=eed->next) { + stats->totedge++; + if(eed->f & SELECT) stats->totedgesel++; + } + for(efa= em->faces.first; efa; efa=efa->next) { + stats->totface++; + if(efa->f & SELECT) stats->totfacesel++; + } + + EM_validate_selections(em); + } + else if(obedit->type==OB_ARMATURE){ + /* Armature Edit */ + bArmature *arm= obedit->data; + EditBone *ebo; + + for(ebo=arm->edbo->first; ebo; ebo=ebo->next){ + stats->totbone++; + + if((ebo->flag & BONE_CONNECTED) && ebo->parent) + stats->totvert--; + + if(ebo->flag & BONE_TIPSEL) + stats->totvertsel++; + if(ebo->flag & BONE_ROOTSEL) + stats->totvertsel++; + + if(ebo->flag & BONE_SELECTED) stats->totbonesel++; + + /* if this is a connected child and it's parent is being moved, remove our root */ + if((ebo->flag & BONE_CONNECTED)&& (ebo->flag & BONE_ROOTSEL) && ebo->parent && (ebo->parent->flag & BONE_TIPSEL)) + stats->totvertsel--; + + stats->totvert+=2; + } + } + else if ELEM3(obedit->type, OB_CURVE, OB_SURF, OB_FONT) { + /* Curve Edit */ + Curve *cu= obedit->data; + Nurb *nu; + BezTriple *bezt; + BPoint *bp; + int a; + + for(nu=cu->editnurb->first; nu; nu=nu->next) { + if((nu->type & 7)==CU_BEZIER) { + bezt= nu->bezt; + a= nu->pntsu; + while(a--) { + stats->totvert+=3; + if(bezt->f1) stats->totvertsel++; + if(bezt->f2) stats->totvertsel++; + if(bezt->f3) stats->totvertsel++; + bezt++; + } + } + else { + bp= nu->bp; + a= nu->pntsu*nu->pntsv; + while(a--) { + stats->totvert++; + if(bp->f1 & SELECT) stats->totvertsel++; + bp++; + } + } + } + } + else if(obedit->type==OB_MBALL) { + /* MetaBall Edit */ + MetaBall *mball= obedit->data; + MetaElem *ml; + + for(ml= mball->editelems->first; ml; ml=ml->next) { + stats->totvert++; + if(ml->flag & SELECT) stats->totvertsel++; + } + } + else if(obedit->type==OB_LATTICE) { + /* Lattice Edit */ + Lattice *lt= obedit->data; + Lattice *editlatt= lt->editlatt; + BPoint *bp; + int a; + + bp= editlatt->def; + + a= editlatt->pntsu*editlatt->pntsv*editlatt->pntsw; + while(a--) { + stats->totvert++; + if(bp->f1 & SELECT) stats->totvertsel++; + bp++; + } + } +} + +static void stats_object_pose(Object *ob, SceneStats *stats) +{ + if(ob->pose) { + bArmature *arm= ob->data; + bPoseChannel *pchan; + + for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { + stats->totbone++; + if(pchan->bone && (pchan->bone->flag & BONE_SELECTED)) + if(pchan->bone->layer & arm->layer) + stats->totbonesel++; + } + } +} + +static void stats_object_paint(Object *ob, SceneStats *stats) +{ + if(ob->type == OB_MESH) { + Mesh *me= ob->data; + + stats->totface= me->totface; + stats->totvert= me->totvert; + } +} + +static void stats_dupli_object(Base *base, Object *ob, SceneStats *stats) +{ + if(base->flag & SELECT) stats->totobjsel++; + + if(ob->transflag & OB_DUPLIPARTS) { + /* Dupli Particles */ + ParticleSystem *psys; + ParticleSettings *part; + + for(psys=ob->particlesystem.first; psys; psys=psys->next){ + part=psys->part; + + if(part->draw_as==PART_DRAW_OB && part->dup_ob){ + int tot=count_particles(psys); + stats_object(part->dup_ob, 0, tot, stats); + } + else if(part->draw_as==PART_DRAW_GR && part->dup_group){ + GroupObject *go; + int tot, totgroup=0, cur=0; + + for(go= part->dup_group->gobject.first; go; go=go->next) + totgroup++; + + for(go= part->dup_group->gobject.first; go; go=go->next) { + tot=count_particles_mod(psys,totgroup,cur); + stats_object(go->ob, 0, tot, stats); + cur++; + } + } + } + + stats_object(ob, base->flag & SELECT, 1, stats); + stats->totobj++; + } + else if(ob->parent && (ob->parent->transflag & (OB_DUPLIVERTS|OB_DUPLIFACES))) { + /* Dupli Verts/Faces */ + int tot= count_duplilist(ob->parent); + stats->totobj+=tot; + stats_object(ob, base->flag & SELECT, tot, stats); + } + else if(ob->transflag & OB_DUPLIFRAMES) { + /* Dupli Frames */ + int tot= count_duplilist(ob); + stats->totobj+=tot; + stats_object(ob, base->flag & SELECT, tot, stats); + } + else if((ob->transflag & OB_DUPLIGROUP) && ob->dup_group) { + /* Dupli Group */ + int tot= count_duplilist(ob); + stats->totobj+=tot; + stats_object(ob, base->flag & SELECT, tot, stats); + } + else { + /* No Dupli */ + stats_object(ob, base->flag & SELECT, 1, stats); + stats->totobj++; + } +} + +/* Statistics displayed in info header. Called regularly on scene changes. */ +static void stats_update(Scene *scene) +{ + SceneStats stats; + Object *ob= (scene->basact)? scene->basact->object: NULL; + Base *base; + + memset(&stats, 0, sizeof(stats)); + + if(scene->obedit) { + /* Edit Mode */ + stats_object_edit(scene->obedit, &stats); + } + else if(ob && (ob->mode & OB_MODE_POSE)) { + /* Pose Mode */ + stats_object_pose(ob, &stats); + } + else if(ob && (ob->flag & (OB_MODE_SCULPT|OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT))) { + /* Sculpt and Paint Mode */ + stats_object_paint(ob, &stats); + } + else { + /* Objects */ + for(base= scene->base.first; base; base=base->next) + if(scene->lay & base->lay) + stats_dupli_object(base, base->object, &stats); + } + + if(!scene->stats) + scene->stats= MEM_mallocN(sizeof(SceneStats), "SceneStats"); + + *(scene->stats)= stats; +} + +static void stats_string(Scene *scene) +{ + SceneStats *stats= scene->stats; + Object *ob= (scene->basact)? scene->basact->object: NULL; + uintptr_t mem_in_use, mmap_in_use; + char memstr[64]; + char *s; + + mem_in_use= MEM_get_memory_in_use(); + mmap_in_use= MEM_get_mapped_memory_in_use(); + + /* get memory statistics */ + s= memstr + sprintf(memstr, " | Mem:%.2fM", ((mem_in_use-mmap_in_use)>>10)/1024.0); + if(mmap_in_use) + sprintf(s, " (%.2fM)", ((mmap_in_use)>>10)/1024.0); + + s= stats->infostr; + + if(scene->obedit) { + if(ob_get_keyblock(scene->obedit)) + s+= sprintf(s, "(Key) "); + + if(scene->obedit->type==OB_MESH) { + if(scene->toolsettings->selectmode & SCE_SELECT_VERTEX) + s+= sprintf(s, "Ve:%d-%d | Ed:%d-%d | Fa:%d-%d", + stats->totvertsel, stats->totvert, stats->totedgesel, stats->totedge, stats->totfacesel, stats->totface); + else if(scene->toolsettings->selectmode & SCE_SELECT_EDGE) + s+= sprintf(s, "Ed:%d-%d | Fa:%d-%d", + stats->totedgesel, stats->totedge, stats->totfacesel, stats->totface); + else + s+= sprintf(s, "Fa:%d-%d", stats->totfacesel, stats->totface); + } + else if(scene->obedit->type==OB_ARMATURE) { + s+= sprintf(s, "Ve:%d-%d | Bo:%d-%d", stats->totvertsel, stats->totvert, stats->totbonesel, stats->totbone); + } + else { + s+= sprintf(s, "Ve:%d-%d", stats->totvertsel, stats->totvert); + } + + strcat(s, memstr); + } + else if(ob && (ob->mode & OB_MODE_POSE)) { + s += sprintf(s, "Bo:%d-%d %s", + stats->totbonesel, stats->totbone, memstr); + } + else { + s += sprintf(s, "Ve:%d | Fa:%d | Ob:%d-%d | La:%d%s", + stats->totvert, stats->totface, stats->totobj, stats->totobjsel, stats->totlamp, memstr); + } + + if(ob) + sprintf(s, " | %s", ob->id.name+2); +} + +void ED_info_stats_clear(Scene *scene) +{ + if(scene->stats) { + MEM_freeN(scene->stats); + scene->stats= NULL; + } +} + +char *ED_info_stats_string(Scene *scene) +{ + if(!scene->stats) + stats_update(scene); + stats_string(scene); + + return scene->stats->infostr; +} + diff --git a/source/blender/editors/space_info/space_info.c b/source/blender/editors/space_info/space_info.c index fe5bbf04af1..b6f9cbeabb5 100644 --- a/source/blender/editors/space_info/space_info.c +++ b/source/blender/editors/space_info/space_info.c @@ -1,5 +1,5 @@ /** - * $Id: + * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** * @@ -58,6 +58,7 @@ #include "UI_view2d.h" #include "ED_markers.h" +#include "ED_object.h" #include "info_intern.h" // own include @@ -166,6 +167,9 @@ static void info_header_listener(ARegion *ar, wmNotifier *wmn) if(wmn->data==ND_RENDER_RESULT) ED_region_tag_redraw(ar); break; + case NC_INFO: + ED_region_tag_redraw(ar); + break; } } diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 4a3d555ca33..f1a77d78b7b 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -47,6 +47,7 @@ struct Text; struct bNodeTree; struct AnimData; struct Editing; +struct SceneStats; typedef struct Base { struct Base *next, *prev; @@ -717,7 +718,6 @@ typedef struct Scene { /* Units */ struct UnitSettings unit; - } Scene; diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 88796919c3e..0301932aef3 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -62,6 +62,7 @@ EnumPropertyItem prop_mode_items[] ={ #include "BLI_threads.h" +#include "ED_info.h" #include "ED_node.h" #include "RE_pipeline.h" @@ -1823,6 +1824,7 @@ void RNA_def_scene(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; + FunctionRNA *func; /* Struct definition */ srna= RNA_def_struct(brna, "Scene", "ID"); @@ -1982,6 +1984,11 @@ void RNA_def_scene(BlenderRNA *brna) RNA_def_property_pointer_sdna(prop, NULL, "gm"); RNA_def_property_struct_type(prop, "SceneGameData"); RNA_def_property_ui_text(prop, "Game Data", ""); + + /* Statistics */ + func= RNA_def_function(srna, "statistics", "ED_info_stats_string"); + prop= RNA_def_string(func, "statistics", "", 0, "Statistics", ""); + RNA_def_function_return(func, prop); rna_def_tool_settings(brna); rna_def_unit_settings(brna); diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 00e9f6a2fa2..b717df8f61f 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -134,6 +134,7 @@ typedef struct wmNotifier { #define NC_ANIMATION (15<<24) #define NC_CONSOLE (16<<24) #define NC_NODE (17<<24) +#define NC_INFO (18<<24) /* data type, 256 entries is enough, it can overlap */ #define NOTE_DATA 0x00FF0000 diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index f0d9f8c0989..6c34ed6f902 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -52,6 +52,7 @@ #include "BKE_pointcache.h" #include "ED_fileselect.h" +#include "ED_info.h" #include "ED_screen.h" #include "ED_space_api.h" #include "ED_util.h" @@ -129,7 +130,7 @@ static wmNotifier *wm_notifier_next(wmWindowManager *wm) void wm_event_do_notifiers(bContext *C) { wmWindowManager *wm= CTX_wm_manager(C); - wmNotifier *note; + wmNotifier *note, *next; wmWindow *win; if(wm==NULL) @@ -141,7 +142,9 @@ void wm_event_do_notifiers(bContext *C) CTX_wm_window_set(C, win); - for(note= wm->queue.first; note; note= note->next) { + for(note= wm->queue.first; note; note= next) { + next= note->next; + if(note->category==NC_WM) { if( ELEM(note->data, ND_FILEREAD, ND_FILESAVE)) { wm->file_saved= 1; @@ -174,6 +177,10 @@ void wm_event_do_notifiers(bContext *C) do_anim= 1; } } + if(note->category == NC_SCENE || note->category == NC_OBJECT) { + ED_info_stats_clear(CTX_data_scene(C)); + WM_event_add_notifier(C, NC_INFO, NULL); + } } if(do_anim) { /* depsgraph gets called, might send more notifiers */ From 315229ea5ffb6d0519b0a5d144996760871dd3bb Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 19 Aug 2009 14:04:21 +0000 Subject: [PATCH 06/73] texture enum was crashing when generating docs, removed radiosity from makefiles. --- source/blender/makesrna/intern/rna_texture.c | 2 +- source/blender/render/intern/source/Makefile | 1 - source/creator/Makefile | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/source/blender/makesrna/intern/rna_texture.c b/source/blender/makesrna/intern/rna_texture.c index b7403ab1178..f82edee8ff1 100644 --- a/source/blender/makesrna/intern/rna_texture.c +++ b/source/blender/makesrna/intern/rna_texture.c @@ -142,7 +142,7 @@ static EnumPropertyItem *rna_TextureSlot_output_node_itemf(bContext *C, PointerR EnumPropertyItem *item= NULL; int totitem= 0; - if(tex) { + if(tex && C) { /* Note, tex/mtex/ntree can be invalid of C is NULL, TODO - can this give valid results when C is NULL? */ bNodeTree *ntree= tex->nodetree; if(ntree) { EnumPropertyItem tmp= {0, "", 0, "", ""}; diff --git a/source/blender/render/intern/source/Makefile b/source/blender/render/intern/source/Makefile index 3c8d0f637a3..5d4a224002e 100644 --- a/source/blender/render/intern/source/Makefile +++ b/source/blender/render/intern/source/Makefile @@ -39,7 +39,6 @@ CFLAGS += $(LEVEL_1_C_WARNINGS) # The external modules follow after. There should be a nicer way to say this. CPPFLAGS += -I../include CPPFLAGS += -I../../extern/include -CPPFLAGS += -I../../../radiosity/extern/include CPPFLAGS += -I../../../blenlib CPPFLAGS += -I../../../imbuf CPPFLAGS += -I../../../makesdna diff --git a/source/creator/Makefile b/source/creator/Makefile index fbe5d252a77..592cf913dfa 100644 --- a/source/creator/Makefile +++ b/source/creator/Makefile @@ -40,7 +40,6 @@ include nan_compile.mk CFLAGS += $(LEVEL_1_C_WARNINGS) CPPFLAGS += -I../blender/render/extern/include -CPPFLAGS += -I../blender/radiosity/extern/include # two needed for the kernel CPPFLAGS += -I../blender/imbuf From 792d526489011215db32dba424809d6e741b05c3 Mon Sep 17 00:00:00 2001 From: Robin Allen Date: Wed, 19 Aug 2009 15:45:16 +0000 Subject: [PATCH 07/73] More texnode preview fixes. Previews now have correct aspect ratio and are drawn by the renderer. --- source/blender/blenkernel/BKE_node.h | 5 +-- .../blender/editors/preview/previewrender.c | 6 ++- source/blender/editors/space_node/node_edit.c | 5 --- .../blender/editors/space_node/space_node.c | 5 ++- source/blender/nodes/intern/TEX_util.c | 44 ++++++++----------- source/blender/nodes/intern/TEX_util.h | 3 +- source/blender/render/intern/source/texture.c | 2 +- 7 files changed, 30 insertions(+), 40 deletions(-) diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 4ac95b61a5e..40afa1dba36 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -421,10 +421,9 @@ extern struct ListBase node_all_textures; /* API */ int ntreeTexTagAnimated(struct bNodeTree *ntree); -void ntreeTexUpdatePreviews( struct bNodeTree* nodetree ); -void ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target, float *coord, float *dxt, float *dyt, char do_preview, short thread, struct Tex *tex, short which_output, int cfra); +void ntreeTexSetPreviewFlag(int); +void ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target, float *coord, float *dxt, float *dyt, short thread, struct Tex *tex, short which_output, int cfra); void ntreeTexCheckCyclics(struct bNodeTree *ntree); -void ntreeTexAssignIndex(struct bNodeTree *ntree, struct bNode *node); char* ntreeTexOutputMenu(struct bNodeTree *ntree); diff --git a/source/blender/editors/preview/previewrender.c b/source/blender/editors/preview/previewrender.c index 8fcf65202ee..94db74c18d9 100644 --- a/source/blender/editors/preview/previewrender.c +++ b/source/blender/editors/preview/previewrender.c @@ -946,7 +946,11 @@ void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, M /* XXX ugly global still, but we can't do preview while rendering */ if(G.rendering) return; - + + if(GS(id->name) == ID_TE) { + ntreeTexSetPreviewFlag(1); + } + steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), owner); sp= MEM_callocN(sizeof(ShaderPreview), "shader preview"); diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index e1b612d74e1..bc81c25d106 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -574,7 +574,6 @@ void ED_node_texture_default(Tex *tx) nodeAddLink(tx->nodetree, in, fromsock, out, tosock); ntreeSolveOrder(tx->nodetree); /* needed for pointers */ - ntreeTexUpdatePreviews(tx->nodetree); /* XXX texture nodes should follow shader node methods (ton) */ } /* Here we set the active tree(s), even called for each redraw now, so keep it fast :) */ @@ -1111,9 +1110,6 @@ static int node_resize_modal(bContext *C, wmOperator *op, wmEvent *event) node->width= nsw->oldwidth + mx - nsw->mxstart; CLAMP(node->width, node->typeinfo->minwidth, node->typeinfo->maxwidth); } - // XXX - if(snode->nodetree->type == NTREE_TEXTURE) - ntreeTexUpdatePreviews(snode->nodetree); /* XXX texture nodes should follow shader node methods (ton) */ ED_region_tag_redraw(ar); @@ -1659,7 +1655,6 @@ bNode *node_add_node(SpaceNode *snode, Scene *scene, int type, float locx, float if(snode->nodetree->type==NTREE_TEXTURE) { ntreeTexCheckCyclics(snode->edittree); - ntreeTexUpdatePreviews(snode->edittree); /* XXX texture nodes should follow shader node methods (ton) */ } return node; diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c index cb25d29fd27..2233a4db3a0 100644 --- a/source/blender/editors/space_node/space_node.c +++ b/source/blender/editors/space_node/space_node.c @@ -184,8 +184,9 @@ static void node_area_refresh(const struct bContext *C, struct ScrArea *sa) } else if(snode->treetype==NTREE_TEXTURE) { Tex *tex= (Tex *)snode->id; - if(tex->use_nodes) - ntreeTexUpdatePreviews(tex->nodetree); + if(tex->use_nodes) { + ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100); + } } } } diff --git a/source/blender/nodes/intern/TEX_util.c b/source/blender/nodes/intern/TEX_util.c index a6a5877722b..2c21627dad9 100644 --- a/source/blender/nodes/intern/TEX_util.c +++ b/source/blender/nodes/intern/TEX_util.c @@ -47,6 +47,8 @@ #define PREV_RES 128 /* default preview resolution */ +int preview_flag = 0; + void tex_call_delegate(TexDelegate *dg, float *out, TexParams *params, short thread) { if(dg->node->need_exec) @@ -108,12 +110,6 @@ static void init_preview(bNode *node) if(node->preview==NULL) node->preview= MEM_callocN(sizeof(bNodePreview), "node preview"); - if(node->preview->rect) - if(node->preview->xsize!=xsize && node->preview->ysize!=ysize) { - MEM_freeN(node->preview->rect); - node->preview->rect= NULL; - } - if(node->preview->rect==NULL) { node->preview->rect= MEM_callocN(4*xsize + xsize*ysize*sizeof(float)*4, "node preview rect"); node->preview->xsize= xsize; @@ -136,6 +132,8 @@ void tex_do_preview(bNode *node, bNodeStack *ns, TexCallData *cdata) bNodePreview *preview; float coord[3] = {0, 0, 0}; TexParams params; + int resolution; + int xsize, ysize; if(!cdata->do_preview) return; @@ -146,19 +144,23 @@ void tex_do_preview(bNode *node, bNodeStack *ns, TexCallData *cdata) init_preview(node); preview = node->preview; + xsize = preview->xsize; + ysize = preview->ysize; params.dxt = 0; params.dyt = 0; params.cfra = cdata->cfra; params.coord = coord; - for(x=0; xxsize; x++) - for(y=0; yysize; y++) + resolution = (xsize < ysize) ? xsize : ysize; + + for(x=0; xxsize) * 2 - 1; - params.coord[1] = ((float) y / preview->ysize) * 2 - 1; + params.coord[0] = ((float) x / resolution) * 2 - 1; + params.coord[1] = ((float) y / resolution) * 2 - 1; - result = preview->rect + 4 * (preview->xsize*y + x); + result = preview->rect + 4 * (xsize*y + x); tex_input_rgba(result, ns, ¶ms, cdata->thread); } @@ -212,7 +214,6 @@ void ntreeTexExecTree( TexResult *texres, float *coord, float *dxt, float *dyt, - char do_preview, short thread, Tex *tex, short which_output, @@ -230,28 +231,19 @@ void ntreeTexExecTree( data.dxt = dxt; data.dyt = dyt; data.target = texres; - data.do_preview = do_preview; + data.do_preview = preview_flag; data.thread = thread; data.which_output = which_output; data.cfra= cfra; + preview_flag = 0; + ntreeExecTree(nodes, &data, thread); } -void ntreeTexUpdatePreviews(bNodeTree* nodetree) +void ntreeTexSetPreviewFlag(int doit) { - Tex *tex; - float coord[] = {0,0,0}; - TexResult dummy_texres; - - for(tex= G.main->tex.first; tex; tex= tex->id.next) - if(tex->nodetree == nodetree) break; - if(tex) { - dummy_texres.nor = 0; - - ntreeBeginExecTree(nodetree); - ntreeTexExecTree(nodetree, &dummy_texres, coord, 0, 0, 1, 0, tex, 0, 0); - } + preview_flag = doit; } char* ntreeTexOutputMenu(bNodeTree *ntree) diff --git a/source/blender/nodes/intern/TEX_util.h b/source/blender/nodes/intern/TEX_util.h index 7fff8d04651..87a9cf288d6 100644 --- a/source/blender/nodes/intern/TEX_util.h +++ b/source/blender/nodes/intern/TEX_util.h @@ -102,8 +102,7 @@ float tex_input_value(bNodeStack *in, TexParams *params, short thread); void tex_output(bNode *node, bNodeStack **in, bNodeStack *out, TexFn texfn); void tex_do_preview(bNode *node, bNodeStack *ns, TexCallData *cdata); -void ntreeTexUpdatePreviews( bNodeTree* nodetree ); -void ntreeTexExecTree(bNodeTree *nodes, TexResult *texres, float *coord, float *dxt, float *dyt, char do_preview, short thread, struct Tex *tex, short which_output, int cfra); +void ntreeTexExecTree(bNodeTree *nodes, TexResult *texres, float *coord, float *dxt, float *dyt, short thread, struct Tex *tex, short which_output, int cfra); void params_from_cdata(TexParams *out, TexCallData *in); diff --git a/source/blender/render/intern/source/texture.c b/source/blender/render/intern/source/texture.c index 3db78bfea93..e6d6e78e27b 100644 --- a/source/blender/render/intern/source/texture.c +++ b/source/blender/render/intern/source/texture.c @@ -719,7 +719,7 @@ static int evalnodes(Tex *tex, float *texvec, float *dxt, float *dyt, TexResult short rv = TEX_INT; bNodeTree *nodes = tex->nodetree; - ntreeTexExecTree(nodes, texres, texvec, dxt, dyt, 0, thread, tex, which_output, R.r.cfra); + ntreeTexExecTree(nodes, texres, texvec, dxt, dyt, thread, tex, which_output, R.r.cfra); if(texres->nor) rv |= TEX_NOR; rv |= TEX_RGB; From 8a5a7d3d280f3270ce3115bced8a3975643f7cda Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Wed, 19 Aug 2009 16:49:21 +0000 Subject: [PATCH 08/73] 2.5/Multires: * Fixed saving most recent sculpting on a multires object. Uses the same hack already in place for saving that info for undo. --- source/blender/blenloader/intern/writefile.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 62ec1b71938..ede7aacfea8 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1100,7 +1100,7 @@ static void write_defgroups(WriteData *wd, ListBase *defbase) writestruct(wd, DATA, "bDeformGroup", 1, defgroup); } -static void write_modifiers(WriteData *wd, ListBase *modbase, int write_undo) +static void write_modifiers(WriteData *wd, ListBase *modbase) { ModifierData *md; @@ -1166,13 +1166,13 @@ static void write_modifiers(WriteData *wd, ListBase *modbase, int write_undo) else if (md->type==eModifierType_Multires) { MultiresModifierData *mmd = (MultiresModifierData*) md; - if(mmd->undo_verts && write_undo) + if(mmd->undo_verts) writestruct(wd, DATA, "MVert", mmd->undo_verts_tot, mmd->undo_verts); } } } -static void write_objects(WriteData *wd, ListBase *idbase, int write_undo) +static void write_objects(WriteData *wd, ListBase *idbase) { Object *ob; @@ -1206,7 +1206,7 @@ static void write_objects(WriteData *wd, ListBase *idbase, int write_undo) writestruct(wd, DATA, "BulletSoftBody", 1, ob->bsoft); write_particlesystems(wd, &ob->particlesystem); - write_modifiers(wd, &ob->modifiers, write_undo); + write_modifiers(wd, &ob->modifiers); } ob= ob->id.next; } @@ -2320,7 +2320,7 @@ static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFil write_groups (wd, &mainvar->group); write_armatures(wd, &mainvar->armature); write_actions (wd, &mainvar->action); - write_objects (wd, &mainvar->object, (current != NULL)); + write_objects (wd, &mainvar->object); write_materials(wd, &mainvar->mat); write_textures (wd, &mainvar->tex); write_meshs (wd, &mainvar->mesh); From c21627e31b0e82f28e35af51cec681897285ff78 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Wed, 19 Aug 2009 21:24:52 +0000 Subject: [PATCH 09/73] 2.5/Paint: * Some initial work on a new paint abstraction, PaintStroke. For now, most of the code just pulls out stroke-related stuff from sculpt mode, next step is to integrate the other paint modes to use this. It'll enable stuff like smooth stroke for all the paint modes with less code duplication. --- source/blender/editors/include/ED_view3d.h | 1 + .../editors/sculpt_paint/paint_intern.h | 15 ++ .../editors/sculpt_paint/paint_stroke.c | 224 +++++++++++++++++ .../editors/sculpt_paint/paint_vertex.c | 203 ++++++++-------- source/blender/editors/sculpt_paint/sculpt.c | 229 +++++------------- .../editors/space_view3d/view3d_view.c | 13 + 6 files changed, 415 insertions(+), 270 deletions(-) create mode 100644 source/blender/editors/sculpt_paint/paint_stroke.c diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 07aa44cadd8..fd1b7e1351d 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -70,6 +70,7 @@ float *give_cursor(struct Scene *scene, struct View3D *v3d); void initgrabz(struct RegionView3D *rv3d, float x, float y, float z); void window_to_3d(struct ARegion *ar, float *vec, short mx, short my); void window_to_3d_delta(struct ARegion *ar, float *vec, short mx, short my); +void view3d_unproject(struct bglMats *mats, float out[3], const short x, const short y, const float z); /* Depth buffer */ float read_cached_depth(struct ViewContext *vc, int x, int y); diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 40423e17fe4..41764a70686 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -29,13 +29,28 @@ #ifndef ED_PAINT_INTERN_H #define ED_PAINT_INTERN_H +struct bContext; struct Scene; struct Object; struct Mesh; +struct PaintStroke; +struct PointerRNA; struct ViewContext; +struct wmEvent; +struct wmOperator; struct wmOperatorType; struct ARegion; +/* paint_stroke.c */ +typedef int (*StrokeTestStart)(struct bContext *C, struct wmOperator *op, struct wmEvent *event); +typedef void (*StrokeUpdateStep)(struct bContext *C, struct PaintStroke *stroke, struct PointerRNA *itemptr); +typedef void (*StrokeDone)(struct bContext *C, struct PaintStroke *stroke); + +struct PaintStroke *paint_stroke_new(bContext *C, StrokeTestStart test_start, + StrokeUpdateStep update_step, StrokeDone done); +int paint_stroke_modal(struct bContext *C, struct wmOperator *op, struct wmEvent *event); +struct ViewContext *paint_stroke_view_context(struct PaintStroke *stroke); + /* paint_vertex.c */ void PAINT_OT_weight_paint_toggle(struct wmOperatorType *ot); void PAINT_OT_weight_paint_radial_control(struct wmOperatorType *ot); diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c new file mode 100644 index 00000000000..634b82674b5 --- /dev/null +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -0,0 +1,224 @@ +/* + * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 by Nicholas Bishop + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + * + */ + +#include "MEM_guardedalloc.h" + +#include "DNA_brush_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" +#include "DNA_screen_types.h" + +#include "RNA_access.h" + +#include "BKE_context.h" +#include "BKE_paint.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "BLI_arithb.h" + +#include "BIF_glutil.h" + +#include "ED_screen.h" +#include "ED_view3d.h" + +#include "paint_intern.h" + +#include +#include + +typedef struct PaintStroke { + /* Cached values */ + ViewContext vc; + bglMats mats; + Brush *brush; + + float last_mouse_position[2]; + + /* Set whether any stroke step has yet occured + e.g. in sculpt mode, stroke doesn't start until cursor + passes over the mesh */ + int stroke_started; + + StrokeTestStart test_start; + StrokeUpdateStep update_step; + StrokeDone done; +} PaintStroke; + +/* Put the location of the next stroke dot into the stroke RNA and apply it to the mesh */ +static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *event, float mouse[2]) +{ + PointerRNA itemptr; + float cur_depth, pressure = 1; + float center[3]; + PaintStroke *stroke = op->customdata; + + cur_depth = read_cached_depth(&stroke->vc, mouse[0], mouse[1]); + view3d_unproject(&stroke->mats, center, mouse[0], mouse[1], cur_depth); + + /* Tablet */ + if(event->custom == EVT_DATA_TABLET) { + wmTabletData *wmtab= event->customdata; + if(wmtab->Active != EVT_TABLET_NONE) + pressure= wmtab->Pressure; + } + + /* Add to stroke */ + RNA_collection_add(op->ptr, "stroke", &itemptr); + RNA_float_set_array(&itemptr, "location", center); + RNA_float_set_array(&itemptr, "mouse", mouse); + RNA_boolean_set(&itemptr, "flip", event->shift); + RNA_float_set(&itemptr, "pressure", pressure); + + stroke->last_mouse_position[0] = mouse[0]; + stroke->last_mouse_position[1] = mouse[1]; + + stroke->update_step(C, stroke, &itemptr); +} + +/* Returns zero if no sculpt changes should be made, non-zero otherwise */ +static int paint_smooth_stroke(PaintStroke *stroke, float output[2], wmEvent *event) +{ + output[0] = event->x; + output[1] = event->y; + + if(stroke->brush->flag & BRUSH_SMOOTH_STROKE && stroke->brush->sculpt_tool != SCULPT_TOOL_GRAB) { + float u = stroke->brush->smooth_stroke_factor, v = 1.0 - u; + float dx = stroke->last_mouse_position[0] - event->x, dy = stroke->last_mouse_position[1] - event->y; + + /* If the mouse is moving within the radius of the last move, + don't update the mouse position. This allows sharp turns. */ + if(dx*dx + dy*dy < stroke->brush->smooth_stroke_radius * stroke->brush->smooth_stroke_radius) + return 0; + + output[0] = event->x * v + stroke->last_mouse_position[0] * u; + output[1] = event->y * v + stroke->last_mouse_position[1] * u; + } + + return 1; +} + +/* Returns zero if the stroke dots should not be spaced, non-zero otherwise */ +static int paint_space_stroke_enabled(Brush *br) +{ + return (br->flag & BRUSH_SPACE) && !(br->flag & BRUSH_ANCHORED) && (br->sculpt_tool != SCULPT_TOOL_GRAB); +} + +/* For brushes with stroke spacing enabled, moves mouse in steps + towards the final mouse location. */ +static int paint_space_stroke(bContext *C, wmOperator *op, wmEvent *event, const float final_mouse[2]) +{ + PaintStroke *stroke = op->customdata; + int cnt = 0; + + if(paint_space_stroke_enabled(stroke->brush)) { + float mouse[2] = {stroke->last_mouse_position[0], stroke->last_mouse_position[1]}; + float vec[2] = {final_mouse[0] - mouse[0], final_mouse[1] - mouse[1]}; + float length, scale; + int steps = 0, i; + + /* Normalize the vector between the last stroke dot and the goal */ + length = sqrt(vec[0]*vec[0] + vec[1]*vec[1]); + + if(length > FLT_EPSILON) { + scale = stroke->brush->spacing / length; + vec[0] *= scale; + vec[1] *= scale; + + steps = (int)(length / stroke->brush->spacing); + for(i = 0; i < steps; ++i, ++cnt) { + mouse[0] += vec[0]; + mouse[1] += vec[1]; + paint_brush_stroke_add_step(C, op, event, mouse); + } + } + } + + return cnt; +} + +/**** Public API ****/ + +PaintStroke *paint_stroke_new(bContext *C, StrokeTestStart test_start, + StrokeUpdateStep update_step, StrokeDone done) +{ + PaintStroke *stroke = MEM_callocN(sizeof(PaintStroke), "PaintStroke"); + + stroke->brush = paint_brush(paint_get_active(CTX_data_scene(C))); + view3d_set_viewcontext(C, &stroke->vc); + view3d_get_transformation(&stroke->vc, stroke->vc.obact, &stroke->mats); + + stroke->test_start = test_start; + stroke->update_step = update_step; + stroke->done = done; + + return stroke; +} + +int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event) +{ + ARegion *ar = CTX_wm_region(C); + PaintStroke *stroke = op->customdata; + float mouse[2]; + + if(!stroke->stroke_started) { + stroke->last_mouse_position[0] = event->x; + stroke->last_mouse_position[1] = event->y; + stroke->stroke_started = stroke->test_start(C, op, event); + ED_region_tag_redraw(ar); + } + + if(stroke->stroke_started) { + if(paint_smooth_stroke(stroke, mouse, event)) { + if(paint_space_stroke_enabled(stroke->brush)) { + if(!paint_space_stroke(C, op, event, mouse)) + ED_region_tag_redraw(ar); + } + else + paint_brush_stroke_add_step(C, op, event, mouse); + } + else + ED_region_tag_redraw(ar); + } + + /* TODO: fix hardcoded event here */ + if(event->type == LEFTMOUSE && event->val == 0) { + stroke->done(C, stroke); + MEM_freeN(stroke); + return OPERATOR_FINISHED; + } + else + return OPERATOR_RUNNING_MODAL; +} + +ViewContext *paint_stroke_view_context(PaintStroke *stroke) +{ + return &stroke->vc; +} + diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 1a548708ec8..05faa47e0f4 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1709,122 +1709,123 @@ static void vpaint_exit(bContext *C, wmOperator *op) op->customdata= NULL; } -static int vpaint_modal(bContext *C, wmOperator *op, wmEvent *event) +static void vpaint_dot(bContext *C, struct VPaintData *vpd, wmEvent *event) { ToolSettings *ts= CTX_data_tool_settings(C); VPaint *vp= ts->vpaint; Brush *brush = paint_brush(&vp->paint); - - switch(event->type) { - case LEFTMOUSE: - if(event->val==0) { /* release */ - vpaint_exit(C, op); - return OPERATOR_FINISHED; - } - /* pass on, first press gets painted too */ + ViewContext *vc= &vpd->vc; + Object *ob= vc->obact; + Mesh *me= ob->data; + float mat[4][4]; + int *indexar= vpd->indexar; + int totindex, index; + short mval[2]; - case MOUSEMOVE: - { - struct VPaintData *vpd= op->customdata; - ViewContext *vc= &vpd->vc; - Object *ob= vc->obact; - Mesh *me= ob->data; - float mat[4][4]; - int *indexar= vpd->indexar; - int totindex, index; - short mval[2]; + view3d_operator_needs_opengl(C); - view3d_operator_needs_opengl(C); + /* load projection matrix */ + wmMultMatrix(ob->obmat); + wmGetSingleMatrix(mat); + wmLoadMatrix(vc->rv3d->viewmat); - /* load projection matrix */ - wmMultMatrix(ob->obmat); - wmGetSingleMatrix(mat); - wmLoadMatrix(vc->rv3d->viewmat); - - mval[0]= event->x - vc->ar->winrct.xmin; - mval[1]= event->y - vc->ar->winrct.ymin; + mval[0]= event->x - vc->ar->winrct.xmin; + mval[1]= event->y - vc->ar->winrct.ymin; - /* which faces are involved */ - if(vp->flag & VP_AREA) { - totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], brush->size); - } - else { - indexar[0]= view3d_sample_backbuf(vc, mval[0], mval[1]); - if(indexar[0]) totindex= 1; - else totindex= 0; - } + /* which faces are involved */ + if(vp->flag & VP_AREA) { + totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], brush->size); + } + else { + indexar[0]= view3d_sample_backbuf(vc, mval[0], mval[1]); + if(indexar[0]) totindex= 1; + else totindex= 0; + } - MTC_Mat4SwapMat4(vc->rv3d->persmat, mat); + MTC_Mat4SwapMat4(vc->rv3d->persmat, mat); - if(vp->flag & VP_COLINDEX) { - for(index=0; indextotface) { - MFace *mface= ((MFace *)me->mface) + (indexar[index]-1); + if(vp->flag & VP_COLINDEX) { + for(index=0; indextotface) { + MFace *mface= ((MFace *)me->mface) + (indexar[index]-1); - if(mface->mat_nr!=ob->actcol-1) { - indexar[index]= 0; - } - } + if(mface->mat_nr!=ob->actcol-1) { + indexar[index]= 0; } - } - if((G.f & G_FACESELECT) && me->mface) { - for(index=0; indextotface) { - MFace *mface= ((MFace *)me->mface) + (indexar[index]-1); - - if((mface->flag & ME_FACE_SEL)==0) - indexar[index]= 0; - } - } - } - - for(index=0; indextotface) { - MFace *mface= ((MFace *)me->mface) + (indexar[index]-1); - unsigned int *mcol= ( (unsigned int *)me->mcol) + 4*(indexar[index]-1); - unsigned int *mcolorig= ( (unsigned int *)vp->vpaint_prev) + 4*(indexar[index]-1); - int alpha; - - if(vp->mode==VP_BLUR) { - unsigned int fcol1= mcol_blend( mcol[0], mcol[1], 128); - if(mface->v4) { - unsigned int fcol2= mcol_blend( mcol[2], mcol[3], 128); - vpd->paintcol= mcol_blend( fcol1, fcol2, 128); - } - else { - vpd->paintcol= mcol_blend( mcol[2], fcol1, 170); - } - - } - - alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*mface->v1, mval); - if(alpha) vpaint_blend(vp, mcol, mcolorig, vpd->paintcol, alpha); - - alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*mface->v2, mval); - if(alpha) vpaint_blend(vp, mcol+1, mcolorig+1, vpd->paintcol, alpha); - - alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*mface->v3, mval); - if(alpha) vpaint_blend(vp, mcol+2, mcolorig+2, vpd->paintcol, alpha); - - if(mface->v4) { - alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*mface->v4, mval); - if(alpha) vpaint_blend(vp, mcol+3, mcolorig+3, vpd->paintcol, alpha); - } - } - } - - MTC_Mat4SwapMat4(vc->rv3d->persmat, mat); - - do_shared_vertexcol(me); - - ED_region_tag_redraw(vc->ar); - - DAG_object_flush_update(vc->scene, ob, OB_RECALC_DATA); + } } + } + if((G.f & G_FACESELECT) && me->mface) { + for(index=0; indextotface) { + MFace *mface= ((MFace *)me->mface) + (indexar[index]-1); + + if((mface->flag & ME_FACE_SEL)==0) + indexar[index]= 0; + } + } + } + + for(index=0; indextotface) { + MFace *mface= ((MFace *)me->mface) + (indexar[index]-1); + unsigned int *mcol= ( (unsigned int *)me->mcol) + 4*(indexar[index]-1); + unsigned int *mcolorig= ( (unsigned int *)vp->vpaint_prev) + 4*(indexar[index]-1); + int alpha; + + if(vp->mode==VP_BLUR) { + unsigned int fcol1= mcol_blend( mcol[0], mcol[1], 128); + if(mface->v4) { + unsigned int fcol2= mcol_blend( mcol[2], mcol[3], 128); + vpd->paintcol= mcol_blend( fcol1, fcol2, 128); + } + else { + vpd->paintcol= mcol_blend( mcol[2], fcol1, 170); + } + + } + + alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*mface->v1, mval); + if(alpha) vpaint_blend(vp, mcol, mcolorig, vpd->paintcol, alpha); + + alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*mface->v2, mval); + if(alpha) vpaint_blend(vp, mcol+1, mcolorig+1, vpd->paintcol, alpha); + + alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*mface->v3, mval); + if(alpha) vpaint_blend(vp, mcol+2, mcolorig+2, vpd->paintcol, alpha); + + if(mface->v4) { + alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*mface->v4, mval); + if(alpha) vpaint_blend(vp, mcol+3, mcolorig+3, vpd->paintcol, alpha); + } + } + } + + MTC_Mat4SwapMat4(vc->rv3d->persmat, mat); + + do_shared_vertexcol(me); + + ED_region_tag_redraw(vc->ar); + + DAG_object_flush_update(vc->scene, ob, OB_RECALC_DATA); +} + +static int vpaint_modal(bContext *C, wmOperator *op, wmEvent *event) +{ + switch(event->type) { + case LEFTMOUSE: + if(event->val==0) { /* release */ + vpaint_exit(C, op); + return OPERATOR_FINISHED; + } + /* pass on, first press gets painted too */ + + case MOUSEMOVE: + vpaint_dot(C, op->customdata, event); break; } - + return OPERATOR_RUNNING_MODAL; } diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index f7f72d611dc..c01004f5b7e 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -80,6 +80,7 @@ #include "ED_space_api.h" #include "ED_util.h" #include "ED_view3d.h" +#include "paint_intern.h" #include "sculpt_intern.h" #include "RNA_access.h" @@ -144,7 +145,6 @@ typedef struct StrokeCache { int first_time; /* Beginning of stroke may do some things special */ - ViewContext vc; bglMats *mats; short (*orig_norms)[3]; /* Copy of the mesh vertices' normals */ @@ -178,19 +178,6 @@ typedef struct ProjVert { * Simple functions to get data from the GL */ -/* Uses window coordinates (x,y) and depth component z to find a point in - modelspace */ -static void unproject(bglMats *mats, float out[3], const short x, const short y, const float z) -{ - double ux, uy, uz; - - gluUnProject(x,y,z, mats->modelview, mats->projection, - (GLint *)mats->viewport, &ux, &uy, &uz ); - out[0] = ux; - out[1] = uy; - out[2] = uz; -} - /* Convert a point in model coordinates to 2D screen coordinates. */ static void projectf(bglMats *mats, const float v[3], float p[2]) { @@ -547,7 +534,7 @@ static void do_flatten_clay_brush(Sculpt *sd, SculptSession *ss, const ListBase ActiveData *node= active_verts->first; /* area_normal and cntr define the plane towards which vertices are squashed */ float area_normal[3]; - float cntr[3], cntr2[3], bstr; + float cntr[3], cntr2[3], bstr = 0; int flip = 0; calc_area_normal(sd, ss, area_normal, active_verts); @@ -1169,7 +1156,7 @@ static float unproject_brush_radius(SculptSession *ss, float offset) float brush_edge[3]; /* In anchored mode, brush size changes with mouse loc, otherwise it's fixed using the brush radius */ - unproject(ss->cache->mats, brush_edge, ss->cache->initial_mouse[0] + offset, + view3d_unproject(ss->cache->mats, brush_edge, ss->cache->initial_mouse[0] + offset, ss->cache->initial_mouse[1], ss->cache->depth); return VecLenf(ss->cache->true_location, brush_edge); @@ -1194,6 +1181,7 @@ static void sculpt_update_cache_invariants(Sculpt *sd, SculptSession *ss, bConte { StrokeCache *cache = MEM_callocN(sizeof(StrokeCache), "stroke cache"); Brush *brush = paint_brush(&sd->paint); + ViewContext *vc = paint_stroke_view_context(op->customdata); int i; ss->cache = cache; @@ -1209,10 +1197,8 @@ static void sculpt_update_cache_invariants(Sculpt *sd, SculptSession *ss, bConte /* Truly temporary data that isn't stored in properties */ - view3d_set_viewcontext(C, &cache->vc); - cache->mats = MEM_callocN(sizeof(bglMats), "sculpt bglMats"); - view3d_get_transformation(&cache->vc, cache->vc.obact, cache->mats); + view3d_get_transformation(vc, vc->obact, cache->mats); sculpt_update_mesh_elements(C); @@ -1252,7 +1238,7 @@ static void sculpt_update_cache_invariants(Sculpt *sd, SculptSession *ss, bConte } } - unproject(cache->mats, cache->true_location, cache->initial_mouse[0], cache->initial_mouse[1], cache->depth); + view3d_unproject(cache->mats, cache->true_location, cache->initial_mouse[0], cache->initial_mouse[1], cache->depth); cache->initial_radius = unproject_brush_radius(ss, brush->size); cache->rotation = 0; cache->first_time = 1; @@ -1312,7 +1298,7 @@ static void sculpt_update_cache_variants(Sculpt *sd, SculptSession *ss, PointerR /* Find the grab delta */ if(brush->sculpt_tool == SCULPT_TOOL_GRAB) { - unproject(cache->mats, grab_location, cache->mouse[0], cache->mouse[1], cache->depth); + view3d_unproject(cache->mats, grab_location, cache->mouse[0], cache->mouse[1], cache->depth); if(!cache->first_time) VecSubf(cache->grab_delta, grab_location, cache->old_grab_location); VecCopyf(cache->old_grab_location, grab_location); @@ -1325,7 +1311,6 @@ static void sculpt_brush_stroke_init_properties(bContext *C, wmOperator *op, wmE Sculpt *sd = CTX_data_tool_settings(C)->sculpt; Object *ob= CTX_data_active_object(C); ModifierData *md; - ViewContext vc; float scale[3], clip_tolerance[3] = {0,0,0}; float mouse[2]; int flag = 0; @@ -1358,13 +1343,12 @@ static void sculpt_brush_stroke_init_properties(bContext *C, wmOperator *op, wmE RNA_float_set_array(op->ptr, "initial_mouse", mouse); /* Initial screen depth under the mouse */ - view3d_set_viewcontext(C, &vc); - RNA_float_set(op->ptr, "depth", read_cached_depth(&vc, event->x, event->y)); + RNA_float_set(op->ptr, "depth", read_cached_depth(paint_stroke_view_context(op->customdata), event->x, event->y)); sculpt_update_cache_invariants(sd, ss, C, op); } -static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, wmEvent *event) +static void sculpt_brush_stroke_init(bContext *C) { Sculpt *sd = CTX_data_tool_settings(C)->sculpt; SculptSession *ss = CTX_data_active_object(C)->sculpt; @@ -1376,10 +1360,7 @@ static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, wmEvent *even changes are made to the texture. */ sculpt_update_tex(sd, ss); - /* add modal handler */ - WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op); - - return OPERATOR_RUNNING_MODAL; + sculpt_update_mesh_elements(C); } static void sculpt_restore_mesh(Sculpt *sd, SculptSession *ss) @@ -1435,157 +1416,67 @@ static void sculpt_flush_update(bContext *C) ED_region_tag_redraw(ar); } -/* Returns zero if no sculpt changes should be made, non-zero otherwise */ -static int sculpt_smooth_stroke(Sculpt *s, SculptSession *ss, float output[2], wmEvent *event) +static int sculpt_stroke_test_start(bContext *C, struct wmOperator *op, wmEvent *event) { - Brush *brush = paint_brush(&s->paint); - - output[0] = event->x; - output[1] = event->y; - - if(brush->flag & BRUSH_SMOOTH_STROKE && brush->sculpt_tool != SCULPT_TOOL_GRAB) { - StrokeCache *cache = ss->cache; - float u = brush->smooth_stroke_factor, v = 1.0 - u; - float dx = cache->mouse[0] - event->x, dy = cache->mouse[1] - event->y; - - /* If the mouse is moving within the radius of the last move, - don't update the mouse position. This allows sharp turns. */ - if(dx*dx + dy*dy < brush->smooth_stroke_radius * brush->smooth_stroke_radius) - return 0; - - output[0] = event->x * v + cache->mouse[0] * u; - output[1] = event->y * v + cache->mouse[1] * u; - } - - return 1; -} - -/* Returns zero if the stroke dots should not be spaced, non-zero otherwise */ -int sculpt_space_stroke_enabled(Sculpt *s) -{ - Brush *br = paint_brush(&s->paint); - return (br->flag & BRUSH_SPACE) && !(br->flag & BRUSH_ANCHORED) && (br->sculpt_tool != SCULPT_TOOL_GRAB); -} - -/* Put the location of the next sculpt stroke dot into the stroke RNA and apply it to the mesh */ -static void sculpt_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *event, float mouse[2]) -{ - Sculpt *sd = CTX_data_tool_settings(C)->sculpt; - SculptSession *ss = CTX_data_active_object(C)->sculpt; - StrokeCache *cache = ss->cache; - PointerRNA itemptr; - float cur_depth, pressure = 1; - float center[3]; - - cur_depth = read_cached_depth(&cache->vc, mouse[0], mouse[1]); - unproject(ss->cache->mats, center, mouse[0], mouse[1], cur_depth); - - /* Tablet */ - if(event->custom == EVT_DATA_TABLET) { - wmTabletData *wmtab= event->customdata; - if(wmtab->Active != EVT_TABLET_NONE) - pressure= wmtab->Pressure; - } - - /* Add to stroke */ - RNA_collection_add(op->ptr, "stroke", &itemptr); - RNA_float_set_array(&itemptr, "location", center); - RNA_float_set_array(&itemptr, "mouse", mouse); - RNA_boolean_set(&itemptr, "flip", event->shift); - RNA_float_set(&itemptr, "pressure", pressure); - sculpt_update_cache_variants(sd, ss, &itemptr); - - sculpt_restore_mesh(sd, ss); - do_symmetrical_brush_actions(sd, ss); -} - -/* For brushes with stroke spacing enabled, moves mouse in steps - towards the final mouse location. */ -static int sculpt_space_stroke(bContext *C, wmOperator *op, wmEvent *event, Sculpt *s, SculptSession *ss, const float final_mouse[2]) -{ - StrokeCache *cache = ss->cache; - Brush *brush = paint_brush(&s->paint); - int cnt = 0; - - if(sculpt_space_stroke_enabled(s)) { - float vec[2] = {final_mouse[0] - cache->mouse[0], final_mouse[1] - cache->mouse[1]}; - float mouse[2] = {cache->mouse[0], cache->mouse[1]}; - float length, scale; - int steps = 0, i; - - /* Normalize the vector between the last stroke dot and the goal */ - length = sqrt(vec[0]*vec[0] + vec[1]*vec[1]); - - if(length > FLT_EPSILON) { - scale = brush->spacing / length; - vec[0] *= scale; - vec[1] *= scale; - - steps = (int)(length / brush->spacing); - for(i = 0; i < steps; ++i, ++cnt) { - mouse[0] += vec[0]; - mouse[1] += vec[1]; - sculpt_brush_stroke_add_step(C, op, event, mouse); - } - } - } - - return cnt; -} - -static int sculpt_brush_stroke_modal(bContext *C, wmOperator *op, wmEvent *event) -{ - Sculpt *sd = CTX_data_tool_settings(C)->sculpt; - SculptSession *ss = CTX_data_active_object(C)->sculpt; - ARegion *ar = CTX_wm_region(C); + ViewContext vc; float cur_depth; - sculpt_update_mesh_elements(C); + view3d_set_viewcontext(C, &vc); + cur_depth = read_cached_depth(&vc, event->x, event->y); + + /* Don't start the stroke until a valid depth is found */ + if(cur_depth < 1.0 - FLT_EPSILON) { + SculptSession *ss = CTX_data_active_object(C)->sculpt; - if(!ss->cache) { - ViewContext vc; - view3d_set_viewcontext(C, &vc); - cur_depth = read_cached_depth(&vc, event->x, event->y); + sculpt_brush_stroke_init_properties(C, op, event, ss); + sculptmode_update_all_projverts(ss); - /* Don't start the stroke until a valid depth is found */ - if(cur_depth < 1.0 - FLT_EPSILON) { - sculpt_brush_stroke_init_properties(C, op, event, ss); - sculptmode_update_all_projverts(ss); - } - - ED_region_tag_redraw(ar); + return 1; } + else + return 0; +} - if(ss->cache) { - float mouse[2]; +static void sculpt_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr) +{ + Sculpt *sd = CTX_data_tool_settings(C)->sculpt; + SculptSession *ss = CTX_data_active_object(C)->sculpt; - if(sculpt_smooth_stroke(sd, ss, mouse, event)) { - if(sculpt_space_stroke_enabled(sd)) { - if(!sculpt_space_stroke(C, op, event, sd, ss, mouse)) - ED_region_tag_redraw(ar); - } - else - sculpt_brush_stroke_add_step(C, op, event, mouse); + sculpt_update_cache_variants(sd, ss, itemptr); + sculpt_restore_mesh(sd, ss); + do_symmetrical_brush_actions(sd, ss); - sculpt_flush_update(C); - sculpt_post_stroke_free(ss); - } - else - ED_region_tag_redraw(ar); - } + /* Cleanup */ + sculpt_flush_update(C); // XXX: during exec, shouldn't do this every time + sculpt_post_stroke_free(ss); +} + +static void sculpt_stroke_done(bContext *C, struct PaintStroke *stroke) +{ + SculptSession *ss = CTX_data_active_object(C)->sculpt; /* Finished */ - if(event->type == LEFTMOUSE && event->val == 0) { - if(ss->cache) { - request_depth_update(ss->cache->vc.rv3d); - sculpt_cache_free(ss->cache); - ss->cache = NULL; - sculpt_undo_push(C, sd); - } + if(ss->cache) { + Sculpt *sd = CTX_data_tool_settings(C)->sculpt; - return OPERATOR_FINISHED; + request_depth_update(paint_stroke_view_context(stroke)->rv3d); + sculpt_cache_free(ss->cache); + ss->cache = NULL; + sculpt_undo_push(C, sd); } +} +static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + sculpt_brush_stroke_init(C); + + op->customdata = paint_stroke_new(C, sculpt_stroke_test_start, + sculpt_stroke_update_step, + sculpt_stroke_done); + + /* add modal handler */ + WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op); + return OPERATOR_RUNNING_MODAL; } @@ -1594,10 +1485,10 @@ static int sculpt_brush_stroke_exec(bContext *C, wmOperator *op) Sculpt *sd = CTX_data_tool_settings(C)->sculpt; SculptSession *ss = CTX_data_active_object(C)->sculpt; - view3d_operator_needs_opengl(C); + sculpt_brush_stroke_init(C); + sculpt_update_cache_invariants(sd, ss, C, op); sculptmode_update_all_projverts(ss); - sculpt_update_tex(sd, ss); RNA_BEGIN(op->ptr, itemptr, "stroke") { sculpt_update_cache_variants(sd, ss, &itemptr); @@ -1627,7 +1518,7 @@ static void SCULPT_OT_brush_stroke(wmOperatorType *ot) /* api callbacks */ ot->invoke= sculpt_brush_stroke_invoke; - ot->modal= sculpt_brush_stroke_modal; + ot->modal= paint_stroke_modal; ot->exec= sculpt_brush_stroke_exec; ot->poll= sculpt_poll; diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 58b7a70a128..ce7b6ba454d 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -63,6 +63,7 @@ #include "RE_pipeline.h" // make_stars #include "BIF_gl.h" +#include "BIF_glutil.h" #include "WM_api.h" #include "WM_types.h" @@ -543,6 +544,18 @@ void view3d_get_object_project_mat(RegionView3D *rv3d, Object *ob, float pmat[4] Mat4MulMat4(pmat, vmat, rv3d->winmat); } +/* Uses window coordinates (x,y) and depth component z to find a point in + modelspace */ +void view3d_unproject(bglMats *mats, float out[3], const short x, const short y, const float z) +{ + double ux, uy, uz; + + gluUnProject(x,y,z, mats->modelview, mats->projection, + (GLint *)mats->viewport, &ux, &uy, &uz ); + out[0] = ux; + out[1] = uy; + out[2] = uz; +} /* use above call to get projecting mat */ void view3d_project_float(ARegion *ar, float *vec, float *adr, float mat[4][4]) From 286c2ca80be4ae46dc220ada2fcc5bf636d5ff49 Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Thu, 20 Aug 2009 00:33:59 +0000 Subject: [PATCH 10/73] Smoke: * cache for low res (deactivating high res for now) * new way of view3d rendering of smoke (no longer 3 axes) -using 3dtexture now (introduced into gpu/intern) * introducing LZO and LZMA libs into extern (makefiles missing for now) * reducing memory usage after simulating for the frame ended (freeing temporary buffers) * splitting smoke into 2 modifier for the cache-sake (it cannot handle more than 1 cache on the same modifier-index) * no color on gui anymore * fixing non-power-of-2 resolutions (hopefully) * fixing select-deselect of domain drawing bug * fixing drawobject.c coding style (making Ton happy) ;-) HINT #1: If scons doesn't work -> cmakefiles are up-to-date, couldn't test scons (but i tried to mantain them, too) CODERS HINT #1: we really need a way to disable adding all modifiers through "Add Modifiers" dropdown! WARNING #1: before applying this commit, deactivate your SMOKE DOMAIN in your old files and save them then. You can open them then savely after that. WARNING #2: File and cache format of smoke can be changed, this is not final! --- extern/CMakeLists.txt | 3 + extern/SConscript | 4 +- extern/lzma/7zBuf.c | 36 + extern/lzma/7zBuf.h | 31 + extern/lzma/7zBuf2.c | 45 + extern/lzma/7zCrc.c | 35 + extern/lzma/7zCrc.h | 24 + extern/lzma/7zFile.c | 263 ++ extern/lzma/7zFile.h | 74 + extern/lzma/7zStream.c | 169 + extern/lzma/7zVersion.h | 7 + extern/lzma/Alloc.c | 127 + extern/lzma/Alloc.h | 32 + extern/lzma/Bcj2.c | 132 + extern/lzma/Bcj2.h | 30 + extern/lzma/Bra.c | 133 + extern/lzma/Bra.h | 60 + extern/lzma/Bra86.c | 85 + extern/lzma/BraIA64.c | 67 + extern/lzma/CMakeLists.txt | 34 + extern/lzma/CpuArch.h | 69 + extern/lzma/LzFind.c | 751 +++ extern/lzma/LzFind.h | 107 + extern/lzma/LzFindMt.c | 793 ++++ extern/lzma/LzFindMt.h | 97 + extern/lzma/LzHash.h | 54 + extern/lzma/LzmaDec.c | 1007 ++++ extern/lzma/LzmaDec.h | 223 + extern/lzma/LzmaEnc.c | 2281 +++++++++ extern/lzma/LzmaEnc.h | 72 + extern/lzma/LzmaLib.c | 46 + extern/lzma/LzmaLib.h | 135 + extern/lzma/Threads.c | 109 + extern/lzma/Threads.h | 68 + extern/lzma/Types.h | 208 + extern/lzma/history.txt | 236 + extern/lzma/lzma.txt | 594 +++ extern/lzo/CMakeLists.txt | 34 + extern/lzo/SConscript | 9 + extern/lzo/minilzo/COPYING | 340 ++ extern/lzo/minilzo/Makefile | 113 + extern/lzo/minilzo/README.LZO | 123 + extern/lzo/minilzo/lzoconf.h | 417 ++ extern/lzo/minilzo/lzodefs.h | 1807 ++++++++ extern/lzo/minilzo/minilzo.c | 4112 +++++++++++++++++ extern/lzo/minilzo/minilzo.h | 112 + intern/smoke/extern/smoke_API.h | 15 +- intern/smoke/intern/FLUID_3D.cpp | 79 +- intern/smoke/intern/FLUID_3D.h | 17 +- intern/smoke/intern/FLUID_3D_SOLVERS.cpp | 24 + intern/smoke/intern/WTURBULENCE.cpp | 481 +- intern/smoke/intern/WTURBULENCE.h | 21 +- intern/smoke/intern/smoke_API.cpp | 51 +- release/ui/buttons_physics_smoke.py | 215 +- source/blender/blenkernel/BKE_pointcache.h | 6 +- source/blender/blenkernel/BKE_smoke.h | 17 +- source/blender/blenkernel/CMakeLists.txt | 2 + source/blender/blenkernel/SConscript | 2 + source/blender/blenkernel/intern/modifier.c | 79 +- source/blender/blenkernel/intern/pointcache.c | 271 +- source/blender/blenkernel/intern/smoke.c | 1155 +++-- .../blender/blenkernel/intern/smokehighres.c | 137 + source/blender/blenlib/BLI_winstuff.h | 30 +- source/blender/blenloader/intern/readfile.c | 21 +- source/blender/blenloader/intern/writefile.c | 9 +- .../blender/editors/object/object_modifier.c | 7 + .../editors/space_buttons/buttons_context.c | 12 +- .../blender/editors/space_view3d/drawobject.c | 362 +- .../blender/editors/space_view3d/drawvolume.c | 304 ++ .../editors/space_view3d/view3d_intern.h | 3 + source/blender/gpu/GPU_draw.h | 4 + source/blender/gpu/GPU_extensions.h | 1 + source/blender/gpu/intern/gpu_draw.c | 19 + source/blender/gpu/intern/gpu_extensions.c | 72 + source/blender/makesdna/DNA_modifier_types.h | 30 +- source/blender/makesdna/DNA_smoke_types.h | 34 +- source/blender/makesrna/RNA_access.h | 1 + source/blender/makesrna/intern/rna_modifier.c | 70 +- source/blender/makesrna/intern/rna_smoke.c | 85 +- source/creator/CMakeLists.txt | 2 + 80 files changed, 17406 insertions(+), 1540 deletions(-) create mode 100644 extern/lzma/7zBuf.c create mode 100644 extern/lzma/7zBuf.h create mode 100644 extern/lzma/7zBuf2.c create mode 100644 extern/lzma/7zCrc.c create mode 100644 extern/lzma/7zCrc.h create mode 100644 extern/lzma/7zFile.c create mode 100644 extern/lzma/7zFile.h create mode 100644 extern/lzma/7zStream.c create mode 100644 extern/lzma/7zVersion.h create mode 100644 extern/lzma/Alloc.c create mode 100644 extern/lzma/Alloc.h create mode 100644 extern/lzma/Bcj2.c create mode 100644 extern/lzma/Bcj2.h create mode 100644 extern/lzma/Bra.c create mode 100644 extern/lzma/Bra.h create mode 100644 extern/lzma/Bra86.c create mode 100644 extern/lzma/BraIA64.c create mode 100644 extern/lzma/CMakeLists.txt create mode 100644 extern/lzma/CpuArch.h create mode 100644 extern/lzma/LzFind.c create mode 100644 extern/lzma/LzFind.h create mode 100644 extern/lzma/LzFindMt.c create mode 100644 extern/lzma/LzFindMt.h create mode 100644 extern/lzma/LzHash.h create mode 100644 extern/lzma/LzmaDec.c create mode 100644 extern/lzma/LzmaDec.h create mode 100644 extern/lzma/LzmaEnc.c create mode 100644 extern/lzma/LzmaEnc.h create mode 100644 extern/lzma/LzmaLib.c create mode 100644 extern/lzma/LzmaLib.h create mode 100644 extern/lzma/Threads.c create mode 100644 extern/lzma/Threads.h create mode 100644 extern/lzma/Types.h create mode 100644 extern/lzma/history.txt create mode 100644 extern/lzma/lzma.txt create mode 100644 extern/lzo/CMakeLists.txt create mode 100644 extern/lzo/SConscript create mode 100644 extern/lzo/minilzo/COPYING create mode 100644 extern/lzo/minilzo/Makefile create mode 100644 extern/lzo/minilzo/README.LZO create mode 100644 extern/lzo/minilzo/lzoconf.h create mode 100644 extern/lzo/minilzo/lzodefs.h create mode 100644 extern/lzo/minilzo/minilzo.c create mode 100644 extern/lzo/minilzo/minilzo.h create mode 100644 source/blender/blenkernel/intern/smokehighres.c create mode 100644 source/blender/editors/space_view3d/drawvolume.c diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index b6cfe3b113e..019cd9de28b 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -37,3 +37,6 @@ ADD_SUBDIRECTORY(glew) IF(WITH_OPENJPEG) ADD_SUBDIRECTORY(libopenjpeg) ENDIF(WITH_OPENJPEG) + +ADD_SUBDIRECTORY(lzo) +ADD_SUBDIRECTORY(lzma) diff --git a/extern/SConscript b/extern/SConscript index 175613c3d2b..20604d87e45 100644 --- a/extern/SConscript +++ b/extern/SConscript @@ -22,5 +22,5 @@ if env['WITH_BF_REDCODE'] and env['BF_REDCODE_LIB'] == '': if env['OURPLATFORM'] == 'linux2': SConscript(['binreloc/SConscript']); -# FFTW not needed atm - dg -# SConscript(['fftw/SConscript']) +SConscript(['lzo/SConscript']) +SConscript(['lzma/SConscript']) diff --git a/extern/lzma/7zBuf.c b/extern/lzma/7zBuf.c new file mode 100644 index 00000000000..14e7f4e2b92 --- /dev/null +++ b/extern/lzma/7zBuf.c @@ -0,0 +1,36 @@ +/* 7zBuf.c -- Byte Buffer +2008-03-28 +Igor Pavlov +Public domain */ + +#include "7zBuf.h" + +void Buf_Init(CBuf *p) +{ + p->data = 0; + p->size = 0; +} + +int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc) +{ + p->size = 0; + if (size == 0) + { + p->data = 0; + return 1; + } + p->data = (Byte *)alloc->Alloc(alloc, size); + if (p->data != 0) + { + p->size = size; + return 1; + } + return 0; +} + +void Buf_Free(CBuf *p, ISzAlloc *alloc) +{ + alloc->Free(alloc, p->data); + p->data = 0; + p->size = 0; +} diff --git a/extern/lzma/7zBuf.h b/extern/lzma/7zBuf.h new file mode 100644 index 00000000000..c5bd71879cc --- /dev/null +++ b/extern/lzma/7zBuf.h @@ -0,0 +1,31 @@ +/* 7zBuf.h -- Byte Buffer +2008-10-04 : Igor Pavlov : Public domain */ + +#ifndef __7Z_BUF_H +#define __7Z_BUF_H + +#include "Types.h" + +typedef struct +{ + Byte *data; + size_t size; +} CBuf; + +void Buf_Init(CBuf *p); +int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc); +void Buf_Free(CBuf *p, ISzAlloc *alloc); + +typedef struct +{ + Byte *data; + size_t size; + size_t pos; +} CDynBuf; + +void DynBuf_Construct(CDynBuf *p); +void DynBuf_SeekToBeg(CDynBuf *p); +int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc); +void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc); + +#endif diff --git a/extern/lzma/7zBuf2.c b/extern/lzma/7zBuf2.c new file mode 100644 index 00000000000..8d17e0dcf80 --- /dev/null +++ b/extern/lzma/7zBuf2.c @@ -0,0 +1,45 @@ +/* 7zBuf2.c -- Byte Buffer +2008-10-04 : Igor Pavlov : Public domain */ + +#include +#include "7zBuf.h" + +void DynBuf_Construct(CDynBuf *p) +{ + p->data = 0; + p->size = 0; + p->pos = 0; +} + +void DynBuf_SeekToBeg(CDynBuf *p) +{ + p->pos = 0; +} + +int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc) +{ + if (size > p->size - p->pos) + { + size_t newSize = p->pos + size; + Byte *data; + newSize += newSize / 4; + data = (Byte *)alloc->Alloc(alloc, newSize); + if (data == 0) + return 0; + p->size = newSize; + memcpy(data, p->data, p->pos); + alloc->Free(alloc, p->data); + p->data = data; + } + memcpy(p->data + p->pos, buf, size); + p->pos += size; + return 1; +} + +void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc) +{ + alloc->Free(alloc, p->data); + p->data = 0; + p->size = 0; + p->pos = 0; +} diff --git a/extern/lzma/7zCrc.c b/extern/lzma/7zCrc.c new file mode 100644 index 00000000000..71962b2c28d --- /dev/null +++ b/extern/lzma/7zCrc.c @@ -0,0 +1,35 @@ +/* 7zCrc.c -- CRC32 calculation +2008-08-05 +Igor Pavlov +Public domain */ + +#include "7zCrc.h" + +#define kCrcPoly 0xEDB88320 +UInt32 g_CrcTable[256]; + +void MY_FAST_CALL CrcGenerateTable(void) +{ + UInt32 i; + for (i = 0; i < 256; i++) + { + UInt32 r = i; + int j; + for (j = 0; j < 8; j++) + r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1)); + g_CrcTable[i] = r; + } +} + +UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size) +{ + const Byte *p = (const Byte *)data; + for (; size > 0 ; size--, p++) + v = CRC_UPDATE_BYTE(v, *p); + return v; +} + +UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size) +{ + return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF; +} diff --git a/extern/lzma/7zCrc.h b/extern/lzma/7zCrc.h new file mode 100644 index 00000000000..00dc29cee3c --- /dev/null +++ b/extern/lzma/7zCrc.h @@ -0,0 +1,24 @@ +/* 7zCrc.h -- CRC32 calculation +2008-03-13 +Igor Pavlov +Public domain */ + +#ifndef __7Z_CRC_H +#define __7Z_CRC_H + +#include + +#include "Types.h" + +extern UInt32 g_CrcTable[]; + +void MY_FAST_CALL CrcGenerateTable(void); + +#define CRC_INIT_VAL 0xFFFFFFFF +#define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF) +#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) + +UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size); +UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size); + +#endif diff --git a/extern/lzma/7zFile.c b/extern/lzma/7zFile.c new file mode 100644 index 00000000000..9a44c59ac0c --- /dev/null +++ b/extern/lzma/7zFile.c @@ -0,0 +1,263 @@ +/* 7zFile.c -- File IO +2008-11-22 : Igor Pavlov : Public domain */ + +#include "7zFile.h" + +#ifndef USE_WINDOWS_FILE + +#include + +#endif + +#ifdef USE_WINDOWS_FILE + +/* + ReadFile and WriteFile functions in Windows have BUG: + If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) + from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES + (Insufficient system resources exist to complete the requested service). + Probably in some version of Windows there are problems with other sizes: + for 32 MB (maybe also for 16 MB). + And message can be "Network connection was lost" +*/ + +#define kChunkSizeMax (1 << 22) + +#endif + +void File_Construct(CSzFile *p) +{ + #ifdef USE_WINDOWS_FILE + p->handle = INVALID_HANDLE_VALUE; + #else + p->file = NULL; + #endif +} + +static WRes File_Open(CSzFile *p, const char *name, int writeMode) +{ + #ifdef USE_WINDOWS_FILE + p->handle = CreateFileA(name, + writeMode ? GENERIC_WRITE : GENERIC_READ, + FILE_SHARE_READ, NULL, + writeMode ? CREATE_ALWAYS : OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); + return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError(); + #else + p->file = fopen(name, writeMode ? "wb+" : "rb"); + return (p->file != 0) ? 0 : errno; + #endif +} + +WRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); } +WRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); } + +WRes File_Close(CSzFile *p) +{ + #ifdef USE_WINDOWS_FILE + if (p->handle != INVALID_HANDLE_VALUE) + { + if (!CloseHandle(p->handle)) + return GetLastError(); + p->handle = INVALID_HANDLE_VALUE; + } + #else + if (p->file != NULL) + { + int res = fclose(p->file); + if (res != 0) + return res; + p->file = NULL; + } + #endif + return 0; +} + +WRes File_Read(CSzFile *p, void *data, size_t *size) +{ + size_t originalSize = *size; + if (originalSize == 0) + return 0; + + #ifdef USE_WINDOWS_FILE + + *size = 0; + do + { + DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize; + DWORD processed = 0; + BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL); + data = (void *)((Byte *)data + processed); + originalSize -= processed; + *size += processed; + if (!res) + return GetLastError(); + if (processed == 0) + break; + } + while (originalSize > 0); + return 0; + + #else + + *size = fread(data, 1, originalSize, p->file); + if (*size == originalSize) + return 0; + return ferror(p->file); + + #endif +} + +WRes File_Write(CSzFile *p, const void *data, size_t *size) +{ + size_t originalSize = *size; + if (originalSize == 0) + return 0; + + #ifdef USE_WINDOWS_FILE + + *size = 0; + do + { + DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize; + DWORD processed = 0; + BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL); + data = (void *)((Byte *)data + processed); + originalSize -= processed; + *size += processed; + if (!res) + return GetLastError(); + if (processed == 0) + break; + } + while (originalSize > 0); + return 0; + + #else + + *size = fwrite(data, 1, originalSize, p->file); + if (*size == originalSize) + return 0; + return ferror(p->file); + + #endif +} + +WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin) +{ + #ifdef USE_WINDOWS_FILE + + LARGE_INTEGER value; + DWORD moveMethod; + value.LowPart = (DWORD)*pos; + value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */ + switch (origin) + { + case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break; + case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break; + case SZ_SEEK_END: moveMethod = FILE_END; break; + default: return ERROR_INVALID_PARAMETER; + } + value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod); + if (value.LowPart == 0xFFFFFFFF) + { + WRes res = GetLastError(); + if (res != NO_ERROR) + return res; + } + *pos = ((Int64)value.HighPart << 32) | value.LowPart; + return 0; + + #else + + int moveMethod; + int res; + switch (origin) + { + case SZ_SEEK_SET: moveMethod = SEEK_SET; break; + case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break; + case SZ_SEEK_END: moveMethod = SEEK_END; break; + default: return 1; + } + res = fseek(p->file, (long)*pos, moveMethod); + *pos = ftell(p->file); + return res; + + #endif +} + +WRes File_GetLength(CSzFile *p, UInt64 *length) +{ + #ifdef USE_WINDOWS_FILE + + DWORD sizeHigh; + DWORD sizeLow = GetFileSize(p->handle, &sizeHigh); + if (sizeLow == 0xFFFFFFFF) + { + DWORD res = GetLastError(); + if (res != NO_ERROR) + return res; + } + *length = (((UInt64)sizeHigh) << 32) + sizeLow; + return 0; + + #else + + long pos = ftell(p->file); + int res = fseek(p->file, 0, SEEK_END); + *length = ftell(p->file); + fseek(p->file, pos, SEEK_SET); + return res; + + #endif +} + + +/* ---------- FileSeqInStream ---------- */ + +static SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size) +{ + CFileSeqInStream *p = (CFileSeqInStream *)pp; + return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ; +} + +void FileSeqInStream_CreateVTable(CFileSeqInStream *p) +{ + p->s.Read = FileSeqInStream_Read; +} + + +/* ---------- FileInStream ---------- */ + +static SRes FileInStream_Read(void *pp, void *buf, size_t *size) +{ + CFileInStream *p = (CFileInStream *)pp; + return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ; +} + +static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin) +{ + CFileInStream *p = (CFileInStream *)pp; + return File_Seek(&p->file, pos, origin); +} + +void FileInStream_CreateVTable(CFileInStream *p) +{ + p->s.Read = FileInStream_Read; + p->s.Seek = FileInStream_Seek; +} + + +/* ---------- FileOutStream ---------- */ + +static size_t FileOutStream_Write(void *pp, const void *data, size_t size) +{ + CFileOutStream *p = (CFileOutStream *)pp; + File_Write(&p->file, data, &size); + return size; +} + +void FileOutStream_CreateVTable(CFileOutStream *p) +{ + p->s.Write = FileOutStream_Write; +} diff --git a/extern/lzma/7zFile.h b/extern/lzma/7zFile.h new file mode 100644 index 00000000000..fbef6837f86 --- /dev/null +++ b/extern/lzma/7zFile.h @@ -0,0 +1,74 @@ +/* 7zFile.h -- File IO +2008-11-22 : Igor Pavlov : Public domain */ + +#ifndef __7Z_FILE_H +#define __7Z_FILE_H + +#ifdef _WIN32 +#define USE_WINDOWS_FILE +#endif + +#ifdef USE_WINDOWS_FILE +#include +#else +#include +#endif + +#include "Types.h" + + +/* ---------- File ---------- */ + +typedef struct +{ + #ifdef USE_WINDOWS_FILE + HANDLE handle; + #else + FILE *file; + #endif +} CSzFile; + +void File_Construct(CSzFile *p); +WRes InFile_Open(CSzFile *p, const char *name); +WRes OutFile_Open(CSzFile *p, const char *name); +WRes File_Close(CSzFile *p); + +/* reads max(*size, remain file's size) bytes */ +WRes File_Read(CSzFile *p, void *data, size_t *size); + +/* writes *size bytes */ +WRes File_Write(CSzFile *p, const void *data, size_t *size); + +WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin); +WRes File_GetLength(CSzFile *p, UInt64 *length); + + +/* ---------- FileInStream ---------- */ + +typedef struct +{ + ISeqInStream s; + CSzFile file; +} CFileSeqInStream; + +void FileSeqInStream_CreateVTable(CFileSeqInStream *p); + + +typedef struct +{ + ISeekInStream s; + CSzFile file; +} CFileInStream; + +void FileInStream_CreateVTable(CFileInStream *p); + + +typedef struct +{ + ISeqOutStream s; + CSzFile file; +} CFileOutStream; + +void FileOutStream_CreateVTable(CFileOutStream *p); + +#endif diff --git a/extern/lzma/7zStream.c b/extern/lzma/7zStream.c new file mode 100644 index 00000000000..86232aa3411 --- /dev/null +++ b/extern/lzma/7zStream.c @@ -0,0 +1,169 @@ +/* 7zStream.c -- 7z Stream functions +2008-11-23 : Igor Pavlov : Public domain */ + +#include + +#include "Types.h" + +SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType) +{ + while (size != 0) + { + size_t processed = size; + RINOK(stream->Read(stream, buf, &processed)); + if (processed == 0) + return errorType; + buf = (void *)((Byte *)buf + processed); + size -= processed; + } + return SZ_OK; +} + +SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size) +{ + return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); +} + +SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf) +{ + size_t processed = 1; + RINOK(stream->Read(stream, buf, &processed)); + return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF; +} + +SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset) +{ + Int64 t = offset; + return stream->Seek(stream, &t, SZ_SEEK_SET); +} + +SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size) +{ + void *lookBuf; + if (*size == 0) + return SZ_OK; + RINOK(stream->Look(stream, &lookBuf, size)); + memcpy(buf, lookBuf, *size); + return stream->Skip(stream, *size); +} + +SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType) +{ + while (size != 0) + { + size_t processed = size; + RINOK(stream->Read(stream, buf, &processed)); + if (processed == 0) + return errorType; + buf = (void *)((Byte *)buf + processed); + size -= processed; + } + return SZ_OK; +} + +SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size) +{ + return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); +} + +static SRes LookToRead_Look_Lookahead(void *pp, void **buf, size_t *size) +{ + SRes res = SZ_OK; + CLookToRead *p = (CLookToRead *)pp; + size_t size2 = p->size - p->pos; + if (size2 == 0 && *size > 0) + { + p->pos = 0; + size2 = LookToRead_BUF_SIZE; + res = p->realStream->Read(p->realStream, p->buf, &size2); + p->size = size2; + } + if (size2 < *size) + *size = size2; + *buf = p->buf + p->pos; + return res; +} + +static SRes LookToRead_Look_Exact(void *pp, void **buf, size_t *size) +{ + SRes res = SZ_OK; + CLookToRead *p = (CLookToRead *)pp; + size_t size2 = p->size - p->pos; + if (size2 == 0 && *size > 0) + { + p->pos = 0; + if (*size > LookToRead_BUF_SIZE) + *size = LookToRead_BUF_SIZE; + res = p->realStream->Read(p->realStream, p->buf, size); + size2 = p->size = *size; + } + if (size2 < *size) + *size = size2; + *buf = p->buf + p->pos; + return res; +} + +static SRes LookToRead_Skip(void *pp, size_t offset) +{ + CLookToRead *p = (CLookToRead *)pp; + p->pos += offset; + return SZ_OK; +} + +static SRes LookToRead_Read(void *pp, void *buf, size_t *size) +{ + CLookToRead *p = (CLookToRead *)pp; + size_t rem = p->size - p->pos; + if (rem == 0) + return p->realStream->Read(p->realStream, buf, size); + if (rem > *size) + rem = *size; + memcpy(buf, p->buf + p->pos, rem); + p->pos += rem; + *size = rem; + return SZ_OK; +} + +static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin) +{ + CLookToRead *p = (CLookToRead *)pp; + p->pos = p->size = 0; + return p->realStream->Seek(p->realStream, pos, origin); +} + +void LookToRead_CreateVTable(CLookToRead *p, int lookahead) +{ + p->s.Look = lookahead ? + LookToRead_Look_Lookahead : + LookToRead_Look_Exact; + p->s.Skip = LookToRead_Skip; + p->s.Read = LookToRead_Read; + p->s.Seek = LookToRead_Seek; +} + +void LookToRead_Init(CLookToRead *p) +{ + p->pos = p->size = 0; +} + +static SRes SecToLook_Read(void *pp, void *buf, size_t *size) +{ + CSecToLook *p = (CSecToLook *)pp; + return LookInStream_LookRead(p->realStream, buf, size); +} + +void SecToLook_CreateVTable(CSecToLook *p) +{ + p->s.Read = SecToLook_Read; +} + +static SRes SecToRead_Read(void *pp, void *buf, size_t *size) +{ + CSecToRead *p = (CSecToRead *)pp; + return p->realStream->Read(p->realStream, buf, size); +} + +void SecToRead_CreateVTable(CSecToRead *p) +{ + p->s.Read = SecToRead_Read; +} diff --git a/extern/lzma/7zVersion.h b/extern/lzma/7zVersion.h new file mode 100644 index 00000000000..b7eb235548f --- /dev/null +++ b/extern/lzma/7zVersion.h @@ -0,0 +1,7 @@ +#define MY_VER_MAJOR 4 +#define MY_VER_MINOR 65 +#define MY_VER_BUILD 0 +#define MY_VERSION "4.65" +#define MY_DATE "2009-02-03" +#define MY_COPYRIGHT ": Igor Pavlov : Public domain" +#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE diff --git a/extern/lzma/Alloc.c b/extern/lzma/Alloc.c new file mode 100644 index 00000000000..358a7b52650 --- /dev/null +++ b/extern/lzma/Alloc.c @@ -0,0 +1,127 @@ +/* Alloc.c -- Memory allocation functions +2008-09-24 +Igor Pavlov +Public domain */ + +#ifdef _WIN32 +#include +#endif +#include + +#include "Alloc.h" + +/* #define _SZ_ALLOC_DEBUG */ + +/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */ +#ifdef _SZ_ALLOC_DEBUG +#include +int g_allocCount = 0; +int g_allocCountMid = 0; +int g_allocCountBig = 0; +#endif + +void *MyAlloc(size_t size) +{ + if (size == 0) + return 0; + #ifdef _SZ_ALLOC_DEBUG + { + void *p = malloc(size); + fprintf(stderr, "\nAlloc %10d bytes, count = %10d, addr = %8X", size, g_allocCount++, (unsigned)p); + return p; + } + #else + return malloc(size); + #endif +} + +void MyFree(void *address) +{ + #ifdef _SZ_ALLOC_DEBUG + if (address != 0) + fprintf(stderr, "\nFree; count = %10d, addr = %8X", --g_allocCount, (unsigned)address); + #endif + free(address); +} + +#ifdef _WIN32 + +void *MidAlloc(size_t size) +{ + if (size == 0) + return 0; + #ifdef _SZ_ALLOC_DEBUG + fprintf(stderr, "\nAlloc_Mid %10d bytes; count = %10d", size, g_allocCountMid++); + #endif + return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE); +} + +void MidFree(void *address) +{ + #ifdef _SZ_ALLOC_DEBUG + if (address != 0) + fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid); + #endif + if (address == 0) + return; + VirtualFree(address, 0, MEM_RELEASE); +} + +#ifndef MEM_LARGE_PAGES +#undef _7ZIP_LARGE_PAGES +#endif + +#ifdef _7ZIP_LARGE_PAGES +SIZE_T g_LargePageSize = 0; +typedef SIZE_T (WINAPI *GetLargePageMinimumP)(); +#endif + +void SetLargePageSize() +{ + #ifdef _7ZIP_LARGE_PAGES + SIZE_T size = 0; + GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP) + GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum"); + if (largePageMinimum == 0) + return; + size = largePageMinimum(); + if (size == 0 || (size & (size - 1)) != 0) + return; + g_LargePageSize = size; + #endif +} + + +void *BigAlloc(size_t size) +{ + if (size == 0) + return 0; + #ifdef _SZ_ALLOC_DEBUG + fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++); + #endif + + #ifdef _7ZIP_LARGE_PAGES + if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18)) + { + void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), + MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE); + if (res != 0) + return res; + } + #endif + return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE); +} + +void BigFree(void *address) +{ + #ifdef _SZ_ALLOC_DEBUG + if (address != 0) + fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig); + #endif + + if (address == 0) + return; + VirtualFree(address, 0, MEM_RELEASE); +} + +#endif diff --git a/extern/lzma/Alloc.h b/extern/lzma/Alloc.h new file mode 100644 index 00000000000..ff0669cad8d --- /dev/null +++ b/extern/lzma/Alloc.h @@ -0,0 +1,32 @@ +/* Alloc.h -- Memory allocation functions +2008-03-13 +Igor Pavlov +Public domain */ + +#ifndef __COMMON_ALLOC_H +#define __COMMON_ALLOC_H + +#include + +void *MyAlloc(size_t size); +void MyFree(void *address); + +#ifdef _WIN32 + +void SetLargePageSize(); + +void *MidAlloc(size_t size); +void MidFree(void *address); +void *BigAlloc(size_t size); +void BigFree(void *address); + +#else + +#define MidAlloc(size) MyAlloc(size) +#define MidFree(address) MyFree(address) +#define BigAlloc(size) MyAlloc(size) +#define BigFree(address) MyFree(address) + +#endif + +#endif diff --git a/extern/lzma/Bcj2.c b/extern/lzma/Bcj2.c new file mode 100644 index 00000000000..20199ce5659 --- /dev/null +++ b/extern/lzma/Bcj2.c @@ -0,0 +1,132 @@ +/* Bcj2.c -- Converter for x86 code (BCJ2) +2008-10-04 : Igor Pavlov : Public domain */ + +#include "Bcj2.h" + +#ifdef _LZMA_PROB32 +#define CProb UInt32 +#else +#define CProb UInt16 +#endif + +#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80) +#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)) + +#define kNumTopBits 24 +#define kTopValue ((UInt32)1 << kNumTopBits) + +#define kNumBitModelTotalBits 11 +#define kBitModelTotal (1 << kNumBitModelTotalBits) +#define kNumMoveBits 5 + +#define RC_READ_BYTE (*buffer++) +#define RC_TEST { if (buffer == bufferLim) return SZ_ERROR_DATA; } +#define RC_INIT2 code = 0; range = 0xFFFFFFFF; \ + { int i; for (i = 0; i < 5; i++) { RC_TEST; code = (code << 8) | RC_READ_BYTE; }} + +#define NORMALIZE if (range < kTopValue) { RC_TEST; range <<= 8; code = (code << 8) | RC_READ_BYTE; } + +#define IF_BIT_0(p) ttt = *(p); bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound) +#define UPDATE_0(p) range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE; +#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE; + +int Bcj2_Decode( + const Byte *buf0, SizeT size0, + const Byte *buf1, SizeT size1, + const Byte *buf2, SizeT size2, + const Byte *buf3, SizeT size3, + Byte *outBuf, SizeT outSize) +{ + CProb p[256 + 2]; + SizeT inPos = 0, outPos = 0; + + const Byte *buffer, *bufferLim; + UInt32 range, code; + Byte prevByte = 0; + + unsigned int i; + for (i = 0; i < sizeof(p) / sizeof(p[0]); i++) + p[i] = kBitModelTotal >> 1; + + buffer = buf3; + bufferLim = buffer + size3; + RC_INIT2 + + if (outSize == 0) + return SZ_OK; + + for (;;) + { + Byte b; + CProb *prob; + UInt32 bound; + UInt32 ttt; + + SizeT limit = size0 - inPos; + if (outSize - outPos < limit) + limit = outSize - outPos; + while (limit != 0) + { + Byte b = buf0[inPos]; + outBuf[outPos++] = b; + if (IsJ(prevByte, b)) + break; + inPos++; + prevByte = b; + limit--; + } + + if (limit == 0 || outPos == outSize) + break; + + b = buf0[inPos++]; + + if (b == 0xE8) + prob = p + prevByte; + else if (b == 0xE9) + prob = p + 256; + else + prob = p + 257; + + IF_BIT_0(prob) + { + UPDATE_0(prob) + prevByte = b; + } + else + { + UInt32 dest; + const Byte *v; + UPDATE_1(prob) + if (b == 0xE8) + { + v = buf1; + if (size1 < 4) + return SZ_ERROR_DATA; + buf1 += 4; + size1 -= 4; + } + else + { + v = buf2; + if (size2 < 4) + return SZ_ERROR_DATA; + buf2 += 4; + size2 -= 4; + } + dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) | + ((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4); + outBuf[outPos++] = (Byte)dest; + if (outPos == outSize) + break; + outBuf[outPos++] = (Byte)(dest >> 8); + if (outPos == outSize) + break; + outBuf[outPos++] = (Byte)(dest >> 16); + if (outPos == outSize) + break; + outBuf[outPos++] = prevByte = (Byte)(dest >> 24); + } + } + return (outPos == outSize) ? SZ_OK : SZ_ERROR_DATA; +} diff --git a/extern/lzma/Bcj2.h b/extern/lzma/Bcj2.h new file mode 100644 index 00000000000..32d450b3b99 --- /dev/null +++ b/extern/lzma/Bcj2.h @@ -0,0 +1,30 @@ +/* Bcj2.h -- Converter for x86 code (BCJ2) +2008-10-04 : Igor Pavlov : Public domain */ + +#ifndef __BCJ2_H +#define __BCJ2_H + +#include "Types.h" + +/* +Conditions: + outSize <= FullOutputSize, + where FullOutputSize is full size of output stream of x86_2 filter. + +If buf0 overlaps outBuf, there are two required conditions: + 1) (buf0 >= outBuf) + 2) (buf0 + size0 >= outBuf + FullOutputSize). + +Returns: + SZ_OK + SZ_ERROR_DATA - Data error +*/ + +int Bcj2_Decode( + const Byte *buf0, SizeT size0, + const Byte *buf1, SizeT size1, + const Byte *buf2, SizeT size2, + const Byte *buf3, SizeT size3, + Byte *outBuf, SizeT outSize); + +#endif diff --git a/extern/lzma/Bra.c b/extern/lzma/Bra.c new file mode 100644 index 00000000000..5e5469592db --- /dev/null +++ b/extern/lzma/Bra.c @@ -0,0 +1,133 @@ +/* Bra.c -- Converters for RISC code +2008-10-04 : Igor Pavlov : Public domain */ + +#include "Bra.h" + +SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) +{ + SizeT i; + if (size < 4) + return 0; + size -= 4; + ip += 8; + for (i = 0; i <= size; i += 4) + { + if (data[i + 3] == 0xEB) + { + UInt32 dest; + UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]); + src <<= 2; + if (encoding) + dest = ip + (UInt32)i + src; + else + dest = src - (ip + (UInt32)i); + dest >>= 2; + data[i + 2] = (Byte)(dest >> 16); + data[i + 1] = (Byte)(dest >> 8); + data[i + 0] = (Byte)dest; + } + } + return i; +} + +SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) +{ + SizeT i; + if (size < 4) + return 0; + size -= 4; + ip += 4; + for (i = 0; i <= size; i += 2) + { + if ((data[i + 1] & 0xF8) == 0xF0 && + (data[i + 3] & 0xF8) == 0xF8) + { + UInt32 dest; + UInt32 src = + (((UInt32)data[i + 1] & 0x7) << 19) | + ((UInt32)data[i + 0] << 11) | + (((UInt32)data[i + 3] & 0x7) << 8) | + (data[i + 2]); + + src <<= 1; + if (encoding) + dest = ip + (UInt32)i + src; + else + dest = src - (ip + (UInt32)i); + dest >>= 1; + + data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7)); + data[i + 0] = (Byte)(dest >> 11); + data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7)); + data[i + 2] = (Byte)dest; + i += 2; + } + } + return i; +} + +SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) +{ + SizeT i; + if (size < 4) + return 0; + size -= 4; + for (i = 0; i <= size; i += 4) + { + if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1) + { + UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) | + ((UInt32)data[i + 1] << 16) | + ((UInt32)data[i + 2] << 8) | + ((UInt32)data[i + 3] & (~3)); + + UInt32 dest; + if (encoding) + dest = ip + (UInt32)i + src; + else + dest = src - (ip + (UInt32)i); + data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3)); + data[i + 1] = (Byte)(dest >> 16); + data[i + 2] = (Byte)(dest >> 8); + data[i + 3] &= 0x3; + data[i + 3] |= dest; + } + } + return i; +} + +SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) +{ + UInt32 i; + if (size < 4) + return 0; + size -= 4; + for (i = 0; i <= size; i += 4) + { + if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 || + data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0) + { + UInt32 src = + ((UInt32)data[i + 0] << 24) | + ((UInt32)data[i + 1] << 16) | + ((UInt32)data[i + 2] << 8) | + ((UInt32)data[i + 3]); + UInt32 dest; + + src <<= 2; + if (encoding) + dest = ip + i + src; + else + dest = src - (ip + i); + dest >>= 2; + + dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000; + + data[i + 0] = (Byte)(dest >> 24); + data[i + 1] = (Byte)(dest >> 16); + data[i + 2] = (Byte)(dest >> 8); + data[i + 3] = (Byte)dest; + } + } + return i; +} diff --git a/extern/lzma/Bra.h b/extern/lzma/Bra.h new file mode 100644 index 00000000000..45e231e8496 --- /dev/null +++ b/extern/lzma/Bra.h @@ -0,0 +1,60 @@ +/* Bra.h -- Branch converters for executables +2008-10-04 : Igor Pavlov : Public domain */ + +#ifndef __BRA_H +#define __BRA_H + +#include "Types.h" + +/* +These functions convert relative addresses to absolute addresses +in CALL instructions to increase the compression ratio. + + In: + data - data buffer + size - size of data + ip - current virtual Instruction Pinter (IP) value + state - state variable for x86 converter + encoding - 0 (for decoding), 1 (for encoding) + + Out: + state - state variable for x86 converter + + Returns: + The number of processed bytes. If you call these functions with multiple calls, + you must start next call with first byte after block of processed bytes. + + Type Endian Alignment LookAhead + + x86 little 1 4 + ARMT little 2 2 + ARM little 4 0 + PPC big 4 0 + SPARC big 4 0 + IA64 little 16 0 + + size must be >= Alignment + LookAhead, if it's not last block. + If (size < Alignment + LookAhead), converter returns 0. + + Example: + + UInt32 ip = 0; + for () + { + ; size must be >= Alignment + LookAhead, if it's not last block + SizeT processed = Convert(data, size, ip, 1); + data += processed; + size -= processed; + ip += processed; + } +*/ + +#define x86_Convert_Init(state) { state = 0; } +SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding); +SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); +SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); +SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); +SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); +SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); + +#endif diff --git a/extern/lzma/Bra86.c b/extern/lzma/Bra86.c new file mode 100644 index 00000000000..1ee0e709b88 --- /dev/null +++ b/extern/lzma/Bra86.c @@ -0,0 +1,85 @@ +/* Bra86.c -- Converter for x86 code (BCJ) +2008-10-04 : Igor Pavlov : Public domain */ + +#include "Bra.h" + +#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF) + +const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0}; +const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3}; + +SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding) +{ + SizeT bufferPos = 0, prevPosT; + UInt32 prevMask = *state & 0x7; + if (size < 5) + return 0; + ip += 5; + prevPosT = (SizeT)0 - 1; + + for (;;) + { + Byte *p = data + bufferPos; + Byte *limit = data + size - 4; + for (; p < limit; p++) + if ((*p & 0xFE) == 0xE8) + break; + bufferPos = (SizeT)(p - data); + if (p >= limit) + break; + prevPosT = bufferPos - prevPosT; + if (prevPosT > 3) + prevMask = 0; + else + { + prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7; + if (prevMask != 0) + { + Byte b = p[4 - kMaskToBitNumber[prevMask]]; + if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b)) + { + prevPosT = bufferPos; + prevMask = ((prevMask << 1) & 0x7) | 1; + bufferPos++; + continue; + } + } + } + prevPosT = bufferPos; + + if (Test86MSByte(p[4])) + { + UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]); + UInt32 dest; + for (;;) + { + Byte b; + int index; + if (encoding) + dest = (ip + (UInt32)bufferPos) + src; + else + dest = src - (ip + (UInt32)bufferPos); + if (prevMask == 0) + break; + index = kMaskToBitNumber[prevMask] * 8; + b = (Byte)(dest >> (24 - index)); + if (!Test86MSByte(b)) + break; + src = dest ^ ((1 << (32 - index)) - 1); + } + p[4] = (Byte)(~(((dest >> 24) & 1) - 1)); + p[3] = (Byte)(dest >> 16); + p[2] = (Byte)(dest >> 8); + p[1] = (Byte)dest; + bufferPos += 5; + } + else + { + prevMask = ((prevMask << 1) & 0x7) | 1; + bufferPos++; + } + } + prevPosT = bufferPos - prevPosT; + *state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7)); + return bufferPos; +} diff --git a/extern/lzma/BraIA64.c b/extern/lzma/BraIA64.c new file mode 100644 index 00000000000..0b4ee85bc76 --- /dev/null +++ b/extern/lzma/BraIA64.c @@ -0,0 +1,67 @@ +/* BraIA64.c -- Converter for IA-64 code +2008-10-04 : Igor Pavlov : Public domain */ + +#include "Bra.h" + +static const Byte kBranchTable[32] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 4, 4, 6, 6, 0, 0, 7, 7, + 4, 4, 0, 0, 4, 4, 0, 0 +}; + +SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) +{ + SizeT i; + if (size < 16) + return 0; + size -= 16; + for (i = 0; i <= size; i += 16) + { + UInt32 instrTemplate = data[i] & 0x1F; + UInt32 mask = kBranchTable[instrTemplate]; + UInt32 bitPos = 5; + int slot; + for (slot = 0; slot < 3; slot++, bitPos += 41) + { + UInt32 bytePos, bitRes; + UInt64 instruction, instNorm; + int j; + if (((mask >> slot) & 1) == 0) + continue; + bytePos = (bitPos >> 3); + bitRes = bitPos & 0x7; + instruction = 0; + for (j = 0; j < 6; j++) + instruction += (UInt64)data[i + j + bytePos] << (8 * j); + + instNorm = instruction >> bitRes; + if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0) + { + UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF); + UInt32 dest; + src |= ((UInt32)(instNorm >> 36) & 1) << 20; + + src <<= 4; + + if (encoding) + dest = ip + (UInt32)i + src; + else + dest = src - (ip + (UInt32)i); + + dest >>= 4; + + instNorm &= ~((UInt64)(0x8FFFFF) << 13); + instNorm |= ((UInt64)(dest & 0xFFFFF) << 13); + instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20)); + + instruction &= (1 << bitRes) - 1; + instruction |= (instNorm << bitRes); + for (j = 0; j < 6; j++) + data[i + j + bytePos] = (Byte)(instruction >> (8 * j)); + } + } + } + return i; +} diff --git a/extern/lzma/CMakeLists.txt b/extern/lzma/CMakeLists.txt new file mode 100644 index 00000000000..235cd8c7f8e --- /dev/null +++ b/extern/lzma/CMakeLists.txt @@ -0,0 +1,34 @@ +# $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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# The Original Code is Copyright (C) 2006, Blender Foundation +# All rights reserved. +# +# The Original Code is: all of this file. +# +# Contributor(s): Daniel Genrich +# +# ***** END GPL LICENSE BLOCK ***** + +SET(INC . ) + +FILE(GLOB SRC ./*.c) + + + +BLENDERLIB(bf_lzma "${SRC}" "${INC}") +#, libtype='blender', priority = 0 ) diff --git a/extern/lzma/CpuArch.h b/extern/lzma/CpuArch.h new file mode 100644 index 00000000000..7384b0c32ae --- /dev/null +++ b/extern/lzma/CpuArch.h @@ -0,0 +1,69 @@ +/* CpuArch.h +2008-08-05 +Igor Pavlov +Public domain */ + +#ifndef __CPUARCH_H +#define __CPUARCH_H + +/* +LITTLE_ENDIAN_UNALIGN means: + 1) CPU is LITTLE_ENDIAN + 2) it's allowed to make unaligned memory accesses +if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know +about these properties of platform. +*/ + +#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__) +#define LITTLE_ENDIAN_UNALIGN +#endif + +#ifdef LITTLE_ENDIAN_UNALIGN + +#define GetUi16(p) (*(const UInt16 *)(p)) +#define GetUi32(p) (*(const UInt32 *)(p)) +#define GetUi64(p) (*(const UInt64 *)(p)) +#define SetUi32(p, d) *(UInt32 *)(p) = (d); + +#else + +#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8)) + +#define GetUi32(p) ( \ + ((const Byte *)(p))[0] | \ + ((UInt32)((const Byte *)(p))[1] << 8) | \ + ((UInt32)((const Byte *)(p))[2] << 16) | \ + ((UInt32)((const Byte *)(p))[3] << 24)) + +#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32)) + +#define SetUi32(p, d) { UInt32 _x_ = (d); \ + ((Byte *)(p))[0] = (Byte)_x_; \ + ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \ + ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \ + ((Byte *)(p))[3] = (Byte)(_x_ >> 24); } + +#endif + +#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300) + +#pragma intrinsic(_byteswap_ulong) +#pragma intrinsic(_byteswap_uint64) +#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p)) +#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p)) + +#else + +#define GetBe32(p) ( \ + ((UInt32)((const Byte *)(p))[0] << 24) | \ + ((UInt32)((const Byte *)(p))[1] << 16) | \ + ((UInt32)((const Byte *)(p))[2] << 8) | \ + ((const Byte *)(p))[3] ) + +#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4)) + +#endif + +#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1]) + +#endif diff --git a/extern/lzma/LzFind.c b/extern/lzma/LzFind.c new file mode 100644 index 00000000000..34f4f09ea58 --- /dev/null +++ b/extern/lzma/LzFind.c @@ -0,0 +1,751 @@ +/* LzFind.c -- Match finder for LZ algorithms +2008-10-04 : Igor Pavlov : Public domain */ + +#include + +#include "LzFind.h" +#include "LzHash.h" + +#define kEmptyHashValue 0 +#define kMaxValForNormalize ((UInt32)0xFFFFFFFF) +#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */ +#define kNormalizeMask (~(kNormalizeStepMin - 1)) +#define kMaxHistorySize ((UInt32)3 << 30) + +#define kStartMaxLen 3 + +static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc) +{ + if (!p->directInput) + { + alloc->Free(alloc, p->bufferBase); + p->bufferBase = 0; + } +} + +/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */ + +static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc) +{ + UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv; + if (p->directInput) + { + p->blockSize = blockSize; + return 1; + } + if (p->bufferBase == 0 || p->blockSize != blockSize) + { + LzInWindow_Free(p, alloc); + p->blockSize = blockSize; + p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize); + } + return (p->bufferBase != 0); +} + +Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; } +Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; } + +UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; } + +void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue) +{ + p->posLimit -= subValue; + p->pos -= subValue; + p->streamPos -= subValue; +} + +static void MatchFinder_ReadBlock(CMatchFinder *p) +{ + if (p->streamEndWasReached || p->result != SZ_OK) + return; + for (;;) + { + Byte *dest = p->buffer + (p->streamPos - p->pos); + size_t size = (p->bufferBase + p->blockSize - dest); + if (size == 0) + return; + p->result = p->stream->Read(p->stream, dest, &size); + if (p->result != SZ_OK) + return; + if (size == 0) + { + p->streamEndWasReached = 1; + return; + } + p->streamPos += (UInt32)size; + if (p->streamPos - p->pos > p->keepSizeAfter) + return; + } +} + +void MatchFinder_MoveBlock(CMatchFinder *p) +{ + memmove(p->bufferBase, + p->buffer - p->keepSizeBefore, + (size_t)(p->streamPos - p->pos + p->keepSizeBefore)); + p->buffer = p->bufferBase + p->keepSizeBefore; +} + +int MatchFinder_NeedMove(CMatchFinder *p) +{ + /* if (p->streamEndWasReached) return 0; */ + return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter); +} + +void MatchFinder_ReadIfRequired(CMatchFinder *p) +{ + if (p->streamEndWasReached) + return; + if (p->keepSizeAfter >= p->streamPos - p->pos) + MatchFinder_ReadBlock(p); +} + +static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p) +{ + if (MatchFinder_NeedMove(p)) + MatchFinder_MoveBlock(p); + MatchFinder_ReadBlock(p); +} + +static void MatchFinder_SetDefaultSettings(CMatchFinder *p) +{ + p->cutValue = 32; + p->btMode = 1; + p->numHashBytes = 4; + /* p->skipModeBits = 0; */ + p->directInput = 0; + p->bigHash = 0; +} + +#define kCrcPoly 0xEDB88320 + +void MatchFinder_Construct(CMatchFinder *p) +{ + UInt32 i; + p->bufferBase = 0; + p->directInput = 0; + p->hash = 0; + MatchFinder_SetDefaultSettings(p); + + for (i = 0; i < 256; i++) + { + UInt32 r = i; + int j; + for (j = 0; j < 8; j++) + r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1)); + p->crc[i] = r; + } +} + +static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc) +{ + alloc->Free(alloc, p->hash); + p->hash = 0; +} + +void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc) +{ + MatchFinder_FreeThisClassMemory(p, alloc); + LzInWindow_Free(p, alloc); +} + +static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc) +{ + size_t sizeInBytes = (size_t)num * sizeof(CLzRef); + if (sizeInBytes / sizeof(CLzRef) != num) + return 0; + return (CLzRef *)alloc->Alloc(alloc, sizeInBytes); +} + +int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, + UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, + ISzAlloc *alloc) +{ + UInt32 sizeReserv; + if (historySize > kMaxHistorySize) + { + MatchFinder_Free(p, alloc); + return 0; + } + sizeReserv = historySize >> 1; + if (historySize > ((UInt32)2 << 30)) + sizeReserv = historySize >> 2; + sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19); + + p->keepSizeBefore = historySize + keepAddBufferBefore + 1; + p->keepSizeAfter = matchMaxLen + keepAddBufferAfter; + /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */ + if (LzInWindow_Create(p, sizeReserv, alloc)) + { + UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1; + UInt32 hs; + p->matchMaxLen = matchMaxLen; + { + p->fixedHashSize = 0; + if (p->numHashBytes == 2) + hs = (1 << 16) - 1; + else + { + hs = historySize - 1; + hs |= (hs >> 1); + hs |= (hs >> 2); + hs |= (hs >> 4); + hs |= (hs >> 8); + hs >>= 1; + /* hs >>= p->skipModeBits; */ + hs |= 0xFFFF; /* don't change it! It's required for Deflate */ + if (hs > (1 << 24)) + { + if (p->numHashBytes == 3) + hs = (1 << 24) - 1; + else + hs >>= 1; + } + } + p->hashMask = hs; + hs++; + if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size; + if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size; + if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size; + hs += p->fixedHashSize; + } + + { + UInt32 prevSize = p->hashSizeSum + p->numSons; + UInt32 newSize; + p->historySize = historySize; + p->hashSizeSum = hs; + p->cyclicBufferSize = newCyclicBufferSize; + p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize); + newSize = p->hashSizeSum + p->numSons; + if (p->hash != 0 && prevSize == newSize) + return 1; + MatchFinder_FreeThisClassMemory(p, alloc); + p->hash = AllocRefs(newSize, alloc); + if (p->hash != 0) + { + p->son = p->hash + p->hashSizeSum; + return 1; + } + } + } + MatchFinder_Free(p, alloc); + return 0; +} + +static void MatchFinder_SetLimits(CMatchFinder *p) +{ + UInt32 limit = kMaxValForNormalize - p->pos; + UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos; + if (limit2 < limit) + limit = limit2; + limit2 = p->streamPos - p->pos; + if (limit2 <= p->keepSizeAfter) + { + if (limit2 > 0) + limit2 = 1; + } + else + limit2 -= p->keepSizeAfter; + if (limit2 < limit) + limit = limit2; + { + UInt32 lenLimit = p->streamPos - p->pos; + if (lenLimit > p->matchMaxLen) + lenLimit = p->matchMaxLen; + p->lenLimit = lenLimit; + } + p->posLimit = p->pos + limit; +} + +void MatchFinder_Init(CMatchFinder *p) +{ + UInt32 i; + for (i = 0; i < p->hashSizeSum; i++) + p->hash[i] = kEmptyHashValue; + p->cyclicBufferPos = 0; + p->buffer = p->bufferBase; + p->pos = p->streamPos = p->cyclicBufferSize; + p->result = SZ_OK; + p->streamEndWasReached = 0; + MatchFinder_ReadBlock(p); + MatchFinder_SetLimits(p); +} + +static UInt32 MatchFinder_GetSubValue(CMatchFinder *p) +{ + return (p->pos - p->historySize - 1) & kNormalizeMask; +} + +void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems) +{ + UInt32 i; + for (i = 0; i < numItems; i++) + { + UInt32 value = items[i]; + if (value <= subValue) + value = kEmptyHashValue; + else + value -= subValue; + items[i] = value; + } +} + +static void MatchFinder_Normalize(CMatchFinder *p) +{ + UInt32 subValue = MatchFinder_GetSubValue(p); + MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons); + MatchFinder_ReduceOffsets(p, subValue); +} + +static void MatchFinder_CheckLimits(CMatchFinder *p) +{ + if (p->pos == kMaxValForNormalize) + MatchFinder_Normalize(p); + if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos) + MatchFinder_CheckAndMoveAndRead(p); + if (p->cyclicBufferPos == p->cyclicBufferSize) + p->cyclicBufferPos = 0; + MatchFinder_SetLimits(p); +} + +static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, + UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue, + UInt32 *distances, UInt32 maxLen) +{ + son[_cyclicBufferPos] = curMatch; + for (;;) + { + UInt32 delta = pos - curMatch; + if (cutValue-- == 0 || delta >= _cyclicBufferSize) + return distances; + { + const Byte *pb = cur - delta; + curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)]; + if (pb[maxLen] == cur[maxLen] && *pb == *cur) + { + UInt32 len = 0; + while (++len != lenLimit) + if (pb[len] != cur[len]) + break; + if (maxLen < len) + { + *distances++ = maxLen = len; + *distances++ = delta - 1; + if (len == lenLimit) + return distances; + } + } + } + } +} + +UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, + UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue, + UInt32 *distances, UInt32 maxLen) +{ + CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1; + CLzRef *ptr1 = son + (_cyclicBufferPos << 1); + UInt32 len0 = 0, len1 = 0; + for (;;) + { + UInt32 delta = pos - curMatch; + if (cutValue-- == 0 || delta >= _cyclicBufferSize) + { + *ptr0 = *ptr1 = kEmptyHashValue; + return distances; + } + { + CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1); + const Byte *pb = cur - delta; + UInt32 len = (len0 < len1 ? len0 : len1); + if (pb[len] == cur[len]) + { + if (++len != lenLimit && pb[len] == cur[len]) + while (++len != lenLimit) + if (pb[len] != cur[len]) + break; + if (maxLen < len) + { + *distances++ = maxLen = len; + *distances++ = delta - 1; + if (len == lenLimit) + { + *ptr1 = pair[0]; + *ptr0 = pair[1]; + return distances; + } + } + } + if (pb[len] < cur[len]) + { + *ptr1 = curMatch; + ptr1 = pair + 1; + curMatch = *ptr1; + len1 = len; + } + else + { + *ptr0 = curMatch; + ptr0 = pair; + curMatch = *ptr0; + len0 = len; + } + } + } +} + +static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, + UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue) +{ + CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1; + CLzRef *ptr1 = son + (_cyclicBufferPos << 1); + UInt32 len0 = 0, len1 = 0; + for (;;) + { + UInt32 delta = pos - curMatch; + if (cutValue-- == 0 || delta >= _cyclicBufferSize) + { + *ptr0 = *ptr1 = kEmptyHashValue; + return; + } + { + CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1); + const Byte *pb = cur - delta; + UInt32 len = (len0 < len1 ? len0 : len1); + if (pb[len] == cur[len]) + { + while (++len != lenLimit) + if (pb[len] != cur[len]) + break; + { + if (len == lenLimit) + { + *ptr1 = pair[0]; + *ptr0 = pair[1]; + return; + } + } + } + if (pb[len] < cur[len]) + { + *ptr1 = curMatch; + ptr1 = pair + 1; + curMatch = *ptr1; + len1 = len; + } + else + { + *ptr0 = curMatch; + ptr0 = pair; + curMatch = *ptr0; + len0 = len; + } + } + } +} + +#define MOVE_POS \ + ++p->cyclicBufferPos; \ + p->buffer++; \ + if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p); + +#define MOVE_POS_RET MOVE_POS return offset; + +static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; } + +#define GET_MATCHES_HEADER2(minLen, ret_op) \ + UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \ + lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \ + cur = p->buffer; + +#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0) +#define SKIP_HEADER(minLen) GET_MATCHES_HEADER2(minLen, continue) + +#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue + +#define GET_MATCHES_FOOTER(offset, maxLen) \ + offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \ + distances + offset, maxLen) - distances); MOVE_POS_RET; + +#define SKIP_FOOTER \ + SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS; + +static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) +{ + UInt32 offset; + GET_MATCHES_HEADER(2) + HASH2_CALC; + curMatch = p->hash[hashValue]; + p->hash[hashValue] = p->pos; + offset = 0; + GET_MATCHES_FOOTER(offset, 1) +} + +UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) +{ + UInt32 offset; + GET_MATCHES_HEADER(3) + HASH_ZIP_CALC; + curMatch = p->hash[hashValue]; + p->hash[hashValue] = p->pos; + offset = 0; + GET_MATCHES_FOOTER(offset, 2) +} + +static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) +{ + UInt32 hash2Value, delta2, maxLen, offset; + GET_MATCHES_HEADER(3) + + HASH3_CALC; + + delta2 = p->pos - p->hash[hash2Value]; + curMatch = p->hash[kFix3HashSize + hashValue]; + + p->hash[hash2Value] = + p->hash[kFix3HashSize + hashValue] = p->pos; + + + maxLen = 2; + offset = 0; + if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur) + { + for (; maxLen != lenLimit; maxLen++) + if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen]) + break; + distances[0] = maxLen; + distances[1] = delta2 - 1; + offset = 2; + if (maxLen == lenLimit) + { + SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); + MOVE_POS_RET; + } + } + GET_MATCHES_FOOTER(offset, maxLen) +} + +static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) +{ + UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset; + GET_MATCHES_HEADER(4) + + HASH4_CALC; + + delta2 = p->pos - p->hash[ hash2Value]; + delta3 = p->pos - p->hash[kFix3HashSize + hash3Value]; + curMatch = p->hash[kFix4HashSize + hashValue]; + + p->hash[ hash2Value] = + p->hash[kFix3HashSize + hash3Value] = + p->hash[kFix4HashSize + hashValue] = p->pos; + + maxLen = 1; + offset = 0; + if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur) + { + distances[0] = maxLen = 2; + distances[1] = delta2 - 1; + offset = 2; + } + if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur) + { + maxLen = 3; + distances[offset + 1] = delta3 - 1; + offset += 2; + delta2 = delta3; + } + if (offset != 0) + { + for (; maxLen != lenLimit; maxLen++) + if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen]) + break; + distances[offset - 2] = maxLen; + if (maxLen == lenLimit) + { + SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); + MOVE_POS_RET; + } + } + if (maxLen < 3) + maxLen = 3; + GET_MATCHES_FOOTER(offset, maxLen) +} + +static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) +{ + UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset; + GET_MATCHES_HEADER(4) + + HASH4_CALC; + + delta2 = p->pos - p->hash[ hash2Value]; + delta3 = p->pos - p->hash[kFix3HashSize + hash3Value]; + curMatch = p->hash[kFix4HashSize + hashValue]; + + p->hash[ hash2Value] = + p->hash[kFix3HashSize + hash3Value] = + p->hash[kFix4HashSize + hashValue] = p->pos; + + maxLen = 1; + offset = 0; + if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur) + { + distances[0] = maxLen = 2; + distances[1] = delta2 - 1; + offset = 2; + } + if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur) + { + maxLen = 3; + distances[offset + 1] = delta3 - 1; + offset += 2; + delta2 = delta3; + } + if (offset != 0) + { + for (; maxLen != lenLimit; maxLen++) + if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen]) + break; + distances[offset - 2] = maxLen; + if (maxLen == lenLimit) + { + p->son[p->cyclicBufferPos] = curMatch; + MOVE_POS_RET; + } + } + if (maxLen < 3) + maxLen = 3; + offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), + distances + offset, maxLen) - (distances)); + MOVE_POS_RET +} + +UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) +{ + UInt32 offset; + GET_MATCHES_HEADER(3) + HASH_ZIP_CALC; + curMatch = p->hash[hashValue]; + p->hash[hashValue] = p->pos; + offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), + distances, 2) - (distances)); + MOVE_POS_RET +} + +static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num) +{ + do + { + SKIP_HEADER(2) + HASH2_CALC; + curMatch = p->hash[hashValue]; + p->hash[hashValue] = p->pos; + SKIP_FOOTER + } + while (--num != 0); +} + +void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) +{ + do + { + SKIP_HEADER(3) + HASH_ZIP_CALC; + curMatch = p->hash[hashValue]; + p->hash[hashValue] = p->pos; + SKIP_FOOTER + } + while (--num != 0); +} + +static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num) +{ + do + { + UInt32 hash2Value; + SKIP_HEADER(3) + HASH3_CALC; + curMatch = p->hash[kFix3HashSize + hashValue]; + p->hash[hash2Value] = + p->hash[kFix3HashSize + hashValue] = p->pos; + SKIP_FOOTER + } + while (--num != 0); +} + +static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) +{ + do + { + UInt32 hash2Value, hash3Value; + SKIP_HEADER(4) + HASH4_CALC; + curMatch = p->hash[kFix4HashSize + hashValue]; + p->hash[ hash2Value] = + p->hash[kFix3HashSize + hash3Value] = p->pos; + p->hash[kFix4HashSize + hashValue] = p->pos; + SKIP_FOOTER + } + while (--num != 0); +} + +static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) +{ + do + { + UInt32 hash2Value, hash3Value; + SKIP_HEADER(4) + HASH4_CALC; + curMatch = p->hash[kFix4HashSize + hashValue]; + p->hash[ hash2Value] = + p->hash[kFix3HashSize + hash3Value] = + p->hash[kFix4HashSize + hashValue] = p->pos; + p->son[p->cyclicBufferPos] = curMatch; + MOVE_POS + } + while (--num != 0); +} + +void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) +{ + do + { + SKIP_HEADER(3) + HASH_ZIP_CALC; + curMatch = p->hash[hashValue]; + p->hash[hashValue] = p->pos; + p->son[p->cyclicBufferPos] = curMatch; + MOVE_POS + } + while (--num != 0); +} + +void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable) +{ + vTable->Init = (Mf_Init_Func)MatchFinder_Init; + vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte; + vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes; + vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos; + if (!p->btMode) + { + vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches; + vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip; + } + else if (p->numHashBytes == 2) + { + vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches; + vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip; + } + else if (p->numHashBytes == 3) + { + vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches; + vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip; + } + else + { + vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches; + vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip; + } +} diff --git a/extern/lzma/LzFind.h b/extern/lzma/LzFind.h new file mode 100644 index 00000000000..5b9cebfdffe --- /dev/null +++ b/extern/lzma/LzFind.h @@ -0,0 +1,107 @@ +/* LzFind.h -- Match finder for LZ algorithms +2008-10-04 : Igor Pavlov : Public domain */ + +#ifndef __LZFIND_H +#define __LZFIND_H + +#include "Types.h" + +typedef UInt32 CLzRef; + +typedef struct _CMatchFinder +{ + Byte *buffer; + UInt32 pos; + UInt32 posLimit; + UInt32 streamPos; + UInt32 lenLimit; + + UInt32 cyclicBufferPos; + UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */ + + UInt32 matchMaxLen; + CLzRef *hash; + CLzRef *son; + UInt32 hashMask; + UInt32 cutValue; + + Byte *bufferBase; + ISeqInStream *stream; + int streamEndWasReached; + + UInt32 blockSize; + UInt32 keepSizeBefore; + UInt32 keepSizeAfter; + + UInt32 numHashBytes; + int directInput; + int btMode; + /* int skipModeBits; */ + int bigHash; + UInt32 historySize; + UInt32 fixedHashSize; + UInt32 hashSizeSum; + UInt32 numSons; + SRes result; + UInt32 crc[256]; +} CMatchFinder; + +#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer) +#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)]) + +#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos) + +int MatchFinder_NeedMove(CMatchFinder *p); +Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p); +void MatchFinder_MoveBlock(CMatchFinder *p); +void MatchFinder_ReadIfRequired(CMatchFinder *p); + +void MatchFinder_Construct(CMatchFinder *p); + +/* Conditions: + historySize <= 3 GB + keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB +*/ +int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, + UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, + ISzAlloc *alloc); +void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc); +void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems); +void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue); + +UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son, + UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, + UInt32 *distances, UInt32 maxLen); + +/* +Conditions: + Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func. + Mf_GetPointerToCurrentPos_Func's result must be used only before any other function +*/ + +typedef void (*Mf_Init_Func)(void *object); +typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index); +typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object); +typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object); +typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances); +typedef void (*Mf_Skip_Func)(void *object, UInt32); + +typedef struct _IMatchFinder +{ + Mf_Init_Func Init; + Mf_GetIndexByte_Func GetIndexByte; + Mf_GetNumAvailableBytes_Func GetNumAvailableBytes; + Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos; + Mf_GetMatches_Func GetMatches; + Mf_Skip_Func Skip; +} IMatchFinder; + +void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable); + +void MatchFinder_Init(CMatchFinder *p); +UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); +UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); +void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); +void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); + +#endif diff --git a/extern/lzma/LzFindMt.c b/extern/lzma/LzFindMt.c new file mode 100644 index 00000000000..b49cd76b294 --- /dev/null +++ b/extern/lzma/LzFindMt.c @@ -0,0 +1,793 @@ +/* LzFindMt.c -- multithreaded Match finder for LZ algorithms +2008-10-04 : Igor Pavlov : Public domain */ + +#include "LzHash.h" + +#include "LzFindMt.h" + +void MtSync_Construct(CMtSync *p) +{ + p->wasCreated = False; + p->csWasInitialized = False; + p->csWasEntered = False; + Thread_Construct(&p->thread); + Event_Construct(&p->canStart); + Event_Construct(&p->wasStarted); + Event_Construct(&p->wasStopped); + Semaphore_Construct(&p->freeSemaphore); + Semaphore_Construct(&p->filledSemaphore); +} + +void MtSync_GetNextBlock(CMtSync *p) +{ + if (p->needStart) + { + p->numProcessedBlocks = 1; + p->needStart = False; + p->stopWriting = False; + p->exit = False; + Event_Reset(&p->wasStarted); + Event_Reset(&p->wasStopped); + + Event_Set(&p->canStart); + Event_Wait(&p->wasStarted); + } + else + { + CriticalSection_Leave(&p->cs); + p->csWasEntered = False; + p->numProcessedBlocks++; + Semaphore_Release1(&p->freeSemaphore); + } + Semaphore_Wait(&p->filledSemaphore); + CriticalSection_Enter(&p->cs); + p->csWasEntered = True; +} + +/* MtSync_StopWriting must be called if Writing was started */ + +void MtSync_StopWriting(CMtSync *p) +{ + UInt32 myNumBlocks = p->numProcessedBlocks; + if (!Thread_WasCreated(&p->thread) || p->needStart) + return; + p->stopWriting = True; + if (p->csWasEntered) + { + CriticalSection_Leave(&p->cs); + p->csWasEntered = False; + } + Semaphore_Release1(&p->freeSemaphore); + + Event_Wait(&p->wasStopped); + + while (myNumBlocks++ != p->numProcessedBlocks) + { + Semaphore_Wait(&p->filledSemaphore); + Semaphore_Release1(&p->freeSemaphore); + } + p->needStart = True; +} + +void MtSync_Destruct(CMtSync *p) +{ + if (Thread_WasCreated(&p->thread)) + { + MtSync_StopWriting(p); + p->exit = True; + if (p->needStart) + Event_Set(&p->canStart); + Thread_Wait(&p->thread); + Thread_Close(&p->thread); + } + if (p->csWasInitialized) + { + CriticalSection_Delete(&p->cs); + p->csWasInitialized = False; + } + + Event_Close(&p->canStart); + Event_Close(&p->wasStarted); + Event_Close(&p->wasStopped); + Semaphore_Close(&p->freeSemaphore); + Semaphore_Close(&p->filledSemaphore); + + p->wasCreated = False; +} + +#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; } + +static SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks) +{ + if (p->wasCreated) + return SZ_OK; + + RINOK_THREAD(CriticalSection_Init(&p->cs)); + p->csWasInitialized = True; + + RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart)); + RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted)); + RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped)); + + RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks)); + RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks)); + + p->needStart = True; + + RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj)); + p->wasCreated = True; + return SZ_OK; +} + +static SRes MtSync_Create(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks) +{ + SRes res = MtSync_Create2(p, startAddress, obj, numBlocks); + if (res != SZ_OK) + MtSync_Destruct(p); + return res; +} + +void MtSync_Init(CMtSync *p) { p->needStart = True; } + +#define kMtMaxValForNormalize 0xFFFFFFFF + +#define DEF_GetHeads2(name, v, action) \ +static void GetHeads ## name(const Byte *p, UInt32 pos, \ +UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \ +{ action; for (; numHeads != 0; numHeads--) { \ +const UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++; } } + +#define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;) + +DEF_GetHeads2(2, (p[0] | ((UInt32)p[1] << 8)), hashMask = hashMask; crc = crc; ) +DEF_GetHeads(3, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask) +DEF_GetHeads(4, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask) +DEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask) +DEF_GetHeads(5, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask) + +void HashThreadFunc(CMatchFinderMt *mt) +{ + CMtSync *p = &mt->hashSync; + for (;;) + { + UInt32 numProcessedBlocks = 0; + Event_Wait(&p->canStart); + Event_Set(&p->wasStarted); + for (;;) + { + if (p->exit) + return; + if (p->stopWriting) + { + p->numProcessedBlocks = numProcessedBlocks; + Event_Set(&p->wasStopped); + break; + } + + { + CMatchFinder *mf = mt->MatchFinder; + if (MatchFinder_NeedMove(mf)) + { + CriticalSection_Enter(&mt->btSync.cs); + CriticalSection_Enter(&mt->hashSync.cs); + { + const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf); + const Byte *afterPtr; + MatchFinder_MoveBlock(mf); + afterPtr = MatchFinder_GetPointerToCurrentPos(mf); + mt->pointerToCurPos -= beforePtr - afterPtr; + mt->buffer -= beforePtr - afterPtr; + } + CriticalSection_Leave(&mt->btSync.cs); + CriticalSection_Leave(&mt->hashSync.cs); + continue; + } + + Semaphore_Wait(&p->freeSemaphore); + + MatchFinder_ReadIfRequired(mf); + if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize)) + { + UInt32 subValue = (mf->pos - mf->historySize - 1); + MatchFinder_ReduceOffsets(mf, subValue); + MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1); + } + { + UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize; + UInt32 num = mf->streamPos - mf->pos; + heads[0] = 2; + heads[1] = num; + if (num >= mf->numHashBytes) + { + num = num - mf->numHashBytes + 1; + if (num > kMtHashBlockSize - 2) + num = kMtHashBlockSize - 2; + mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc); + heads[0] += num; + } + mf->pos += num; + mf->buffer += num; + } + } + + Semaphore_Release1(&p->filledSemaphore); + } + } +} + +void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p) +{ + MtSync_GetNextBlock(&p->hashSync); + p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize; + p->hashBufPosLimit += p->hashBuf[p->hashBufPos++]; + p->hashNumAvail = p->hashBuf[p->hashBufPos++]; +} + +#define kEmptyHashValue 0 + +/* #define MFMT_GM_INLINE */ + +#ifdef MFMT_GM_INLINE + +#define NO_INLINE MY_FAST_CALL + +Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son, + UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, + UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes) +{ + do + { + UInt32 *distances = _distances + 1; + UInt32 curMatch = pos - *hash++; + + CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1; + CLzRef *ptr1 = son + (_cyclicBufferPos << 1); + UInt32 len0 = 0, len1 = 0; + UInt32 cutValue = _cutValue; + UInt32 maxLen = _maxLen; + for (;;) + { + UInt32 delta = pos - curMatch; + if (cutValue-- == 0 || delta >= _cyclicBufferSize) + { + *ptr0 = *ptr1 = kEmptyHashValue; + break; + } + { + CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1); + const Byte *pb = cur - delta; + UInt32 len = (len0 < len1 ? len0 : len1); + if (pb[len] == cur[len]) + { + if (++len != lenLimit && pb[len] == cur[len]) + while (++len != lenLimit) + if (pb[len] != cur[len]) + break; + if (maxLen < len) + { + *distances++ = maxLen = len; + *distances++ = delta - 1; + if (len == lenLimit) + { + *ptr1 = pair[0]; + *ptr0 = pair[1]; + break; + } + } + } + if (pb[len] < cur[len]) + { + *ptr1 = curMatch; + ptr1 = pair + 1; + curMatch = *ptr1; + len1 = len; + } + else + { + *ptr0 = curMatch; + ptr0 = pair; + curMatch = *ptr0; + len0 = len; + } + } + } + pos++; + _cyclicBufferPos++; + cur++; + { + UInt32 num = (UInt32)(distances - _distances); + *_distances = num - 1; + _distances += num; + limit -= num; + } + } + while (limit > 0 && --size != 0); + *posRes = pos; + return limit; +} + +#endif + +void BtGetMatches(CMatchFinderMt *p, UInt32 *distances) +{ + UInt32 numProcessed = 0; + UInt32 curPos = 2; + UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2); + distances[1] = p->hashNumAvail; + while (curPos < limit) + { + if (p->hashBufPos == p->hashBufPosLimit) + { + MatchFinderMt_GetNextBlock_Hash(p); + distances[1] = numProcessed + p->hashNumAvail; + if (p->hashNumAvail >= p->numHashBytes) + continue; + for (; p->hashNumAvail != 0; p->hashNumAvail--) + distances[curPos++] = 0; + break; + } + { + UInt32 size = p->hashBufPosLimit - p->hashBufPos; + UInt32 lenLimit = p->matchMaxLen; + UInt32 pos = p->pos; + UInt32 cyclicBufferPos = p->cyclicBufferPos; + if (lenLimit >= p->hashNumAvail) + lenLimit = p->hashNumAvail; + { + UInt32 size2 = p->hashNumAvail - lenLimit + 1; + if (size2 < size) + size = size2; + size2 = p->cyclicBufferSize - cyclicBufferPos; + if (size2 < size) + size = size2; + } + #ifndef MFMT_GM_INLINE + while (curPos < limit && size-- != 0) + { + UInt32 *startDistances = distances + curPos; + UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++], + pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue, + startDistances + 1, p->numHashBytes - 1) - startDistances); + *startDistances = num - 1; + curPos += num; + cyclicBufferPos++; + pos++; + p->buffer++; + } + #else + { + UInt32 posRes; + curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue, + distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes); + p->hashBufPos += posRes - pos; + cyclicBufferPos += posRes - pos; + p->buffer += posRes - pos; + pos = posRes; + } + #endif + + numProcessed += pos - p->pos; + p->hashNumAvail -= pos - p->pos; + p->pos = pos; + if (cyclicBufferPos == p->cyclicBufferSize) + cyclicBufferPos = 0; + p->cyclicBufferPos = cyclicBufferPos; + } + } + distances[0] = curPos; +} + +void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex) +{ + CMtSync *sync = &p->hashSync; + if (!sync->needStart) + { + CriticalSection_Enter(&sync->cs); + sync->csWasEntered = True; + } + + BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize); + + if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize) + { + UInt32 subValue = p->pos - p->cyclicBufferSize; + MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2); + p->pos -= subValue; + } + + if (!sync->needStart) + { + CriticalSection_Leave(&sync->cs); + sync->csWasEntered = False; + } +} + +void BtThreadFunc(CMatchFinderMt *mt) +{ + CMtSync *p = &mt->btSync; + for (;;) + { + UInt32 blockIndex = 0; + Event_Wait(&p->canStart); + Event_Set(&p->wasStarted); + for (;;) + { + if (p->exit) + return; + if (p->stopWriting) + { + p->numProcessedBlocks = blockIndex; + MtSync_StopWriting(&mt->hashSync); + Event_Set(&p->wasStopped); + break; + } + Semaphore_Wait(&p->freeSemaphore); + BtFillBlock(mt, blockIndex++); + Semaphore_Release1(&p->filledSemaphore); + } + } +} + +void MatchFinderMt_Construct(CMatchFinderMt *p) +{ + p->hashBuf = 0; + MtSync_Construct(&p->hashSync); + MtSync_Construct(&p->btSync); +} + +void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc) +{ + alloc->Free(alloc, p->hashBuf); + p->hashBuf = 0; +} + +void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc) +{ + MtSync_Destruct(&p->hashSync); + MtSync_Destruct(&p->btSync); + MatchFinderMt_FreeMem(p, alloc); +} + +#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks) +#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks) + +static unsigned MY_STD_CALL HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p); return 0; } +static unsigned MY_STD_CALL BtThreadFunc2(void *p) +{ + Byte allocaDummy[0x180]; + int i = 0; + for (i = 0; i < 16; i++) + allocaDummy[i] = (Byte)i; + BtThreadFunc((CMatchFinderMt *)p); + return 0; +} + +SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, + UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc) +{ + CMatchFinder *mf = p->MatchFinder; + p->historySize = historySize; + if (kMtBtBlockSize <= matchMaxLen * 4) + return SZ_ERROR_PARAM; + if (p->hashBuf == 0) + { + p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32)); + if (p->hashBuf == 0) + return SZ_ERROR_MEM; + p->btBuf = p->hashBuf + kHashBufferSize; + } + keepAddBufferBefore += (kHashBufferSize + kBtBufferSize); + keepAddBufferAfter += kMtHashBlockSize; + if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc)) + return SZ_ERROR_MEM; + + RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks)); + RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks)); + return SZ_OK; +} + +/* Call it after ReleaseStream / SetStream */ +void MatchFinderMt_Init(CMatchFinderMt *p) +{ + CMatchFinder *mf = p->MatchFinder; + p->btBufPos = p->btBufPosLimit = 0; + p->hashBufPos = p->hashBufPosLimit = 0; + MatchFinder_Init(mf); + p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf); + p->btNumAvailBytes = 0; + p->lzPos = p->historySize + 1; + + p->hash = mf->hash; + p->fixedHashSize = mf->fixedHashSize; + p->crc = mf->crc; + + p->son = mf->son; + p->matchMaxLen = mf->matchMaxLen; + p->numHashBytes = mf->numHashBytes; + p->pos = mf->pos; + p->buffer = mf->buffer; + p->cyclicBufferPos = mf->cyclicBufferPos; + p->cyclicBufferSize = mf->cyclicBufferSize; + p->cutValue = mf->cutValue; +} + +/* ReleaseStream is required to finish multithreading */ +void MatchFinderMt_ReleaseStream(CMatchFinderMt *p) +{ + MtSync_StopWriting(&p->btSync); + /* p->MatchFinder->ReleaseStream(); */ +} + +void MatchFinderMt_Normalize(CMatchFinderMt *p) +{ + MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize); + p->lzPos = p->historySize + 1; +} + +void MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p) +{ + UInt32 blockIndex; + MtSync_GetNextBlock(&p->btSync); + blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask); + p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize; + p->btBufPosLimit += p->btBuf[p->btBufPos++]; + p->btNumAvailBytes = p->btBuf[p->btBufPos++]; + if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize) + MatchFinderMt_Normalize(p); +} + +const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p) +{ + return p->pointerToCurPos; +} + +#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p); + +UInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p) +{ + GET_NEXT_BLOCK_IF_REQUIRED; + return p->btNumAvailBytes; +} + +Byte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index) +{ + return p->pointerToCurPos[index]; +} + +UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances) +{ + UInt32 hash2Value, curMatch2; + UInt32 *hash = p->hash; + const Byte *cur = p->pointerToCurPos; + UInt32 lzPos = p->lzPos; + MT_HASH2_CALC + + curMatch2 = hash[hash2Value]; + hash[hash2Value] = lzPos; + + if (curMatch2 >= matchMinPos) + if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0]) + { + *distances++ = 2; + *distances++ = lzPos - curMatch2 - 1; + } + return distances; +} + +UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances) +{ + UInt32 hash2Value, hash3Value, curMatch2, curMatch3; + UInt32 *hash = p->hash; + const Byte *cur = p->pointerToCurPos; + UInt32 lzPos = p->lzPos; + MT_HASH3_CALC + + curMatch2 = hash[ hash2Value]; + curMatch3 = hash[kFix3HashSize + hash3Value]; + + hash[ hash2Value] = + hash[kFix3HashSize + hash3Value] = + lzPos; + + if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0]) + { + distances[1] = lzPos - curMatch2 - 1; + if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2]) + { + distances[0] = 3; + return distances + 2; + } + distances[0] = 2; + distances += 2; + } + if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0]) + { + *distances++ = 3; + *distances++ = lzPos - curMatch3 - 1; + } + return distances; +} + +/* +UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances) +{ + UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4; + UInt32 *hash = p->hash; + const Byte *cur = p->pointerToCurPos; + UInt32 lzPos = p->lzPos; + MT_HASH4_CALC + + curMatch2 = hash[ hash2Value]; + curMatch3 = hash[kFix3HashSize + hash3Value]; + curMatch4 = hash[kFix4HashSize + hash4Value]; + + hash[ hash2Value] = + hash[kFix3HashSize + hash3Value] = + hash[kFix4HashSize + hash4Value] = + lzPos; + + if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0]) + { + distances[1] = lzPos - curMatch2 - 1; + if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2]) + { + distances[0] = (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3; + return distances + 2; + } + distances[0] = 2; + distances += 2; + } + if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0]) + { + distances[1] = lzPos - curMatch3 - 1; + if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3]) + { + distances[0] = 4; + return distances + 2; + } + distances[0] = 3; + distances += 2; + } + + if (curMatch4 >= matchMinPos) + if ( + cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] && + cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3] + ) + { + *distances++ = 4; + *distances++ = lzPos - curMatch4 - 1; + } + return distances; +} +*/ + +#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++; + +UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances) +{ + const UInt32 *btBuf = p->btBuf + p->btBufPos; + UInt32 len = *btBuf++; + p->btBufPos += 1 + len; + p->btNumAvailBytes--; + { + UInt32 i; + for (i = 0; i < len; i += 2) + { + *distances++ = *btBuf++; + *distances++ = *btBuf++; + } + } + INCREASE_LZ_POS + return len; +} + +UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances) +{ + const UInt32 *btBuf = p->btBuf + p->btBufPos; + UInt32 len = *btBuf++; + p->btBufPos += 1 + len; + + if (len == 0) + { + if (p->btNumAvailBytes-- >= 4) + len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances)); + } + else + { + /* Condition: there are matches in btBuf with length < p->numHashBytes */ + UInt32 *distances2; + p->btNumAvailBytes--; + distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances); + do + { + *distances2++ = *btBuf++; + *distances2++ = *btBuf++; + } + while ((len -= 2) != 0); + len = (UInt32)(distances2 - (distances)); + } + INCREASE_LZ_POS + return len; +} + +#define SKIP_HEADER2 do { GET_NEXT_BLOCK_IF_REQUIRED +#define SKIP_HEADER(n) SKIP_HEADER2 if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash; +#define SKIP_FOOTER } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num != 0); + +void MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num) +{ + SKIP_HEADER2 { p->btNumAvailBytes--; + SKIP_FOOTER +} + +void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num) +{ + SKIP_HEADER(2) + UInt32 hash2Value; + MT_HASH2_CALC + hash[hash2Value] = p->lzPos; + SKIP_FOOTER +} + +void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num) +{ + SKIP_HEADER(3) + UInt32 hash2Value, hash3Value; + MT_HASH3_CALC + hash[kFix3HashSize + hash3Value] = + hash[ hash2Value] = + p->lzPos; + SKIP_FOOTER +} + +/* +void MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num) +{ + SKIP_HEADER(4) + UInt32 hash2Value, hash3Value, hash4Value; + MT_HASH4_CALC + hash[kFix4HashSize + hash4Value] = + hash[kFix3HashSize + hash3Value] = + hash[ hash2Value] = + p->lzPos; + SKIP_FOOTER +} +*/ + +void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable) +{ + vTable->Init = (Mf_Init_Func)MatchFinderMt_Init; + vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte; + vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes; + vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos; + vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches; + switch(p->MatchFinder->numHashBytes) + { + case 2: + p->GetHeadsFunc = GetHeads2; + p->MixMatchesFunc = (Mf_Mix_Matches)0; + vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip; + vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches; + break; + case 3: + p->GetHeadsFunc = GetHeads3; + p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2; + vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip; + break; + default: + /* case 4: */ + p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4; + /* p->GetHeadsFunc = GetHeads4; */ + p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3; + vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip; + break; + /* + default: + p->GetHeadsFunc = GetHeads5; + p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4; + vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip; + break; + */ + } +} diff --git a/extern/lzma/LzFindMt.h b/extern/lzma/LzFindMt.h new file mode 100644 index 00000000000..2c7e462d592 --- /dev/null +++ b/extern/lzma/LzFindMt.h @@ -0,0 +1,97 @@ +/* LzFindMt.h -- multithreaded Match finder for LZ algorithms +2008-10-04 : Igor Pavlov : Public domain */ + +#ifndef __LZFINDMT_H +#define __LZFINDMT_H + +#include "Threads.h" +#include "LzFind.h" + +#define kMtHashBlockSize (1 << 13) +#define kMtHashNumBlocks (1 << 3) +#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1) + +#define kMtBtBlockSize (1 << 14) +#define kMtBtNumBlocks (1 << 6) +#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1) + +typedef struct _CMtSync +{ + Bool wasCreated; + Bool needStart; + Bool exit; + Bool stopWriting; + + CThread thread; + CAutoResetEvent canStart; + CAutoResetEvent wasStarted; + CAutoResetEvent wasStopped; + CSemaphore freeSemaphore; + CSemaphore filledSemaphore; + Bool csWasInitialized; + Bool csWasEntered; + CCriticalSection cs; + UInt32 numProcessedBlocks; +} CMtSync; + +typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances); + +/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */ +#define kMtCacheLineDummy 128 + +typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos, + UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc); + +typedef struct _CMatchFinderMt +{ + /* LZ */ + const Byte *pointerToCurPos; + UInt32 *btBuf; + UInt32 btBufPos; + UInt32 btBufPosLimit; + UInt32 lzPos; + UInt32 btNumAvailBytes; + + UInt32 *hash; + UInt32 fixedHashSize; + UInt32 historySize; + const UInt32 *crc; + + Mf_Mix_Matches MixMatchesFunc; + + /* LZ + BT */ + CMtSync btSync; + Byte btDummy[kMtCacheLineDummy]; + + /* BT */ + UInt32 *hashBuf; + UInt32 hashBufPos; + UInt32 hashBufPosLimit; + UInt32 hashNumAvail; + + CLzRef *son; + UInt32 matchMaxLen; + UInt32 numHashBytes; + UInt32 pos; + Byte *buffer; + UInt32 cyclicBufferPos; + UInt32 cyclicBufferSize; /* it must be historySize + 1 */ + UInt32 cutValue; + + /* BT + Hash */ + CMtSync hashSync; + /* Byte hashDummy[kMtCacheLineDummy]; */ + + /* Hash */ + Mf_GetHeads GetHeadsFunc; + CMatchFinder *MatchFinder; +} CMatchFinderMt; + +void MatchFinderMt_Construct(CMatchFinderMt *p); +void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc); +SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, + UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc); +void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable); +void MatchFinderMt_ReleaseStream(CMatchFinderMt *p); + +#endif diff --git a/extern/lzma/LzHash.h b/extern/lzma/LzHash.h new file mode 100644 index 00000000000..9f4173e7e33 --- /dev/null +++ b/extern/lzma/LzHash.h @@ -0,0 +1,54 @@ +/* LzHash.h -- HASH functions for LZ algorithms +2008-10-04 : Igor Pavlov : Public domain */ + +#ifndef __LZHASH_H +#define __LZHASH_H + +#define kHash2Size (1 << 10) +#define kHash3Size (1 << 16) +#define kHash4Size (1 << 20) + +#define kFix3HashSize (kHash2Size) +#define kFix4HashSize (kHash2Size + kHash3Size) +#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size) + +#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8); + +#define HASH3_CALC { \ + UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ + hash2Value = temp & (kHash2Size - 1); \ + hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; } + +#define HASH4_CALC { \ + UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ + hash2Value = temp & (kHash2Size - 1); \ + hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ + hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; } + +#define HASH5_CALC { \ + UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ + hash2Value = temp & (kHash2Size - 1); \ + hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ + hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \ + hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \ + hash4Value &= (kHash4Size - 1); } + +/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */ +#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF; + + +#define MT_HASH2_CALC \ + hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1); + +#define MT_HASH3_CALC { \ + UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ + hash2Value = temp & (kHash2Size - 1); \ + hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); } + +#define MT_HASH4_CALC { \ + UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ + hash2Value = temp & (kHash2Size - 1); \ + hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ + hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); } + +#endif diff --git a/extern/lzma/LzmaDec.c b/extern/lzma/LzmaDec.c new file mode 100644 index 00000000000..d87eb1914ea --- /dev/null +++ b/extern/lzma/LzmaDec.c @@ -0,0 +1,1007 @@ +/* LzmaDec.c -- LZMA Decoder +2008-11-06 : Igor Pavlov : Public domain */ + +#include "LzmaDec.h" + +#include + +#define kNumTopBits 24 +#define kTopValue ((UInt32)1 << kNumTopBits) + +#define kNumBitModelTotalBits 11 +#define kBitModelTotal (1 << kNumBitModelTotalBits) +#define kNumMoveBits 5 + +#define RC_INIT_SIZE 5 + +#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); } + +#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound) +#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); +#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits)); +#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \ + { UPDATE_0(p); i = (i + i); A0; } else \ + { UPDATE_1(p); i = (i + i) + 1; A1; } +#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;) + +#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); } +#define TREE_DECODE(probs, limit, i) \ + { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; } + +/* #define _LZMA_SIZE_OPT */ + +#ifdef _LZMA_SIZE_OPT +#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i) +#else +#define TREE_6_DECODE(probs, i) \ + { i = 1; \ + TREE_GET_BIT(probs, i); \ + TREE_GET_BIT(probs, i); \ + TREE_GET_BIT(probs, i); \ + TREE_GET_BIT(probs, i); \ + TREE_GET_BIT(probs, i); \ + TREE_GET_BIT(probs, i); \ + i -= 0x40; } +#endif + +#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); } + +#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound) +#define UPDATE_0_CHECK range = bound; +#define UPDATE_1_CHECK range -= bound; code -= bound; +#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \ + { UPDATE_0_CHECK; i = (i + i); A0; } else \ + { UPDATE_1_CHECK; i = (i + i) + 1; A1; } +#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;) +#define TREE_DECODE_CHECK(probs, limit, i) \ + { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; } + + +#define kNumPosBitsMax 4 +#define kNumPosStatesMax (1 << kNumPosBitsMax) + +#define kLenNumLowBits 3 +#define kLenNumLowSymbols (1 << kLenNumLowBits) +#define kLenNumMidBits 3 +#define kLenNumMidSymbols (1 << kLenNumMidBits) +#define kLenNumHighBits 8 +#define kLenNumHighSymbols (1 << kLenNumHighBits) + +#define LenChoice 0 +#define LenChoice2 (LenChoice + 1) +#define LenLow (LenChoice2 + 1) +#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits)) +#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits)) +#define kNumLenProbs (LenHigh + kLenNumHighSymbols) + + +#define kNumStates 12 +#define kNumLitStates 7 + +#define kStartPosModelIndex 4 +#define kEndPosModelIndex 14 +#define kNumFullDistances (1 << (kEndPosModelIndex >> 1)) + +#define kNumPosSlotBits 6 +#define kNumLenToPosStates 4 + +#define kNumAlignBits 4 +#define kAlignTableSize (1 << kNumAlignBits) + +#define kMatchMinLen 2 +#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols) + +#define IsMatch 0 +#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax)) +#define IsRepG0 (IsRep + kNumStates) +#define IsRepG1 (IsRepG0 + kNumStates) +#define IsRepG2 (IsRepG1 + kNumStates) +#define IsRep0Long (IsRepG2 + kNumStates) +#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax)) +#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits)) +#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex) +#define LenCoder (Align + kAlignTableSize) +#define RepLenCoder (LenCoder + kNumLenProbs) +#define Literal (RepLenCoder + kNumLenProbs) + +#define LZMA_BASE_SIZE 1846 +#define LZMA_LIT_SIZE 768 + +#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp))) + +#if Literal != LZMA_BASE_SIZE +StopCompilingDueBUG +#endif + +static const Byte kLiteralNextStates[kNumStates * 2] = +{ + 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5, + 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10 +}; + +#define LZMA_DIC_MIN (1 << 12) + +/* First LZMA-symbol is always decoded. +And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization +Out: + Result: + SZ_OK - OK + SZ_ERROR_DATA - Error + p->remainLen: + < kMatchSpecLenStart : normal remain + = kMatchSpecLenStart : finished + = kMatchSpecLenStart + 1 : Flush marker + = kMatchSpecLenStart + 2 : State Init Marker +*/ + +static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit) +{ + CLzmaProb *probs = p->probs; + + unsigned state = p->state; + UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3]; + unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1; + unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1; + unsigned lc = p->prop.lc; + + Byte *dic = p->dic; + SizeT dicBufSize = p->dicBufSize; + SizeT dicPos = p->dicPos; + + UInt32 processedPos = p->processedPos; + UInt32 checkDicSize = p->checkDicSize; + unsigned len = 0; + + const Byte *buf = p->buf; + UInt32 range = p->range; + UInt32 code = p->code; + + do + { + CLzmaProb *prob; + UInt32 bound; + unsigned ttt; + unsigned posState = processedPos & pbMask; + + prob = probs + IsMatch + (state << kNumPosBitsMax) + posState; + IF_BIT_0(prob) + { + unsigned symbol; + UPDATE_0(prob); + prob = probs + Literal; + if (checkDicSize != 0 || processedPos != 0) + prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) + + (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc)))); + + if (state < kNumLitStates) + { + symbol = 1; + do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100); + } + else + { + unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)]; + unsigned offs = 0x100; + symbol = 1; + do + { + unsigned bit; + CLzmaProb *probLit; + matchByte <<= 1; + bit = (matchByte & offs); + probLit = prob + offs + bit + symbol; + GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit) + } + while (symbol < 0x100); + } + dic[dicPos++] = (Byte)symbol; + processedPos++; + + state = kLiteralNextStates[state]; + /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */ + continue; + } + else + { + UPDATE_1(prob); + prob = probs + IsRep + state; + IF_BIT_0(prob) + { + UPDATE_0(prob); + state += kNumStates; + prob = probs + LenCoder; + } + else + { + UPDATE_1(prob); + if (checkDicSize == 0 && processedPos == 0) + return SZ_ERROR_DATA; + prob = probs + IsRepG0 + state; + IF_BIT_0(prob) + { + UPDATE_0(prob); + prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState; + IF_BIT_0(prob) + { + UPDATE_0(prob); + dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)]; + dicPos++; + processedPos++; + state = state < kNumLitStates ? 9 : 11; + continue; + } + UPDATE_1(prob); + } + else + { + UInt32 distance; + UPDATE_1(prob); + prob = probs + IsRepG1 + state; + IF_BIT_0(prob) + { + UPDATE_0(prob); + distance = rep1; + } + else + { + UPDATE_1(prob); + prob = probs + IsRepG2 + state; + IF_BIT_0(prob) + { + UPDATE_0(prob); + distance = rep2; + } + else + { + UPDATE_1(prob); + distance = rep3; + rep3 = rep2; + } + rep2 = rep1; + } + rep1 = rep0; + rep0 = distance; + } + state = state < kNumLitStates ? 8 : 11; + prob = probs + RepLenCoder; + } + { + unsigned limit, offset; + CLzmaProb *probLen = prob + LenChoice; + IF_BIT_0(probLen) + { + UPDATE_0(probLen); + probLen = prob + LenLow + (posState << kLenNumLowBits); + offset = 0; + limit = (1 << kLenNumLowBits); + } + else + { + UPDATE_1(probLen); + probLen = prob + LenChoice2; + IF_BIT_0(probLen) + { + UPDATE_0(probLen); + probLen = prob + LenMid + (posState << kLenNumMidBits); + offset = kLenNumLowSymbols; + limit = (1 << kLenNumMidBits); + } + else + { + UPDATE_1(probLen); + probLen = prob + LenHigh; + offset = kLenNumLowSymbols + kLenNumMidSymbols; + limit = (1 << kLenNumHighBits); + } + } + TREE_DECODE(probLen, limit, len); + len += offset; + } + + if (state >= kNumStates) + { + UInt32 distance; + prob = probs + PosSlot + + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits); + TREE_6_DECODE(prob, distance); + if (distance >= kStartPosModelIndex) + { + unsigned posSlot = (unsigned)distance; + int numDirectBits = (int)(((distance >> 1) - 1)); + distance = (2 | (distance & 1)); + if (posSlot < kEndPosModelIndex) + { + distance <<= numDirectBits; + prob = probs + SpecPos + distance - posSlot - 1; + { + UInt32 mask = 1; + unsigned i = 1; + do + { + GET_BIT2(prob + i, i, ; , distance |= mask); + mask <<= 1; + } + while (--numDirectBits != 0); + } + } + else + { + numDirectBits -= kNumAlignBits; + do + { + NORMALIZE + range >>= 1; + + { + UInt32 t; + code -= range; + t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */ + distance = (distance << 1) + (t + 1); + code += range & t; + } + /* + distance <<= 1; + if (code >= range) + { + code -= range; + distance |= 1; + } + */ + } + while (--numDirectBits != 0); + prob = probs + Align; + distance <<= kNumAlignBits; + { + unsigned i = 1; + GET_BIT2(prob + i, i, ; , distance |= 1); + GET_BIT2(prob + i, i, ; , distance |= 2); + GET_BIT2(prob + i, i, ; , distance |= 4); + GET_BIT2(prob + i, i, ; , distance |= 8); + } + if (distance == (UInt32)0xFFFFFFFF) + { + len += kMatchSpecLenStart; + state -= kNumStates; + break; + } + } + } + rep3 = rep2; + rep2 = rep1; + rep1 = rep0; + rep0 = distance + 1; + if (checkDicSize == 0) + { + if (distance >= processedPos) + return SZ_ERROR_DATA; + } + else if (distance >= checkDicSize) + return SZ_ERROR_DATA; + state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3; + /* state = kLiteralNextStates[state]; */ + } + + len += kMatchMinLen; + + if (limit == dicPos) + return SZ_ERROR_DATA; + { + SizeT rem = limit - dicPos; + unsigned curLen = ((rem < len) ? (unsigned)rem : len); + SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0); + + processedPos += curLen; + + len -= curLen; + if (pos + curLen <= dicBufSize) + { + Byte *dest = dic + dicPos; + ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos; + const Byte *lim = dest + curLen; + dicPos += curLen; + do + *(dest) = (Byte)*(dest + src); + while (++dest != lim); + } + else + { + do + { + dic[dicPos++] = dic[pos]; + if (++pos == dicBufSize) + pos = 0; + } + while (--curLen != 0); + } + } + } + } + while (dicPos < limit && buf < bufLimit); + NORMALIZE; + p->buf = buf; + p->range = range; + p->code = code; + p->remainLen = len; + p->dicPos = dicPos; + p->processedPos = processedPos; + p->reps[0] = rep0; + p->reps[1] = rep1; + p->reps[2] = rep2; + p->reps[3] = rep3; + p->state = state; + + return SZ_OK; +} + +static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit) +{ + if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart) + { + Byte *dic = p->dic; + SizeT dicPos = p->dicPos; + SizeT dicBufSize = p->dicBufSize; + unsigned len = p->remainLen; + UInt32 rep0 = p->reps[0]; + if (limit - dicPos < len) + len = (unsigned)(limit - dicPos); + + if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len) + p->checkDicSize = p->prop.dicSize; + + p->processedPos += len; + p->remainLen -= len; + while (len-- != 0) + { + dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)]; + dicPos++; + } + p->dicPos = dicPos; + } +} + +static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit) +{ + do + { + SizeT limit2 = limit; + if (p->checkDicSize == 0) + { + UInt32 rem = p->prop.dicSize - p->processedPos; + if (limit - p->dicPos > rem) + limit2 = p->dicPos + rem; + } + RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit)); + if (p->processedPos >= p->prop.dicSize) + p->checkDicSize = p->prop.dicSize; + LzmaDec_WriteRem(p, limit); + } + while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart); + + if (p->remainLen > kMatchSpecLenStart) + { + p->remainLen = kMatchSpecLenStart; + } + return 0; +} + +typedef enum +{ + DUMMY_ERROR, /* unexpected end of input stream */ + DUMMY_LIT, + DUMMY_MATCH, + DUMMY_REP +} ELzmaDummy; + +static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize) +{ + UInt32 range = p->range; + UInt32 code = p->code; + const Byte *bufLimit = buf + inSize; + CLzmaProb *probs = p->probs; + unsigned state = p->state; + ELzmaDummy res; + + { + CLzmaProb *prob; + UInt32 bound; + unsigned ttt; + unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1); + + prob = probs + IsMatch + (state << kNumPosBitsMax) + posState; + IF_BIT_0_CHECK(prob) + { + UPDATE_0_CHECK + + /* if (bufLimit - buf >= 7) return DUMMY_LIT; */ + + prob = probs + Literal; + if (p->checkDicSize != 0 || p->processedPos != 0) + prob += (LZMA_LIT_SIZE * + ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) + + (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc)))); + + if (state < kNumLitStates) + { + unsigned symbol = 1; + do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100); + } + else + { + unsigned matchByte = p->dic[p->dicPos - p->reps[0] + + ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)]; + unsigned offs = 0x100; + unsigned symbol = 1; + do + { + unsigned bit; + CLzmaProb *probLit; + matchByte <<= 1; + bit = (matchByte & offs); + probLit = prob + offs + bit + symbol; + GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit) + } + while (symbol < 0x100); + } + res = DUMMY_LIT; + } + else + { + unsigned len; + UPDATE_1_CHECK; + + prob = probs + IsRep + state; + IF_BIT_0_CHECK(prob) + { + UPDATE_0_CHECK; + state = 0; + prob = probs + LenCoder; + res = DUMMY_MATCH; + } + else + { + UPDATE_1_CHECK; + res = DUMMY_REP; + prob = probs + IsRepG0 + state; + IF_BIT_0_CHECK(prob) + { + UPDATE_0_CHECK; + prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState; + IF_BIT_0_CHECK(prob) + { + UPDATE_0_CHECK; + NORMALIZE_CHECK; + return DUMMY_REP; + } + else + { + UPDATE_1_CHECK; + } + } + else + { + UPDATE_1_CHECK; + prob = probs + IsRepG1 + state; + IF_BIT_0_CHECK(prob) + { + UPDATE_0_CHECK; + } + else + { + UPDATE_1_CHECK; + prob = probs + IsRepG2 + state; + IF_BIT_0_CHECK(prob) + { + UPDATE_0_CHECK; + } + else + { + UPDATE_1_CHECK; + } + } + } + state = kNumStates; + prob = probs + RepLenCoder; + } + { + unsigned limit, offset; + CLzmaProb *probLen = prob + LenChoice; + IF_BIT_0_CHECK(probLen) + { + UPDATE_0_CHECK; + probLen = prob + LenLow + (posState << kLenNumLowBits); + offset = 0; + limit = 1 << kLenNumLowBits; + } + else + { + UPDATE_1_CHECK; + probLen = prob + LenChoice2; + IF_BIT_0_CHECK(probLen) + { + UPDATE_0_CHECK; + probLen = prob + LenMid + (posState << kLenNumMidBits); + offset = kLenNumLowSymbols; + limit = 1 << kLenNumMidBits; + } + else + { + UPDATE_1_CHECK; + probLen = prob + LenHigh; + offset = kLenNumLowSymbols + kLenNumMidSymbols; + limit = 1 << kLenNumHighBits; + } + } + TREE_DECODE_CHECK(probLen, limit, len); + len += offset; + } + + if (state < 4) + { + unsigned posSlot; + prob = probs + PosSlot + + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << + kNumPosSlotBits); + TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot); + if (posSlot >= kStartPosModelIndex) + { + int numDirectBits = ((posSlot >> 1) - 1); + + /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */ + + if (posSlot < kEndPosModelIndex) + { + prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1; + } + else + { + numDirectBits -= kNumAlignBits; + do + { + NORMALIZE_CHECK + range >>= 1; + code -= range & (((code - range) >> 31) - 1); + /* if (code >= range) code -= range; */ + } + while (--numDirectBits != 0); + prob = probs + Align; + numDirectBits = kNumAlignBits; + } + { + unsigned i = 1; + do + { + GET_BIT_CHECK(prob + i, i); + } + while (--numDirectBits != 0); + } + } + } + } + } + NORMALIZE_CHECK; + return res; +} + + +static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data) +{ + p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]); + p->range = 0xFFFFFFFF; + p->needFlush = 0; +} + +void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState) +{ + p->needFlush = 1; + p->remainLen = 0; + p->tempBufSize = 0; + + if (initDic) + { + p->processedPos = 0; + p->checkDicSize = 0; + p->needInitState = 1; + } + if (initState) + p->needInitState = 1; +} + +void LzmaDec_Init(CLzmaDec *p) +{ + p->dicPos = 0; + LzmaDec_InitDicAndState(p, True, True); +} + +static void LzmaDec_InitStateReal(CLzmaDec *p) +{ + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp)); + UInt32 i; + CLzmaProb *probs = p->probs; + for (i = 0; i < numProbs; i++) + probs[i] = kBitModelTotal >> 1; + p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1; + p->state = 0; + p->needInitState = 0; +} + +SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, + ELzmaFinishMode finishMode, ELzmaStatus *status) +{ + SizeT inSize = *srcLen; + (*srcLen) = 0; + LzmaDec_WriteRem(p, dicLimit); + + *status = LZMA_STATUS_NOT_SPECIFIED; + + while (p->remainLen != kMatchSpecLenStart) + { + int checkEndMarkNow; + + if (p->needFlush != 0) + { + for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--) + p->tempBuf[p->tempBufSize++] = *src++; + if (p->tempBufSize < RC_INIT_SIZE) + { + *status = LZMA_STATUS_NEEDS_MORE_INPUT; + return SZ_OK; + } + if (p->tempBuf[0] != 0) + return SZ_ERROR_DATA; + + LzmaDec_InitRc(p, p->tempBuf); + p->tempBufSize = 0; + } + + checkEndMarkNow = 0; + if (p->dicPos >= dicLimit) + { + if (p->remainLen == 0 && p->code == 0) + { + *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK; + return SZ_OK; + } + if (finishMode == LZMA_FINISH_ANY) + { + *status = LZMA_STATUS_NOT_FINISHED; + return SZ_OK; + } + if (p->remainLen != 0) + { + *status = LZMA_STATUS_NOT_FINISHED; + return SZ_ERROR_DATA; + } + checkEndMarkNow = 1; + } + + if (p->needInitState) + LzmaDec_InitStateReal(p); + + if (p->tempBufSize == 0) + { + SizeT processed; + const Byte *bufLimit; + if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) + { + int dummyRes = LzmaDec_TryDummy(p, src, inSize); + if (dummyRes == DUMMY_ERROR) + { + memcpy(p->tempBuf, src, inSize); + p->tempBufSize = (unsigned)inSize; + (*srcLen) += inSize; + *status = LZMA_STATUS_NEEDS_MORE_INPUT; + return SZ_OK; + } + if (checkEndMarkNow && dummyRes != DUMMY_MATCH) + { + *status = LZMA_STATUS_NOT_FINISHED; + return SZ_ERROR_DATA; + } + bufLimit = src; + } + else + bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX; + p->buf = src; + if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0) + return SZ_ERROR_DATA; + processed = (SizeT)(p->buf - src); + (*srcLen) += processed; + src += processed; + inSize -= processed; + } + else + { + unsigned rem = p->tempBufSize, lookAhead = 0; + while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize) + p->tempBuf[rem++] = src[lookAhead++]; + p->tempBufSize = rem; + if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) + { + int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem); + if (dummyRes == DUMMY_ERROR) + { + (*srcLen) += lookAhead; + *status = LZMA_STATUS_NEEDS_MORE_INPUT; + return SZ_OK; + } + if (checkEndMarkNow && dummyRes != DUMMY_MATCH) + { + *status = LZMA_STATUS_NOT_FINISHED; + return SZ_ERROR_DATA; + } + } + p->buf = p->tempBuf; + if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0) + return SZ_ERROR_DATA; + lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf)); + (*srcLen) += lookAhead; + src += lookAhead; + inSize -= lookAhead; + p->tempBufSize = 0; + } + } + if (p->code == 0) + *status = LZMA_STATUS_FINISHED_WITH_MARK; + return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA; +} + +SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status) +{ + SizeT outSize = *destLen; + SizeT inSize = *srcLen; + *srcLen = *destLen = 0; + for (;;) + { + SizeT inSizeCur = inSize, outSizeCur, dicPos; + ELzmaFinishMode curFinishMode; + SRes res; + if (p->dicPos == p->dicBufSize) + p->dicPos = 0; + dicPos = p->dicPos; + if (outSize > p->dicBufSize - dicPos) + { + outSizeCur = p->dicBufSize; + curFinishMode = LZMA_FINISH_ANY; + } + else + { + outSizeCur = dicPos + outSize; + curFinishMode = finishMode; + } + + res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status); + src += inSizeCur; + inSize -= inSizeCur; + *srcLen += inSizeCur; + outSizeCur = p->dicPos - dicPos; + memcpy(dest, p->dic + dicPos, outSizeCur); + dest += outSizeCur; + outSize -= outSizeCur; + *destLen += outSizeCur; + if (res != 0) + return res; + if (outSizeCur == 0 || outSize == 0) + return SZ_OK; + } +} + +void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc) +{ + alloc->Free(alloc, p->probs); + p->probs = 0; +} + +static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc) +{ + alloc->Free(alloc, p->dic); + p->dic = 0; +} + +void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc) +{ + LzmaDec_FreeProbs(p, alloc); + LzmaDec_FreeDict(p, alloc); +} + +SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size) +{ + UInt32 dicSize; + Byte d; + + if (size < LZMA_PROPS_SIZE) + return SZ_ERROR_UNSUPPORTED; + else + dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24); + + if (dicSize < LZMA_DIC_MIN) + dicSize = LZMA_DIC_MIN; + p->dicSize = dicSize; + + d = data[0]; + if (d >= (9 * 5 * 5)) + return SZ_ERROR_UNSUPPORTED; + + p->lc = d % 9; + d /= 9; + p->pb = d / 5; + p->lp = d % 5; + + return SZ_OK; +} + +static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc) +{ + UInt32 numProbs = LzmaProps_GetNumProbs(propNew); + if (p->probs == 0 || numProbs != p->numProbs) + { + LzmaDec_FreeProbs(p, alloc); + p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb)); + p->numProbs = numProbs; + if (p->probs == 0) + return SZ_ERROR_MEM; + } + return SZ_OK; +} + +SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc) +{ + CLzmaProps propNew; + RINOK(LzmaProps_Decode(&propNew, props, propsSize)); + RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc)); + p->prop = propNew; + return SZ_OK; +} + +SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc) +{ + CLzmaProps propNew; + SizeT dicBufSize; + RINOK(LzmaProps_Decode(&propNew, props, propsSize)); + RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc)); + dicBufSize = propNew.dicSize; + if (p->dic == 0 || dicBufSize != p->dicBufSize) + { + LzmaDec_FreeDict(p, alloc); + p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize); + if (p->dic == 0) + { + LzmaDec_FreeProbs(p, alloc); + return SZ_ERROR_MEM; + } + } + p->dicBufSize = dicBufSize; + p->prop = propNew; + return SZ_OK; +} + +SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, + const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, + ELzmaStatus *status, ISzAlloc *alloc) +{ + CLzmaDec p; + SRes res; + SizeT inSize = *srcLen; + SizeT outSize = *destLen; + *srcLen = *destLen = 0; + if (inSize < RC_INIT_SIZE) + return SZ_ERROR_INPUT_EOF; + + LzmaDec_Construct(&p); + res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc); + if (res != 0) + return res; + p.dic = dest; + p.dicBufSize = outSize; + + LzmaDec_Init(&p); + + *srcLen = inSize; + res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status); + + if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT) + res = SZ_ERROR_INPUT_EOF; + + (*destLen) = p.dicPos; + LzmaDec_FreeProbs(&p, alloc); + return res; +} diff --git a/extern/lzma/LzmaDec.h b/extern/lzma/LzmaDec.h new file mode 100644 index 00000000000..98cdbe94949 --- /dev/null +++ b/extern/lzma/LzmaDec.h @@ -0,0 +1,223 @@ +/* LzmaDec.h -- LZMA Decoder +2008-10-04 : Igor Pavlov : Public domain */ + +#ifndef __LZMADEC_H +#define __LZMADEC_H + +#include "Types.h" + +/* #define _LZMA_PROB32 */ +/* _LZMA_PROB32 can increase the speed on some CPUs, + but memory usage for CLzmaDec::probs will be doubled in that case */ + +#ifdef _LZMA_PROB32 +#define CLzmaProb UInt32 +#else +#define CLzmaProb UInt16 +#endif + + +/* ---------- LZMA Properties ---------- */ + +#define LZMA_PROPS_SIZE 5 + +typedef struct _CLzmaProps +{ + unsigned lc, lp, pb; + UInt32 dicSize; +} CLzmaProps; + +/* LzmaProps_Decode - decodes properties +Returns: + SZ_OK + SZ_ERROR_UNSUPPORTED - Unsupported properties +*/ + +SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size); + + +/* ---------- LZMA Decoder state ---------- */ + +/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case. + Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */ + +#define LZMA_REQUIRED_INPUT_MAX 20 + +typedef struct +{ + CLzmaProps prop; + CLzmaProb *probs; + Byte *dic; + const Byte *buf; + UInt32 range, code; + SizeT dicPos; + SizeT dicBufSize; + UInt32 processedPos; + UInt32 checkDicSize; + unsigned state; + UInt32 reps[4]; + unsigned remainLen; + int needFlush; + int needInitState; + UInt32 numProbs; + unsigned tempBufSize; + Byte tempBuf[LZMA_REQUIRED_INPUT_MAX]; +} CLzmaDec; + +#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; } + +void LzmaDec_Init(CLzmaDec *p); + +/* There are two types of LZMA streams: + 0) Stream with end mark. That end mark adds about 6 bytes to compressed size. + 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */ + +typedef enum +{ + LZMA_FINISH_ANY, /* finish at any point */ + LZMA_FINISH_END /* block must be finished at the end */ +} ELzmaFinishMode; + +/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!! + + You must use LZMA_FINISH_END, when you know that current output buffer + covers last bytes of block. In other cases you must use LZMA_FINISH_ANY. + + If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK, + and output value of destLen will be less than output buffer size limit. + You can check status result also. + + You can use multiple checks to test data integrity after full decompression: + 1) Check Result and "status" variable. + 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize. + 3) Check that output(srcLen) = compressedSize, if you know real compressedSize. + You must use correct finish mode in that case. */ + +typedef enum +{ + LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */ + LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */ + LZMA_STATUS_NOT_FINISHED, /* stream was not finished */ + LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */ + LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */ +} ELzmaStatus; + +/* ELzmaStatus is used only as output value for function call */ + + +/* ---------- Interfaces ---------- */ + +/* There are 3 levels of interfaces: + 1) Dictionary Interface + 2) Buffer Interface + 3) One Call Interface + You can select any of these interfaces, but don't mix functions from different + groups for same object. */ + + +/* There are two variants to allocate state for Dictionary Interface: + 1) LzmaDec_Allocate / LzmaDec_Free + 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs + You can use variant 2, if you set dictionary buffer manually. + For Buffer Interface you must always use variant 1. + +LzmaDec_Allocate* can return: + SZ_OK + SZ_ERROR_MEM - Memory allocation error + SZ_ERROR_UNSUPPORTED - Unsupported properties +*/ + +SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc); +void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc); + +SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc); +void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc); + +/* ---------- Dictionary Interface ---------- */ + +/* You can use it, if you want to eliminate the overhead for data copying from + dictionary to some other external buffer. + You must work with CLzmaDec variables directly in this interface. + + STEPS: + LzmaDec_Constr() + LzmaDec_Allocate() + for (each new stream) + { + LzmaDec_Init() + while (it needs more decompression) + { + LzmaDec_DecodeToDic() + use data from CLzmaDec::dic and update CLzmaDec::dicPos + } + } + LzmaDec_Free() +*/ + +/* LzmaDec_DecodeToDic + + The decoding to internal dictionary buffer (CLzmaDec::dic). + You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!! + +finishMode: + It has meaning only if the decoding reaches output limit (dicLimit). + LZMA_FINISH_ANY - Decode just dicLimit bytes. + LZMA_FINISH_END - Stream must be finished after dicLimit. + +Returns: + SZ_OK + status: + LZMA_STATUS_FINISHED_WITH_MARK + LZMA_STATUS_NOT_FINISHED + LZMA_STATUS_NEEDS_MORE_INPUT + LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK + SZ_ERROR_DATA - Data error +*/ + +SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, + const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); + + +/* ---------- Buffer Interface ---------- */ + +/* It's zlib-like interface. + See LzmaDec_DecodeToDic description for information about STEPS and return results, + but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need + to work with CLzmaDec variables manually. + +finishMode: + It has meaning only if the decoding reaches output limit (*destLen). + LZMA_FINISH_ANY - Decode just destLen bytes. + LZMA_FINISH_END - Stream must be finished after (*destLen). +*/ + +SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, + const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); + + +/* ---------- One Call Interface ---------- */ + +/* LzmaDecode + +finishMode: + It has meaning only if the decoding reaches output limit (*destLen). + LZMA_FINISH_ANY - Decode just destLen bytes. + LZMA_FINISH_END - Stream must be finished after (*destLen). + +Returns: + SZ_OK + status: + LZMA_STATUS_FINISHED_WITH_MARK + LZMA_STATUS_NOT_FINISHED + LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK + SZ_ERROR_DATA - Data error + SZ_ERROR_MEM - Memory allocation error + SZ_ERROR_UNSUPPORTED - Unsupported properties + SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). +*/ + +SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, + const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, + ELzmaStatus *status, ISzAlloc *alloc); + +#endif diff --git a/extern/lzma/LzmaEnc.c b/extern/lzma/LzmaEnc.c new file mode 100644 index 00000000000..9196c43f64b --- /dev/null +++ b/extern/lzma/LzmaEnc.c @@ -0,0 +1,2281 @@ +/* LzmaEnc.c -- LZMA Encoder +2009-02-02 : Igor Pavlov : Public domain */ + +#include + +/* #define SHOW_STAT */ +/* #define SHOW_STAT2 */ + +#if defined(SHOW_STAT) || defined(SHOW_STAT2) +#include +#endif + +#include "LzmaEnc.h" + +#include "LzFind.h" +#ifdef COMPRESS_MF_MT +#include "LzFindMt.h" +#endif + +#ifdef SHOW_STAT +static int ttt = 0; +#endif + +#define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1) + +#define kBlockSize (9 << 10) +#define kUnpackBlockSize (1 << 18) +#define kMatchArraySize (1 << 21) +#define kMatchRecordMaxSize ((LZMA_MATCH_LEN_MAX * 2 + 3) * LZMA_MATCH_LEN_MAX) + +#define kNumMaxDirectBits (31) + +#define kNumTopBits 24 +#define kTopValue ((UInt32)1 << kNumTopBits) + +#define kNumBitModelTotalBits 11 +#define kBitModelTotal (1 << kNumBitModelTotalBits) +#define kNumMoveBits 5 +#define kProbInitValue (kBitModelTotal >> 1) + +#define kNumMoveReducingBits 4 +#define kNumBitPriceShiftBits 4 +#define kBitPrice (1 << kNumBitPriceShiftBits) + +void LzmaEncProps_Init(CLzmaEncProps *p) +{ + p->level = 5; + p->dictSize = p->mc = 0; + p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1; + p->writeEndMark = 0; +} + +void LzmaEncProps_Normalize(CLzmaEncProps *p) +{ + int level = p->level; + if (level < 0) level = 5; + p->level = level; + if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26))); + if (p->lc < 0) p->lc = 3; + if (p->lp < 0) p->lp = 0; + if (p->pb < 0) p->pb = 2; + if (p->algo < 0) p->algo = (level < 5 ? 0 : 1); + if (p->fb < 0) p->fb = (level < 7 ? 32 : 64); + if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1); + if (p->numHashBytes < 0) p->numHashBytes = 4; + if (p->mc == 0) p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1); + if (p->numThreads < 0) + p->numThreads = + #ifdef COMPRESS_MF_MT + ((p->btMode && p->algo) ? 2 : 1); + #else + 1; + #endif +} + +UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2) +{ + CLzmaEncProps props = *props2; + LzmaEncProps_Normalize(&props); + return props.dictSize; +} + +/* #define LZMA_LOG_BSR */ +/* Define it for Intel's CPU */ + + +#ifdef LZMA_LOG_BSR + +#define kDicLogSizeMaxCompress 30 + +#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); } + +UInt32 GetPosSlot1(UInt32 pos) +{ + UInt32 res; + BSR2_RET(pos, res); + return res; +} +#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); } +#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); } + +#else + +#define kNumLogBits (9 + (int)sizeof(size_t) / 2) +#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7) + +void LzmaEnc_FastPosInit(Byte *g_FastPos) +{ + int c = 2, slotFast; + g_FastPos[0] = 0; + g_FastPos[1] = 1; + + for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++) + { + UInt32 k = (1 << ((slotFast >> 1) - 1)); + UInt32 j; + for (j = 0; j < k; j++, c++) + g_FastPos[c] = (Byte)slotFast; + } +} + +#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \ + (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \ + res = p->g_FastPos[pos >> i] + (i * 2); } +/* +#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \ + p->g_FastPos[pos >> 6] + 12 : \ + p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; } +*/ + +#define GetPosSlot1(pos) p->g_FastPos[pos] +#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); } +#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(pos, res); } + +#endif + + +#define LZMA_NUM_REPS 4 + +typedef unsigned CState; + +typedef struct _COptimal +{ + UInt32 price; + + CState state; + int prev1IsChar; + int prev2; + + UInt32 posPrev2; + UInt32 backPrev2; + + UInt32 posPrev; + UInt32 backPrev; + UInt32 backs[LZMA_NUM_REPS]; +} COptimal; + +#define kNumOpts (1 << 12) + +#define kNumLenToPosStates 4 +#define kNumPosSlotBits 6 +#define kDicLogSizeMin 0 +#define kDicLogSizeMax 32 +#define kDistTableSizeMax (kDicLogSizeMax * 2) + + +#define kNumAlignBits 4 +#define kAlignTableSize (1 << kNumAlignBits) +#define kAlignMask (kAlignTableSize - 1) + +#define kStartPosModelIndex 4 +#define kEndPosModelIndex 14 +#define kNumPosModels (kEndPosModelIndex - kStartPosModelIndex) + +#define kNumFullDistances (1 << (kEndPosModelIndex / 2)) + +#ifdef _LZMA_PROB32 +#define CLzmaProb UInt32 +#else +#define CLzmaProb UInt16 +#endif + +#define LZMA_PB_MAX 4 +#define LZMA_LC_MAX 8 +#define LZMA_LP_MAX 4 + +#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX) + + +#define kLenNumLowBits 3 +#define kLenNumLowSymbols (1 << kLenNumLowBits) +#define kLenNumMidBits 3 +#define kLenNumMidSymbols (1 << kLenNumMidBits) +#define kLenNumHighBits 8 +#define kLenNumHighSymbols (1 << kLenNumHighBits) + +#define kLenNumSymbolsTotal (kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols) + +#define LZMA_MATCH_LEN_MIN 2 +#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1) + +#define kNumStates 12 + +typedef struct +{ + CLzmaProb choice; + CLzmaProb choice2; + CLzmaProb low[LZMA_NUM_PB_STATES_MAX << kLenNumLowBits]; + CLzmaProb mid[LZMA_NUM_PB_STATES_MAX << kLenNumMidBits]; + CLzmaProb high[kLenNumHighSymbols]; +} CLenEnc; + +typedef struct +{ + CLenEnc p; + UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal]; + UInt32 tableSize; + UInt32 counters[LZMA_NUM_PB_STATES_MAX]; +} CLenPriceEnc; + +typedef struct _CRangeEnc +{ + UInt32 range; + Byte cache; + UInt64 low; + UInt64 cacheSize; + Byte *buf; + Byte *bufLim; + Byte *bufBase; + ISeqOutStream *outStream; + UInt64 processed; + SRes res; +} CRangeEnc; + +typedef struct _CSeqInStreamBuf +{ + ISeqInStream funcTable; + const Byte *data; + SizeT rem; +} CSeqInStreamBuf; + +static SRes MyRead(void *pp, void *data, size_t *size) +{ + size_t curSize = *size; + CSeqInStreamBuf *p = (CSeqInStreamBuf *)pp; + if (p->rem < curSize) + curSize = p->rem; + memcpy(data, p->data, curSize); + p->rem -= curSize; + p->data += curSize; + *size = curSize; + return SZ_OK; +} + +typedef struct +{ + CLzmaProb *litProbs; + + CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX]; + CLzmaProb isRep[kNumStates]; + CLzmaProb isRepG0[kNumStates]; + CLzmaProb isRepG1[kNumStates]; + CLzmaProb isRepG2[kNumStates]; + CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX]; + + CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits]; + CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex]; + CLzmaProb posAlignEncoder[1 << kNumAlignBits]; + + CLenPriceEnc lenEnc; + CLenPriceEnc repLenEnc; + + UInt32 reps[LZMA_NUM_REPS]; + UInt32 state; +} CSaveState; + +typedef struct _CLzmaEnc +{ + IMatchFinder matchFinder; + void *matchFinderObj; + + #ifdef COMPRESS_MF_MT + Bool mtMode; + CMatchFinderMt matchFinderMt; + #endif + + CMatchFinder matchFinderBase; + + #ifdef COMPRESS_MF_MT + Byte pad[128]; + #endif + + UInt32 optimumEndIndex; + UInt32 optimumCurrentIndex; + + UInt32 longestMatchLength; + UInt32 numPairs; + UInt32 numAvail; + COptimal opt[kNumOpts]; + + #ifndef LZMA_LOG_BSR + Byte g_FastPos[1 << kNumLogBits]; + #endif + + UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits]; + UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1]; + UInt32 numFastBytes; + UInt32 additionalOffset; + UInt32 reps[LZMA_NUM_REPS]; + UInt32 state; + + UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax]; + UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances]; + UInt32 alignPrices[kAlignTableSize]; + UInt32 alignPriceCount; + + UInt32 distTableSize; + + unsigned lc, lp, pb; + unsigned lpMask, pbMask; + + CLzmaProb *litProbs; + + CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX]; + CLzmaProb isRep[kNumStates]; + CLzmaProb isRepG0[kNumStates]; + CLzmaProb isRepG1[kNumStates]; + CLzmaProb isRepG2[kNumStates]; + CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX]; + + CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits]; + CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex]; + CLzmaProb posAlignEncoder[1 << kNumAlignBits]; + + CLenPriceEnc lenEnc; + CLenPriceEnc repLenEnc; + + unsigned lclp; + + Bool fastMode; + + CRangeEnc rc; + + Bool writeEndMark; + UInt64 nowPos64; + UInt32 matchPriceCount; + Bool finished; + Bool multiThread; + + SRes result; + UInt32 dictSize; + UInt32 matchFinderCycles; + + ISeqInStream *inStream; + CSeqInStreamBuf seqBufInStream; + + CSaveState saveState; +} CLzmaEnc; + +void LzmaEnc_SaveState(CLzmaEncHandle pp) +{ + CLzmaEnc *p = (CLzmaEnc *)pp; + CSaveState *dest = &p->saveState; + int i; + dest->lenEnc = p->lenEnc; + dest->repLenEnc = p->repLenEnc; + dest->state = p->state; + + for (i = 0; i < kNumStates; i++) + { + memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i])); + memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i])); + } + for (i = 0; i < kNumLenToPosStates; i++) + memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i])); + memcpy(dest->isRep, p->isRep, sizeof(p->isRep)); + memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0)); + memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1)); + memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2)); + memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders)); + memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder)); + memcpy(dest->reps, p->reps, sizeof(p->reps)); + memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb)); +} + +void LzmaEnc_RestoreState(CLzmaEncHandle pp) +{ + CLzmaEnc *dest = (CLzmaEnc *)pp; + const CSaveState *p = &dest->saveState; + int i; + dest->lenEnc = p->lenEnc; + dest->repLenEnc = p->repLenEnc; + dest->state = p->state; + + for (i = 0; i < kNumStates; i++) + { + memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i])); + memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i])); + } + for (i = 0; i < kNumLenToPosStates; i++) + memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i])); + memcpy(dest->isRep, p->isRep, sizeof(p->isRep)); + memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0)); + memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1)); + memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2)); + memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders)); + memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder)); + memcpy(dest->reps, p->reps, sizeof(p->reps)); + memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb)); +} + +SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2) +{ + CLzmaEnc *p = (CLzmaEnc *)pp; + CLzmaEncProps props = *props2; + LzmaEncProps_Normalize(&props); + + if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX || + props.dictSize > (1 << kDicLogSizeMaxCompress) || props.dictSize > (1 << 30)) + return SZ_ERROR_PARAM; + p->dictSize = props.dictSize; + p->matchFinderCycles = props.mc; + { + unsigned fb = props.fb; + if (fb < 5) + fb = 5; + if (fb > LZMA_MATCH_LEN_MAX) + fb = LZMA_MATCH_LEN_MAX; + p->numFastBytes = fb; + } + p->lc = props.lc; + p->lp = props.lp; + p->pb = props.pb; + p->fastMode = (props.algo == 0); + p->matchFinderBase.btMode = props.btMode; + { + UInt32 numHashBytes = 4; + if (props.btMode) + { + if (props.numHashBytes < 2) + numHashBytes = 2; + else if (props.numHashBytes < 4) + numHashBytes = props.numHashBytes; + } + p->matchFinderBase.numHashBytes = numHashBytes; + } + + p->matchFinderBase.cutValue = props.mc; + + p->writeEndMark = props.writeEndMark; + + #ifdef COMPRESS_MF_MT + /* + if (newMultiThread != _multiThread) + { + ReleaseMatchFinder(); + _multiThread = newMultiThread; + } + */ + p->multiThread = (props.numThreads > 1); + #endif + + return SZ_OK; +} + +static const int kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5}; +static const int kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10}; +static const int kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11}; +static const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11}; + +#define IsCharState(s) ((s) < 7) + +#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1) + +#define kInfinityPrice (1 << 30) + +static void RangeEnc_Construct(CRangeEnc *p) +{ + p->outStream = 0; + p->bufBase = 0; +} + +#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize) + +#define RC_BUF_SIZE (1 << 16) +static int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc) +{ + if (p->bufBase == 0) + { + p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE); + if (p->bufBase == 0) + return 0; + p->bufLim = p->bufBase + RC_BUF_SIZE; + } + return 1; +} + +static void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc) +{ + alloc->Free(alloc, p->bufBase); + p->bufBase = 0; +} + +static void RangeEnc_Init(CRangeEnc *p) +{ + /* Stream.Init(); */ + p->low = 0; + p->range = 0xFFFFFFFF; + p->cacheSize = 1; + p->cache = 0; + + p->buf = p->bufBase; + + p->processed = 0; + p->res = SZ_OK; +} + +static void RangeEnc_FlushStream(CRangeEnc *p) +{ + size_t num; + if (p->res != SZ_OK) + return; + num = p->buf - p->bufBase; + if (num != p->outStream->Write(p->outStream, p->bufBase, num)) + p->res = SZ_ERROR_WRITE; + p->processed += num; + p->buf = p->bufBase; +} + +static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p) +{ + if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0) + { + Byte temp = p->cache; + do + { + Byte *buf = p->buf; + *buf++ = (Byte)(temp + (Byte)(p->low >> 32)); + p->buf = buf; + if (buf == p->bufLim) + RangeEnc_FlushStream(p); + temp = 0xFF; + } + while (--p->cacheSize != 0); + p->cache = (Byte)((UInt32)p->low >> 24); + } + p->cacheSize++; + p->low = (UInt32)p->low << 8; +} + +static void RangeEnc_FlushData(CRangeEnc *p) +{ + int i; + for (i = 0; i < 5; i++) + RangeEnc_ShiftLow(p); +} + +static void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, int numBits) +{ + do + { + p->range >>= 1; + p->low += p->range & (0 - ((value >> --numBits) & 1)); + if (p->range < kTopValue) + { + p->range <<= 8; + RangeEnc_ShiftLow(p); + } + } + while (numBits != 0); +} + +static void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol) +{ + UInt32 ttt = *prob; + UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt; + if (symbol == 0) + { + p->range = newBound; + ttt += (kBitModelTotal - ttt) >> kNumMoveBits; + } + else + { + p->low += newBound; + p->range -= newBound; + ttt -= ttt >> kNumMoveBits; + } + *prob = (CLzmaProb)ttt; + if (p->range < kTopValue) + { + p->range <<= 8; + RangeEnc_ShiftLow(p); + } +} + +static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol) +{ + symbol |= 0x100; + do + { + RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1); + symbol <<= 1; + } + while (symbol < 0x10000); +} + +static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte) +{ + UInt32 offs = 0x100; + symbol |= 0x100; + do + { + matchByte <<= 1; + RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1); + symbol <<= 1; + offs &= ~(matchByte ^ symbol); + } + while (symbol < 0x10000); +} + +void LzmaEnc_InitPriceTables(UInt32 *ProbPrices) +{ + UInt32 i; + for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits)) + { + const int kCyclesBits = kNumBitPriceShiftBits; + UInt32 w = i; + UInt32 bitCount = 0; + int j; + for (j = 0; j < kCyclesBits; j++) + { + w = w * w; + bitCount <<= 1; + while (w >= ((UInt32)1 << 16)) + { + w >>= 1; + bitCount++; + } + } + ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount); + } +} + + +#define GET_PRICE(prob, symbol) \ + p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits]; + +#define GET_PRICEa(prob, symbol) \ + ProbPrices[((prob) ^ ((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits]; + +#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits] +#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits] + +#define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits] +#define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits] + +static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *ProbPrices) +{ + UInt32 price = 0; + symbol |= 0x100; + do + { + price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1); + symbol <<= 1; + } + while (symbol < 0x10000); + return price; +} + +static UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, UInt32 *ProbPrices) +{ + UInt32 price = 0; + UInt32 offs = 0x100; + symbol |= 0x100; + do + { + matchByte <<= 1; + price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1); + symbol <<= 1; + offs &= ~(matchByte ^ symbol); + } + while (symbol < 0x10000); + return price; +} + + +static void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol) +{ + UInt32 m = 1; + int i; + for (i = numBitLevels; i != 0;) + { + UInt32 bit; + i--; + bit = (symbol >> i) & 1; + RangeEnc_EncodeBit(rc, probs + m, bit); + m = (m << 1) | bit; + } +} + +static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol) +{ + UInt32 m = 1; + int i; + for (i = 0; i < numBitLevels; i++) + { + UInt32 bit = symbol & 1; + RangeEnc_EncodeBit(rc, probs + m, bit); + m = (m << 1) | bit; + symbol >>= 1; + } +} + +static UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices) +{ + UInt32 price = 0; + symbol |= (1 << numBitLevels); + while (symbol != 1) + { + price += GET_PRICEa(probs[symbol >> 1], symbol & 1); + symbol >>= 1; + } + return price; +} + +static UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices) +{ + UInt32 price = 0; + UInt32 m = 1; + int i; + for (i = numBitLevels; i != 0; i--) + { + UInt32 bit = symbol & 1; + symbol >>= 1; + price += GET_PRICEa(probs[m], bit); + m = (m << 1) | bit; + } + return price; +} + + +static void LenEnc_Init(CLenEnc *p) +{ + unsigned i; + p->choice = p->choice2 = kProbInitValue; + for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++) + p->low[i] = kProbInitValue; + for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++) + p->mid[i] = kProbInitValue; + for (i = 0; i < kLenNumHighSymbols; i++) + p->high[i] = kProbInitValue; +} + +static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState) +{ + if (symbol < kLenNumLowSymbols) + { + RangeEnc_EncodeBit(rc, &p->choice, 0); + RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol); + } + else + { + RangeEnc_EncodeBit(rc, &p->choice, 1); + if (symbol < kLenNumLowSymbols + kLenNumMidSymbols) + { + RangeEnc_EncodeBit(rc, &p->choice2, 0); + RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbols); + } + else + { + RangeEnc_EncodeBit(rc, &p->choice2, 1); + RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols); + } + } +} + +static void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32 *ProbPrices) +{ + UInt32 a0 = GET_PRICE_0a(p->choice); + UInt32 a1 = GET_PRICE_1a(p->choice); + UInt32 b0 = a1 + GET_PRICE_0a(p->choice2); + UInt32 b1 = a1 + GET_PRICE_1a(p->choice2); + UInt32 i = 0; + for (i = 0; i < kLenNumLowSymbols; i++) + { + if (i >= numSymbols) + return; + prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPrices); + } + for (; i < kLenNumLowSymbols + kLenNumMidSymbols; i++) + { + if (i >= numSymbols) + return; + prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNumLowSymbols, ProbPrices); + } + for (; i < numSymbols; i++) + prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices); +} + +static void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPrices) +{ + LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices); + p->counters[posState] = p->tableSize; +} + +static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices) +{ + UInt32 posState; + for (posState = 0; posState < numPosStates; posState++) + LenPriceEnc_UpdateTable(p, posState, ProbPrices); +} + +static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, UInt32 *ProbPrices) +{ + LenEnc_Encode(&p->p, rc, symbol, posState); + if (updatePrice) + if (--p->counters[posState] == 0) + LenPriceEnc_UpdateTable(p, posState, ProbPrices); +} + + + + +static void MovePos(CLzmaEnc *p, UInt32 num) +{ + #ifdef SHOW_STAT + ttt += num; + printf("\n MovePos %d", num); + #endif + if (num != 0) + { + p->additionalOffset += num; + p->matchFinder.Skip(p->matchFinderObj, num); + } +} + +static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes) +{ + UInt32 lenRes = 0, numPairs; + p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj); + numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches); + #ifdef SHOW_STAT + printf("\n i = %d numPairs = %d ", ttt, numPairs / 2); + ttt++; + { + UInt32 i; + for (i = 0; i < numPairs; i += 2) + printf("%2d %6d | ", p->matches[i], p->matches[i + 1]); + } + #endif + if (numPairs > 0) + { + lenRes = p->matches[numPairs - 2]; + if (lenRes == p->numFastBytes) + { + const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; + UInt32 distance = p->matches[numPairs - 1] + 1; + UInt32 numAvail = p->numAvail; + if (numAvail > LZMA_MATCH_LEN_MAX) + numAvail = LZMA_MATCH_LEN_MAX; + { + const Byte *pby2 = pby - distance; + for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++); + } + } + } + p->additionalOffset++; + *numDistancePairsRes = numPairs; + return lenRes; +} + + +#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False; +#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False; +#define IsShortRep(p) ((p)->backPrev == 0) + +static UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState) +{ + return + GET_PRICE_0(p->isRepG0[state]) + + GET_PRICE_0(p->isRep0Long[state][posState]); +} + +static UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState) +{ + UInt32 price; + if (repIndex == 0) + { + price = GET_PRICE_0(p->isRepG0[state]); + price += GET_PRICE_1(p->isRep0Long[state][posState]); + } + else + { + price = GET_PRICE_1(p->isRepG0[state]); + if (repIndex == 1) + price += GET_PRICE_0(p->isRepG1[state]); + else + { + price += GET_PRICE_1(p->isRepG1[state]); + price += GET_PRICE(p->isRepG2[state], repIndex - 2); + } + } + return price; +} + +static UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState) +{ + return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] + + GetPureRepPrice(p, repIndex, state, posState); +} + +static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur) +{ + UInt32 posMem = p->opt[cur].posPrev; + UInt32 backMem = p->opt[cur].backPrev; + p->optimumEndIndex = cur; + do + { + if (p->opt[cur].prev1IsChar) + { + MakeAsChar(&p->opt[posMem]) + p->opt[posMem].posPrev = posMem - 1; + if (p->opt[cur].prev2) + { + p->opt[posMem - 1].prev1IsChar = False; + p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2; + p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2; + } + } + { + UInt32 posPrev = posMem; + UInt32 backCur = backMem; + + backMem = p->opt[posPrev].backPrev; + posMem = p->opt[posPrev].posPrev; + + p->opt[posPrev].backPrev = backCur; + p->opt[posPrev].posPrev = cur; + cur = posPrev; + } + } + while (cur != 0); + *backRes = p->opt[0].backPrev; + p->optimumCurrentIndex = p->opt[0].posPrev; + return p->optimumCurrentIndex; +} + +#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300) + +static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) +{ + UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur; + UInt32 matchPrice, repMatchPrice, normalMatchPrice; + UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS]; + UInt32 *matches; + const Byte *data; + Byte curByte, matchByte; + if (p->optimumEndIndex != p->optimumCurrentIndex) + { + const COptimal *opt = &p->opt[p->optimumCurrentIndex]; + UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex; + *backRes = opt->backPrev; + p->optimumCurrentIndex = opt->posPrev; + return lenRes; + } + p->optimumCurrentIndex = p->optimumEndIndex = 0; + + if (p->additionalOffset == 0) + mainLen = ReadMatchDistances(p, &numPairs); + else + { + mainLen = p->longestMatchLength; + numPairs = p->numPairs; + } + + numAvail = p->numAvail; + if (numAvail < 2) + { + *backRes = (UInt32)(-1); + return 1; + } + if (numAvail > LZMA_MATCH_LEN_MAX) + numAvail = LZMA_MATCH_LEN_MAX; + + data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; + repMaxIndex = 0; + for (i = 0; i < LZMA_NUM_REPS; i++) + { + UInt32 lenTest; + const Byte *data2; + reps[i] = p->reps[i]; + data2 = data - (reps[i] + 1); + if (data[0] != data2[0] || data[1] != data2[1]) + { + repLens[i] = 0; + continue; + } + for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++); + repLens[i] = lenTest; + if (lenTest > repLens[repMaxIndex]) + repMaxIndex = i; + } + if (repLens[repMaxIndex] >= p->numFastBytes) + { + UInt32 lenRes; + *backRes = repMaxIndex; + lenRes = repLens[repMaxIndex]; + MovePos(p, lenRes - 1); + return lenRes; + } + + matches = p->matches; + if (mainLen >= p->numFastBytes) + { + *backRes = matches[numPairs - 1] + LZMA_NUM_REPS; + MovePos(p, mainLen - 1); + return mainLen; + } + curByte = *data; + matchByte = *(data - (reps[0] + 1)); + + if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2) + { + *backRes = (UInt32)-1; + return 1; + } + + p->opt[0].state = (CState)p->state; + + posState = (position & p->pbMask); + + { + const CLzmaProb *probs = LIT_PROBS(position, *(data - 1)); + p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) + + (!IsCharState(p->state) ? + LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) : + LitEnc_GetPrice(probs, curByte, p->ProbPrices)); + } + + MakeAsChar(&p->opt[1]); + + matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]); + repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]); + + if (matchByte == curByte) + { + UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState); + if (shortRepPrice < p->opt[1].price) + { + p->opt[1].price = shortRepPrice; + MakeAsShortRep(&p->opt[1]); + } + } + lenEnd = ((mainLen >= repLens[repMaxIndex]) ? mainLen : repLens[repMaxIndex]); + + if (lenEnd < 2) + { + *backRes = p->opt[1].backPrev; + return 1; + } + + p->opt[1].posPrev = 0; + for (i = 0; i < LZMA_NUM_REPS; i++) + p->opt[0].backs[i] = reps[i]; + + len = lenEnd; + do + p->opt[len--].price = kInfinityPrice; + while (len >= 2); + + for (i = 0; i < LZMA_NUM_REPS; i++) + { + UInt32 repLen = repLens[i]; + UInt32 price; + if (repLen < 2) + continue; + price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState); + do + { + UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2]; + COptimal *opt = &p->opt[repLen]; + if (curAndLenPrice < opt->price) + { + opt->price = curAndLenPrice; + opt->posPrev = 0; + opt->backPrev = i; + opt->prev1IsChar = False; + } + } + while (--repLen >= 2); + } + + normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]); + + len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2); + if (len <= mainLen) + { + UInt32 offs = 0; + while (len > matches[offs]) + offs += 2; + for (; ; len++) + { + COptimal *opt; + UInt32 distance = matches[offs + 1]; + + UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN]; + UInt32 lenToPosState = GetLenToPosState(len); + if (distance < kNumFullDistances) + curAndLenPrice += p->distancesPrices[lenToPosState][distance]; + else + { + UInt32 slot; + GetPosSlot2(distance, slot); + curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot]; + } + opt = &p->opt[len]; + if (curAndLenPrice < opt->price) + { + opt->price = curAndLenPrice; + opt->posPrev = 0; + opt->backPrev = distance + LZMA_NUM_REPS; + opt->prev1IsChar = False; + } + if (len == matches[offs]) + { + offs += 2; + if (offs == numPairs) + break; + } + } + } + + cur = 0; + + #ifdef SHOW_STAT2 + if (position >= 0) + { + unsigned i; + printf("\n pos = %4X", position); + for (i = cur; i <= lenEnd; i++) + printf("\nprice[%4X] = %d", position - cur + i, p->opt[i].price); + } + #endif + + for (;;) + { + UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen; + UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice; + Bool nextIsChar; + Byte curByte, matchByte; + const Byte *data; + COptimal *curOpt; + COptimal *nextOpt; + + cur++; + if (cur == lenEnd) + return Backward(p, backRes, cur); + + newLen = ReadMatchDistances(p, &numPairs); + if (newLen >= p->numFastBytes) + { + p->numPairs = numPairs; + p->longestMatchLength = newLen; + return Backward(p, backRes, cur); + } + position++; + curOpt = &p->opt[cur]; + posPrev = curOpt->posPrev; + if (curOpt->prev1IsChar) + { + posPrev--; + if (curOpt->prev2) + { + state = p->opt[curOpt->posPrev2].state; + if (curOpt->backPrev2 < LZMA_NUM_REPS) + state = kRepNextStates[state]; + else + state = kMatchNextStates[state]; + } + else + state = p->opt[posPrev].state; + state = kLiteralNextStates[state]; + } + else + state = p->opt[posPrev].state; + if (posPrev == cur - 1) + { + if (IsShortRep(curOpt)) + state = kShortRepNextStates[state]; + else + state = kLiteralNextStates[state]; + } + else + { + UInt32 pos; + const COptimal *prevOpt; + if (curOpt->prev1IsChar && curOpt->prev2) + { + posPrev = curOpt->posPrev2; + pos = curOpt->backPrev2; + state = kRepNextStates[state]; + } + else + { + pos = curOpt->backPrev; + if (pos < LZMA_NUM_REPS) + state = kRepNextStates[state]; + else + state = kMatchNextStates[state]; + } + prevOpt = &p->opt[posPrev]; + if (pos < LZMA_NUM_REPS) + { + UInt32 i; + reps[0] = prevOpt->backs[pos]; + for (i = 1; i <= pos; i++) + reps[i] = prevOpt->backs[i - 1]; + for (; i < LZMA_NUM_REPS; i++) + reps[i] = prevOpt->backs[i]; + } + else + { + UInt32 i; + reps[0] = (pos - LZMA_NUM_REPS); + for (i = 1; i < LZMA_NUM_REPS; i++) + reps[i] = prevOpt->backs[i - 1]; + } + } + curOpt->state = (CState)state; + + curOpt->backs[0] = reps[0]; + curOpt->backs[1] = reps[1]; + curOpt->backs[2] = reps[2]; + curOpt->backs[3] = reps[3]; + + curPrice = curOpt->price; + nextIsChar = False; + data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; + curByte = *data; + matchByte = *(data - (reps[0] + 1)); + + posState = (position & p->pbMask); + + curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]); + { + const CLzmaProb *probs = LIT_PROBS(position, *(data - 1)); + curAnd1Price += + (!IsCharState(state) ? + LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) : + LitEnc_GetPrice(probs, curByte, p->ProbPrices)); + } + + nextOpt = &p->opt[cur + 1]; + + if (curAnd1Price < nextOpt->price) + { + nextOpt->price = curAnd1Price; + nextOpt->posPrev = cur; + MakeAsChar(nextOpt); + nextIsChar = True; + } + + matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]); + repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]); + + if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0)) + { + UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState); + if (shortRepPrice <= nextOpt->price) + { + nextOpt->price = shortRepPrice; + nextOpt->posPrev = cur; + MakeAsShortRep(nextOpt); + nextIsChar = True; + } + } + numAvailFull = p->numAvail; + { + UInt32 temp = kNumOpts - 1 - cur; + if (temp < numAvailFull) + numAvailFull = temp; + } + + if (numAvailFull < 2) + continue; + numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes); + + if (!nextIsChar && matchByte != curByte) /* speed optimization */ + { + /* try Literal + rep0 */ + UInt32 temp; + UInt32 lenTest2; + const Byte *data2 = data - (reps[0] + 1); + UInt32 limit = p->numFastBytes + 1; + if (limit > numAvailFull) + limit = numAvailFull; + + for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++); + lenTest2 = temp - 1; + if (lenTest2 >= 2) + { + UInt32 state2 = kLiteralNextStates[state]; + UInt32 posStateNext = (position + 1) & p->pbMask; + UInt32 nextRepMatchPrice = curAnd1Price + + GET_PRICE_1(p->isMatch[state2][posStateNext]) + + GET_PRICE_1(p->isRep[state2]); + /* for (; lenTest2 >= 2; lenTest2--) */ + { + UInt32 curAndLenPrice; + COptimal *opt; + UInt32 offset = cur + 1 + lenTest2; + while (lenEnd < offset) + p->opt[++lenEnd].price = kInfinityPrice; + curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext); + opt = &p->opt[offset]; + if (curAndLenPrice < opt->price) + { + opt->price = curAndLenPrice; + opt->posPrev = cur + 1; + opt->backPrev = 0; + opt->prev1IsChar = True; + opt->prev2 = False; + } + } + } + } + + startLen = 2; /* speed optimization */ + { + UInt32 repIndex; + for (repIndex = 0; repIndex < LZMA_NUM_REPS; repIndex++) + { + UInt32 lenTest; + UInt32 lenTestTemp; + UInt32 price; + const Byte *data2 = data - (reps[repIndex] + 1); + if (data[0] != data2[0] || data[1] != data2[1]) + continue; + for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++); + while (lenEnd < cur + lenTest) + p->opt[++lenEnd].price = kInfinityPrice; + lenTestTemp = lenTest; + price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState); + do + { + UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2]; + COptimal *opt = &p->opt[cur + lenTest]; + if (curAndLenPrice < opt->price) + { + opt->price = curAndLenPrice; + opt->posPrev = cur; + opt->backPrev = repIndex; + opt->prev1IsChar = False; + } + } + while (--lenTest >= 2); + lenTest = lenTestTemp; + + if (repIndex == 0) + startLen = lenTest + 1; + + /* if (_maxMode) */ + { + UInt32 lenTest2 = lenTest + 1; + UInt32 limit = lenTest2 + p->numFastBytes; + UInt32 nextRepMatchPrice; + if (limit > numAvailFull) + limit = numAvailFull; + for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++); + lenTest2 -= lenTest + 1; + if (lenTest2 >= 2) + { + UInt32 state2 = kRepNextStates[state]; + UInt32 posStateNext = (position + lenTest) & p->pbMask; + UInt32 curAndLenCharPrice = + price + p->repLenEnc.prices[posState][lenTest - 2] + + GET_PRICE_0(p->isMatch[state2][posStateNext]) + + LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]), + data[lenTest], data2[lenTest], p->ProbPrices); + state2 = kLiteralNextStates[state2]; + posStateNext = (position + lenTest + 1) & p->pbMask; + nextRepMatchPrice = curAndLenCharPrice + + GET_PRICE_1(p->isMatch[state2][posStateNext]) + + GET_PRICE_1(p->isRep[state2]); + + /* for (; lenTest2 >= 2; lenTest2--) */ + { + UInt32 curAndLenPrice; + COptimal *opt; + UInt32 offset = cur + lenTest + 1 + lenTest2; + while (lenEnd < offset) + p->opt[++lenEnd].price = kInfinityPrice; + curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext); + opt = &p->opt[offset]; + if (curAndLenPrice < opt->price) + { + opt->price = curAndLenPrice; + opt->posPrev = cur + lenTest + 1; + opt->backPrev = 0; + opt->prev1IsChar = True; + opt->prev2 = True; + opt->posPrev2 = cur; + opt->backPrev2 = repIndex; + } + } + } + } + } + } + /* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */ + if (newLen > numAvail) + { + newLen = numAvail; + for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2); + matches[numPairs] = newLen; + numPairs += 2; + } + if (newLen >= startLen) + { + UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]); + UInt32 offs, curBack, posSlot; + UInt32 lenTest; + while (lenEnd < cur + newLen) + p->opt[++lenEnd].price = kInfinityPrice; + + offs = 0; + while (startLen > matches[offs]) + offs += 2; + curBack = matches[offs + 1]; + GetPosSlot2(curBack, posSlot); + for (lenTest = /*2*/ startLen; ; lenTest++) + { + UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN]; + UInt32 lenToPosState = GetLenToPosState(lenTest); + COptimal *opt; + if (curBack < kNumFullDistances) + curAndLenPrice += p->distancesPrices[lenToPosState][curBack]; + else + curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask]; + + opt = &p->opt[cur + lenTest]; + if (curAndLenPrice < opt->price) + { + opt->price = curAndLenPrice; + opt->posPrev = cur; + opt->backPrev = curBack + LZMA_NUM_REPS; + opt->prev1IsChar = False; + } + + if (/*_maxMode && */lenTest == matches[offs]) + { + /* Try Match + Literal + Rep0 */ + const Byte *data2 = data - (curBack + 1); + UInt32 lenTest2 = lenTest + 1; + UInt32 limit = lenTest2 + p->numFastBytes; + UInt32 nextRepMatchPrice; + if (limit > numAvailFull) + limit = numAvailFull; + for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++); + lenTest2 -= lenTest + 1; + if (lenTest2 >= 2) + { + UInt32 state2 = kMatchNextStates[state]; + UInt32 posStateNext = (position + lenTest) & p->pbMask; + UInt32 curAndLenCharPrice = curAndLenPrice + + GET_PRICE_0(p->isMatch[state2][posStateNext]) + + LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]), + data[lenTest], data2[lenTest], p->ProbPrices); + state2 = kLiteralNextStates[state2]; + posStateNext = (posStateNext + 1) & p->pbMask; + nextRepMatchPrice = curAndLenCharPrice + + GET_PRICE_1(p->isMatch[state2][posStateNext]) + + GET_PRICE_1(p->isRep[state2]); + + /* for (; lenTest2 >= 2; lenTest2--) */ + { + UInt32 offset = cur + lenTest + 1 + lenTest2; + UInt32 curAndLenPrice; + COptimal *opt; + while (lenEnd < offset) + p->opt[++lenEnd].price = kInfinityPrice; + curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext); + opt = &p->opt[offset]; + if (curAndLenPrice < opt->price) + { + opt->price = curAndLenPrice; + opt->posPrev = cur + lenTest + 1; + opt->backPrev = 0; + opt->prev1IsChar = True; + opt->prev2 = True; + opt->posPrev2 = cur; + opt->backPrev2 = curBack + LZMA_NUM_REPS; + } + } + } + offs += 2; + if (offs == numPairs) + break; + curBack = matches[offs + 1]; + if (curBack >= kNumFullDistances) + GetPosSlot2(curBack, posSlot); + } + } + } + } +} + +#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist)) + +static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes) +{ + UInt32 numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i; + const Byte *data; + const UInt32 *matches; + + if (p->additionalOffset == 0) + mainLen = ReadMatchDistances(p, &numPairs); + else + { + mainLen = p->longestMatchLength; + numPairs = p->numPairs; + } + + numAvail = p->numAvail; + *backRes = (UInt32)-1; + if (numAvail < 2) + return 1; + if (numAvail > LZMA_MATCH_LEN_MAX) + numAvail = LZMA_MATCH_LEN_MAX; + data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; + + repLen = repIndex = 0; + for (i = 0; i < LZMA_NUM_REPS; i++) + { + UInt32 len; + const Byte *data2 = data - (p->reps[i] + 1); + if (data[0] != data2[0] || data[1] != data2[1]) + continue; + for (len = 2; len < numAvail && data[len] == data2[len]; len++); + if (len >= p->numFastBytes) + { + *backRes = i; + MovePos(p, len - 1); + return len; + } + if (len > repLen) + { + repIndex = i; + repLen = len; + } + } + + matches = p->matches; + if (mainLen >= p->numFastBytes) + { + *backRes = matches[numPairs - 1] + LZMA_NUM_REPS; + MovePos(p, mainLen - 1); + return mainLen; + } + + mainDist = 0; /* for GCC */ + if (mainLen >= 2) + { + mainDist = matches[numPairs - 1]; + while (numPairs > 2 && mainLen == matches[numPairs - 4] + 1) + { + if (!ChangePair(matches[numPairs - 3], mainDist)) + break; + numPairs -= 2; + mainLen = matches[numPairs - 2]; + mainDist = matches[numPairs - 1]; + } + if (mainLen == 2 && mainDist >= 0x80) + mainLen = 1; + } + + if (repLen >= 2 && ( + (repLen + 1 >= mainLen) || + (repLen + 2 >= mainLen && mainDist >= (1 << 9)) || + (repLen + 3 >= mainLen && mainDist >= (1 << 15)))) + { + *backRes = repIndex; + MovePos(p, repLen - 1); + return repLen; + } + + if (mainLen < 2 || numAvail <= 2) + return 1; + + p->longestMatchLength = ReadMatchDistances(p, &p->numPairs); + if (p->longestMatchLength >= 2) + { + UInt32 newDistance = matches[p->numPairs - 1]; + if ((p->longestMatchLength >= mainLen && newDistance < mainDist) || + (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) || + (p->longestMatchLength > mainLen + 1) || + (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist))) + return 1; + } + + data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; + for (i = 0; i < LZMA_NUM_REPS; i++) + { + UInt32 len, limit; + const Byte *data2 = data - (p->reps[i] + 1); + if (data[0] != data2[0] || data[1] != data2[1]) + continue; + limit = mainLen - 1; + for (len = 2; len < limit && data[len] == data2[len]; len++); + if (len >= limit) + return 1; + } + *backRes = mainDist + LZMA_NUM_REPS; + MovePos(p, mainLen - 2); + return mainLen; +} + +static void WriteEndMarker(CLzmaEnc *p, UInt32 posState) +{ + UInt32 len; + RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1); + RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0); + p->state = kMatchNextStates[p->state]; + len = LZMA_MATCH_LEN_MIN; + LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices); + RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlotBits) - 1); + RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits); + RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask); +} + +static SRes CheckErrors(CLzmaEnc *p) +{ + if (p->result != SZ_OK) + return p->result; + if (p->rc.res != SZ_OK) + p->result = SZ_ERROR_WRITE; + if (p->matchFinderBase.result != SZ_OK) + p->result = SZ_ERROR_READ; + if (p->result != SZ_OK) + p->finished = True; + return p->result; +} + +static SRes Flush(CLzmaEnc *p, UInt32 nowPos) +{ + /* ReleaseMFStream(); */ + p->finished = True; + if (p->writeEndMark) + WriteEndMarker(p, nowPos & p->pbMask); + RangeEnc_FlushData(&p->rc); + RangeEnc_FlushStream(&p->rc); + return CheckErrors(p); +} + +static void FillAlignPrices(CLzmaEnc *p) +{ + UInt32 i; + for (i = 0; i < kAlignTableSize; i++) + p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices); + p->alignPriceCount = 0; +} + +static void FillDistancesPrices(CLzmaEnc *p) +{ + UInt32 tempPrices[kNumFullDistances]; + UInt32 i, lenToPosState; + for (i = kStartPosModelIndex; i < kNumFullDistances; i++) + { + UInt32 posSlot = GetPosSlot1(i); + UInt32 footerBits = ((posSlot >> 1) - 1); + UInt32 base = ((2 | (posSlot & 1)) << footerBits); + tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, p->ProbPrices); + } + + for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++) + { + UInt32 posSlot; + const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState]; + UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState]; + for (posSlot = 0; posSlot < p->distTableSize; posSlot++) + posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices); + for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++) + posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits); + + { + UInt32 *distancesPrices = p->distancesPrices[lenToPosState]; + UInt32 i; + for (i = 0; i < kStartPosModelIndex; i++) + distancesPrices[i] = posSlotPrices[i]; + for (; i < kNumFullDistances; i++) + distancesPrices[i] = posSlotPrices[GetPosSlot1(i)] + tempPrices[i]; + } + } + p->matchPriceCount = 0; +} + +void LzmaEnc_Construct(CLzmaEnc *p) +{ + RangeEnc_Construct(&p->rc); + MatchFinder_Construct(&p->matchFinderBase); + #ifdef COMPRESS_MF_MT + MatchFinderMt_Construct(&p->matchFinderMt); + p->matchFinderMt.MatchFinder = &p->matchFinderBase; + #endif + + { + CLzmaEncProps props; + LzmaEncProps_Init(&props); + LzmaEnc_SetProps(p, &props); + } + + #ifndef LZMA_LOG_BSR + LzmaEnc_FastPosInit(p->g_FastPos); + #endif + + LzmaEnc_InitPriceTables(p->ProbPrices); + p->litProbs = 0; + p->saveState.litProbs = 0; +} + +CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc) +{ + void *p; + p = alloc->Alloc(alloc, sizeof(CLzmaEnc)); + if (p != 0) + LzmaEnc_Construct((CLzmaEnc *)p); + return p; +} + +void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc) +{ + alloc->Free(alloc, p->litProbs); + alloc->Free(alloc, p->saveState.litProbs); + p->litProbs = 0; + p->saveState.litProbs = 0; +} + +void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig) +{ + #ifdef COMPRESS_MF_MT + MatchFinderMt_Destruct(&p->matchFinderMt, allocBig); + #endif + MatchFinder_Free(&p->matchFinderBase, allocBig); + LzmaEnc_FreeLits(p, alloc); + RangeEnc_Free(&p->rc, alloc); +} + +void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig) +{ + LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig); + alloc->Free(alloc, p); +} + +static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize) +{ + UInt32 nowPos32, startPos32; + if (p->inStream != 0) + { + p->matchFinderBase.stream = p->inStream; + p->matchFinder.Init(p->matchFinderObj); + p->inStream = 0; + } + + if (p->finished) + return p->result; + RINOK(CheckErrors(p)); + + nowPos32 = (UInt32)p->nowPos64; + startPos32 = nowPos32; + + if (p->nowPos64 == 0) + { + UInt32 numPairs; + Byte curByte; + if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0) + return Flush(p, nowPos32); + ReadMatchDistances(p, &numPairs); + RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0); + p->state = kLiteralNextStates[p->state]; + curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset); + LitEnc_Encode(&p->rc, p->litProbs, curByte); + p->additionalOffset--; + nowPos32++; + } + + if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0) + for (;;) + { + UInt32 pos, len, posState; + + if (p->fastMode) + len = GetOptimumFast(p, &pos); + else + len = GetOptimum(p, nowPos32, &pos); + + #ifdef SHOW_STAT2 + printf("\n pos = %4X, len = %d pos = %d", nowPos32, len, pos); + #endif + + posState = nowPos32 & p->pbMask; + if (len == 1 && pos == (UInt32)-1) + { + Byte curByte; + CLzmaProb *probs; + const Byte *data; + + RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0); + data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset; + curByte = *data; + probs = LIT_PROBS(nowPos32, *(data - 1)); + if (IsCharState(p->state)) + LitEnc_Encode(&p->rc, probs, curByte); + else + LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1)); + p->state = kLiteralNextStates[p->state]; + } + else + { + RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1); + if (pos < LZMA_NUM_REPS) + { + RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1); + if (pos == 0) + { + RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0); + RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1)); + } + else + { + UInt32 distance = p->reps[pos]; + RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1); + if (pos == 1) + RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0); + else + { + RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1); + RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2); + if (pos == 3) + p->reps[3] = p->reps[2]; + p->reps[2] = p->reps[1]; + } + p->reps[1] = p->reps[0]; + p->reps[0] = distance; + } + if (len == 1) + p->state = kShortRepNextStates[p->state]; + else + { + LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices); + p->state = kRepNextStates[p->state]; + } + } + else + { + UInt32 posSlot; + RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0); + p->state = kMatchNextStates[p->state]; + LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices); + pos -= LZMA_NUM_REPS; + GetPosSlot(pos, posSlot); + RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot); + + if (posSlot >= kStartPosModelIndex) + { + UInt32 footerBits = ((posSlot >> 1) - 1); + UInt32 base = ((2 | (posSlot & 1)) << footerBits); + UInt32 posReduced = pos - base; + + if (posSlot < kEndPosModelIndex) + RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced); + else + { + RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits); + RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask); + p->alignPriceCount++; + } + } + p->reps[3] = p->reps[2]; + p->reps[2] = p->reps[1]; + p->reps[1] = p->reps[0]; + p->reps[0] = pos; + p->matchPriceCount++; + } + } + p->additionalOffset -= len; + nowPos32 += len; + if (p->additionalOffset == 0) + { + UInt32 processed; + if (!p->fastMode) + { + if (p->matchPriceCount >= (1 << 7)) + FillDistancesPrices(p); + if (p->alignPriceCount >= kAlignTableSize) + FillAlignPrices(p); + } + if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0) + break; + processed = nowPos32 - startPos32; + if (useLimits) + { + if (processed + kNumOpts + 300 >= maxUnpackSize || + RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize) + break; + } + else if (processed >= (1 << 15)) + { + p->nowPos64 += nowPos32 - startPos32; + return CheckErrors(p); + } + } + } + p->nowPos64 += nowPos32 - startPos32; + return Flush(p, nowPos32); +} + +#define kBigHashDicLimit ((UInt32)1 << 24) + +static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) +{ + UInt32 beforeSize = kNumOpts; + Bool btMode; + if (!RangeEnc_Alloc(&p->rc, alloc)) + return SZ_ERROR_MEM; + btMode = (p->matchFinderBase.btMode != 0); + #ifdef COMPRESS_MF_MT + p->mtMode = (p->multiThread && !p->fastMode && btMode); + #endif + + { + unsigned lclp = p->lc + p->lp; + if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp) + { + LzmaEnc_FreeLits(p, alloc); + p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb)); + p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb)); + if (p->litProbs == 0 || p->saveState.litProbs == 0) + { + LzmaEnc_FreeLits(p, alloc); + return SZ_ERROR_MEM; + } + p->lclp = lclp; + } + } + + p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit); + + if (beforeSize + p->dictSize < keepWindowSize) + beforeSize = keepWindowSize - p->dictSize; + + #ifdef COMPRESS_MF_MT + if (p->mtMode) + { + RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig)); + p->matchFinderObj = &p->matchFinderMt; + MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder); + } + else + #endif + { + if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig)) + return SZ_ERROR_MEM; + p->matchFinderObj = &p->matchFinderBase; + MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder); + } + return SZ_OK; +} + +void LzmaEnc_Init(CLzmaEnc *p) +{ + UInt32 i; + p->state = 0; + for (i = 0 ; i < LZMA_NUM_REPS; i++) + p->reps[i] = 0; + + RangeEnc_Init(&p->rc); + + + for (i = 0; i < kNumStates; i++) + { + UInt32 j; + for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++) + { + p->isMatch[i][j] = kProbInitValue; + p->isRep0Long[i][j] = kProbInitValue; + } + p->isRep[i] = kProbInitValue; + p->isRepG0[i] = kProbInitValue; + p->isRepG1[i] = kProbInitValue; + p->isRepG2[i] = kProbInitValue; + } + + { + UInt32 num = 0x300 << (p->lp + p->lc); + for (i = 0; i < num; i++) + p->litProbs[i] = kProbInitValue; + } + + { + for (i = 0; i < kNumLenToPosStates; i++) + { + CLzmaProb *probs = p->posSlotEncoder[i]; + UInt32 j; + for (j = 0; j < (1 << kNumPosSlotBits); j++) + probs[j] = kProbInitValue; + } + } + { + for (i = 0; i < kNumFullDistances - kEndPosModelIndex; i++) + p->posEncoders[i] = kProbInitValue; + } + + LenEnc_Init(&p->lenEnc.p); + LenEnc_Init(&p->repLenEnc.p); + + for (i = 0; i < (1 << kNumAlignBits); i++) + p->posAlignEncoder[i] = kProbInitValue; + + p->optimumEndIndex = 0; + p->optimumCurrentIndex = 0; + p->additionalOffset = 0; + + p->pbMask = (1 << p->pb) - 1; + p->lpMask = (1 << p->lp) - 1; +} + +void LzmaEnc_InitPrices(CLzmaEnc *p) +{ + if (!p->fastMode) + { + FillDistancesPrices(p); + FillAlignPrices(p); + } + + p->lenEnc.tableSize = + p->repLenEnc.tableSize = + p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN; + LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices); + LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices); +} + +static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) +{ + UInt32 i; + for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++) + if (p->dictSize <= ((UInt32)1 << i)) + break; + p->distTableSize = i * 2; + + p->finished = False; + p->result = SZ_OK; + RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig)); + LzmaEnc_Init(p); + LzmaEnc_InitPrices(p); + p->nowPos64 = 0; + return SZ_OK; +} + +static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqInStream *inStream, ISeqOutStream *outStream, + ISzAlloc *alloc, ISzAlloc *allocBig) +{ + CLzmaEnc *p = (CLzmaEnc *)pp; + p->inStream = inStream; + p->rc.outStream = outStream; + return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig); +} + +SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp, + ISeqInStream *inStream, UInt32 keepWindowSize, + ISzAlloc *alloc, ISzAlloc *allocBig) +{ + CLzmaEnc *p = (CLzmaEnc *)pp; + p->inStream = inStream; + return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig); +} + +static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen) +{ + p->seqBufInStream.funcTable.Read = MyRead; + p->seqBufInStream.data = src; + p->seqBufInStream.rem = srcLen; +} + +SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen, + UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) +{ + CLzmaEnc *p = (CLzmaEnc *)pp; + LzmaEnc_SetInputBuf(p, src, srcLen); + p->inStream = &p->seqBufInStream.funcTable; + return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig); +} + +void LzmaEnc_Finish(CLzmaEncHandle pp) +{ + #ifdef COMPRESS_MF_MT + CLzmaEnc *p = (CLzmaEnc *)pp; + if (p->mtMode) + MatchFinderMt_ReleaseStream(&p->matchFinderMt); + #else + pp = pp; + #endif +} + +typedef struct _CSeqOutStreamBuf +{ + ISeqOutStream funcTable; + Byte *data; + SizeT rem; + Bool overflow; +} CSeqOutStreamBuf; + +static size_t MyWrite(void *pp, const void *data, size_t size) +{ + CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp; + if (p->rem < size) + { + size = p->rem; + p->overflow = True; + } + memcpy(p->data, data, size); + p->rem -= size; + p->data += size; + return size; +} + + +UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp) +{ + const CLzmaEnc *p = (CLzmaEnc *)pp; + return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj); +} + +const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp) +{ + const CLzmaEnc *p = (CLzmaEnc *)pp; + return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset; +} + +SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit, + Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize) +{ + CLzmaEnc *p = (CLzmaEnc *)pp; + UInt64 nowPos64; + SRes res; + CSeqOutStreamBuf outStream; + + outStream.funcTable.Write = MyWrite; + outStream.data = dest; + outStream.rem = *destLen; + outStream.overflow = False; + + p->writeEndMark = False; + p->finished = False; + p->result = SZ_OK; + + if (reInit) + LzmaEnc_Init(p); + LzmaEnc_InitPrices(p); + nowPos64 = p->nowPos64; + RangeEnc_Init(&p->rc); + p->rc.outStream = &outStream.funcTable; + + res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize); + + *unpackSize = (UInt32)(p->nowPos64 - nowPos64); + *destLen -= outStream.rem; + if (outStream.overflow) + return SZ_ERROR_OUTPUT_EOF; + + return res; +} + +SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress, + ISzAlloc *alloc, ISzAlloc *allocBig) +{ + CLzmaEnc *p = (CLzmaEnc *)pp; + SRes res = SZ_OK; + + #ifdef COMPRESS_MF_MT + Byte allocaDummy[0x300]; + int i = 0; + for (i = 0; i < 16; i++) + allocaDummy[i] = (Byte)i; + #endif + + RINOK(LzmaEnc_Prepare(pp, inStream, outStream, alloc, allocBig)); + + for (;;) + { + res = LzmaEnc_CodeOneBlock(p, False, 0, 0); + if (res != SZ_OK || p->finished != 0) + break; + if (progress != 0) + { + res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc)); + if (res != SZ_OK) + { + res = SZ_ERROR_PROGRESS; + break; + } + } + } + LzmaEnc_Finish(pp); + return res; +} + +SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size) +{ + CLzmaEnc *p = (CLzmaEnc *)pp; + int i; + UInt32 dictSize = p->dictSize; + if (*size < LZMA_PROPS_SIZE) + return SZ_ERROR_PARAM; + *size = LZMA_PROPS_SIZE; + props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc); + + for (i = 11; i <= 30; i++) + { + if (dictSize <= ((UInt32)2 << i)) + { + dictSize = (2 << i); + break; + } + if (dictSize <= ((UInt32)3 << i)) + { + dictSize = (3 << i); + break; + } + } + + for (i = 0; i < 4; i++) + props[1 + i] = (Byte)(dictSize >> (8 * i)); + return SZ_OK; +} + +SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, + int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig) +{ + SRes res; + CLzmaEnc *p = (CLzmaEnc *)pp; + + CSeqOutStreamBuf outStream; + + LzmaEnc_SetInputBuf(p, src, srcLen); + + outStream.funcTable.Write = MyWrite; + outStream.data = dest; + outStream.rem = *destLen; + outStream.overflow = False; + + p->writeEndMark = writeEndMark; + res = LzmaEnc_Encode(pp, &outStream.funcTable, &p->seqBufInStream.funcTable, + progress, alloc, allocBig); + + *destLen -= outStream.rem; + if (outStream.overflow) + return SZ_ERROR_OUTPUT_EOF; + return res; +} + +SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, + const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, + ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig) +{ + CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc); + SRes res; + if (p == 0) + return SZ_ERROR_MEM; + + res = LzmaEnc_SetProps(p, props); + if (res == SZ_OK) + { + res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize); + if (res == SZ_OK) + res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen, + writeEndMark, progress, alloc, allocBig); + } + + LzmaEnc_Destroy(p, alloc, allocBig); + return res; +} diff --git a/extern/lzma/LzmaEnc.h b/extern/lzma/LzmaEnc.h new file mode 100644 index 00000000000..bfbc7d2b9c3 --- /dev/null +++ b/extern/lzma/LzmaEnc.h @@ -0,0 +1,72 @@ +/* LzmaEnc.h -- LZMA Encoder +2008-10-04 : Igor Pavlov : Public domain */ + +#ifndef __LZMAENC_H +#define __LZMAENC_H + +#include "Types.h" + +#define LZMA_PROPS_SIZE 5 + +typedef struct _CLzmaEncProps +{ + int level; /* 0 <= level <= 9 */ + UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version + (1 << 12) <= dictSize <= (1 << 30) for 64-bit version + default = (1 << 24) */ + int lc; /* 0 <= lc <= 8, default = 3 */ + int lp; /* 0 <= lp <= 4, default = 0 */ + int pb; /* 0 <= pb <= 4, default = 2 */ + int algo; /* 0 - fast, 1 - normal, default = 1 */ + int fb; /* 5 <= fb <= 273, default = 32 */ + int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */ + int numHashBytes; /* 2, 3 or 4, default = 4 */ + UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */ + unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */ + int numThreads; /* 1 or 2, default = 2 */ +} CLzmaEncProps; + +void LzmaEncProps_Init(CLzmaEncProps *p); +void LzmaEncProps_Normalize(CLzmaEncProps *p); +UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2); + + +/* ---------- CLzmaEncHandle Interface ---------- */ + +/* LzmaEnc_* functions can return the following exit codes: +Returns: + SZ_OK - OK + SZ_ERROR_MEM - Memory allocation error + SZ_ERROR_PARAM - Incorrect paramater in props + SZ_ERROR_WRITE - Write callback error. + SZ_ERROR_PROGRESS - some break from progress callback + SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) +*/ + +typedef void * CLzmaEncHandle; + +CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc); +void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig); +SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props); +SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size); +SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream, + ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); +SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, + int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); + +/* ---------- One Call Interface ---------- */ + +/* LzmaEncode +Return code: + SZ_OK - OK + SZ_ERROR_MEM - Memory allocation error + SZ_ERROR_PARAM - Incorrect paramater + SZ_ERROR_OUTPUT_EOF - output buffer overflow + SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) +*/ + +SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, + const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, + ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); + +#endif diff --git a/extern/lzma/LzmaLib.c b/extern/lzma/LzmaLib.c new file mode 100644 index 00000000000..02a511857c9 --- /dev/null +++ b/extern/lzma/LzmaLib.c @@ -0,0 +1,46 @@ +/* LzmaLib.c -- LZMA library wrapper +2008-08-05 +Igor Pavlov +Public domain */ + +#include "LzmaEnc.h" +#include "LzmaDec.h" +#include "Alloc.h" +#include "LzmaLib.h" + +static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); } +static void SzFree(void *p, void *address) { p = p; MyFree(address); } +static ISzAlloc g_Alloc = { SzAlloc, SzFree }; + +MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen, + unsigned char *outProps, size_t *outPropsSize, + int level, /* 0 <= level <= 9, default = 5 */ + unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */ + int lc, /* 0 <= lc <= 8, default = 3 */ + int lp, /* 0 <= lp <= 4, default = 0 */ + int pb, /* 0 <= pb <= 4, default = 2 */ + int fb, /* 5 <= fb <= 273, default = 32 */ + int numThreads /* 1 or 2, default = 2 */ +) +{ + CLzmaEncProps props; + LzmaEncProps_Init(&props); + props.level = level; + props.dictSize = dictSize; + props.lc = lc; + props.lp = lp; + props.pb = pb; + props.fb = fb; + props.numThreads = numThreads; + + return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0, + NULL, &g_Alloc, &g_Alloc); +} + + +MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t *srcLen, + const unsigned char *props, size_t propsSize) +{ + ELzmaStatus status; + return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc); +} diff --git a/extern/lzma/LzmaLib.h b/extern/lzma/LzmaLib.h new file mode 100644 index 00000000000..5c9eeec73ca --- /dev/null +++ b/extern/lzma/LzmaLib.h @@ -0,0 +1,135 @@ +/* LzmaLib.h -- LZMA library interface +2008-08-05 +Igor Pavlov +Public domain */ + +#ifndef __LZMALIB_H +#define __LZMALIB_H + +#include "Types.h" + +#ifdef __cplusplus + #define MY_EXTERN_C extern "C" +#else + #define MY_EXTERN_C extern +#endif + +#define MY_STDAPI MY_EXTERN_C int MY_STD_CALL + +#define LZMA_PROPS_SIZE 5 + +/* +RAM requirements for LZMA: + for compression: (dictSize * 11.5 + 6 MB) + state_size + for decompression: dictSize + state_size + state_size = (4 + (1.5 << (lc + lp))) KB + by default (lc=3, lp=0), state_size = 16 KB. + +LZMA properties (5 bytes) format + Offset Size Description + 0 1 lc, lp and pb in encoded form. + 1 4 dictSize (little endian). +*/ + +/* +LzmaCompress +------------ + +outPropsSize - + In: the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5. + Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5. + + LZMA Encoder will use defult values for any parameter, if it is + -1 for any from: level, loc, lp, pb, fb, numThreads + 0 for dictSize + +level - compression level: 0 <= level <= 9; + + level dictSize algo fb + 0: 16 KB 0 32 + 1: 64 KB 0 32 + 2: 256 KB 0 32 + 3: 1 MB 0 32 + 4: 4 MB 0 32 + 5: 16 MB 1 32 + 6: 32 MB 1 32 + 7+: 64 MB 1 64 + + The default value for "level" is 5. + + algo = 0 means fast method + algo = 1 means normal method + +dictSize - The dictionary size in bytes. The maximum value is + 128 MB = (1 << 27) bytes for 32-bit version + 1 GB = (1 << 30) bytes for 64-bit version + The default value is 16 MB = (1 << 24) bytes. + It's recommended to use the dictionary that is larger than 4 KB and + that can be calculated as (1 << N) or (3 << N) sizes. + +lc - The number of literal context bits (high bits of previous literal). + It can be in the range from 0 to 8. The default value is 3. + Sometimes lc=4 gives the gain for big files. + +lp - The number of literal pos bits (low bits of current position for literals). + It can be in the range from 0 to 4. The default value is 0. + The lp switch is intended for periodical data when the period is equal to 2^lp. + For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's + better to set lc=0, if you change lp switch. + +pb - The number of pos bits (low bits of current position). + It can be in the range from 0 to 4. The default value is 2. + The pb switch is intended for periodical data when the period is equal 2^pb. + +fb - Word size (the number of fast bytes). + It can be in the range from 5 to 273. The default value is 32. + Usually, a big number gives a little bit better compression ratio and + slower compression process. + +numThreads - The number of thereads. 1 or 2. The default value is 2. + Fast mode (algo = 0) can use only 1 thread. + +Out: + destLen - processed output size +Returns: + SZ_OK - OK + SZ_ERROR_MEM - Memory allocation error + SZ_ERROR_PARAM - Incorrect paramater + SZ_ERROR_OUTPUT_EOF - output buffer overflow + SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) +*/ + +MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen, + unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */ + int level, /* 0 <= level <= 9, default = 5 */ + unsigned dictSize, /* default = (1 << 24) */ + int lc, /* 0 <= lc <= 8, default = 3 */ + int lp, /* 0 <= lp <= 4, default = 0 */ + int pb, /* 0 <= pb <= 4, default = 2 */ + int fb, /* 5 <= fb <= 273, default = 32 */ + int numThreads /* 1 or 2, default = 2 */ + ); + +/* +LzmaUncompress +-------------- +In: + dest - output data + destLen - output data size + src - input data + srcLen - input data size +Out: + destLen - processed output size + srcLen - processed input size +Returns: + SZ_OK - OK + SZ_ERROR_DATA - Data error + SZ_ERROR_MEM - Memory allocation arror + SZ_ERROR_UNSUPPORTED - Unsupported properties + SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer (src) +*/ + +MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen, + const unsigned char *props, size_t propsSize); + +#endif diff --git a/extern/lzma/Threads.c b/extern/lzma/Threads.c new file mode 100644 index 00000000000..4fdd69b0d5c --- /dev/null +++ b/extern/lzma/Threads.c @@ -0,0 +1,109 @@ +/* Threads.c -- multithreading library +2008-08-05 +Igor Pavlov +Public domain */ + +#include "Threads.h" +#include + +static WRes GetError() +{ + DWORD res = GetLastError(); + return (res) ? (WRes)(res) : 1; +} + +WRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); } +WRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); } + +static WRes MyCloseHandle(HANDLE *h) +{ + if (*h != NULL) + if (!CloseHandle(*h)) + return GetError(); + *h = NULL; + return 0; +} + +WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter) +{ + unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */ + thread->handle = + /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */ + (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId); + /* maybe we must use errno here, but probably GetLastError() is also OK. */ + return HandleToWRes(thread->handle); +} + +WRes WaitObject(HANDLE h) +{ + return (WRes)WaitForSingleObject(h, INFINITE); +} + +WRes Thread_Wait(CThread *thread) +{ + if (thread->handle == NULL) + return 1; + return WaitObject(thread->handle); +} + +WRes Thread_Close(CThread *thread) +{ + return MyCloseHandle(&thread->handle); +} + +WRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled) +{ + p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL); + return HandleToWRes(p->handle); +} + +WRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled) + { return Event_Create(p, TRUE, initialSignaled); } +WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p) + { return ManualResetEvent_Create(p, 0); } + +WRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled) + { return Event_Create(p, FALSE, initialSignaled); } +WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) + { return AutoResetEvent_Create(p, 0); } + +WRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(p->handle)); } +WRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(p->handle)); } +WRes Event_Wait(CEvent *p) { return WaitObject(p->handle); } +WRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); } + + +WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount) +{ + p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL); + return HandleToWRes(p->handle); +} + +WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount) +{ + return BOOLToWRes(ReleaseSemaphore(p->handle, releaseCount, previousCount)); +} +WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount) +{ + return Semaphore_Release(p, (LONG)releaseCount, NULL); +} +WRes Semaphore_Release1(CSemaphore *p) +{ + return Semaphore_ReleaseN(p, 1); +} + +WRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); } +WRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); } + +WRes CriticalSection_Init(CCriticalSection *p) +{ + /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */ + __try + { + InitializeCriticalSection(p); + /* InitializeCriticalSectionAndSpinCount(p, 0); */ + } + __except (EXCEPTION_EXECUTE_HANDLER) { return 1; } + return 0; +} + diff --git a/extern/lzma/Threads.h b/extern/lzma/Threads.h new file mode 100644 index 00000000000..a823e57858a --- /dev/null +++ b/extern/lzma/Threads.h @@ -0,0 +1,68 @@ +/* Threads.h -- multithreading library +2008-11-22 : Igor Pavlov : Public domain */ + +#ifndef __7Z_THRESDS_H +#define __7Z_THRESDS_H + +#include "Types.h" + +typedef struct _CThread +{ + HANDLE handle; +} CThread; + +#define Thread_Construct(thread) (thread)->handle = NULL +#define Thread_WasCreated(thread) ((thread)->handle != NULL) + +typedef unsigned THREAD_FUNC_RET_TYPE; +#define THREAD_FUNC_CALL_TYPE MY_STD_CALL +#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE + +WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter); +WRes Thread_Wait(CThread *thread); +WRes Thread_Close(CThread *thread); + +typedef struct _CEvent +{ + HANDLE handle; +} CEvent; + +typedef CEvent CAutoResetEvent; +typedef CEvent CManualResetEvent; + +#define Event_Construct(event) (event)->handle = NULL +#define Event_IsCreated(event) ((event)->handle != NULL) + +WRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled); +WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event); +WRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled); +WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event); +WRes Event_Set(CEvent *event); +WRes Event_Reset(CEvent *event); +WRes Event_Wait(CEvent *event); +WRes Event_Close(CEvent *event); + + +typedef struct _CSemaphore +{ + HANDLE handle; +} CSemaphore; + +#define Semaphore_Construct(p) (p)->handle = NULL + +WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount); +WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num); +WRes Semaphore_Release1(CSemaphore *p); +WRes Semaphore_Wait(CSemaphore *p); +WRes Semaphore_Close(CSemaphore *p); + + +typedef CRITICAL_SECTION CCriticalSection; + +WRes CriticalSection_Init(CCriticalSection *p); +#define CriticalSection_Delete(p) DeleteCriticalSection(p) +#define CriticalSection_Enter(p) EnterCriticalSection(p) +#define CriticalSection_Leave(p) LeaveCriticalSection(p) + +#endif + diff --git a/extern/lzma/Types.h b/extern/lzma/Types.h new file mode 100644 index 00000000000..1af5cfc4d86 --- /dev/null +++ b/extern/lzma/Types.h @@ -0,0 +1,208 @@ +/* Types.h -- Basic types +2008-11-23 : Igor Pavlov : Public domain */ + +#ifndef __7Z_TYPES_H +#define __7Z_TYPES_H + +#include + +#ifdef _WIN32 +#include +#endif + +#define SZ_OK 0 + +#define SZ_ERROR_DATA 1 +#define SZ_ERROR_MEM 2 +#define SZ_ERROR_CRC 3 +#define SZ_ERROR_UNSUPPORTED 4 +#define SZ_ERROR_PARAM 5 +#define SZ_ERROR_INPUT_EOF 6 +#define SZ_ERROR_OUTPUT_EOF 7 +#define SZ_ERROR_READ 8 +#define SZ_ERROR_WRITE 9 +#define SZ_ERROR_PROGRESS 10 +#define SZ_ERROR_FAIL 11 +#define SZ_ERROR_THREAD 12 + +#define SZ_ERROR_ARCHIVE 16 +#define SZ_ERROR_NO_ARCHIVE 17 + +typedef int SRes; + +#ifdef _WIN32 +typedef DWORD WRes; +#else +typedef int WRes; +#endif + +#ifndef RINOK +#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; } +#endif + +typedef unsigned char Byte; +typedef short Int16; +typedef unsigned short UInt16; + +#ifdef _LZMA_UINT32_IS_ULONG +typedef long Int32; +typedef unsigned long UInt32; +#else +typedef int Int32; +typedef unsigned int UInt32; +#endif + +#ifdef _SZ_NO_INT_64 + +/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers. + NOTES: Some code will work incorrectly in that case! */ + +typedef long Int64; +typedef unsigned long UInt64; + +#else + +#if defined(_MSC_VER) || defined(__BORLANDC__) +typedef __int64 Int64; +typedef unsigned __int64 UInt64; +#else +typedef long long int Int64; +typedef unsigned long long int UInt64; +#endif + +#endif + +#ifdef _LZMA_NO_SYSTEM_SIZE_T +typedef UInt32 SizeT; +#else +typedef size_t SizeT; +#endif + +typedef int Bool; +#define True 1 +#define False 0 + + +#ifdef _MSC_VER + +#if _MSC_VER >= 1300 +#define MY_NO_INLINE __declspec(noinline) +#else +#define MY_NO_INLINE +#endif + +#define MY_CDECL __cdecl +#define MY_STD_CALL __stdcall +#define MY_FAST_CALL MY_NO_INLINE __fastcall + +#else + +#define MY_CDECL +#define MY_STD_CALL +#define MY_FAST_CALL + +#endif + + +/* The following interfaces use first parameter as pointer to structure */ + +typedef struct +{ + SRes (*Read)(void *p, void *buf, size_t *size); + /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. + (output(*size) < input(*size)) is allowed */ +} ISeqInStream; + +/* it can return SZ_ERROR_INPUT_EOF */ +SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size); +SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType); +SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf); + +typedef struct +{ + size_t (*Write)(void *p, const void *buf, size_t size); + /* Returns: result - the number of actually written bytes. + (result < size) means error */ +} ISeqOutStream; + +typedef enum +{ + SZ_SEEK_SET = 0, + SZ_SEEK_CUR = 1, + SZ_SEEK_END = 2 +} ESzSeek; + +typedef struct +{ + SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */ + SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin); +} ISeekInStream; + +typedef struct +{ + SRes (*Look)(void *p, void **buf, size_t *size); + /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. + (output(*size) > input(*size)) is not allowed + (output(*size) < input(*size)) is allowed */ + SRes (*Skip)(void *p, size_t offset); + /* offset must be <= output(*size) of Look */ + + SRes (*Read)(void *p, void *buf, size_t *size); + /* reads directly (without buffer). It's same as ISeqInStream::Read */ + SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin); +} ILookInStream; + +SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size); +SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset); + +/* reads via ILookInStream::Read */ +SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType); +SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size); + +#define LookToRead_BUF_SIZE (1 << 14) + +typedef struct +{ + ILookInStream s; + ISeekInStream *realStream; + size_t pos; + size_t size; + Byte buf[LookToRead_BUF_SIZE]; +} CLookToRead; + +void LookToRead_CreateVTable(CLookToRead *p, int lookahead); +void LookToRead_Init(CLookToRead *p); + +typedef struct +{ + ISeqInStream s; + ILookInStream *realStream; +} CSecToLook; + +void SecToLook_CreateVTable(CSecToLook *p); + +typedef struct +{ + ISeqInStream s; + ILookInStream *realStream; +} CSecToRead; + +void SecToRead_CreateVTable(CSecToRead *p); + +typedef struct +{ + SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize); + /* Returns: result. (result != SZ_OK) means break. + Value (UInt64)(Int64)-1 for size means unknown value. */ +} ICompressProgress; + +typedef struct +{ + void *(*Alloc)(void *p, size_t size); + void (*Free)(void *p, void *address); /* address can be 0 */ +} ISzAlloc; + +#define IAlloc_Alloc(p, size) (p)->Alloc((p), size) +#define IAlloc_Free(p, a) (p)->Free((p), a) + +#endif diff --git a/extern/lzma/history.txt b/extern/lzma/history.txt new file mode 100644 index 00000000000..014186717da --- /dev/null +++ b/extern/lzma/history.txt @@ -0,0 +1,236 @@ +HISTORY of the LZMA SDK +----------------------- + +4.65 2009-02-03 +------------------------- +- Some minor fixes + + +4.63 2008-12-31 +------------------------- +- Some minor fixes + + +4.61 beta 2008-11-23 +------------------------- +- The bug in ANSI-C LZMA Decoder was fixed: + If encoded stream was corrupted, decoder could access memory + outside of allocated range. +- Some changes in ANSI-C 7z Decoder interfaces. +- LZMA SDK is placed in the public domain. + + +4.60 beta 2008-08-19 +------------------------- +- Some minor fixes. + + +4.59 beta 2008-08-13 +------------------------- +- The bug was fixed: + LZMA Encoder in fast compression mode could access memory outside of + allocated range in some rare cases. + + +4.58 beta 2008-05-05 +------------------------- +- ANSI-C LZMA Decoder was rewritten for speed optimizations. +- ANSI-C LZMA Encoder was included to LZMA SDK. +- C++ LZMA code now is just wrapper over ANSI-C code. + + +4.57 2007-12-12 +------------------------- +- Speed optimizations in Ñ++ LZMA Decoder. +- Small changes for more compatibility with some C/C++ compilers. + + +4.49 beta 2007-07-05 +------------------------- +- .7z ANSI-C Decoder: + - now it supports BCJ and BCJ2 filters + - now it supports files larger than 4 GB. + - now it supports "Last Write Time" field for files. +- C++ code for .7z archives compressing/decompressing from 7-zip + was included to LZMA SDK. + + +4.43 2006-06-04 +------------------------- +- Small changes for more compatibility with some C/C++ compilers. + + +4.42 2006-05-15 +------------------------- +- Small changes in .h files in ANSI-C version. + + +4.39 beta 2006-04-14 +------------------------- +- The bug in versions 4.33b:4.38b was fixed: + C++ version of LZMA encoder could not correctly compress + files larger than 2 GB with HC4 match finder (-mfhc4). + + +4.37 beta 2005-04-06 +------------------------- +- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined. + + +4.35 beta 2005-03-02 +------------------------- +- The bug was fixed in C++ version of LZMA Decoder: + If encoded stream was corrupted, decoder could access memory + outside of allocated range. + + +4.34 beta 2006-02-27 +------------------------- +- Compressing speed and memory requirements for compressing were increased +- LZMA now can use only these match finders: HC4, BT2, BT3, BT4 + + +4.32 2005-12-09 +------------------------- +- Java version of LZMA SDK was included + + +4.30 2005-11-20 +------------------------- +- Compression ratio was improved in -a2 mode +- Speed optimizations for compressing in -a2 mode +- -fb switch now supports values up to 273 +- The bug in 7z_C (7zIn.c) was fixed: + It used Alloc/Free functions from different memory pools. + So if program used two memory pools, it worked incorrectly. +- 7z_C: .7z format supporting was improved +- LZMA# SDK (C#.NET version) was included + + +4.27 (Updated) 2005-09-21 +------------------------- +- Some GUIDs/interfaces in C++ were changed. + IStream.h: + ISequentialInStream::Read now works as old ReadPart + ISequentialOutStream::Write now works as old WritePart + + +4.27 2005-08-07 +------------------------- +- The bug in LzmaDecodeSize.c was fixed: + if _LZMA_IN_CB and _LZMA_OUT_READ were defined, + decompressing worked incorrectly. + + +4.26 2005-08-05 +------------------------- +- Fixes in 7z_C code and LzmaTest.c: + previous versions could work incorrectly, + if malloc(0) returns 0 + + +4.23 2005-06-29 +------------------------- +- Small fixes in C++ code + + +4.22 2005-06-10 +------------------------- +- Small fixes + + +4.21 2005-06-08 +------------------------- +- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed +- New additional version of ANSI-C LZMA Decoder with zlib-like interface: + - LzmaStateDecode.h + - LzmaStateDecode.c + - LzmaStateTest.c +- ANSI-C LZMA Decoder now can decompress files larger than 4 GB + + +4.17 2005-04-18 +------------------------- +- New example for RAM->RAM compressing/decompressing: + LZMA + BCJ (filter for x86 code): + - LzmaRam.h + - LzmaRam.cpp + - LzmaRamDecode.h + - LzmaRamDecode.c + - -f86 switch for lzma.exe + + +4.16 2005-03-29 +------------------------- +- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): + If _LZMA_OUT_READ was defined, and if encoded stream was corrupted, + decoder could access memory outside of allocated range. +- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster). + Old version of LZMA Decoder now is in file LzmaDecodeSize.c. + LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c +- Small speed optimization in LZMA C++ code +- filter for SPARC's code was added +- Simplified version of .7z ANSI-C Decoder was included + + +4.06 2004-09-05 +------------------------- +- The bug in v4.05 was fixed: + LZMA-Encoder didn't release output stream in some cases. + + +4.05 2004-08-25 +------------------------- +- Source code of filters for x86, IA-64, ARM, ARM-Thumb + and PowerPC code was included to SDK +- Some internal minor changes + + +4.04 2004-07-28 +------------------------- +- More compatibility with some C++ compilers + + +4.03 2004-06-18 +------------------------- +- "Benchmark" command was added. It measures compressing + and decompressing speed and shows rating values. + Also it checks hardware errors. + + +4.02 2004-06-10 +------------------------- +- C++ LZMA Encoder/Decoder code now is more portable + and it can be compiled by GCC on Linux. + + +4.01 2004-02-15 +------------------------- +- Some detection of data corruption was enabled. + LzmaDecode.c / RangeDecoderReadByte + ..... + { + rd->ExtraBytes = 1; + return 0xFF; + } + + +4.00 2004-02-13 +------------------------- +- Original version of LZMA SDK + + + +HISTORY of the LZMA +------------------- + 2001-2008: Improvements to LZMA compressing/decompressing code, + keeping compatibility with original LZMA format + 1996-2001: Development of LZMA compression format + + Some milestones: + + 2001-08-30: LZMA compression was added to 7-Zip + 1999-01-02: First version of 7-Zip was released + + +End of document diff --git a/extern/lzma/lzma.txt b/extern/lzma/lzma.txt new file mode 100644 index 00000000000..715792d6c17 --- /dev/null +++ b/extern/lzma/lzma.txt @@ -0,0 +1,594 @@ +LZMA SDK 4.65 +------------- + +LZMA SDK provides the documentation, samples, header files, libraries, +and tools you need to develop applications that use LZMA compression. + +LZMA is default and general compression method of 7z format +in 7-Zip compression program (www.7-zip.org). LZMA provides high +compression ratio and very fast decompression. + +LZMA is an improved version of famous LZ77 compression algorithm. +It was improved in way of maximum increasing of compression ratio, +keeping high decompression speed and low memory requirements for +decompressing. + + + +LICENSE +------- + +LZMA SDK is written and placed in the public domain by Igor Pavlov. + + +LZMA SDK Contents +----------------- + +LZMA SDK includes: + + - ANSI-C/C++/C#/Java source code for LZMA compressing and decompressing + - Compiled file->file LZMA compressing/decompressing program for Windows system + + +UNIX/Linux version +------------------ +To compile C++ version of file->file LZMA encoding, go to directory +C++/7zip/Compress/LZMA_Alone +and call make to recompile it: + make -f makefile.gcc clean all + +In some UNIX/Linux versions you must compile LZMA with static libraries. +To compile with static libraries, you can use +LIB = -lm -static + + +Files +--------------------- +lzma.txt - LZMA SDK description (this file) +7zFormat.txt - 7z Format description +7zC.txt - 7z ANSI-C Decoder description +methods.txt - Compression method IDs for .7z +lzma.exe - Compiled file->file LZMA encoder/decoder for Windows +history.txt - history of the LZMA SDK + + +Source code structure +--------------------- + +C/ - C files + 7zCrc*.* - CRC code + Alloc.* - Memory allocation functions + Bra*.* - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code + LzFind.* - Match finder for LZ (LZMA) encoders + LzFindMt.* - Match finder for LZ (LZMA) encoders for multithreading encoding + LzHash.h - Additional file for LZ match finder + LzmaDec.* - LZMA decoding + LzmaEnc.* - LZMA encoding + LzmaLib.* - LZMA Library for DLL calling + Types.h - Basic types for another .c files + Threads.* - The code for multithreading. + + LzmaLib - LZMA Library (.DLL for Windows) + + LzmaUtil - LZMA Utility (file->file LZMA encoder/decoder). + + Archive - files related to archiving + 7z - 7z ANSI-C Decoder + +CPP/ -- CPP files + + Common - common files for C++ projects + Windows - common files for Windows related code + + 7zip - files related to 7-Zip Project + + Common - common files for 7-Zip + + Compress - files related to compression/decompression + + Copy - Copy coder + RangeCoder - Range Coder (special code of compression/decompression) + LZMA - LZMA compression/decompression on C++ + LZMA_Alone - file->file LZMA compression/decompression + Branch - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code + + Archive - files related to archiving + + Common - common files for archive handling + 7z - 7z C++ Encoder/Decoder + + Bundles - Modules that are bundles of other modules + + Alone7z - 7zr.exe: Standalone version of 7z.exe that supports only 7z/LZMA/BCJ/BCJ2 + Format7zR - 7zr.dll: Reduced version of 7za.dll: extracting/compressing to 7z/LZMA/BCJ/BCJ2 + Format7zExtractR - 7zxr.dll: Reduced version of 7zxa.dll: extracting from 7z/LZMA/BCJ/BCJ2. + + UI - User Interface files + + Client7z - Test application for 7za.dll, 7zr.dll, 7zxr.dll + Common - Common UI files + Console - Code for console archiver + + + +CS/ - C# files + 7zip + Common - some common files for 7-Zip + Compress - files related to compression/decompression + LZ - files related to LZ (Lempel-Ziv) compression algorithm + LZMA - LZMA compression/decompression + LzmaAlone - file->file LZMA compression/decompression + RangeCoder - Range Coder (special code of compression/decompression) + +Java/ - Java files + SevenZip + Compression - files related to compression/decompression + LZ - files related to LZ (Lempel-Ziv) compression algorithm + LZMA - LZMA compression/decompression + RangeCoder - Range Coder (special code of compression/decompression) + + +C/C++ source code of LZMA SDK is part of 7-Zip project. +7-Zip source code can be downloaded from 7-Zip's SourceForge page: + + http://sourceforge.net/projects/sevenzip/ + + + +LZMA features +------------- + - Variable dictionary size (up to 1 GB) + - Estimated compressing speed: about 2 MB/s on 2 GHz CPU + - Estimated decompressing speed: + - 20-30 MB/s on 2 GHz Core 2 or AMD Athlon 64 + - 1-2 MB/s on 200 MHz ARM, MIPS, PowerPC or other simple RISC + - Small memory requirements for decompressing (16 KB + DictionarySize) + - Small code size for decompressing: 5-8 KB + +LZMA decoder uses only integer operations and can be +implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions). + +Some critical operations that affect the speed of LZMA decompression: + 1) 32*16 bit integer multiply + 2) Misspredicted branches (penalty mostly depends from pipeline length) + 3) 32-bit shift and arithmetic operations + +The speed of LZMA decompressing mostly depends from CPU speed. +Memory speed has no big meaning. But if your CPU has small data cache, +overall weight of memory speed will slightly increase. + + +How To Use +---------- + +Using LZMA encoder/decoder executable +-------------------------------------- + +Usage: LZMA inputFile outputFile [...] + + e: encode file + + d: decode file + + b: Benchmark. There are two tests: compressing and decompressing + with LZMA method. Benchmark shows rating in MIPS (million + instructions per second). Rating value is calculated from + measured speed and it is normalized with Intel's Core 2 results. + Also Benchmark checks possible hardware errors (RAM + errors in most cases). Benchmark uses these settings: + (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter. + Also you can change the number of iterations. Example for 30 iterations: + LZMA b 30 + Default number of iterations is 10. + + + + + -a{N}: set compression mode 0 = fast, 1 = normal + default: 1 (normal) + + d{N}: Sets Dictionary size - [0, 30], default: 23 (8MB) + The maximum value for dictionary size is 1 GB = 2^30 bytes. + Dictionary size is calculated as DictionarySize = 2^N bytes. + For decompressing file compressed by LZMA method with dictionary + size D = 2^N you need about D bytes of memory (RAM). + + -fb{N}: set number of fast bytes - [5, 273], default: 128 + Usually big number gives a little bit better compression ratio + and slower compression process. + + -lc{N}: set number of literal context bits - [0, 8], default: 3 + Sometimes lc=4 gives gain for big files. + + -lp{N}: set number of literal pos bits - [0, 4], default: 0 + lp switch is intended for periodical data when period is + equal 2^N. For example, for 32-bit (4 bytes) + periodical data you can use lp=2. Often it's better to set lc0, + if you change lp switch. + + -pb{N}: set number of pos bits - [0, 4], default: 2 + pb switch is intended for periodical data + when period is equal 2^N. + + -mf{MF_ID}: set Match Finder. Default: bt4. + Algorithms from hc* group doesn't provide good compression + ratio, but they often works pretty fast in combination with + fast mode (-a0). + + Memory requirements depend from dictionary size + (parameter "d" in table below). + + MF_ID Memory Description + + bt2 d * 9.5 + 4MB Binary Tree with 2 bytes hashing. + bt3 d * 11.5 + 4MB Binary Tree with 3 bytes hashing. + bt4 d * 11.5 + 4MB Binary Tree with 4 bytes hashing. + hc4 d * 7.5 + 4MB Hash Chain with 4 bytes hashing. + + -eos: write End Of Stream marker. By default LZMA doesn't write + eos marker, since LZMA decoder knows uncompressed size + stored in .lzma file header. + + -si: Read data from stdin (it will write End Of Stream marker). + -so: Write data to stdout + + +Examples: + +1) LZMA e file.bin file.lzma -d16 -lc0 + +compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K) +and 0 literal context bits. -lc0 allows to reduce memory requirements +for decompression. + + +2) LZMA e file.bin file.lzma -lc0 -lp2 + +compresses file.bin to file.lzma with settings suitable +for 32-bit periodical data (for example, ARM or MIPS code). + +3) LZMA d file.lzma file.bin + +decompresses file.lzma to file.bin. + + +Compression ratio hints +----------------------- + +Recommendations +--------------- + +To increase the compression ratio for LZMA compressing it's desirable +to have aligned data (if it's possible) and also it's desirable to locate +data in such order, where code is grouped in one place and data is +grouped in other place (it's better than such mixing: code, data, code, +data, ...). + + +Filters +------- +You can increase the compression ratio for some data types, using +special filters before compressing. For example, it's possible to +increase the compression ratio on 5-10% for code for those CPU ISAs: +x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC. + +You can find C source code of such filters in C/Bra*.* files + +You can check the compression ratio gain of these filters with such +7-Zip commands (example for ARM code): +No filter: + 7z a a1.7z a.bin -m0=lzma + +With filter for little-endian ARM code: + 7z a a2.7z a.bin -m0=arm -m1=lzma + +It works in such manner: +Compressing = Filter_encoding + LZMA_encoding +Decompressing = LZMA_decoding + Filter_decoding + +Compressing and decompressing speed of such filters is very high, +so it will not increase decompressing time too much. +Moreover, it reduces decompression time for LZMA_decoding, +since compression ratio with filtering is higher. + +These filters convert CALL (calling procedure) instructions +from relative offsets to absolute addresses, so such data becomes more +compressible. + +For some ISAs (for example, for MIPS) it's impossible to get gain from such filter. + + +LZMA compressed file format +--------------------------- +Offset Size Description + 0 1 Special LZMA properties (lc,lp, pb in encoded form) + 1 4 Dictionary size (little endian) + 5 8 Uncompressed size (little endian). -1 means unknown size + 13 Compressed data + + +ANSI-C LZMA Decoder +~~~~~~~~~~~~~~~~~~~ + +Please note that interfaces for ANSI-C code were changed in LZMA SDK 4.58. +If you want to use old interfaces you can download previous version of LZMA SDK +from sourceforge.net site. + +To use ANSI-C LZMA Decoder you need the following files: +1) LzmaDec.h + LzmaDec.c + Types.h +LzmaUtil/LzmaUtil.c is example application that uses these files. + + +Memory requirements for LZMA decoding +------------------------------------- + +Stack usage of LZMA decoding function for local variables is not +larger than 200-400 bytes. + +LZMA Decoder uses dictionary buffer and internal state structure. +Internal state structure consumes + state_size = (4 + (1.5 << (lc + lp))) KB +by default (lc=3, lp=0), state_size = 16 KB. + + +How To decompress data +---------------------- + +LZMA Decoder (ANSI-C version) now supports 2 interfaces: +1) Single-call Decompressing +2) Multi-call State Decompressing (zlib-like interface) + +You must use external allocator: +Example: +void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); } +void SzFree(void *p, void *address) { p = p; free(address); } +ISzAlloc alloc = { SzAlloc, SzFree }; + +You can use p = p; operator to disable compiler warnings. + + +Single-call Decompressing +------------------------- +When to use: RAM->RAM decompressing +Compile files: LzmaDec.h + LzmaDec.c + Types.h +Compile defines: no defines +Memory Requirements: + - Input buffer: compressed size + - Output buffer: uncompressed size + - LZMA Internal Structures: state_size (16 KB for default settings) + +Interface: + int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, + const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, + ELzmaStatus *status, ISzAlloc *alloc); + In: + dest - output data + destLen - output data size + src - input data + srcLen - input data size + propData - LZMA properties (5 bytes) + propSize - size of propData buffer (5 bytes) + finishMode - It has meaning only if the decoding reaches output limit (*destLen). + LZMA_FINISH_ANY - Decode just destLen bytes. + LZMA_FINISH_END - Stream must be finished after (*destLen). + You can use LZMA_FINISH_END, when you know that + current output buffer covers last bytes of stream. + alloc - Memory allocator. + + Out: + destLen - processed output size + srcLen - processed input size + + Output: + SZ_OK + status: + LZMA_STATUS_FINISHED_WITH_MARK + LZMA_STATUS_NOT_FINISHED + LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK + SZ_ERROR_DATA - Data error + SZ_ERROR_MEM - Memory allocation error + SZ_ERROR_UNSUPPORTED - Unsupported properties + SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). + + If LZMA decoder sees end_marker before reaching output limit, it returns OK result, + and output value of destLen will be less than output buffer size limit. + + You can use multiple checks to test data integrity after full decompression: + 1) Check Result and "status" variable. + 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize. + 3) Check that output(srcLen) = compressedSize, if you know real compressedSize. + You must use correct finish mode in that case. */ + + +Multi-call State Decompressing (zlib-like interface) +---------------------------------------------------- + +When to use: file->file decompressing +Compile files: LzmaDec.h + LzmaDec.c + Types.h + +Memory Requirements: + - Buffer for input stream: any size (for example, 16 KB) + - Buffer for output stream: any size (for example, 16 KB) + - LZMA Internal Structures: state_size (16 KB for default settings) + - LZMA dictionary (dictionary size is encoded in LZMA properties header) + +1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header: + unsigned char header[LZMA_PROPS_SIZE + 8]; + ReadFile(inFile, header, sizeof(header) + +2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties + + CLzmaDec state; + LzmaDec_Constr(&state); + res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc); + if (res != SZ_OK) + return res; + +3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop + + LzmaDec_Init(&state); + for (;;) + { + ... + int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, + const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode); + ... + } + + +4) Free all allocated structures + LzmaDec_Free(&state, &g_Alloc); + +For full code example, look at C/LzmaUtil/LzmaUtil.c code. + + +How To compress data +-------------------- + +Compile files: LzmaEnc.h + LzmaEnc.c + Types.h + +LzFind.c + LzFind.h + LzFindMt.c + LzFindMt.h + LzHash.h + +Memory Requirements: + - (dictSize * 11.5 + 6 MB) + state_size + +Lzma Encoder can use two memory allocators: +1) alloc - for small arrays. +2) allocBig - for big arrays. + +For example, you can use Large RAM Pages (2 MB) in allocBig allocator for +better compression speed. Note that Windows has bad implementation for +Large RAM Pages. +It's OK to use same allocator for alloc and allocBig. + + +Single-call Compression with callbacks +-------------------------------------- + +Check C/LzmaUtil/LzmaUtil.c as example, + +When to use: file->file decompressing + +1) you must implement callback structures for interfaces: +ISeqInStream +ISeqOutStream +ICompressProgress +ISzAlloc + +static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); } +static void SzFree(void *p, void *address) { p = p; MyFree(address); } +static ISzAlloc g_Alloc = { SzAlloc, SzFree }; + + CFileSeqInStream inStream; + CFileSeqOutStream outStream; + + inStream.funcTable.Read = MyRead; + inStream.file = inFile; + outStream.funcTable.Write = MyWrite; + outStream.file = outFile; + + +2) Create CLzmaEncHandle object; + + CLzmaEncHandle enc; + + enc = LzmaEnc_Create(&g_Alloc); + if (enc == 0) + return SZ_ERROR_MEM; + + +3) initialize CLzmaEncProps properties; + + LzmaEncProps_Init(&props); + + Then you can change some properties in that structure. + +4) Send LZMA properties to LZMA Encoder + + res = LzmaEnc_SetProps(enc, &props); + +5) Write encoded properties to header + + Byte header[LZMA_PROPS_SIZE + 8]; + size_t headerSize = LZMA_PROPS_SIZE; + UInt64 fileSize; + int i; + + res = LzmaEnc_WriteProperties(enc, header, &headerSize); + fileSize = MyGetFileLength(inFile); + for (i = 0; i < 8; i++) + header[headerSize++] = (Byte)(fileSize >> (8 * i)); + MyWriteFileAndCheck(outFile, header, headerSize) + +6) Call encoding function: + res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable, + NULL, &g_Alloc, &g_Alloc); + +7) Destroy LZMA Encoder Object + LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc); + + +If callback function return some error code, LzmaEnc_Encode also returns that code. + + +Single-call RAM->RAM Compression +-------------------------------- + +Single-call RAM->RAM Compression is similar to Compression with callbacks, +but you provide pointers to buffers instead of pointers to stream callbacks: + +HRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, + CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, + ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); + +Return code: + SZ_OK - OK + SZ_ERROR_MEM - Memory allocation error + SZ_ERROR_PARAM - Incorrect paramater + SZ_ERROR_OUTPUT_EOF - output buffer overflow + SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) + + + +LZMA Defines +------------ + +_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code. + +_LZMA_PROB32 - It can increase the speed on some 32-bit CPUs, but memory usage for + some structures will be doubled in that case. + +_LZMA_UINT32_IS_ULONG - Define it if int is 16-bit on your compiler and long is 32-bit. + +_LZMA_NO_SYSTEM_SIZE_T - Define it if you don't want to use size_t type. + + +C++ LZMA Encoder/Decoder +~~~~~~~~~~~~~~~~~~~~~~~~ +C++ LZMA code use COM-like interfaces. So if you want to use it, +you can study basics of COM/OLE. +C++ LZMA code is just wrapper over ANSI-C code. + + +C++ Notes +~~~~~~~~~~~~~~~~~~~~~~~~ +If you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling), +you must check that you correctly work with "new" operator. +7-Zip can be compiled with MSVC 6.0 that doesn't throw "exception" from "new" operator. +So 7-Zip uses "CPP\Common\NewHandler.cpp" that redefines "new" operator: +operator new(size_t size) +{ + void *p = ::malloc(size); + if (p == 0) + throw CNewException(); + return p; +} +If you use MSCV that throws exception for "new" operator, you can compile without +"NewHandler.cpp". So standard exception will be used. Actually some code of +7-Zip catches any exception in internal code and converts it to HRESULT code. +So you don't need to catch CNewException, if you call COM interfaces of 7-Zip. + +--- + +http://www.7-zip.org +http://www.7-zip.org/sdk.html +http://www.7-zip.org/support.html diff --git a/extern/lzo/CMakeLists.txt b/extern/lzo/CMakeLists.txt new file mode 100644 index 00000000000..b640cf658da --- /dev/null +++ b/extern/lzo/CMakeLists.txt @@ -0,0 +1,34 @@ +# $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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# The Original Code is Copyright (C) 2006, Blender Foundation +# All rights reserved. +# +# The Original Code is: all of this file. +# +# Contributor(s): Daniel Genrich +# +# ***** END GPL LICENSE BLOCK ***** + +SET(INC include) + +FILE(GLOB SRC minilzo/*.c) + + + +BLENDERLIB(bf_minilzo "${SRC}" "${INC}") +#, libtype='blender', priority = 0 ) diff --git a/extern/lzo/SConscript b/extern/lzo/SConscript new file mode 100644 index 00000000000..81bedad25d8 --- /dev/null +++ b/extern/lzo/SConscript @@ -0,0 +1,9 @@ +#!/usr/bin/python +Import ('env') + +sources = env.Glob('minilzo/*.c') + +defs = '' +incs = ' include ' + +env.BlenderLib ('bf_minilzo', sources, Split(incs), Split(defs), libtype=['intern'], priority=[40] ) diff --git a/extern/lzo/minilzo/COPYING b/extern/lzo/minilzo/COPYING new file mode 100644 index 00000000000..5ee49f42e91 --- /dev/null +++ b/extern/lzo/minilzo/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/extern/lzo/minilzo/Makefile b/extern/lzo/minilzo/Makefile new file mode 100644 index 00000000000..a6ee373e8bc --- /dev/null +++ b/extern/lzo/minilzo/Makefile @@ -0,0 +1,113 @@ +# +# a very simple Makefile for miniLZO +# +# Copyright (C) 1996-2008 Markus F.X.J. Oberhumer +# + +PROGRAM = testmini +SOURCES = testmini.c minilzo.c + +default: + @echo "Please choose one of the following targets:" + @echo " gcc: gcc" + @echo " unix: hpux hpux9" + @echo " win32: win32-bc win32-cygwin win32-dm win32-lccwin32" + @echo " win32-intelc win32-mingw win32-vc win32-watcomc" + @echo " dos16: dos16-bc dos16-mc dos16-wc" + @echo " dos32: dos32-djgpp2 dos32-wc" + + +# Make sure that minilzo.h, lzoconf.h and lzodefs.h are in the +# current dircectory. Otherwise you may want to adjust CPPFLAGS. +##CPPFLAGS = -I../include/lzo -I. + +GCC_CFLAGS = -s -Wall -O2 -fomit-frame-pointer + + +# +# gcc (generic) +# + +gcc: + gcc $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM) $(SOURCES) + +cc: + cc $(CPPFLAGS) -o $(PROGRAM) $(SOURCES) + + +# +# UNIX +# + +hpux: + cc -Ae $(CPPFLAGS) -o $(PROGRAM) $(SOURCES) + +hpux9: + cc -Aa -D_HPUX_SOURCE $(CPPFLAGS) -o $(PROGRAM) $(SOURCES) + + +# +# Windows (32-bit) +# + +win32-borlandc win32-bc: + bcc32 -O2 -d -w -w-aus $(CPPFLAGS) $(SOURCES) + +win32-cygwin32 win32-cygwin: + gcc -mcygwin $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM).exe $(SOURCES) + +win32-digitalmars win32-dm: + dmc -mn -o -w- $(CPPFLAGS) $(SOURCES) + +win32-intelc win32-ic: + icl -nologo -MD -W3 -O2 -GF $(CPPFLAGS) $(SOURCES) + +win32-lccwin32: + @echo "NOTE: need lcc 2002-07-25 or newer, older versions have bugs" + lc -A -unused -O $(CPPFLAGS) $(SOURCES) + +win32-mingw32 win32-mingw: + gcc -mno-cygwin $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM).exe $(SOURCES) + +win32-visualc win32-vc: + cl -nologo -MD -W3 -O2 -GF $(CPPFLAGS) $(SOURCES) + +win32-watcomc win32-wc: + wcl386 -bt=nt -zq -mf -5r -zc -w5 -oneatx $(CPPFLAGS) $(SOURCES) + + +# +# DOS (16-bit) +# + +dos16-borlandc dos16-bc: + bcc -ml -w -d -O -4 $(CPPFLAGS) $(SOURCES) + +dos16-microsoftc dos16-msc dos16-mc: + cl -nologo -f- -AL -O -G2 -W3 $(CPPFLAGS) $(SOURCES) + +dos16-watcomc dos16-wc: + wcl -zq -ml -bt=dos -l=dos -ox -w5 $(CPPFLAGS) $(SOURCES) + + +# +# DOS (32-bit) +# + +dos32-djgpp2 dos32-dj2: + gcc $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM).exe $(SOURCES) + +dos32-watcomc dos32-wc: + wcl386 -zq -mf -bt=dos -l=dos4g -5r -ox -zc $(CPPFLAGS) $(SOURCES) + + +# +# other targets +# + +clean: + rm -f $(PROGRAM) $(PROGRAM).exe $(PROGRAM).map $(PROGRAM).tds + rm -f *.err *.o *.obj + +.PHONY: default clean + diff --git a/extern/lzo/minilzo/README.LZO b/extern/lzo/minilzo/README.LZO new file mode 100644 index 00000000000..3700f28e310 --- /dev/null +++ b/extern/lzo/minilzo/README.LZO @@ -0,0 +1,123 @@ + + ============================================================================ + miniLZO -- mini subset of the LZO real-time data compression library + ============================================================================ + + Author : Markus Franz Xaver Johannes Oberhumer + + http://www.oberhumer.com/opensource/lzo/ + Version : 2.03 + Date : 30 Apr 2008 + + I've created miniLZO for projects where it is inconvenient to + include (or require) the full LZO source code just because you + want to add a little bit of data compression to your application. + + miniLZO implements the LZO1X-1 compressor and both the standard and + safe LZO1X decompressor. Apart from fast compression it also useful + for situations where you want to use pre-compressed data files (which + must have been compressed with LZO1X-999). + + miniLZO consists of one C source file and three header files: + minilzo.c + minilzo.h, lzoconf.h, lzodefs.h + + To use miniLZO just copy these files into your source directory, add + minilzo.c to your Makefile and #include minilzo.h from your program. + Note: you also must distribute this file (`README.LZO') with your project. + + minilzo.o compiles to about 6 kB (using gcc or Visual C on a i386), and + the sources are about 30 kB when packed with zip - so there's no more + excuse that your application doesn't support data compression :-) + + For more information, documentation, example programs and other support + files (like Makefiles and build scripts) please download the full LZO + package from + http://www.oberhumer.com/opensource/lzo/ + + Have fun, + Markus + + + P.S. minilzo.c is generated automatically from the LZO sources and + therefore functionality is completely identical + + + Appendix A: building miniLZO + ---------------------------- + miniLZO is written such a way that it should compile and run + out-of-the-box on most machines. + + If you are running on a very unusual architecture and lzo_init() fails then + you should first recompile with `-DLZO_DEBUG' to see what causes the failure. + The most probable case is something like `sizeof(char *) != sizeof(long)'. + After identifying the problem you can compile by adding some defines + like `-DSIZEOF_CHAR_P=8' to your Makefile. + + The best solution is (of course) using Autoconf - if your project uses + Autoconf anyway just add `-DMINILZO_HAVE_CONFIG_H' to your compiler + flags when compiling minilzo.c. See the LZO distribution for an example + how to set up configure.in. + + + Appendix B: list of public functions available in miniLZO + --------------------------------------------------------- + Library initialization + lzo_init() + + Compression + lzo1x_1_compress() + + Decompression + lzo1x_decompress() + lzo1x_decompress_safe() + + Checksum functions + lzo_adler32() + + Version functions + lzo_version() + lzo_version_string() + lzo_version_date() + + Portable (but slow) string functions + lzo_memcmp() + lzo_memcpy() + lzo_memmove() + lzo_memset() + + + Appendix C: suggested macros for `configure.in' when using Autoconf + ------------------------------------------------------------------- + Checks for typedefs and structures + AC_CHECK_TYPE(ptrdiff_t,long) + AC_TYPE_SIZE_T + AC_CHECK_SIZEOF(short) + AC_CHECK_SIZEOF(int) + AC_CHECK_SIZEOF(long) + AC_CHECK_SIZEOF(long long) + AC_CHECK_SIZEOF(__int64) + AC_CHECK_SIZEOF(void *) + AC_CHECK_SIZEOF(size_t) + AC_CHECK_SIZEOF(ptrdiff_t) + + Checks for compiler characteristics + AC_C_CONST + + Checks for library functions + AC_CHECK_FUNCS(memcmp memcpy memmove memset) + + + Appendix D: Copyright + --------------------- + LZO and miniLZO are Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, + 2003, 2004, 2005, 2006, 2007, 2008 Markus Franz Xaver Johannes Oberhumer + + LZO and miniLZO are distributed under the terms of the GNU General + Public License (GPL). See the file COPYING. + + Special licenses for commercial and other applications which + are not willing to accept the GNU General Public License + are available by contacting the author. + + diff --git a/extern/lzo/minilzo/lzoconf.h b/extern/lzo/minilzo/lzoconf.h new file mode 100644 index 00000000000..cc437f1ebfe --- /dev/null +++ b/extern/lzo/minilzo/lzoconf.h @@ -0,0 +1,417 @@ +/* lzoconf.h -- configuration for the LZO real-time data compression library + + This file is part of the LZO real-time data compression library. + + Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer + All Rights Reserved. + + The LZO library 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. + + The LZO library 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 the LZO library; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Markus F.X.J. Oberhumer + + http://www.oberhumer.com/opensource/lzo/ + */ + + +#ifndef __LZOCONF_H_INCLUDED +#define __LZOCONF_H_INCLUDED + +#define LZO_VERSION 0x2030 +#define LZO_VERSION_STRING "2.03" +#define LZO_VERSION_DATE "Apr 30 2008" + +/* internal Autoconf configuration file - only used when building LZO */ +#if defined(LZO_HAVE_CONFIG_H) +# include +#endif +#include +#include + + +/*********************************************************************** +// LZO requires a conforming +************************************************************************/ + +#if !defined(CHAR_BIT) || (CHAR_BIT != 8) +# error "invalid CHAR_BIT" +#endif +#if !defined(UCHAR_MAX) || !defined(UINT_MAX) || !defined(ULONG_MAX) +# error "check your compiler installation" +#endif +#if (USHRT_MAX < 1) || (UINT_MAX < 1) || (ULONG_MAX < 1) +# error "your limits.h macros are broken" +#endif + +/* get OS and architecture defines */ +#ifndef __LZODEFS_H_INCLUDED +#include "lzodefs.h" +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*********************************************************************** +// some core defines +************************************************************************/ + +#if !defined(LZO_UINT32_C) +# if (UINT_MAX < LZO_0xffffffffL) +# define LZO_UINT32_C(c) c ## UL +# else +# define LZO_UINT32_C(c) ((c) + 0U) +# endif +#endif + +/* memory checkers */ +#if !defined(__LZO_CHECKER) +# if defined(__BOUNDS_CHECKING_ON) +# define __LZO_CHECKER 1 +# elif defined(__CHECKER__) +# define __LZO_CHECKER 1 +# elif defined(__INSURE__) +# define __LZO_CHECKER 1 +# elif defined(__PURIFY__) +# define __LZO_CHECKER 1 +# endif +#endif + + +/*********************************************************************** +// integral and pointer types +************************************************************************/ + +/* lzo_uint should match size_t */ +#if !defined(LZO_UINT_MAX) +# if defined(LZO_ABI_LLP64) /* WIN64 */ +# if defined(LZO_OS_WIN64) + typedef unsigned __int64 lzo_uint; + typedef __int64 lzo_int; +# else + typedef unsigned long long lzo_uint; + typedef long long lzo_int; +# endif +# define LZO_UINT_MAX 0xffffffffffffffffull +# define LZO_INT_MAX 9223372036854775807LL +# define LZO_INT_MIN (-1LL - LZO_INT_MAX) +# elif defined(LZO_ABI_IP32L64) /* MIPS R5900 */ + typedef unsigned int lzo_uint; + typedef int lzo_int; +# define LZO_UINT_MAX UINT_MAX +# define LZO_INT_MAX INT_MAX +# define LZO_INT_MIN INT_MIN +# elif (ULONG_MAX >= LZO_0xffffffffL) + typedef unsigned long lzo_uint; + typedef long lzo_int; +# define LZO_UINT_MAX ULONG_MAX +# define LZO_INT_MAX LONG_MAX +# define LZO_INT_MIN LONG_MIN +# else +# error "lzo_uint" +# endif +#endif + +/* Integral types with 32 bits or more. */ +#if !defined(LZO_UINT32_MAX) +# if (UINT_MAX >= LZO_0xffffffffL) + typedef unsigned int lzo_uint32; + typedef int lzo_int32; +# define LZO_UINT32_MAX UINT_MAX +# define LZO_INT32_MAX INT_MAX +# define LZO_INT32_MIN INT_MIN +# elif (ULONG_MAX >= LZO_0xffffffffL) + typedef unsigned long lzo_uint32; + typedef long lzo_int32; +# define LZO_UINT32_MAX ULONG_MAX +# define LZO_INT32_MAX LONG_MAX +# define LZO_INT32_MIN LONG_MIN +# else +# error "lzo_uint32" +# endif +#endif + +/* The larger type of lzo_uint and lzo_uint32. */ +#if (LZO_UINT_MAX >= LZO_UINT32_MAX) +# define lzo_xint lzo_uint +#else +# define lzo_xint lzo_uint32 +#endif + +/* Memory model that allows to access memory at offsets of lzo_uint. */ +#if !defined(__LZO_MMODEL) +# if (LZO_UINT_MAX <= UINT_MAX) +# define __LZO_MMODEL +# elif defined(LZO_HAVE_MM_HUGE_PTR) +# define __LZO_MMODEL_HUGE 1 +# define __LZO_MMODEL __huge +# else +# define __LZO_MMODEL +# endif +#endif + +/* no typedef here because of const-pointer issues */ +#define lzo_bytep unsigned char __LZO_MMODEL * +#define lzo_charp char __LZO_MMODEL * +#define lzo_voidp void __LZO_MMODEL * +#define lzo_shortp short __LZO_MMODEL * +#define lzo_ushortp unsigned short __LZO_MMODEL * +#define lzo_uint32p lzo_uint32 __LZO_MMODEL * +#define lzo_int32p lzo_int32 __LZO_MMODEL * +#define lzo_uintp lzo_uint __LZO_MMODEL * +#define lzo_intp lzo_int __LZO_MMODEL * +#define lzo_xintp lzo_xint __LZO_MMODEL * +#define lzo_voidpp lzo_voidp __LZO_MMODEL * +#define lzo_bytepp lzo_bytep __LZO_MMODEL * +/* deprecated - use `lzo_bytep' instead of `lzo_byte *' */ +#define lzo_byte unsigned char __LZO_MMODEL + +typedef int lzo_bool; + + +/*********************************************************************** +// function types +************************************************************************/ + +/* name mangling */ +#if !defined(__LZO_EXTERN_C) +# ifdef __cplusplus +# define __LZO_EXTERN_C extern "C" +# else +# define __LZO_EXTERN_C extern +# endif +#endif + +/* calling convention */ +#if !defined(__LZO_CDECL) +# define __LZO_CDECL __lzo_cdecl +#endif + +/* DLL export information */ +#if !defined(__LZO_EXPORT1) +# define __LZO_EXPORT1 +#endif +#if !defined(__LZO_EXPORT2) +# define __LZO_EXPORT2 +#endif + +/* __cdecl calling convention for public C and assembly functions */ +#if !defined(LZO_PUBLIC) +# define LZO_PUBLIC(_rettype) __LZO_EXPORT1 _rettype __LZO_EXPORT2 __LZO_CDECL +#endif +#if !defined(LZO_EXTERN) +# define LZO_EXTERN(_rettype) __LZO_EXTERN_C LZO_PUBLIC(_rettype) +#endif +#if !defined(LZO_PRIVATE) +# define LZO_PRIVATE(_rettype) static _rettype __LZO_CDECL +#endif + +/* function types */ +typedef int +(__LZO_CDECL *lzo_compress_t) ( const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem ); + +typedef int +(__LZO_CDECL *lzo_decompress_t) ( const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem ); + +typedef int +(__LZO_CDECL *lzo_optimize_t) ( lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem ); + +typedef int +(__LZO_CDECL *lzo_compress_dict_t)(const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem, + const lzo_bytep dict, lzo_uint dict_len ); + +typedef int +(__LZO_CDECL *lzo_decompress_dict_t)(const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem, + const lzo_bytep dict, lzo_uint dict_len ); + + +/* Callback interface. Currently only the progress indicator ("nprogress") + * is used, but this may change in a future release. */ + +struct lzo_callback_t; +typedef struct lzo_callback_t lzo_callback_t; +#define lzo_callback_p lzo_callback_t __LZO_MMODEL * + +/* malloc & free function types */ +typedef lzo_voidp (__LZO_CDECL *lzo_alloc_func_t) + (lzo_callback_p self, lzo_uint items, lzo_uint size); +typedef void (__LZO_CDECL *lzo_free_func_t) + (lzo_callback_p self, lzo_voidp ptr); + +/* a progress indicator callback function */ +typedef void (__LZO_CDECL *lzo_progress_func_t) + (lzo_callback_p, lzo_uint, lzo_uint, int); + +struct lzo_callback_t +{ + /* custom allocators (set to 0 to disable) */ + lzo_alloc_func_t nalloc; /* [not used right now] */ + lzo_free_func_t nfree; /* [not used right now] */ + + /* a progress indicator callback function (set to 0 to disable) */ + lzo_progress_func_t nprogress; + + /* NOTE: the first parameter "self" of the nalloc/nfree/nprogress + * callbacks points back to this struct, so you are free to store + * some extra info in the following variables. */ + lzo_voidp user1; + lzo_xint user2; + lzo_xint user3; +}; + + +/*********************************************************************** +// error codes and prototypes +************************************************************************/ + +/* Error codes for the compression/decompression functions. Negative + * values are errors, positive values will be used for special but + * normal events. + */ +#define LZO_E_OK 0 +#define LZO_E_ERROR (-1) +#define LZO_E_OUT_OF_MEMORY (-2) /* [not used right now] */ +#define LZO_E_NOT_COMPRESSIBLE (-3) /* [not used right now] */ +#define LZO_E_INPUT_OVERRUN (-4) +#define LZO_E_OUTPUT_OVERRUN (-5) +#define LZO_E_LOOKBEHIND_OVERRUN (-6) +#define LZO_E_EOF_NOT_FOUND (-7) +#define LZO_E_INPUT_NOT_CONSUMED (-8) +#define LZO_E_NOT_YET_IMPLEMENTED (-9) /* [not used right now] */ + + +#ifndef lzo_sizeof_dict_t +# define lzo_sizeof_dict_t ((unsigned)sizeof(lzo_bytep)) +#endif + +/* lzo_init() should be the first function you call. + * Check the return code ! + * + * lzo_init() is a macro to allow checking that the library and the + * compiler's view of various types are consistent. + */ +#define lzo_init() __lzo_init_v2(LZO_VERSION,(int)sizeof(short),(int)sizeof(int),\ + (int)sizeof(long),(int)sizeof(lzo_uint32),(int)sizeof(lzo_uint),\ + (int)lzo_sizeof_dict_t,(int)sizeof(char *),(int)sizeof(lzo_voidp),\ + (int)sizeof(lzo_callback_t)) +LZO_EXTERN(int) __lzo_init_v2(unsigned,int,int,int,int,int,int,int,int,int); + +/* version functions (useful for shared libraries) */ +LZO_EXTERN(unsigned) lzo_version(void); +LZO_EXTERN(const char *) lzo_version_string(void); +LZO_EXTERN(const char *) lzo_version_date(void); +LZO_EXTERN(const lzo_charp) _lzo_version_string(void); +LZO_EXTERN(const lzo_charp) _lzo_version_date(void); + +/* string functions */ +LZO_EXTERN(int) +lzo_memcmp(const lzo_voidp _s1, const lzo_voidp _s2, lzo_uint _len); +LZO_EXTERN(lzo_voidp) +lzo_memcpy(lzo_voidp _dest, const lzo_voidp _src, lzo_uint _len); +LZO_EXTERN(lzo_voidp) +lzo_memmove(lzo_voidp _dest, const lzo_voidp _src, lzo_uint _len); +LZO_EXTERN(lzo_voidp) +lzo_memset(lzo_voidp _s, int _c, lzo_uint _len); + +/* checksum functions */ +LZO_EXTERN(lzo_uint32) +lzo_adler32(lzo_uint32 _adler, const lzo_bytep _buf, lzo_uint _len); +LZO_EXTERN(lzo_uint32) +lzo_crc32(lzo_uint32 _c, const lzo_bytep _buf, lzo_uint _len); +LZO_EXTERN(const lzo_uint32p) +lzo_get_crc32_table(void); + +/* misc. */ +LZO_EXTERN(int) _lzo_config_check(void); +typedef union { lzo_bytep p; lzo_uint u; } __lzo_pu_u; +typedef union { lzo_bytep p; lzo_uint32 u32; } __lzo_pu32_u; +typedef union { void *vp; lzo_bytep bp; lzo_uint32 u32; long l; } lzo_align_t; + +/* align a char pointer on a boundary that is a multiple of `size' */ +LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp _ptr, lzo_uint _size); +#define LZO_PTR_ALIGN_UP(_ptr,_size) \ + ((_ptr) + (lzo_uint) __lzo_align_gap((const lzo_voidp)(_ptr),(lzo_uint)(_size))) + + +/*********************************************************************** +// deprecated macros - only for backward compatibility with LZO v1.xx +************************************************************************/ + +#if defined(LZO_CFG_COMPAT) + +#define __LZOCONF_H 1 + +#if defined(LZO_ARCH_I086) +# define __LZO_i386 1 +#elif defined(LZO_ARCH_I386) +# define __LZO_i386 1 +#endif + +#if defined(LZO_OS_DOS16) +# define __LZO_DOS 1 +# define __LZO_DOS16 1 +#elif defined(LZO_OS_DOS32) +# define __LZO_DOS 1 +#elif defined(LZO_OS_WIN16) +# define __LZO_WIN 1 +# define __LZO_WIN16 1 +#elif defined(LZO_OS_WIN32) +# define __LZO_WIN 1 +#endif + +#define __LZO_CMODEL +#define __LZO_DMODEL +#define __LZO_ENTRY __LZO_CDECL +#define LZO_EXTERN_CDECL LZO_EXTERN +#define LZO_ALIGN LZO_PTR_ALIGN_UP + +#define lzo_compress_asm_t lzo_compress_t +#define lzo_decompress_asm_t lzo_decompress_t + +#endif /* LZO_CFG_COMPAT */ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* already included */ + + +/* vim:set ts=4 et: */ diff --git a/extern/lzo/minilzo/lzodefs.h b/extern/lzo/minilzo/lzodefs.h new file mode 100644 index 00000000000..180563723e5 --- /dev/null +++ b/extern/lzo/minilzo/lzodefs.h @@ -0,0 +1,1807 @@ +/* lzodefs.h -- architecture, OS and compiler specific defines + + This file is part of the LZO real-time data compression library. + + Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer + All Rights Reserved. + + The LZO library 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. + + The LZO library 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 the LZO library; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Markus F.X.J. Oberhumer + + http://www.oberhumer.com/opensource/lzo/ + */ + + +#ifndef __LZODEFS_H_INCLUDED +#define __LZODEFS_H_INCLUDED 1 + +#if defined(__CYGWIN32__) && !defined(__CYGWIN__) +# define __CYGWIN__ __CYGWIN32__ +#endif +#if defined(__IBMCPP__) && !defined(__IBMC__) +# define __IBMC__ __IBMCPP__ +#endif +#if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER) +# define __INTEL_COMPILER __ICL +#endif +#if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE) +# define _ALL_SOURCE 1 +#endif +#if defined(__mips__) && defined(__R5900__) +# if !defined(__LONG_MAX__) +# define __LONG_MAX__ 9223372036854775807L +# endif +#endif +#if defined(__INTEL_COMPILER) && defined(__linux__) +# pragma warning(disable: 193) +#endif +#if defined(__KEIL__) && defined(__C166__) +# pragma warning disable = 322 +#elif 0 && defined(__C251__) +# pragma warning disable = 322 +#endif +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) +# if (_MSC_VER >= 1300) +# pragma warning(disable: 4668) +# endif +#endif +#if 0 && defined(__WATCOMC__) +# if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060) +# pragma warning 203 9 +# endif +#endif +#if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__) +# pragma option -h +#endif +#if 0 +#define LZO_0xffffL 0xfffful +#define LZO_0xffffffffL 0xfffffffful +#else +#define LZO_0xffffL 65535ul +#define LZO_0xffffffffL 4294967295ul +#endif +#if (LZO_0xffffL == LZO_0xffffffffL) +# error "your preprocessor is broken 1" +#endif +#if (16ul * 16384ul != 262144ul) +# error "your preprocessor is broken 2" +#endif +#if 0 +#if (32767 >= 4294967295ul) +# error "your preprocessor is broken 3" +#endif +#if (65535u >= 4294967295ul) +# error "your preprocessor is broken 4" +#endif +#endif +#if (UINT_MAX == LZO_0xffffL) +#if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__) +# if !defined(MSDOS) +# define MSDOS 1 +# endif +# if !defined(_MSDOS) +# define _MSDOS 1 +# endif +#elif 0 && defined(__VERSION) && defined(MB_LEN_MAX) +# if (__VERSION == 520) && (MB_LEN_MAX == 1) +# if !defined(__AZTEC_C__) +# define __AZTEC_C__ __VERSION +# endif +# if !defined(__DOS__) +# define __DOS__ 1 +# endif +# endif +#endif +#endif +#if defined(_MSC_VER) && defined(M_I86HM) && (UINT_MAX == LZO_0xffffL) +# define ptrdiff_t long +# define _PTRDIFF_T_DEFINED +#endif +#if (UINT_MAX == LZO_0xffffL) +# undef __LZO_RENAME_A +# undef __LZO_RENAME_B +# if defined(__AZTEC_C__) && defined(__DOS__) +# define __LZO_RENAME_A 1 +# elif defined(_MSC_VER) && defined(MSDOS) +# if (_MSC_VER < 600) +# define __LZO_RENAME_A 1 +# elif (_MSC_VER < 700) +# define __LZO_RENAME_B 1 +# endif +# elif defined(__TSC__) && defined(__OS2__) +# define __LZO_RENAME_A 1 +# elif defined(__MSDOS__) && defined(__TURBOC__) && (__TURBOC__ < 0x0410) +# define __LZO_RENAME_A 1 +# elif defined(__PACIFIC__) && defined(DOS) +# if !defined(__far) +# define __far far +# endif +# if !defined(__near) +# define __near near +# endif +# endif +# if defined(__LZO_RENAME_A) +# if !defined(__cdecl) +# define __cdecl cdecl +# endif +# if !defined(__far) +# define __far far +# endif +# if !defined(__huge) +# define __huge huge +# endif +# if !defined(__near) +# define __near near +# endif +# if !defined(__pascal) +# define __pascal pascal +# endif +# if !defined(__huge) +# define __huge huge +# endif +# elif defined(__LZO_RENAME_B) +# if !defined(__cdecl) +# define __cdecl _cdecl +# endif +# if !defined(__far) +# define __far _far +# endif +# if !defined(__huge) +# define __huge _huge +# endif +# if !defined(__near) +# define __near _near +# endif +# if !defined(__pascal) +# define __pascal _pascal +# endif +# elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__) +# if !defined(__cdecl) +# define __cdecl cdecl +# endif +# if !defined(__pascal) +# define __pascal pascal +# endif +# endif +# undef __LZO_RENAME_A +# undef __LZO_RENAME_B +#endif +#if (UINT_MAX == LZO_0xffffL) +#if defined(__AZTEC_C__) && defined(__DOS__) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +#elif defined(_MSC_VER) && defined(MSDOS) +# if (_MSC_VER < 600) +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +# endif +# if (_MSC_VER < 700) +# define LZO_BROKEN_INTEGRAL_PROMOTION 1 +# define LZO_BROKEN_SIZEOF 1 +# endif +#elif defined(__PACIFIC__) && defined(DOS) +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +#elif defined(__TURBOC__) && defined(__MSDOS__) +# if (__TURBOC__ < 0x0150) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +# define LZO_BROKEN_INTEGRAL_PROMOTION 1 +# endif +# if (__TURBOC__ < 0x0200) +# define LZO_BROKEN_SIZEOF 1 +# endif +# if (__TURBOC__ < 0x0400) && defined(__cplusplus) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +# endif +#elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +# define LZO_BROKEN_SIZEOF 1 +#endif +#endif +#if defined(__WATCOMC__) && (__WATCOMC__ < 900) +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +#endif +#if defined(_CRAY) && defined(_CRAY1) +# define LZO_BROKEN_SIGNED_RIGHT_SHIFT 1 +#endif +#define LZO_PP_STRINGIZE(x) #x +#define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x) +#define LZO_PP_CONCAT2(a,b) a ## b +#define LZO_PP_CONCAT3(a,b,c) a ## b ## c +#define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d +#define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e +#define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b) +#define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c) +#define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d) +#define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e) +#if 1 +#define LZO_CPP_STRINGIZE(x) #x +#define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x) +#define LZO_CPP_CONCAT2(a,b) a ## b +#define LZO_CPP_CONCAT3(a,b,c) a ## b ## c +#define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d +#define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e +#define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b) +#define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c) +#define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d) +#define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e) +#endif +#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o)) +#if 1 && defined(__cplusplus) +# if !defined(__STDC_CONSTANT_MACROS) +# define __STDC_CONSTANT_MACROS 1 +# endif +# if !defined(__STDC_LIMIT_MACROS) +# define __STDC_LIMIT_MACROS 1 +# endif +#endif +#if defined(__cplusplus) +# define LZO_EXTERN_C extern "C" +#else +# define LZO_EXTERN_C extern +#endif +#if !defined(__LZO_OS_OVERRIDE) +#if defined(LZO_OS_FREESTANDING) +# define LZO_INFO_OS "freestanding" +#elif defined(LZO_OS_EMBEDDED) +# define LZO_INFO_OS "embedded" +#elif 1 && defined(__IAR_SYSTEMS_ICC__) +# define LZO_OS_EMBEDDED 1 +# define LZO_INFO_OS "embedded" +#elif defined(__CYGWIN__) && defined(__GNUC__) +# define LZO_OS_CYGWIN 1 +# define LZO_INFO_OS "cygwin" +#elif defined(__EMX__) && defined(__GNUC__) +# define LZO_OS_EMX 1 +# define LZO_INFO_OS "emx" +#elif defined(__BEOS__) +# define LZO_OS_BEOS 1 +# define LZO_INFO_OS "beos" +#elif defined(__Lynx__) +# define LZO_OS_LYNXOS 1 +# define LZO_INFO_OS "lynxos" +#elif defined(__OS400__) +# define LZO_OS_OS400 1 +# define LZO_INFO_OS "os400" +#elif defined(__QNX__) +# define LZO_OS_QNX 1 +# define LZO_INFO_OS "qnx" +#elif defined(__BORLANDC__) && defined(__DPMI32__) && (__BORLANDC__ >= 0x0460) +# define LZO_OS_DOS32 1 +# define LZO_INFO_OS "dos32" +#elif defined(__BORLANDC__) && defined(__DPMI16__) +# define LZO_OS_DOS16 1 +# define LZO_INFO_OS "dos16" +#elif defined(__ZTC__) && defined(DOS386) +# define LZO_OS_DOS32 1 +# define LZO_INFO_OS "dos32" +#elif defined(__OS2__) || defined(__OS2V2__) +# if (UINT_MAX == LZO_0xffffL) +# define LZO_OS_OS216 1 +# define LZO_INFO_OS "os216" +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_OS_OS2 1 +# define LZO_INFO_OS "os2" +# else +# error "check your limits.h header" +# endif +#elif defined(__WIN64__) || defined(_WIN64) || defined(WIN64) +# define LZO_OS_WIN64 1 +# define LZO_INFO_OS "win64" +#elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WINDOWS_386__) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +#elif defined(__MWERKS__) && defined(__INTEL__) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +#elif defined(__WINDOWS__) || defined(_WINDOWS) || defined(_Windows) +# if (UINT_MAX == LZO_0xffffL) +# define LZO_OS_WIN16 1 +# define LZO_INFO_OS "win16" +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +# else +# error "check your limits.h header" +# endif +#elif defined(__DOS__) || defined(__MSDOS__) || defined(_MSDOS) || defined(MSDOS) || (defined(__PACIFIC__) && defined(DOS)) +# if (UINT_MAX == LZO_0xffffL) +# define LZO_OS_DOS16 1 +# define LZO_INFO_OS "dos16" +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_OS_DOS32 1 +# define LZO_INFO_OS "dos32" +# else +# error "check your limits.h header" +# endif +#elif defined(__WATCOMC__) +# if defined(__NT__) && (UINT_MAX == LZO_0xffffL) +# define LZO_OS_DOS16 1 +# define LZO_INFO_OS "dos16" +# elif defined(__NT__) && (__WATCOMC__ < 1100) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +# elif defined(__linux__) || defined(__LINUX__) +# define LZO_OS_POSIX 1 +# define LZO_INFO_OS "posix" +# else +# error "please specify a target using the -bt compiler option" +# endif +#elif defined(__palmos__) +# define LZO_OS_PALMOS 1 +# define LZO_INFO_OS "palmos" +#elif defined(__TOS__) || defined(__atarist__) +# define LZO_OS_TOS 1 +# define LZO_INFO_OS "tos" +#elif defined(macintosh) && !defined(__ppc__) +# define LZO_OS_MACCLASSIC 1 +# define LZO_INFO_OS "macclassic" +#elif defined(__VMS) +# define LZO_OS_VMS 1 +# define LZO_INFO_OS "vms" +#elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +# define LZO_OS_CONSOLE 1 +# define LZO_OS_CONSOLE_PS2 1 +# define LZO_INFO_OS "console" +# define LZO_INFO_OS_CONSOLE "ps2" +#elif (defined(__mips__) && defined(__psp__)) +# define LZO_OS_CONSOLE 1 +# define LZO_OS_CONSOLE_PSP 1 +# define LZO_INFO_OS "console" +# define LZO_INFO_OS_CONSOLE "psp" +#else +# define LZO_OS_POSIX 1 +# define LZO_INFO_OS "posix" +#endif +#if (LZO_OS_POSIX) +# if defined(_AIX) || defined(__AIX__) || defined(__aix__) +# define LZO_OS_POSIX_AIX 1 +# define LZO_INFO_OS_POSIX "aix" +# elif defined(__FreeBSD__) +# define LZO_OS_POSIX_FREEBSD 1 +# define LZO_INFO_OS_POSIX "freebsd" +# elif defined(__hpux__) || defined(__hpux) +# define LZO_OS_POSIX_HPUX 1 +# define LZO_INFO_OS_POSIX "hpux" +# elif defined(__INTERIX) +# define LZO_OS_POSIX_INTERIX 1 +# define LZO_INFO_OS_POSIX "interix" +# elif defined(__IRIX__) || defined(__irix__) +# define LZO_OS_POSIX_IRIX 1 +# define LZO_INFO_OS_POSIX "irix" +# elif defined(__linux__) || defined(__linux) || defined(__LINUX__) +# define LZO_OS_POSIX_LINUX 1 +# define LZO_INFO_OS_POSIX "linux" +# elif defined(__APPLE__) || defined(__MACOS__) +# define LZO_OS_POSIX_MACOSX 1 +# define LZO_INFO_OS_POSIX "macosx" +# elif defined(__minix__) || defined(__minix) +# define LZO_OS_POSIX_MINIX 1 +# define LZO_INFO_OS_POSIX "minix" +# elif defined(__NetBSD__) +# define LZO_OS_POSIX_NETBSD 1 +# define LZO_INFO_OS_POSIX "netbsd" +# elif defined(__OpenBSD__) +# define LZO_OS_POSIX_OPENBSD 1 +# define LZO_INFO_OS_POSIX "openbsd" +# elif defined(__osf__) +# define LZO_OS_POSIX_OSF 1 +# define LZO_INFO_OS_POSIX "osf" +# elif defined(__solaris__) || defined(__sun) +# if defined(__SVR4) || defined(__svr4__) +# define LZO_OS_POSIX_SOLARIS 1 +# define LZO_INFO_OS_POSIX "solaris" +# else +# define LZO_OS_POSIX_SUNOS 1 +# define LZO_INFO_OS_POSIX "sunos" +# endif +# elif defined(__ultrix__) || defined(__ultrix) +# define LZO_OS_POSIX_ULTRIX 1 +# define LZO_INFO_OS_POSIX "ultrix" +# elif defined(_UNICOS) +# define LZO_OS_POSIX_UNICOS 1 +# define LZO_INFO_OS_POSIX "unicos" +# else +# define LZO_OS_POSIX_UNKNOWN 1 +# define LZO_INFO_OS_POSIX "unknown" +# endif +#endif +#endif +#if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +# if (UINT_MAX != LZO_0xffffL) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64) +# if (UINT_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if defined(CIL) && defined(_GNUCC) && defined(__GNUC__) +# define LZO_CC_CILLY 1 +# define LZO_INFO_CC "Cilly" +# if defined(__CILLY__) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__CILLY__) +# else +# define LZO_INFO_CCVER "unknown" +# endif +#elif 0 && defined(SDCC) && defined(__VERSION__) && !defined(__GNUC__) +# define LZO_CC_SDCC 1 +# define LZO_INFO_CC "sdcc" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC) +#elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__) +# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__) +# define LZO_INFO_CC "Pathscale C" +# define LZO_INFO_CCVER __PATHSCALE__ +#elif defined(__INTEL_COMPILER) +# define LZO_CC_INTELC 1 +# define LZO_INFO_CC "Intel C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER) +# if defined(_WIN32) || defined(_WIN64) +# define LZO_CC_SYNTAX_MSC 1 +# else +# define LZO_CC_SYNTAX_GNUC 1 +# endif +#elif defined(__POCC__) && defined(_WIN32) +# define LZO_CC_PELLESC 1 +# define LZO_INFO_CC "Pelles C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__) +#elif defined(__llvm__) && defined(__GNUC__) && defined(__VERSION__) +# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +# define LZO_CC_LLVM (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# else +# define LZO_CC_LLVM (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# endif +# define LZO_INFO_CC "llvm-gcc" +# define LZO_INFO_CCVER __VERSION__ +#elif defined(__GNUC__) && defined(__VERSION__) +# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# elif defined(__GNUC_MINOR__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# else +# define LZO_CC_GNUC (__GNUC__ * 0x10000L) +# endif +# define LZO_INFO_CC "gcc" +# define LZO_INFO_CCVER __VERSION__ +#elif defined(__ACK__) && defined(_ACK) +# define LZO_CC_ACK 1 +# define LZO_INFO_CC "Amsterdam Compiler Kit C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__AZTEC_C__) +# define LZO_CC_AZTECC 1 +# define LZO_INFO_CC "Aztec C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__AZTEC_C__) +#elif defined(__BORLANDC__) +# define LZO_CC_BORLANDC 1 +# define LZO_INFO_CC "Borland C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__BORLANDC__) +#elif defined(_CRAYC) && defined(_RELEASE) +# define LZO_CC_CRAYC 1 +# define LZO_INFO_CC "Cray C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_RELEASE) +#elif defined(__DMC__) && defined(__SC__) +# define LZO_CC_DMC 1 +# define LZO_INFO_CC "Digital Mars C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DMC__) +#elif defined(__DECC) +# define LZO_CC_DECC 1 +# define LZO_INFO_CC "DEC C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC) +#elif defined(__HIGHC__) +# define LZO_CC_HIGHC 1 +# define LZO_INFO_CC "MetaWare High C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__IAR_SYSTEMS_ICC__) +# define LZO_CC_IARC 1 +# define LZO_INFO_CC "IAR C" +# if defined(__VER__) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__VER__) +# else +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(__IBMC__) +# define LZO_CC_IBMC 1 +# define LZO_INFO_CC "IBM C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__) +#elif defined(__KEIL__) && defined(__C166__) +# define LZO_CC_KEILC 1 +# define LZO_INFO_CC "Keil C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__C166__) +#elif defined(__LCC__) && defined(_WIN32) && defined(__LCCOPTIMLEVEL) +# define LZO_CC_LCCWIN32 1 +# define LZO_INFO_CC "lcc-win32" +# define LZO_INFO_CCVER "unknown" +#elif defined(__LCC__) +# define LZO_CC_LCC 1 +# define LZO_INFO_CC "lcc" +# if defined(__LCC_VERSION__) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__LCC_VERSION__) +# else +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(_MSC_VER) +# define LZO_CC_MSC 1 +# define LZO_INFO_CC "Microsoft C" +# if defined(_MSC_FULL_VER) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) +# else +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) +# endif +#elif defined(__MWERKS__) +# define LZO_CC_MWERKS 1 +# define LZO_INFO_CC "Metrowerks C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__) +#elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386) +# define LZO_CC_NDPC 1 +# define LZO_INFO_CC "Microway NDP C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__PACIFIC__) +# define LZO_CC_PACIFICC 1 +# define LZO_INFO_CC "Pacific C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__) +#elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__)) +# define LZO_CC_PGI 1 +# define LZO_INFO_CC "Portland Group PGI C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__PUREC__) && defined(__TOS__) +# define LZO_CC_PUREC 1 +# define LZO_INFO_CC "Pure C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PUREC__) +#elif defined(__SC__) && defined(__ZTC__) +# define LZO_CC_SYMANTECC 1 +# define LZO_INFO_CC "Symantec C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__) +#elif defined(__SUNPRO_C) +# define LZO_INFO_CC "SunPro C" +# if ((__SUNPRO_C)+0 > 0) +# define LZO_CC_SUNPROC __SUNPRO_C +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C) +# else +# define LZO_CC_SUNPROC 1 +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(__SUNPRO_CC) +# define LZO_INFO_CC "SunPro C" +# if ((__SUNPRO_CC)+0 > 0) +# define LZO_CC_SUNPROC __SUNPRO_CC +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC) +# else +# define LZO_CC_SUNPROC 1 +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(__TINYC__) +# define LZO_CC_TINYC 1 +# define LZO_INFO_CC "Tiny C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TINYC__) +#elif defined(__TSC__) +# define LZO_CC_TOPSPEEDC 1 +# define LZO_INFO_CC "TopSpeed C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TSC__) +#elif defined(__WATCOMC__) +# define LZO_CC_WATCOMC 1 +# define LZO_INFO_CC "Watcom C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__WATCOMC__) +#elif defined(__TURBOC__) +# define LZO_CC_TURBOC 1 +# define LZO_INFO_CC "Turbo C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TURBOC__) +#elif defined(__ZTC__) +# define LZO_CC_ZORTECHC 1 +# define LZO_INFO_CC "Zortech C" +# if (__ZTC__ == 0x310) +# define LZO_INFO_CCVER "0x310" +# else +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__) +# endif +#else +# define LZO_CC_UNKNOWN 1 +# define LZO_INFO_CC "unknown" +# define LZO_INFO_CCVER "unknown" +#endif +#if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER) +# error "LZO_CC_MSC: _MSC_FULL_VER is not defined" +#endif +#if !defined(__LZO_ARCH_OVERRIDE) && !defined(LZO_ARCH_GENERIC) && defined(_CRAY) +# if (UINT_MAX > LZO_0xffffffffL) && defined(_CRAY) +# if defined(_CRAYMPP) || defined(_CRAYT3D) || defined(_CRAYT3E) +# define LZO_ARCH_CRAY_MPP 1 +# elif defined(_CRAY1) +# define LZO_ARCH_CRAY_PVP 1 +# endif +# endif +#endif +#if !defined(__LZO_ARCH_OVERRIDE) +#if defined(LZO_ARCH_GENERIC) +# define LZO_INFO_ARCH "generic" +#elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +# define LZO_ARCH_I086 1 +# define LZO_ARCH_IA16 1 +# define LZO_INFO_ARCH "i086" +#elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) +# define LZO_ARCH_ALPHA 1 +# define LZO_INFO_ARCH "alpha" +#elif (LZO_ARCH_CRAY_MPP) && (defined(_CRAYT3D) || defined(_CRAYT3E)) +# define LZO_ARCH_ALPHA 1 +# define LZO_INFO_ARCH "alpha" +#elif defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64) +# define LZO_ARCH_AMD64 1 +# define LZO_INFO_ARCH "amd64" +#elif defined(__thumb__) || (defined(_M_ARM) && defined(_M_THUMB)) +# define LZO_ARCH_ARM 1 +# define LZO_ARCH_ARM_THUMB 1 +# define LZO_INFO_ARCH "arm_thumb" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__) +# define LZO_ARCH_ARM 1 +# if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1) +# define LZO_ARCH_ARM_THUMB 1 +# define LZO_INFO_ARCH "arm_thumb" +# elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2) +# define LZO_INFO_ARCH "arm" +# else +# define LZO_INFO_ARCH "arm" +# endif +#elif defined(__arm__) || defined(_M_ARM) +# define LZO_ARCH_ARM 1 +# define LZO_INFO_ARCH "arm" +#elif (UINT_MAX <= LZO_0xffffL) && defined(__AVR__) +# define LZO_ARCH_AVR 1 +# define LZO_INFO_ARCH "avr" +#elif defined(__bfin__) +# define LZO_ARCH_BLACKFIN 1 +# define LZO_INFO_ARCH "blackfin" +#elif (UINT_MAX == LZO_0xffffL) && defined(__C166__) +# define LZO_ARCH_C166 1 +# define LZO_INFO_ARCH "c166" +#elif defined(__cris__) +# define LZO_ARCH_CRIS 1 +# define LZO_INFO_ARCH "cris" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCEZ80__) +# define LZO_ARCH_EZ80 1 +# define LZO_INFO_ARCH "ez80" +#elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# define LZO_ARCH_H8300 1 +# define LZO_INFO_ARCH "h8300" +#elif defined(__hppa__) || defined(__hppa) +# define LZO_ARCH_HPPA 1 +# define LZO_INFO_ARCH "hppa" +#elif defined(__386__) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_M_I386) +# define LZO_ARCH_I386 1 +# define LZO_ARCH_IA32 1 +# define LZO_INFO_ARCH "i386" +#elif (LZO_CC_ZORTECHC && defined(__I86__)) +# define LZO_ARCH_I386 1 +# define LZO_ARCH_IA32 1 +# define LZO_INFO_ARCH "i386" +#elif (LZO_OS_DOS32 && LZO_CC_HIGHC) && defined(_I386) +# define LZO_ARCH_I386 1 +# define LZO_ARCH_IA32 1 +# define LZO_INFO_ARCH "i386" +#elif defined(__ia64__) || defined(__ia64) || defined(_M_IA64) +# define LZO_ARCH_IA64 1 +# define LZO_INFO_ARCH "ia64" +#elif (UINT_MAX == LZO_0xffffL) && defined(__m32c__) +# define LZO_ARCH_M16C 1 +# define LZO_INFO_ARCH "m16c" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCM16C__) +# define LZO_ARCH_M16C 1 +# define LZO_INFO_ARCH "m16c" +#elif defined(__m32r__) +# define LZO_ARCH_M32R 1 +# define LZO_INFO_ARCH "m32r" +#elif (LZO_OS_TOS) || defined(__m68k__) || defined(__m68000__) || defined(__mc68000__) || defined(__mc68020__) || defined(_M_M68K) +# define LZO_ARCH_M68K 1 +# define LZO_INFO_ARCH "m68k" +#elif (UINT_MAX == LZO_0xffffL) && defined(__C251__) +# define LZO_ARCH_MCS251 1 +# define LZO_INFO_ARCH "mcs251" +#elif (UINT_MAX == LZO_0xffffL) && defined(__C51__) +# define LZO_ARCH_MCS51 1 +# define LZO_INFO_ARCH "mcs51" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC8051__) +# define LZO_ARCH_MCS51 1 +# define LZO_INFO_ARCH "mcs51" +#elif defined(__mips__) || defined(__mips) || defined(_MIPS_ARCH) || defined(_M_MRX000) +# define LZO_ARCH_MIPS 1 +# define LZO_INFO_ARCH "mips" +#elif (UINT_MAX == LZO_0xffffL) && defined(__MSP430__) +# define LZO_ARCH_MSP430 1 +# define LZO_INFO_ARCH "msp430" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC430__) +# define LZO_ARCH_MSP430 1 +# define LZO_INFO_ARCH "msp430" +#elif defined(__powerpc__) || defined(__powerpc) || defined(__ppc__) || defined(__PPC__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PWR) +# define LZO_ARCH_POWERPC 1 +# define LZO_INFO_ARCH "powerpc" +#elif defined(__s390__) || defined(__s390) || defined(__s390x__) || defined(__s390x) +# define LZO_ARCH_S390 1 +# define LZO_INFO_ARCH "s390" +#elif defined(__sh__) || defined(_M_SH) +# define LZO_ARCH_SH 1 +# define LZO_INFO_ARCH "sh" +#elif defined(__sparc__) || defined(__sparc) || defined(__sparcv8) +# define LZO_ARCH_SPARC 1 +# define LZO_INFO_ARCH "sparc" +#elif defined(__SPU__) +# define LZO_ARCH_SPU 1 +# define LZO_INFO_ARCH "spu" +#elif (UINT_MAX == LZO_0xffffL) && defined(__z80) +# define LZO_ARCH_Z80 1 +# define LZO_INFO_ARCH "z80" +#elif (LZO_ARCH_CRAY_PVP) +# if defined(_CRAYSV1) +# define LZO_ARCH_CRAY_SV1 1 +# define LZO_INFO_ARCH "cray_sv1" +# elif (_ADDR64) +# define LZO_ARCH_CRAY_T90 1 +# define LZO_INFO_ARCH "cray_t90" +# elif (_ADDR32) +# define LZO_ARCH_CRAY_YMP 1 +# define LZO_INFO_ARCH "cray_ymp" +# else +# define LZO_ARCH_CRAY_XMP 1 +# define LZO_INFO_ARCH "cray_xmp" +# endif +#else +# define LZO_ARCH_UNKNOWN 1 +# define LZO_INFO_ARCH "unknown" +#endif +#endif +#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_DOS32 || LZO_OS_OS2) +# error "FIXME - missing define for CPU architecture" +#endif +#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32) +# error "FIXME - missing WIN32 define for CPU architecture" +#endif +#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64) +# error "FIXME - missing WIN64 define for CPU architecture" +#endif +#if (LZO_OS_OS216 || LZO_OS_WIN16) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#elif 1 && (LZO_OS_DOS16 && defined(BLX286)) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#elif 1 && (LZO_OS_DOS16 && defined(DOSX286)) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__)) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#endif +#if defined(LZO_ARCH_ARM_THUMB) && !defined(LZO_ARCH_ARM) +# error "this should not happen" +#endif +#if defined(LZO_ARCH_I086PM) && !defined(LZO_ARCH_I086) +# error "this should not happen" +#endif +#if (LZO_ARCH_I086) +# if (UINT_MAX != LZO_0xffffL) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if (LZO_ARCH_I386) +# if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__) +# error "this should not happen" +# endif +# if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if !defined(__LZO_MM_OVERRIDE) +#if (LZO_ARCH_I086) +#if (UINT_MAX != LZO_0xffffL) +# error "this should not happen" +#endif +#if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM) +# define LZO_MM_TINY 1 +#elif defined(__HUGE__) || defined(_HUGE_) || defined(M_I86HM) || defined(_M_I86HM) +# define LZO_MM_HUGE 1 +#elif defined(__SMALL__) || defined(M_I86SM) || defined(_M_I86SM) || defined(SMALL_MODEL) +# define LZO_MM_SMALL 1 +#elif defined(__MEDIUM__) || defined(M_I86MM) || defined(_M_I86MM) +# define LZO_MM_MEDIUM 1 +#elif defined(__COMPACT__) || defined(M_I86CM) || defined(_M_I86CM) +# define LZO_MM_COMPACT 1 +#elif defined(__LARGE__) || defined(M_I86LM) || defined(_M_I86LM) || defined(LARGE_MODEL) +# define LZO_MM_LARGE 1 +#elif (LZO_CC_AZTECC) +# if defined(_LARGE_CODE) && defined(_LARGE_DATA) +# define LZO_MM_LARGE 1 +# elif defined(_LARGE_CODE) +# define LZO_MM_MEDIUM 1 +# elif defined(_LARGE_DATA) +# define LZO_MM_COMPACT 1 +# else +# define LZO_MM_SMALL 1 +# endif +#elif (LZO_CC_ZORTECHC && defined(__VCM__)) +# define LZO_MM_LARGE 1 +#else +# error "unknown memory model" +#endif +#if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +#define LZO_HAVE_MM_HUGE_PTR 1 +#define LZO_HAVE_MM_HUGE_ARRAY 1 +#if (LZO_MM_TINY) +# undef LZO_HAVE_MM_HUGE_ARRAY +#endif +#if (LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_ZORTECHC) +# undef LZO_HAVE_MM_HUGE_PTR +# undef LZO_HAVE_MM_HUGE_ARRAY +#elif (LZO_CC_DMC || LZO_CC_SYMANTECC) +# undef LZO_HAVE_MM_HUGE_ARRAY +#elif (LZO_CC_MSC && defined(_QC)) +# undef LZO_HAVE_MM_HUGE_ARRAY +# if (_MSC_VER < 600) +# undef LZO_HAVE_MM_HUGE_PTR +# endif +#elif (LZO_CC_TURBOC && (__TURBOC__ < 0x0295)) +# undef LZO_HAVE_MM_HUGE_ARRAY +#endif +#if (LZO_ARCH_I086PM) && !defined(LZO_HAVE_MM_HUGE_PTR) +# if (LZO_OS_DOS16) +# error "this should not happen" +# elif (LZO_CC_ZORTECHC) +# else +# error "this should not happen" +# endif +#endif +#ifdef __cplusplus +extern "C" { +#endif +#if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0200)) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif (LZO_CC_MSC || LZO_CC_TOPSPEEDC) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif (LZO_CC_TURBOC && (__TURBOC__ >= 0x0295)) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif ((LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_TURBOC) && LZO_OS_DOS16) +# define LZO_MM_AHSHIFT 12 +#elif (LZO_CC_WATCOMC) + extern unsigned char _HShift; +# define LZO_MM_AHSHIFT ((unsigned) _HShift) +#else +# error "FIXME - implement LZO_MM_AHSHIFT" +#endif +#ifdef __cplusplus +} +#endif +#endif +#elif (LZO_ARCH_C166) +#if !defined(__MODEL__) +# error "FIXME - C166 __MODEL__" +#elif ((__MODEL__) == 0) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 1) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 2) +# define LZO_MM_LARGE 1 +#elif ((__MODEL__) == 3) +# define LZO_MM_TINY 1 +#elif ((__MODEL__) == 4) +# define LZO_MM_XTINY 1 +#elif ((__MODEL__) == 5) +# define LZO_MM_XSMALL 1 +#else +# error "FIXME - C166 __MODEL__" +#endif +#elif (LZO_ARCH_MCS251) +#if !defined(__MODEL__) +# error "FIXME - MCS251 __MODEL__" +#elif ((__MODEL__) == 0) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 2) +# define LZO_MM_LARGE 1 +#elif ((__MODEL__) == 3) +# define LZO_MM_TINY 1 +#elif ((__MODEL__) == 4) +# define LZO_MM_XTINY 1 +#elif ((__MODEL__) == 5) +# define LZO_MM_XSMALL 1 +#else +# error "FIXME - MCS251 __MODEL__" +#endif +#elif (LZO_ARCH_MCS51) +#if !defined(__MODEL__) +# error "FIXME - MCS51 __MODEL__" +#elif ((__MODEL__) == 1) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 2) +# define LZO_MM_LARGE 1 +#elif ((__MODEL__) == 3) +# define LZO_MM_TINY 1 +#elif ((__MODEL__) == 4) +# define LZO_MM_XTINY 1 +#elif ((__MODEL__) == 5) +# define LZO_MM_XSMALL 1 +#else +# error "FIXME - MCS51 __MODEL__" +#endif +#elif (LZO_ARCH_CRAY_PVP) +# define LZO_MM_PVP 1 +#else +# define LZO_MM_FLAT 1 +#endif +#if (LZO_MM_COMPACT) +# define LZO_INFO_MM "compact" +#elif (LZO_MM_FLAT) +# define LZO_INFO_MM "flat" +#elif (LZO_MM_HUGE) +# define LZO_INFO_MM "huge" +#elif (LZO_MM_LARGE) +# define LZO_INFO_MM "large" +#elif (LZO_MM_MEDIUM) +# define LZO_INFO_MM "medium" +#elif (LZO_MM_PVP) +# define LZO_INFO_MM "pvp" +#elif (LZO_MM_SMALL) +# define LZO_INFO_MM "small" +#elif (LZO_MM_TINY) +# define LZO_INFO_MM "tiny" +#else +# error "unknown memory model" +#endif +#endif +#if defined(SIZEOF_SHORT) +# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) +#endif +#if defined(SIZEOF_INT) +# define LZO_SIZEOF_INT (SIZEOF_INT) +#endif +#if defined(SIZEOF_LONG) +# define LZO_SIZEOF_LONG (SIZEOF_LONG) +#endif +#if defined(SIZEOF_LONG_LONG) +# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) +#endif +#if defined(SIZEOF___INT16) +# define LZO_SIZEOF___INT16 (SIZEOF___INT16) +#endif +#if defined(SIZEOF___INT32) +# define LZO_SIZEOF___INT32 (SIZEOF___INT32) +#endif +#if defined(SIZEOF___INT64) +# define LZO_SIZEOF___INT64 (SIZEOF___INT64) +#endif +#if defined(SIZEOF_VOID_P) +# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) +#endif +#if defined(SIZEOF_SIZE_T) +# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) +#endif +#if defined(SIZEOF_PTRDIFF_T) +# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) +#endif +#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) +#if !defined(LZO_SIZEOF_SHORT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_SHORT 8 +# elif (USHRT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,7) == 1) +# define LZO_SIZEOF_SHORT 1 +# elif (__LZO_LSR(USHRT_MAX,15) == 1) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,31) == 1) +# define LZO_SIZEOF_SHORT 4 +# elif (__LZO_LSR(USHRT_MAX,63) == 1) +# define LZO_SIZEOF_SHORT 8 +# elif (__LZO_LSR(USHRT_MAX,127) == 1) +# define LZO_SIZEOF_SHORT 16 +# else +# error "LZO_SIZEOF_SHORT" +# endif +#endif +#if !defined(LZO_SIZEOF_INT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_INT 8 +# elif (UINT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_INT 2 +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,7) == 1) +# define LZO_SIZEOF_INT 1 +# elif (__LZO_LSR(UINT_MAX,15) == 1) +# define LZO_SIZEOF_INT 2 +# elif (__LZO_LSR(UINT_MAX,31) == 1) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,63) == 1) +# define LZO_SIZEOF_INT 8 +# elif (__LZO_LSR(UINT_MAX,127) == 1) +# define LZO_SIZEOF_INT 16 +# else +# error "LZO_SIZEOF_INT" +# endif +#endif +#if !defined(LZO_SIZEOF_LONG) +# if (ULONG_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,7) == 1) +# define LZO_SIZEOF_LONG 1 +# elif (__LZO_LSR(ULONG_MAX,15) == 1) +# define LZO_SIZEOF_LONG 2 +# elif (__LZO_LSR(ULONG_MAX,31) == 1) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,63) == 1) +# define LZO_SIZEOF_LONG 8 +# elif (__LZO_LSR(ULONG_MAX,127) == 1) +# define LZO_SIZEOF_LONG 16 +# else +# error "LZO_SIZEOF_LONG" +# endif +#endif +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) +# if (LZO_CC_GNUC >= 0x030300ul) +# if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0) +# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG +# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) +# define LZO_SIZEOF_LONG_LONG 4 +# endif +# endif +# endif +#endif +#endif +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +#if (LZO_ARCH_I086 && LZO_CC_DMC) +#elif (LZO_CC_CILLY) && defined(__GNUC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_SIZEOF_LONG_LONG 8 +#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_OS_WIN64 || defined(_WIN64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) +#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# define LZO_SIZEOF_LONG_LONG 8 +#endif +#endif +#endif +#if defined(__cplusplus) && defined(LZO_CC_GNUC) +# if (LZO_CC_GNUC < 0x020800ul) +# undef LZO_SIZEOF_LONG_LONG +# endif +#endif +#if defined(LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG) +# undef LZO_SIZEOF_LONG_LONG +#endif +#if !defined(LZO_SIZEOF_VOID_P) +#if (LZO_ARCH_I086) +# define __LZO_WORDSIZE 2 +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) +# define LZO_SIZEOF_VOID_P 2 +# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) +# define LZO_SIZEOF_VOID_P 4 +# else +# error "LZO_MM" +# endif +#elif (LZO_ARCH_AVR || LZO_ARCH_Z80) +# define __LZO_WORDSIZE 1 +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_H8300) +# if defined(__NORMAL_MODE__) +# define __LZO_WORDSIZE 4 +# define LZO_SIZEOF_VOID_P 2 +# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# define __LZO_WORDSIZE 4 +# define LZO_SIZEOF_VOID_P 4 +# else +# define __LZO_WORDSIZE 2 +# define LZO_SIZEOF_VOID_P 2 +# endif +# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT +# endif +#elif (LZO_ARCH_M16C) +# define __LZO_WORDSIZE 2 +# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) +# define LZO_SIZEOF_VOID_P 4 +# else +# define LZO_SIZEOF_VOID_P 2 +# endif +#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +# define __LZO_WORDSIZE 8 +# define LZO_SIZEOF_VOID_P 4 +#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) +# define __LZO_WORDSIZE 8 +# define LZO_SIZEOF_VOID_P 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (LZO_OS_OS400 || defined(__OS400__)) +# define __LZO_WORDSIZE LZO_SIZEOF_LONG +# define LZO_SIZEOF_VOID_P 16 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_SIZEOF_VOID_P 8 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (LZO_ARCH_SPU) +# if 0 +# define __LZO_WORDSIZE 16 +# endif +# define LZO_SIZEOF_VOID_P 4 +#else +# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +#endif +#endif +#if !defined(LZO_WORDSIZE) +# if defined(__LZO_WORDSIZE) +# define LZO_WORDSIZE __LZO_WORDSIZE +# else +# define LZO_WORDSIZE LZO_SIZEOF_VOID_P +# endif +#endif +#if !defined(LZO_SIZEOF_SIZE_T) +#if (LZO_ARCH_I086 || LZO_ARCH_M16C) +# define LZO_SIZEOF_SIZE_T 2 +#else +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P +#endif +#endif +#if !defined(LZO_SIZEOF_PTRDIFF_T) +#if (LZO_ARCH_I086) +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P +# elif (LZO_MM_COMPACT || LZO_MM_LARGE) +# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) +# define LZO_SIZEOF_PTRDIFF_T 4 +# else +# define LZO_SIZEOF_PTRDIFF_T 2 +# endif +# else +# error "LZO_MM" +# endif +#else +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T +#endif +#endif +#if defined(LZO_ABI_NEUTRAL_ENDIAN) +# undef LZO_ABI_BIG_ENDIAN +# undef LZO_ABI_LITTLE_ENDIAN +#elif !defined(LZO_ABI_BIG_ENDIAN) && !defined(LZO_ABI_LITTLE_ENDIAN) +#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) +# define LZO_ABI_BIG_ENDIAN 1 +#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif (LZO_ARCH_M68K || LZO_ARCH_S390) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) +# if (__LITTLE_ENDIAN__ == 1) +# define LZO_ABI_LITTLE_ENDIAN 1 +# else +# define LZO_ABI_BIG_ENDIAN 1 +# endif +#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#endif +#endif +#if defined(LZO_ABI_BIG_ENDIAN) && defined(LZO_ABI_LITTLE_ENDIAN) +# error "this should not happen" +#endif +#if defined(LZO_ABI_BIG_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "be" +#elif defined(LZO_ABI_LITTLE_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "le" +#elif defined(LZO_ABI_NEUTRAL_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "neutral" +#endif +#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_I8LP16 1 +# define LZO_INFO_ABI_PM "i8lp16" +#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_ILP16 1 +# define LZO_INFO_ABI_PM "ilp16" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_ILP32 1 +# define LZO_INFO_ABI_PM "ilp32" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) +# define LZO_ABI_LLP64 1 +# define LZO_INFO_ABI_PM "llp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_LP64 1 +# define LZO_INFO_ABI_PM "lp64" +#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_ILP64 1 +# define LZO_INFO_ABI_PM "ilp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_IP32L64 1 +# define LZO_INFO_ABI_PM "ip32l64" +#endif +#if !defined(__LZO_LIBC_OVERRIDE) +#if defined(LZO_LIBC_NAKED) +# define LZO_INFO_LIBC "naked" +#elif defined(LZO_LIBC_FREESTANDING) +# define LZO_INFO_LIBC "freestanding" +#elif defined(LZO_LIBC_MOSTLY_FREESTANDING) +# define LZO_INFO_LIBC "mfreestanding" +#elif defined(LZO_LIBC_ISOC90) +# define LZO_INFO_LIBC "isoc90" +#elif defined(LZO_LIBC_ISOC99) +# define LZO_INFO_LIBC "isoc99" +#elif defined(__dietlibc__) +# define LZO_LIBC_DIETLIBC 1 +# define LZO_INFO_LIBC "dietlibc" +#elif defined(_NEWLIB_VERSION) +# define LZO_LIBC_NEWLIB 1 +# define LZO_INFO_LIBC "newlib" +#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) +# if defined(__UCLIBC_SUBLEVEL__) +# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__) +# else +# define LZO_LIBC_UCLIBC 0x00090bL +# endif +# define LZO_INFO_LIBC "uclibc" +#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) +# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100) +# define LZO_INFO_LIBC "glibc" +#elif (LZO_CC_MWERKS) && defined(__MSL__) +# define LZO_LIBC_MSL __MSL__ +# define LZO_INFO_LIBC "msl" +#elif 1 && defined(__IAR_SYSTEMS_ICC__) +# define LZO_LIBC_ISOC90 1 +# define LZO_INFO_LIBC "isoc90" +#else +# define LZO_LIBC_DEFAULT 1 +# define LZO_INFO_LIBC "default" +#endif +#endif +#if !defined(__lzo_gnuc_extension__) +#if (LZO_CC_GNUC >= 0x020800ul) +# define __lzo_gnuc_extension__ __extension__ +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_gnuc_extension__ __extension__ +#else +# define __lzo_gnuc_extension__ +#endif +#endif +#if !defined(__lzo_ua_volatile) +# define __lzo_ua_volatile volatile +#endif +#if !defined(__lzo_alignof) +#if (LZO_CC_CILLY || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_alignof(e) __alignof(e) +#endif +#endif +#if defined(__lzo_alignof) +# define __lzo_HAVE_alignof 1 +#endif +#if !defined(__lzo_constructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_constructor __attribute__((__constructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_constructor __attribute__((__constructor__)) +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_constructor __attribute__((__constructor__)) +#endif +#endif +#if defined(__lzo_constructor) +# define __lzo_HAVE_constructor 1 +#endif +#if !defined(__lzo_destructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_destructor __attribute__((__destructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_destructor __attribute__((__destructor__)) +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_destructor __attribute__((__destructor__)) +#endif +#endif +#if defined(__lzo_destructor) +# define __lzo_HAVE_destructor 1 +#endif +#if defined(__lzo_HAVE_destructor) && !defined(__lzo_HAVE_constructor) +# error "this should not happen" +#endif +#if !defined(__lzo_inline) +#if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) +#elif defined(__cplusplus) +# define __lzo_inline inline +#elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) +# define __lzo_inline __inline +#elif (LZO_CC_CILLY || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define __lzo_inline __inline__ +#elif (LZO_CC_DMC) +# define __lzo_inline __inline +#elif (LZO_CC_INTELC) +# define __lzo_inline __inline +#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) +# define __lzo_inline __inline +#elif (LZO_CC_MSC && (_MSC_VER >= 900)) +# define __lzo_inline __inline +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# define __lzo_inline inline +#endif +#endif +#if defined(__lzo_inline) +# define __lzo_HAVE_inline 1 +#else +# define __lzo_inline +#endif +#if !defined(__lzo_forceinline) +#if (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +# define __lzo_forceinline __forceinline +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +# define __lzo_forceinline __forceinline +#endif +#endif +#if defined(__lzo_forceinline) +# define __lzo_HAVE_forceinline 1 +#else +# define __lzo_forceinline +#endif +#if !defined(__lzo_noinline) +#if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) +# define __lzo_noinline __attribute__((__noinline__,__used__)) +#elif (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC) +# define __lzo_noinline __declspec(noinline) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_noinline __declspec(noinline) +#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64)) +# if defined(__cplusplus) +# else +# define __lzo_noinline __declspec(noinline) +# endif +#endif +#endif +#if defined(__lzo_noinline) +# define __lzo_HAVE_noinline 1 +#else +# define __lzo_noinline +#endif +#if (defined(__lzo_HAVE_forceinline) || defined(__lzo_HAVE_noinline)) && !defined(__lzo_HAVE_inline) +# error "this should not happen" +#endif +#if !defined(__lzo_noreturn) +#if (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +# define __lzo_noreturn __declspec(noreturn) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +# define __lzo_noreturn __declspec(noreturn) +#endif +#endif +#if defined(__lzo_noreturn) +# define __lzo_HAVE_noreturn 1 +#else +# define __lzo_noreturn +#endif +#if !defined(__lzo_nothrow) +#if (LZO_CC_GNUC >= 0x030300ul) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus) +# define __lzo_nothrow __declspec(nothrow) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) +# define __lzo_nothrow __declspec(nothrow) +#endif +#endif +#if defined(__lzo_nothrow) +# define __lzo_HAVE_nothrow 1 +#else +# define __lzo_nothrow +#endif +#if !defined(__lzo_restrict) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_LLVM) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_MSC && (_MSC_VER >= 1400)) +# define __lzo_restrict __restrict +#endif +#endif +#if defined(__lzo_restrict) +# define __lzo_HAVE_restrict 1 +#else +# define __lzo_restrict +#endif +#if !defined(__lzo_likely) && !defined(__lzo_unlikely) +#if (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#endif +#endif +#if defined(__lzo_likely) +# define __lzo_HAVE_likely 1 +#else +# define __lzo_likely(e) (e) +#endif +#if defined(__lzo_unlikely) +# define __lzo_HAVE_unlikely 1 +#else +# define __lzo_unlikely(e) (e) +#endif +#if !defined(LZO_UNUSED) +# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +# define LZO_UNUSED(var) ((void) &var) +# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) +# define LZO_UNUSED(var) if (&var) ; else +# elif (LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNUSED(var) ((void) var) +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_UNUSED(var) if (&var) ; else +# elif (LZO_CC_KEILC) +# define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];} +# elif (LZO_CC_PACIFICC) +# define LZO_UNUSED(var) ((void) sizeof(var)) +# elif (LZO_CC_WATCOMC) && defined(__cplusplus) +# define LZO_UNUSED(var) ((void) var) +# else +# define LZO_UNUSED(var) ((void) &var) +# endif +#endif +#if !defined(LZO_UNUSED_FUNC) +# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +# define LZO_UNUSED_FUNC(func) ((void) func) +# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) +# define LZO_UNUSED_FUNC(func) if (func) ; else +# elif (LZO_CC_LLVM) +# define LZO_UNUSED_FUNC(func) ((void) &func) +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_UNUSED_FUNC(func) if (func) ; else +# elif (LZO_CC_MSC) +# define LZO_UNUSED_FUNC(func) ((void) &func) +# elif (LZO_CC_KEILC || LZO_CC_PELLESC) +# define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];} +# else +# define LZO_UNUSED_FUNC(func) ((void) func) +# endif +#endif +#if !defined(LZO_UNUSED_LABEL) +# if (LZO_CC_WATCOMC) && defined(__cplusplus) +# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l +# elif (LZO_CC_INTELC || LZO_CC_WATCOMC) +# define LZO_UNUSED_LABEL(l) if (0) goto l +# else +# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l +# endif +#endif +#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) +# if 0 +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var +# elif 0 && (LZO_CC_GNUC) +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var +# else +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init +# endif +#endif +#if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) +# if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +# elif (LZO_CC_DMC || LZO_CC_SYMANTECC) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)]; +# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +# else +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)]; +# endif +#endif +#if !defined(LZO_COMPILE_TIME_ASSERT) +# if (LZO_CC_AZTECC) +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];} +# elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) +# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) +# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +# else +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];} +# endif +#endif +#if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) +# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) +# elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) +# define __lzo_cdecl __cdecl +# define __lzo_cdecl_atexit +# define __lzo_cdecl_main __cdecl +# if (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) +# define __lzo_cdecl_qsort __pascal +# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) +# define __lzo_cdecl_qsort _stdcall +# else +# define __lzo_cdecl_qsort __cdecl +# endif +# elif (LZO_CC_WATCOMC) +# define __lzo_cdecl __cdecl +# else +# define __lzo_cdecl __cdecl +# define __lzo_cdecl_atexit __cdecl +# define __lzo_cdecl_main __cdecl +# define __lzo_cdecl_qsort __cdecl +# endif +# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC || LZO_CC_WATCOMC) +# elif (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) +# define __lzo_cdecl_sighandler __pascal +# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) +# define __lzo_cdecl_sighandler _stdcall +# elif (LZO_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE) +# define __lzo_cdecl_sighandler __clrcall +# elif (LZO_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700)) +# if defined(_DLL) +# define __lzo_cdecl_sighandler _far _cdecl _loadds +# elif defined(_MT) +# define __lzo_cdecl_sighandler _far _cdecl +# else +# define __lzo_cdecl_sighandler _cdecl +# endif +# else +# define __lzo_cdecl_sighandler __cdecl +# endif +#elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC) +# define __lzo_cdecl __cdecl +#elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC)) +# define __lzo_cdecl cdecl +#endif +#if !defined(__lzo_cdecl) +# define __lzo_cdecl +#endif +#if !defined(__lzo_cdecl_atexit) +# define __lzo_cdecl_atexit +#endif +#if !defined(__lzo_cdecl_main) +# define __lzo_cdecl_main +#endif +#if !defined(__lzo_cdecl_qsort) +# define __lzo_cdecl_qsort +#endif +#if !defined(__lzo_cdecl_sighandler) +# define __lzo_cdecl_sighandler +#endif +#if !defined(__lzo_cdecl_va) +# define __lzo_cdecl_va __lzo_cdecl +#endif +#if !defined(LZO_CFG_NO_WINDOWS_H) +#if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) +# if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) +# elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) +# elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul))) +# else +# define LZO_HAVE_WINDOWS_H 1 +# endif +#endif +#endif +#if (LZO_ARCH_ALPHA) +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_AVOID_SHORT 1 +# define LZO_OPT_AVOID_USHORT 1 +#elif (LZO_ARCH_AMD64) +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# define LZO_OPT_UNALIGNED64 1 +#elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB) +#elif (LZO_ARCH_ARM) +# define LZO_OPT_AVOID_SHORT 1 +# define LZO_OPT_AVOID_USHORT 1 +#elif (LZO_ARCH_CRIS) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +#elif (LZO_ARCH_I386) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +#elif (LZO_ARCH_IA64) +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_PREFER_POSTINC 1 +#elif (LZO_ARCH_M68K) +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 +# if defined(__mc68020__) && !defined(__mcoldfire__) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# endif +#elif (LZO_ARCH_MIPS) +# define LZO_OPT_AVOID_UINT_INDEX 1 +#elif (LZO_ARCH_POWERPC) +# define LZO_OPT_PREFER_PREINC 1 +# define LZO_OPT_PREFER_PREDEC 1 +# if defined(LZO_ABI_BIG_ENDIAN) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# endif +#elif (LZO_ARCH_S390) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# if (LZO_SIZEOF_SIZE_T == 8) +# define LZO_OPT_UNALIGNED64 1 +# endif +#elif (LZO_ARCH_SH) +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 +#endif +#if !defined(LZO_CFG_NO_INLINE_ASM) +#if defined(LZO_CC_LLVM) +# define LZO_CFG_NO_INLINE_ASM 1 +#endif +#endif +#if !defined(LZO_CFG_NO_UNALIGNED) +#if defined(LZO_ABI_NEUTRAL_ENDIAN) || defined(LZO_ARCH_GENERIC) +# define LZO_CFG_NO_UNALIGNED 1 +#endif +#endif +#if defined(LZO_CFG_NO_UNALIGNED) +# undef LZO_OPT_UNALIGNED16 +# undef LZO_OPT_UNALIGNED32 +# undef LZO_OPT_UNALIGNED64 +#endif +#if defined(LZO_CFG_NO_INLINE_ASM) +#elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +# define LZO_ASM_SYNTAX_MSC 1 +#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +#elif (LZO_ARCH_I386 && (LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#elif (LZO_ARCH_AMD64 && (LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#endif +#if (LZO_ASM_SYNTAX_GNUC) +#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) +# define __LZO_ASM_CLOBBER "ax" +#elif (LZO_CC_INTELC) +# define __LZO_ASM_CLOBBER "memory" +#else +# define __LZO_ASM_CLOBBER "cc", "memory" +#endif +#endif +#if defined(__LZO_INFOSTR_MM) +#elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM)) +# define __LZO_INFOSTR_MM "" +#elif defined(LZO_INFO_MM) +# define __LZO_INFOSTR_MM "." LZO_INFO_MM +#else +# define __LZO_INFOSTR_MM "" +#endif +#if defined(__LZO_INFOSTR_PM) +#elif defined(LZO_INFO_ABI_PM) +# define __LZO_INFOSTR_PM "." LZO_INFO_ABI_PM +#else +# define __LZO_INFOSTR_PM "" +#endif +#if defined(__LZO_INFOSTR_ENDIAN) +#elif defined(LZO_INFO_ABI_ENDIAN) +# define __LZO_INFOSTR_ENDIAN "." LZO_INFO_ABI_ENDIAN +#else +# define __LZO_INFOSTR_ENDIAN "" +#endif +#if defined(__LZO_INFOSTR_OSNAME) +#elif defined(LZO_INFO_OS_CONSOLE) +# define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_CONSOLE +#elif defined(LZO_INFO_OS_POSIX) +# define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_POSIX +#else +# define __LZO_INFOSTR_OSNAME LZO_INFO_OS +#endif +#if defined(__LZO_INFOSTR_LIBC) +#elif defined(LZO_INFO_LIBC) +# define __LZO_INFOSTR_LIBC "." LZO_INFO_LIBC +#else +# define __LZO_INFOSTR_LIBC "" +#endif +#if defined(__LZO_INFOSTR_CCVER) +#elif defined(LZO_INFO_CCVER) +# define __LZO_INFOSTR_CCVER " " LZO_INFO_CCVER +#else +# define __LZO_INFOSTR_CCVER "" +#endif +#define LZO_INFO_STRING \ + LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \ + " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER + +#endif /* already included */ + +/* vim:set ts=4 et: */ diff --git a/extern/lzo/minilzo/minilzo.c b/extern/lzo/minilzo/minilzo.c new file mode 100644 index 00000000000..6a62b31b94a --- /dev/null +++ b/extern/lzo/minilzo/minilzo.c @@ -0,0 +1,4112 @@ +/* minilzo.c -- mini subset of the LZO real-time data compression library + + This file is part of the LZO real-time data compression library. + + Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer + All Rights Reserved. + + The LZO library 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. + + The LZO library 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 the LZO library; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Markus F.X.J. Oberhumer + + http://www.oberhumer.com/opensource/lzo/ + */ + +/* + * NOTE: + * the full LZO package can be found at + * http://www.oberhumer.com/opensource/lzo/ + */ + +#define __LZO_IN_MINILZO +#define LZO_BUILD + +#if defined(LZO_CFG_FREESTANDING) +# undef MINILZO_HAVE_CONFIG_H +# define LZO_LIBC_FREESTANDING 1 +# define LZO_OS_FREESTANDING 1 +#endif + +#ifdef MINILZO_HAVE_CONFIG_H +# include +#endif +#include +#include +#if defined(MINILZO_CFG_USE_INTERNAL_LZODEFS) + +#ifndef __LZODEFS_H_INCLUDED +#define __LZODEFS_H_INCLUDED 1 + +#if defined(__CYGWIN32__) && !defined(__CYGWIN__) +# define __CYGWIN__ __CYGWIN32__ +#endif +#if defined(__IBMCPP__) && !defined(__IBMC__) +# define __IBMC__ __IBMCPP__ +#endif +#if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER) +# define __INTEL_COMPILER __ICL +#endif +#if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE) +# define _ALL_SOURCE 1 +#endif +#if defined(__mips__) && defined(__R5900__) +# if !defined(__LONG_MAX__) +# define __LONG_MAX__ 9223372036854775807L +# endif +#endif +#if defined(__INTEL_COMPILER) && defined(__linux__) +# pragma warning(disable: 193) +#endif +#if defined(__KEIL__) && defined(__C166__) +# pragma warning disable = 322 +#elif 0 && defined(__C251__) +# pragma warning disable = 322 +#endif +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) +# if (_MSC_VER >= 1300) +# pragma warning(disable: 4668) +# endif +#endif +#if 0 && defined(__WATCOMC__) +# if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060) +# pragma warning 203 9 +# endif +#endif +#if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__) +# pragma option -h +#endif +#if 0 +#define LZO_0xffffL 0xfffful +#define LZO_0xffffffffL 0xfffffffful +#else +#define LZO_0xffffL 65535ul +#define LZO_0xffffffffL 4294967295ul +#endif +#if (LZO_0xffffL == LZO_0xffffffffL) +# error "your preprocessor is broken 1" +#endif +#if (16ul * 16384ul != 262144ul) +# error "your preprocessor is broken 2" +#endif +#if 0 +#if (32767 >= 4294967295ul) +# error "your preprocessor is broken 3" +#endif +#if (65535u >= 4294967295ul) +# error "your preprocessor is broken 4" +#endif +#endif +#if (UINT_MAX == LZO_0xffffL) +#if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__) +# if !defined(MSDOS) +# define MSDOS 1 +# endif +# if !defined(_MSDOS) +# define _MSDOS 1 +# endif +#elif 0 && defined(__VERSION) && defined(MB_LEN_MAX) +# if (__VERSION == 520) && (MB_LEN_MAX == 1) +# if !defined(__AZTEC_C__) +# define __AZTEC_C__ __VERSION +# endif +# if !defined(__DOS__) +# define __DOS__ 1 +# endif +# endif +#endif +#endif +#if defined(_MSC_VER) && defined(M_I86HM) && (UINT_MAX == LZO_0xffffL) +# define ptrdiff_t long +# define _PTRDIFF_T_DEFINED +#endif +#if (UINT_MAX == LZO_0xffffL) +# undef __LZO_RENAME_A +# undef __LZO_RENAME_B +# if defined(__AZTEC_C__) && defined(__DOS__) +# define __LZO_RENAME_A 1 +# elif defined(_MSC_VER) && defined(MSDOS) +# if (_MSC_VER < 600) +# define __LZO_RENAME_A 1 +# elif (_MSC_VER < 700) +# define __LZO_RENAME_B 1 +# endif +# elif defined(__TSC__) && defined(__OS2__) +# define __LZO_RENAME_A 1 +# elif defined(__MSDOS__) && defined(__TURBOC__) && (__TURBOC__ < 0x0410) +# define __LZO_RENAME_A 1 +# elif defined(__PACIFIC__) && defined(DOS) +# if !defined(__far) +# define __far far +# endif +# if !defined(__near) +# define __near near +# endif +# endif +# if defined(__LZO_RENAME_A) +# if !defined(__cdecl) +# define __cdecl cdecl +# endif +# if !defined(__far) +# define __far far +# endif +# if !defined(__huge) +# define __huge huge +# endif +# if !defined(__near) +# define __near near +# endif +# if !defined(__pascal) +# define __pascal pascal +# endif +# if !defined(__huge) +# define __huge huge +# endif +# elif defined(__LZO_RENAME_B) +# if !defined(__cdecl) +# define __cdecl _cdecl +# endif +# if !defined(__far) +# define __far _far +# endif +# if !defined(__huge) +# define __huge _huge +# endif +# if !defined(__near) +# define __near _near +# endif +# if !defined(__pascal) +# define __pascal _pascal +# endif +# elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__) +# if !defined(__cdecl) +# define __cdecl cdecl +# endif +# if !defined(__pascal) +# define __pascal pascal +# endif +# endif +# undef __LZO_RENAME_A +# undef __LZO_RENAME_B +#endif +#if (UINT_MAX == LZO_0xffffL) +#if defined(__AZTEC_C__) && defined(__DOS__) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +#elif defined(_MSC_VER) && defined(MSDOS) +# if (_MSC_VER < 600) +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +# endif +# if (_MSC_VER < 700) +# define LZO_BROKEN_INTEGRAL_PROMOTION 1 +# define LZO_BROKEN_SIZEOF 1 +# endif +#elif defined(__PACIFIC__) && defined(DOS) +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +#elif defined(__TURBOC__) && defined(__MSDOS__) +# if (__TURBOC__ < 0x0150) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +# define LZO_BROKEN_INTEGRAL_PROMOTION 1 +# endif +# if (__TURBOC__ < 0x0200) +# define LZO_BROKEN_SIZEOF 1 +# endif +# if (__TURBOC__ < 0x0400) && defined(__cplusplus) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +# endif +#elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__) +# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 +# define LZO_BROKEN_SIZEOF 1 +#endif +#endif +#if defined(__WATCOMC__) && (__WATCOMC__ < 900) +# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 +#endif +#if defined(_CRAY) && defined(_CRAY1) +# define LZO_BROKEN_SIGNED_RIGHT_SHIFT 1 +#endif +#define LZO_PP_STRINGIZE(x) #x +#define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x) +#define LZO_PP_CONCAT2(a,b) a ## b +#define LZO_PP_CONCAT3(a,b,c) a ## b ## c +#define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d +#define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e +#define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b) +#define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c) +#define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d) +#define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e) +#if 1 +#define LZO_CPP_STRINGIZE(x) #x +#define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x) +#define LZO_CPP_CONCAT2(a,b) a ## b +#define LZO_CPP_CONCAT3(a,b,c) a ## b ## c +#define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d +#define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e +#define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b) +#define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c) +#define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d) +#define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e) +#endif +#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o)) +#if 1 && defined(__cplusplus) +# if !defined(__STDC_CONSTANT_MACROS) +# define __STDC_CONSTANT_MACROS 1 +# endif +# if !defined(__STDC_LIMIT_MACROS) +# define __STDC_LIMIT_MACROS 1 +# endif +#endif +#if defined(__cplusplus) +# define LZO_EXTERN_C extern "C" +#else +# define LZO_EXTERN_C extern +#endif +#if !defined(__LZO_OS_OVERRIDE) +#if defined(LZO_OS_FREESTANDING) +# define LZO_INFO_OS "freestanding" +#elif defined(LZO_OS_EMBEDDED) +# define LZO_INFO_OS "embedded" +#elif 1 && defined(__IAR_SYSTEMS_ICC__) +# define LZO_OS_EMBEDDED 1 +# define LZO_INFO_OS "embedded" +#elif defined(__CYGWIN__) && defined(__GNUC__) +# define LZO_OS_CYGWIN 1 +# define LZO_INFO_OS "cygwin" +#elif defined(__EMX__) && defined(__GNUC__) +# define LZO_OS_EMX 1 +# define LZO_INFO_OS "emx" +#elif defined(__BEOS__) +# define LZO_OS_BEOS 1 +# define LZO_INFO_OS "beos" +#elif defined(__Lynx__) +# define LZO_OS_LYNXOS 1 +# define LZO_INFO_OS "lynxos" +#elif defined(__OS400__) +# define LZO_OS_OS400 1 +# define LZO_INFO_OS "os400" +#elif defined(__QNX__) +# define LZO_OS_QNX 1 +# define LZO_INFO_OS "qnx" +#elif defined(__BORLANDC__) && defined(__DPMI32__) && (__BORLANDC__ >= 0x0460) +# define LZO_OS_DOS32 1 +# define LZO_INFO_OS "dos32" +#elif defined(__BORLANDC__) && defined(__DPMI16__) +# define LZO_OS_DOS16 1 +# define LZO_INFO_OS "dos16" +#elif defined(__ZTC__) && defined(DOS386) +# define LZO_OS_DOS32 1 +# define LZO_INFO_OS "dos32" +#elif defined(__OS2__) || defined(__OS2V2__) +# if (UINT_MAX == LZO_0xffffL) +# define LZO_OS_OS216 1 +# define LZO_INFO_OS "os216" +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_OS_OS2 1 +# define LZO_INFO_OS "os2" +# else +# error "check your limits.h header" +# endif +#elif defined(__WIN64__) || defined(_WIN64) || defined(WIN64) +# define LZO_OS_WIN64 1 +# define LZO_INFO_OS "win64" +#elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WINDOWS_386__) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +#elif defined(__MWERKS__) && defined(__INTEL__) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +#elif defined(__WINDOWS__) || defined(_WINDOWS) || defined(_Windows) +# if (UINT_MAX == LZO_0xffffL) +# define LZO_OS_WIN16 1 +# define LZO_INFO_OS "win16" +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +# else +# error "check your limits.h header" +# endif +#elif defined(__DOS__) || defined(__MSDOS__) || defined(_MSDOS) || defined(MSDOS) || (defined(__PACIFIC__) && defined(DOS)) +# if (UINT_MAX == LZO_0xffffL) +# define LZO_OS_DOS16 1 +# define LZO_INFO_OS "dos16" +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_OS_DOS32 1 +# define LZO_INFO_OS "dos32" +# else +# error "check your limits.h header" +# endif +#elif defined(__WATCOMC__) +# if defined(__NT__) && (UINT_MAX == LZO_0xffffL) +# define LZO_OS_DOS16 1 +# define LZO_INFO_OS "dos16" +# elif defined(__NT__) && (__WATCOMC__ < 1100) +# define LZO_OS_WIN32 1 +# define LZO_INFO_OS "win32" +# elif defined(__linux__) || defined(__LINUX__) +# define LZO_OS_POSIX 1 +# define LZO_INFO_OS "posix" +# else +# error "please specify a target using the -bt compiler option" +# endif +#elif defined(__palmos__) +# define LZO_OS_PALMOS 1 +# define LZO_INFO_OS "palmos" +#elif defined(__TOS__) || defined(__atarist__) +# define LZO_OS_TOS 1 +# define LZO_INFO_OS "tos" +#elif defined(macintosh) && !defined(__ppc__) +# define LZO_OS_MACCLASSIC 1 +# define LZO_INFO_OS "macclassic" +#elif defined(__VMS) +# define LZO_OS_VMS 1 +# define LZO_INFO_OS "vms" +#elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +# define LZO_OS_CONSOLE 1 +# define LZO_OS_CONSOLE_PS2 1 +# define LZO_INFO_OS "console" +# define LZO_INFO_OS_CONSOLE "ps2" +#elif (defined(__mips__) && defined(__psp__)) +# define LZO_OS_CONSOLE 1 +# define LZO_OS_CONSOLE_PSP 1 +# define LZO_INFO_OS "console" +# define LZO_INFO_OS_CONSOLE "psp" +#else +# define LZO_OS_POSIX 1 +# define LZO_INFO_OS "posix" +#endif +#if (LZO_OS_POSIX) +# if defined(_AIX) || defined(__AIX__) || defined(__aix__) +# define LZO_OS_POSIX_AIX 1 +# define LZO_INFO_OS_POSIX "aix" +# elif defined(__FreeBSD__) +# define LZO_OS_POSIX_FREEBSD 1 +# define LZO_INFO_OS_POSIX "freebsd" +# elif defined(__hpux__) || defined(__hpux) +# define LZO_OS_POSIX_HPUX 1 +# define LZO_INFO_OS_POSIX "hpux" +# elif defined(__INTERIX) +# define LZO_OS_POSIX_INTERIX 1 +# define LZO_INFO_OS_POSIX "interix" +# elif defined(__IRIX__) || defined(__irix__) +# define LZO_OS_POSIX_IRIX 1 +# define LZO_INFO_OS_POSIX "irix" +# elif defined(__linux__) || defined(__linux) || defined(__LINUX__) +# define LZO_OS_POSIX_LINUX 1 +# define LZO_INFO_OS_POSIX "linux" +# elif defined(__APPLE__) || defined(__MACOS__) +# define LZO_OS_POSIX_MACOSX 1 +# define LZO_INFO_OS_POSIX "macosx" +# elif defined(__minix__) || defined(__minix) +# define LZO_OS_POSIX_MINIX 1 +# define LZO_INFO_OS_POSIX "minix" +# elif defined(__NetBSD__) +# define LZO_OS_POSIX_NETBSD 1 +# define LZO_INFO_OS_POSIX "netbsd" +# elif defined(__OpenBSD__) +# define LZO_OS_POSIX_OPENBSD 1 +# define LZO_INFO_OS_POSIX "openbsd" +# elif defined(__osf__) +# define LZO_OS_POSIX_OSF 1 +# define LZO_INFO_OS_POSIX "osf" +# elif defined(__solaris__) || defined(__sun) +# if defined(__SVR4) || defined(__svr4__) +# define LZO_OS_POSIX_SOLARIS 1 +# define LZO_INFO_OS_POSIX "solaris" +# else +# define LZO_OS_POSIX_SUNOS 1 +# define LZO_INFO_OS_POSIX "sunos" +# endif +# elif defined(__ultrix__) || defined(__ultrix) +# define LZO_OS_POSIX_ULTRIX 1 +# define LZO_INFO_OS_POSIX "ultrix" +# elif defined(_UNICOS) +# define LZO_OS_POSIX_UNICOS 1 +# define LZO_INFO_OS_POSIX "unicos" +# else +# define LZO_OS_POSIX_UNKNOWN 1 +# define LZO_INFO_OS_POSIX "unknown" +# endif +#endif +#endif +#if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +# if (UINT_MAX != LZO_0xffffL) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64) +# if (UINT_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if defined(CIL) && defined(_GNUCC) && defined(__GNUC__) +# define LZO_CC_CILLY 1 +# define LZO_INFO_CC "Cilly" +# if defined(__CILLY__) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__CILLY__) +# else +# define LZO_INFO_CCVER "unknown" +# endif +#elif 0 && defined(SDCC) && defined(__VERSION__) && !defined(__GNUC__) +# define LZO_CC_SDCC 1 +# define LZO_INFO_CC "sdcc" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC) +#elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__) +# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__) +# define LZO_INFO_CC "Pathscale C" +# define LZO_INFO_CCVER __PATHSCALE__ +#elif defined(__INTEL_COMPILER) +# define LZO_CC_INTELC 1 +# define LZO_INFO_CC "Intel C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER) +# if defined(_WIN32) || defined(_WIN64) +# define LZO_CC_SYNTAX_MSC 1 +# else +# define LZO_CC_SYNTAX_GNUC 1 +# endif +#elif defined(__POCC__) && defined(_WIN32) +# define LZO_CC_PELLESC 1 +# define LZO_INFO_CC "Pelles C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__) +#elif defined(__llvm__) && defined(__GNUC__) && defined(__VERSION__) +# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +# define LZO_CC_LLVM (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# else +# define LZO_CC_LLVM (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# endif +# define LZO_INFO_CC "llvm-gcc" +# define LZO_INFO_CCVER __VERSION__ +#elif defined(__GNUC__) && defined(__VERSION__) +# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# elif defined(__GNUC_MINOR__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# else +# define LZO_CC_GNUC (__GNUC__ * 0x10000L) +# endif +# define LZO_INFO_CC "gcc" +# define LZO_INFO_CCVER __VERSION__ +#elif defined(__ACK__) && defined(_ACK) +# define LZO_CC_ACK 1 +# define LZO_INFO_CC "Amsterdam Compiler Kit C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__AZTEC_C__) +# define LZO_CC_AZTECC 1 +# define LZO_INFO_CC "Aztec C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__AZTEC_C__) +#elif defined(__BORLANDC__) +# define LZO_CC_BORLANDC 1 +# define LZO_INFO_CC "Borland C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__BORLANDC__) +#elif defined(_CRAYC) && defined(_RELEASE) +# define LZO_CC_CRAYC 1 +# define LZO_INFO_CC "Cray C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_RELEASE) +#elif defined(__DMC__) && defined(__SC__) +# define LZO_CC_DMC 1 +# define LZO_INFO_CC "Digital Mars C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DMC__) +#elif defined(__DECC) +# define LZO_CC_DECC 1 +# define LZO_INFO_CC "DEC C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC) +#elif defined(__HIGHC__) +# define LZO_CC_HIGHC 1 +# define LZO_INFO_CC "MetaWare High C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__IAR_SYSTEMS_ICC__) +# define LZO_CC_IARC 1 +# define LZO_INFO_CC "IAR C" +# if defined(__VER__) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__VER__) +# else +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(__IBMC__) +# define LZO_CC_IBMC 1 +# define LZO_INFO_CC "IBM C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__) +#elif defined(__KEIL__) && defined(__C166__) +# define LZO_CC_KEILC 1 +# define LZO_INFO_CC "Keil C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__C166__) +#elif defined(__LCC__) && defined(_WIN32) && defined(__LCCOPTIMLEVEL) +# define LZO_CC_LCCWIN32 1 +# define LZO_INFO_CC "lcc-win32" +# define LZO_INFO_CCVER "unknown" +#elif defined(__LCC__) +# define LZO_CC_LCC 1 +# define LZO_INFO_CC "lcc" +# if defined(__LCC_VERSION__) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__LCC_VERSION__) +# else +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(_MSC_VER) +# define LZO_CC_MSC 1 +# define LZO_INFO_CC "Microsoft C" +# if defined(_MSC_FULL_VER) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) +# else +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) +# endif +#elif defined(__MWERKS__) +# define LZO_CC_MWERKS 1 +# define LZO_INFO_CC "Metrowerks C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__) +#elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386) +# define LZO_CC_NDPC 1 +# define LZO_INFO_CC "Microway NDP C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__PACIFIC__) +# define LZO_CC_PACIFICC 1 +# define LZO_INFO_CC "Pacific C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__) +#elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__)) +# define LZO_CC_PGI 1 +# define LZO_INFO_CC "Portland Group PGI C" +# define LZO_INFO_CCVER "unknown" +#elif defined(__PUREC__) && defined(__TOS__) +# define LZO_CC_PUREC 1 +# define LZO_INFO_CC "Pure C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PUREC__) +#elif defined(__SC__) && defined(__ZTC__) +# define LZO_CC_SYMANTECC 1 +# define LZO_INFO_CC "Symantec C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__) +#elif defined(__SUNPRO_C) +# define LZO_INFO_CC "SunPro C" +# if ((__SUNPRO_C)+0 > 0) +# define LZO_CC_SUNPROC __SUNPRO_C +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C) +# else +# define LZO_CC_SUNPROC 1 +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(__SUNPRO_CC) +# define LZO_INFO_CC "SunPro C" +# if ((__SUNPRO_CC)+0 > 0) +# define LZO_CC_SUNPROC __SUNPRO_CC +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC) +# else +# define LZO_CC_SUNPROC 1 +# define LZO_INFO_CCVER "unknown" +# endif +#elif defined(__TINYC__) +# define LZO_CC_TINYC 1 +# define LZO_INFO_CC "Tiny C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TINYC__) +#elif defined(__TSC__) +# define LZO_CC_TOPSPEEDC 1 +# define LZO_INFO_CC "TopSpeed C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TSC__) +#elif defined(__WATCOMC__) +# define LZO_CC_WATCOMC 1 +# define LZO_INFO_CC "Watcom C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__WATCOMC__) +#elif defined(__TURBOC__) +# define LZO_CC_TURBOC 1 +# define LZO_INFO_CC "Turbo C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TURBOC__) +#elif defined(__ZTC__) +# define LZO_CC_ZORTECHC 1 +# define LZO_INFO_CC "Zortech C" +# if (__ZTC__ == 0x310) +# define LZO_INFO_CCVER "0x310" +# else +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__) +# endif +#else +# define LZO_CC_UNKNOWN 1 +# define LZO_INFO_CC "unknown" +# define LZO_INFO_CCVER "unknown" +#endif +#if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER) +# error "LZO_CC_MSC: _MSC_FULL_VER is not defined" +#endif +#if !defined(__LZO_ARCH_OVERRIDE) && !defined(LZO_ARCH_GENERIC) && defined(_CRAY) +# if (UINT_MAX > LZO_0xffffffffL) && defined(_CRAY) +# if defined(_CRAYMPP) || defined(_CRAYT3D) || defined(_CRAYT3E) +# define LZO_ARCH_CRAY_MPP 1 +# elif defined(_CRAY1) +# define LZO_ARCH_CRAY_PVP 1 +# endif +# endif +#endif +#if !defined(__LZO_ARCH_OVERRIDE) +#if defined(LZO_ARCH_GENERIC) +# define LZO_INFO_ARCH "generic" +#elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +# define LZO_ARCH_I086 1 +# define LZO_ARCH_IA16 1 +# define LZO_INFO_ARCH "i086" +#elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) +# define LZO_ARCH_ALPHA 1 +# define LZO_INFO_ARCH "alpha" +#elif (LZO_ARCH_CRAY_MPP) && (defined(_CRAYT3D) || defined(_CRAYT3E)) +# define LZO_ARCH_ALPHA 1 +# define LZO_INFO_ARCH "alpha" +#elif defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64) +# define LZO_ARCH_AMD64 1 +# define LZO_INFO_ARCH "amd64" +#elif defined(__thumb__) || (defined(_M_ARM) && defined(_M_THUMB)) +# define LZO_ARCH_ARM 1 +# define LZO_ARCH_ARM_THUMB 1 +# define LZO_INFO_ARCH "arm_thumb" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__) +# define LZO_ARCH_ARM 1 +# if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1) +# define LZO_ARCH_ARM_THUMB 1 +# define LZO_INFO_ARCH "arm_thumb" +# elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2) +# define LZO_INFO_ARCH "arm" +# else +# define LZO_INFO_ARCH "arm" +# endif +#elif defined(__arm__) || defined(_M_ARM) +# define LZO_ARCH_ARM 1 +# define LZO_INFO_ARCH "arm" +#elif (UINT_MAX <= LZO_0xffffL) && defined(__AVR__) +# define LZO_ARCH_AVR 1 +# define LZO_INFO_ARCH "avr" +#elif defined(__bfin__) +# define LZO_ARCH_BLACKFIN 1 +# define LZO_INFO_ARCH "blackfin" +#elif (UINT_MAX == LZO_0xffffL) && defined(__C166__) +# define LZO_ARCH_C166 1 +# define LZO_INFO_ARCH "c166" +#elif defined(__cris__) +# define LZO_ARCH_CRIS 1 +# define LZO_INFO_ARCH "cris" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCEZ80__) +# define LZO_ARCH_EZ80 1 +# define LZO_INFO_ARCH "ez80" +#elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# define LZO_ARCH_H8300 1 +# define LZO_INFO_ARCH "h8300" +#elif defined(__hppa__) || defined(__hppa) +# define LZO_ARCH_HPPA 1 +# define LZO_INFO_ARCH "hppa" +#elif defined(__386__) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_M_I386) +# define LZO_ARCH_I386 1 +# define LZO_ARCH_IA32 1 +# define LZO_INFO_ARCH "i386" +#elif (LZO_CC_ZORTECHC && defined(__I86__)) +# define LZO_ARCH_I386 1 +# define LZO_ARCH_IA32 1 +# define LZO_INFO_ARCH "i386" +#elif (LZO_OS_DOS32 && LZO_CC_HIGHC) && defined(_I386) +# define LZO_ARCH_I386 1 +# define LZO_ARCH_IA32 1 +# define LZO_INFO_ARCH "i386" +#elif defined(__ia64__) || defined(__ia64) || defined(_M_IA64) +# define LZO_ARCH_IA64 1 +# define LZO_INFO_ARCH "ia64" +#elif (UINT_MAX == LZO_0xffffL) && defined(__m32c__) +# define LZO_ARCH_M16C 1 +# define LZO_INFO_ARCH "m16c" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCM16C__) +# define LZO_ARCH_M16C 1 +# define LZO_INFO_ARCH "m16c" +#elif defined(__m32r__) +# define LZO_ARCH_M32R 1 +# define LZO_INFO_ARCH "m32r" +#elif (LZO_OS_TOS) || defined(__m68k__) || defined(__m68000__) || defined(__mc68000__) || defined(__mc68020__) || defined(_M_M68K) +# define LZO_ARCH_M68K 1 +# define LZO_INFO_ARCH "m68k" +#elif (UINT_MAX == LZO_0xffffL) && defined(__C251__) +# define LZO_ARCH_MCS251 1 +# define LZO_INFO_ARCH "mcs251" +#elif (UINT_MAX == LZO_0xffffL) && defined(__C51__) +# define LZO_ARCH_MCS51 1 +# define LZO_INFO_ARCH "mcs51" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC8051__) +# define LZO_ARCH_MCS51 1 +# define LZO_INFO_ARCH "mcs51" +#elif defined(__mips__) || defined(__mips) || defined(_MIPS_ARCH) || defined(_M_MRX000) +# define LZO_ARCH_MIPS 1 +# define LZO_INFO_ARCH "mips" +#elif (UINT_MAX == LZO_0xffffL) && defined(__MSP430__) +# define LZO_ARCH_MSP430 1 +# define LZO_INFO_ARCH "msp430" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC430__) +# define LZO_ARCH_MSP430 1 +# define LZO_INFO_ARCH "msp430" +#elif defined(__powerpc__) || defined(__powerpc) || defined(__ppc__) || defined(__PPC__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PWR) +# define LZO_ARCH_POWERPC 1 +# define LZO_INFO_ARCH "powerpc" +#elif defined(__s390__) || defined(__s390) || defined(__s390x__) || defined(__s390x) +# define LZO_ARCH_S390 1 +# define LZO_INFO_ARCH "s390" +#elif defined(__sh__) || defined(_M_SH) +# define LZO_ARCH_SH 1 +# define LZO_INFO_ARCH "sh" +#elif defined(__sparc__) || defined(__sparc) || defined(__sparcv8) +# define LZO_ARCH_SPARC 1 +# define LZO_INFO_ARCH "sparc" +#elif defined(__SPU__) +# define LZO_ARCH_SPU 1 +# define LZO_INFO_ARCH "spu" +#elif (UINT_MAX == LZO_0xffffL) && defined(__z80) +# define LZO_ARCH_Z80 1 +# define LZO_INFO_ARCH "z80" +#elif (LZO_ARCH_CRAY_PVP) +# if defined(_CRAYSV1) +# define LZO_ARCH_CRAY_SV1 1 +# define LZO_INFO_ARCH "cray_sv1" +# elif (_ADDR64) +# define LZO_ARCH_CRAY_T90 1 +# define LZO_INFO_ARCH "cray_t90" +# elif (_ADDR32) +# define LZO_ARCH_CRAY_YMP 1 +# define LZO_INFO_ARCH "cray_ymp" +# else +# define LZO_ARCH_CRAY_XMP 1 +# define LZO_INFO_ARCH "cray_xmp" +# endif +#else +# define LZO_ARCH_UNKNOWN 1 +# define LZO_INFO_ARCH "unknown" +#endif +#endif +#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_DOS32 || LZO_OS_OS2) +# error "FIXME - missing define for CPU architecture" +#endif +#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32) +# error "FIXME - missing WIN32 define for CPU architecture" +#endif +#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64) +# error "FIXME - missing WIN64 define for CPU architecture" +#endif +#if (LZO_OS_OS216 || LZO_OS_WIN16) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#elif 1 && (LZO_OS_DOS16 && defined(BLX286)) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#elif 1 && (LZO_OS_DOS16 && defined(DOSX286)) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__)) +# define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 +#endif +#if defined(LZO_ARCH_ARM_THUMB) && !defined(LZO_ARCH_ARM) +# error "this should not happen" +#endif +#if defined(LZO_ARCH_I086PM) && !defined(LZO_ARCH_I086) +# error "this should not happen" +#endif +#if (LZO_ARCH_I086) +# if (UINT_MAX != LZO_0xffffL) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if (LZO_ARCH_I386) +# if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__) +# error "this should not happen" +# endif +# if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__) +# error "this should not happen" +# endif +# if (ULONG_MAX != LZO_0xffffffffL) +# error "this should not happen" +# endif +#endif +#if !defined(__LZO_MM_OVERRIDE) +#if (LZO_ARCH_I086) +#if (UINT_MAX != LZO_0xffffL) +# error "this should not happen" +#endif +#if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM) +# define LZO_MM_TINY 1 +#elif defined(__HUGE__) || defined(_HUGE_) || defined(M_I86HM) || defined(_M_I86HM) +# define LZO_MM_HUGE 1 +#elif defined(__SMALL__) || defined(M_I86SM) || defined(_M_I86SM) || defined(SMALL_MODEL) +# define LZO_MM_SMALL 1 +#elif defined(__MEDIUM__) || defined(M_I86MM) || defined(_M_I86MM) +# define LZO_MM_MEDIUM 1 +#elif defined(__COMPACT__) || defined(M_I86CM) || defined(_M_I86CM) +# define LZO_MM_COMPACT 1 +#elif defined(__LARGE__) || defined(M_I86LM) || defined(_M_I86LM) || defined(LARGE_MODEL) +# define LZO_MM_LARGE 1 +#elif (LZO_CC_AZTECC) +# if defined(_LARGE_CODE) && defined(_LARGE_DATA) +# define LZO_MM_LARGE 1 +# elif defined(_LARGE_CODE) +# define LZO_MM_MEDIUM 1 +# elif defined(_LARGE_DATA) +# define LZO_MM_COMPACT 1 +# else +# define LZO_MM_SMALL 1 +# endif +#elif (LZO_CC_ZORTECHC && defined(__VCM__)) +# define LZO_MM_LARGE 1 +#else +# error "unknown memory model" +#endif +#if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +#define LZO_HAVE_MM_HUGE_PTR 1 +#define LZO_HAVE_MM_HUGE_ARRAY 1 +#if (LZO_MM_TINY) +# undef LZO_HAVE_MM_HUGE_ARRAY +#endif +#if (LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_ZORTECHC) +# undef LZO_HAVE_MM_HUGE_PTR +# undef LZO_HAVE_MM_HUGE_ARRAY +#elif (LZO_CC_DMC || LZO_CC_SYMANTECC) +# undef LZO_HAVE_MM_HUGE_ARRAY +#elif (LZO_CC_MSC && defined(_QC)) +# undef LZO_HAVE_MM_HUGE_ARRAY +# if (_MSC_VER < 600) +# undef LZO_HAVE_MM_HUGE_PTR +# endif +#elif (LZO_CC_TURBOC && (__TURBOC__ < 0x0295)) +# undef LZO_HAVE_MM_HUGE_ARRAY +#endif +#if (LZO_ARCH_I086PM) && !defined(LZO_HAVE_MM_HUGE_PTR) +# if (LZO_OS_DOS16) +# error "this should not happen" +# elif (LZO_CC_ZORTECHC) +# else +# error "this should not happen" +# endif +#endif +#ifdef __cplusplus +extern "C" { +#endif +#if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0200)) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif (LZO_CC_MSC || LZO_CC_TOPSPEEDC) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif (LZO_CC_TURBOC && (__TURBOC__ >= 0x0295)) + extern void __near __cdecl _AHSHIFT(void); +# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) +#elif ((LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_TURBOC) && LZO_OS_DOS16) +# define LZO_MM_AHSHIFT 12 +#elif (LZO_CC_WATCOMC) + extern unsigned char _HShift; +# define LZO_MM_AHSHIFT ((unsigned) _HShift) +#else +# error "FIXME - implement LZO_MM_AHSHIFT" +#endif +#ifdef __cplusplus +} +#endif +#endif +#elif (LZO_ARCH_C166) +#if !defined(__MODEL__) +# error "FIXME - C166 __MODEL__" +#elif ((__MODEL__) == 0) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 1) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 2) +# define LZO_MM_LARGE 1 +#elif ((__MODEL__) == 3) +# define LZO_MM_TINY 1 +#elif ((__MODEL__) == 4) +# define LZO_MM_XTINY 1 +#elif ((__MODEL__) == 5) +# define LZO_MM_XSMALL 1 +#else +# error "FIXME - C166 __MODEL__" +#endif +#elif (LZO_ARCH_MCS251) +#if !defined(__MODEL__) +# error "FIXME - MCS251 __MODEL__" +#elif ((__MODEL__) == 0) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 2) +# define LZO_MM_LARGE 1 +#elif ((__MODEL__) == 3) +# define LZO_MM_TINY 1 +#elif ((__MODEL__) == 4) +# define LZO_MM_XTINY 1 +#elif ((__MODEL__) == 5) +# define LZO_MM_XSMALL 1 +#else +# error "FIXME - MCS251 __MODEL__" +#endif +#elif (LZO_ARCH_MCS51) +#if !defined(__MODEL__) +# error "FIXME - MCS51 __MODEL__" +#elif ((__MODEL__) == 1) +# define LZO_MM_SMALL 1 +#elif ((__MODEL__) == 2) +# define LZO_MM_LARGE 1 +#elif ((__MODEL__) == 3) +# define LZO_MM_TINY 1 +#elif ((__MODEL__) == 4) +# define LZO_MM_XTINY 1 +#elif ((__MODEL__) == 5) +# define LZO_MM_XSMALL 1 +#else +# error "FIXME - MCS51 __MODEL__" +#endif +#elif (LZO_ARCH_CRAY_PVP) +# define LZO_MM_PVP 1 +#else +# define LZO_MM_FLAT 1 +#endif +#if (LZO_MM_COMPACT) +# define LZO_INFO_MM "compact" +#elif (LZO_MM_FLAT) +# define LZO_INFO_MM "flat" +#elif (LZO_MM_HUGE) +# define LZO_INFO_MM "huge" +#elif (LZO_MM_LARGE) +# define LZO_INFO_MM "large" +#elif (LZO_MM_MEDIUM) +# define LZO_INFO_MM "medium" +#elif (LZO_MM_PVP) +# define LZO_INFO_MM "pvp" +#elif (LZO_MM_SMALL) +# define LZO_INFO_MM "small" +#elif (LZO_MM_TINY) +# define LZO_INFO_MM "tiny" +#else +# error "unknown memory model" +#endif +#endif +#if defined(SIZEOF_SHORT) +# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) +#endif +#if defined(SIZEOF_INT) +# define LZO_SIZEOF_INT (SIZEOF_INT) +#endif +#if defined(SIZEOF_LONG) +# define LZO_SIZEOF_LONG (SIZEOF_LONG) +#endif +#if defined(SIZEOF_LONG_LONG) +# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) +#endif +#if defined(SIZEOF___INT16) +# define LZO_SIZEOF___INT16 (SIZEOF___INT16) +#endif +#if defined(SIZEOF___INT32) +# define LZO_SIZEOF___INT32 (SIZEOF___INT32) +#endif +#if defined(SIZEOF___INT64) +# define LZO_SIZEOF___INT64 (SIZEOF___INT64) +#endif +#if defined(SIZEOF_VOID_P) +# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) +#endif +#if defined(SIZEOF_SIZE_T) +# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) +#endif +#if defined(SIZEOF_PTRDIFF_T) +# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) +#endif +#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) +#if !defined(LZO_SIZEOF_SHORT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_SHORT 8 +# elif (USHRT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,7) == 1) +# define LZO_SIZEOF_SHORT 1 +# elif (__LZO_LSR(USHRT_MAX,15) == 1) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,31) == 1) +# define LZO_SIZEOF_SHORT 4 +# elif (__LZO_LSR(USHRT_MAX,63) == 1) +# define LZO_SIZEOF_SHORT 8 +# elif (__LZO_LSR(USHRT_MAX,127) == 1) +# define LZO_SIZEOF_SHORT 16 +# else +# error "LZO_SIZEOF_SHORT" +# endif +#endif +#if !defined(LZO_SIZEOF_INT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_INT 8 +# elif (UINT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_INT 2 +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,7) == 1) +# define LZO_SIZEOF_INT 1 +# elif (__LZO_LSR(UINT_MAX,15) == 1) +# define LZO_SIZEOF_INT 2 +# elif (__LZO_LSR(UINT_MAX,31) == 1) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,63) == 1) +# define LZO_SIZEOF_INT 8 +# elif (__LZO_LSR(UINT_MAX,127) == 1) +# define LZO_SIZEOF_INT 16 +# else +# error "LZO_SIZEOF_INT" +# endif +#endif +#if !defined(LZO_SIZEOF_LONG) +# if (ULONG_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,7) == 1) +# define LZO_SIZEOF_LONG 1 +# elif (__LZO_LSR(ULONG_MAX,15) == 1) +# define LZO_SIZEOF_LONG 2 +# elif (__LZO_LSR(ULONG_MAX,31) == 1) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,63) == 1) +# define LZO_SIZEOF_LONG 8 +# elif (__LZO_LSR(ULONG_MAX,127) == 1) +# define LZO_SIZEOF_LONG 16 +# else +# error "LZO_SIZEOF_LONG" +# endif +#endif +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) +# if (LZO_CC_GNUC >= 0x030300ul) +# if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0) +# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG +# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) +# define LZO_SIZEOF_LONG_LONG 4 +# endif +# endif +# endif +#endif +#endif +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +#if (LZO_ARCH_I086 && LZO_CC_DMC) +#elif (LZO_CC_CILLY) && defined(__GNUC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_SIZEOF_LONG_LONG 8 +#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_OS_WIN64 || defined(_WIN64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) +#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# define LZO_SIZEOF_LONG_LONG 8 +#endif +#endif +#endif +#if defined(__cplusplus) && defined(LZO_CC_GNUC) +# if (LZO_CC_GNUC < 0x020800ul) +# undef LZO_SIZEOF_LONG_LONG +# endif +#endif +#if defined(LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG) +# undef LZO_SIZEOF_LONG_LONG +#endif +#if !defined(LZO_SIZEOF_VOID_P) +#if (LZO_ARCH_I086) +# define __LZO_WORDSIZE 2 +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) +# define LZO_SIZEOF_VOID_P 2 +# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) +# define LZO_SIZEOF_VOID_P 4 +# else +# error "LZO_MM" +# endif +#elif (LZO_ARCH_AVR || LZO_ARCH_Z80) +# define __LZO_WORDSIZE 1 +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_H8300) +# if defined(__NORMAL_MODE__) +# define __LZO_WORDSIZE 4 +# define LZO_SIZEOF_VOID_P 2 +# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# define __LZO_WORDSIZE 4 +# define LZO_SIZEOF_VOID_P 4 +# else +# define __LZO_WORDSIZE 2 +# define LZO_SIZEOF_VOID_P 2 +# endif +# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT +# endif +#elif (LZO_ARCH_M16C) +# define __LZO_WORDSIZE 2 +# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) +# define LZO_SIZEOF_VOID_P 4 +# else +# define LZO_SIZEOF_VOID_P 2 +# endif +#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +# define __LZO_WORDSIZE 8 +# define LZO_SIZEOF_VOID_P 4 +#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) +# define __LZO_WORDSIZE 8 +# define LZO_SIZEOF_VOID_P 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (LZO_OS_OS400 || defined(__OS400__)) +# define __LZO_WORDSIZE LZO_SIZEOF_LONG +# define LZO_SIZEOF_VOID_P 16 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_SIZEOF_VOID_P 8 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (LZO_ARCH_SPU) +# if 0 +# define __LZO_WORDSIZE 16 +# endif +# define LZO_SIZEOF_VOID_P 4 +#else +# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +#endif +#endif +#if !defined(LZO_WORDSIZE) +# if defined(__LZO_WORDSIZE) +# define LZO_WORDSIZE __LZO_WORDSIZE +# else +# define LZO_WORDSIZE LZO_SIZEOF_VOID_P +# endif +#endif +#if !defined(LZO_SIZEOF_SIZE_T) +#if (LZO_ARCH_I086 || LZO_ARCH_M16C) +# define LZO_SIZEOF_SIZE_T 2 +#else +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P +#endif +#endif +#if !defined(LZO_SIZEOF_PTRDIFF_T) +#if (LZO_ARCH_I086) +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P +# elif (LZO_MM_COMPACT || LZO_MM_LARGE) +# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) +# define LZO_SIZEOF_PTRDIFF_T 4 +# else +# define LZO_SIZEOF_PTRDIFF_T 2 +# endif +# else +# error "LZO_MM" +# endif +#else +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T +#endif +#endif +#if defined(LZO_ABI_NEUTRAL_ENDIAN) +# undef LZO_ABI_BIG_ENDIAN +# undef LZO_ABI_LITTLE_ENDIAN +#elif !defined(LZO_ABI_BIG_ENDIAN) && !defined(LZO_ABI_LITTLE_ENDIAN) +#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) +# define LZO_ABI_BIG_ENDIAN 1 +#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif (LZO_ARCH_M68K || LZO_ARCH_S390) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) +# if (__LITTLE_ENDIAN__ == 1) +# define LZO_ABI_LITTLE_ENDIAN 1 +# else +# define LZO_ABI_BIG_ENDIAN 1 +# endif +#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#endif +#endif +#if defined(LZO_ABI_BIG_ENDIAN) && defined(LZO_ABI_LITTLE_ENDIAN) +# error "this should not happen" +#endif +#if defined(LZO_ABI_BIG_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "be" +#elif defined(LZO_ABI_LITTLE_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "le" +#elif defined(LZO_ABI_NEUTRAL_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "neutral" +#endif +#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_I8LP16 1 +# define LZO_INFO_ABI_PM "i8lp16" +#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_ILP16 1 +# define LZO_INFO_ABI_PM "ilp16" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_ILP32 1 +# define LZO_INFO_ABI_PM "ilp32" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) +# define LZO_ABI_LLP64 1 +# define LZO_INFO_ABI_PM "llp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_LP64 1 +# define LZO_INFO_ABI_PM "lp64" +#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_ILP64 1 +# define LZO_INFO_ABI_PM "ilp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_IP32L64 1 +# define LZO_INFO_ABI_PM "ip32l64" +#endif +#if !defined(__LZO_LIBC_OVERRIDE) +#if defined(LZO_LIBC_NAKED) +# define LZO_INFO_LIBC "naked" +#elif defined(LZO_LIBC_FREESTANDING) +# define LZO_INFO_LIBC "freestanding" +#elif defined(LZO_LIBC_MOSTLY_FREESTANDING) +# define LZO_INFO_LIBC "mfreestanding" +#elif defined(LZO_LIBC_ISOC90) +# define LZO_INFO_LIBC "isoc90" +#elif defined(LZO_LIBC_ISOC99) +# define LZO_INFO_LIBC "isoc99" +#elif defined(__dietlibc__) +# define LZO_LIBC_DIETLIBC 1 +# define LZO_INFO_LIBC "dietlibc" +#elif defined(_NEWLIB_VERSION) +# define LZO_LIBC_NEWLIB 1 +# define LZO_INFO_LIBC "newlib" +#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) +# if defined(__UCLIBC_SUBLEVEL__) +# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__) +# else +# define LZO_LIBC_UCLIBC 0x00090bL +# endif +# define LZO_INFO_LIBC "uclibc" +#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) +# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100) +# define LZO_INFO_LIBC "glibc" +#elif (LZO_CC_MWERKS) && defined(__MSL__) +# define LZO_LIBC_MSL __MSL__ +# define LZO_INFO_LIBC "msl" +#elif 1 && defined(__IAR_SYSTEMS_ICC__) +# define LZO_LIBC_ISOC90 1 +# define LZO_INFO_LIBC "isoc90" +#else +# define LZO_LIBC_DEFAULT 1 +# define LZO_INFO_LIBC "default" +#endif +#endif +#if !defined(__lzo_gnuc_extension__) +#if (LZO_CC_GNUC >= 0x020800ul) +# define __lzo_gnuc_extension__ __extension__ +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_gnuc_extension__ __extension__ +#else +# define __lzo_gnuc_extension__ +#endif +#endif +#if !defined(__lzo_ua_volatile) +# define __lzo_ua_volatile volatile +#endif +#if !defined(__lzo_alignof) +#if (LZO_CC_CILLY || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_alignof(e) __alignof(e) +#endif +#endif +#if defined(__lzo_alignof) +# define __lzo_HAVE_alignof 1 +#endif +#if !defined(__lzo_constructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_constructor __attribute__((__constructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_constructor __attribute__((__constructor__)) +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_constructor __attribute__((__constructor__)) +#endif +#endif +#if defined(__lzo_constructor) +# define __lzo_HAVE_constructor 1 +#endif +#if !defined(__lzo_destructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_destructor __attribute__((__destructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_destructor __attribute__((__destructor__)) +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_destructor __attribute__((__destructor__)) +#endif +#endif +#if defined(__lzo_destructor) +# define __lzo_HAVE_destructor 1 +#endif +#if defined(__lzo_HAVE_destructor) && !defined(__lzo_HAVE_constructor) +# error "this should not happen" +#endif +#if !defined(__lzo_inline) +#if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) +#elif defined(__cplusplus) +# define __lzo_inline inline +#elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) +# define __lzo_inline __inline +#elif (LZO_CC_CILLY || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define __lzo_inline __inline__ +#elif (LZO_CC_DMC) +# define __lzo_inline __inline +#elif (LZO_CC_INTELC) +# define __lzo_inline __inline +#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) +# define __lzo_inline __inline +#elif (LZO_CC_MSC && (_MSC_VER >= 900)) +# define __lzo_inline __inline +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# define __lzo_inline inline +#endif +#endif +#if defined(__lzo_inline) +# define __lzo_HAVE_inline 1 +#else +# define __lzo_inline +#endif +#if !defined(__lzo_forceinline) +#if (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +# define __lzo_forceinline __forceinline +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +# define __lzo_forceinline __forceinline +#endif +#endif +#if defined(__lzo_forceinline) +# define __lzo_HAVE_forceinline 1 +#else +# define __lzo_forceinline +#endif +#if !defined(__lzo_noinline) +#if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) +# define __lzo_noinline __attribute__((__noinline__,__used__)) +#elif (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC) +# define __lzo_noinline __declspec(noinline) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_noinline __declspec(noinline) +#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64)) +# if defined(__cplusplus) +# else +# define __lzo_noinline __declspec(noinline) +# endif +#endif +#endif +#if defined(__lzo_noinline) +# define __lzo_HAVE_noinline 1 +#else +# define __lzo_noinline +#endif +#if (defined(__lzo_HAVE_forceinline) || defined(__lzo_HAVE_noinline)) && !defined(__lzo_HAVE_inline) +# error "this should not happen" +#endif +#if !defined(__lzo_noreturn) +#if (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +# define __lzo_noreturn __declspec(noreturn) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +# define __lzo_noreturn __declspec(noreturn) +#endif +#endif +#if defined(__lzo_noreturn) +# define __lzo_HAVE_noreturn 1 +#else +# define __lzo_noreturn +#endif +#if !defined(__lzo_nothrow) +#if (LZO_CC_GNUC >= 0x030300ul) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus) +# define __lzo_nothrow __declspec(nothrow) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) +# define __lzo_nothrow __declspec(nothrow) +#endif +#endif +#if defined(__lzo_nothrow) +# define __lzo_HAVE_nothrow 1 +#else +# define __lzo_nothrow +#endif +#if !defined(__lzo_restrict) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_LLVM) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_MSC && (_MSC_VER >= 1400)) +# define __lzo_restrict __restrict +#endif +#endif +#if defined(__lzo_restrict) +# define __lzo_HAVE_restrict 1 +#else +# define __lzo_restrict +#endif +#if !defined(__lzo_likely) && !defined(__lzo_unlikely) +#if (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#endif +#endif +#if defined(__lzo_likely) +# define __lzo_HAVE_likely 1 +#else +# define __lzo_likely(e) (e) +#endif +#if defined(__lzo_unlikely) +# define __lzo_HAVE_unlikely 1 +#else +# define __lzo_unlikely(e) (e) +#endif +#if !defined(LZO_UNUSED) +# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +# define LZO_UNUSED(var) ((void) &var) +# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) +# define LZO_UNUSED(var) if (&var) ; else +# elif (LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNUSED(var) ((void) var) +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_UNUSED(var) if (&var) ; else +# elif (LZO_CC_KEILC) +# define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];} +# elif (LZO_CC_PACIFICC) +# define LZO_UNUSED(var) ((void) sizeof(var)) +# elif (LZO_CC_WATCOMC) && defined(__cplusplus) +# define LZO_UNUSED(var) ((void) var) +# else +# define LZO_UNUSED(var) ((void) &var) +# endif +#endif +#if !defined(LZO_UNUSED_FUNC) +# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +# define LZO_UNUSED_FUNC(func) ((void) func) +# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) +# define LZO_UNUSED_FUNC(func) if (func) ; else +# elif (LZO_CC_LLVM) +# define LZO_UNUSED_FUNC(func) ((void) &func) +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_UNUSED_FUNC(func) if (func) ; else +# elif (LZO_CC_MSC) +# define LZO_UNUSED_FUNC(func) ((void) &func) +# elif (LZO_CC_KEILC || LZO_CC_PELLESC) +# define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];} +# else +# define LZO_UNUSED_FUNC(func) ((void) func) +# endif +#endif +#if !defined(LZO_UNUSED_LABEL) +# if (LZO_CC_WATCOMC) && defined(__cplusplus) +# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l +# elif (LZO_CC_INTELC || LZO_CC_WATCOMC) +# define LZO_UNUSED_LABEL(l) if (0) goto l +# else +# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l +# endif +#endif +#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) +# if 0 +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var +# elif 0 && (LZO_CC_GNUC) +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var +# else +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init +# endif +#endif +#if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) +# if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +# elif (LZO_CC_DMC || LZO_CC_SYMANTECC) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)]; +# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +# else +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)]; +# endif +#endif +#if !defined(LZO_COMPILE_TIME_ASSERT) +# if (LZO_CC_AZTECC) +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];} +# elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) +# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) +# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +# else +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];} +# endif +#endif +#if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) +# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) +# elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) +# define __lzo_cdecl __cdecl +# define __lzo_cdecl_atexit +# define __lzo_cdecl_main __cdecl +# if (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) +# define __lzo_cdecl_qsort __pascal +# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) +# define __lzo_cdecl_qsort _stdcall +# else +# define __lzo_cdecl_qsort __cdecl +# endif +# elif (LZO_CC_WATCOMC) +# define __lzo_cdecl __cdecl +# else +# define __lzo_cdecl __cdecl +# define __lzo_cdecl_atexit __cdecl +# define __lzo_cdecl_main __cdecl +# define __lzo_cdecl_qsort __cdecl +# endif +# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC || LZO_CC_WATCOMC) +# elif (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) +# define __lzo_cdecl_sighandler __pascal +# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) +# define __lzo_cdecl_sighandler _stdcall +# elif (LZO_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE) +# define __lzo_cdecl_sighandler __clrcall +# elif (LZO_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700)) +# if defined(_DLL) +# define __lzo_cdecl_sighandler _far _cdecl _loadds +# elif defined(_MT) +# define __lzo_cdecl_sighandler _far _cdecl +# else +# define __lzo_cdecl_sighandler _cdecl +# endif +# else +# define __lzo_cdecl_sighandler __cdecl +# endif +#elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC) +# define __lzo_cdecl __cdecl +#elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC)) +# define __lzo_cdecl cdecl +#endif +#if !defined(__lzo_cdecl) +# define __lzo_cdecl +#endif +#if !defined(__lzo_cdecl_atexit) +# define __lzo_cdecl_atexit +#endif +#if !defined(__lzo_cdecl_main) +# define __lzo_cdecl_main +#endif +#if !defined(__lzo_cdecl_qsort) +# define __lzo_cdecl_qsort +#endif +#if !defined(__lzo_cdecl_sighandler) +# define __lzo_cdecl_sighandler +#endif +#if !defined(__lzo_cdecl_va) +# define __lzo_cdecl_va __lzo_cdecl +#endif +#if !defined(LZO_CFG_NO_WINDOWS_H) +#if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) +# if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) +# elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) +# elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul))) +# else +# define LZO_HAVE_WINDOWS_H 1 +# endif +#endif +#endif +#if (LZO_ARCH_ALPHA) +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_AVOID_SHORT 1 +# define LZO_OPT_AVOID_USHORT 1 +#elif (LZO_ARCH_AMD64) +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# define LZO_OPT_UNALIGNED64 1 +#elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB) +#elif (LZO_ARCH_ARM) +# define LZO_OPT_AVOID_SHORT 1 +# define LZO_OPT_AVOID_USHORT 1 +#elif (LZO_ARCH_CRIS) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +#elif (LZO_ARCH_I386) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +#elif (LZO_ARCH_IA64) +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_PREFER_POSTINC 1 +#elif (LZO_ARCH_M68K) +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 +# if defined(__mc68020__) && !defined(__mcoldfire__) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# endif +#elif (LZO_ARCH_MIPS) +# define LZO_OPT_AVOID_UINT_INDEX 1 +#elif (LZO_ARCH_POWERPC) +# define LZO_OPT_PREFER_PREINC 1 +# define LZO_OPT_PREFER_PREDEC 1 +# if defined(LZO_ABI_BIG_ENDIAN) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# endif +#elif (LZO_ARCH_S390) +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# if (LZO_SIZEOF_SIZE_T == 8) +# define LZO_OPT_UNALIGNED64 1 +# endif +#elif (LZO_ARCH_SH) +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 +#endif +#if !defined(LZO_CFG_NO_INLINE_ASM) +#if defined(LZO_CC_LLVM) +# define LZO_CFG_NO_INLINE_ASM 1 +#endif +#endif +#if !defined(LZO_CFG_NO_UNALIGNED) +#if defined(LZO_ABI_NEUTRAL_ENDIAN) || defined(LZO_ARCH_GENERIC) +# define LZO_CFG_NO_UNALIGNED 1 +#endif +#endif +#if defined(LZO_CFG_NO_UNALIGNED) +# undef LZO_OPT_UNALIGNED16 +# undef LZO_OPT_UNALIGNED32 +# undef LZO_OPT_UNALIGNED64 +#endif +#if defined(LZO_CFG_NO_INLINE_ASM) +#elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +# define LZO_ASM_SYNTAX_MSC 1 +#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +#elif (LZO_ARCH_I386 && (LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#elif (LZO_ARCH_AMD64 && (LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#endif +#if (LZO_ASM_SYNTAX_GNUC) +#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) +# define __LZO_ASM_CLOBBER "ax" +#elif (LZO_CC_INTELC) +# define __LZO_ASM_CLOBBER "memory" +#else +# define __LZO_ASM_CLOBBER "cc", "memory" +#endif +#endif +#if defined(__LZO_INFOSTR_MM) +#elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM)) +# define __LZO_INFOSTR_MM "" +#elif defined(LZO_INFO_MM) +# define __LZO_INFOSTR_MM "." LZO_INFO_MM +#else +# define __LZO_INFOSTR_MM "" +#endif +#if defined(__LZO_INFOSTR_PM) +#elif defined(LZO_INFO_ABI_PM) +# define __LZO_INFOSTR_PM "." LZO_INFO_ABI_PM +#else +# define __LZO_INFOSTR_PM "" +#endif +#if defined(__LZO_INFOSTR_ENDIAN) +#elif defined(LZO_INFO_ABI_ENDIAN) +# define __LZO_INFOSTR_ENDIAN "." LZO_INFO_ABI_ENDIAN +#else +# define __LZO_INFOSTR_ENDIAN "" +#endif +#if defined(__LZO_INFOSTR_OSNAME) +#elif defined(LZO_INFO_OS_CONSOLE) +# define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_CONSOLE +#elif defined(LZO_INFO_OS_POSIX) +# define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_POSIX +#else +# define __LZO_INFOSTR_OSNAME LZO_INFO_OS +#endif +#if defined(__LZO_INFOSTR_LIBC) +#elif defined(LZO_INFO_LIBC) +# define __LZO_INFOSTR_LIBC "." LZO_INFO_LIBC +#else +# define __LZO_INFOSTR_LIBC "" +#endif +#if defined(__LZO_INFOSTR_CCVER) +#elif defined(LZO_INFO_CCVER) +# define __LZO_INFOSTR_CCVER " " LZO_INFO_CCVER +#else +# define __LZO_INFOSTR_CCVER "" +#endif +#define LZO_INFO_STRING \ + LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \ + " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER + +#endif + +#endif + +#undef LZO_HAVE_CONFIG_H +#include "minilzo.h" + +#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x2030) +# error "version mismatch in miniLZO source files" +#endif + +#ifdef MINILZO_HAVE_CONFIG_H +# define LZO_HAVE_CONFIG_H +#endif + +#ifndef __LZO_CONF_H +#define __LZO_CONF_H + +#if !defined(__LZO_IN_MINILZO) +#if defined(LZO_CFG_FREESTANDING) +# define LZO_LIBC_FREESTANDING 1 +# define LZO_OS_FREESTANDING 1 +# define ACC_LIBC_FREESTANDING 1 +# define ACC_OS_FREESTANDING 1 +#endif +#if defined(LZO_CFG_NO_UNALIGNED) +# define ACC_CFG_NO_UNALIGNED 1 +#endif +#if defined(LZO_ARCH_GENERIC) +# define ACC_ARCH_GENERIC 1 +#endif +#if defined(LZO_ABI_NEUTRAL_ENDIAN) +# define ACC_ABI_NEUTRAL_ENDIAN 1 +#endif +#if defined(LZO_HAVE_CONFIG_H) +# define ACC_CONFIG_NO_HEADER 1 +#endif +#if defined(LZO_CFG_EXTRA_CONFIG_HEADER) +# include LZO_CFG_EXTRA_CONFIG_HEADER +#endif +#if defined(__LZOCONF_H) || defined(__LZOCONF_H_INCLUDED) +# error "include this file first" +#endif +#include "lzo/lzoconf.h" +#endif + +#if (LZO_VERSION < 0x02000) || !defined(__LZOCONF_H_INCLUDED) +# error "version mismatch" +#endif + +#if (LZO_CC_BORLANDC && LZO_ARCH_I086) +# pragma option -h +#endif + +#if (LZO_CC_MSC && (_MSC_VER >= 1000)) +# pragma warning(disable: 4127 4701) +#endif +#if (LZO_CC_MSC && (_MSC_VER >= 1300)) +# pragma warning(disable: 4820) +# pragma warning(disable: 4514 4710 4711) +#endif + +#if (LZO_CC_SUNPROC) +# pragma error_messages(off,E_END_OF_LOOP_CODE_NOT_REACHED) +# pragma error_messages(off,E_LOOP_NOT_ENTERED_AT_TOP) +#endif + +#if defined(__LZO_MMODEL_HUGE) && (!LZO_HAVE_MM_HUGE_PTR) +# error "this should not happen - check defines for __huge" +#endif + +#if defined(__LZO_IN_MINILZO) || defined(LZO_CFG_FREESTANDING) +#elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +# define ACC_WANT_ACC_INCD_H 1 +# define ACC_WANT_ACC_INCE_H 1 +# define ACC_WANT_ACC_INCI_H 1 +#elif 1 +# include +#else +# define ACC_WANT_ACC_INCD_H 1 +#endif + +#if (LZO_ARCH_I086) +# define ACC_MM_AHSHIFT LZO_MM_AHSHIFT +# define ACC_PTR_FP_OFF(x) (((const unsigned __far*)&(x))[0]) +# define ACC_PTR_FP_SEG(x) (((const unsigned __far*)&(x))[1]) +# define ACC_PTR_MK_FP(s,o) ((void __far*)(((unsigned long)(s)<<16)+(unsigned)(o))) +#endif + +#if !defined(lzo_uintptr_t) +# if defined(__LZO_MMODEL_HUGE) +# define lzo_uintptr_t unsigned long +# elif 1 && defined(LZO_OS_OS400) && (LZO_SIZEOF_VOID_P == 16) +# define __LZO_UINTPTR_T_IS_POINTER 1 + typedef char* lzo_uintptr_t; +# define lzo_uintptr_t lzo_uintptr_t +# elif (LZO_SIZEOF_SIZE_T == LZO_SIZEOF_VOID_P) +# define lzo_uintptr_t size_t +# elif (LZO_SIZEOF_LONG == LZO_SIZEOF_VOID_P) +# define lzo_uintptr_t unsigned long +# elif (LZO_SIZEOF_INT == LZO_SIZEOF_VOID_P) +# define lzo_uintptr_t unsigned int +# elif (LZO_SIZEOF_LONG_LONG == LZO_SIZEOF_VOID_P) +# define lzo_uintptr_t unsigned long long +# else +# define lzo_uintptr_t size_t +# endif +#endif +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) + +#if 1 && !defined(LZO_CFG_FREESTANDING) +#if 1 && !defined(HAVE_STRING_H) +#define HAVE_STRING_H 1 +#endif +#if 1 && !defined(HAVE_MEMCMP) +#define HAVE_MEMCMP 1 +#endif +#if 1 && !defined(HAVE_MEMCPY) +#define HAVE_MEMCPY 1 +#endif +#if 1 && !defined(HAVE_MEMMOVE) +#define HAVE_MEMMOVE 1 +#endif +#if 1 && !defined(HAVE_MEMSET) +#define HAVE_MEMSET 1 +#endif +#endif + +#if 1 && defined(HAVE_STRING_H) +#include +#endif + +#if defined(LZO_CFG_FREESTANDING) +# undef HAVE_MEMCMP +# undef HAVE_MEMCPY +# undef HAVE_MEMMOVE +# undef HAVE_MEMSET +#endif + +#if !defined(HAVE_MEMCMP) +# undef memcmp +# define memcmp(a,b,c) lzo_memcmp(a,b,c) +#elif !defined(__LZO_MMODEL_HUGE) +# define lzo_memcmp(a,b,c) memcmp(a,b,c) +#endif +#if !defined(HAVE_MEMCPY) +# undef memcpy +# define memcpy(a,b,c) lzo_memcpy(a,b,c) +#elif !defined(__LZO_MMODEL_HUGE) +# define lzo_memcpy(a,b,c) memcpy(a,b,c) +#endif +#if !defined(HAVE_MEMMOVE) +# undef memmove +# define memmove(a,b,c) lzo_memmove(a,b,c) +#elif !defined(__LZO_MMODEL_HUGE) +# define lzo_memmove(a,b,c) memmove(a,b,c) +#endif +#if !defined(HAVE_MEMSET) +# undef memset +# define memset(a,b,c) lzo_memset(a,b,c) +#elif !defined(__LZO_MMODEL_HUGE) +# define lzo_memset(a,b,c) memset(a,b,c) +#endif + +#undef NDEBUG +#if defined(LZO_CFG_FREESTANDING) +# undef LZO_DEBUG +# define NDEBUG 1 +# undef assert +# define assert(e) ((void)0) +#else +# if !defined(LZO_DEBUG) +# define NDEBUG 1 +# endif +# include +#endif + +#if 0 && defined(__BOUNDS_CHECKING_ON) +# include +#else +# define BOUNDS_CHECKING_OFF_DURING(stmt) stmt +# define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr) +#endif + +#if !defined(__lzo_inline) +# define __lzo_inline +#endif +#if !defined(__lzo_forceinline) +# define __lzo_forceinline +#endif +#if !defined(__lzo_noinline) +# define __lzo_noinline +#endif + +#if 1 +# define LZO_BYTE(x) ((unsigned char) (x)) +#else +# define LZO_BYTE(x) ((unsigned char) ((x) & 0xff)) +#endif + +#define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b)) +#define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b)) +#define LZO_MAX3(a,b,c) ((a) >= (b) ? LZO_MAX(a,c) : LZO_MAX(b,c)) +#define LZO_MIN3(a,b,c) ((a) <= (b) ? LZO_MIN(a,c) : LZO_MIN(b,c)) + +#define lzo_sizeof(type) ((lzo_uint) (sizeof(type))) + +#define LZO_HIGH(array) ((lzo_uint) (sizeof(array)/sizeof(*(array)))) + +#define LZO_SIZE(bits) (1u << (bits)) +#define LZO_MASK(bits) (LZO_SIZE(bits) - 1) + +#define LZO_LSIZE(bits) (1ul << (bits)) +#define LZO_LMASK(bits) (LZO_LSIZE(bits) - 1) + +#define LZO_USIZE(bits) ((lzo_uint) 1 << (bits)) +#define LZO_UMASK(bits) (LZO_USIZE(bits) - 1) + +#if !defined(DMUL) +#if 0 + +# define DMUL(a,b) ((lzo_xint) ((lzo_uint32)(a) * (lzo_uint32)(b))) +#else +# define DMUL(a,b) ((lzo_xint) ((a) * (b))) +#endif +#endif + +#if 1 && !defined(LZO_CFG_NO_UNALIGNED) +#if 1 && (LZO_ARCH_AMD64 || LZO_ARCH_I386) +# if (LZO_SIZEOF_SHORT == 2) +# define LZO_UNALIGNED_OK_2 +# endif +# if (LZO_SIZEOF_INT == 4) +# define LZO_UNALIGNED_OK_4 +# endif +#endif +#endif + +#if defined(LZO_UNALIGNED_OK_2) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(short) == 2) +#endif +#if defined(LZO_UNALIGNED_OK_4) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint32) == 4) +#elif defined(LZO_ALIGNED_OK_4) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint32) == 4) +#endif + +#define MEMCPY8_DS(dest,src,len) \ + lzo_memcpy(dest,src,len); dest += len; src += len + +#define BZERO8_PTR(s,l,n) \ + lzo_memset((lzo_voidp)(s),0,(lzo_uint)(l)*(n)) + +#define MEMCPY_DS(dest,src,len) \ + do *dest++ = *src++; while (--len > 0) + +__LZO_EXTERN_C int __lzo_init_done; +__LZO_EXTERN_C const char __lzo_copyright[]; +LZO_EXTERN(const lzo_bytep) lzo_copyright(void); + +#ifndef __LZO_PTR_H +#define __LZO_PTR_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(lzo_uintptr_t) +# if defined(__LZO_MMODEL_HUGE) +# define lzo_uintptr_t unsigned long +# else +# define lzo_uintptr_t acc_uintptr_t +# ifdef __ACC_INTPTR_T_IS_POINTER +# define __LZO_UINTPTR_T_IS_POINTER 1 +# endif +# endif +#endif + +#if (LZO_ARCH_I086) +#define PTR(a) ((lzo_bytep) (a)) +#define PTR_ALIGNED_4(a) ((ACC_PTR_FP_OFF(a) & 3) == 0) +#define PTR_ALIGNED2_4(a,b) (((ACC_PTR_FP_OFF(a) | ACC_PTR_FP_OFF(b)) & 3) == 0) +#elif (LZO_MM_PVP) +#define PTR(a) ((lzo_bytep) (a)) +#define PTR_ALIGNED_8(a) ((((lzo_uintptr_t)(a)) >> 61) == 0) +#define PTR_ALIGNED2_8(a,b) ((((lzo_uintptr_t)(a)|(lzo_uintptr_t)(b)) >> 61) == 0) +#else +#define PTR(a) ((lzo_uintptr_t) (a)) +#define PTR_LINEAR(a) PTR(a) +#define PTR_ALIGNED_4(a) ((PTR_LINEAR(a) & 3) == 0) +#define PTR_ALIGNED_8(a) ((PTR_LINEAR(a) & 7) == 0) +#define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0) +#define PTR_ALIGNED2_8(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 7) == 0) +#endif + +#define PTR_LT(a,b) (PTR(a) < PTR(b)) +#define PTR_GE(a,b) (PTR(a) >= PTR(b)) +#define PTR_DIFF(a,b) (PTR(a) - PTR(b)) +#define pd(a,b) ((lzo_uint) ((a)-(b))) + +LZO_EXTERN(lzo_uintptr_t) +__lzo_ptr_linear(const lzo_voidp ptr); + +typedef union +{ + char a_char; + unsigned char a_uchar; + short a_short; + unsigned short a_ushort; + int a_int; + unsigned int a_uint; + long a_long; + unsigned long a_ulong; + lzo_int a_lzo_int; + lzo_uint a_lzo_uint; + lzo_int32 a_lzo_int32; + lzo_uint32 a_lzo_uint32; + ptrdiff_t a_ptrdiff_t; + lzo_uintptr_t a_lzo_uintptr_t; + lzo_voidp a_lzo_voidp; + void * a_void_p; + lzo_bytep a_lzo_bytep; + lzo_bytepp a_lzo_bytepp; + lzo_uintp a_lzo_uintp; + lzo_uint * a_lzo_uint_p; + lzo_uint32p a_lzo_uint32p; + lzo_uint32 * a_lzo_uint32_p; + unsigned char * a_uchar_p; + char * a_char_p; +} +lzo_full_align_t; + +#ifdef __cplusplus +} +#endif + +#endif + +#define LZO_DETERMINISTIC + +#define LZO_DICT_USE_PTR +#if 0 && (LZO_ARCH_I086) +# undef LZO_DICT_USE_PTR +#endif + +#if defined(LZO_DICT_USE_PTR) +# define lzo_dict_t const lzo_bytep +# define lzo_dict_p lzo_dict_t __LZO_MMODEL * +#else +# define lzo_dict_t lzo_uint +# define lzo_dict_p lzo_dict_t __LZO_MMODEL * +#endif + +#endif + +#if !defined(MINILZO_CFG_SKIP_LZO_PTR) + +LZO_PUBLIC(lzo_uintptr_t) +__lzo_ptr_linear(const lzo_voidp ptr) +{ + lzo_uintptr_t p; + +#if (LZO_ARCH_I086) + p = (((lzo_uintptr_t)(ACC_PTR_FP_SEG(ptr))) << (16 - ACC_MM_AHSHIFT)) + (ACC_PTR_FP_OFF(ptr)); +#elif (LZO_MM_PVP) + p = (lzo_uintptr_t) (ptr); + p = (p << 3) | (p >> 61); +#else + p = (lzo_uintptr_t) PTR_LINEAR(ptr); +#endif + + return p; +} + +LZO_PUBLIC(unsigned) +__lzo_align_gap(const lzo_voidp ptr, lzo_uint size) +{ +#if defined(__LZO_UINTPTR_T_IS_POINTER) + size_t n = (size_t) ptr; + n = (((n + size - 1) / size) * size) - n; +#else + lzo_uintptr_t p, n; + p = __lzo_ptr_linear(ptr); + n = (((p + size - 1) / size) * size) - p; +#endif + + assert(size > 0); + assert((long)n >= 0); + assert(n <= size); + return (unsigned)n; +} + +#endif + +/* If you use the LZO library in a product, I would appreciate that you + * keep this copyright string in the executable of your product. + */ + +const char __lzo_copyright[] = +#if !defined(__LZO_IN_MINLZO) + LZO_VERSION_STRING; +#else + "\r\n\n" + "LZO data compression library.\n" + "$Copyright: LZO (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Markus Franz Xaver Johannes Oberhumer\n" + "\n" + "http://www.oberhumer.com $\n\n" + "$Id: LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE " $\n" + "$Built: " __DATE__ " " __TIME__ " $\n" + "$Info: " LZO_INFO_STRING " $\n"; +#endif + +LZO_PUBLIC(const lzo_bytep) +lzo_copyright(void) +{ +#if (LZO_OS_DOS16 && LZO_CC_TURBOC) + return (lzo_voidp) __lzo_copyright; +#else + return (const lzo_bytep) __lzo_copyright; +#endif +} + +LZO_PUBLIC(unsigned) +lzo_version(void) +{ + return LZO_VERSION; +} + +LZO_PUBLIC(const char *) +lzo_version_string(void) +{ + return LZO_VERSION_STRING; +} + +LZO_PUBLIC(const char *) +lzo_version_date(void) +{ + return LZO_VERSION_DATE; +} + +LZO_PUBLIC(const lzo_charp) +_lzo_version_string(void) +{ + return LZO_VERSION_STRING; +} + +LZO_PUBLIC(const lzo_charp) +_lzo_version_date(void) +{ + return LZO_VERSION_DATE; +} + +#define LZO_BASE 65521u +#define LZO_NMAX 5552 + +#define LZO_DO1(buf,i) s1 += buf[i]; s2 += s1 +#define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1); +#define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2); +#define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4); +#define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8); + +LZO_PUBLIC(lzo_uint32) +lzo_adler32(lzo_uint32 adler, const lzo_bytep buf, lzo_uint len) +{ + lzo_uint32 s1 = adler & 0xffff; + lzo_uint32 s2 = (adler >> 16) & 0xffff; + unsigned k; + + if (buf == NULL) + return 1; + + while (len > 0) + { + k = len < LZO_NMAX ? (unsigned) len : LZO_NMAX; + len -= k; + if (k >= 16) do + { + LZO_DO16(buf,0); + buf += 16; + k -= 16; + } while (k >= 16); + if (k != 0) do + { + s1 += *buf++; + s2 += s1; + } while (--k > 0); + s1 %= LZO_BASE; + s2 %= LZO_BASE; + } + return (s2 << 16) | s1; +} + +#undef LZO_DO1 +#undef LZO_DO2 +#undef LZO_DO4 +#undef LZO_DO8 +#undef LZO_DO16 + +#if !defined(MINILZO_CFG_SKIP_LZO_STRING) +#undef lzo_memcmp +#undef lzo_memcpy +#undef lzo_memmove +#undef lzo_memset +#if !defined(__LZO_MMODEL_HUGE) +# undef LZO_HAVE_MM_HUGE_PTR +#endif +#define lzo_hsize_t lzo_uint +#define lzo_hvoid_p lzo_voidp +#define lzo_hbyte_p lzo_bytep +#define LZOLIB_PUBLIC(r,f) LZO_PUBLIC(r) f +#define lzo_hmemcmp lzo_memcmp +#define lzo_hmemcpy lzo_memcpy +#define lzo_hmemmove lzo_memmove +#define lzo_hmemset lzo_memset +#define __LZOLIB_HMEMCPY_CH_INCLUDED 1 +#if !defined(LZOLIB_PUBLIC) +# define LZOLIB_PUBLIC(r,f) r __LZOLIB_FUNCNAME(f) +#endif +LZOLIB_PUBLIC(int, lzo_hmemcmp) (const lzo_hvoid_p s1, const lzo_hvoid_p s2, lzo_hsize_t len) +{ +#if (LZO_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMCMP) + const lzo_hbyte_p p1 = (const lzo_hbyte_p) s1; + const lzo_hbyte_p p2 = (const lzo_hbyte_p) s2; + if __lzo_likely(len > 0) do + { + int d = *p1 - *p2; + if (d != 0) + return d; + p1++; p2++; + } while __lzo_likely(--len > 0); + return 0; +#else + return memcmp(s1, s2, len); +#endif +} +LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemcpy) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len) +{ +#if (LZO_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMCPY) + lzo_hbyte_p p1 = (lzo_hbyte_p) dest; + const lzo_hbyte_p p2 = (const lzo_hbyte_p) src; + if (!(len > 0) || p1 == p2) + return dest; + do + *p1++ = *p2++; + while __lzo_likely(--len > 0); + return dest; +#else + return memcpy(dest, src, len); +#endif +} +LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemmove) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len) +{ +#if (LZO_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMMOVE) + lzo_hbyte_p p1 = (lzo_hbyte_p) dest; + const lzo_hbyte_p p2 = (const lzo_hbyte_p) src; + if (!(len > 0) || p1 == p2) + return dest; + if (p1 < p2) + { + do + *p1++ = *p2++; + while __lzo_likely(--len > 0); + } + else + { + p1 += len; + p2 += len; + do + *--p1 = *--p2; + while __lzo_likely(--len > 0); + } + return dest; +#else + return memmove(dest, src, len); +#endif +} +LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int c, lzo_hsize_t len) +{ +#if (LZO_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMSET) + lzo_hbyte_p p = (lzo_hbyte_p) s; + if __lzo_likely(len > 0) do + *p++ = (unsigned char) c; + while __lzo_likely(--len > 0); + return s; +#else + return memset(s, c, len); +#endif +} +#undef LZOLIB_PUBLIC +#endif + +#if !defined(__LZO_IN_MINILZO) + +#define ACC_WANT_ACC_CHK_CH 1 +#undef ACCCHK_ASSERT + + ACCCHK_ASSERT_IS_SIGNED_T(lzo_int) + ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint) + + ACCCHK_ASSERT_IS_SIGNED_T(lzo_int32) + ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint32) + ACCCHK_ASSERT((LZO_UINT32_C(1) << (int)(8*sizeof(LZO_UINT32_C(1))-1)) > 0) + ACCCHK_ASSERT(sizeof(lzo_uint32) >= 4) + +#if !defined(__LZO_UINTPTR_T_IS_POINTER) + ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t) +#endif + ACCCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) + + ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_xint) + ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint32)) + ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint)) + ACCCHK_ASSERT(sizeof(lzo_xint) == sizeof(lzo_uint32) || sizeof(lzo_xint) == sizeof(lzo_uint)) + +#endif +#undef ACCCHK_ASSERT + +LZO_PUBLIC(int) +_lzo_config_check(void) +{ + lzo_bool r = 1; + union { unsigned char c[2*sizeof(lzo_xint)]; lzo_xint l[2]; } u; + lzo_uintptr_t p; + +#if !defined(LZO_CFG_NO_CONFIG_CHECK) +#if defined(LZO_ABI_BIG_ENDIAN) + u.l[0] = u.l[1] = 0; u.c[sizeof(lzo_xint) - 1] = 128; + r &= (u.l[0] == 128); +#endif +#if defined(LZO_ABI_LITTLE_ENDIAN) + u.l[0] = u.l[1] = 0; u.c[0] = 128; + r &= (u.l[0] == 128); +#endif +#if defined(LZO_UNALIGNED_OK_2) + p = (lzo_uintptr_t) (const lzo_voidp) &u.c[0]; + u.l[0] = u.l[1] = 0; + r &= ((* (const lzo_ushortp) (p+1)) == 0); +#endif +#if defined(LZO_UNALIGNED_OK_4) + p = (lzo_uintptr_t) (const lzo_voidp) &u.c[0]; + u.l[0] = u.l[1] = 0; + r &= ((* (const lzo_uint32p) (p+1)) == 0); +#endif +#endif + + LZO_UNUSED(u); LZO_UNUSED(p); + return r == 1 ? LZO_E_OK : LZO_E_ERROR; +} + +int __lzo_init_done = 0; + +LZO_PUBLIC(int) +__lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5, + int s6, int s7, int s8, int s9) +{ + int r; + +#if defined(__LZO_IN_MINILZO) +#elif (LZO_CC_MSC && ((_MSC_VER) < 700)) +#else +#define ACC_WANT_ACC_CHK_CH 1 +#undef ACCCHK_ASSERT +#define ACCCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr) +#endif +#undef ACCCHK_ASSERT + + __lzo_init_done = 1; + + if (v == 0) + return LZO_E_ERROR; + + r = (s1 == -1 || s1 == (int) sizeof(short)) && + (s2 == -1 || s2 == (int) sizeof(int)) && + (s3 == -1 || s3 == (int) sizeof(long)) && + (s4 == -1 || s4 == (int) sizeof(lzo_uint32)) && + (s5 == -1 || s5 == (int) sizeof(lzo_uint)) && + (s6 == -1 || s6 == (int) lzo_sizeof_dict_t) && + (s7 == -1 || s7 == (int) sizeof(char *)) && + (s8 == -1 || s8 == (int) sizeof(lzo_voidp)) && + (s9 == -1 || s9 == (int) sizeof(lzo_callback_t)); + if (!r) + return LZO_E_ERROR; + + r = _lzo_config_check(); + if (r != LZO_E_OK) + return r; + + return r; +} + +#if !defined(__LZO_IN_MINILZO) + +#if (LZO_OS_WIN16 && LZO_CC_WATCOMC) && defined(__SW_BD) + +#if 0 +BOOL FAR PASCAL LibMain ( HANDLE hInstance, WORD wDataSegment, + WORD wHeapSize, LPSTR lpszCmdLine ) +#else +int __far __pascal LibMain ( int a, short b, short c, long d ) +#endif +{ + LZO_UNUSED(a); LZO_UNUSED(b); LZO_UNUSED(c); LZO_UNUSED(d); + return 1; +} + +#endif + +#endif + +#define do_compress _lzo1x_1_do_compress + +#if !defined(MINILZO_CFG_SKIP_LZO1X_1_COMPRESS) + +#define LZO_NEED_DICT_H +#define D_BITS 14 +#define D_INDEX1(d,p) d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5) +#define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f) + +#ifndef __LZO_CONFIG1X_H +#define __LZO_CONFIG1X_H + +#if !defined(LZO1X) && !defined(LZO1Y) && !defined(LZO1Z) +# define LZO1X +#endif + +#if !defined(__LZO_IN_MINILZO) +#include "lzo/lzo1x.h" +#endif + +#define LZO_EOF_CODE +#undef LZO_DETERMINISTIC + +#define M1_MAX_OFFSET 0x0400 +#ifndef M2_MAX_OFFSET +#define M2_MAX_OFFSET 0x0800 +#endif +#define M3_MAX_OFFSET 0x4000 +#define M4_MAX_OFFSET 0xbfff + +#define MX_MAX_OFFSET (M1_MAX_OFFSET + M2_MAX_OFFSET) + +#define M1_MIN_LEN 2 +#define M1_MAX_LEN 2 +#define M2_MIN_LEN 3 +#ifndef M2_MAX_LEN +#define M2_MAX_LEN 8 +#endif +#define M3_MIN_LEN 3 +#define M3_MAX_LEN 33 +#define M4_MIN_LEN 3 +#define M4_MAX_LEN 9 + +#define M1_MARKER 0 +#define M2_MARKER 64 +#define M3_MARKER 32 +#define M4_MARKER 16 + +#ifndef MIN_LOOKAHEAD +#define MIN_LOOKAHEAD (M2_MAX_LEN + 1) +#endif + +#if defined(LZO_NEED_DICT_H) + +#ifndef LZO_HASH +#define LZO_HASH LZO_HASH_LZO_INCREMENTAL_B +#endif +#define DL_MIN_LEN M2_MIN_LEN + +#ifndef __LZO_DICT_H +#define __LZO_DICT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(D_BITS) && defined(DBITS) +# define D_BITS DBITS +#endif +#if !defined(D_BITS) +# error "D_BITS is not defined" +#endif +#if (D_BITS < 16) +# define D_SIZE LZO_SIZE(D_BITS) +# define D_MASK LZO_MASK(D_BITS) +#else +# define D_SIZE LZO_USIZE(D_BITS) +# define D_MASK LZO_UMASK(D_BITS) +#endif +#define D_HIGH ((D_MASK >> 1) + 1) + +#if !defined(DD_BITS) +# define DD_BITS 0 +#endif +#define DD_SIZE LZO_SIZE(DD_BITS) +#define DD_MASK LZO_MASK(DD_BITS) + +#if !defined(DL_BITS) +# define DL_BITS (D_BITS - DD_BITS) +#endif +#if (DL_BITS < 16) +# define DL_SIZE LZO_SIZE(DL_BITS) +# define DL_MASK LZO_MASK(DL_BITS) +#else +# define DL_SIZE LZO_USIZE(DL_BITS) +# define DL_MASK LZO_UMASK(DL_BITS) +#endif + +#if (D_BITS != DL_BITS + DD_BITS) +# error "D_BITS does not match" +#endif +#if (D_BITS < 8 || D_BITS > 18) +# error "invalid D_BITS" +#endif +#if (DL_BITS < 8 || DL_BITS > 20) +# error "invalid DL_BITS" +#endif +#if (DD_BITS < 0 || DD_BITS > 6) +# error "invalid DD_BITS" +#endif + +#if !defined(DL_MIN_LEN) +# define DL_MIN_LEN 3 +#endif +#if !defined(DL_SHIFT) +# define DL_SHIFT ((DL_BITS + (DL_MIN_LEN - 1)) / DL_MIN_LEN) +#endif + +#define LZO_HASH_GZIP 1 +#define LZO_HASH_GZIP_INCREMENTAL 2 +#define LZO_HASH_LZO_INCREMENTAL_A 3 +#define LZO_HASH_LZO_INCREMENTAL_B 4 + +#if !defined(LZO_HASH) +# error "choose a hashing strategy" +#endif + +#undef DM +#undef DX + +#if (DL_MIN_LEN == 3) +# define _DV2_A(p,shift1,shift2) \ + (((( (lzo_xint)((p)[0]) << shift1) ^ (p)[1]) << shift2) ^ (p)[2]) +# define _DV2_B(p,shift1,shift2) \ + (((( (lzo_xint)((p)[2]) << shift1) ^ (p)[1]) << shift2) ^ (p)[0]) +# define _DV3_B(p,shift1,shift2,shift3) \ + ((_DV2_B((p)+1,shift1,shift2) << (shift3)) ^ (p)[0]) +#elif (DL_MIN_LEN == 2) +# define _DV2_A(p,shift1,shift2) \ + (( (lzo_xint)(p[0]) << shift1) ^ p[1]) +# define _DV2_B(p,shift1,shift2) \ + (( (lzo_xint)(p[1]) << shift1) ^ p[2]) +#else +# error "invalid DL_MIN_LEN" +#endif +#define _DV_A(p,shift) _DV2_A(p,shift,shift) +#define _DV_B(p,shift) _DV2_B(p,shift,shift) +#define DA2(p,s1,s2) \ + (((((lzo_xint)((p)[2]) << (s2)) + (p)[1]) << (s1)) + (p)[0]) +#define DS2(p,s1,s2) \ + (((((lzo_xint)((p)[2]) << (s2)) - (p)[1]) << (s1)) - (p)[0]) +#define DX2(p,s1,s2) \ + (((((lzo_xint)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0]) +#define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0]) +#define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0]) +#define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0]) +#define DMS(v,s) ((lzo_uint) (((v) & (D_MASK >> (s))) << (s))) +#define DM(v) DMS(v,0) + +#if (LZO_HASH == LZO_HASH_GZIP) +# define _DINDEX(dv,p) (_DV_A((p),DL_SHIFT)) + +#elif (LZO_HASH == LZO_HASH_GZIP_INCREMENTAL) +# define __LZO_HASH_INCREMENTAL +# define DVAL_FIRST(dv,p) dv = _DV_A((p),DL_SHIFT) +# define DVAL_NEXT(dv,p) dv = (((dv) << DL_SHIFT) ^ p[2]) +# define _DINDEX(dv,p) (dv) +# define DVAL_LOOKAHEAD DL_MIN_LEN + +#elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_A) +# define __LZO_HASH_INCREMENTAL +# define DVAL_FIRST(dv,p) dv = _DV_A((p),5) +# define DVAL_NEXT(dv,p) \ + dv ^= (lzo_xint)(p[-1]) << (2*5); dv = (((dv) << 5) ^ p[2]) +# define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5) +# define DVAL_LOOKAHEAD DL_MIN_LEN + +#elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_B) +# define __LZO_HASH_INCREMENTAL +# define DVAL_FIRST(dv,p) dv = _DV_B((p),5) +# define DVAL_NEXT(dv,p) \ + dv ^= p[-1]; dv = (((dv) >> 5) ^ ((lzo_xint)(p[2]) << (2*5))) +# define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5) +# define DVAL_LOOKAHEAD DL_MIN_LEN + +#else +# error "choose a hashing strategy" +#endif + +#ifndef DINDEX +#define DINDEX(dv,p) ((lzo_uint)((_DINDEX(dv,p)) & DL_MASK) << DD_BITS) +#endif +#if !defined(DINDEX1) && defined(D_INDEX1) +#define DINDEX1 D_INDEX1 +#endif +#if !defined(DINDEX2) && defined(D_INDEX2) +#define DINDEX2 D_INDEX2 +#endif + +#if !defined(__LZO_HASH_INCREMENTAL) +# define DVAL_FIRST(dv,p) ((void) 0) +# define DVAL_NEXT(dv,p) ((void) 0) +# define DVAL_LOOKAHEAD 0 +#endif + +#if !defined(DVAL_ASSERT) +#if defined(__LZO_HASH_INCREMENTAL) && !defined(NDEBUG) +static void DVAL_ASSERT(lzo_xint dv, const lzo_bytep p) +{ + lzo_xint df; + DVAL_FIRST(df,(p)); + assert(DINDEX(dv,p) == DINDEX(df,p)); +} +#else +# define DVAL_ASSERT(dv,p) ((void) 0) +#endif +#endif + +#if defined(LZO_DICT_USE_PTR) +# define DENTRY(p,in) (p) +# define GINDEX(m_pos,m_off,dict,dindex,in) m_pos = dict[dindex] +#else +# define DENTRY(p,in) ((lzo_uint) ((p)-(in))) +# define GINDEX(m_pos,m_off,dict,dindex,in) m_off = dict[dindex] +#endif + +#if (DD_BITS == 0) + +# define UPDATE_D(dict,drun,dv,p,in) dict[ DINDEX(dv,p) ] = DENTRY(p,in) +# define UPDATE_I(dict,drun,index,p,in) dict[index] = DENTRY(p,in) +# define UPDATE_P(ptr,drun,p,in) (ptr)[0] = DENTRY(p,in) + +#else + +# define UPDATE_D(dict,drun,dv,p,in) \ + dict[ DINDEX(dv,p) + drun++ ] = DENTRY(p,in); drun &= DD_MASK +# define UPDATE_I(dict,drun,index,p,in) \ + dict[ (index) + drun++ ] = DENTRY(p,in); drun &= DD_MASK +# define UPDATE_P(ptr,drun,p,in) \ + (ptr) [ drun++ ] = DENTRY(p,in); drun &= DD_MASK + +#endif + +#if defined(LZO_DICT_USE_PTR) + +#define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \ + (m_pos == NULL || (m_off = pd(ip, m_pos)) > max_offset) + +#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \ + (BOUNDS_CHECKING_OFF_IN_EXPR(( \ + m_pos = ip - (lzo_uint) PTR_DIFF(ip,m_pos), \ + PTR_LT(m_pos,in) || \ + (m_off = (lzo_uint) PTR_DIFF(ip,m_pos)) <= 0 || \ + m_off > max_offset ))) + +#else + +#define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \ + (m_off == 0 || \ + ((m_off = pd(ip, in) - m_off) > max_offset) || \ + (m_pos = (ip) - (m_off), 0) ) + +#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \ + (pd(ip, in) <= m_off || \ + ((m_off = pd(ip, in) - m_off) > max_offset) || \ + (m_pos = (ip) - (m_off), 0) ) + +#endif + +#if defined(LZO_DETERMINISTIC) +# define LZO_CHECK_MPOS LZO_CHECK_MPOS_DET +#else +# define LZO_CHECK_MPOS LZO_CHECK_MPOS_NON_DET +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +#endif + +#endif + +#define DO_COMPRESS lzo1x_1_compress + +static __lzo_noinline lzo_uint +do_compress ( const lzo_bytep in , lzo_uint in_len, + lzo_bytep out, lzo_uintp out_len, + lzo_voidp wrkmem ) +{ + register const lzo_bytep ip; + lzo_bytep op; + const lzo_bytep const in_end = in + in_len; + const lzo_bytep const ip_end = in + in_len - M2_MAX_LEN - 5; + const lzo_bytep ii; + lzo_dict_p const dict = (lzo_dict_p) wrkmem; + + op = out; + ip = in; + ii = ip; + + ip += 4; + for (;;) + { + register const lzo_bytep m_pos; + lzo_uint m_off; + lzo_uint m_len; + lzo_uint dindex; + + DINDEX1(dindex,ip); + GINDEX(m_pos,m_off,dict,dindex,in); + if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET)) + goto literal; +#if 1 + if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) + goto try_match; + DINDEX2(dindex,ip); +#endif + GINDEX(m_pos,m_off,dict,dindex,in); + if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET)) + goto literal; + if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) + goto try_match; + goto literal; + +try_match: +#if 1 && defined(LZO_UNALIGNED_OK_2) + if (* (const lzo_ushortp) m_pos != * (const lzo_ushortp) ip) +#else + if (m_pos[0] != ip[0] || m_pos[1] != ip[1]) +#endif + { + } + else + { + if __lzo_likely(m_pos[2] == ip[2]) + { +#if 0 + if (m_off <= M2_MAX_OFFSET) + goto match; + if (lit <= 3) + goto match; + if (lit == 3) + { + assert(op - 2 > out); op[-2] |= LZO_BYTE(3); + *op++ = *ii++; *op++ = *ii++; *op++ = *ii++; + goto code_match; + } + if (m_pos[3] == ip[3]) +#endif + goto match; + } + else + { +#if 0 +#if 0 + if (m_off <= M1_MAX_OFFSET && lit > 0 && lit <= 3) +#else + if (m_off <= M1_MAX_OFFSET && lit == 3) +#endif + { + register lzo_uint t; + + t = lit; + assert(op - 2 > out); op[-2] |= LZO_BYTE(t); + do *op++ = *ii++; while (--t > 0); + assert(ii == ip); + m_off -= 1; + *op++ = LZO_BYTE(M1_MARKER | ((m_off & 3) << 2)); + *op++ = LZO_BYTE(m_off >> 2); + ip += 2; + goto match_done; + } +#endif + } + } + +literal: + UPDATE_I(dict,0,dindex,ip,in); + ++ip; + if __lzo_unlikely(ip >= ip_end) + break; + continue; + +match: + UPDATE_I(dict,0,dindex,ip,in); + if (pd(ip,ii) > 0) + { + register lzo_uint t = pd(ip,ii); + + if (t <= 3) + { + assert(op - 2 > out); + op[-2] |= LZO_BYTE(t); + } + else if (t <= 18) + *op++ = LZO_BYTE(t - 3); + else + { + register lzo_uint tt = t - 18; + + *op++ = 0; + while (tt > 255) + { + tt -= 255; + *op++ = 0; + } + assert(tt > 0); + *op++ = LZO_BYTE(tt); + } + do *op++ = *ii++; while (--t > 0); + } + + assert(ii == ip); + ip += 3; + if (m_pos[3] != *ip++ || m_pos[4] != *ip++ || m_pos[5] != *ip++ || + m_pos[6] != *ip++ || m_pos[7] != *ip++ || m_pos[8] != *ip++ +#ifdef LZO1Y + || m_pos[ 9] != *ip++ || m_pos[10] != *ip++ || m_pos[11] != *ip++ + || m_pos[12] != *ip++ || m_pos[13] != *ip++ || m_pos[14] != *ip++ +#endif + ) + { + --ip; + m_len = pd(ip, ii); + assert(m_len >= 3); assert(m_len <= M2_MAX_LEN); + + if (m_off <= M2_MAX_OFFSET) + { + m_off -= 1; +#if defined(LZO1X) + *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2)); + *op++ = LZO_BYTE(m_off >> 3); +#elif defined(LZO1Y) + *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2)); + *op++ = LZO_BYTE(m_off >> 2); +#endif + } + else if (m_off <= M3_MAX_OFFSET) + { + m_off -= 1; + *op++ = LZO_BYTE(M3_MARKER | (m_len - 2)); + goto m3_m4_offset; + } + else +#if defined(LZO1X) + { + m_off -= 0x4000; + assert(m_off > 0); assert(m_off <= 0x7fff); + *op++ = LZO_BYTE(M4_MARKER | + ((m_off & 0x4000) >> 11) | (m_len - 2)); + goto m3_m4_offset; + } +#elif defined(LZO1Y) + goto m4_match; +#endif + } + else + { + { + const lzo_bytep end = in_end; + const lzo_bytep m = m_pos + M2_MAX_LEN + 1; + while (ip < end && *m == *ip) + m++, ip++; + m_len = pd(ip, ii); + } + assert(m_len > M2_MAX_LEN); + + if (m_off <= M3_MAX_OFFSET) + { + m_off -= 1; + if (m_len <= 33) + *op++ = LZO_BYTE(M3_MARKER | (m_len - 2)); + else + { + m_len -= 33; + *op++ = M3_MARKER | 0; + goto m3_m4_len; + } + } + else + { +#if defined(LZO1Y) +m4_match: +#endif + m_off -= 0x4000; + assert(m_off > 0); assert(m_off <= 0x7fff); + if (m_len <= M4_MAX_LEN) + *op++ = LZO_BYTE(M4_MARKER | + ((m_off & 0x4000) >> 11) | (m_len - 2)); + else + { + m_len -= M4_MAX_LEN; + *op++ = LZO_BYTE(M4_MARKER | ((m_off & 0x4000) >> 11)); +m3_m4_len: + while (m_len > 255) + { + m_len -= 255; + *op++ = 0; + } + assert(m_len > 0); + *op++ = LZO_BYTE(m_len); + } + } + +m3_m4_offset: + *op++ = LZO_BYTE((m_off & 63) << 2); + *op++ = LZO_BYTE(m_off >> 6); + } + +#if 0 +match_done: +#endif + ii = ip; + if __lzo_unlikely(ip >= ip_end) + break; + } + + *out_len = pd(op, out); + return pd(in_end,ii); +} + +LZO_PUBLIC(int) +DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, + lzo_bytep out, lzo_uintp out_len, + lzo_voidp wrkmem ) +{ + lzo_bytep op = out; + lzo_uint t; + + if __lzo_unlikely(in_len <= M2_MAX_LEN + 5) + t = in_len; + else + { + t = do_compress(in,in_len,op,out_len,wrkmem); + op += *out_len; + } + + if (t > 0) + { + const lzo_bytep ii = in + in_len - t; + + if (op == out && t <= 238) + *op++ = LZO_BYTE(17 + t); + else if (t <= 3) + op[-2] |= LZO_BYTE(t); + else if (t <= 18) + *op++ = LZO_BYTE(t - 3); + else + { + lzo_uint tt = t - 18; + + *op++ = 0; + while (tt > 255) + { + tt -= 255; + *op++ = 0; + } + assert(tt > 0); + *op++ = LZO_BYTE(tt); + } + do *op++ = *ii++; while (--t > 0); + } + + *op++ = M4_MARKER | 1; + *op++ = 0; + *op++ = 0; + + *out_len = pd(op, out); + return LZO_E_OK; +} + +#endif + +#undef do_compress +#undef DO_COMPRESS +#undef LZO_HASH + +#undef LZO_TEST_OVERRUN +#undef DO_DECOMPRESS +#define DO_DECOMPRESS lzo1x_decompress + +#if !defined(MINILZO_CFG_SKIP_LZO1X_DECOMPRESS) + +#if defined(LZO_TEST_OVERRUN) +# if !defined(LZO_TEST_OVERRUN_INPUT) +# define LZO_TEST_OVERRUN_INPUT 2 +# endif +# if !defined(LZO_TEST_OVERRUN_OUTPUT) +# define LZO_TEST_OVERRUN_OUTPUT 2 +# endif +# if !defined(LZO_TEST_OVERRUN_LOOKBEHIND) +# define LZO_TEST_OVERRUN_LOOKBEHIND +# endif +#endif + +#undef TEST_IP +#undef TEST_OP +#undef TEST_LB +#undef TEST_LBO +#undef NEED_IP +#undef NEED_OP +#undef HAVE_TEST_IP +#undef HAVE_TEST_OP +#undef HAVE_NEED_IP +#undef HAVE_NEED_OP +#undef HAVE_ANY_IP +#undef HAVE_ANY_OP + +#if defined(LZO_TEST_OVERRUN_INPUT) +# if (LZO_TEST_OVERRUN_INPUT >= 1) +# define TEST_IP (ip < ip_end) +# endif +# if (LZO_TEST_OVERRUN_INPUT >= 2) +# define NEED_IP(x) \ + if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun +# endif +#endif + +#if defined(LZO_TEST_OVERRUN_OUTPUT) +# if (LZO_TEST_OVERRUN_OUTPUT >= 1) +# define TEST_OP (op <= op_end) +# endif +# if (LZO_TEST_OVERRUN_OUTPUT >= 2) +# undef TEST_OP +# define NEED_OP(x) \ + if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun +# endif +#endif + +#if defined(LZO_TEST_OVERRUN_LOOKBEHIND) +# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun +# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun +#else +# define TEST_LB(m_pos) ((void) 0) +# define TEST_LBO(m_pos,o) ((void) 0) +#endif + +#if !defined(LZO_EOF_CODE) && !defined(TEST_IP) +# define TEST_IP (ip < ip_end) +#endif + +#if defined(TEST_IP) +# define HAVE_TEST_IP +#else +# define TEST_IP 1 +#endif +#if defined(TEST_OP) +# define HAVE_TEST_OP +#else +# define TEST_OP 1 +#endif + +#if defined(NEED_IP) +# define HAVE_NEED_IP +#else +# define NEED_IP(x) ((void) 0) +#endif +#if defined(NEED_OP) +# define HAVE_NEED_OP +#else +# define NEED_OP(x) ((void) 0) +#endif + +#if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) +# define HAVE_ANY_IP +#endif +#if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP) +# define HAVE_ANY_OP +#endif + +#undef __COPY4 +#define __COPY4(dst,src) * (lzo_uint32p)(dst) = * (const lzo_uint32p)(src) + +#undef COPY4 +#if defined(LZO_UNALIGNED_OK_4) +# define COPY4(dst,src) __COPY4(dst,src) +#elif defined(LZO_ALIGNED_OK_4) +# define COPY4(dst,src) __COPY4((lzo_uintptr_t)(dst),(lzo_uintptr_t)(src)) +#endif + +#if defined(DO_DECOMPRESS) +LZO_PUBLIC(int) +DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, + lzo_bytep out, lzo_uintp out_len, + lzo_voidp wrkmem ) +#endif +{ + register lzo_bytep op; + register const lzo_bytep ip; + register lzo_uint t; +#if defined(COPY_DICT) + lzo_uint m_off; + const lzo_bytep dict_end; +#else + register const lzo_bytep m_pos; +#endif + + const lzo_bytep const ip_end = in + in_len; +#if defined(HAVE_ANY_OP) + lzo_bytep const op_end = out + *out_len; +#endif +#if defined(LZO1Z) + lzo_uint last_m_off = 0; +#endif + + LZO_UNUSED(wrkmem); + +#if defined(COPY_DICT) + if (dict) + { + if (dict_len > M4_MAX_OFFSET) + { + dict += dict_len - M4_MAX_OFFSET; + dict_len = M4_MAX_OFFSET; + } + dict_end = dict + dict_len; + } + else + { + dict_len = 0; + dict_end = NULL; + } +#endif + + *out_len = 0; + + op = out; + ip = in; + + if (*ip > 17) + { + t = *ip++ - 17; + if (t < 4) + goto match_next; + assert(t > 0); NEED_OP(t); NEED_IP(t+1); + do *op++ = *ip++; while (--t > 0); + goto first_literal_run; + } + + while (TEST_IP && TEST_OP) + { + t = *ip++; + if (t >= 16) + goto match; + if (t == 0) + { + NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; + NEED_IP(1); + } + t += 15 + *ip++; + } + assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); +#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +#if !defined(LZO_UNALIGNED_OK_4) + if (PTR_ALIGNED2_4(op,ip)) + { +#endif + COPY4(op,ip); + op += 4; ip += 4; + if (--t > 0) + { + if (t >= 4) + { + do { + COPY4(op,ip); + op += 4; ip += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *ip++; while (--t > 0); + } + else + do *op++ = *ip++; while (--t > 0); + } +#if !defined(LZO_UNALIGNED_OK_4) + } + else +#endif +#endif +#if !defined(LZO_UNALIGNED_OK_4) + { + *op++ = *ip++; *op++ = *ip++; *op++ = *ip++; + do *op++ = *ip++; while (--t > 0); + } +#endif + +first_literal_run: + + t = *ip++; + if (t >= 16) + goto match; +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); + last_m_off = m_off; +#else + m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2); +#endif + NEED_OP(3); + t = 3; COPY_DICT(t,m_off) +#else +#if defined(LZO1Z) + t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); + m_pos = op - t; + last_m_off = t; +#else + m_pos = op - (1 + M2_MAX_OFFSET); + m_pos -= t >> 2; + m_pos -= *ip++ << 2; +#endif + TEST_LB(m_pos); NEED_OP(3); + *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos; +#endif + goto match_done; + + do { +match: + if (t >= 64) + { +#if defined(COPY_DICT) +#if defined(LZO1X) + m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3); + t = (t >> 5) - 1; +#elif defined(LZO1Y) + m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2); + t = (t >> 4) - 3; +#elif defined(LZO1Z) + m_off = t & 0x1f; + if (m_off >= 0x1c) + m_off = last_m_off; + else + { + m_off = 1 + (m_off << 6) + (*ip++ >> 2); + last_m_off = m_off; + } + t = (t >> 5) - 1; +#endif +#else +#if defined(LZO1X) + m_pos = op - 1; + m_pos -= (t >> 2) & 7; + m_pos -= *ip++ << 3; + t = (t >> 5) - 1; +#elif defined(LZO1Y) + m_pos = op - 1; + m_pos -= (t >> 2) & 3; + m_pos -= *ip++ << 2; + t = (t >> 4) - 3; +#elif defined(LZO1Z) + { + lzo_uint off = t & 0x1f; + m_pos = op; + if (off >= 0x1c) + { + assert(last_m_off > 0); + m_pos -= last_m_off; + } + else + { + off = 1 + (off << 6) + (*ip++ >> 2); + m_pos -= off; + last_m_off = off; + } + } + t = (t >> 5) - 1; +#endif + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); + goto copy_match; +#endif + } + else if (t >= 32) + { + t &= 31; + if (t == 0) + { + NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; + NEED_IP(1); + } + t += 31 + *ip++; + } +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off = 1 + (ip[0] << 6) + (ip[1] >> 2); + last_m_off = m_off; +#else + m_off = 1 + (ip[0] >> 2) + (ip[1] << 6); +#endif +#else +#if defined(LZO1Z) + { + lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2); + m_pos = op - off; + last_m_off = off; + } +#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) + m_pos = op - 1; + m_pos -= (* (const lzo_ushortp) ip) >> 2; +#else + m_pos = op - 1; + m_pos -= (ip[0] >> 2) + (ip[1] << 6); +#endif +#endif + ip += 2; + } + else if (t >= 16) + { +#if defined(COPY_DICT) + m_off = (t & 8) << 11; +#else + m_pos = op; + m_pos -= (t & 8) << 11; +#endif + t &= 7; + if (t == 0) + { + NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; + NEED_IP(1); + } + t += 7 + *ip++; + } +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off += (ip[0] << 6) + (ip[1] >> 2); +#else + m_off += (ip[0] >> 2) + (ip[1] << 6); +#endif + ip += 2; + if (m_off == 0) + goto eof_found; + m_off += 0x4000; +#if defined(LZO1Z) + last_m_off = m_off; +#endif +#else +#if defined(LZO1Z) + m_pos -= (ip[0] << 6) + (ip[1] >> 2); +#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) + m_pos -= (* (const lzo_ushortp) ip) >> 2; +#else + m_pos -= (ip[0] >> 2) + (ip[1] << 6); +#endif + ip += 2; + if (m_pos == op) + goto eof_found; + m_pos -= 0x4000; +#if defined(LZO1Z) + last_m_off = pd((const lzo_bytep)op, m_pos); +#endif +#endif + } + else + { +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off = 1 + (t << 6) + (*ip++ >> 2); + last_m_off = m_off; +#else + m_off = 1 + (t >> 2) + (*ip++ << 2); +#endif + NEED_OP(2); + t = 2; COPY_DICT(t,m_off) +#else +#if defined(LZO1Z) + t = 1 + (t << 6) + (*ip++ >> 2); + m_pos = op - t; + last_m_off = t; +#else + m_pos = op - 1; + m_pos -= t >> 2; + m_pos -= *ip++ << 2; +#endif + TEST_LB(m_pos); NEED_OP(2); + *op++ = *m_pos++; *op++ = *m_pos; +#endif + goto match_done; + } + +#if defined(COPY_DICT) + + NEED_OP(t+3-1); + t += 3-1; COPY_DICT(t,m_off) + +#else + + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); +#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +#if !defined(LZO_UNALIGNED_OK_4) + if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) + { + assert((op - m_pos) >= 4); +#else + if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) + { +#endif + COPY4(op,m_pos); + op += 4; m_pos += 4; t -= 4 - (3 - 1); + do { + COPY4(op,m_pos); + op += 4; m_pos += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *m_pos++; while (--t > 0); + } + else +#endif + { +copy_match: + *op++ = *m_pos++; *op++ = *m_pos++; + do *op++ = *m_pos++; while (--t > 0); + } + +#endif + +match_done: +#if defined(LZO1Z) + t = ip[-1] & 3; +#else + t = ip[-2] & 3; +#endif + if (t == 0) + break; + +match_next: + assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1); +#if 0 + do *op++ = *ip++; while (--t > 0); +#else + *op++ = *ip++; + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } +#endif + t = *ip++; + } while (TEST_IP && TEST_OP); + } + +#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) + *out_len = pd(op, out); + return LZO_E_EOF_NOT_FOUND; +#endif + +eof_found: + assert(t == 1); + *out_len = pd(op, out); + return (ip == ip_end ? LZO_E_OK : + (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); + +#if defined(HAVE_NEED_IP) +input_overrun: + *out_len = pd(op, out); + return LZO_E_INPUT_OVERRUN; +#endif + +#if defined(HAVE_NEED_OP) +output_overrun: + *out_len = pd(op, out); + return LZO_E_OUTPUT_OVERRUN; +#endif + +#if defined(LZO_TEST_OVERRUN_LOOKBEHIND) +lookbehind_overrun: + *out_len = pd(op, out); + return LZO_E_LOOKBEHIND_OVERRUN; +#endif +} + +#endif + +#define LZO_TEST_OVERRUN +#undef DO_DECOMPRESS +#define DO_DECOMPRESS lzo1x_decompress_safe + +#if !defined(MINILZO_CFG_SKIP_LZO1X_DECOMPRESS_SAFE) + +#if defined(LZO_TEST_OVERRUN) +# if !defined(LZO_TEST_OVERRUN_INPUT) +# define LZO_TEST_OVERRUN_INPUT 2 +# endif +# if !defined(LZO_TEST_OVERRUN_OUTPUT) +# define LZO_TEST_OVERRUN_OUTPUT 2 +# endif +# if !defined(LZO_TEST_OVERRUN_LOOKBEHIND) +# define LZO_TEST_OVERRUN_LOOKBEHIND +# endif +#endif + +#undef TEST_IP +#undef TEST_OP +#undef TEST_LB +#undef TEST_LBO +#undef NEED_IP +#undef NEED_OP +#undef HAVE_TEST_IP +#undef HAVE_TEST_OP +#undef HAVE_NEED_IP +#undef HAVE_NEED_OP +#undef HAVE_ANY_IP +#undef HAVE_ANY_OP + +#if defined(LZO_TEST_OVERRUN_INPUT) +# if (LZO_TEST_OVERRUN_INPUT >= 1) +# define TEST_IP (ip < ip_end) +# endif +# if (LZO_TEST_OVERRUN_INPUT >= 2) +# define NEED_IP(x) \ + if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun +# endif +#endif + +#if defined(LZO_TEST_OVERRUN_OUTPUT) +# if (LZO_TEST_OVERRUN_OUTPUT >= 1) +# define TEST_OP (op <= op_end) +# endif +# if (LZO_TEST_OVERRUN_OUTPUT >= 2) +# undef TEST_OP +# define NEED_OP(x) \ + if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun +# endif +#endif + +#if defined(LZO_TEST_OVERRUN_LOOKBEHIND) +# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun +# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun +#else +# define TEST_LB(m_pos) ((void) 0) +# define TEST_LBO(m_pos,o) ((void) 0) +#endif + +#if !defined(LZO_EOF_CODE) && !defined(TEST_IP) +# define TEST_IP (ip < ip_end) +#endif + +#if defined(TEST_IP) +# define HAVE_TEST_IP +#else +# define TEST_IP 1 +#endif +#if defined(TEST_OP) +# define HAVE_TEST_OP +#else +# define TEST_OP 1 +#endif + +#if defined(NEED_IP) +# define HAVE_NEED_IP +#else +# define NEED_IP(x) ((void) 0) +#endif +#if defined(NEED_OP) +# define HAVE_NEED_OP +#else +# define NEED_OP(x) ((void) 0) +#endif + +#if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) +# define HAVE_ANY_IP +#endif +#if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP) +# define HAVE_ANY_OP +#endif + +#undef __COPY4 +#define __COPY4(dst,src) * (lzo_uint32p)(dst) = * (const lzo_uint32p)(src) + +#undef COPY4 +#if defined(LZO_UNALIGNED_OK_4) +# define COPY4(dst,src) __COPY4(dst,src) +#elif defined(LZO_ALIGNED_OK_4) +# define COPY4(dst,src) __COPY4((lzo_uintptr_t)(dst),(lzo_uintptr_t)(src)) +#endif + +#if defined(DO_DECOMPRESS) +LZO_PUBLIC(int) +DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, + lzo_bytep out, lzo_uintp out_len, + lzo_voidp wrkmem ) +#endif +{ + register lzo_bytep op; + register const lzo_bytep ip; + register lzo_uint t; +#if defined(COPY_DICT) + lzo_uint m_off; + const lzo_bytep dict_end; +#else + register const lzo_bytep m_pos; +#endif + + const lzo_bytep const ip_end = in + in_len; +#if defined(HAVE_ANY_OP) + lzo_bytep const op_end = out + *out_len; +#endif +#if defined(LZO1Z) + lzo_uint last_m_off = 0; +#endif + + LZO_UNUSED(wrkmem); + +#if defined(COPY_DICT) + if (dict) + { + if (dict_len > M4_MAX_OFFSET) + { + dict += dict_len - M4_MAX_OFFSET; + dict_len = M4_MAX_OFFSET; + } + dict_end = dict + dict_len; + } + else + { + dict_len = 0; + dict_end = NULL; + } +#endif + + *out_len = 0; + + op = out; + ip = in; + + if (*ip > 17) + { + t = *ip++ - 17; + if (t < 4) + goto match_next; + assert(t > 0); NEED_OP(t); NEED_IP(t+1); + do *op++ = *ip++; while (--t > 0); + goto first_literal_run; + } + + while (TEST_IP && TEST_OP) + { + t = *ip++; + if (t >= 16) + goto match; + if (t == 0) + { + NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; + NEED_IP(1); + } + t += 15 + *ip++; + } + assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); +#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +#if !defined(LZO_UNALIGNED_OK_4) + if (PTR_ALIGNED2_4(op,ip)) + { +#endif + COPY4(op,ip); + op += 4; ip += 4; + if (--t > 0) + { + if (t >= 4) + { + do { + COPY4(op,ip); + op += 4; ip += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *ip++; while (--t > 0); + } + else + do *op++ = *ip++; while (--t > 0); + } +#if !defined(LZO_UNALIGNED_OK_4) + } + else +#endif +#endif +#if !defined(LZO_UNALIGNED_OK_4) + { + *op++ = *ip++; *op++ = *ip++; *op++ = *ip++; + do *op++ = *ip++; while (--t > 0); + } +#endif + +first_literal_run: + + t = *ip++; + if (t >= 16) + goto match; +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); + last_m_off = m_off; +#else + m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2); +#endif + NEED_OP(3); + t = 3; COPY_DICT(t,m_off) +#else +#if defined(LZO1Z) + t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); + m_pos = op - t; + last_m_off = t; +#else + m_pos = op - (1 + M2_MAX_OFFSET); + m_pos -= t >> 2; + m_pos -= *ip++ << 2; +#endif + TEST_LB(m_pos); NEED_OP(3); + *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos; +#endif + goto match_done; + + do { +match: + if (t >= 64) + { +#if defined(COPY_DICT) +#if defined(LZO1X) + m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3); + t = (t >> 5) - 1; +#elif defined(LZO1Y) + m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2); + t = (t >> 4) - 3; +#elif defined(LZO1Z) + m_off = t & 0x1f; + if (m_off >= 0x1c) + m_off = last_m_off; + else + { + m_off = 1 + (m_off << 6) + (*ip++ >> 2); + last_m_off = m_off; + } + t = (t >> 5) - 1; +#endif +#else +#if defined(LZO1X) + m_pos = op - 1; + m_pos -= (t >> 2) & 7; + m_pos -= *ip++ << 3; + t = (t >> 5) - 1; +#elif defined(LZO1Y) + m_pos = op - 1; + m_pos -= (t >> 2) & 3; + m_pos -= *ip++ << 2; + t = (t >> 4) - 3; +#elif defined(LZO1Z) + { + lzo_uint off = t & 0x1f; + m_pos = op; + if (off >= 0x1c) + { + assert(last_m_off > 0); + m_pos -= last_m_off; + } + else + { + off = 1 + (off << 6) + (*ip++ >> 2); + m_pos -= off; + last_m_off = off; + } + } + t = (t >> 5) - 1; +#endif + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); + goto copy_match; +#endif + } + else if (t >= 32) + { + t &= 31; + if (t == 0) + { + NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; + NEED_IP(1); + } + t += 31 + *ip++; + } +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off = 1 + (ip[0] << 6) + (ip[1] >> 2); + last_m_off = m_off; +#else + m_off = 1 + (ip[0] >> 2) + (ip[1] << 6); +#endif +#else +#if defined(LZO1Z) + { + lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2); + m_pos = op - off; + last_m_off = off; + } +#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) + m_pos = op - 1; + m_pos -= (* (const lzo_ushortp) ip) >> 2; +#else + m_pos = op - 1; + m_pos -= (ip[0] >> 2) + (ip[1] << 6); +#endif +#endif + ip += 2; + } + else if (t >= 16) + { +#if defined(COPY_DICT) + m_off = (t & 8) << 11; +#else + m_pos = op; + m_pos -= (t & 8) << 11; +#endif + t &= 7; + if (t == 0) + { + NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; + NEED_IP(1); + } + t += 7 + *ip++; + } +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off += (ip[0] << 6) + (ip[1] >> 2); +#else + m_off += (ip[0] >> 2) + (ip[1] << 6); +#endif + ip += 2; + if (m_off == 0) + goto eof_found; + m_off += 0x4000; +#if defined(LZO1Z) + last_m_off = m_off; +#endif +#else +#if defined(LZO1Z) + m_pos -= (ip[0] << 6) + (ip[1] >> 2); +#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) + m_pos -= (* (const lzo_ushortp) ip) >> 2; +#else + m_pos -= (ip[0] >> 2) + (ip[1] << 6); +#endif + ip += 2; + if (m_pos == op) + goto eof_found; + m_pos -= 0x4000; +#if defined(LZO1Z) + last_m_off = pd((const lzo_bytep)op, m_pos); +#endif +#endif + } + else + { +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off = 1 + (t << 6) + (*ip++ >> 2); + last_m_off = m_off; +#else + m_off = 1 + (t >> 2) + (*ip++ << 2); +#endif + NEED_OP(2); + t = 2; COPY_DICT(t,m_off) +#else +#if defined(LZO1Z) + t = 1 + (t << 6) + (*ip++ >> 2); + m_pos = op - t; + last_m_off = t; +#else + m_pos = op - 1; + m_pos -= t >> 2; + m_pos -= *ip++ << 2; +#endif + TEST_LB(m_pos); NEED_OP(2); + *op++ = *m_pos++; *op++ = *m_pos; +#endif + goto match_done; + } + +#if defined(COPY_DICT) + + NEED_OP(t+3-1); + t += 3-1; COPY_DICT(t,m_off) + +#else + + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); +#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +#if !defined(LZO_UNALIGNED_OK_4) + if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) + { + assert((op - m_pos) >= 4); +#else + if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) + { +#endif + COPY4(op,m_pos); + op += 4; m_pos += 4; t -= 4 - (3 - 1); + do { + COPY4(op,m_pos); + op += 4; m_pos += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *m_pos++; while (--t > 0); + } + else +#endif + { +copy_match: + *op++ = *m_pos++; *op++ = *m_pos++; + do *op++ = *m_pos++; while (--t > 0); + } + +#endif + +match_done: +#if defined(LZO1Z) + t = ip[-1] & 3; +#else + t = ip[-2] & 3; +#endif + if (t == 0) + break; + +match_next: + assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1); +#if 0 + do *op++ = *ip++; while (--t > 0); +#else + *op++ = *ip++; + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } +#endif + t = *ip++; + } while (TEST_IP && TEST_OP); + } + +#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) + *out_len = pd(op, out); + return LZO_E_EOF_NOT_FOUND; +#endif + +eof_found: + assert(t == 1); + *out_len = pd(op, out); + return (ip == ip_end ? LZO_E_OK : + (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); + +#if defined(HAVE_NEED_IP) +input_overrun: + *out_len = pd(op, out); + return LZO_E_INPUT_OVERRUN; +#endif + +#if defined(HAVE_NEED_OP) +output_overrun: + *out_len = pd(op, out); + return LZO_E_OUTPUT_OVERRUN; +#endif + +#if defined(LZO_TEST_OVERRUN_LOOKBEHIND) +lookbehind_overrun: + *out_len = pd(op, out); + return LZO_E_LOOKBEHIND_OVERRUN; +#endif +} + +#endif + +/***** End of minilzo.c *****/ + diff --git a/extern/lzo/minilzo/minilzo.h b/extern/lzo/minilzo/minilzo.h new file mode 100644 index 00000000000..93916bc89b2 --- /dev/null +++ b/extern/lzo/minilzo/minilzo.h @@ -0,0 +1,112 @@ +/* minilzo.h -- mini subset of the LZO real-time data compression library + + This file is part of the LZO real-time data compression library. + + Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer + All Rights Reserved. + + The LZO library 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. + + The LZO library 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 the LZO library; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Markus F.X.J. Oberhumer + + http://www.oberhumer.com/opensource/lzo/ + */ + +/* + * NOTE: + * the full LZO package can be found at + * http://www.oberhumer.com/opensource/lzo/ + */ + + +#ifndef __MINILZO_H +#define __MINILZO_H + +#define MINILZO_VERSION 0x2030 + +#ifdef __LZOCONF_H +# error "you cannot use both LZO and miniLZO" +#endif + +#undef LZO_HAVE_CONFIG_H +#include "lzoconf.h" + +#if !defined(LZO_VERSION) || (LZO_VERSION != MINILZO_VERSION) +# error "version mismatch in header files" +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*********************************************************************** +// +************************************************************************/ + +/* Memory required for the wrkmem parameter. + * When the required size is 0, you can also pass a NULL pointer. + */ + +#define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS +#define LZO1X_1_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t)) +#define LZO1X_MEM_DECOMPRESS (0) + + +/* compression */ +LZO_EXTERN(int) +lzo1x_1_compress ( const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem ); + +/* decompression */ +LZO_EXTERN(int) +lzo1x_decompress ( const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem /* NOT USED */ ); + +/* safe decompression with overrun testing */ +LZO_EXTERN(int) +lzo1x_decompress_safe ( const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem /* NOT USED */ ); + + +#define LZO_OUT_LEN(size) ((size) + (size) / 16 + 64 + 3) + +#define LZO_HEAP_ALLOC(var,size) \ + lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ] + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* already included */ + diff --git a/intern/smoke/extern/smoke_API.h b/intern/smoke/extern/smoke_API.h index f0dba3cc7a4..b21ce473202 100644 --- a/intern/smoke/extern/smoke_API.h +++ b/intern/smoke/extern/smoke_API.h @@ -20,7 +20,7 @@ * The Original Code is Copyright (C) 2009 by Daniel Genrich * All rights reserved. * - * Contributor(s): None + * Contributor(s): Daniel Genrich * * ***** END GPL LICENSE BLOCK ***** */ @@ -32,6 +32,10 @@ extern "C" { #endif +// export +void smoke_export(struct FLUID_3D *fluid, float *dt, float *dx, float **dens, float **densold, float **heat, float **heatold, float **vx, float **vy, float **vz, float **vxold, float **vyold, float **vzold, unsigned char **obstacles); + +// low res struct FLUID_3D *smoke_init(int *res, float *p0, float dt); void smoke_free(struct FLUID_3D *fluid); @@ -57,11 +61,14 @@ void smoke_turbulence_free(struct WTURBULENCE *wt); void smoke_turbulence_step(struct WTURBULENCE *wt, struct FLUID_3D *fluid); float *smoke_turbulence_get_density(struct WTURBULENCE *wt); -void smoke_turbulence_get_res(struct WTURBULENCE *wt, int *res); +void smoke_turbulence_get_res(struct WTURBULENCE *wt, unsigned int *res); void smoke_turbulence_set_noise(struct WTURBULENCE *wt, int type); -void smoke_initWaveletBlenderRNA(struct WTURBULENCE *wt, float *strength); +void smoke_turbulence_initBlenderRNA(struct WTURBULENCE *wt, float *strength); -void smoke_dissolve_wavelet(struct WTURBULENCE *wt, int speed, int log); +void smoke_turbulence_dissolve(struct WTURBULENCE *wt, int speed, int log); + +// export +void smoke_turbulence_export(struct WTURBULENCE *wt, float **dens, float **densold, float **tcu, float **tcv, float **tcw); #ifdef __cplusplus } diff --git a/intern/smoke/intern/FLUID_3D.cpp b/intern/smoke/intern/FLUID_3D.cpp index ff66f29143c..89dd893198b 100644 --- a/intern/smoke/intern/FLUID_3D.cpp +++ b/intern/smoke/intern/FLUID_3D.cpp @@ -75,8 +75,6 @@ FLUID_3D::FLUID_3D(int *res, float *p0, float dt) : // allocate arrays _totalCells = _xRes * _yRes * _zRes; _slabSize = _xRes * _yRes; - _divergence = new float[_totalCells]; - _pressure = new float[_totalCells]; _xVelocity = new float[_totalCells]; _yVelocity = new float[_totalCells]; _zVelocity = new float[_totalCells]; @@ -86,20 +84,11 @@ FLUID_3D::FLUID_3D(int *res, float *p0, float dt) : _xForce = new float[_totalCells]; _yForce = new float[_totalCells]; _zForce = new float[_totalCells]; - _vorticity = new float[_totalCells]; _density = new float[_totalCells]; _densityOld = new float[_totalCells]; _heat = new float[_totalCells]; _heatOld = new float[_totalCells]; - _residual = new float[_totalCells]; - _direction = new float[_totalCells]; - _q = new float[_totalCells]; - _obstacles = new unsigned char[_totalCells]; - _xVorticity = new float[_totalCells]; - _yVorticity = new float[_totalCells]; - _zVorticity = new float[_totalCells]; - _h = new float[_totalCells]; - _Precond = new float[_totalCells]; + _obstacles = new unsigned char[_totalCells]; // set 0 at end of step // DG TODO: check if alloc went fine @@ -109,8 +98,6 @@ FLUID_3D::FLUID_3D(int *res, float *p0, float dt) : _densityOld[x] = 0.0f; _heat[x] = 0.0f; _heatOld[x] = 0.0f; - _divergence[x] = 0.0f; - _pressure[x] = 0.0f; _xVelocity[x] = 0.0f; _yVelocity[x] = 0.0f; _zVelocity[x] = 0.0f; @@ -120,19 +107,11 @@ FLUID_3D::FLUID_3D(int *res, float *p0, float dt) : _xForce[x] = 0.0f; _yForce[x] = 0.0f; _zForce[x] = 0.0f; - _xVorticity[x] = 0.0f; - _yVorticity[x] = 0.0f; - _zVorticity[x] = 0.0f; - _residual[x] = 0.0f; - _q[x] = 0.0f; - _direction[x] = 0.0f; - _h[x] = 0.0f; - _Precond[x] = 0.0f; _obstacles[x] = false; } // set side obstacles - int index; + size_t index; for (int y = 0; y < _yRes; y++) // z for (int x = 0; x < _xRes; x++) { @@ -177,8 +156,6 @@ FLUID_3D::FLUID_3D(int *res, float *p0, float dt) : FLUID_3D::~FLUID_3D() { - if (_divergence) delete[] _divergence; - if (_pressure) delete[] _pressure; if (_xVelocity) delete[] _xVelocity; if (_yVelocity) delete[] _yVelocity; if (_zVelocity) delete[] _zVelocity; @@ -188,23 +165,14 @@ FLUID_3D::~FLUID_3D() if (_xForce) delete[] _xForce; if (_yForce) delete[] _yForce; if (_zForce) delete[] _zForce; - if (_residual) delete[] _residual; - if (_direction) delete[] _direction; - if (_q) delete[] _q; if (_density) delete[] _density; if (_densityOld) delete[] _densityOld; if (_heat) delete[] _heat; if (_heatOld) delete[] _heatOld; - if (_xVorticity) delete[] _xVorticity; - if (_yVorticity) delete[] _yVorticity; - if (_zVorticity) delete[] _zVorticity; - if (_vorticity) delete[] _vorticity; - if (_h) delete[] _h; - if (_Precond) delete[] _Precond; if (_obstacles) delete[] _obstacles; // if (_wTurbulence) delete _wTurbulence; - printf("deleted fluid\n"); + // printf("deleted fluid\n"); } // init direct access functions from blender @@ -263,6 +231,8 @@ void FLUID_3D::step() */ _totalTime += _dt; _totalSteps++; + + memset(_obstacles, 0, sizeof(unsigned char)*_xRes*_yRes*_zRes); } ////////////////////////////////////////////////////////////////////// @@ -300,7 +270,7 @@ void FLUID_3D::artificialDamping(float* field) { ////////////////////////////////////////////////////////////////////// void FLUID_3D::copyBorderAll(float* field) { - int index; + size_t index; for (int y = 0; y < _yRes; y++) for (int x = 0; x < _xRes; x++) { @@ -367,9 +337,16 @@ void FLUID_3D::addForce() ////////////////////////////////////////////////////////////////////// void FLUID_3D::project() { - int index, x, y, z; + int x, y, z; + size_t index; - setObstacleBoundaries(); + float *_pressure = new float[_totalCells]; + float *_divergence = new float[_totalCells]; + + memset(_pressure, 0, sizeof(float)*_totalCells); + memset(_divergence, 0, sizeof(float)*_totalCells); + + setObstacleBoundaries(_pressure); // copy out the boundaries if(DOMAIN_BC_LEFT == 0) setNeumannX(_xVelocity, _res); @@ -414,7 +391,7 @@ void FLUID_3D::project() // solve Poisson equation solvePressurePre(_pressure, _divergence, _obstacles); - setObstaclePressure(); + setObstaclePressure(_pressure); // project out solution float invDx = 1.0f / _dx; @@ -430,6 +407,9 @@ void FLUID_3D::project() _zVelocity[index] -= 0.5f * (_pressure[index + _slabSize] - _pressure[index - _slabSize]) * invDx; } } + + if (_pressure) delete[] _pressure; + if (_divergence) delete[] _divergence; } ////////////////////////////////////////////////////////////////////// @@ -465,7 +445,7 @@ void FLUID_3D::addObstacle(OBSTACLE* obstacle) ////////////////////////////////////////////////////////////////////// // calculate the obstacle directional types ////////////////////////////////////////////////////////////////////// -void FLUID_3D::setObstaclePressure() +void FLUID_3D::setObstaclePressure(float *_pressure) { // tag remaining obstacle blocks for (int z = 1, index = _slabSize + _xRes + 1; @@ -539,7 +519,7 @@ void FLUID_3D::setObstaclePressure() } } -void FLUID_3D::setObstacleBoundaries() +void FLUID_3D::setObstacleBoundaries(float *_pressure) { // cull degenerate obstacles , move to addObstacle? for (int z = 1, index = _slabSize + _xRes + 1; @@ -600,6 +580,18 @@ void FLUID_3D::addVorticity() int x,y,z,index; if(_vorticityEps<=0.) return; + float *_xVorticity, *_yVorticity, *_zVorticity, *_vorticity; + + _xVorticity = new float[_totalCells]; + _yVorticity = new float[_totalCells]; + _zVorticity = new float[_totalCells]; + _vorticity = new float[_totalCells]; + + memset(_xVorticity, 0, sizeof(float)*_totalCells); + memset(_yVorticity, 0, sizeof(float)*_totalCells); + memset(_zVorticity, 0, sizeof(float)*_totalCells); + memset(_vorticity, 0, sizeof(float)*_totalCells); + // calculate vorticity float gridSize = 0.5f / _dx; index = _slabSize + _xRes + 1; @@ -662,6 +654,11 @@ void FLUID_3D::addVorticity() _zForce[index] += (N[0] * _yVorticity[index] - N[1] * _xVorticity[index]) * _dx * eps; } } + + if (_xVorticity) delete[] _xVorticity; + if (_yVorticity) delete[] _yVorticity; + if (_zVorticity) delete[] _zVorticity; + if (_vorticity) delete[] _vorticity; } ////////////////////////////////////////////////////////////////////// diff --git a/intern/smoke/intern/FLUID_3D.h b/intern/smoke/intern/FLUID_3D.h index 78a4cf076e3..9d9e7318204 100644 --- a/intern/smoke/intern/FLUID_3D.h +++ b/intern/smoke/intern/FLUID_3D.h @@ -64,7 +64,7 @@ class FLUID_3D // dimensions int _xRes, _yRes, _zRes, _maxRes; Vec3Int _res; - int _totalCells; + size_t _totalCells; int _slabSize; float _dx; float _p0[3]; @@ -81,7 +81,6 @@ class FLUID_3D float* _densityOld; float* _heat; float* _heatOld; - float* _pressure; float* _xVelocity; float* _yVelocity; float* _zVelocity; @@ -91,19 +90,9 @@ class FLUID_3D float* _xForce; float* _yForce; float* _zForce; - float* _divergence; - float* _xVorticity; - float* _yVorticity; - float* _zVorticity; - float* _vorticity; - float* _h; - float* _Precond; unsigned char* _obstacles; // CG fields - float* _residual; - float* _direction; - float* _q; int _iterations; // simulation constants @@ -134,8 +123,8 @@ class FLUID_3D void solveHeat(float* field, float* b, unsigned char* skip); // handle obstacle boundaries - void setObstacleBoundaries(); - void setObstaclePressure(); + void setObstacleBoundaries(float *_pressure); + void setObstaclePressure(float *_pressure); public: // advection, accessed e.g. by WTURBULENCE class diff --git a/intern/smoke/intern/FLUID_3D_SOLVERS.cpp b/intern/smoke/intern/FLUID_3D_SOLVERS.cpp index a35beaa05d7..7d078d86d61 100644 --- a/intern/smoke/intern/FLUID_3D_SOLVERS.cpp +++ b/intern/smoke/intern/FLUID_3D_SOLVERS.cpp @@ -28,10 +28,17 @@ void FLUID_3D::solvePressurePre(float* field, float* b, unsigned char* skip) { int x, y, z; size_t index; + float *_q, *_Precond, *_h, *_residual, *_direction; // i = 0 int i = 0; + _residual = new float[_totalCells]; // set 0 + _direction = new float[_totalCells]; // set 0 + _q = new float[_totalCells]; // set 0 + _h = new float[_totalCells]; // set 0 + _Precond = new float[_totalCells]; // set 0 + memset(_residual, 0, sizeof(float)*_xRes*_yRes*_zRes); memset(_q, 0, sizeof(float)*_xRes*_yRes*_zRes); memset(_direction, 0, sizeof(float)*_xRes*_yRes*_zRes); @@ -191,11 +198,18 @@ void FLUID_3D::solvePressurePre(float* field, float* b, unsigned char* skip) i++; } // cout << i << " iterations converged to " << sqrt(maxR) << endl; + + if (_h) delete[] _h; + if (_Precond) delete[] _Precond; + if (_residual) delete[] _residual; + if (_direction) delete[] _direction; + if (_q) delete[] _q; } ////////////////////////////////////////////////////////////////////// // solve the poisson equation with CG ////////////////////////////////////////////////////////////////////// +#if 0 void FLUID_3D::solvePressure(float* field, float* b, unsigned char* skip) { int x, y, z; @@ -344,6 +358,7 @@ void FLUID_3D::solvePressure(float* field, float* b, unsigned char* skip) } // cout << i << " iterations converged to " << maxR << endl; } +#endif ////////////////////////////////////////////////////////////////////// // solve the heat equation with CG @@ -353,10 +368,15 @@ void FLUID_3D::solveHeat(float* field, float* b, unsigned char* skip) int x, y, z; size_t index; const float heatConst = _dt * _heatDiffusion / (_dx * _dx); + float *_q, *_residual, *_direction; // i = 0 int i = 0; + _residual = new float[_totalCells]; // set 0 + _direction = new float[_totalCells]; // set 0 + _q = new float[_totalCells]; // set 0 + memset(_residual, 0, sizeof(float)*_xRes*_yRes*_zRes); memset(_q, 0, sizeof(float)*_xRes*_yRes*_zRes); memset(_direction, 0, sizeof(float)*_xRes*_yRes*_zRes); @@ -496,5 +516,9 @@ void FLUID_3D::solveHeat(float* field, float* b, unsigned char* skip) i++; } // cout << i << " iterations converged to " << maxR << endl; + + if (_residual) delete[] _residual; + if (_direction) delete[] _direction; + if (_q) delete[] _q; } diff --git a/intern/smoke/intern/WTURBULENCE.cpp b/intern/smoke/intern/WTURBULENCE.cpp index db7a1b55afa..dd092d4f0cc 100644 --- a/intern/smoke/intern/WTURBULENCE.cpp +++ b/intern/smoke/intern/WTURBULENCE.cpp @@ -81,25 +81,9 @@ WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int no _densityBig = new float[_totalCellsBig]; _densityBigOld = new float[_totalCellsBig]; - // allocate high resolution velocity field. Note that this is only - // necessary because we use MacCormack advection. For semi-Lagrangian - // advection, these arrays are not necessary. - _tempBig1 = _tempBig2 = - _bigUx = _bigUy = _bigUz = NULL; - _tempBig1 = new float[_totalCellsBig]; - _tempBig2 = new float[_totalCellsBig]; - _bigUx = new float[_totalCellsBig]; - _bigUy = new float[_totalCellsBig]; - _bigUz = new float[_totalCellsBig]; - for(int i = 0; i < _totalCellsBig; i++) { _densityBig[i] = - _densityBigOld[i] = - _bigUx[i] = - _bigUy[i] = - _bigUz[i] = - _tempBig1[i] = - _tempBig2[i] = 0.; + _densityBigOld[i] = 0.; } // allocate & init texture coordinates @@ -154,12 +138,6 @@ WTURBULENCE::~WTURBULENCE() { delete[] _densityBig; delete[] _densityBigOld; - delete[] _bigUx; - delete[] _bigUy; - delete[] _bigUz; - delete[] _tempBig1; - delete[] _tempBig2; - delete[] _tcU; delete[] _tcV; delete[] _tcW; @@ -315,7 +293,7 @@ static float minDz(int x, int y, int z, float* input, Vec3Int res) // handle texture coordinates (advection, reset, eigenvalues), // Beware -- uses big density maccormack as temporary arrays ////////////////////////////////////////////////////////////////////// -void WTURBULENCE::advectTextureCoordinates (float dtOrg, float* xvel, float* yvel, float* zvel) { +void WTURBULENCE::advectTextureCoordinates (float dtOrg, float* xvel, float* yvel, float* zvel, float *_tempBig1, float *_tempBig2) { // advection SWAP_POINTERS(_tcTemp, _tcU); FLUID_3D::copyBorderX(_tcTemp, _resSm); @@ -602,12 +580,32 @@ Vec3 WTURBULENCE::WVelocityWithJacobian(Vec3 orgPos, float* xUnwarped, float* yU ////////////////////////////////////////////////////////////////////// void WTURBULENCE::stepTurbulenceReadable(float dtOrg, float* xvel, float* yvel, float* zvel, unsigned char *obstacles) { + // big velocity macCormack fields + float* _bigUx; + float* _bigUy; + float* _bigUz; + + // temp arrays for BFECC and MacCormack - they have more convenient + // names in the actual implementations + float* _tempBig1; + float* _tempBig2; + + // allocate high resolution velocity field. Note that this is only + // necessary because we use MacCormack advection. For semi-Lagrangian + // advection, these arrays are not necessary. + _tempBig1 = new float[_totalCellsBig]; + _tempBig2 = new float[_totalCellsBig]; + // enlarge timestep to match grid const float dt = dtOrg * _amplify; const float invAmp = 1.0f / _amplify; + _bigUx = new float[_totalCellsBig]; + _bigUy = new float[_totalCellsBig]; + _bigUz = new float[_totalCellsBig]; + // prepare textures - advectTextureCoordinates(dtOrg, xvel,yvel,zvel); + advectTextureCoordinates(dtOrg, xvel,yvel,zvel, _tempBig1, _tempBig2); // compute eigenvalues of the texture coordinates computeEigenvalues(); @@ -744,6 +742,13 @@ void WTURBULENCE::stepTurbulenceReadable(float dtOrg, float* xvel, float* yvel, IMAGE::dumpPBRT(_totalStepsBig, pbrtPrefix, _densityBig, _resBig[0],_resBig[1],_resBig[2]); */ _totalStepsBig++; + + delete[] _bigUx; + delete[] _bigUy; + delete[] _bigUz; + + delete[] _tempBig1; + delete[] _tempBig2; } ////////////////////////////////////////////////////////////////////// @@ -752,225 +757,257 @@ void WTURBULENCE::stepTurbulenceReadable(float dtOrg, float* xvel, float* yvel, ////////////////////////////////////////////////////////////////////// void WTURBULENCE::stepTurbulenceFull(float dtOrg, float* xvel, float* yvel, float* zvel, unsigned char *obstacles) { - // enlarge timestep to match grid - const float dt = dtOrg * _amplify; - const float invAmp = 1.0f / _amplify; + // big velocity macCormack fields + float* _bigUx; + float* _bigUy; + float* _bigUz; - // prepare textures - advectTextureCoordinates(dtOrg, xvel,yvel,zvel); + // temp arrays for BFECC and MacCormack - they have more convenient + // names in the actual implementations + float* _tempBig1; + float* _tempBig2; - // do wavelet decomposition of energy - computeEnergy(xvel, yvel, zvel, obstacles); - decomposeEnergy(); + // allocate high resolution velocity field. Note that this is only + // necessary because we use MacCormack advection. For semi-Lagrangian + // advection, these arrays are not necessary. + _tempBig1 = new float[_totalCellsBig]; + _tempBig2 = new float[_totalCellsBig]; - // zero out coefficients inside of the obstacle - for (int x = 0; x < _totalCellsSm; x++) - if (obstacles[x]) _energy[x] = 0.f; + // enlarge timestep to match grid + const float dt = dtOrg * _amplify; + const float invAmp = 1.0f / _amplify; - // parallel region setup - float maxVelMagThreads[8] = { -1., -1., -1., -1., -1., -1., -1., -1. }; -#if PARALLEL==1 -#pragma omp parallel -#endif - { float maxVelMag1 = 0.; -#if PARALLEL==1 - const int id = omp_get_thread_num(); /*, num = omp_get_num_threads(); */ -#endif + _bigUx = new float[_totalCellsBig]; + _bigUy = new float[_totalCellsBig]; + _bigUz = new float[_totalCellsBig]; - // vector noise main loop -#if PARALLEL==1 -#pragma omp for schedule(static) -#endif - for (int zSmall = 0; zSmall < _zResSm; zSmall++) - for (int ySmall = 0; ySmall < _yResSm; ySmall++) - for (int xSmall = 0; xSmall < _xResSm; xSmall++) - { - const int indexSmall = xSmall + ySmall * _xResSm + zSmall * _slabSizeSm; + // prepare textures + advectTextureCoordinates(dtOrg, xvel,yvel,zvel, _tempBig1, _tempBig2); - // compute jacobian - float jacobian[3][3] = { - { minDx(xSmall, ySmall, zSmall, _tcU, _resSm), minDx(xSmall, ySmall, zSmall, _tcV, _resSm), minDx(xSmall, ySmall, zSmall, _tcW, _resSm) } , - { minDy(xSmall, ySmall, zSmall, _tcU, _resSm), minDy(xSmall, ySmall, zSmall, _tcV, _resSm), minDy(xSmall, ySmall, zSmall, _tcW, _resSm) } , - { minDz(xSmall, ySmall, zSmall, _tcU, _resSm), minDz(xSmall, ySmall, zSmall, _tcV, _resSm), minDz(xSmall, ySmall, zSmall, _tcW, _resSm) } - }; + // do wavelet decomposition of energy + computeEnergy(xvel, yvel, zvel, obstacles); + decomposeEnergy(); - // get LU factorization of texture jacobian and apply - // it to unit vectors - JAMA::LU LU = computeLU3x3(jacobian); - float xUnwarped[] = {1.0f, 0.0f, 0.0f}; - float yUnwarped[] = {0.0f, 1.0f, 0.0f}; - float zUnwarped[] = {0.0f, 0.0f, 1.0f}; - float xWarped[] = {1.0f, 0.0f, 0.0f}; - float yWarped[] = {0.0f, 1.0f, 0.0f}; - float zWarped[] = {0.0f, 0.0f, 1.0f}; - bool nonSingular = LU.isNonsingular(); -#if 0 - // UNUSED - float eigMax = 10.0f; - float eigMin = 0.1f; -#endif - if (nonSingular) - { - solveLU3x3(LU, xUnwarped, xWarped); - solveLU3x3(LU, yUnwarped, yWarped); - solveLU3x3(LU, zUnwarped, zWarped); + // zero out coefficients inside of the obstacle + for (int x = 0; x < _totalCellsSm; x++) + if (obstacles[x]) _energy[x] = 0.f; - // compute the eigenvalues while we have the Jacobian available - Vec3 eigenvalues = Vec3(1.); - computeEigenvalues3x3( &eigenvalues[0], jacobian); - _eigMax[indexSmall] = MAX3V(eigenvalues); - _eigMin[indexSmall] = MIN3V(eigenvalues); - } - - // make sure to skip one on the beginning and end - int xStart = (xSmall == 0) ? 1 : 0; - int xEnd = (xSmall == _xResSm - 1) ? _amplify - 1 : _amplify; - int yStart = (ySmall == 0) ? 1 : 0; - int yEnd = (ySmall == _yResSm - 1) ? _amplify - 1 : _amplify; - int zStart = (zSmall == 0) ? 1 : 0; - int zEnd = (zSmall == _zResSm - 1) ? _amplify - 1 : _amplify; - - for (int zBig = zStart; zBig < zEnd; zBig++) - for (int yBig = yStart; yBig < yEnd; yBig++) - for (int xBig = xStart; xBig < xEnd; xBig++) - { - const int x = xSmall * _amplify + xBig; - const int y = ySmall * _amplify + yBig; - const int z = zSmall * _amplify + zBig; - - // get unit position for both fine and coarse grid - const Vec3 pos = Vec3(x,y,z); - const Vec3 posSm = pos * invAmp; - - // get grid index for both fine and coarse grid - const int index = x + y *_xResBig + z *_slabSizeBig; - - // get a linearly interpolated velocity and texcoords - // from the coarse grid - Vec3 vel = INTERPOLATE::lerp3dVec( xvel,yvel,zvel, - posSm[0], posSm[1], posSm[2], _xResSm,_yResSm,_zResSm); - Vec3 uvw = INTERPOLATE::lerp3dVec( _tcU,_tcV,_tcW, - posSm[0], posSm[1], posSm[2], _xResSm,_yResSm,_zResSm); + // parallel region setup + float maxVelMagThreads[8] = { -1., -1., -1., -1., -1., -1., -1., -1. }; - // multiply the texture coordinate by _resSm so that turbulence - // synthesis begins at the first octave that the coarse grid - // cannot capture - Vec3 texCoord = Vec3(uvw[0] * _resSm[0], - uvw[1] * _resSm[1], - uvw[2] * _resSm[2]); + #if PARALLEL==1 + #pragma omp parallel + #endif + { float maxVelMag1 = 0.; + #if PARALLEL==1 + const int id = omp_get_thread_num(); /*, num = omp_get_num_threads(); */ + #endif - // retrieve wavelet energy at highest frequency - float energy = INTERPOLATE::lerp3d( - _highFreqEnergy, posSm[0],posSm[1],posSm[2], _xResSm, _yResSm, _zResSm); + // vector noise main loop + #if PARALLEL==1 + #pragma omp for schedule(static) + #endif + for (int zSmall = 0; zSmall < _zResSm; zSmall++) + for (int ySmall = 0; ySmall < _yResSm; ySmall++) + for (int xSmall = 0; xSmall < _xResSm; xSmall++) + { + const int indexSmall = xSmall + ySmall * _xResSm + zSmall * _slabSizeSm; - // base amplitude for octave 0 - float coefficient = sqrtf(2.0f * fabs(energy)); - const float amplitude = *_strength * fabs(0.5 * coefficient) * persistence; + // compute jacobian + float jacobian[3][3] = { + { minDx(xSmall, ySmall, zSmall, _tcU, _resSm), minDx(xSmall, ySmall, zSmall, _tcV, _resSm), minDx(xSmall, ySmall, zSmall, _tcW, _resSm) } , + { minDy(xSmall, ySmall, zSmall, _tcU, _resSm), minDy(xSmall, ySmall, zSmall, _tcV, _resSm), minDy(xSmall, ySmall, zSmall, _tcW, _resSm) } , + { minDz(xSmall, ySmall, zSmall, _tcU, _resSm), minDz(xSmall, ySmall, zSmall, _tcV, _resSm), minDz(xSmall, ySmall, zSmall, _tcW, _resSm) } + }; - // add noise to velocity, but only if the turbulence is - // sufficiently undeformed, and the energy is large enough - // to make a difference - const bool addNoise = _eigMax[indexSmall] < 2. && - _eigMin[indexSmall] > 0.5; - if (addNoise && amplitude > _cullingThreshold) { - // base amplitude for octave 0 - float amplitudeScaled = amplitude; + // get LU factorization of texture jacobian and apply + // it to unit vectors + JAMA::LU LU = computeLU3x3(jacobian); + float xUnwarped[] = {1.0f, 0.0f, 0.0f}; + float yUnwarped[] = {0.0f, 1.0f, 0.0f}; + float zUnwarped[] = {0.0f, 0.0f, 1.0f}; + float xWarped[] = {1.0f, 0.0f, 0.0f}; + float yWarped[] = {0.0f, 1.0f, 0.0f}; + float zWarped[] = {0.0f, 0.0f, 1.0f}; + bool nonSingular = LU.isNonsingular(); - for (int octave = 0; octave < _octaves; octave++) - { - // multiply the vector noise times the maximum allowed - // noise amplitude at this octave, and add it to the total - vel += WVelocityWithJacobian(texCoord, &xUnwarped[0], &yUnwarped[0], &zUnwarped[0]) * amplitudeScaled; + #if 0 + // UNUSED + float eigMax = 10.0f; + float eigMin = 0.1f; + #endif - // scale coefficient for next octave - amplitudeScaled *= persistence; - texCoord *= 2.0f; - } - } + if (nonSingular) + { + solveLU3x3(LU, xUnwarped, xWarped); + solveLU3x3(LU, yUnwarped, yWarped); + solveLU3x3(LU, zUnwarped, zWarped); - // Store velocity + turbulence in big grid for maccormack step - // - // If you wanted to save memory, you would instead perform a - // semi-Lagrangian backtrace for the current grid cell here. Then - // you could just throw the velocity away. - _bigUx[index] = vel[0]; - _bigUy[index] = vel[1]; - _bigUz[index] = vel[2]; + // compute the eigenvalues while we have the Jacobian available + Vec3 eigenvalues = Vec3(1.); + computeEigenvalues3x3( &eigenvalues[0], jacobian); + _eigMax[indexSmall] = MAX3V(eigenvalues); + _eigMin[indexSmall] = MIN3V(eigenvalues); + } - // compute the velocity magnitude for substepping later - const float velMag = _bigUx[index] * _bigUx[index] + - _bigUy[index] * _bigUy[index] + - _bigUz[index] * _bigUz[index]; - if (velMag > maxVelMag1) maxVelMag1 = velMag; + // make sure to skip one on the beginning and end + int xStart = (xSmall == 0) ? 1 : 0; + int xEnd = (xSmall == _xResSm - 1) ? _amplify - 1 : _amplify; + int yStart = (ySmall == 0) ? 1 : 0; + int yEnd = (ySmall == _yResSm - 1) ? _amplify - 1 : _amplify; + int zStart = (zSmall == 0) ? 1 : 0; + int zEnd = (zSmall == _zResSm - 1) ? _amplify - 1 : _amplify; + + for (int zBig = zStart; zBig < zEnd; zBig++) + for (int yBig = yStart; yBig < yEnd; yBig++) + for (int xBig = xStart; xBig < xEnd; xBig++) + { + const int x = xSmall * _amplify + xBig; + const int y = ySmall * _amplify + yBig; + const int z = zSmall * _amplify + zBig; - // zero out velocity inside obstacles - float obsCheck = INTERPOLATE::lerp3dToFloat( - obstacles, posSm[0], posSm[1], posSm[2], _xResSm, _yResSm, _zResSm); - if (obsCheck > 0.95) - _bigUx[index] = _bigUy[index] = _bigUz[index] = 0.; - } // xyz + // get unit position for both fine and coarse grid + const Vec3 pos = Vec3(x,y,z); + const Vec3 posSm = pos * invAmp; -#if PARALLEL==1 - maxVelMagThreads[id] = maxVelMag1; -#else - maxVelMagThreads[0] = maxVelMag1; -#endif - } - } // omp - - // compute maximum over threads - float maxVelMag = maxVelMagThreads[0]; -#if PARALLEL==1 - for (int i = 1; i < 8; i++) - if (maxVelMag < maxVelMagThreads[i]) - maxVelMag = maxVelMagThreads[i]; -#endif + // get grid index for both fine and coarse grid + const int index = x + y *_xResBig + z *_slabSizeBig; - // prepare density for an advection - SWAP_POINTERS(_densityBig, _densityBigOld); + // get a linearly interpolated velocity and texcoords + // from the coarse grid + Vec3 vel = INTERPOLATE::lerp3dVec( xvel,yvel,zvel, + posSm[0], posSm[1], posSm[2], _xResSm,_yResSm,_zResSm); + Vec3 uvw = INTERPOLATE::lerp3dVec( _tcU,_tcV,_tcW, + posSm[0], posSm[1], posSm[2], _xResSm,_yResSm,_zResSm); - // based on the maximum velocity present, see if we need to substep, - // but cap the maximum number of substeps to 5 - const int maxSubSteps = 25; - const int maxVel = 5; - maxVelMag = sqrt(maxVelMag) * dt; - int totalSubsteps = (int)(maxVelMag / (float)maxVel); - totalSubsteps = (totalSubsteps < 1) ? 1 : totalSubsteps; - // printf("totalSubsteps: %d\n", totalSubsteps); - totalSubsteps = (totalSubsteps > maxSubSteps) ? maxSubSteps : totalSubsteps; - const float dtSubdiv = dt / (float)totalSubsteps; + // multiply the texture coordinate by _resSm so that turbulence + // synthesis begins at the first octave that the coarse grid + // cannot capture + Vec3 texCoord = Vec3(uvw[0] * _resSm[0], + uvw[1] * _resSm[1], + uvw[2] * _resSm[2]); - // set boundaries of big velocity grid - FLUID_3D::setZeroX(_bigUx, _resBig); - FLUID_3D::setZeroY(_bigUy, _resBig); - FLUID_3D::setZeroZ(_bigUz, _resBig); + // retrieve wavelet energy at highest frequency + float energy = INTERPOLATE::lerp3d( + _highFreqEnergy, posSm[0],posSm[1],posSm[2], _xResSm, _yResSm, _zResSm); - // do the MacCormack advection, with substepping if necessary - for(int substep = 0; substep < totalSubsteps; substep++) - { - FLUID_3D::advectFieldMacCormack(dtSubdiv, _bigUx, _bigUy, _bigUz, - _densityBigOld, _densityBig, _tempBig1, _tempBig2, _resBig, NULL); + // base amplitude for octave 0 + float coefficient = sqrtf(2.0f * fabs(energy)); + const float amplitude = *_strength * fabs(0.5 * coefficient) * persistence; - if (substep < totalSubsteps - 1) - SWAP_POINTERS(_densityBig, _densityBigOld); - } // substep - - // wipe the density borders - FLUID_3D::setZeroBorder(_densityBig, _resBig); - - // reset texture coordinates now in preparation for next timestep - // Shouldn't do this before generating the noise because then the - // eigenvalues stored do not reflect the underlying texture coordinates - resetTextureCoordinates(); - - // output files - // string prefix = string("./amplified.preview/density_bigxy_"); - // FLUID_3D::writeImageSliceXY(_densityBig, _resBig, _resBig[2]/2, prefix, _totalStepsBig, 1.0f); - //string df3prefix = string("./df3/density_big_"); - //IMAGE::dumpDF3(_totalStepsBig, df3prefix, _densityBig, _resBig[0],_resBig[1],_resBig[2]); - // string pbrtPrefix = string("./pbrt/density_big_"); - // IMAGE::dumpPBRT(_totalStepsBig, pbrtPrefix, _densityBig, _resBig[0],_resBig[1],_resBig[2]); - - _totalStepsBig++; + // add noise to velocity, but only if the turbulence is + // sufficiently undeformed, and the energy is large enough + // to make a difference + const bool addNoise = _eigMax[indexSmall] < 2. && + _eigMin[indexSmall] > 0.5; + + if (addNoise && amplitude > _cullingThreshold) { + // base amplitude for octave 0 + float amplitudeScaled = amplitude; + + for (int octave = 0; octave < _octaves; octave++) + { + // multiply the vector noise times the maximum allowed + // noise amplitude at this octave, and add it to the total + vel += WVelocityWithJacobian(texCoord, &xUnwarped[0], &yUnwarped[0], &zUnwarped[0]) * amplitudeScaled; + + // scale coefficient for next octave + amplitudeScaled *= persistence; + texCoord *= 2.0f; + } + } + + // Store velocity + turbulence in big grid for maccormack step + // + // If you wanted to save memory, you would instead perform a + // semi-Lagrangian backtrace for the current grid cell here. Then + // you could just throw the velocity away. + _bigUx[index] = vel[0]; + _bigUy[index] = vel[1]; + _bigUz[index] = vel[2]; + + // compute the velocity magnitude for substepping later + const float velMag = _bigUx[index] * _bigUx[index] + + _bigUy[index] * _bigUy[index] + + _bigUz[index] * _bigUz[index]; + if (velMag > maxVelMag1) maxVelMag1 = velMag; + + // zero out velocity inside obstacles + float obsCheck = INTERPOLATE::lerp3dToFloat( + obstacles, posSm[0], posSm[1], posSm[2], _xResSm, _yResSm, _zResSm); + + if (obsCheck > 0.95) + _bigUx[index] = _bigUy[index] = _bigUz[index] = 0.; + } // xyz + + #if PARALLEL==1 + maxVelMagThreads[id] = maxVelMag1; + #else + maxVelMagThreads[0] = maxVelMag1; + #endif + } + } // omp + + // compute maximum over threads + float maxVelMag = maxVelMagThreads[0]; + #if PARALLEL==1 + for (int i = 1; i < 8; i++) + if (maxVelMag < maxVelMagThreads[i]) + maxVelMag = maxVelMagThreads[i]; + #endif + + // prepare density for an advection + SWAP_POINTERS(_densityBig, _densityBigOld); + + // based on the maximum velocity present, see if we need to substep, + // but cap the maximum number of substeps to 5 + const int maxSubSteps = 25; + const int maxVel = 5; + maxVelMag = sqrt(maxVelMag) * dt; + int totalSubsteps = (int)(maxVelMag / (float)maxVel); + totalSubsteps = (totalSubsteps < 1) ? 1 : totalSubsteps; + // printf("totalSubsteps: %d\n", totalSubsteps); + totalSubsteps = (totalSubsteps > maxSubSteps) ? maxSubSteps : totalSubsteps; + const float dtSubdiv = dt / (float)totalSubsteps; + + // set boundaries of big velocity grid + FLUID_3D::setZeroX(_bigUx, _resBig); + FLUID_3D::setZeroY(_bigUy, _resBig); + FLUID_3D::setZeroZ(_bigUz, _resBig); + + // do the MacCormack advection, with substepping if necessary + for(int substep = 0; substep < totalSubsteps; substep++) + { + FLUID_3D::advectFieldMacCormack(dtSubdiv, _bigUx, _bigUy, _bigUz, + _densityBigOld, _densityBig, _tempBig1, _tempBig2, _resBig, NULL); + + if (substep < totalSubsteps - 1) + SWAP_POINTERS(_densityBig, _densityBigOld); + } // substep + + // wipe the density borders + FLUID_3D::setZeroBorder(_densityBig, _resBig); + + // reset texture coordinates now in preparation for next timestep + // Shouldn't do this before generating the noise because then the + // eigenvalues stored do not reflect the underlying texture coordinates + resetTextureCoordinates(); + + // output files + // string prefix = string("./amplified.preview/density_bigxy_"); + // FLUID_3D::writeImageSliceXY(_densityBig, _resBig, _resBig[2]/2, prefix, _totalStepsBig, 1.0f); + //string df3prefix = string("./df3/density_big_"); + //IMAGE::dumpDF3(_totalStepsBig, df3prefix, _densityBig, _resBig[0],_resBig[1],_resBig[2]); + // string pbrtPrefix = string("./pbrt/density_big_"); + // IMAGE::dumpPBRT(_totalStepsBig, pbrtPrefix, _densityBig, _resBig[0],_resBig[1],_resBig[2]); + + _totalStepsBig++; + + delete[] _bigUx; + delete[] _bigUy; + delete[] _bigUz; + + delete[] _tempBig1; + delete[] _tempBig2; } diff --git a/intern/smoke/intern/WTURBULENCE.h b/intern/smoke/intern/WTURBULENCE.h index d4e6b0c6a17..c21e002ad48 100644 --- a/intern/smoke/intern/WTURBULENCE.h +++ b/intern/smoke/intern/WTURBULENCE.h @@ -49,7 +49,7 @@ class WTURBULENCE void stepTurbulenceFull(float dt, float* xvel, float* yvel, float* zvel, unsigned char *obstacles); // texcoord functions - void advectTextureCoordinates(float dtOrg, float* xvel, float* yvel, float* zvel); + void advectTextureCoordinates (float dtOrg, float* xvel, float* yvel, float* zvel, float *_tempBig1, float *_tempBig2); void resetTextureCoordinates(); void computeEnergy(float* xvel, float* yvel, float* zvel, unsigned char *obstacles); @@ -73,7 +73,7 @@ class WTURBULENCE // is accessed on through rna gui float *_strength; - protected: + // protected: // enlargement factor from original velocity field / simulation // _Big = _amplify * _Sm int _amplify; @@ -111,26 +111,17 @@ class WTURBULENCE float* _densityBig; float* _densityBigOld; - // big velocity macCormack fields - float* _bigUx; - float* _bigUy; - float* _bigUz; - // temp arrays for BFECC and MacCormack - they have more convenient - // names in the actual implementations - float* _tempBig1; - float* _tempBig2; - // texture coordinates for noise float* _tcU; float* _tcV; float* _tcW; float* _tcTemp; - float* _eigMin; - float* _eigMax; + float* _eigMin; // no save -dg + float* _eigMax; // no save -dg // wavelet decomposition of velocity energies - float* _energy; + float* _energy; // no save -dg // noise data float* _noiseTile; @@ -140,7 +131,7 @@ class WTURBULENCE int _totalStepsBig; // highest frequency component of wavelet decomposition - float* _highFreqEnergy; + float* _highFreqEnergy; // no save -dg void computeEigenvalues(); void decomposeEnergy(); diff --git a/intern/smoke/intern/smoke_API.cpp b/intern/smoke/intern/smoke_API.cpp index 2e95a576eaf..5a016b51bbe 100644 --- a/intern/smoke/intern/smoke_API.cpp +++ b/intern/smoke/intern/smoke_API.cpp @@ -20,7 +20,7 @@ * The Original Code is Copyright (C) 2009 by Daniel Genrich * All rights reserved. * - * Contributor(s): None + * Contributor(s): Daniel Genrich * * ***** END GPL LICENSE BLOCK ***** */ @@ -137,7 +137,7 @@ extern "C" void smoke_dissolve(FLUID_3D *fluid, int speed, int log) } } -extern "C" void smoke_dissolve_wavelet(WTURBULENCE *wt, int speed, int log) +extern "C" void smoke_turbulence_dissolve(WTURBULENCE *wt, int speed, int log) { float *density = wt->getDensityBig(); Vec3Int r = wt->getResBig(); @@ -172,7 +172,7 @@ extern "C" void smoke_dissolve_wavelet(WTURBULENCE *wt, int speed, int log) } } -extern "C" void smoke_initWaveletBlenderRNA(WTURBULENCE *wt, float *strength) +extern "C" void smoke_turbulence_initBlenderRNA(WTURBULENCE *wt, float *strength) { wt->initBlenderRNA(strength); } @@ -181,6 +181,36 @@ template < class T > inline T ABS( T a ) { return (0 < a) ? a : -a ; } +extern "C" void smoke_export(FLUID_3D *fluid, float *dt, float *dx, float **dens, float **densold, float **heat, float **heatold, float **vx, float **vy, float **vz, float **vxold, float **vyold, float **vzold, unsigned char **obstacles) +{ + *dens = fluid->_density; + *densold = fluid->_densityOld; + *heat = fluid->_heat; + *heatold = fluid->_heatOld; + *vx = fluid->_xVelocity; + *vy = fluid->_yVelocity; + *vz = fluid->_zVelocity; + *vxold = fluid->_xVelocityOld; + *vyold = fluid->_yVelocityOld; + *vzold = fluid->_zVelocityOld; + *obstacles = fluid->_obstacles; + dt = &(fluid->_dt); + dx = &(fluid->_dx); + +} + +extern "C" void smoke_turbulence_export(WTURBULENCE *wt, float **dens, float **densold, float **tcu, float **tcv, float **tcw) +{ + if(!wt) + return; + + *dens = wt->_densityBig; + *densold = wt->_densityBigOld; + *tcu = wt->_tcU; + *tcv = wt->_tcV; + *tcw = wt->_tcW; +} + extern "C" float *smoke_get_density(FLUID_3D *fluid) { return fluid->_density; @@ -193,17 +223,17 @@ extern "C" float *smoke_get_heat(FLUID_3D *fluid) extern "C" float *smoke_get_velocity_x(FLUID_3D *fluid) { - return fluid->_xVorticity; + return fluid->_xVelocity; } extern "C" float *smoke_get_velocity_y(FLUID_3D *fluid) { - return fluid->_yVorticity; + return fluid->_yVelocity; } extern "C" float *smoke_get_velocity_z(FLUID_3D *fluid) { - return fluid->_zVorticity; + return fluid->_zVelocity; } extern "C" float *smoke_turbulence_get_density(WTURBULENCE *wt) @@ -211,14 +241,13 @@ extern "C" float *smoke_turbulence_get_density(WTURBULENCE *wt) return wt ? wt->getDensityBig() : NULL; } -extern "C" void smoke_turbulence_get_res(WTURBULENCE *wt, int *res) +extern "C" void smoke_turbulence_get_res(WTURBULENCE *wt, unsigned int *res) { if(wt) { - Vec3Int r = wt->getResBig(); - res[0] = r[0]; - res[1] = r[1]; - res[2] = r[2]; + res[0] = wt->_resBig[0]; + res[1] = wt->_resBig[1]; + res[2] = wt->_resBig[2]; } } diff --git a/release/ui/buttons_physics_smoke.py b/release/ui/buttons_physics_smoke.py index 7e2395216c0..d187e4c5901 100644 --- a/release/ui/buttons_physics_smoke.py +++ b/release/ui/buttons_physics_smoke.py @@ -1,6 +1,11 @@ import bpy +def smoke_panel_enabled_low(smd): + if smd.smoke_type == 'TYPE_DOMAIN': + return smd.domain.point_cache.baked==False + return True + class PhysicButtonsPanel(bpy.types.Panel): __space_type__ = "PROPERTIES" __region_type__ = "WINDOW" @@ -38,6 +43,8 @@ class PHYSICS_PT_smoke(PhysicButtonsPanel): split.itemL() if md: + + # layout.enabled = smoke_panel_enabled(md) layout.itemR(md, "smoke_type", expand=True) if md.smoke_type == 'TYPE_DOMAIN': @@ -49,13 +56,6 @@ class PHYSICS_PT_smoke(PhysicButtonsPanel): col = split.column() col.itemL(text="Resolution:") col.itemR(domain, "maxres", text="Divisions") - - col.itemL(text="Display:") - col.itemR(domain, "visibility", text="Resolution") - col.itemR(domain, "color", slider=True) - sub = col.column() - sub.active = domain.highres - sub.itemR(domain, "viewhighres") col = split.column() col.itemL(text="Behavior:") @@ -88,43 +88,7 @@ class PHYSICS_PT_smoke(PhysicButtonsPanel): #elif md.smoke_type == 'TYPE_COLL': # layout.itemS() - -class PHYSICS_PT_smoke_highres(PhysicButtonsPanel): - __label__ = "Smoke High Resolution" - __default_closed__ = True - - def poll(self, context): - md = context.smoke - if md: - return (md.smoke_type == 'TYPE_DOMAIN') - - return False - - def draw_header(self, context): - layout = self.layout - - high = context.smoke.domain_settings - - layout.itemR(high, "highres", text="") - - def draw(self, context): - layout = self.layout - - high = context.smoke.domain_settings - - layout.active = high.highres - - split = layout.split() - - col = split.column() - col.itemL(text="Resolution:") - col.itemR(high, "amplify", text="Divisions") - - sub = split.column() - sub.itemL(text="Noise Method:") - sub.row().itemR(high, "noise_type", text="") - sub.itemR(high, "strength") - + class PHYSICS_PT_smoke_groups(PhysicButtonsPanel): __label__ = "Smoke Groups" __default_closed__ = True @@ -153,7 +117,168 @@ class PHYSICS_PT_smoke_groups(PhysicButtonsPanel): col = split.column() col.itemL(text="Collision Group:") col.itemR(group, "coll_group", text="") + +class PHYSICS_PT_smoke_cache(PhysicButtonsPanel): + __label__ = "Smoke Cache" + __default_closed__ = True + + def poll(self, context): + md = context.smoke + if md: + return (md.smoke_type == 'TYPE_DOMAIN') + + return False + + def draw(self, context): + layout = self.layout + + md = context.smoke + + if md.smoke_type == 'TYPE_DOMAIN': + + domain = md.domain_settings + cache = domain.point_cache + + layout.set_context_pointer("PointCache", cache) + + row = layout.row() + row.template_list(cache, "point_cache_list", cache, "active_point_cache_index") + col = row.column(align=True) + col.itemO("ptcache.add_new", icon="ICON_ZOOMIN", text="") + col.itemO("ptcache.remove", icon="ICON_ZOOMOUT", text="") + + row = layout.row() + row.itemR(cache, "name") + + row = layout.row() + row.itemR(cache, "start_frame") + row.itemR(cache, "end_frame") + + row = layout.row() + + if cache.baked == True: + row.itemO("ptcache.free_bake", text="Free Bake") + else: + row.item_booleanO("ptcache.bake", "bake", True, text="Bake") + + subrow = row.row() + subrow.enabled = cache.frames_skipped or cache.outdated + subrow.itemO("ptcache.bake", "bake", False, text="Calculate to Current Frame") + + row = layout.row() + #row.enabled = smoke_panel_enabled(psys) + row.itemO("ptcache.bake_from_cache", text="Current Cache to Bake") + + row = layout.row() + #row.enabled = smoke_panel_enabled(psys) + + layout.itemL(text=cache.info) + + layout.itemS() + + row = layout.row() + row.itemO("ptcache.bake_all", "bake", True, text="Bake All Dynamics") + row.itemO("ptcache.free_bake_all", text="Free All Bakes") + layout.itemO("ptcache.bake_all", "bake", False, text="Update All Dynamics to current frame") + +class PHYSICS_PT_smoke_highres(PhysicButtonsPanel): + __label__ = "Smoke High Resolution" + __default_closed__ = True + + def poll(self, context): + md = context.smoke + if md: + return (md.smoke_type == 'TYPE_DOMAIN') + + return False + + def draw_header(self, context): + layout = self.layout + + high = context.smoke.domain_settings + + layout.itemR(high, "highres", text="") + + def draw(self, context): + layout = self.layout + + md = context.smoke_hr + + if md: + + split = layout.split() + + col = split.column() + col.itemL(text="Resolution:") + col.itemR(md, "amplify", text="Divisions") + + sub = split.column() + sub.itemL(text="Noise Method:") + sub.row().itemR(md, "noise_type", text="") + sub.itemR(md, "strength") + sub.itemR(md, "show_highres") + +class PHYSICS_PT_smoke_cache_highres(PhysicButtonsPanel): + __label__ = "Smoke Cache" + __default_closed__ = True + + def poll(self, context): + return (context.smoke_hr != None) + + def draw(self, context): + layout = self.layout + + md = context.smoke_hr + + if md: + + cache = md.point_cache + + layout.set_context_pointer("PointCache", cache) + + row = layout.row() + row.template_list(cache, "point_cache_list", cache, "active_point_cache_index") + col = row.column(align=True) + col.itemO("ptcache.add_new", icon="ICON_ZOOMIN", text="") + col.itemO("ptcache.remove", icon="ICON_ZOOMOUT", text="") + + row = layout.row() + row.itemR(cache, "name") + + row = layout.row() + row.itemR(cache, "start_frame") + row.itemR(cache, "end_frame") + + row = layout.row() + + if cache.baked == True: + row.itemO("ptcache.free_bake", text="Free Bake") + else: + row.item_booleanO("ptcache.bake", "bake", True, text="Bake") + + subrow = row.row() + subrow.enabled = cache.frames_skipped or cache.outdated + subrow.itemO("ptcache.bake", "bake", False, text="Calculate to Current Frame") + + row = layout.row() + #row.enabled = smoke_panel_enabled(psys) + row.itemO("ptcache.bake_from_cache", text="Current Cache to Bake") + + row = layout.row() + #row.enabled = smoke_panel_enabled(psys) + + layout.itemL(text=cache.info) + + layout.itemS() + + row = layout.row() + row.itemO("ptcache.bake_all", "bake", True, text="Bake All Dynamics") + row.itemO("ptcache.free_bake_all", text="Free All Bakes") + layout.itemO("ptcache.bake_all", "bake", False, text="Update All Dynamics to current frame") + bpy.types.register(PHYSICS_PT_smoke) -bpy.types.register(PHYSICS_PT_smoke_highres) +bpy.types.register(PHYSICS_PT_smoke_cache) bpy.types.register(PHYSICS_PT_smoke_groups) +#bpy.types.register(PHYSICS_PT_smoke_highres) +#bpy.types.register(PHYSICS_PT_smoke_cache_highres) diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h index 5d9dddfe30d..531487549da 100644 --- a/source/blender/blenkernel/BKE_pointcache.h +++ b/source/blender/blenkernel/BKE_pointcache.h @@ -60,8 +60,8 @@ #define PTCACHE_TYPE_SOFTBODY 0 #define PTCACHE_TYPE_PARTICLES 1 #define PTCACHE_TYPE_CLOTH 2 -#define PTCACHE_TYPE_SMOKE_DOMAIN_LOW 3 -#define PTCACHE_TYPE_SMOKE_DOMAIN_HIGH 4 +#define PTCACHE_TYPE_SMOKE_DOMAIN 3 +#define PTCACHE_TYPE_SMOKE_HIGHRES 4 /* PTCache read return code */ #define PTCACHE_READ_EXACT 1 @@ -158,7 +158,7 @@ void BKE_ptcache_make_particle_key(struct ParticleKey *key, int index, void **da void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb); void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys); void BKE_ptcache_id_from_cloth(PTCacheID *pid, struct Object *ob, struct ClothModifierData *clmd); -void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd, int num); +void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd); void BKE_ptcache_ids_from_object(struct ListBase *lb, struct Object *ob); diff --git a/source/blender/blenkernel/BKE_smoke.h b/source/blender/blenkernel/BKE_smoke.h index 8dc38640e9a..bd8581112f8 100644 --- a/source/blender/blenkernel/BKE_smoke.h +++ b/source/blender/blenkernel/BKE_smoke.h @@ -32,24 +32,17 @@ #ifndef BKE_SMOKE_H_ #define BKE_SMOKE_H_ +typedef int (*bresenham_callback) (float *input, int res[3], int *pixel, float *tRay); + void smokeModifier_do(struct SmokeModifierData *smd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, int useRenderParams, int isFinalCalc); void smokeModifier_free (struct SmokeModifierData *smd); void smokeModifier_reset(struct SmokeModifierData *smd); void smokeModifier_createType(struct SmokeModifierData *smd); -void smoke_set_tray(struct SmokeModifierData *smd, size_t index, float transparency); -float smoke_get_tray(struct SmokeModifierData *smd, size_t index); -float smoke_get_tvox(struct SmokeModifierData *smd, size_t index); -void smoke_set_tvox(struct SmokeModifierData *smd, size_t index, float tvox); +// high res modifier +void smokeHRModifier_do(struct SmokeHRModifierData *shrmd, struct Scene *scene, struct Object *ob, int useRenderParams, int isFinalCalc); +void smokeHRModifier_free(struct SmokeHRModifierData *shrmd); -void smoke_set_bigtray(struct SmokeModifierData *smd, size_t index, float transparency); -float smoke_get_bigtray(struct SmokeModifierData *smd, size_t index); -float smoke_get_bigtvox(struct SmokeModifierData *smd, size_t index); -void smoke_set_bigtvox(struct SmokeModifierData *smd, size_t index, float tvox); - -long long smoke_get_mem_req(int xres, int yres, int zres, int amplify); -void smoke_prepare_View(struct SmokeModifierData *smd, float *light); -void smoke_prepare_bigView(struct SmokeModifierData *smd, float *light); #endif /* BKE_SMOKE_H_ */ diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 8d1df98c5b4..17079205423 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -34,6 +34,8 @@ SET(INC ../nodes ../../../extern/glew/include ../gpu ../makesrna ../../../intern/smoke/extern ../../../intern/bsp/extern ../blenfont ../../../intern/audaspace/intern + ../../../extern/lzo/minilzo + ../../../extern/lzma ${ZLIB_INC} ) diff --git a/source/blender/blenkernel/SConscript b/source/blender/blenkernel/SConscript index fdc7782a0b1..0c7922de6ff 100644 --- a/source/blender/blenkernel/SConscript +++ b/source/blender/blenkernel/SConscript @@ -11,6 +11,8 @@ incs += ' #/extern/bullet2/src' incs += ' #/intern/opennl/extern #/intern/bsp/extern' incs += ' ../gpu #/extern/glew/include' incs += ' #/intern/smoke/extern' +incs += ' #/extern/lzo/minilzo' +incs += ' #/extern/lzma' incs += ' #/intern/audaspace/intern' incs += ' ' + env['BF_OPENGL_INC'] diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 53d1baa5c9c..1e2560bf809 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -5801,26 +5801,6 @@ static void smokeModifier_initData(ModifierData *md) smd->coll = NULL; smd->type = 0; smd->time = -1; - - /* - smd->fluid = NULL; - smd->maxres = 48; - smd->amplify = 4; - smd->omega = 0.5; - smd->time = 0; - smd->flags = 0; - smd->noise = MOD_SMOKE_NOISEWAVE; - smd->visibility = 1; - - // init 3dview buffer - smd->tvox = NULL; - smd->tray = NULL; - smd->tvoxbig = NULL; - smd->traybig = NULL; - smd->viewsettings = 0; - smd->bind = NULL; - smd->max_textures = 0; - */ } static void smokeModifier_freeData(ModifierData *md) @@ -5884,6 +5864,50 @@ static void smokeModifier_updateDepgraph( */ } + +/* Smoke High Resolution */ + +static void smokeHRModifier_initData(ModifierData *md) +{ + SmokeHRModifierData *shrmd = (SmokeHRModifierData*) md; + + shrmd->wt = NULL; + shrmd->time = -1; + shrmd->strength = 2.0f; + shrmd->amplify = 1; + shrmd->noise = MOD_SMOKE_NOISEWAVE; + shrmd->point_cache = BKE_ptcache_add(&shrmd->ptcaches); + shrmd->point_cache->flag |= PTCACHE_DISK_CACHE; + shrmd->point_cache->step = 1; +} + +static void smokeHRModifier_freeData(ModifierData *md) +{ + SmokeHRModifierData *shrmd = (SmokeHRModifierData*) md; + + smokeHRModifier_free (shrmd); +} + +static void smokeHRModifier_deformVerts( + ModifierData *md, Object *ob, DerivedMesh *derivedData, + float (*vertexCos)[3], int numVerts, int useRenderParams, int isFinalCalc) +{ + SmokeHRModifierData *shrmd = (SmokeHRModifierData*) md; + smokeHRModifier_do(shrmd, md->scene, ob, useRenderParams, isFinalCalc); +} + +static int smokeHRModifier_dependsOnTime(ModifierData *md) +{ + return 1; +} + +static void smokeHRModifier_updateDepgraph( + ModifierData *md, DagForest *forest, Scene *scene, Object *ob, + DagNode *obNode) +{ + ; +} + /* Cloth */ static void clothModifier_initData(ModifierData *md) @@ -8580,10 +8604,23 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type) mti->type = eModifierTypeType_OnlyDeform; mti->initData = smokeModifier_initData; mti->freeData = smokeModifier_freeData; - mti->flags = eModifierTypeFlag_AcceptsMesh; + mti->flags = eModifierTypeFlag_AcceptsMesh + | eModifierTypeFlag_UsesPointCache + | eModifierTypeFlag_Single; mti->deformVerts = smokeModifier_deformVerts; mti->dependsOnTime = smokeModifier_dependsOnTime; mti->updateDepgraph = smokeModifier_updateDepgraph; + + mti = INIT_TYPE(SmokeHR); + mti->type = eModifierTypeType_OnlyDeform; + mti->initData = smokeHRModifier_initData; + mti->freeData = smokeHRModifier_freeData; + mti->flags = eModifierTypeFlag_AcceptsMesh + | eModifierTypeFlag_UsesPointCache + | eModifierTypeFlag_Single; + mti->deformVerts = smokeHRModifier_deformVerts; + mti->dependsOnTime = smokeHRModifier_dependsOnTime; + mti->updateDepgraph = smokeHRModifier_updateDepgraph; mti = INIT_TYPE(Cloth); mti->type = eModifierTypeType_Nonconstructive; diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 09170d92866..ca27bde039b 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -59,7 +59,12 @@ #include "BLI_blenlib.h" +/* both in intern */ #include "smoke_API.h" +#include "minilzo.h" + +#include "LzmaLib.h" + /* needed for directory lookup */ #ifndef WIN32 @@ -469,43 +474,116 @@ void BKE_ptcache_id_from_particles(PTCacheID *pid, Object *ob, ParticleSystem *p pid->info_types= (1<domain; - if(sds->fluid) - { + if(sds->fluid) { return sds->res[0]*sds->res[1]*sds->res[2]; } else return 0; } +static int ptcache_totpoint_smoke_turbulence(void *smoke_v) +{ + SmokeHRModifierData *shrmd= (SmokeHRModifierData *)smoke_v; + + if(shrmd->wt) { + /* + unsigned int res[3]; + + smoke_turbulence_get_res(sds->wt, res); + return res[0]*res[1]*res[2]; + */ + return 0; + } + else + return 0; +} + // forward decleration static int ptcache_file_write(PTCacheFile *pf, void *f, size_t tot, int size); +static int ptcache_compress_write(PTCacheFile *pf, unsigned char *in, unsigned int in_len, unsigned char *out, int mode) +{ + int r; + unsigned char compressed; + LZO_HEAP_ALLOC(wrkmem, LZO1X_MEM_COMPRESS); + unsigned int out_len = LZO_OUT_LEN(in_len); + unsigned char *props = MEM_callocN(16*sizeof(char), "tmp"); + size_t sizeOfIt = 5; + + if(mode == 1) { + r = lzo1x_1_compress(in, (lzo_uint)in_len, out, (lzo_uint *)&out_len, wrkmem); + if (!(r == LZO_E_OK) || (out_len >= in_len)) + compressed = 0; + else + compressed = 1; + } + else if(mode == 2) { + + r = LzmaCompress(out, (size_t *)&out_len, in, in_len,//assume sizeof(char)==1.... + props, &sizeOfIt, 5, 1 << 24, 3, 0, 2, 32, 2); + + if(!(r == SZ_OK) || (out_len >= in_len)) + compressed = 0; + else + compressed = 2; + } + + ptcache_file_write(pf, &compressed, 1, sizeof(unsigned char)); + if(compressed) { + ptcache_file_write(pf, &out_len, 1, sizeof(unsigned int)); + ptcache_file_write(pf, out, out_len, sizeof(unsigned char)); + } + else + ptcache_file_write(pf, in, in_len, sizeof(unsigned char)); + + if(compressed == 2) + { + ptcache_file_write(pf, &sizeOfIt, 1, sizeof(unsigned int)); + ptcache_file_write(pf, props, sizeOfIt, sizeof(unsigned char)); + } + + MEM_freeN(props); + + return r; +} + static int ptcache_write_smoke(PTCacheFile *pf, void *smoke_v) { SmokeModifierData *smd= (SmokeModifierData *)smoke_v; SmokeDomainSettings *sds = smd->domain; - if(sds->fluid) - { + if(sds->fluid) { size_t res = sds->res[0]*sds->res[1]*sds->res[2]; - float *dens, *densold, *heat, *heatold, *vx, *vy, *vz; - - smoke_export(sds->fluid, &dens, &densold, &heat, &heatold, &vx, &vy, &vz); - - ptcache_file_write(pf, dens, res, sizeof(float)); - ptcache_file_write(pf, densold, res, sizeof(float)); - ptcache_file_write(pf, heat, res, sizeof(float)); - ptcache_file_write(pf, heatold, res, sizeof(float)); - ptcache_file_write(pf, vx, res, sizeof(float)); - ptcache_file_write(pf, vy, res, sizeof(float)); - ptcache_file_write(pf, vz, res, sizeof(float)); + float dt, dx, *dens, *densold, *heat, *heatold, *vx, *vy, *vz, *vxold, *vyold, *vzold; + unsigned char *obstacles; + unsigned int in_len = sizeof(float)*(unsigned int)res; + unsigned char *out = (unsigned char *)MEM_callocN(LZO_OUT_LEN(in_len)*4, "pointcache_lzo_buffer"); + int mode = res >= 1000000 ? 2 : 1; + + smoke_export(sds->fluid, &dt, &dx, &dens, &densold, &heat, &heatold, &vx, &vy, &vz, &vxold, &vyold, &vzold, &obstacles); + + ptcache_compress_write(pf, (unsigned char *)sds->view3d, in_len*4, out, mode); + ptcache_compress_write(pf, (unsigned char *)dens, in_len, out, mode); + ptcache_compress_write(pf, (unsigned char *)densold, in_len, out, mode); + ptcache_compress_write(pf, (unsigned char *)heat, in_len, out, mode); + ptcache_compress_write(pf, (unsigned char *)heatold, in_len, out, mode); + ptcache_compress_write(pf, (unsigned char *)vx, in_len, out, mode); + ptcache_compress_write(pf, (unsigned char *)vy, in_len, out, mode); + ptcache_compress_write(pf, (unsigned char *)vz, in_len, out, mode); + ptcache_compress_write(pf, (unsigned char *)vxold, in_len, out, mode); + ptcache_compress_write(pf, (unsigned char *)vyold, in_len, out, mode); + ptcache_compress_write(pf, (unsigned char *)vzold, in_len, out, mode); + ptcache_compress_write(pf, (unsigned char *)obstacles, (unsigned int)res, out, mode); + ptcache_file_write(pf, &dt, 1, sizeof(float)); + ptcache_file_write(pf, &dx, 1, sizeof(float)); + + MEM_freeN(out); return 1; } @@ -513,32 +591,134 @@ static int ptcache_write_smoke(PTCacheFile *pf, void *smoke_v) return 0; } +static int ptcache_write_smoke_turbulence(PTCacheFile *pf, void *smoke_v) +{ + SmokeModifierData *smd= (SmokeModifierData *)smoke_v; + SmokeDomainSettings *sds = smd->domain; + /* + if(sds->wt) { + unsigned int res_big[3]; + size_t res = sds->res[0]*sds->res[1]*sds->res[2]; + float *dens, *densold, *tcu, *tcv, *tcw; + unsigned int in_len = sizeof(float)*(unsigned int)res; + unsigned int in_len_big = sizeof(float) * (unsigned int)res_big; + unsigned char *out; + int mode; + + smoke_turbulence_get_res(sds->wt, res_big); + mode = res_big[0]*res_big[1]*res_big[2] >= 1000000 ? 2 : 1; + + smoke_turbulence_export(sds->wt, &dens, &densold, &tcu, &tcv, &tcw); + + out = (unsigned char *)MEM_callocN(LZO_OUT_LEN(in_len_big), "pointcache_lzo_buffer"); + + ptcache_compress_write(pf, (unsigned char *)dens, in_len_big, out, mode); + ptcache_compress_write(pf, (unsigned char *)densold, in_len_big, out, mode); + + MEM_freeN(out); + out = (unsigned char *)MEM_callocN(LZO_OUT_LEN(in_len), "pointcache_lzo_buffer"); + ptcache_compress_write(pf, (unsigned char *)tcu, in_len, out, mode); + ptcache_compress_write(pf, (unsigned char *)tcv, in_len, out, mode); + ptcache_compress_write(pf, (unsigned char *)tcw, in_len, out, mode); + MEM_freeN(out); + + return 1; + } +*/ + return 0; +} + // forward decleration static int ptcache_file_read(PTCacheFile *pf, void *f, size_t tot, int size); +static int ptcache_compress_read(PTCacheFile *pf, unsigned char *result, unsigned int len) +{ + int r; + unsigned char compressed = 0; + unsigned int in_len; + unsigned int out_len = len; + unsigned char *in; + unsigned char *props = MEM_callocN(16*sizeof(char), "tmp"); + size_t sizeOfIt = 5; + + ptcache_file_read(pf, &compressed, 1, sizeof(unsigned char)); + if(compressed) { + ptcache_file_read(pf, &in_len, 1, sizeof(unsigned int)); + in = (unsigned char *)MEM_callocN(sizeof(unsigned char)*in_len, "pointcache_compressed_buffer"); + ptcache_file_read(pf, in, in_len, sizeof(unsigned char)); + + if(compressed == 1) + r = lzo1x_decompress(in, (lzo_uint)in_len, result, (lzo_uint *)&out_len, NULL); + else if(compressed == 2) + { + size_t leni = in_len, leno = out_len; + ptcache_file_read(pf, &sizeOfIt, 1, sizeof(unsigned int)); + ptcache_file_read(pf, props, sizeOfIt, sizeof(unsigned char)); + r = LzmaUncompress(result, &leno, in, &leni, props, sizeOfIt); + } + + MEM_freeN(in); + } + else { + ptcache_file_read(pf, result, len, sizeof(unsigned char)); + } + + MEM_freeN(props); + + return r; +} + static void ptcache_read_smoke(PTCacheFile *pf, void *smoke_v) { SmokeModifierData *smd= (SmokeModifierData *)smoke_v; SmokeDomainSettings *sds = smd->domain; - if(sds->fluid) - { + if(sds->fluid) { size_t res = sds->res[0]*sds->res[1]*sds->res[2]; - float *dens, *densold, *heat, *heatold, *vx, *vy, *vz; + float dt, dx, *dens, *densold, *heat, *heatold, *vx, *vy, *vz, *vxold, *vyold, *vzold; + unsigned char *obstacles; + unsigned int out_len = (unsigned int)res * sizeof(float); - smoke_export(sds->fluid, &dens, &densold, &heat, &heatold, &vx, &vy, &vz); + smoke_export(sds->fluid, &dt, &dx, &dens, &densold, &heat, &heatold, &vx, &vy, &vz, &vxold, &vyold, &vzold, &obstacles); - ptcache_file_read(pf, dens, res, sizeof(float)); - ptcache_file_read(pf, densold, res, sizeof(float)); - ptcache_file_read(pf, heat, res, sizeof(float)); - ptcache_file_read(pf, heatold, res, sizeof(float)); - ptcache_file_read(pf, vx, res, sizeof(float)); - ptcache_file_read(pf, vy, res, sizeof(float)); - ptcache_file_read(pf, vz, res, sizeof(float)); - + ptcache_compress_read(pf, (unsigned char *)sds->view3d, out_len*4); + ptcache_compress_read(pf, (unsigned char*)dens, out_len); + ptcache_compress_read(pf, (unsigned char*)densold, out_len); + ptcache_compress_read(pf, (unsigned char*)heat, out_len); + ptcache_compress_read(pf, (unsigned char*)heatold, out_len); + ptcache_compress_read(pf, (unsigned char*)vx, out_len); + ptcache_compress_read(pf, (unsigned char*)vy, out_len); + ptcache_compress_read(pf, (unsigned char*)vz, out_len); + ptcache_compress_read(pf, (unsigned char*)vxold, out_len); + ptcache_compress_read(pf, (unsigned char*)vyold, out_len); + ptcache_compress_read(pf, (unsigned char*)vzold, out_len); + ptcache_compress_read(pf, (unsigned char*)obstacles, (unsigned int)res); + ptcache_file_read(pf, &dt, 1, sizeof(float)); + ptcache_file_read(pf, &dx, 1, sizeof(float)); } } -void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd, int num) + +static void ptcache_read_smoke_turbulence(PTCacheFile *pf, void *smoke_v) +{ + SmokeModifierData *smd= (SmokeModifierData *)smoke_v; + SmokeDomainSettings *sds = smd->domain; + /* + if(sds->fluid) { + unsigned int res[3]; + float *dens, *densold, *tcu, *tcv, *tcw; + unsigned int out_len = sizeof(float)*(unsigned int)res; + + smoke_turbulence_get_res(sds->wt, res); + + smoke_turbulence_export(sds->wt, &dens, &densold, &tcu, &tcv, &tcw); + + ptcache_compress_read(pf, (unsigned char*)dens, out_len); + + } + */ +} + +void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd) { SmokeDomainSettings *sds = smd->domain; @@ -547,24 +727,21 @@ void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeMo pid->ob= ob; pid->calldata= smd; - // if(num == 0) - pid->type= PTCACHE_TYPE_SMOKE_DOMAIN_LOW; - // else if(num == 1) - // pid->type= PTCACHE_TYPE_SMOKE_DOMAIN_HIGH; - + pid->type= PTCACHE_TYPE_SMOKE_DOMAIN; pid->stack_index= modifiers_indexInObject(ob, (ModifierData *)smd); pid->cache= sds->point_cache; pid->cache_ptr= &sds->point_cache; pid->ptcaches= &sds->ptcaches; - pid->totpoint= pid->totwrite= ptcache_totpoint_smoke; pid->write_elem= NULL; pid->read_elem= NULL; + pid->read_stream = ptcache_read_smoke; pid->write_stream = ptcache_write_smoke; + pid->interpolate_elem= NULL; pid->write_header= ptcache_write_basic_header; @@ -573,7 +750,6 @@ void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeMo pid->data_types= (1<info_types= 0; } -#endif // XXX smoke poitcache stuff breaks compiling void BKE_ptcache_id_from_cloth(PTCacheID *pid, Object *ob, ClothModifierData *clmd) { @@ -633,18 +809,15 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob) BKE_ptcache_id_from_cloth(pid, ob, (ClothModifierData*)md); BLI_addtail(lb, pid); } - /* - // enabled on next commit if(md->type == eModifierType_Smoke) { SmokeModifierData *smd = (SmokeModifierData *)md; if(smd->type & MOD_SMOKE_TYPE_DOMAIN) { pid= MEM_callocN(sizeof(PTCacheID), "PTCacheID"); - BKE_ptcache_id_from_smoke(pid, ob, (SmokeModifierData*)md, 0); + BKE_ptcache_id_from_smoke(pid, ob, (SmokeModifierData*)md); BLI_addtail(lb, pid); } } - */ } } @@ -1140,13 +1313,13 @@ int BKE_ptcache_read_cache(PTCacheID *pid, float cfra, float frs_sec) if(use_old) { if(pid->read_elem && ptcache_file_read(pf, (void*)old_data1, 1, old_elemsize)) pid->read_elem(i, pid->calldata, NULL, frs_sec, cfra, old_data1); - else + else if(pid->read_elem) { error = 1; break; } } else { if(pid->read_elem && (pm || ptcache_file_read_data(pf))) pid->read_elem(*index, pid->calldata, pm ? pm->cur : pf->cur, frs_sec, cfra1 ? (float)cfra1 : (float)cfrai, NULL); - else + else if(pid->read_elem) { error = 1; break; } } @@ -1185,7 +1358,7 @@ int BKE_ptcache_read_cache(PTCacheID *pid, float cfra, float frs_sec) else { error = 1; break; } } - else + else if(pid->read_elem) { error = 1; break; } } else { @@ -1197,7 +1370,7 @@ int BKE_ptcache_read_cache(PTCacheID *pid, float cfra, float frs_sec) else { error = 1; break; } } - else + else if(pid->read_elem) { error = 1; break; } } @@ -1639,8 +1812,11 @@ int BKE_ptcache_id_reset(Scene *scene, PTCacheID *pid, int mode) sbFreeSimulation(pid->calldata); else if(pid->type == PTCACHE_TYPE_PARTICLES) psys_reset(pid->calldata, PSYS_RESET_DEPSGRAPH); - else if(pid->type == PTCACHE_TYPE_SMOKE_DOMAIN_LOW) + else if(pid->type == PTCACHE_TYPE_SMOKE_DOMAIN) + { smokeModifier_reset(pid->calldata); + printf("reset PTCACHE_TYPE_SMOKE_DOMAIN\n"); + } } if(clear) BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0); @@ -1689,17 +1865,14 @@ int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode) BKE_ptcache_id_from_cloth(&pid, ob, (ClothModifierData*)md); reset |= BKE_ptcache_id_reset(scene, &pid, mode); } - /* - // enabled on next commit if(md->type == eModifierType_Smoke) { SmokeModifierData *smd = (SmokeModifierData *)md; if(smd->type & MOD_SMOKE_TYPE_DOMAIN) { - BKE_ptcache_id_from_smoke(&pid, ob, (SmokeModifierData*)md, 0); + BKE_ptcache_id_from_smoke(&pid, ob, (SmokeModifierData*)md); reset |= BKE_ptcache_id_reset(scene, &pid, mode); } } - */ } return reset; diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 22ea41276ff..6449ae10eee 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -54,10 +54,13 @@ #include "BKE_DerivedMesh.h" #include "BKE_modifier.h" #include "BKE_particle.h" +#include "BKE_pointcache.h" +#include "BKE_smoke.h" #include "BKE_utildefines.h" #include "DNA_customdata_types.h" #include "DNA_group_types.h" +#include "DNA_lamp_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" #include "DNA_modifier_types.h" @@ -120,9 +123,9 @@ struct DerivedMesh; struct SmokeModifierData; // forward declerations -static void get_cell(struct SmokeModifierData *smd, float *pos, int *cell, int correct); -static void get_bigcell(struct SmokeModifierData *smd, float *pos, int *cell, int correct); +void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int correct); void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *tris, int numfaces, int numtris, int **tridivs, float cell_len); +void smoke_prepare_View(SmokeModifierData *smd, float framenr, float *light, int have_light); #define TRI_UVOFFSET (1./4.) @@ -205,17 +208,18 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive // TODO: put in failsafe if res<=0 - dg // printf("res[0]: %d, res[1]: %d, res[2]: %d\n", smd->domain->res[0], smd->domain->res[1], smd->domain->res[2]); - // dt max is 0.1 smd->domain->fluid = smoke_init(smd->domain->res, smd->domain->p0, 0.1); - smd->domain->wt = smoke_turbulence_init(smd->domain->res, (smd->domain->flags & MOD_SMOKE_HIGHRES) ? (smd->domain->amplify + 1) : 0, smd->domain->noise); smd->time = scene->r.cfra; smd->domain->firstframe = smd->time; - - smoke_initBlenderRNA(smd->domain->fluid, &(smd->domain->alpha), &(smd->domain->beta)); - if(smd->domain->wt) - smoke_initWaveletBlenderRNA(smd->domain->wt, &(smd->domain->strength)); + if(!smd->domain->view3d) + { + // TVox is for transparency + smd->domain->view3d = MEM_callocN(sizeof(float)*smd->domain->res[0]*smd->domain->res[1]*smd->domain->res[2]*4, "Smoke_tVox"); + } + + smoke_initBlenderRNA(smd->domain->fluid, &(smd->domain->alpha), &(smd->domain->beta)); return 1; } @@ -256,7 +260,8 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive SmokeCollSettings *scs = smd->coll; MVert *mvert = dm->getVertArray(dm); MFace *mface = dm->getFaceArray(dm); - size_t i = 0, divs = 0; + size_t i = 0; + int divs = 0; int *tridivs = NULL; float cell_len = 1.0 / 50.0; // for res = 50 size_t newdivs = 0; @@ -507,27 +512,14 @@ void smokeModifier_freeDomain(SmokeModifierData *smd) if(smd->domain) { // free visualisation buffers - if(smd->domain->bind) - { - glDeleteTextures(smd->domain->max_textures, (GLuint *)smd->domain->bind); - MEM_freeN(smd->domain->bind); - } - smd->domain->max_textures = 0; // unnecessary but let's be sure - - if(smd->domain->tray) - MEM_freeN(smd->domain->tray); - if(smd->domain->tvox) - MEM_freeN(smd->domain->tvox); - if(smd->domain->traybig) - MEM_freeN(smd->domain->traybig); - if(smd->domain->tvoxbig) - MEM_freeN(smd->domain->tvoxbig); - + if(smd->domain->view3d) + MEM_freeN(smd->domain->view3d); + if(smd->domain->fluid) smoke_free(smd->domain->fluid); - if(smd->domain->wt) - smoke_turbulence_free(smd->domain->wt); + BKE_ptcache_free_list(&smd->domain->ptcaches); + smd->domain->point_cache = NULL; MEM_freeN(smd->domain); smd->domain = NULL; @@ -582,44 +574,24 @@ void smokeModifier_reset(struct SmokeModifierData *smd) { if(smd->domain) { - // free visualisation buffers - if(smd->domain->bind) - { - glDeleteTextures(smd->domain->max_textures, (GLuint *)smd->domain->bind); - MEM_freeN(smd->domain->bind); - smd->domain->bind = NULL; - } - smd->domain->max_textures = 0; - if(smd->domain->viewsettings < MOD_SMOKE_VIEW_USEBIG) - smd->domain->viewsettings = 0; - else - smd->domain->viewsettings = MOD_SMOKE_VIEW_USEBIG; + if(smd->domain->view3d) + MEM_freeN(smd->domain->view3d); + smd->domain->view3d = NULL; - if(smd->domain->tray) - MEM_freeN(smd->domain->tray); - if(smd->domain->tvox) - MEM_freeN(smd->domain->tvox); - if(smd->domain->traybig) - MEM_freeN(smd->domain->traybig); - if(smd->domain->tvoxbig) - MEM_freeN(smd->domain->tvoxbig); - - smd->domain->tvox = NULL; - smd->domain->tray = NULL; - smd->domain->tvoxbig = NULL; - smd->domain->traybig = NULL; + smd->domain->tex = NULL; if(smd->domain->fluid) { smoke_free(smd->domain->fluid); smd->domain->fluid = NULL; } - - if(smd->domain->wt) - { - smoke_turbulence_free(smd->domain->wt); - smd->domain->wt = NULL; - } + + smd->domain->point_cache->flag &= ~PTCACHE_SIMULATION_VALID; + smd->domain->point_cache->flag |= PTCACHE_OUTDATED; + smd->domain->point_cache->simframe= 0; + smd->domain->point_cache->last_exact= 0; + + printf("reset_domain\n"); } else if(smd->flow) { @@ -677,31 +649,24 @@ void smokeModifier_createType(struct SmokeModifierData *smd) smd->domain->smd = smd; + smd->domain->point_cache = BKE_ptcache_add(&smd->domain->ptcaches); + smd->domain->point_cache->flag |= PTCACHE_DISK_CACHE; + smd->domain->point_cache->step = 1; + /* set some standard values */ smd->domain->fluid = NULL; - smd->domain->wt = NULL; smd->domain->eff_group = NULL; smd->domain->fluid_group = NULL; smd->domain->coll_group = NULL; smd->domain->maxres = 32; - smd->domain->amplify = 1; - smd->domain->omega = 1.0; smd->domain->alpha = -0.001; smd->domain->beta = 0.1; smd->domain->flags = MOD_SMOKE_DISSOLVE_LOG; - smd->domain->strength = 2.0; - smd->domain->noise = MOD_SMOKE_NOISEWAVE; - smd->domain->visibility = 1; smd->domain->diss_speed = 5; // init 3dview buffer - smd->domain->tvox = NULL; - smd->domain->tray = NULL; - smd->domain->tvoxbig = NULL; - smd->domain->traybig = NULL; - smd->domain->viewsettings = 0; - smd->domain->bind = NULL; - smd->domain->max_textures = 0; + smd->domain->view3d = NULL; + smd->domain->tex = NULL; } else if(smd->type & MOD_SMOKE_TYPE_FLOW) { @@ -736,15 +701,15 @@ void smokeModifier_createType(struct SmokeModifierData *smd) } // forward declaration -void smoke_calc_transparency(struct SmokeModifierData *smd, float *light, int big); +void smoke_simulate_domain(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedMesh *dm); void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedMesh *dm, int useRenderParams, int isFinalCalc) { - if(scene->r.cfra >= smd->time) - smokeModifier_init(smd, ob, scene, dm); - if((smd->type & MOD_SMOKE_TYPE_FLOW)) { + if(scene->r.cfra >= smd->time) + smokeModifier_init(smd, ob, scene, dm); + if(scene->r.cfra > smd->time) { // XXX TODO @@ -764,6 +729,9 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM } else if(smd->type & MOD_SMOKE_TYPE_COLL) { + if(scene->r.cfra >= smd->time) + smokeModifier_init(smd, ob, scene, dm); + if(scene->r.cfra > smd->time) { // XXX TODO @@ -786,459 +754,484 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM } else if(smd->type & MOD_SMOKE_TYPE_DOMAIN) { + PointCache *cache; + PTCacheID pid; + float timescale; + int cache_result = 0; + int startframe, endframe, framenr; SmokeDomainSettings *sds = smd->domain; + float light[3] = {0.0,0.0,0.0}; + int have_lamp = 0; + + printf("smd->type & MOD_SMOKE_TYPE_DOMAIN\n"); + + framenr = scene->r.cfra; + + cache = sds->point_cache; + + BKE_ptcache_id_from_smoke(&pid, ob, smd); + BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, ×cale); + + /* handle continuous simulation with the play button */ + if(BKE_ptcache_get_continue_physics()) + { + cache->flag &= ~PTCACHE_SIMULATION_VALID; + cache->simframe= 0; + cache->last_exact= 0; + + smokeModifier_init(smd, ob, scene, dm); + + smoke_simulate_domain(smd, scene, ob, dm); + + return; + } - if(scene->r.cfra > smd->time) + if(framenr < startframe) { - GroupObject *go = NULL; - Base *base = NULL; - - tstart(); - - if(sds->flags & MOD_SMOKE_DISSOLVE) - { - smoke_dissolve(sds->fluid, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG); - - if(sds->wt) - smoke_dissolve_wavelet(sds->wt, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG); - } + cache->flag &= ~PTCACHE_SIMULATION_VALID; + cache->simframe= 0; + cache->last_exact= 0; - /* reset view for new frame */ - if(sds->viewsettings < MOD_SMOKE_VIEW_USEBIG) - sds->viewsettings = 0; - else - sds->viewsettings = MOD_SMOKE_VIEW_USEBIG; - - // do flows and fluids - if(1) - { - Object *otherobj = NULL; - ModifierData *md = NULL; - - if(sds->fluid_group) // we use groups since we have 2 domains - go = sds->fluid_group->gobject.first; - else - base = scene->base.first; - - while(base || go) - { - otherobj = NULL; - - if(sds->fluid_group) - { - if(go->ob) - otherobj = go->ob; - } - else - otherobj = base->object; - - if(!otherobj) - { - if(sds->fluid_group) - go = go->next; - else - base= base->next; - - continue; - } - - md = modifiers_findByType(otherobj, eModifierType_Smoke); - - // check for active smoke modifier - if(md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) - { - SmokeModifierData *smd2 = (SmokeModifierData *)md; - - // check for initialized smoke object - if((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) - { - // we got nice flow object - SmokeFlowSettings *sfs = smd2->flow; - - if(sfs->psys && sfs->psys->part && sfs->psys->part->type==PART_EMITTER) // is particle system selected - { - ParticleSystem *psys = sfs->psys; - ParticleSettings *part=psys->part; - ParticleData *pa = NULL; - int p = 0; - float *density = smoke_get_density(sds->fluid); - float *bigdensity = smoke_turbulence_get_density(sds->wt); - float *heat = smoke_get_heat(sds->fluid); - float *velocity_x = smoke_get_velocity_x(sds->fluid); - float *velocity_y = smoke_get_velocity_y(sds->fluid); - float *velocity_z = smoke_get_velocity_z(sds->fluid); - unsigned char *obstacle = smoke_get_obstacle(sds->fluid); - int bigres[3]; - - printf("found flow psys\n"); - - // mostly copied from particle code - for(p=0, pa=psys->particles; ptotpart; p++, pa++) - { - int cell[3]; - size_t i = 0; - size_t index = 0; - int badcell = 0; - - if(pa->alive == PARS_KILLED) continue; - else if(pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN)==0) continue; - else if(pa->alive == PARS_DEAD && (part->flag & PART_DIED)==0) continue; - else if(pa->flag & (PARS_UNEXIST+PARS_NO_DISP)) continue; - - // VECCOPY(pos, pa->state.co); - // Mat4MulVecfl (ob->imat, pos); - - // 1. get corresponding cell - get_cell(smd, pa->state.co, cell, 0); - - // check if cell is valid (in the domain boundary) - for(i = 0; i < 3; i++) - { - if((cell[i] > sds->res[i] - 1) || (cell[i] < 0)) - { - badcell = 1; - break; - } - } - - if(badcell) - continue; - - // 2. set cell values (heat, density and velocity) - index = smoke_get_index(cell[0], sds->res[0], cell[1], sds->res[1], cell[2]); - - if(!(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW) && !(obstacle[index] & 2)) // this is inflow - { - // heat[index] += sfs->temp * 0.1; - // density[index] += sfs->density * 0.1; - - heat[index] = sfs->temp; - density[index] = sfs->density; - - /* - velocity_x[index] = pa->state.vel[0]; - velocity_y[index] = pa->state.vel[1]; - velocity_z[index] = pa->state.vel[2]; - */ - obstacle[index] |= 2; - - // we need different handling for the high-res feature - if(bigdensity) - { - // init all surrounding cells according to amplification, too - int i, j, k; - - smoke_turbulence_get_res(smd->domain->wt, bigres); - - for(i = 0; i < smd->domain->amplify + 1; i++) - for(j = 0; j < smd->domain->amplify + 1; j++) - for(k = 0; k < smd->domain->amplify + 1; k++) - { - index = smoke_get_index((smd->domain->amplify + 1)* cell[0] + i, bigres[0], (smd->domain->amplify + 1)* cell[1] + j, bigres[1], (smd->domain->amplify + 1)* cell[2] + k); - bigdensity[index] = sfs->density; - } - } - } - else if(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW) // outflow - { - heat[index] = 0.f; - density[index] = 0.f; - velocity_x[index] = 0.f; - velocity_y[index] = 0.f; - velocity_z[index] = 0.f; - - // we need different handling for the high-res feature - if(bigdensity) - { - // init all surrounding cells according to amplification, too - int i, j, k; - - smoke_turbulence_get_res(smd->domain->wt, bigres); - - for(i = 0; i < smd->domain->amplify + 1; i++) - for(j = 0; j < smd->domain->amplify + 1; j++) - for(k = 0; k < smd->domain->amplify + 1; k++) - { - index = smoke_get_index((smd->domain->amplify + 1)* cell[0] + i, bigres[0], (smd->domain->amplify + 1)* cell[1] + j, bigres[1], (smd->domain->amplify + 1)* cell[2] + k); - bigdensity[index] = 0.f; - } - } - } - } - } - else - { - /* - for() - { - // no psys - BVHTreeNearest nearest; - - nearest.index = -1; - nearest.dist = FLT_MAX; - - BLI_bvhtree_find_nearest(sfs->bvh->tree, pco, &nearest, sfs->bvh->nearest_callback, sfs->bvh); - }*/ - } - } - } - - if(sds->fluid_group) - go = go->next; - else - base= base->next; - } - } - - // do effectors - /* - if(sds->eff_group) - { - for(go = sds->eff_group->gobject.first; go; go = go->next) - { - if(go->ob) - { - if(ob->pd) - { - - } - } - } - } - */ - - // do collisions - if(1) - { - Object *otherobj = NULL; - ModifierData *md = NULL; - - if(sds->coll_group) // we use groups since we have 2 domains - go = sds->coll_group->gobject.first; - else - base = scene->base.first; - - while(base || go) - { - otherobj = NULL; - - if(sds->coll_group) - { - if(go->ob) - otherobj = go->ob; - } - else - otherobj = base->object; - - if(!otherobj) - { - if(sds->coll_group) - go = go->next; - else - base= base->next; - - continue; - } - - md = modifiers_findByType(otherobj, eModifierType_Smoke); - - // check for active smoke modifier - if(md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) - { - SmokeModifierData *smd2 = (SmokeModifierData *)md; - - if((smd2->type & MOD_SMOKE_TYPE_COLL) && smd2->coll) - { - // we got nice collision object - SmokeCollSettings *scs = smd2->coll; - size_t i, j; - unsigned char *obstacles = smoke_get_obstacle(smd->domain->fluid); - - for(i = 0; i < scs->numpoints; i++) - { - int badcell = 0; - size_t index = 0; - int cell[3]; - - // 1. get corresponding cell - get_cell(smd, &scs->points[3 * i], cell, 0); - - // check if cell is valid (in the domain boundary) - for(j = 0; j < 3; j++) - if((cell[j] > sds->res[j] - 1) || (cell[j] < 0)) - { - badcell = 1; - break; - } - - if(badcell) - continue; - - // 2. set cell values (heat, density and velocity) - index = smoke_get_index(cell[0], sds->res[0], cell[1], sds->res[1], cell[2]); - - // printf("cell[0]: %d, cell[1]: %d, cell[2]: %d\n", cell[0], cell[1], cell[2]); - // printf("res[0]: %d, res[1]: %d, res[2]: %d, index: %d\n\n", sds->res[0], sds->res[1], sds->res[2], index); - - obstacles[index] = 1; - - // for moving gobstacles - /* - const LbmFloat maxVelVal = 0.1666; - const LbmFloat maxusqr = maxVelVal*maxVelVal*3. *1.5; - - LbmVec objvel = vec2L((mMOIVertices[n]-mMOIVerticesOld[n]) /dvec); { - const LbmFloat usqr = (objvel[0]*objvel[0]+objvel[1]*objvel[1]+objvel[2]*objvel[2])*1.5; - USQRMAXCHECK(usqr, objvel[0],objvel[1],objvel[2], mMaxVlen, mMxvx,mMxvy,mMxvz); - if(usqr>maxusqr) { - // cutoff at maxVelVal - for(int jj=0; jj<3; jj++) { - if(objvel[jj]>0.) objvel[jj] = maxVelVal; - if(objvel[jj]<0.) objvel[jj] = -maxVelVal; - } - } } - - const LbmFloat dp=dot(objvel, vec2L((*pNormals)[n]) ); - const LbmVec oldov=objvel; // debug - objvel = vec2L((*pNormals)[n]) *dp; - */ - } - } - } - - if(sds->coll_group) - go = go->next; - else - base= base->next; - } - } - - // set new time - smd->time = scene->r.cfra; - - // simulate the actual smoke (c++ code in intern/smoke) - smoke_step(sds->fluid, smd->time); - if(sds->wt) - smoke_turbulence_step(sds->wt, sds->fluid); - - tend(); - printf ( "Frame: %d, Time: %f\n", (int)smd->time, ( float ) tval() ); - } - else if(scene->r.cfra < smd->time) - { // we got back in time, reset smoke in this case (TODO: use cache later) - smd->time = scene->r.cfra; - smokeModifier_reset(smd); + // smd->time = scene->r.cfra; + // smokeModifier_reset(smd); + + return; } + else if(framenr > endframe) + { + framenr = endframe; + } + + if(!(cache->flag & PTCACHE_SIMULATION_VALID)) + { + // printf("reseting\n"); + BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED); + } + + smokeModifier_init(smd, ob, scene, dm); + + /* try to read from cache */ + cache_result = BKE_ptcache_read_cache(&pid, (float)framenr, scene->r.frs_sec); + printf("cache_result: %d\n", cache_result); + + if(cache_result == PTCACHE_READ_EXACT) + { + SmokeDomainSettings *sds = smd->domain; + + cache->flag |= PTCACHE_SIMULATION_VALID; + cache->simframe= framenr; + sds->v3dnum = framenr; + + // printf("PTCACHE_READ_EXACT\n"); + return; + } + else if(cache_result==PTCACHE_READ_OLD) + { + BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_FREE); + + // printf("PTCACHE_READ_OLD\n"); + + cache->flag |= PTCACHE_SIMULATION_VALID; + } + else if(ob->id.lib || (cache->flag & PTCACHE_BAKED)) + { + /* if baked and nothing in cache, do nothing */ + cache->flag &= ~PTCACHE_SIMULATION_VALID; + cache->simframe= 0; + cache->last_exact= 0; + + // printf("PTCACHE_BAKED\n"); + return; + } + else if((cache_result==0) && (startframe!=framenr) && !(cache->flag & PTCACHE_SIMULATION_VALID)) + { + cache->flag &= ~PTCACHE_SIMULATION_VALID; + cache->simframe= 0; + cache->last_exact= 0; + + return; + } + + /* do simulation */ + + // low res + cache->flag |= PTCACHE_SIMULATION_VALID; + cache->simframe= framenr; + + smoke_simulate_domain(smd, scene, ob, dm); + + { + // float light[3] = {0.0,0.0,0.0}; // TODO: take real LAMP coordinates - dg + Base *base_tmp = NULL; + + for(base_tmp = scene->base.first; base_tmp; base_tmp= base_tmp->next) + { + if(base_tmp->object->type == OB_LAMP) + { + Lamp *la = (Lamp *)base_tmp->object->data; + + if(la->type == LA_LOCAL) + { + VECCOPY(light, base_tmp->object->obmat[3]); + have_lamp = 1; + break; + } + } + } + } + + smoke_prepare_View(smd, (float)framenr, light, have_lamp); + + BKE_ptcache_write_cache(&pid, framenr); + + printf("Writing cache_low\n"); + + + tend(); + printf ( "Frame: %d, Time: %f\n", (int)smd->time, ( float ) tval() ); } } +void smoke_simulate_domain(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedMesh *dm) +{ + GroupObject *go = NULL; + Base *base = NULL; + SmokeDomainSettings *sds = smd->domain; + + tstart(); + + if(sds->flags & MOD_SMOKE_DISSOLVE) + smoke_dissolve(sds->fluid, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG); + + // do flows and fluids + if(1) + { + Object *otherobj = NULL; + ModifierData *md = NULL; + + if(sds->fluid_group) // we use groups since we have 2 domains + go = sds->fluid_group->gobject.first; + else + base = scene->base.first; + + while(base || go) + { + otherobj = NULL; + + if(sds->fluid_group) + { + if(go->ob) + otherobj = go->ob; + } + else + otherobj = base->object; + + if(!otherobj) + { + if(sds->fluid_group) + go = go->next; + else + base= base->next; + + continue; + } + + md = modifiers_findByType(otherobj, eModifierType_Smoke); + + // check for active smoke modifier + if(md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) + { + SmokeModifierData *smd2 = (SmokeModifierData *)md; + + // check for initialized smoke object + if((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) + { + // we got nice flow object + SmokeFlowSettings *sfs = smd2->flow; + + if(sfs->psys && sfs->psys->part && sfs->psys->part->type==PART_EMITTER) // is particle system selected + { + ParticleSystem *psys = sfs->psys; + ParticleSettings *part=psys->part; + ParticleData *pa = NULL; + int p = 0; + float *density = smoke_get_density(sds->fluid); + // float *bigdensity = smoke_turbulence_get_density(sds->wt); + float *heat = smoke_get_heat(sds->fluid); + float *velocity_x = smoke_get_velocity_x(sds->fluid); + float *velocity_y = smoke_get_velocity_y(sds->fluid); + float *velocity_z = smoke_get_velocity_z(sds->fluid); + unsigned char *obstacle = smoke_get_obstacle(sds->fluid); + + // debug printf("found flow psys\n"); + + // mostly copied from particle code + for(p=0, pa=psys->particles; ptotpart; p++, pa++) + { + int cell[3]; + size_t i = 0; + size_t index = 0; + int badcell = 0; + + if(pa->alive == PARS_KILLED) continue; + else if(pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN)==0) continue; + else if(pa->alive == PARS_DEAD && (part->flag & PART_DIED)==0) continue; + else if(pa->flag & (PARS_UNEXIST+PARS_NO_DISP)) continue; + + // VECCOPY(pos, pa->state.co); + // Mat4MulVecfl (ob->imat, pos); + + // 1. get corresponding cell + get_cell(sds->p0, sds->res, sds->dx, pa->state.co, cell, 0); + + // check if cell is valid (in the domain boundary) + for(i = 0; i < 3; i++) + { + if((cell[i] > sds->res[i] - 1) || (cell[i] < 0)) + { + badcell = 1; + break; + } + } + + if(badcell) + continue; + + // 2. set cell values (heat, density and velocity) + index = smoke_get_index(cell[0], sds->res[0], cell[1], sds->res[1], cell[2]); + + if(!(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW) && !(obstacle[index] & 2)) // this is inflow + { + // heat[index] += sfs->temp * 0.1; + // density[index] += sfs->density * 0.1; + + heat[index] = sfs->temp; + density[index] = sfs->density; + + /* + velocity_x[index] = pa->state.vel[0]; + velocity_y[index] = pa->state.vel[1]; + velocity_z[index] = pa->state.vel[2]; + */ + obstacle[index] |= 2; + } + else if(sfs->type & MOD_SMOKE_FLOW_TYPE_OUTFLOW) // outflow + { + heat[index] = 0.f; + density[index] = 0.f; + velocity_x[index] = 0.f; + velocity_y[index] = 0.f; + velocity_z[index] = 0.f; + } + } + } + else + { + /* + for() + { + // no psys + BVHTreeNearest nearest; + + nearest.index = -1; + nearest.dist = FLT_MAX; + + BLI_bvhtree_find_nearest(sfs->bvh->tree, pco, &nearest, sfs->bvh->nearest_callback, sfs->bvh); + }*/ + } + } + } + + if(sds->fluid_group) + go = go->next; + else + base= base->next; + } + } + + // do effectors + /* + if(sds->eff_group) + { + for(go = sds->eff_group->gobject.first; go; go = go->next) + { + if(go->ob) + { + if(ob->pd) + { + + } + } + } + } + */ + + // do collisions + if(1) + { + Object *otherobj = NULL; + ModifierData *md = NULL; + + if(sds->coll_group) // we use groups since we have 2 domains + go = sds->coll_group->gobject.first; + else + base = scene->base.first; + + while(base || go) + { + otherobj = NULL; + + if(sds->coll_group) + { + if(go->ob) + otherobj = go->ob; + } + else + otherobj = base->object; + + if(!otherobj) + { + if(sds->coll_group) + go = go->next; + else + base= base->next; + + continue; + } + + md = modifiers_findByType(otherobj, eModifierType_Smoke); + + // check for active smoke modifier + if(md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) + { + SmokeModifierData *smd2 = (SmokeModifierData *)md; + + if((smd2->type & MOD_SMOKE_TYPE_COLL) && smd2->coll) + { + // we got nice collision object + SmokeCollSettings *scs = smd2->coll; + size_t i, j; + unsigned char *obstacles = smoke_get_obstacle(smd->domain->fluid); + + for(i = 0; i < scs->numpoints; i++) + { + int badcell = 0; + size_t index = 0; + int cell[3]; + + // 1. get corresponding cell + get_cell(sds->p0, sds->res, sds->dx, &scs->points[3 * i], cell, 0); + + // check if cell is valid (in the domain boundary) + for(j = 0; j < 3; j++) + if((cell[j] > sds->res[j] - 1) || (cell[j] < 0)) + { + badcell = 1; + break; + } + + if(badcell) + continue; + + // 2. set cell values (heat, density and velocity) + index = smoke_get_index(cell[0], sds->res[0], cell[1], sds->res[1], cell[2]); + + // printf("cell[0]: %d, cell[1]: %d, cell[2]: %d\n", cell[0], cell[1], cell[2]); + // printf("res[0]: %d, res[1]: %d, res[2]: %d, index: %d\n\n", sds->res[0], sds->res[1], sds->res[2], index); + + obstacles[index] = 1; + + // for moving gobstacles + /* + const LbmFloat maxVelVal = 0.1666; + const LbmFloat maxusqr = maxVelVal*maxVelVal*3. *1.5; + + LbmVec objvel = vec2L((mMOIVertices[n]-mMOIVerticesOld[n]) /dvec); { + const LbmFloat usqr = (objvel[0]*objvel[0]+objvel[1]*objvel[1]+objvel[2]*objvel[2])*1.5; + USQRMAXCHECK(usqr, objvel[0],objvel[1],objvel[2], mMaxVlen, mMxvx,mMxvy,mMxvz); + if(usqr>maxusqr) { + // cutoff at maxVelVal + for(int jj=0; jj<3; jj++) { + if(objvel[jj]>0.) objvel[jj] = maxVelVal; + if(objvel[jj]<0.) objvel[jj] = -maxVelVal; + } + } } + + const LbmFloat dp=dot(objvel, vec2L((*pNormals)[n]) ); + const LbmVec oldov=objvel; // debug + objvel = vec2L((*pNormals)[n]) *dp; + */ + } + } + } + + if(sds->coll_group) + go = go->next; + else + base= base->next; + } + } + + // set new time + smd->time = scene->r.cfra; + + // simulate the actual smoke (c++ code in intern/smoke) + smoke_step(sds->fluid, smd->time); +} + +static int calc_voxel_transp(float *input, int res[3], int *pixel, float *tRay) +{ + const size_t index = smoke_get_index(pixel[0], res[0], pixel[1], res[1], pixel[2]); + + // T_ray *= T_vox + *tRay *= input[index*4]; + + return *tRay; +} + +// forward decleration +void smoke_calc_transparency(float *result, float *p0, float *p1, int res[3], float dx, float *light, bresenham_callback cb); + // update necessary information for 3dview -void smoke_prepare_View(SmokeModifierData *smd, float *light) +void smoke_prepare_View(SmokeModifierData *smd, float framenr, float *light, int have_light) { float *density = NULL; int x, y, z; - - if(!smd->domain->tray) - { - // TRay is for self shadowing - smd->domain->tray = MEM_callocN(sizeof(float)*smd->domain->res[0]*smd->domain->res[1]*smd->domain->res[2], "Smoke_tRay"); - } - if(!smd->domain->tvox) - { - // TVox is for tranaparency - smd->domain->tvox = MEM_callocN(sizeof(float)*smd->domain->res[0]*smd->domain->res[1]*smd->domain->res[2], "Smoke_tVox"); - } + size_t cells, i; + SmokeDomainSettings *sds = smd->domain; // update 3dview density = smoke_get_density(smd->domain->fluid); for(x = 0; x < smd->domain->res[0]; x++) - for(y = 0; y < smd->domain->res[1]; y++) - for(z = 0; z < smd->domain->res[2]; z++) - { - size_t index; + for(y = 0; y < smd->domain->res[1]; y++) + for(z = 0; z < smd->domain->res[2]; z++) + { + size_t index; - index = smoke_get_index(x, smd->domain->res[0], y, smd->domain->res[1], z); - // Transparency computation - // formula taken from "Visual Simulation of Smoke" / Fedkiw et al. pg. 4 - // T_vox = exp(-C_ext * h) - // C_ext/sigma_t = density * C_ext - smoke_set_tvox(smd, index, exp(-density[index] * 7.0 * smd->domain->dx)); - } - smoke_calc_transparency(smd, light, 0); -} + index = smoke_get_index(x, smd->domain->res[0], y, smd->domain->res[1], z); + // Transparency computation + // formula taken from "Visual Simulation of Smoke" / Fedkiw et al. pg. 4 + // T_vox = exp(-C_ext * h) + // C_ext/sigma_t = density * C_ext + smd->domain->view3d[index * 4] = smd->domain->view3d[index * 4 + 1] = + smd->domain->view3d[index * 4 + 2] = exp(-density[index] * 7.0 * smd->domain->dx); + smd->domain->view3d[index * 4 + 3] = 1.0 - smd->domain->view3d[index * 4]; + + } -// update necessary information for 3dview ("high res" option) -void smoke_prepare_bigView(SmokeModifierData *smd, float *light) -{ - float *density = NULL; - size_t i = 0; - int bigres[3]; - - smoke_turbulence_get_res(smd->domain->wt, bigres); - - if(!smd->domain->traybig) + if(have_light) { - // TRay is for self shadowing - smd->domain->traybig = MEM_callocN(sizeof(float)*bigres[0]*bigres[1]*bigres[2], "Smoke_tRayBig"); + smoke_calc_transparency(sds->view3d, sds->p0, sds->p1, sds->res, sds->dx, light, calc_voxel_transp); + + cells = smd->domain->res[0]*smd->domain->res[1]*smd->domain->res[2]; + for(i = 0; i < cells; i++) + { + smd->domain->view3d[i * 4] = smd->domain->view3d[i * 4 + 1] = + smd->domain->view3d[i * 4 + 2] = smd->domain->view3d[i * 4 + 1] * smd->domain->view3d[i * 4 + 0]; + } } - if(!smd->domain->tvoxbig) - { - // TVox is for tranaparency - smd->domain->tvoxbig = MEM_callocN(sizeof(float)*bigres[0]*bigres[1]*bigres[2], "Smoke_tVoxBig"); - } - - density = smoke_turbulence_get_density(smd->domain->wt); - for (i = 0; i < bigres[0] * bigres[1] * bigres[2]; i++) - { - // Transparency computation - // formula taken from "Visual Simulation of Smoke" / Fedkiw et al. pg. 4 - // T_vox = exp(-C_ext * h) - // C_ext/sigma_t = density * C_ext - smoke_set_bigtvox(smd, i, exp(-density[i] * 7.0 * smd->domain->dx / (smd->domain->amplify + 1)) ); - } - smoke_calc_transparency(smd, light, 1); -} - - -float smoke_get_tvox(SmokeModifierData *smd, size_t index) -{ - return smd->domain->tvox[index]; -} - -void smoke_set_tvox(SmokeModifierData *smd, size_t index, float tvox) -{ - smd->domain->tvox[index] = tvox; -} - -float smoke_get_tray(SmokeModifierData *smd, size_t index) -{ - return smd->domain->tray[index]; -} - -void smoke_set_tray(SmokeModifierData *smd, size_t index, float transparency) -{ - smd->domain->tray[index] = transparency; -} - -float smoke_get_bigtvox(SmokeModifierData *smd, size_t index) -{ - return smd->domain->tvoxbig[index]; -} - -void smoke_set_bigtvox(SmokeModifierData *smd, size_t index, float tvox) -{ - smd->domain->tvoxbig[index] = tvox; -} - -float smoke_get_bigtray(SmokeModifierData *smd, size_t index) -{ - return smd->domain->traybig[index]; -} - -void smoke_set_bigtray(SmokeModifierData *smd, size_t index, float transparency) -{ - smd->domain->traybig[index] = transparency; + smd->domain->v3dnum = framenr; } long long smoke_get_mem_req(int xres, int yres, int zres, int amplify) @@ -1259,34 +1252,7 @@ long long smoke_get_mem_req(int xres, int yres, int zres, int amplify) return totalMB; } - -static void calc_voxel_transp(SmokeModifierData *smd, int *pixel, float *tRay) -{ - // printf("Pixel(%d, %d, %d)\n", pixel[0], pixel[1], pixel[2]); - const size_t index = smoke_get_index(pixel[0], smd->domain->res[0], pixel[1], smd->domain->res[1], pixel[2]); - - // T_ray *= T_vox - *tRay *= smoke_get_tvox(smd, index); -} - -static void calc_voxel_transp_big(SmokeModifierData *smd, int *pixel, float *tRay) -{ - int bigres[3]; - size_t index; - - smoke_turbulence_get_res(smd->domain->wt, bigres); - index = smoke_get_index(pixel[0], bigres[0], pixel[1], bigres[1], pixel[2]); - - /* - if(index > bigres[0]*bigres[1]*bigres[2]) - printf("pixel[0]: %d, [1]: %d, [2]: %d\n", pixel[0], pixel[1], pixel[2]); - */ - - // T_ray *= T_vox - *tRay *= smoke_get_bigtvox(smd, index); -} - -static void bresenham_linie_3D(SmokeModifierData *smd, int x1, int y1, int z1, int x2, int y2, int z2, float *tRay, int big) +static void bresenham_linie_3D(int x1, int y1, int z1, int x2, int y2, int z2, float *tRay, bresenham_callback cb, float *input, int res[3]) { int dx, dy, dz, i, l, m, n, x_inc, y_inc, z_inc, err_1, err_2, dx2, dy2, dz2; int pixel[3]; @@ -1313,11 +1279,7 @@ static void bresenham_linie_3D(SmokeModifierData *smd, int x1, int y1, int z1, i err_1 = dy2 - l; err_2 = dz2 - l; for (i = 0; i < l; i++) { - if(!big) - calc_voxel_transp(smd, pixel, tRay); - else - calc_voxel_transp_big(smd, pixel, tRay); - if(*tRay < 0.0f) + if(cb(input, res, pixel, tRay) < 0.0) return; if (err_1 > 0) { pixel[1] += y_inc; @@ -1335,11 +1297,7 @@ static void bresenham_linie_3D(SmokeModifierData *smd, int x1, int y1, int z1, i err_1 = dx2 - m; err_2 = dz2 - m; for (i = 0; i < m; i++) { - if(!big) - calc_voxel_transp(smd, pixel, tRay); - else - calc_voxel_transp_big(smd, pixel, tRay); - if(*tRay < 0.0f) + if(cb(input, res, pixel, tRay) < 0.0f) return; if (err_1 > 0) { pixel[0] += x_inc; @@ -1357,11 +1315,7 @@ static void bresenham_linie_3D(SmokeModifierData *smd, int x1, int y1, int z1, i err_1 = dy2 - n; err_2 = dx2 - n; for (i = 0; i < n; i++) { - if(!big) - calc_voxel_transp(smd, pixel, tRay); - else - calc_voxel_transp_big(smd, pixel, tRay); - if(*tRay < 0.0f) + if(cb(input, res, pixel, tRay) < 0.0f) return; if (err_1 > 0) { pixel[1] += y_inc; @@ -1376,41 +1330,15 @@ static void bresenham_linie_3D(SmokeModifierData *smd, int x1, int y1, int z1, i pixel[2] += z_inc; } } - if(!big) - calc_voxel_transp(smd, pixel, tRay); - else - calc_voxel_transp_big(smd, pixel, tRay); + cb(input, res, pixel, tRay); } -static void get_cell(struct SmokeModifierData *smd, float *pos, int *cell, int correct) +static void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int correct) { float tmp[3]; - VECSUB(tmp, pos, smd->domain->p0); - VecMulf(tmp, 1.0 / smd->domain->dx); - - if(correct) - { - cell[0] = MIN2(smd->domain->res[0] - 1, MAX2(0, (int)floor(tmp[0]))); - cell[1] = MIN2(smd->domain->res[1] - 1, MAX2(0, (int)floor(tmp[1]))); - cell[2] = MIN2(smd->domain->res[2] - 1, MAX2(0, (int)floor(tmp[2]))); - } - else - { - cell[0] = (int)floor(tmp[0]); - cell[1] = (int)floor(tmp[1]); - cell[2] = (int)floor(tmp[2]); - } -} -static void get_bigcell(struct SmokeModifierData *smd, float *pos, int *cell, int correct) -{ - float tmp[3]; - int res[3]; - smoke_turbulence_get_res(smd->domain->wt, res); - - VECSUB(tmp, pos, smd->domain->p0); - - VecMulf(tmp, (smd->domain->amplify + 1)/ smd->domain->dx ); + VECSUB(tmp, pos, p0); + VecMulf(tmp, 1.0 / dx); if(correct) { @@ -1426,43 +1354,23 @@ static void get_bigcell(struct SmokeModifierData *smd, float *pos, int *cell, in } } - -void smoke_calc_transparency(struct SmokeModifierData *smd, float *light, int big) +void smoke_calc_transparency(float *result, float *p0, float *p1, int res[3], float dx, float *light, bresenham_callback cb) { int x, y, z; float bv[6]; - int res[3]; float bigfactor = 1.0; // x - bv[0] = smd->domain->p0[0]; - bv[1] = smd->domain->p1[0]; + bv[0] = p0[0]; + bv[1] = p1[0]; // y - bv[2] = smd->domain->p0[1]; - bv[3] = smd->domain->p1[1]; + bv[2] = p0[1]; + bv[3] = p1[1]; // z - bv[4] = smd->domain->p0[2]; - bv[5] = smd->domain->p1[2]; -/* - printf("bv[0]: %f, [1]: %f, [2]: %f, [3]: %f, [4]: %f, [5]: %f\n", bv[0], bv[1], bv[2], bv[3], bv[4], bv[5]); + bv[4] = p0[2]; + bv[5] = p1[2]; - printf("p0[0]: %f, p0[1]: %f, p0[2]: %f\n", smd->domain->p0[0], smd->domain->p0[1], smd->domain->p0[2]); - printf("p1[0]: %f, p1[1]: %f, p1[2]: %f\n", smd->domain->p1[0], smd->domain->p1[1], smd->domain->p1[2]); - printf("dx: %f, amp: %d\n", smd->domain->dx, smd->domain->amplify); -*/ - if(!big) - { - res[0] = smd->domain->res[0]; - res[1] = smd->domain->res[1]; - res[2] = smd->domain->res[2]; - } - else - { - smoke_turbulence_get_res(smd->domain->wt, res); - bigfactor = 1.0 / (smd->domain->amplify + 1); - } - -#pragma omp parallel for schedule(static) private(y, z) shared(big, smd, light, res, bigfactor) +// #pragma omp parallel for schedule(static) private(y, z) for(x = 0; x < res[0]; x++) for(y = 0; y < res[1]; y++) for(z = 0; z < res[2]; z++) @@ -1475,41 +1383,26 @@ void smoke_calc_transparency(struct SmokeModifierData *smd, float *light, int bi index = smoke_get_index(x, res[0], y, res[1], z); - // voxelCenter = m_voxelarray[i].GetCenter(); - voxelCenter[0] = smd->domain->p0[0] + smd->domain->dx * bigfactor * x + smd->domain->dx * bigfactor * 0.5; - voxelCenter[1] = smd->domain->p0[1] + smd->domain->dx * bigfactor * y + smd->domain->dx * bigfactor * 0.5; - voxelCenter[2] = smd->domain->p0[2] + smd->domain->dx * bigfactor * z + smd->domain->dx * bigfactor * 0.5; - - // printf("vc[0]: %f, vc[1]: %f, vc[2]: %f\n", voxelCenter[0], voxelCenter[1], voxelCenter[2]); - // printf("light[0]: %f, light[1]: %f, light[2]: %f\n", light[0], light[1], light[2]); + voxelCenter[0] = p0[0] + dx * x + dx * 0.5; + voxelCenter[1] = p0[1] + dx * y + dx * 0.5; + voxelCenter[2] = p0[2] + dx * z + dx * 0.5; // get starting position (in voxel coords) if(BLI_bvhtree_bb_raycast(bv, light, voxelCenter, pos) > FLT_EPSILON) { // we're ouside - // printf("out: pos[0]: %f, pos[1]: %f, pos[2]: %f\n", pos[0], pos[1], pos[2]); - if(!big) - get_cell(smd, pos, cell, 1); - else - get_bigcell(smd, pos, cell, 1); + get_cell(p0, res, dx, pos, cell, 1); } else { - // printf("in: pos[0]: %f, pos[1]: %f, pos[2]: %f\n", light[0], light[1], light[2]); // we're inside - if(!big) - get_cell(smd, light, cell, 1); - else - get_bigcell(smd, light, cell, 1); + get_cell(p0, res, dx, light, cell, 1); } - // printf("cell - [0]: %d, [1]: %d, [2]: %d\n", cell[0], cell[1], cell[2]); - bresenham_linie_3D(smd, cell[0], cell[1], cell[2], x, y, z, &tRay, big); + bresenham_linie_3D(cell[0], cell[1], cell[2], x, y, z, &tRay, cb, result, res); - if(!big) - smoke_set_tray(smd, index, tRay); - else - smoke_set_bigtray(smd, index, tRay); + // convention -> from a RGBA float array, use G value for tRay + result[index*4 + 1] = tRay; } } diff --git a/source/blender/blenkernel/intern/smokehighres.c b/source/blender/blenkernel/intern/smokehighres.c new file mode 100644 index 00000000000..6a2e0549158 --- /dev/null +++ b/source/blender/blenkernel/intern/smokehighres.c @@ -0,0 +1,137 @@ +/** + * smokehighres.c + * + * $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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Daniel Genrich + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/* Part of the code copied from elbeem fluid library, copyright by Nils Thuerey */ + +#include "DNA_scene_types.h" +#include "DNA_listBase.h" +#include "DNA_modifier_types.h" +#include "DNA_object_types.h" +#include "DNA_smoke_types.h" + +#include "BKE_modifier.h" +#include "BKE_smoke.h" +#include "BKE_pointcache.h" + +#include "smoke_API.h" + +// we need different handling for the high-res feature +/* +if(bigdensity) +{ + // init all surrounding cells according to amplification, too + int i, j, k; + + smoke_turbulence_get_res(smd->domain->wt, bigres); + + for(i = 0; i < smd->domain->amplify + 1; i++) + for(j = 0; j < smd->domain->amplify + 1; j++) + for(k = 0; k < smd->domain->amplify + 1; k++) + { + index = smoke_get_index((smd->domain->amplify + 1)* cell[0] + i, bigres[0], (smd->domain->amplify + 1)* cell[1] + j, bigres[1], (smd->domain->amplify + 1)* cell[2] + k); + bigdensity[index] = sfs->density; + } +} +*/ + +static void smokeHRinit(SmokeHRModifierData *shrmd, SmokeDomainSettings *sds) +{ + if(!shrmd->wt) + { + shrmd->wt = smoke_turbulence_init(sds->res, shrmd->amplify + 1, shrmd->noise); + smoke_turbulence_initBlenderRNA(shrmd->wt, &shrmd->strength); + } +} + +void smokeHRModifier_free(SmokeHRModifierData *shrmd) +{ + if(shrmd->wt) + smoke_turbulence_free(shrmd->wt); + + BKE_ptcache_free_list(&shrmd->ptcaches); + shrmd->point_cache = NULL; +} + +void smokeHRModifier_do(SmokeHRModifierData *shrmd, Scene *scene, Object *ob, int useRenderParams, int isFinalCalc) +{ + ModifierData *md = NULL; + SmokeModifierData *smd = NULL; + SmokeDomainSettings *sds = NULL; + + // find underlaying smoke domain + smd = (SmokeModifierData *)modifiers_findByType(ob, eModifierType_Smoke); + if(!(smd && smd->type == MOD_SMOKE_TYPE_DOMAIN)) + return; + + sds = smd->domain; + + smokeHRinit(shrmd, sds); + + // smoke_turbulence_dissolve(shrmd->wt, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG); + + // smoke_turbulence_step(shrmd->wt, sds->fluid); +} + + +// update necessary information for 3dview ("high res" option) +void smoke_prepare_bigView(SmokeHRModifierData *shrmd, float *light) +{ + float *density = NULL; + size_t i = 0; + int bigres[3]; +/* + smoke_turbulence_get_res(shrmd->wt, bigres); + + if(!smd->domain->traybig) + { + // TRay is for self shadowing + smd->domain->traybig = MEM_callocN(sizeof(float)*bigres[0]*bigres[1]*bigres[2], "Smoke_tRayBig"); + } + if(!smd->domain->tvoxbig) + { + // TVox is for tranaparency + smd->domain->tvoxbig = MEM_callocN(sizeof(float)*bigres[0]*bigres[1]*bigres[2], "Smoke_tVoxBig"); + } + + density = smoke_turbulence_get_density(smd->domain->wt); + for (i = 0; i < bigres[0] * bigres[1] * bigres[2]; i++) + { + // Transparency computation + // formula taken from "Visual Simulation of Smoke" / Fedkiw et al. pg. 4 + // T_vox = exp(-C_ext * h) + // C_ext/sigma_t = density * C_ext + smoke_set_bigtvox(smd, i, exp(-density[i] * 7.0 * smd->domain->dx / (smd->domain->amplify + 1)) ); + } + smoke_calc_transparency(smd, light, 1); + */ +} + + diff --git a/source/blender/blenlib/BLI_winstuff.h b/source/blender/blenlib/BLI_winstuff.h index 3e1b73e51be..fad45f1b6c3 100644 --- a/source/blender/blenlib/BLI_winstuff.h +++ b/source/blender/blenlib/BLI_winstuff.h @@ -65,20 +65,22 @@ extern "C" { #endif -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif -#ifndef M_PI_2 -#define M_PI_2 1.57079632679489661923 -#endif -#ifndef M_SQRT2 -#define M_SQRT2 1.41421356237309504880 -#endif -#ifndef M_SQRT1_2 -#define M_SQRT1_2 0.70710678118654752440 -#endif -#ifndef M_1_PI -#define M_1_PI 0.318309886183790671538 +# ifndef _WIN64 + #ifndef M_PI + #define M_PI 3.14159265358979323846 + #endif + #ifndef M_PI_2 + #define M_PI_2 1.57079632679489661923 + #endif + #ifndef M_SQRT2 + #define M_SQRT2 1.41421356237309504880 + #endif + #ifndef M_SQRT1_2 + #define M_SQRT1_2 0.70710678118654752440 + #endif + #ifndef M_1_PI + #define M_1_PI 0.318309886183790671538 + #endif #endif #define MAXPATHLEN MAX_PATH diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index db811b22460..71994b97521 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -3669,8 +3669,6 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) else if (md->type==eModifierType_Smoke) { SmokeModifierData *smd = (SmokeModifierData*) md; - smd->point_cache = NULL; - if(smd->type==MOD_SMOKE_TYPE_DOMAIN) { smd->flow = NULL; @@ -3679,23 +3677,10 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) smd->domain->smd = smd; smd->domain->fluid = NULL; - smd->domain->wt = NULL; - smd->domain->tvox = NULL; - smd->domain->tray = NULL; - smd->domain->tvoxbig = NULL; - smd->domain->traybig = NULL; - smd->domain->bind = NULL; - smd->domain->max_textures= 0; + smd->domain->view3d = NULL; + smd->domain->tex = NULL; - // do_versions trick - if(smd->domain->strength < 1.0) - smd->domain->strength = 2.0; - - // reset 3dview - if(smd->domain->viewsettings < MOD_SMOKE_VIEW_USEBIG) - smd->domain->viewsettings = 0; - else - smd->domain->viewsettings = MOD_SMOKE_VIEW_USEBIG; + direct_link_pointcache_list(fd, &smd->domain->ptcaches, &smd->domain->point_cache); } else if(smd->type==MOD_SMOKE_TYPE_FLOW) { diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index ede7aacfea8..31fe0c01900 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1126,14 +1126,17 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) else if(md->type==eModifierType_Smoke) { SmokeModifierData *smd = (SmokeModifierData*) md; - if(smd->type==MOD_SMOKE_TYPE_DOMAIN) + if(smd->type & MOD_SMOKE_TYPE_DOMAIN) writestruct(wd, DATA, "SmokeDomainSettings", 1, smd->domain); - else if(smd->type==MOD_SMOKE_TYPE_FLOW) + else if(smd->type & MOD_SMOKE_TYPE_FLOW) writestruct(wd, DATA, "SmokeFlowSettings", 1, smd->flow); /* - else if(smd->type==MOD_SMOKE_TYPE_COLL) + else if(smd->type & MOD_SMOKE_TYPE_COLL) writestruct(wd, DATA, "SmokeCollSettings", 1, smd->coll); */ + + if((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) + write_pointcaches(wd, &smd->domain->ptcaches); } else if(md->type==eModifierType_Fluidsim) { FluidsimModifierData *fluidmd = (FluidsimModifierData*) md; diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 9983e24f2c9..16900d6d894 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -161,6 +161,13 @@ int ED_object_modifier_remove(ReportList *reports, Scene *scene, Object *ob, Mod DAG_scene_sort(scene); } + else if(md->type == eModifierType_Smoke) { + ModifierData *tmd = modifiers_findByType(ob, eModifierType_SmokeHR); + if(tmd) { + BLI_remlink(&ob->modifiers, tmd); + modifier_free(tmd); + } + } BLI_remlink(&ob->modifiers, md); modifier_free(md); diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c index 530500cfafa..994bb0010d8 100644 --- a/source/blender/editors/space_buttons/buttons_context.c +++ b/source/blender/editors/space_buttons/buttons_context.c @@ -553,7 +553,7 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r "world", "object", "mesh", "armature", "lattice", "curve", "meta_ball", "lamp", "camera", "material", "material_slot", "texture", "texture_slot", "bone", "edit_bone", "particle_system", - "cloth", "soft_body", "fluid", "smoke", "collision", "brush", NULL}; + "cloth", "soft_body", "fluid", "smoke", "smoke_hr", "collision", "brush", NULL}; CTX_data_dir_set(result, dir); return 1; @@ -697,6 +697,16 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r return 1; } } + else if(CTX_data_equals(member, "smoke_hr")) { + PointerRNA *ptr= get_pointer_type(path, &RNA_Object); + + if(ptr && ptr->data) { + Object *ob= ptr->data; + ModifierData *md= modifiers_findByType(ob, eModifierType_SmokeHR); + CTX_data_pointer_set(result, &ob->id, &RNA_SmokeHRModifier, md); + return 1; + } + } else if(CTX_data_equals(member, "collision")) { PointerRNA *ptr= get_pointer_type(path, &RNA_Object); diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 466b55ba862..55565c83f5e 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -5309,356 +5309,20 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) } /* draw code for smoke */ - if((md = modifiers_findByType(ob, eModifierType_Smoke))) - { - SmokeModifierData *smd = (SmokeModifierData *)md; - - // draw collision objects - if((smd->type & MOD_SMOKE_TYPE_COLL) && smd->coll) - { - /*SmokeCollSettings *scs = smd->coll; - if(scs->points) - { - size_t i; - - wmLoadMatrix(rv3d->viewmat); - - if(col || (ob->flag & SELECT)) cpack(0xFFFFFF); - glDepthMask(GL_FALSE); - glEnable(GL_BLEND); - - - // glPointSize(3.0); - bglBegin(GL_POINTS); - - for(i = 0; i < scs->numpoints; i++) - { - bglVertex3fv(&scs->points[3*i]); - } - - bglEnd(); - glPointSize(1.0); - - wmMultMatrix(ob->obmat); - glDisable(GL_BLEND); - glDepthMask(GL_TRUE); - if(col) cpack(col); - + if(((SmokeHRModifierData *)(md = modifiers_findByType(ob, eModifierType_SmokeHR)) && (((SmokeHRModifierData *)md)->flags & MOD_SMOKE_SHOWHIGHRES))) { + // GPU_create_smoke(smd); + // draw_volume(scene, ar, v3d, base, smd->domain->tex, smd->domain->res); + // GPU_free_smoke(smd); + } + else { + md = modifiers_findByType(ob, eModifierType_Smoke); + if (md) { + SmokeModifierData *smd = (SmokeModifierData *)md; + if(smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain) { + GPU_create_smoke(smd); + draw_volume(scene, ar, v3d, base, smd->domain->tex, smd->domain->res); + GPU_free_smoke(smd); } - */ - } - - // only draw domains - if(smd->domain && smd->domain->fluid) - { - int x, y, z, i; - float viewnormal[3]; - int mainaxis[3] = {0,0,0}; - float align = 0, signed_align = 0; - int max_textures = 0, counter_textures = 0; - float *buffer = NULL; - int res[3]; - float bigfactor = 1.0; - int big = (smd->domain->flags & MOD_SMOKE_HIGHRES) && (smd->domain->viewsettings & MOD_SMOKE_VIEW_USEBIG); - int new = 0; - int have_lamp = 0; - - // GUI sent redraw event - if(smd->domain->flags & MOD_SMOKE_VIEW_REDRAWNICE) - { - new = 1; - smd->domain->flags &= ~MOD_SMOKE_VIEW_REDRAWNICE; - } - - if(!big) - { - res[0] = smd->domain->res[0]; - res[1] = smd->domain->res[1]; - res[2] = smd->domain->res[2]; - } - else - { - smoke_turbulence_get_res(smd->domain->wt, res); - bigfactor = 1.0 / (smd->domain->amplify + 1); - } - - wmLoadMatrix(rv3d->viewmat); - - if(col || (ob->flag & SELECT)) cpack(0xFFFFFF); /* for visibility, also while wpaint */ - glDepthMask(GL_FALSE); - glEnable(GL_BLEND); - - // get view vector - VECCOPY(viewnormal, rv3d->viewinv[2]); - Normalize(viewnormal); - for(i = 0; i < 3; i++) - { - if(ABS(viewnormal[i]) > align) - { - mainaxis[0] = i; - align = ABS(viewnormal[i]); - signed_align = viewnormal[i]; - } - } - mainaxis[1] = (mainaxis[0] + 1) % 3; - mainaxis[2] = (mainaxis[0] + 2) % 3; - - if(!smd->domain->bind) - { - smd->domain->bind = MEM_callocN(sizeof(GLuint)*256, "Smoke_bind"); - if(big) - smd->domain->viewsettings |= MOD_SMOKE_VIEW_CHANGETOBIG; - new = 3; - } - - // check if view axis / mode has been changed - if(smd->domain->viewsettings) - { - if(big) - { - if(!(smd->domain->viewsettings & MOD_SMOKE_VIEW_BIG)) - new = 2; - else if(!(smd->domain->viewsettings & MOD_SMOKE_VIEW_CHANGETOBIG)) - new = 1; - - smd->domain->viewsettings |= MOD_SMOKE_VIEW_CHANGETOBIG; - } - else - { - if(!(smd->domain->viewsettings & MOD_SMOKE_VIEW_SMALL)) - new = 2; - else if(smd->domain->viewsettings & MOD_SMOKE_VIEW_CHANGETOBIG) - new = 1; - - smd->domain->viewsettings &= ~MOD_SMOKE_VIEW_CHANGETOBIG; - } - - if(!new) - { - if((mainaxis[0] == 0) && !(smd->domain->viewsettings & MOD_SMOKE_VIEW_X)) - new = 1; - else if((mainaxis[0] == 1) && !(smd->domain->viewsettings & MOD_SMOKE_VIEW_Y)) - new = 1; - else if((mainaxis[0] == 2) && !(smd->domain->viewsettings & MOD_SMOKE_VIEW_Z)) - new = 1; - - // printf("check axis\n"); - } - } - else - new = 3; - - if(new > 1) - { - float light[3] = {0.0,0.0,0.0}; // TODO: take real LAMP coordinates - dg - Base *base_tmp = NULL; - - for(base_tmp = scene->base.first; base_tmp; base_tmp= base_tmp->next) - { - if(base_tmp->object->type == OB_LAMP) - { - Lamp *la = (Lamp *)base_tmp->object->data; - - if(la->type == LA_LOCAL) - { - VECCOPY(light, base_tmp->object->obmat[3]); - have_lamp = 1; - break; - } - } - } - - if(!big && !(smd->domain->viewsettings & MOD_SMOKE_VIEW_SMALL)) - { - smoke_prepare_View(smd, light); - // printf("prepared View!\n"); - } - else if(big && !(smd->domain->viewsettings & MOD_SMOKE_VIEW_BIG)) - { - smoke_prepare_bigView(smd, light); - // printf("prepared bigView!\n"); - } - } - - // printf("big: %d, new: %d\n", big, new); - - // only create buffer if we need to create new textures - if(new) - buffer = MEM_mallocN(sizeof(float)*res[mainaxis[1]]*res[mainaxis[2]]*4, "SmokeDrawBuffer"); - - if(buffer || smd->domain->viewsettings) - { - int mod_texture = 0; - - // printf("if(buffer || smd->domain->viewsettings)\n"); - - max_textures = (res[mainaxis[0]] > 256) ? 256 : res[mainaxis[0]]; - - if(!smd->domain->viewsettings) // new frame or new start - { - smd->domain->max_textures = max_textures; - glGenTextures(smd->domain->max_textures, (GLuint *)smd->domain->bind); - new = 1; - // printf("glGenTextures\n"); - } - else - { - if(new) - { - // printf("glDeleteTextures\n"); - glDeleteTextures(smd->domain->max_textures, (GLuint *)smd->domain->bind); - smd->domain->max_textures = max_textures; - glGenTextures(smd->domain->max_textures, (GLuint *)smd->domain->bind); - } - } - - mod_texture = MAX3(1, smd->domain->visibility, (int)(res[mainaxis[0]] / smd->domain->max_textures )); - - // align order of billboards to be front or backview (e.g. +x or -x axis) - if(signed_align < 0) - { - z = res[mainaxis[0]] - 1; - } - else - { - z = 0; - } - - for (; signed_align > 0 ? (z < res[mainaxis[0]]) : (z >= 0); signed_align > 0 ? z++ : z--) // 2 - { - float quad[4][3]; - - if(new) - { - for (y = 0; y < res[mainaxis[1]]; y++) // 1 - { - for (x = 0; x < res[mainaxis[2]]; x++) // 0 - { - size_t index; - size_t image_index; - float tray, tvox; - - image_index = smoke_get_index2d(y, res[mainaxis[1]], x); - - if(mainaxis[0] == 0) - { - // mainaxis[1] == 1, mainaxis[2] == 2 - index = smoke_get_index(z, res[mainaxis[0]], y, res[mainaxis[1]], x); - } - else if(mainaxis[0] == 1) - { - // mainaxis[1] == 2, mainaxis[2] == 0 - index = smoke_get_index(x, res[mainaxis[2]], z, res[mainaxis[0]], y); - } - else // mainaxis[0] == 2 - { - // mainaxis[1] == 0, mainaxis[2] == 1 - index = smoke_get_index(y, res[mainaxis[1]], x, res[mainaxis[2]], z); - } - - if(!big) - { - tvox = smoke_get_tvox(smd, index); - tray = smoke_get_tray(smd, index); - } - else - { - tvox = smoke_get_bigtvox(smd, index); - tray = smoke_get_bigtray(smd, index); - } - - if(!have_lamp) - tray = 1.0; - - // fill buffer with luminance and alpha - // 1 - T_vox - buffer[image_index*4 + 3] = 1.0 - tvox; // 0 = transparent => d.h. tvox = 1 - - // L_vox = Omega * L_light * (1 - T_vox) * T_ray - buffer[image_index*4] = buffer[image_index*4 + 1] = buffer[image_index*4 + 2] = smd->domain->omega * 1.0 * tvox * tray; - } - } - } - glBindTexture(GL_TEXTURE_2D, smd->domain->bind[counter_textures]); - glEnable(GL_TEXTURE_2D); - - if(new) - { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, res[mainaxis[1]], res[mainaxis[2]], 0, GL_RGBA, GL_FLOAT, buffer); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering - } - - if((z % mod_texture) == 0 ) - { - // botttom left - quad[3][mainaxis[0]] = smd->domain->p0[mainaxis[0]] + z * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5; - quad[3][mainaxis[1]] = smd->domain->p0[mainaxis[1]] + smd->domain->dx * bigfactor * 0.5; - quad[3][mainaxis[2]] = smd->domain->p0[mainaxis[2]] + smd->domain->dx * bigfactor * 0.5; - - // top right - quad[1][mainaxis[0]] = smd->domain->p0[mainaxis[0]] + z * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5; - quad[1][mainaxis[1]] = smd->domain->p0[mainaxis[1]] + (res[mainaxis[1]] - 1) * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5; - quad[1][mainaxis[2]] = smd->domain->p0[mainaxis[2]] + (res[mainaxis[2]] - 1) * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5; - - // top left - quad[2][mainaxis[0]] = smd->domain->p0[mainaxis[0]] + z * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5; - quad[2][mainaxis[1]] = smd->domain->p0[mainaxis[1]] + smd->domain->dx * bigfactor * 0.5; - quad[2][mainaxis[2]] = smd->domain->p0[mainaxis[2]] + (res[mainaxis[2]] - 1) * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5; - - // bottom right - quad[0][mainaxis[0]] = smd->domain->p0[mainaxis[0]] + z * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5; - quad[0][mainaxis[1]] = smd->domain->p0[mainaxis[1]] + (res[mainaxis[1]] - 1) * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5; - quad[0][mainaxis[2]] = smd->domain->p0[mainaxis[2]] + smd->domain->dx * bigfactor * 0.5; - - glBegin(GL_QUADS); // Start Drawing Quads - - glTexCoord2f(1.0f, 0.0f); - glVertex3fv(quad[0]); // Left And Up 1 Unit (Top Left) - glTexCoord2f(1.0f, 1.0f); - glVertex3fv(quad[1]); // Right And Up 1 Unit (Top Right) - glTexCoord2f(0.0f, 1.0f); - glVertex3fv(quad[2]); // Right And Down One Unit (Bottom Right) - glTexCoord2f(0.0f, 0.0f); - glVertex3fv(quad[3]); // Left And Down One Unit (Bottom Left) - - glEnd(); - } - counter_textures++; - } - } - if(buffer) - { - MEM_freeN(buffer); - buffer = NULL; - } - - // set correct flag for viewsettings - if(1) - { - // do not clear BIG/SMALL flag - smd->domain->viewsettings &= ~MOD_SMOKE_VIEW_X; - smd->domain->viewsettings &= ~MOD_SMOKE_VIEW_Y; - smd->domain->viewsettings &= ~MOD_SMOKE_VIEW_Z; - - // set what caches we have - if(big) - smd->domain->viewsettings |= MOD_SMOKE_VIEW_BIG; - else - smd->domain->viewsettings |= MOD_SMOKE_VIEW_SMALL; - - if(mainaxis[0] == 0) - smd->domain->viewsettings |= MOD_SMOKE_VIEW_X; - else if(mainaxis[0] == 1) - smd->domain->viewsettings |= MOD_SMOKE_VIEW_Y; - else if(mainaxis[0] == 2) - smd->domain->viewsettings |= MOD_SMOKE_VIEW_Z; - } - - wmMultMatrix(ob->obmat); - glDisable(GL_BLEND); - glDepthMask(GL_TRUE); - if(col) cpack(col); } } diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c new file mode 100644 index 00000000000..221003360f4 --- /dev/null +++ b/source/blender/editors/space_view3d/drawvolume.c @@ -0,0 +1,304 @@ +/** + * $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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * Contributor(s): Daniel Genrich + * + * ***** END GPL LICENSE BLOCK ***** + */ + + +#include +#include + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "MEM_guardedalloc.h" + +#include "IMB_imbuf.h" + + +#include "MTC_matrixops.h" + +#include "DNA_armature_types.h" +#include "DNA_boid_types.h" +#include "DNA_camera_types.h" +#include "DNA_curve_types.h" +#include "DNA_constraint_types.h" // for drawing constraint +#include "DNA_effect_types.h" +#include "DNA_lamp_types.h" +#include "DNA_lattice_types.h" +#include "DNA_material_types.h" +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" +#include "DNA_meta_types.h" +#include "DNA_modifier_types.h" +#include "DNA_object_types.h" +#include "DNA_object_force.h" +#include "DNA_object_fluidsim.h" +#include "DNA_particle_types.h" +#include "DNA_space_types.h" +#include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_smoke_types.h" +#include "DNA_userdef_types.h" +#include "DNA_view3d_types.h" +#include "DNA_world_types.h" + +#include "BLI_blenlib.h" +#include "BLI_arithb.h" +#include "BLI_editVert.h" +#include "BLI_edgehash.h" +#include "BLI_rand.h" + +#include "BKE_anim.h" //for the where_on_path function +#include "BKE_curve.h" +#include "BKE_constraint.h" // for the get_constraint_target function +#include "BKE_DerivedMesh.h" +#include "BKE_deform.h" +#include "BKE_displist.h" +#include "BKE_effect.h" +#include "BKE_font.h" +#include "BKE_global.h" +#include "BKE_image.h" +#include "BKE_key.h" +#include "BKE_lattice.h" +#include "BKE_mesh.h" +#include "BKE_material.h" +#include "BKE_mball.h" +#include "BKE_modifier.h" +#include "BKE_object.h" +#include "BKE_paint.h" +#include "BKE_particle.h" +#include "BKE_property.h" +#include "BKE_smoke.h" +#include "BKE_unit.h" +#include "BKE_utildefines.h" +#include "smoke_API.h" + +#include "BIF_gl.h" +#include "BIF_glutil.h" + +#include "GPU_draw.h" +#include "GPU_material.h" +#include "GPU_extensions.h" + +#include "ED_mesh.h" +#include "ED_particle.h" +#include "ED_screen.h" +#include "ED_types.h" +#include "ED_util.h" + +#include "UI_resources.h" +#include "UI_interface_icons.h" + +#include "WM_api.h" +#include "BLF_api.h" + +#include "GPU_extensions.h" + +#include "view3d_intern.h" // own include + +struct GPUTexture; + +/* draw slices of smoke is adapted from c++ code authored by: Johannes Schmid and Ingemar Rask, 2006, johnny@grob.org */ +static float cv[][3] = { + {1.0f, 1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {1.0f, -1.0f, 1.0f}, + {1.0f, 1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, {1.0f, -1.0f, -1.0f} +}; + +// edges have the form edges[n][0][xyz] + t*edges[n][1][xyz] +static float edges[12][2][3] = { + {{1.0f, 1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}}, + {{-1.0f, 1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}}, + {{-1.0f, -1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}}, + {{1.0f, -1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}}, + + {{1.0f, -1.0f, 1.0f}, {0.0f, 1.0f, 0.0f}}, + {{-1.0f, -1.0f, 1.0f}, {0.0f, 1.0f, 0.0f}}, + {{-1.0f, -1.0f, -1.0f}, {0.0f, 1.0f, 0.0f}}, + {{1.0f, -1.0f, -1.0f}, {0.0f, 1.0f, 0.0f}}, + + {{-1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f}}, + {{-1.0f, -1.0f, 1.0f}, {1.0f, 0.0f, 0.0f}}, + {{-1.0f, -1.0f, -1.0f}, {1.0f, 0.0f, 0.0f}}, + {{-1.0f, 1.0f, -1.0f}, {1.0f, 0.0f, 0.0f}} +}; + +int intersect_edges(float *points, float a, float b, float c, float d) +{ + int i; + float t; + int numpoints = 0; + + for (i=0; i<12; i++) { + t = -(a*edges[i][0][0] + b*edges[i][0][1] + c*edges[i][0][2] + d) + / (a*edges[i][1][0] + b*edges[i][1][1] + c*edges[i][1][2]); + if ((t>0)&&(t<2)) { + points[numpoints * 3 + 0] = edges[i][0][0] + edges[i][1][0]*t; + points[numpoints * 3 + 1] = edges[i][0][1] + edges[i][1][1]*t; + points[numpoints * 3 + 2] = edges[i][0][2] + edges[i][1][2]*t; + numpoints++; + } + } + return numpoints; +} + +static int convex(float *p0, float *up, float *a, float *b) +{ + // Vec3 va = a-p0, vb = b-p0; + float va[3], vb[3], tmp[3]; + VECSUB(va, a, p0); + VECSUB(vb, b, p0); + Crossf(tmp, va, vb); + return INPR(up, tmp) >= 0; +} + +// copied from gpu_extension.c +static int is_pow2(int n) +{ + return ((n)&(n-1))==0; +} + +static int larger_pow2(int n) +{ + if (is_pow2(n)) + return n; + + while(!is_pow2(n)) + n= n&(n-1); + + return n*2; +} + +void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture *tex, int res[3]) +{ + Object *ob = base->object; + RegionView3D *rv3d= ar->regiondata; + + float viewnormal[3]; + // int res[3]; + int i, j, n; + float d, d0, dd; + float *points = NULL; + int numpoints = 0; + float cor[3] = {1.,1.,1.}; + + /* + res[0] = smd->domain->res[0]; + res[1] = smd->domain->res[1]; + res[2] = smd->domain->res[2]; + */ + + wmLoadMatrix(rv3d->viewmat); + + glDepthMask(GL_FALSE); + glEnable(GL_TEXTURE_3D); + glDisable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + // get view vector + VECCOPY(viewnormal, rv3d->viewinv[2]); + Normalize(viewnormal); + + // find cube vertex that is closest to the viewer + for (i=0; i<8; i++) { + float x,y,z; + + x = cv[i][0] + viewnormal[0]; + y = cv[i][1] + viewnormal[1]; + z = cv[i][2] + viewnormal[2]; + + if ((x>=-1.0f)&&(x<=1.0f) + &&(y>=-1.0f)&&(y<=1.0f) + &&(z>=-1.0f)&&(z<=1.0f)) { + break; + } + } + + GPU_texture_bind(tex, 0); + + cor[0] = (float)res[0]/(float)larger_pow2(res[0]); + cor[1] = (float)res[1]/(float)larger_pow2(res[1]); + cor[2] = (float)res[2]/(float)larger_pow2(res[2]); + + // our slices are defined by the plane equation a*x + b*y +c*z + d = 0 + // (a,b,c), the plane normal, are given by viewdir + // d is the parameter along the view direction. the first d is given by + // inserting previously found vertex into the plane equation + d0 = -(viewnormal[0]*cv[i][0] + viewnormal[1]*cv[i][1] + viewnormal[2]*cv[i][2]); + dd = 2.0*d0/64.0f; + n = 0; + + // printf("d0: %f, dd: %f\n", d0, dd); + + points = MEM_callocN(sizeof(float)*12*3, "smoke_points_preview"); + + for (d = d0; d > -d0; d -= dd) { + float p0[3]; + // intersect_edges returns the intersection points of all cube edges with + // the given plane that lie within the cube + numpoints = intersect_edges(points, viewnormal[0], viewnormal[1], viewnormal[2], d); + + if (numpoints > 2) { + VECCOPY(p0, points); + + // sort points to get a convex polygon + for(i = 1; i < numpoints - 1; i++) + { + for(j = i + 1; j < numpoints; j++) + { + if(convex(p0, viewnormal, &points[j * 3], &points[i * 3])) + { + float tmp2[3]; + VECCOPY(tmp2, &points[i * 3]); + VECCOPY(&points[i * 3], &points[j * 3]); + VECCOPY(&points[j * 3], tmp2); + } + } + } + + glBegin(GL_POLYGON); + for (i = 0; i < numpoints; i++) { + glColor3f(1.0, 1.0, 1.0); + glTexCoord3d((points[i * 3 + 0] + 1.0)*cor[0]/2.0, (points[i * 3 + 1] + 1)*cor[1]/2.0, (points[i * 3 + 2] + 1.0)*cor[2]/2.0); + glVertex3f(points[i * 3 + 0], points[i * 3 + 1], points[i * 3 + 2]); + } + glEnd(); + } + n++; + } + + GPU_texture_unbind(tex); + + MEM_freeN(points); + + wmMultMatrix(ob->obmat); + + glDisable(GL_TEXTURE_3D); + glDisable(GL_BLEND); + glEnable(GL_DEPTH_TEST); + glDepthMask(GL_TRUE); +} + diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index acd1c62bc17..e5e85cf9d16 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -156,6 +156,9 @@ void VIEW3D_OT_snap_menu(struct wmOperatorType *ot); ARegion *view3d_has_buttons_region(ScrArea *sa); ARegion *view3d_has_tools_region(ScrArea *sa); +/* draw_volume.c */ +void draw_volume(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct Base *base, struct GPUTexture *tex, int res[3]); + #endif /* ED_VIEW3D_INTERN_H */ diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h index 82ff51dc5ce..1c6b8399422 100644 --- a/source/blender/gpu/GPU_draw.h +++ b/source/blender/gpu/GPU_draw.h @@ -112,6 +112,10 @@ int GPU_verify_image(struct Image *ima, int tftile, int tfmode, int compare, int void GPU_free_image(struct Image *ima); void GPU_free_images(void); +/* smoke drawing functions */ +void GPU_free_smoke(struct SmokeModifierData *smd); +void GPU_create_smoke(struct SmokeModifierData *smd); + #ifdef __cplusplus } #endif diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h index eba585e8838..e00cab79ce0 100644 --- a/source/blender/gpu/GPU_extensions.h +++ b/source/blender/gpu/GPU_extensions.h @@ -73,6 +73,7 @@ int GPU_print_error(char *str); GPUTexture *GPU_texture_create_1D(int w, float *pixels); GPUTexture *GPU_texture_create_2D(int w, int h, float *pixels); +GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels); GPUTexture *GPU_texture_create_depth(int w, int h); GPUTexture *GPU_texture_from_blender(struct Image *ima, struct ImageUser *iuser, double time, int mipmap); diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index e7846a23905..a81c7e03455 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -38,9 +38,11 @@ #include "DNA_lamp_types.h" #include "DNA_material_types.h" #include "DNA_meshdata_types.h" +#include "DNA_modifier_types.h" #include "DNA_node_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "DNA_smoke_types.h" #include "DNA_userdef_types.h" #include "DNA_view3d_types.h" @@ -744,6 +746,23 @@ int GPU_update_image_time(Image *ima, double time) return inc; } + +void GPU_free_smoke(SmokeModifierData *smd) +{ + if(smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain) + { + if(smd->domain->tex) + GPU_texture_free(smd->domain->tex); + smd->domain->tex = NULL; + } +} + +void GPU_create_smoke(SmokeModifierData *smd) +{ + if(smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain && !smd->domain->tex) + smd->domain->tex = GPU_texture_create_3D(smd->domain->res[0], smd->domain->res[1], smd->domain->res[2], smd->domain->view3d); +} + void GPU_free_image(Image *ima) { /* free regular image binding */ diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index 467b2c4a7f4..0b6640b9e27 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -312,6 +312,78 @@ static GPUTexture *GPU_texture_create_nD(int w, int h, int n, float *fpixels, in return tex; } + +GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels) +{ + GPUTexture *tex; + GLenum type, format, internalformat; + void *pixels = NULL; + + tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture"); + tex->w = w; + tex->h = h; + tex->depth = depth; + tex->number = -1; + tex->refcount = 1; + tex->target = GL_TEXTURE_3D; + + glGenTextures(1, &tex->bindcode); + + if (!tex->bindcode) { + fprintf(stderr, "GPUTexture: texture create failed: %d\n", + (int)glGetError()); + GPU_texture_free(tex); + return NULL; + } + + // if (!GLEW_ARB_texture_non_power_of_two) + { + tex->w = larger_pow2(tex->w); + tex->h = larger_pow2(tex->h); + tex->depth = larger_pow2(tex->depth); + } + + tex->number = 0; + glBindTexture(tex->target, tex->bindcode); + + type = GL_UNSIGNED_BYTE; + format = GL_RGBA; + internalformat = GL_RGBA8; + + if (fpixels) + pixels = GPU_texture_convert_pixels(w*h*depth, fpixels); + + glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, 0); + + if (fpixels) { + glTexSubImage3D(tex->target, 0, 0, 0, 0, w, h, depth, format, type, pixels); + + /* + if (tex->w > w) + GPU_glTexSubImageEmpty(tex->target, format, w, 0, tex->w-w, tex->h); + if (tex->h > h) + GPU_glTexSubImageEmpty(tex->target, format, 0, h, w, tex->h-h); + */ + } + + // glTexImage3D(tex->target, 0, GL_RGBA, w, h, depth, 0, GL_RGBA, GL_FLOAT, fpixels); + + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R,GL_CLAMP_TO_BORDER); + + + if (pixels) + MEM_freeN(pixels); + + if (tex) + GPU_texture_unbind(tex); + + return tex; +} + GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time, int mipmap) { GPUTexture *tex; diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 9d1707599b9..33499574012 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -42,6 +42,7 @@ typedef enum ModifierType { eModifierType_Multires, eModifierType_Surface, eModifierType_Smoke, + eModifierType_SmokeHR, NUM_MODIFIER_TYPES } ModifierType; @@ -252,9 +253,36 @@ typedef struct SmokeModifierData { struct SmokeCollSettings *coll; /* collision objects */ float time; int type; /* domain, inflow, outflow, ... */ - struct PointCache *point_cache; /* definition is in DNA_object_force.h */ } SmokeModifierData; + +/* noise */ +#define MOD_SMOKE_NOISEWAVE (1<<0) +#define MOD_SMOKE_NOISEFFT (1<<1) +#define MOD_SMOKE_NOISECURL (1<<2) + +/* flags */ +#define MOD_SMOKE_SHOWHIGHRES (1<<0) /* show high resolution */ + +typedef struct SmokeHRModifierData { + ModifierData modifier; + + struct WTURBULENCE *wt; // WTURBULENCE object, if active + struct PointCache *point_cache; /* definition is in DNA_object_force.h */ + struct ListBase ptcaches; + struct GPUTexture *tex; + float *view3d; /* voxel data for display */ + unsigned int v3dnum; /* number of frame in view3d buffer */ + float time; + float strength; + int res[3]; + int maxres; + short noise; /* noise type: wave, curl, anisotropic */ + short pad; + int amplify; + int flags; +} SmokeHRModifierData; + typedef struct DisplaceModifierData { ModifierData modifier; diff --git a/source/blender/makesdna/DNA_smoke_types.h b/source/blender/makesdna/DNA_smoke_types.h index c7f49d3ddd2..2d8b21b86de 100644 --- a/source/blender/makesdna/DNA_smoke_types.h +++ b/source/blender/makesdna/DNA_smoke_types.h @@ -30,24 +30,12 @@ #define DNA_SMOKE_TYPES_H /* flags */ -#define MOD_SMOKE_HIGHRES (1<<1) /* compute high resolution */ +#define MOD_SMOKE_HIGHRES (1<<1) /* enable high resolution */ #define MOD_SMOKE_DISSOLVE (1<<2) /* let smoke dissolve */ #define MOD_SMOKE_DISSOLVE_LOG (1<<3) /* using 1/x for dissolve */ -/* noise */ -#define MOD_SMOKE_NOISEWAVE (1<<0) -#define MOD_SMOKE_NOISEFFT (1<<1) -#define MOD_SMOKE_NOISECURL (1<<2) /* viewsettings */ -#define MOD_SMOKE_VIEW_X (1<<0) -#define MOD_SMOKE_VIEW_Y (1<<1) -#define MOD_SMOKE_VIEW_Z (1<<2) -#define MOD_SMOKE_VIEW_SMALL (1<<3) -#define MOD_SMOKE_VIEW_BIG (1<<4) -#define MOD_SMOKE_VIEW_CHANGETOBIG (1<<5) -#define MOD_SMOKE_VIEW_REDRAWNICE (1<<6) -#define MOD_SMOKE_VIEW_REDRAWALL (1<<7) -#define MOD_SMOKE_VIEW_USEBIG (1<<8) +/* nothing so far */ typedef struct SmokeDomainSettings { struct SmokeModifierData *smd; /* for fast RNA access */ @@ -55,33 +43,27 @@ typedef struct SmokeDomainSettings { struct Group *fluid_group; struct Group *eff_group; // effector group for e.g. wind force struct Group *coll_group; // collision objects group - unsigned int *bind; - float *tvox; - float *tray; - float *tvoxbig; - float *traybig; + struct GPUTexture *tex; + float *view3d; /* voxel data for display */ + unsigned int v3dnum; /* number of frame in view3d buffer */ float p0[3]; /* start point of BB */ float p1[3]; /* end point of BB */ float dx; /* edge length of one cell */ float firstframe; float lastframe; - float omega; /* smoke color - from 0 to 1 */ float temp; /* fluid temperature */ float tempAmb; /* ambient temperature */ float alpha; float beta; int res[3]; /* domain resolution */ - int amplify; /* wavelet amplification */ int maxres; /* longest axis on the BB gets this resolution assigned */ int flags; /* show up-res or low res, etc */ - int visibility; /* how many billboards to show (every 2nd, 3rd, 4th,..) */ int viewsettings; - int max_textures; - short noise; /* noise type: wave, curl, anisotropic */ short diss_percent; + short pad; int diss_speed;/* in frames */ - float strength; - struct WTURBULENCE *wt; // WTURBULENCE object, if active + struct PointCache *point_cache; /* definition is in DNA_object_force.h */ + struct ListBase ptcaches; } SmokeDomainSettings; diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index e08bc734242..e4fe92317d4 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -387,6 +387,7 @@ extern StructRNA RNA_SmokeCollSettings; extern StructRNA RNA_SmokeDomainSettings; extern StructRNA RNA_SmokeFlowSettings; extern StructRNA RNA_SmokeModifier; +extern StructRNA RNA_SmokeHRModifier; extern StructRNA RNA_SmoothModifier; extern StructRNA RNA_SoftBodyModifier; extern StructRNA RNA_SoftBodySettings; diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 837158b9ec8..f2c8e404a52 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -68,6 +68,7 @@ EnumPropertyItem modifier_type_items[] ={ {eModifierType_Shrinkwrap, "SHRINKWRAP", ICON_MOD_SHRINKWRAP, "Shrinkwrap", ""}, {eModifierType_SimpleDeform, "SIMPLE_DEFORM", ICON_MOD_SIMPLEDEFORM, "Simple Deform", ""}, {eModifierType_Smoke, "SMOKE", 0, "Smoke", ""}, + {eModifierType_SmokeHR, "SMOKE_HR", 0, "SmokeHR", ""}, {eModifierType_Smooth, "SMOOTH", ICON_MOD_SMOOTH, "Smooth", ""}, {eModifierType_Softbody, "SOFT_BODY", ICON_MOD_SOFT, "Soft Body", ""}, {eModifierType_Subsurf, "SUBSURF", ICON_MOD_SUBSURF, "Subdivision Surface", ""}, @@ -156,6 +157,8 @@ static StructRNA* rna_Modifier_refine(struct PointerRNA *ptr) return &RNA_SurfaceModifier; case eModifierType_Smoke: return &RNA_SmokeModifier; + case eModifierType_SmokeHR: + return &RNA_SmokeHRModifier; default: return &RNA_Modifier; } @@ -181,19 +184,30 @@ static void rna_Smoke_set_type(bContext *C, PointerRNA *ptr) { SmokeModifierData *smd= (SmokeModifierData *)ptr->data; Object *ob= (Object*)ptr->id.data; + + // nothing changed + if((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) + return; smokeModifier_free(smd); // XXX TODO: completely free all 3 pointers smokeModifier_createType(smd); // create regarding of selected type - // particle_system_slot_add_exec(C, NULL); - // particle_system_slot_remove_exec(C, NULL); - if(smd->type == MOD_SMOKE_TYPE_DOMAIN) + if(smd->type & MOD_SMOKE_TYPE_DOMAIN) ob->dt = OB_WIRE; // update dependancy since a domain - other type switch could have happened rna_Modifier_dependency_update(C, ptr); } +static void rna_SmokeHR_reset(bContext *C, PointerRNA *ptr) +{ + // SmokeDomainSettings *settings = (SmokeDomainSettings*)ptr->data; + + // smokeModifier_reset(settings->smd); + + // rna_Smoke_update(C, ptr); +} + static void rna_ExplodeModifier_vgroup_get(PointerRNA *ptr, char *value) { ExplodeModifierData *emd= (ExplodeModifierData*)ptr->data; @@ -1499,6 +1513,55 @@ static void rna_def_modifier_cloth(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Point Cache", ""); } +static void rna_def_modifier_smoke_highresolution(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + static EnumPropertyItem prop_noise_type_items[] = { + {MOD_SMOKE_NOISEWAVE, "NOISEWAVE", 0, "Wavelet", ""}, +#if FFTW3 == 1 + {MOD_SMOKE_NOISEFFT, "NOISEFFT", 0, "FFT", ""}, +#endif + /* {MOD_SMOKE_NOISECURL, "NOISECURL", 0, "Curl", ""}, */ + {0, NULL, 0, NULL, NULL}}; + + srna= RNA_def_struct(brna, "SmokeHRModifier", "Modifier"); + RNA_def_struct_ui_text(srna, "Smoke High Resolution Modifier", "Smoke high resolution simulation modifier."); + RNA_def_struct_sdna(srna, "SmokeHRModifierData"); + + prop= RNA_def_property(srna, "show_highres", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_SMOKE_SHOWHIGHRES); + RNA_def_property_ui_text(prop, "High res", "Show high resolution (using amplification)."); + RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); + + prop= RNA_def_property(srna, "noise_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "noise"); + RNA_def_property_enum_items(prop, prop_noise_type_items); + RNA_def_property_ui_text(prop, "Noise Method", "Noise method which is used for creating the high resolution"); + RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_SmokeHR_reset"); + + prop= RNA_def_property(srna, "amplify", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "amplify"); + RNA_def_property_range(prop, 1, 10); + RNA_def_property_ui_range(prop, 1, 10, 1, 0); + RNA_def_property_ui_text(prop, "Amplification", "Enhance the resolution of smoke by this factor using noise."); + RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_SmokeHR_reset"); + + prop= RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "strength"); + RNA_def_property_range(prop, 1.0, 10.0); + RNA_def_property_ui_range(prop, 1.0, 10.0, 1, 2); + RNA_def_property_ui_text(prop, "Strength", "Strength of wavelet noise"); + RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_SmokeHR_reset"); + + prop= RNA_def_property(srna, "point_cache", PROP_POINTER, PROP_NEVER_NULL); + RNA_def_property_pointer_sdna(prop, NULL, "point_cache"); + RNA_def_property_struct_type(prop, "PointCache"); + RNA_def_property_ui_text(prop, "Point Cache", ""); + +} + static void rna_def_modifier_smoke(BlenderRNA *brna) { StructRNA *srna; @@ -1915,6 +1978,7 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_multires(brna); rna_def_modifier_surface(brna); rna_def_modifier_smoke(brna); + rna_def_modifier_smoke_highresolution(brna); } #endif diff --git a/source/blender/makesrna/intern/rna_smoke.c b/source/blender/makesrna/intern/rna_smoke.c index 6f1babb495a..a119eefa62c 100644 --- a/source/blender/makesrna/intern/rna_smoke.c +++ b/source/blender/makesrna/intern/rna_smoke.c @@ -78,11 +78,28 @@ static void rna_Smoke_reset_dependancy(bContext *C, PointerRNA *ptr) rna_Smoke_dependency_update(C, ptr); } +static void rna_Smoke_enable_HR(bContext *C, PointerRNA *ptr) +{ + SmokeDomainSettings *settings = (SmokeDomainSettings*)ptr->data; + Object *ob = (Object*)ptr->id.data; + + if(settings->flags & MOD_SMOKE_HIGHRES) + BLI_addtail(&ob->modifiers, modifier_new(eModifierType_SmokeHR)); + else + { + ModifierData *tmd = modifiers_findByType(ob, eModifierType_SmokeHR); + if(tmd) { + BLI_remlink(&ob->modifiers, tmd); + modifier_free(tmd); + } + } +} + static void rna_Smoke_redraw(bContext *C, PointerRNA *ptr) { SmokeDomainSettings *settings = (SmokeDomainSettings*)ptr->data; - settings->flags |= MOD_SMOKE_VIEW_REDRAWNICE; + // settings->flags |= MOD_SMOKE_VIEW_REDRAWNICE; } static char *rna_SmokeDomainSettings_path(PointerRNA *ptr) @@ -116,14 +133,6 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna) StructRNA *srna; PropertyRNA *prop; - static EnumPropertyItem prop_noise_type_items[] = { - {MOD_SMOKE_NOISEWAVE, "NOISEWAVE", 0, "Wavelet", ""}, -#if FFTW3 == 1 - {MOD_SMOKE_NOISEFFT, "NOISEFFT", 0, "FFT", ""}, -#endif - /* {MOD_SMOKE_NOISECURL, "NOISECURL", 0, "Curl", ""}, */ - {0, NULL, 0, NULL, NULL}}; - srna = RNA_def_struct(brna, "SmokeDomainSettings", NULL); RNA_def_struct_ui_text(srna, "Domain Settings", "Smoke domain settings."); RNA_def_struct_sdna(srna, "SmokeDomainSettings"); @@ -136,56 +145,19 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Max Res", "Maximal resolution used in the fluid domain."); RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset"); - prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "omega"); - RNA_def_property_range(prop, 0.02, 1.0); - RNA_def_property_ui_range(prop, 0.02, 1.0, 0.02, 2); - RNA_def_property_ui_text(prop, "Color", "Smoke color (0 = black, 1 = white)."); - RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Smoke_redraw"); - - prop= RNA_def_property(srna, "amplify", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, NULL, "amplify"); - RNA_def_property_range(prop, 1, 10); - RNA_def_property_ui_range(prop, 1, 10, 1, 0); - RNA_def_property_ui_text(prop, "Amplification", "Enhance the resolution of smoke by this factor using noise."); - RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset"); - - prop= RNA_def_property(srna, "highres", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_SMOKE_HIGHRES); - RNA_def_property_ui_text(prop, "High res", "Enable high resolution (using amplification)."); - RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset"); - - prop= RNA_def_property(srna, "viewhighres", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "viewsettings", MOD_SMOKE_VIEW_USEBIG); - RNA_def_property_ui_text(prop, "Show High Resolution", "Show high resolution (using amplification)."); - RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_redraw"); - - prop= RNA_def_property(srna, "noise_type", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_sdna(prop, NULL, "noise"); - RNA_def_property_enum_items(prop, prop_noise_type_items); - RNA_def_property_ui_text(prop, "Noise Method", "Noise method which is used for creating the high resolution"); - RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset"); - - prop= RNA_def_property(srna, "visibility", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, NULL, "visibility"); - RNA_def_property_range(prop, 1, 15); - RNA_def_property_ui_range(prop, 1, 15, 1, 0); - RNA_def_property_ui_text(prop, "Display", "How much of the resolution should be shown during preview (every 2nd, 3rd, etc)."); - RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Smoke_redraw"); - prop= RNA_def_property(srna, "alpha", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "alpha"); RNA_def_property_range(prop, -5.0, 5.0); RNA_def_property_ui_range(prop, -5.0, 5.0, 0.02, 5); RNA_def_property_ui_text(prop, "Gravity", "Higher value results in sinking smoke"); - RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset"); + RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, NULL); prop= RNA_def_property(srna, "beta", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "beta"); RNA_def_property_range(prop, -5.0, 5.0); RNA_def_property_ui_range(prop, -5.0, 5.0, 0.02, 5); RNA_def_property_ui_text(prop, "Heat", "Higher value results in faster rising smoke."); - RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset"); + RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, NULL); prop= RNA_def_property(srna, "coll_group", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "coll_group"); @@ -208,13 +180,6 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Effector Group", "Limit effectors to this group."); RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset_dependancy"); - prop= RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "strength"); - RNA_def_property_range(prop, 1.0, 10.0); - RNA_def_property_ui_range(prop, 1.0, 10.0, 1, 2); - RNA_def_property_ui_text(prop, "Strength", "Strength of wavelet noise"); - RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset"); - prop= RNA_def_property(srna, "dissolve_speed", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "diss_speed"); RNA_def_property_range(prop, 1.0, 100.0); @@ -222,6 +187,11 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Dissolve Speed", "Dissolve Speed"); RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, NULL); + prop= RNA_def_property(srna, "highres", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_SMOKE_HIGHRES); + RNA_def_property_ui_text(prop, "High Resolution Smoke", "Enable high resolution smoke"); + RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_enable_HR"); + prop= RNA_def_property(srna, "dissolve_smoke", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_SMOKE_DISSOLVE); RNA_def_property_ui_text(prop, "Dissolve Smoke", "Enable smoke to disappear over time."); @@ -231,6 +201,11 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_SMOKE_DISSOLVE_LOG); RNA_def_property_ui_text(prop, "Logarithmic dissolve", "Using 1/x "); RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, NULL); + + prop= RNA_def_property(srna, "point_cache", PROP_POINTER, PROP_NEVER_NULL); + RNA_def_property_pointer_sdna(prop, NULL, "point_cache"); + RNA_def_property_struct_type(prop, "PointCache"); + RNA_def_property_ui_text(prop, "Point Cache", ""); } static void rna_def_smoke_flow_settings(BlenderRNA *brna) diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 3a2cef2d038..3b95c409b30 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -319,6 +319,8 @@ IF(UNIX) bf_dummy bf_bullet bf_smoke + bf_minilzo + bf_lzma bf_common bf_ketsji bf_logic From 89658db5761516d4c07a2b975e3e6e290cd67cea Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Thu, 20 Aug 2009 00:37:27 +0000 Subject: [PATCH 11/73] Fix Smoke #1: * compile error reported by nudelZ (static/nonstatic) --- source/blender/blenkernel/intern/smoke.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 6449ae10eee..9be60a0a975 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -123,7 +123,7 @@ struct DerivedMesh; struct SmokeModifierData; // forward declerations -void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int correct); +static void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int correct); void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *tris, int numfaces, int numtris, int **tridivs, float cell_len); void smoke_prepare_View(SmokeModifierData *smd, float framenr, float *light, int have_light); From 858dbbe232cce6a8e1d13a98385122ff236b146e Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Thu, 20 Aug 2009 00:42:57 +0000 Subject: [PATCH 12/73] Fix Smoke: *totally forgot scons file for lzma --- extern/lzma/SConscript | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 extern/lzma/SConscript diff --git a/extern/lzma/SConscript b/extern/lzma/SConscript new file mode 100644 index 00000000000..015cdfe339f --- /dev/null +++ b/extern/lzma/SConscript @@ -0,0 +1,9 @@ +#!/usr/bin/python +Import ('env') + +sources = env.Glob('./*.c') + +defs = '' +incs = ' . ' + +env.BlenderLib ('bf_lzma', sources, Split(incs), Split(defs), libtype=['intern'], priority=[40] ) From 147bcc92b618701c4906ff99b09da07a5b13a9a4 Mon Sep 17 00:00:00 2001 From: Matt Ebb Date: Thu, 20 Aug 2009 00:54:40 +0000 Subject: [PATCH 13/73] * Library path fixes for win64 --- CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00d2244511f..9db25115099 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -256,7 +256,11 @@ IF(WIN32) SET(ZLIB ${LIBDIR}/zlib) SET(ZLIB_INC ${ZLIB}/include) - SET(ZLIB_LIBRARIES zlib) + IF(CMAKE_CL_64) + SET(ZLIB_LIBRARIES libz) + ELSE(CMAKE_CL_64) + SET(ZLIB_LIBRARIES zlib) + ENDIF(CMAKE_CL_64) SET(ZLIB_LIBPATH ${ZLIB}/lib) SET(PTHREADS ${LIBDIR}/pthreads) @@ -279,7 +283,7 @@ IF(WIN32) SET(GETTEXT ${LIBDIR}/gettext) SET(GETTEXT_INC ${GETTEXT}/include) IF(CMAKE_CL_64) - SET(GETTEXT_LIB gettextlib) + SET(GETTEXT_LIB gettext) ELSE(CMAKE_CL_64) SET(GETTEXT_LIB gnu_gettext) ENDIF(CMAKE_CL_64) From e56c32073d8b4855e9a6b83d281b80d4b0a2aa4d Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Thu, 20 Aug 2009 01:02:34 +0000 Subject: [PATCH 14/73] LZMA: Deleting unused bad files (bad for gcc) --- extern/lzma/7zBuf.c | 36 -- extern/lzma/7zBuf.h | 31 -- extern/lzma/7zBuf2.c | 45 --- extern/lzma/7zCrc.c | 35 -- extern/lzma/7zCrc.h | 24 -- extern/lzma/7zFile.c | 263 ------------- extern/lzma/7zFile.h | 74 ---- extern/lzma/7zStream.c | 169 --------- extern/lzma/7zVersion.h | 7 - extern/lzma/Bcj2.c | 132 ------- extern/lzma/Bcj2.h | 30 -- extern/lzma/Bra.c | 133 ------- extern/lzma/Bra.h | 60 --- extern/lzma/Bra86.c | 85 ----- extern/lzma/BraIA64.c | 67 ---- extern/lzma/CpuArch.h | 69 ---- extern/lzma/LzFindMt.c | 793 ---------------------------------------- extern/lzma/LzFindMt.h | 97 ----- extern/lzma/Threads.c | 109 ------ extern/lzma/Threads.h | 68 ---- 20 files changed, 2327 deletions(-) delete mode 100644 extern/lzma/7zBuf.c delete mode 100644 extern/lzma/7zBuf.h delete mode 100644 extern/lzma/7zBuf2.c delete mode 100644 extern/lzma/7zCrc.c delete mode 100644 extern/lzma/7zCrc.h delete mode 100644 extern/lzma/7zFile.c delete mode 100644 extern/lzma/7zFile.h delete mode 100644 extern/lzma/7zStream.c delete mode 100644 extern/lzma/7zVersion.h delete mode 100644 extern/lzma/Bcj2.c delete mode 100644 extern/lzma/Bcj2.h delete mode 100644 extern/lzma/Bra.c delete mode 100644 extern/lzma/Bra.h delete mode 100644 extern/lzma/Bra86.c delete mode 100644 extern/lzma/BraIA64.c delete mode 100644 extern/lzma/CpuArch.h delete mode 100644 extern/lzma/LzFindMt.c delete mode 100644 extern/lzma/LzFindMt.h delete mode 100644 extern/lzma/Threads.c delete mode 100644 extern/lzma/Threads.h diff --git a/extern/lzma/7zBuf.c b/extern/lzma/7zBuf.c deleted file mode 100644 index 14e7f4e2b92..00000000000 --- a/extern/lzma/7zBuf.c +++ /dev/null @@ -1,36 +0,0 @@ -/* 7zBuf.c -- Byte Buffer -2008-03-28 -Igor Pavlov -Public domain */ - -#include "7zBuf.h" - -void Buf_Init(CBuf *p) -{ - p->data = 0; - p->size = 0; -} - -int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc) -{ - p->size = 0; - if (size == 0) - { - p->data = 0; - return 1; - } - p->data = (Byte *)alloc->Alloc(alloc, size); - if (p->data != 0) - { - p->size = size; - return 1; - } - return 0; -} - -void Buf_Free(CBuf *p, ISzAlloc *alloc) -{ - alloc->Free(alloc, p->data); - p->data = 0; - p->size = 0; -} diff --git a/extern/lzma/7zBuf.h b/extern/lzma/7zBuf.h deleted file mode 100644 index c5bd71879cc..00000000000 --- a/extern/lzma/7zBuf.h +++ /dev/null @@ -1,31 +0,0 @@ -/* 7zBuf.h -- Byte Buffer -2008-10-04 : Igor Pavlov : Public domain */ - -#ifndef __7Z_BUF_H -#define __7Z_BUF_H - -#include "Types.h" - -typedef struct -{ - Byte *data; - size_t size; -} CBuf; - -void Buf_Init(CBuf *p); -int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc); -void Buf_Free(CBuf *p, ISzAlloc *alloc); - -typedef struct -{ - Byte *data; - size_t size; - size_t pos; -} CDynBuf; - -void DynBuf_Construct(CDynBuf *p); -void DynBuf_SeekToBeg(CDynBuf *p); -int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc); -void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc); - -#endif diff --git a/extern/lzma/7zBuf2.c b/extern/lzma/7zBuf2.c deleted file mode 100644 index 8d17e0dcf80..00000000000 --- a/extern/lzma/7zBuf2.c +++ /dev/null @@ -1,45 +0,0 @@ -/* 7zBuf2.c -- Byte Buffer -2008-10-04 : Igor Pavlov : Public domain */ - -#include -#include "7zBuf.h" - -void DynBuf_Construct(CDynBuf *p) -{ - p->data = 0; - p->size = 0; - p->pos = 0; -} - -void DynBuf_SeekToBeg(CDynBuf *p) -{ - p->pos = 0; -} - -int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc) -{ - if (size > p->size - p->pos) - { - size_t newSize = p->pos + size; - Byte *data; - newSize += newSize / 4; - data = (Byte *)alloc->Alloc(alloc, newSize); - if (data == 0) - return 0; - p->size = newSize; - memcpy(data, p->data, p->pos); - alloc->Free(alloc, p->data); - p->data = data; - } - memcpy(p->data + p->pos, buf, size); - p->pos += size; - return 1; -} - -void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc) -{ - alloc->Free(alloc, p->data); - p->data = 0; - p->size = 0; - p->pos = 0; -} diff --git a/extern/lzma/7zCrc.c b/extern/lzma/7zCrc.c deleted file mode 100644 index 71962b2c28d..00000000000 --- a/extern/lzma/7zCrc.c +++ /dev/null @@ -1,35 +0,0 @@ -/* 7zCrc.c -- CRC32 calculation -2008-08-05 -Igor Pavlov -Public domain */ - -#include "7zCrc.h" - -#define kCrcPoly 0xEDB88320 -UInt32 g_CrcTable[256]; - -void MY_FAST_CALL CrcGenerateTable(void) -{ - UInt32 i; - for (i = 0; i < 256; i++) - { - UInt32 r = i; - int j; - for (j = 0; j < 8; j++) - r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1)); - g_CrcTable[i] = r; - } -} - -UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size) -{ - const Byte *p = (const Byte *)data; - for (; size > 0 ; size--, p++) - v = CRC_UPDATE_BYTE(v, *p); - return v; -} - -UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size) -{ - return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF; -} diff --git a/extern/lzma/7zCrc.h b/extern/lzma/7zCrc.h deleted file mode 100644 index 00dc29cee3c..00000000000 --- a/extern/lzma/7zCrc.h +++ /dev/null @@ -1,24 +0,0 @@ -/* 7zCrc.h -- CRC32 calculation -2008-03-13 -Igor Pavlov -Public domain */ - -#ifndef __7Z_CRC_H -#define __7Z_CRC_H - -#include - -#include "Types.h" - -extern UInt32 g_CrcTable[]; - -void MY_FAST_CALL CrcGenerateTable(void); - -#define CRC_INIT_VAL 0xFFFFFFFF -#define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF) -#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) - -UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size); -UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size); - -#endif diff --git a/extern/lzma/7zFile.c b/extern/lzma/7zFile.c deleted file mode 100644 index 9a44c59ac0c..00000000000 --- a/extern/lzma/7zFile.c +++ /dev/null @@ -1,263 +0,0 @@ -/* 7zFile.c -- File IO -2008-11-22 : Igor Pavlov : Public domain */ - -#include "7zFile.h" - -#ifndef USE_WINDOWS_FILE - -#include - -#endif - -#ifdef USE_WINDOWS_FILE - -/* - ReadFile and WriteFile functions in Windows have BUG: - If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) - from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES - (Insufficient system resources exist to complete the requested service). - Probably in some version of Windows there are problems with other sizes: - for 32 MB (maybe also for 16 MB). - And message can be "Network connection was lost" -*/ - -#define kChunkSizeMax (1 << 22) - -#endif - -void File_Construct(CSzFile *p) -{ - #ifdef USE_WINDOWS_FILE - p->handle = INVALID_HANDLE_VALUE; - #else - p->file = NULL; - #endif -} - -static WRes File_Open(CSzFile *p, const char *name, int writeMode) -{ - #ifdef USE_WINDOWS_FILE - p->handle = CreateFileA(name, - writeMode ? GENERIC_WRITE : GENERIC_READ, - FILE_SHARE_READ, NULL, - writeMode ? CREATE_ALWAYS : OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, NULL); - return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError(); - #else - p->file = fopen(name, writeMode ? "wb+" : "rb"); - return (p->file != 0) ? 0 : errno; - #endif -} - -WRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); } -WRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); } - -WRes File_Close(CSzFile *p) -{ - #ifdef USE_WINDOWS_FILE - if (p->handle != INVALID_HANDLE_VALUE) - { - if (!CloseHandle(p->handle)) - return GetLastError(); - p->handle = INVALID_HANDLE_VALUE; - } - #else - if (p->file != NULL) - { - int res = fclose(p->file); - if (res != 0) - return res; - p->file = NULL; - } - #endif - return 0; -} - -WRes File_Read(CSzFile *p, void *data, size_t *size) -{ - size_t originalSize = *size; - if (originalSize == 0) - return 0; - - #ifdef USE_WINDOWS_FILE - - *size = 0; - do - { - DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize; - DWORD processed = 0; - BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL); - data = (void *)((Byte *)data + processed); - originalSize -= processed; - *size += processed; - if (!res) - return GetLastError(); - if (processed == 0) - break; - } - while (originalSize > 0); - return 0; - - #else - - *size = fread(data, 1, originalSize, p->file); - if (*size == originalSize) - return 0; - return ferror(p->file); - - #endif -} - -WRes File_Write(CSzFile *p, const void *data, size_t *size) -{ - size_t originalSize = *size; - if (originalSize == 0) - return 0; - - #ifdef USE_WINDOWS_FILE - - *size = 0; - do - { - DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize; - DWORD processed = 0; - BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL); - data = (void *)((Byte *)data + processed); - originalSize -= processed; - *size += processed; - if (!res) - return GetLastError(); - if (processed == 0) - break; - } - while (originalSize > 0); - return 0; - - #else - - *size = fwrite(data, 1, originalSize, p->file); - if (*size == originalSize) - return 0; - return ferror(p->file); - - #endif -} - -WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin) -{ - #ifdef USE_WINDOWS_FILE - - LARGE_INTEGER value; - DWORD moveMethod; - value.LowPart = (DWORD)*pos; - value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */ - switch (origin) - { - case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break; - case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break; - case SZ_SEEK_END: moveMethod = FILE_END; break; - default: return ERROR_INVALID_PARAMETER; - } - value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod); - if (value.LowPart == 0xFFFFFFFF) - { - WRes res = GetLastError(); - if (res != NO_ERROR) - return res; - } - *pos = ((Int64)value.HighPart << 32) | value.LowPart; - return 0; - - #else - - int moveMethod; - int res; - switch (origin) - { - case SZ_SEEK_SET: moveMethod = SEEK_SET; break; - case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break; - case SZ_SEEK_END: moveMethod = SEEK_END; break; - default: return 1; - } - res = fseek(p->file, (long)*pos, moveMethod); - *pos = ftell(p->file); - return res; - - #endif -} - -WRes File_GetLength(CSzFile *p, UInt64 *length) -{ - #ifdef USE_WINDOWS_FILE - - DWORD sizeHigh; - DWORD sizeLow = GetFileSize(p->handle, &sizeHigh); - if (sizeLow == 0xFFFFFFFF) - { - DWORD res = GetLastError(); - if (res != NO_ERROR) - return res; - } - *length = (((UInt64)sizeHigh) << 32) + sizeLow; - return 0; - - #else - - long pos = ftell(p->file); - int res = fseek(p->file, 0, SEEK_END); - *length = ftell(p->file); - fseek(p->file, pos, SEEK_SET); - return res; - - #endif -} - - -/* ---------- FileSeqInStream ---------- */ - -static SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size) -{ - CFileSeqInStream *p = (CFileSeqInStream *)pp; - return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ; -} - -void FileSeqInStream_CreateVTable(CFileSeqInStream *p) -{ - p->s.Read = FileSeqInStream_Read; -} - - -/* ---------- FileInStream ---------- */ - -static SRes FileInStream_Read(void *pp, void *buf, size_t *size) -{ - CFileInStream *p = (CFileInStream *)pp; - return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ; -} - -static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin) -{ - CFileInStream *p = (CFileInStream *)pp; - return File_Seek(&p->file, pos, origin); -} - -void FileInStream_CreateVTable(CFileInStream *p) -{ - p->s.Read = FileInStream_Read; - p->s.Seek = FileInStream_Seek; -} - - -/* ---------- FileOutStream ---------- */ - -static size_t FileOutStream_Write(void *pp, const void *data, size_t size) -{ - CFileOutStream *p = (CFileOutStream *)pp; - File_Write(&p->file, data, &size); - return size; -} - -void FileOutStream_CreateVTable(CFileOutStream *p) -{ - p->s.Write = FileOutStream_Write; -} diff --git a/extern/lzma/7zFile.h b/extern/lzma/7zFile.h deleted file mode 100644 index fbef6837f86..00000000000 --- a/extern/lzma/7zFile.h +++ /dev/null @@ -1,74 +0,0 @@ -/* 7zFile.h -- File IO -2008-11-22 : Igor Pavlov : Public domain */ - -#ifndef __7Z_FILE_H -#define __7Z_FILE_H - -#ifdef _WIN32 -#define USE_WINDOWS_FILE -#endif - -#ifdef USE_WINDOWS_FILE -#include -#else -#include -#endif - -#include "Types.h" - - -/* ---------- File ---------- */ - -typedef struct -{ - #ifdef USE_WINDOWS_FILE - HANDLE handle; - #else - FILE *file; - #endif -} CSzFile; - -void File_Construct(CSzFile *p); -WRes InFile_Open(CSzFile *p, const char *name); -WRes OutFile_Open(CSzFile *p, const char *name); -WRes File_Close(CSzFile *p); - -/* reads max(*size, remain file's size) bytes */ -WRes File_Read(CSzFile *p, void *data, size_t *size); - -/* writes *size bytes */ -WRes File_Write(CSzFile *p, const void *data, size_t *size); - -WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin); -WRes File_GetLength(CSzFile *p, UInt64 *length); - - -/* ---------- FileInStream ---------- */ - -typedef struct -{ - ISeqInStream s; - CSzFile file; -} CFileSeqInStream; - -void FileSeqInStream_CreateVTable(CFileSeqInStream *p); - - -typedef struct -{ - ISeekInStream s; - CSzFile file; -} CFileInStream; - -void FileInStream_CreateVTable(CFileInStream *p); - - -typedef struct -{ - ISeqOutStream s; - CSzFile file; -} CFileOutStream; - -void FileOutStream_CreateVTable(CFileOutStream *p); - -#endif diff --git a/extern/lzma/7zStream.c b/extern/lzma/7zStream.c deleted file mode 100644 index 86232aa3411..00000000000 --- a/extern/lzma/7zStream.c +++ /dev/null @@ -1,169 +0,0 @@ -/* 7zStream.c -- 7z Stream functions -2008-11-23 : Igor Pavlov : Public domain */ - -#include - -#include "Types.h" - -SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType) -{ - while (size != 0) - { - size_t processed = size; - RINOK(stream->Read(stream, buf, &processed)); - if (processed == 0) - return errorType; - buf = (void *)((Byte *)buf + processed); - size -= processed; - } - return SZ_OK; -} - -SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size) -{ - return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); -} - -SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf) -{ - size_t processed = 1; - RINOK(stream->Read(stream, buf, &processed)); - return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF; -} - -SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset) -{ - Int64 t = offset; - return stream->Seek(stream, &t, SZ_SEEK_SET); -} - -SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size) -{ - void *lookBuf; - if (*size == 0) - return SZ_OK; - RINOK(stream->Look(stream, &lookBuf, size)); - memcpy(buf, lookBuf, *size); - return stream->Skip(stream, *size); -} - -SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType) -{ - while (size != 0) - { - size_t processed = size; - RINOK(stream->Read(stream, buf, &processed)); - if (processed == 0) - return errorType; - buf = (void *)((Byte *)buf + processed); - size -= processed; - } - return SZ_OK; -} - -SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size) -{ - return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); -} - -static SRes LookToRead_Look_Lookahead(void *pp, void **buf, size_t *size) -{ - SRes res = SZ_OK; - CLookToRead *p = (CLookToRead *)pp; - size_t size2 = p->size - p->pos; - if (size2 == 0 && *size > 0) - { - p->pos = 0; - size2 = LookToRead_BUF_SIZE; - res = p->realStream->Read(p->realStream, p->buf, &size2); - p->size = size2; - } - if (size2 < *size) - *size = size2; - *buf = p->buf + p->pos; - return res; -} - -static SRes LookToRead_Look_Exact(void *pp, void **buf, size_t *size) -{ - SRes res = SZ_OK; - CLookToRead *p = (CLookToRead *)pp; - size_t size2 = p->size - p->pos; - if (size2 == 0 && *size > 0) - { - p->pos = 0; - if (*size > LookToRead_BUF_SIZE) - *size = LookToRead_BUF_SIZE; - res = p->realStream->Read(p->realStream, p->buf, size); - size2 = p->size = *size; - } - if (size2 < *size) - *size = size2; - *buf = p->buf + p->pos; - return res; -} - -static SRes LookToRead_Skip(void *pp, size_t offset) -{ - CLookToRead *p = (CLookToRead *)pp; - p->pos += offset; - return SZ_OK; -} - -static SRes LookToRead_Read(void *pp, void *buf, size_t *size) -{ - CLookToRead *p = (CLookToRead *)pp; - size_t rem = p->size - p->pos; - if (rem == 0) - return p->realStream->Read(p->realStream, buf, size); - if (rem > *size) - rem = *size; - memcpy(buf, p->buf + p->pos, rem); - p->pos += rem; - *size = rem; - return SZ_OK; -} - -static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin) -{ - CLookToRead *p = (CLookToRead *)pp; - p->pos = p->size = 0; - return p->realStream->Seek(p->realStream, pos, origin); -} - -void LookToRead_CreateVTable(CLookToRead *p, int lookahead) -{ - p->s.Look = lookahead ? - LookToRead_Look_Lookahead : - LookToRead_Look_Exact; - p->s.Skip = LookToRead_Skip; - p->s.Read = LookToRead_Read; - p->s.Seek = LookToRead_Seek; -} - -void LookToRead_Init(CLookToRead *p) -{ - p->pos = p->size = 0; -} - -static SRes SecToLook_Read(void *pp, void *buf, size_t *size) -{ - CSecToLook *p = (CSecToLook *)pp; - return LookInStream_LookRead(p->realStream, buf, size); -} - -void SecToLook_CreateVTable(CSecToLook *p) -{ - p->s.Read = SecToLook_Read; -} - -static SRes SecToRead_Read(void *pp, void *buf, size_t *size) -{ - CSecToRead *p = (CSecToRead *)pp; - return p->realStream->Read(p->realStream, buf, size); -} - -void SecToRead_CreateVTable(CSecToRead *p) -{ - p->s.Read = SecToRead_Read; -} diff --git a/extern/lzma/7zVersion.h b/extern/lzma/7zVersion.h deleted file mode 100644 index b7eb235548f..00000000000 --- a/extern/lzma/7zVersion.h +++ /dev/null @@ -1,7 +0,0 @@ -#define MY_VER_MAJOR 4 -#define MY_VER_MINOR 65 -#define MY_VER_BUILD 0 -#define MY_VERSION "4.65" -#define MY_DATE "2009-02-03" -#define MY_COPYRIGHT ": Igor Pavlov : Public domain" -#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE diff --git a/extern/lzma/Bcj2.c b/extern/lzma/Bcj2.c deleted file mode 100644 index 20199ce5659..00000000000 --- a/extern/lzma/Bcj2.c +++ /dev/null @@ -1,132 +0,0 @@ -/* Bcj2.c -- Converter for x86 code (BCJ2) -2008-10-04 : Igor Pavlov : Public domain */ - -#include "Bcj2.h" - -#ifdef _LZMA_PROB32 -#define CProb UInt32 -#else -#define CProb UInt16 -#endif - -#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80) -#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)) - -#define kNumTopBits 24 -#define kTopValue ((UInt32)1 << kNumTopBits) - -#define kNumBitModelTotalBits 11 -#define kBitModelTotal (1 << kNumBitModelTotalBits) -#define kNumMoveBits 5 - -#define RC_READ_BYTE (*buffer++) -#define RC_TEST { if (buffer == bufferLim) return SZ_ERROR_DATA; } -#define RC_INIT2 code = 0; range = 0xFFFFFFFF; \ - { int i; for (i = 0; i < 5; i++) { RC_TEST; code = (code << 8) | RC_READ_BYTE; }} - -#define NORMALIZE if (range < kTopValue) { RC_TEST; range <<= 8; code = (code << 8) | RC_READ_BYTE; } - -#define IF_BIT_0(p) ttt = *(p); bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound) -#define UPDATE_0(p) range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE; -#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE; - -int Bcj2_Decode( - const Byte *buf0, SizeT size0, - const Byte *buf1, SizeT size1, - const Byte *buf2, SizeT size2, - const Byte *buf3, SizeT size3, - Byte *outBuf, SizeT outSize) -{ - CProb p[256 + 2]; - SizeT inPos = 0, outPos = 0; - - const Byte *buffer, *bufferLim; - UInt32 range, code; - Byte prevByte = 0; - - unsigned int i; - for (i = 0; i < sizeof(p) / sizeof(p[0]); i++) - p[i] = kBitModelTotal >> 1; - - buffer = buf3; - bufferLim = buffer + size3; - RC_INIT2 - - if (outSize == 0) - return SZ_OK; - - for (;;) - { - Byte b; - CProb *prob; - UInt32 bound; - UInt32 ttt; - - SizeT limit = size0 - inPos; - if (outSize - outPos < limit) - limit = outSize - outPos; - while (limit != 0) - { - Byte b = buf0[inPos]; - outBuf[outPos++] = b; - if (IsJ(prevByte, b)) - break; - inPos++; - prevByte = b; - limit--; - } - - if (limit == 0 || outPos == outSize) - break; - - b = buf0[inPos++]; - - if (b == 0xE8) - prob = p + prevByte; - else if (b == 0xE9) - prob = p + 256; - else - prob = p + 257; - - IF_BIT_0(prob) - { - UPDATE_0(prob) - prevByte = b; - } - else - { - UInt32 dest; - const Byte *v; - UPDATE_1(prob) - if (b == 0xE8) - { - v = buf1; - if (size1 < 4) - return SZ_ERROR_DATA; - buf1 += 4; - size1 -= 4; - } - else - { - v = buf2; - if (size2 < 4) - return SZ_ERROR_DATA; - buf2 += 4; - size2 -= 4; - } - dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) | - ((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4); - outBuf[outPos++] = (Byte)dest; - if (outPos == outSize) - break; - outBuf[outPos++] = (Byte)(dest >> 8); - if (outPos == outSize) - break; - outBuf[outPos++] = (Byte)(dest >> 16); - if (outPos == outSize) - break; - outBuf[outPos++] = prevByte = (Byte)(dest >> 24); - } - } - return (outPos == outSize) ? SZ_OK : SZ_ERROR_DATA; -} diff --git a/extern/lzma/Bcj2.h b/extern/lzma/Bcj2.h deleted file mode 100644 index 32d450b3b99..00000000000 --- a/extern/lzma/Bcj2.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Bcj2.h -- Converter for x86 code (BCJ2) -2008-10-04 : Igor Pavlov : Public domain */ - -#ifndef __BCJ2_H -#define __BCJ2_H - -#include "Types.h" - -/* -Conditions: - outSize <= FullOutputSize, - where FullOutputSize is full size of output stream of x86_2 filter. - -If buf0 overlaps outBuf, there are two required conditions: - 1) (buf0 >= outBuf) - 2) (buf0 + size0 >= outBuf + FullOutputSize). - -Returns: - SZ_OK - SZ_ERROR_DATA - Data error -*/ - -int Bcj2_Decode( - const Byte *buf0, SizeT size0, - const Byte *buf1, SizeT size1, - const Byte *buf2, SizeT size2, - const Byte *buf3, SizeT size3, - Byte *outBuf, SizeT outSize); - -#endif diff --git a/extern/lzma/Bra.c b/extern/lzma/Bra.c deleted file mode 100644 index 5e5469592db..00000000000 --- a/extern/lzma/Bra.c +++ /dev/null @@ -1,133 +0,0 @@ -/* Bra.c -- Converters for RISC code -2008-10-04 : Igor Pavlov : Public domain */ - -#include "Bra.h" - -SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) -{ - SizeT i; - if (size < 4) - return 0; - size -= 4; - ip += 8; - for (i = 0; i <= size; i += 4) - { - if (data[i + 3] == 0xEB) - { - UInt32 dest; - UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]); - src <<= 2; - if (encoding) - dest = ip + (UInt32)i + src; - else - dest = src - (ip + (UInt32)i); - dest >>= 2; - data[i + 2] = (Byte)(dest >> 16); - data[i + 1] = (Byte)(dest >> 8); - data[i + 0] = (Byte)dest; - } - } - return i; -} - -SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) -{ - SizeT i; - if (size < 4) - return 0; - size -= 4; - ip += 4; - for (i = 0; i <= size; i += 2) - { - if ((data[i + 1] & 0xF8) == 0xF0 && - (data[i + 3] & 0xF8) == 0xF8) - { - UInt32 dest; - UInt32 src = - (((UInt32)data[i + 1] & 0x7) << 19) | - ((UInt32)data[i + 0] << 11) | - (((UInt32)data[i + 3] & 0x7) << 8) | - (data[i + 2]); - - src <<= 1; - if (encoding) - dest = ip + (UInt32)i + src; - else - dest = src - (ip + (UInt32)i); - dest >>= 1; - - data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7)); - data[i + 0] = (Byte)(dest >> 11); - data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7)); - data[i + 2] = (Byte)dest; - i += 2; - } - } - return i; -} - -SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) -{ - SizeT i; - if (size < 4) - return 0; - size -= 4; - for (i = 0; i <= size; i += 4) - { - if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1) - { - UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) | - ((UInt32)data[i + 1] << 16) | - ((UInt32)data[i + 2] << 8) | - ((UInt32)data[i + 3] & (~3)); - - UInt32 dest; - if (encoding) - dest = ip + (UInt32)i + src; - else - dest = src - (ip + (UInt32)i); - data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3)); - data[i + 1] = (Byte)(dest >> 16); - data[i + 2] = (Byte)(dest >> 8); - data[i + 3] &= 0x3; - data[i + 3] |= dest; - } - } - return i; -} - -SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) -{ - UInt32 i; - if (size < 4) - return 0; - size -= 4; - for (i = 0; i <= size; i += 4) - { - if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 || - data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0) - { - UInt32 src = - ((UInt32)data[i + 0] << 24) | - ((UInt32)data[i + 1] << 16) | - ((UInt32)data[i + 2] << 8) | - ((UInt32)data[i + 3]); - UInt32 dest; - - src <<= 2; - if (encoding) - dest = ip + i + src; - else - dest = src - (ip + i); - dest >>= 2; - - dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000; - - data[i + 0] = (Byte)(dest >> 24); - data[i + 1] = (Byte)(dest >> 16); - data[i + 2] = (Byte)(dest >> 8); - data[i + 3] = (Byte)dest; - } - } - return i; -} diff --git a/extern/lzma/Bra.h b/extern/lzma/Bra.h deleted file mode 100644 index 45e231e8496..00000000000 --- a/extern/lzma/Bra.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Bra.h -- Branch converters for executables -2008-10-04 : Igor Pavlov : Public domain */ - -#ifndef __BRA_H -#define __BRA_H - -#include "Types.h" - -/* -These functions convert relative addresses to absolute addresses -in CALL instructions to increase the compression ratio. - - In: - data - data buffer - size - size of data - ip - current virtual Instruction Pinter (IP) value - state - state variable for x86 converter - encoding - 0 (for decoding), 1 (for encoding) - - Out: - state - state variable for x86 converter - - Returns: - The number of processed bytes. If you call these functions with multiple calls, - you must start next call with first byte after block of processed bytes. - - Type Endian Alignment LookAhead - - x86 little 1 4 - ARMT little 2 2 - ARM little 4 0 - PPC big 4 0 - SPARC big 4 0 - IA64 little 16 0 - - size must be >= Alignment + LookAhead, if it's not last block. - If (size < Alignment + LookAhead), converter returns 0. - - Example: - - UInt32 ip = 0; - for () - { - ; size must be >= Alignment + LookAhead, if it's not last block - SizeT processed = Convert(data, size, ip, 1); - data += processed; - size -= processed; - ip += processed; - } -*/ - -#define x86_Convert_Init(state) { state = 0; } -SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding); -SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); -SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); -SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); -SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); -SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); - -#endif diff --git a/extern/lzma/Bra86.c b/extern/lzma/Bra86.c deleted file mode 100644 index 1ee0e709b88..00000000000 --- a/extern/lzma/Bra86.c +++ /dev/null @@ -1,85 +0,0 @@ -/* Bra86.c -- Converter for x86 code (BCJ) -2008-10-04 : Igor Pavlov : Public domain */ - -#include "Bra.h" - -#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF) - -const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0}; -const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3}; - -SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding) -{ - SizeT bufferPos = 0, prevPosT; - UInt32 prevMask = *state & 0x7; - if (size < 5) - return 0; - ip += 5; - prevPosT = (SizeT)0 - 1; - - for (;;) - { - Byte *p = data + bufferPos; - Byte *limit = data + size - 4; - for (; p < limit; p++) - if ((*p & 0xFE) == 0xE8) - break; - bufferPos = (SizeT)(p - data); - if (p >= limit) - break; - prevPosT = bufferPos - prevPosT; - if (prevPosT > 3) - prevMask = 0; - else - { - prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7; - if (prevMask != 0) - { - Byte b = p[4 - kMaskToBitNumber[prevMask]]; - if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b)) - { - prevPosT = bufferPos; - prevMask = ((prevMask << 1) & 0x7) | 1; - bufferPos++; - continue; - } - } - } - prevPosT = bufferPos; - - if (Test86MSByte(p[4])) - { - UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]); - UInt32 dest; - for (;;) - { - Byte b; - int index; - if (encoding) - dest = (ip + (UInt32)bufferPos) + src; - else - dest = src - (ip + (UInt32)bufferPos); - if (prevMask == 0) - break; - index = kMaskToBitNumber[prevMask] * 8; - b = (Byte)(dest >> (24 - index)); - if (!Test86MSByte(b)) - break; - src = dest ^ ((1 << (32 - index)) - 1); - } - p[4] = (Byte)(~(((dest >> 24) & 1) - 1)); - p[3] = (Byte)(dest >> 16); - p[2] = (Byte)(dest >> 8); - p[1] = (Byte)dest; - bufferPos += 5; - } - else - { - prevMask = ((prevMask << 1) & 0x7) | 1; - bufferPos++; - } - } - prevPosT = bufferPos - prevPosT; - *state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7)); - return bufferPos; -} diff --git a/extern/lzma/BraIA64.c b/extern/lzma/BraIA64.c deleted file mode 100644 index 0b4ee85bc76..00000000000 --- a/extern/lzma/BraIA64.c +++ /dev/null @@ -1,67 +0,0 @@ -/* BraIA64.c -- Converter for IA-64 code -2008-10-04 : Igor Pavlov : Public domain */ - -#include "Bra.h" - -static const Byte kBranchTable[32] = -{ - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 4, 4, 6, 6, 0, 0, 7, 7, - 4, 4, 0, 0, 4, 4, 0, 0 -}; - -SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) -{ - SizeT i; - if (size < 16) - return 0; - size -= 16; - for (i = 0; i <= size; i += 16) - { - UInt32 instrTemplate = data[i] & 0x1F; - UInt32 mask = kBranchTable[instrTemplate]; - UInt32 bitPos = 5; - int slot; - for (slot = 0; slot < 3; slot++, bitPos += 41) - { - UInt32 bytePos, bitRes; - UInt64 instruction, instNorm; - int j; - if (((mask >> slot) & 1) == 0) - continue; - bytePos = (bitPos >> 3); - bitRes = bitPos & 0x7; - instruction = 0; - for (j = 0; j < 6; j++) - instruction += (UInt64)data[i + j + bytePos] << (8 * j); - - instNorm = instruction >> bitRes; - if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0) - { - UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF); - UInt32 dest; - src |= ((UInt32)(instNorm >> 36) & 1) << 20; - - src <<= 4; - - if (encoding) - dest = ip + (UInt32)i + src; - else - dest = src - (ip + (UInt32)i); - - dest >>= 4; - - instNorm &= ~((UInt64)(0x8FFFFF) << 13); - instNorm |= ((UInt64)(dest & 0xFFFFF) << 13); - instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20)); - - instruction &= (1 << bitRes) - 1; - instruction |= (instNorm << bitRes); - for (j = 0; j < 6; j++) - data[i + j + bytePos] = (Byte)(instruction >> (8 * j)); - } - } - } - return i; -} diff --git a/extern/lzma/CpuArch.h b/extern/lzma/CpuArch.h deleted file mode 100644 index 7384b0c32ae..00000000000 --- a/extern/lzma/CpuArch.h +++ /dev/null @@ -1,69 +0,0 @@ -/* CpuArch.h -2008-08-05 -Igor Pavlov -Public domain */ - -#ifndef __CPUARCH_H -#define __CPUARCH_H - -/* -LITTLE_ENDIAN_UNALIGN means: - 1) CPU is LITTLE_ENDIAN - 2) it's allowed to make unaligned memory accesses -if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know -about these properties of platform. -*/ - -#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__) -#define LITTLE_ENDIAN_UNALIGN -#endif - -#ifdef LITTLE_ENDIAN_UNALIGN - -#define GetUi16(p) (*(const UInt16 *)(p)) -#define GetUi32(p) (*(const UInt32 *)(p)) -#define GetUi64(p) (*(const UInt64 *)(p)) -#define SetUi32(p, d) *(UInt32 *)(p) = (d); - -#else - -#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8)) - -#define GetUi32(p) ( \ - ((const Byte *)(p))[0] | \ - ((UInt32)((const Byte *)(p))[1] << 8) | \ - ((UInt32)((const Byte *)(p))[2] << 16) | \ - ((UInt32)((const Byte *)(p))[3] << 24)) - -#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32)) - -#define SetUi32(p, d) { UInt32 _x_ = (d); \ - ((Byte *)(p))[0] = (Byte)_x_; \ - ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \ - ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \ - ((Byte *)(p))[3] = (Byte)(_x_ >> 24); } - -#endif - -#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300) - -#pragma intrinsic(_byteswap_ulong) -#pragma intrinsic(_byteswap_uint64) -#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p)) -#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p)) - -#else - -#define GetBe32(p) ( \ - ((UInt32)((const Byte *)(p))[0] << 24) | \ - ((UInt32)((const Byte *)(p))[1] << 16) | \ - ((UInt32)((const Byte *)(p))[2] << 8) | \ - ((const Byte *)(p))[3] ) - -#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4)) - -#endif - -#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1]) - -#endif diff --git a/extern/lzma/LzFindMt.c b/extern/lzma/LzFindMt.c deleted file mode 100644 index b49cd76b294..00000000000 --- a/extern/lzma/LzFindMt.c +++ /dev/null @@ -1,793 +0,0 @@ -/* LzFindMt.c -- multithreaded Match finder for LZ algorithms -2008-10-04 : Igor Pavlov : Public domain */ - -#include "LzHash.h" - -#include "LzFindMt.h" - -void MtSync_Construct(CMtSync *p) -{ - p->wasCreated = False; - p->csWasInitialized = False; - p->csWasEntered = False; - Thread_Construct(&p->thread); - Event_Construct(&p->canStart); - Event_Construct(&p->wasStarted); - Event_Construct(&p->wasStopped); - Semaphore_Construct(&p->freeSemaphore); - Semaphore_Construct(&p->filledSemaphore); -} - -void MtSync_GetNextBlock(CMtSync *p) -{ - if (p->needStart) - { - p->numProcessedBlocks = 1; - p->needStart = False; - p->stopWriting = False; - p->exit = False; - Event_Reset(&p->wasStarted); - Event_Reset(&p->wasStopped); - - Event_Set(&p->canStart); - Event_Wait(&p->wasStarted); - } - else - { - CriticalSection_Leave(&p->cs); - p->csWasEntered = False; - p->numProcessedBlocks++; - Semaphore_Release1(&p->freeSemaphore); - } - Semaphore_Wait(&p->filledSemaphore); - CriticalSection_Enter(&p->cs); - p->csWasEntered = True; -} - -/* MtSync_StopWriting must be called if Writing was started */ - -void MtSync_StopWriting(CMtSync *p) -{ - UInt32 myNumBlocks = p->numProcessedBlocks; - if (!Thread_WasCreated(&p->thread) || p->needStart) - return; - p->stopWriting = True; - if (p->csWasEntered) - { - CriticalSection_Leave(&p->cs); - p->csWasEntered = False; - } - Semaphore_Release1(&p->freeSemaphore); - - Event_Wait(&p->wasStopped); - - while (myNumBlocks++ != p->numProcessedBlocks) - { - Semaphore_Wait(&p->filledSemaphore); - Semaphore_Release1(&p->freeSemaphore); - } - p->needStart = True; -} - -void MtSync_Destruct(CMtSync *p) -{ - if (Thread_WasCreated(&p->thread)) - { - MtSync_StopWriting(p); - p->exit = True; - if (p->needStart) - Event_Set(&p->canStart); - Thread_Wait(&p->thread); - Thread_Close(&p->thread); - } - if (p->csWasInitialized) - { - CriticalSection_Delete(&p->cs); - p->csWasInitialized = False; - } - - Event_Close(&p->canStart); - Event_Close(&p->wasStarted); - Event_Close(&p->wasStopped); - Semaphore_Close(&p->freeSemaphore); - Semaphore_Close(&p->filledSemaphore); - - p->wasCreated = False; -} - -#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; } - -static SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks) -{ - if (p->wasCreated) - return SZ_OK; - - RINOK_THREAD(CriticalSection_Init(&p->cs)); - p->csWasInitialized = True; - - RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart)); - RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted)); - RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped)); - - RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks)); - RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks)); - - p->needStart = True; - - RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj)); - p->wasCreated = True; - return SZ_OK; -} - -static SRes MtSync_Create(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks) -{ - SRes res = MtSync_Create2(p, startAddress, obj, numBlocks); - if (res != SZ_OK) - MtSync_Destruct(p); - return res; -} - -void MtSync_Init(CMtSync *p) { p->needStart = True; } - -#define kMtMaxValForNormalize 0xFFFFFFFF - -#define DEF_GetHeads2(name, v, action) \ -static void GetHeads ## name(const Byte *p, UInt32 pos, \ -UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \ -{ action; for (; numHeads != 0; numHeads--) { \ -const UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++; } } - -#define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;) - -DEF_GetHeads2(2, (p[0] | ((UInt32)p[1] << 8)), hashMask = hashMask; crc = crc; ) -DEF_GetHeads(3, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask) -DEF_GetHeads(4, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask) -DEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask) -DEF_GetHeads(5, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask) - -void HashThreadFunc(CMatchFinderMt *mt) -{ - CMtSync *p = &mt->hashSync; - for (;;) - { - UInt32 numProcessedBlocks = 0; - Event_Wait(&p->canStart); - Event_Set(&p->wasStarted); - for (;;) - { - if (p->exit) - return; - if (p->stopWriting) - { - p->numProcessedBlocks = numProcessedBlocks; - Event_Set(&p->wasStopped); - break; - } - - { - CMatchFinder *mf = mt->MatchFinder; - if (MatchFinder_NeedMove(mf)) - { - CriticalSection_Enter(&mt->btSync.cs); - CriticalSection_Enter(&mt->hashSync.cs); - { - const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf); - const Byte *afterPtr; - MatchFinder_MoveBlock(mf); - afterPtr = MatchFinder_GetPointerToCurrentPos(mf); - mt->pointerToCurPos -= beforePtr - afterPtr; - mt->buffer -= beforePtr - afterPtr; - } - CriticalSection_Leave(&mt->btSync.cs); - CriticalSection_Leave(&mt->hashSync.cs); - continue; - } - - Semaphore_Wait(&p->freeSemaphore); - - MatchFinder_ReadIfRequired(mf); - if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize)) - { - UInt32 subValue = (mf->pos - mf->historySize - 1); - MatchFinder_ReduceOffsets(mf, subValue); - MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1); - } - { - UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize; - UInt32 num = mf->streamPos - mf->pos; - heads[0] = 2; - heads[1] = num; - if (num >= mf->numHashBytes) - { - num = num - mf->numHashBytes + 1; - if (num > kMtHashBlockSize - 2) - num = kMtHashBlockSize - 2; - mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc); - heads[0] += num; - } - mf->pos += num; - mf->buffer += num; - } - } - - Semaphore_Release1(&p->filledSemaphore); - } - } -} - -void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p) -{ - MtSync_GetNextBlock(&p->hashSync); - p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize; - p->hashBufPosLimit += p->hashBuf[p->hashBufPos++]; - p->hashNumAvail = p->hashBuf[p->hashBufPos++]; -} - -#define kEmptyHashValue 0 - -/* #define MFMT_GM_INLINE */ - -#ifdef MFMT_GM_INLINE - -#define NO_INLINE MY_FAST_CALL - -Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son, - UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, - UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes) -{ - do - { - UInt32 *distances = _distances + 1; - UInt32 curMatch = pos - *hash++; - - CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1; - CLzRef *ptr1 = son + (_cyclicBufferPos << 1); - UInt32 len0 = 0, len1 = 0; - UInt32 cutValue = _cutValue; - UInt32 maxLen = _maxLen; - for (;;) - { - UInt32 delta = pos - curMatch; - if (cutValue-- == 0 || delta >= _cyclicBufferSize) - { - *ptr0 = *ptr1 = kEmptyHashValue; - break; - } - { - CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1); - const Byte *pb = cur - delta; - UInt32 len = (len0 < len1 ? len0 : len1); - if (pb[len] == cur[len]) - { - if (++len != lenLimit && pb[len] == cur[len]) - while (++len != lenLimit) - if (pb[len] != cur[len]) - break; - if (maxLen < len) - { - *distances++ = maxLen = len; - *distances++ = delta - 1; - if (len == lenLimit) - { - *ptr1 = pair[0]; - *ptr0 = pair[1]; - break; - } - } - } - if (pb[len] < cur[len]) - { - *ptr1 = curMatch; - ptr1 = pair + 1; - curMatch = *ptr1; - len1 = len; - } - else - { - *ptr0 = curMatch; - ptr0 = pair; - curMatch = *ptr0; - len0 = len; - } - } - } - pos++; - _cyclicBufferPos++; - cur++; - { - UInt32 num = (UInt32)(distances - _distances); - *_distances = num - 1; - _distances += num; - limit -= num; - } - } - while (limit > 0 && --size != 0); - *posRes = pos; - return limit; -} - -#endif - -void BtGetMatches(CMatchFinderMt *p, UInt32 *distances) -{ - UInt32 numProcessed = 0; - UInt32 curPos = 2; - UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2); - distances[1] = p->hashNumAvail; - while (curPos < limit) - { - if (p->hashBufPos == p->hashBufPosLimit) - { - MatchFinderMt_GetNextBlock_Hash(p); - distances[1] = numProcessed + p->hashNumAvail; - if (p->hashNumAvail >= p->numHashBytes) - continue; - for (; p->hashNumAvail != 0; p->hashNumAvail--) - distances[curPos++] = 0; - break; - } - { - UInt32 size = p->hashBufPosLimit - p->hashBufPos; - UInt32 lenLimit = p->matchMaxLen; - UInt32 pos = p->pos; - UInt32 cyclicBufferPos = p->cyclicBufferPos; - if (lenLimit >= p->hashNumAvail) - lenLimit = p->hashNumAvail; - { - UInt32 size2 = p->hashNumAvail - lenLimit + 1; - if (size2 < size) - size = size2; - size2 = p->cyclicBufferSize - cyclicBufferPos; - if (size2 < size) - size = size2; - } - #ifndef MFMT_GM_INLINE - while (curPos < limit && size-- != 0) - { - UInt32 *startDistances = distances + curPos; - UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++], - pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue, - startDistances + 1, p->numHashBytes - 1) - startDistances); - *startDistances = num - 1; - curPos += num; - cyclicBufferPos++; - pos++; - p->buffer++; - } - #else - { - UInt32 posRes; - curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue, - distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes); - p->hashBufPos += posRes - pos; - cyclicBufferPos += posRes - pos; - p->buffer += posRes - pos; - pos = posRes; - } - #endif - - numProcessed += pos - p->pos; - p->hashNumAvail -= pos - p->pos; - p->pos = pos; - if (cyclicBufferPos == p->cyclicBufferSize) - cyclicBufferPos = 0; - p->cyclicBufferPos = cyclicBufferPos; - } - } - distances[0] = curPos; -} - -void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex) -{ - CMtSync *sync = &p->hashSync; - if (!sync->needStart) - { - CriticalSection_Enter(&sync->cs); - sync->csWasEntered = True; - } - - BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize); - - if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize) - { - UInt32 subValue = p->pos - p->cyclicBufferSize; - MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2); - p->pos -= subValue; - } - - if (!sync->needStart) - { - CriticalSection_Leave(&sync->cs); - sync->csWasEntered = False; - } -} - -void BtThreadFunc(CMatchFinderMt *mt) -{ - CMtSync *p = &mt->btSync; - for (;;) - { - UInt32 blockIndex = 0; - Event_Wait(&p->canStart); - Event_Set(&p->wasStarted); - for (;;) - { - if (p->exit) - return; - if (p->stopWriting) - { - p->numProcessedBlocks = blockIndex; - MtSync_StopWriting(&mt->hashSync); - Event_Set(&p->wasStopped); - break; - } - Semaphore_Wait(&p->freeSemaphore); - BtFillBlock(mt, blockIndex++); - Semaphore_Release1(&p->filledSemaphore); - } - } -} - -void MatchFinderMt_Construct(CMatchFinderMt *p) -{ - p->hashBuf = 0; - MtSync_Construct(&p->hashSync); - MtSync_Construct(&p->btSync); -} - -void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc) -{ - alloc->Free(alloc, p->hashBuf); - p->hashBuf = 0; -} - -void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc) -{ - MtSync_Destruct(&p->hashSync); - MtSync_Destruct(&p->btSync); - MatchFinderMt_FreeMem(p, alloc); -} - -#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks) -#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks) - -static unsigned MY_STD_CALL HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p); return 0; } -static unsigned MY_STD_CALL BtThreadFunc2(void *p) -{ - Byte allocaDummy[0x180]; - int i = 0; - for (i = 0; i < 16; i++) - allocaDummy[i] = (Byte)i; - BtThreadFunc((CMatchFinderMt *)p); - return 0; -} - -SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, - UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc) -{ - CMatchFinder *mf = p->MatchFinder; - p->historySize = historySize; - if (kMtBtBlockSize <= matchMaxLen * 4) - return SZ_ERROR_PARAM; - if (p->hashBuf == 0) - { - p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32)); - if (p->hashBuf == 0) - return SZ_ERROR_MEM; - p->btBuf = p->hashBuf + kHashBufferSize; - } - keepAddBufferBefore += (kHashBufferSize + kBtBufferSize); - keepAddBufferAfter += kMtHashBlockSize; - if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc)) - return SZ_ERROR_MEM; - - RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks)); - RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks)); - return SZ_OK; -} - -/* Call it after ReleaseStream / SetStream */ -void MatchFinderMt_Init(CMatchFinderMt *p) -{ - CMatchFinder *mf = p->MatchFinder; - p->btBufPos = p->btBufPosLimit = 0; - p->hashBufPos = p->hashBufPosLimit = 0; - MatchFinder_Init(mf); - p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf); - p->btNumAvailBytes = 0; - p->lzPos = p->historySize + 1; - - p->hash = mf->hash; - p->fixedHashSize = mf->fixedHashSize; - p->crc = mf->crc; - - p->son = mf->son; - p->matchMaxLen = mf->matchMaxLen; - p->numHashBytes = mf->numHashBytes; - p->pos = mf->pos; - p->buffer = mf->buffer; - p->cyclicBufferPos = mf->cyclicBufferPos; - p->cyclicBufferSize = mf->cyclicBufferSize; - p->cutValue = mf->cutValue; -} - -/* ReleaseStream is required to finish multithreading */ -void MatchFinderMt_ReleaseStream(CMatchFinderMt *p) -{ - MtSync_StopWriting(&p->btSync); - /* p->MatchFinder->ReleaseStream(); */ -} - -void MatchFinderMt_Normalize(CMatchFinderMt *p) -{ - MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize); - p->lzPos = p->historySize + 1; -} - -void MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p) -{ - UInt32 blockIndex; - MtSync_GetNextBlock(&p->btSync); - blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask); - p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize; - p->btBufPosLimit += p->btBuf[p->btBufPos++]; - p->btNumAvailBytes = p->btBuf[p->btBufPos++]; - if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize) - MatchFinderMt_Normalize(p); -} - -const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p) -{ - return p->pointerToCurPos; -} - -#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p); - -UInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p) -{ - GET_NEXT_BLOCK_IF_REQUIRED; - return p->btNumAvailBytes; -} - -Byte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index) -{ - return p->pointerToCurPos[index]; -} - -UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances) -{ - UInt32 hash2Value, curMatch2; - UInt32 *hash = p->hash; - const Byte *cur = p->pointerToCurPos; - UInt32 lzPos = p->lzPos; - MT_HASH2_CALC - - curMatch2 = hash[hash2Value]; - hash[hash2Value] = lzPos; - - if (curMatch2 >= matchMinPos) - if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0]) - { - *distances++ = 2; - *distances++ = lzPos - curMatch2 - 1; - } - return distances; -} - -UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances) -{ - UInt32 hash2Value, hash3Value, curMatch2, curMatch3; - UInt32 *hash = p->hash; - const Byte *cur = p->pointerToCurPos; - UInt32 lzPos = p->lzPos; - MT_HASH3_CALC - - curMatch2 = hash[ hash2Value]; - curMatch3 = hash[kFix3HashSize + hash3Value]; - - hash[ hash2Value] = - hash[kFix3HashSize + hash3Value] = - lzPos; - - if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0]) - { - distances[1] = lzPos - curMatch2 - 1; - if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2]) - { - distances[0] = 3; - return distances + 2; - } - distances[0] = 2; - distances += 2; - } - if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0]) - { - *distances++ = 3; - *distances++ = lzPos - curMatch3 - 1; - } - return distances; -} - -/* -UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances) -{ - UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4; - UInt32 *hash = p->hash; - const Byte *cur = p->pointerToCurPos; - UInt32 lzPos = p->lzPos; - MT_HASH4_CALC - - curMatch2 = hash[ hash2Value]; - curMatch3 = hash[kFix3HashSize + hash3Value]; - curMatch4 = hash[kFix4HashSize + hash4Value]; - - hash[ hash2Value] = - hash[kFix3HashSize + hash3Value] = - hash[kFix4HashSize + hash4Value] = - lzPos; - - if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0]) - { - distances[1] = lzPos - curMatch2 - 1; - if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2]) - { - distances[0] = (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3; - return distances + 2; - } - distances[0] = 2; - distances += 2; - } - if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0]) - { - distances[1] = lzPos - curMatch3 - 1; - if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3]) - { - distances[0] = 4; - return distances + 2; - } - distances[0] = 3; - distances += 2; - } - - if (curMatch4 >= matchMinPos) - if ( - cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] && - cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3] - ) - { - *distances++ = 4; - *distances++ = lzPos - curMatch4 - 1; - } - return distances; -} -*/ - -#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++; - -UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances) -{ - const UInt32 *btBuf = p->btBuf + p->btBufPos; - UInt32 len = *btBuf++; - p->btBufPos += 1 + len; - p->btNumAvailBytes--; - { - UInt32 i; - for (i = 0; i < len; i += 2) - { - *distances++ = *btBuf++; - *distances++ = *btBuf++; - } - } - INCREASE_LZ_POS - return len; -} - -UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances) -{ - const UInt32 *btBuf = p->btBuf + p->btBufPos; - UInt32 len = *btBuf++; - p->btBufPos += 1 + len; - - if (len == 0) - { - if (p->btNumAvailBytes-- >= 4) - len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances)); - } - else - { - /* Condition: there are matches in btBuf with length < p->numHashBytes */ - UInt32 *distances2; - p->btNumAvailBytes--; - distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances); - do - { - *distances2++ = *btBuf++; - *distances2++ = *btBuf++; - } - while ((len -= 2) != 0); - len = (UInt32)(distances2 - (distances)); - } - INCREASE_LZ_POS - return len; -} - -#define SKIP_HEADER2 do { GET_NEXT_BLOCK_IF_REQUIRED -#define SKIP_HEADER(n) SKIP_HEADER2 if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash; -#define SKIP_FOOTER } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num != 0); - -void MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num) -{ - SKIP_HEADER2 { p->btNumAvailBytes--; - SKIP_FOOTER -} - -void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num) -{ - SKIP_HEADER(2) - UInt32 hash2Value; - MT_HASH2_CALC - hash[hash2Value] = p->lzPos; - SKIP_FOOTER -} - -void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num) -{ - SKIP_HEADER(3) - UInt32 hash2Value, hash3Value; - MT_HASH3_CALC - hash[kFix3HashSize + hash3Value] = - hash[ hash2Value] = - p->lzPos; - SKIP_FOOTER -} - -/* -void MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num) -{ - SKIP_HEADER(4) - UInt32 hash2Value, hash3Value, hash4Value; - MT_HASH4_CALC - hash[kFix4HashSize + hash4Value] = - hash[kFix3HashSize + hash3Value] = - hash[ hash2Value] = - p->lzPos; - SKIP_FOOTER -} -*/ - -void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable) -{ - vTable->Init = (Mf_Init_Func)MatchFinderMt_Init; - vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte; - vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes; - vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos; - vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches; - switch(p->MatchFinder->numHashBytes) - { - case 2: - p->GetHeadsFunc = GetHeads2; - p->MixMatchesFunc = (Mf_Mix_Matches)0; - vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip; - vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches; - break; - case 3: - p->GetHeadsFunc = GetHeads3; - p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2; - vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip; - break; - default: - /* case 4: */ - p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4; - /* p->GetHeadsFunc = GetHeads4; */ - p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3; - vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip; - break; - /* - default: - p->GetHeadsFunc = GetHeads5; - p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4; - vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip; - break; - */ - } -} diff --git a/extern/lzma/LzFindMt.h b/extern/lzma/LzFindMt.h deleted file mode 100644 index 2c7e462d592..00000000000 --- a/extern/lzma/LzFindMt.h +++ /dev/null @@ -1,97 +0,0 @@ -/* LzFindMt.h -- multithreaded Match finder for LZ algorithms -2008-10-04 : Igor Pavlov : Public domain */ - -#ifndef __LZFINDMT_H -#define __LZFINDMT_H - -#include "Threads.h" -#include "LzFind.h" - -#define kMtHashBlockSize (1 << 13) -#define kMtHashNumBlocks (1 << 3) -#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1) - -#define kMtBtBlockSize (1 << 14) -#define kMtBtNumBlocks (1 << 6) -#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1) - -typedef struct _CMtSync -{ - Bool wasCreated; - Bool needStart; - Bool exit; - Bool stopWriting; - - CThread thread; - CAutoResetEvent canStart; - CAutoResetEvent wasStarted; - CAutoResetEvent wasStopped; - CSemaphore freeSemaphore; - CSemaphore filledSemaphore; - Bool csWasInitialized; - Bool csWasEntered; - CCriticalSection cs; - UInt32 numProcessedBlocks; -} CMtSync; - -typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances); - -/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */ -#define kMtCacheLineDummy 128 - -typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos, - UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc); - -typedef struct _CMatchFinderMt -{ - /* LZ */ - const Byte *pointerToCurPos; - UInt32 *btBuf; - UInt32 btBufPos; - UInt32 btBufPosLimit; - UInt32 lzPos; - UInt32 btNumAvailBytes; - - UInt32 *hash; - UInt32 fixedHashSize; - UInt32 historySize; - const UInt32 *crc; - - Mf_Mix_Matches MixMatchesFunc; - - /* LZ + BT */ - CMtSync btSync; - Byte btDummy[kMtCacheLineDummy]; - - /* BT */ - UInt32 *hashBuf; - UInt32 hashBufPos; - UInt32 hashBufPosLimit; - UInt32 hashNumAvail; - - CLzRef *son; - UInt32 matchMaxLen; - UInt32 numHashBytes; - UInt32 pos; - Byte *buffer; - UInt32 cyclicBufferPos; - UInt32 cyclicBufferSize; /* it must be historySize + 1 */ - UInt32 cutValue; - - /* BT + Hash */ - CMtSync hashSync; - /* Byte hashDummy[kMtCacheLineDummy]; */ - - /* Hash */ - Mf_GetHeads GetHeadsFunc; - CMatchFinder *MatchFinder; -} CMatchFinderMt; - -void MatchFinderMt_Construct(CMatchFinderMt *p); -void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc); -SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, - UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc); -void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable); -void MatchFinderMt_ReleaseStream(CMatchFinderMt *p); - -#endif diff --git a/extern/lzma/Threads.c b/extern/lzma/Threads.c deleted file mode 100644 index 4fdd69b0d5c..00000000000 --- a/extern/lzma/Threads.c +++ /dev/null @@ -1,109 +0,0 @@ -/* Threads.c -- multithreading library -2008-08-05 -Igor Pavlov -Public domain */ - -#include "Threads.h" -#include - -static WRes GetError() -{ - DWORD res = GetLastError(); - return (res) ? (WRes)(res) : 1; -} - -WRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); } -WRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); } - -static WRes MyCloseHandle(HANDLE *h) -{ - if (*h != NULL) - if (!CloseHandle(*h)) - return GetError(); - *h = NULL; - return 0; -} - -WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter) -{ - unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */ - thread->handle = - /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */ - (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId); - /* maybe we must use errno here, but probably GetLastError() is also OK. */ - return HandleToWRes(thread->handle); -} - -WRes WaitObject(HANDLE h) -{ - return (WRes)WaitForSingleObject(h, INFINITE); -} - -WRes Thread_Wait(CThread *thread) -{ - if (thread->handle == NULL) - return 1; - return WaitObject(thread->handle); -} - -WRes Thread_Close(CThread *thread) -{ - return MyCloseHandle(&thread->handle); -} - -WRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled) -{ - p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL); - return HandleToWRes(p->handle); -} - -WRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled) - { return Event_Create(p, TRUE, initialSignaled); } -WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p) - { return ManualResetEvent_Create(p, 0); } - -WRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled) - { return Event_Create(p, FALSE, initialSignaled); } -WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) - { return AutoResetEvent_Create(p, 0); } - -WRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(p->handle)); } -WRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(p->handle)); } -WRes Event_Wait(CEvent *p) { return WaitObject(p->handle); } -WRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); } - - -WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount) -{ - p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL); - return HandleToWRes(p->handle); -} - -WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount) -{ - return BOOLToWRes(ReleaseSemaphore(p->handle, releaseCount, previousCount)); -} -WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount) -{ - return Semaphore_Release(p, (LONG)releaseCount, NULL); -} -WRes Semaphore_Release1(CSemaphore *p) -{ - return Semaphore_ReleaseN(p, 1); -} - -WRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); } -WRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); } - -WRes CriticalSection_Init(CCriticalSection *p) -{ - /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */ - __try - { - InitializeCriticalSection(p); - /* InitializeCriticalSectionAndSpinCount(p, 0); */ - } - __except (EXCEPTION_EXECUTE_HANDLER) { return 1; } - return 0; -} - diff --git a/extern/lzma/Threads.h b/extern/lzma/Threads.h deleted file mode 100644 index a823e57858a..00000000000 --- a/extern/lzma/Threads.h +++ /dev/null @@ -1,68 +0,0 @@ -/* Threads.h -- multithreading library -2008-11-22 : Igor Pavlov : Public domain */ - -#ifndef __7Z_THRESDS_H -#define __7Z_THRESDS_H - -#include "Types.h" - -typedef struct _CThread -{ - HANDLE handle; -} CThread; - -#define Thread_Construct(thread) (thread)->handle = NULL -#define Thread_WasCreated(thread) ((thread)->handle != NULL) - -typedef unsigned THREAD_FUNC_RET_TYPE; -#define THREAD_FUNC_CALL_TYPE MY_STD_CALL -#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE - -WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter); -WRes Thread_Wait(CThread *thread); -WRes Thread_Close(CThread *thread); - -typedef struct _CEvent -{ - HANDLE handle; -} CEvent; - -typedef CEvent CAutoResetEvent; -typedef CEvent CManualResetEvent; - -#define Event_Construct(event) (event)->handle = NULL -#define Event_IsCreated(event) ((event)->handle != NULL) - -WRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled); -WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event); -WRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled); -WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event); -WRes Event_Set(CEvent *event); -WRes Event_Reset(CEvent *event); -WRes Event_Wait(CEvent *event); -WRes Event_Close(CEvent *event); - - -typedef struct _CSemaphore -{ - HANDLE handle; -} CSemaphore; - -#define Semaphore_Construct(p) (p)->handle = NULL - -WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount); -WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num); -WRes Semaphore_Release1(CSemaphore *p); -WRes Semaphore_Wait(CSemaphore *p); -WRes Semaphore_Close(CSemaphore *p); - - -typedef CRITICAL_SECTION CCriticalSection; - -WRes CriticalSection_Init(CCriticalSection *p); -#define CriticalSection_Delete(p) DeleteCriticalSection(p) -#define CriticalSection_Enter(p) EnterCriticalSection(p) -#define CriticalSection_Leave(p) LeaveCriticalSection(p) - -#endif - From 2878eed1c125d07bcfc893eb04d1307c6aa19e3a Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Thu, 20 Aug 2009 01:22:07 +0000 Subject: [PATCH 15/73] Fix Smoke: * Making it less verbose --- source/blender/blenkernel/intern/smoke.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 9be60a0a975..7af67364bc5 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -591,7 +591,7 @@ void smokeModifier_reset(struct SmokeModifierData *smd) smd->domain->point_cache->simframe= 0; smd->domain->point_cache->last_exact= 0; - printf("reset_domain\n"); + // printf("reset_domain\n"); } else if(smd->flow) { @@ -763,7 +763,7 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM float light[3] = {0.0,0.0,0.0}; int have_lamp = 0; - printf("smd->type & MOD_SMOKE_TYPE_DOMAIN\n"); + // printf("smd->type & MOD_SMOKE_TYPE_DOMAIN\n"); framenr = scene->r.cfra; @@ -813,7 +813,7 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM /* try to read from cache */ cache_result = BKE_ptcache_read_cache(&pid, (float)framenr, scene->r.frs_sec); - printf("cache_result: %d\n", cache_result); + // printf("cache_result: %d\n", cache_result); if(cache_result == PTCACHE_READ_EXACT) { @@ -885,7 +885,7 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM BKE_ptcache_write_cache(&pid, framenr); - printf("Writing cache_low\n"); + // printf("Writing cache_low\n"); tend(); From 7dfc1317acc63aea67d4ebd5db8d64c5bef4b8c8 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Thu, 20 Aug 2009 05:13:07 +0000 Subject: [PATCH 16/73] 2.5/Paint: * Converted vertex paint to use the new stroke system. Now supports the same smooth stroke and stroke spacing as sculpt mode. * Refactored the paint cursor a bit, just sculpt for now but other modes soon. * A couple warning fixes --- release/ui/space_view3d_toolbar.py | 2 +- source/blender/blenkernel/BKE_paint.h | 2 +- source/blender/blenkernel/intern/paint.c | 13 +- source/blender/editors/object/object_edit.c | 40 ++++-- .../editors/sculpt_paint/paint_image.c | 2 +- .../editors/sculpt_paint/paint_intern.h | 4 + .../blender/editors/sculpt_paint/paint_ops.c | 6 - .../editors/sculpt_paint/paint_stroke.c | 76 +++++++++++ .../editors/sculpt_paint/paint_vertex.c | 127 +++++++++--------- source/blender/editors/sculpt_paint/sculpt.c | 60 ++------- source/blender/gpu/GPU_draw.h | 1 + source/blender/makesdna/DNA_scene_types.h | 8 +- source/blender/makesrna/intern/rna_space.c | 2 +- source/blender/windowmanager/WM_types.h | 5 + .../windowmanager/intern/wm_operators.c | 2 +- 15 files changed, 207 insertions(+), 143 deletions(-) diff --git a/release/ui/space_view3d_toolbar.py b/release/ui/space_view3d_toolbar.py index 1b4c1e25c34..5d882866e96 100644 --- a/release/ui/space_view3d_toolbar.py +++ b/release/ui/space_view3d_toolbar.py @@ -429,7 +429,7 @@ class VIEW3D_PT_tools_brush_stroke(PaintPanel): def poll(self, context): settings = self.paint_settings(context) - return (settings and settings.brush and context.sculpt_object) + return (settings and settings.brush and (context.sculpt_object or context.vertex_paint_object)) def draw(self, context): settings = self.paint_settings(context) diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 67b260b2348..45d2e24c7f6 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -33,7 +33,7 @@ struct Object; struct Paint; struct Scene; -void paint_init(struct Paint *p, const char *brush_name); +void paint_init(struct Paint *p, const char *col); void free_paint(struct Paint *p); void copy_paint(struct Paint *orig, struct Paint *new); diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 80016f23d7c..f0893e058fa 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -154,14 +154,23 @@ int paint_facesel_test(Object *ob) } -void paint_init(Paint *p, const char *name) +void paint_init(Paint *p, const char *col) { Brush *brush; /* If there's no brush, create one */ brush = paint_brush(p); - brush_check_exists(&brush, name); + brush_check_exists(&brush, "Brush"); paint_brush_set(p, brush); + + if(col) + memcpy(p->paint_cursor_col, col, 3); + else { + p->paint_cursor_col[0] = 255; + p->paint_cursor_col[1] = 255; + p->paint_cursor_col[2] = 255; + } + p->paint_cursor_col[3] = 128; } void free_paint(Paint *paint) diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index f8d969d2462..39fd6433548 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -7073,6 +7073,25 @@ static EnumPropertyItem *object_mode_set_itemsf(bContext *C, PointerRNA *ptr, in return item; } +static const char *object_mode_op_string(int mode) +{ + if(mode == OB_MODE_EDIT) + return "OBJECT_OT_editmode_toggle"; + if(mode == OB_MODE_SCULPT) + return "SCULPT_OT_sculptmode_toggle"; + if(mode == OB_MODE_VERTEX_PAINT) + return "PAINT_OT_vertex_paint_toggle"; + if(mode == OB_MODE_WEIGHT_PAINT) + return "PAINT_OT_weight_paint_toggle"; + if(mode == OB_MODE_TEXTURE_PAINT) + return "PAINT_OT_texture_paint_toggle"; + if(mode == OB_MODE_PARTICLE_EDIT) + return "PARTICLE_OT_particle_edit_toggle"; + if(mode == OB_MODE_POSE) + return "OBJECT_OT_posemode_toggle"; + return NULL; +} + static int object_mode_set_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); @@ -7081,20 +7100,13 @@ static int object_mode_set_exec(bContext *C, wmOperator *op) if(!ob) return OPERATOR_CANCELLED; - if((mode == OB_MODE_EDIT) == !(ob->mode & OB_MODE_EDIT)) - WM_operator_name_call(C, "OBJECT_OT_editmode_toggle", WM_OP_EXEC_REGION_WIN, NULL); - if((mode == OB_MODE_SCULPT) == !(ob->mode & OB_MODE_SCULPT)) - WM_operator_name_call(C, "SCULPT_OT_sculptmode_toggle", WM_OP_EXEC_REGION_WIN, NULL); - if((mode == OB_MODE_VERTEX_PAINT) == !(ob->mode & OB_MODE_VERTEX_PAINT)) - WM_operator_name_call(C, "PAINT_OT_vertex_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL); - if((mode == OB_MODE_WEIGHT_PAINT) == !(ob->mode & OB_MODE_WEIGHT_PAINT)) - WM_operator_name_call(C, "PAINT_OT_weight_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL); - if((mode == OB_MODE_TEXTURE_PAINT) == !(ob->mode & OB_MODE_TEXTURE_PAINT)) - WM_operator_name_call(C, "PAINT_OT_texture_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL); - if((mode == OB_MODE_PARTICLE_EDIT) == !(ob->mode & OB_MODE_PARTICLE_EDIT)) - WM_operator_name_call(C, "PARTICLE_OT_particle_edit_toggle", WM_OP_EXEC_REGION_WIN, NULL); - if((mode == OB_MODE_POSE) == !(ob->mode & OB_MODE_POSE)) - WM_operator_name_call(C, "OBJECT_OT_posemode_toggle", WM_OP_EXEC_REGION_WIN, NULL); + /* Exit off current mode */ + if(ob->mode != OB_MODE_OBJECT) + WM_operator_name_call(C, object_mode_op_string(ob->mode), WM_OP_EXEC_REGION_WIN, NULL); + + /* Enter new mode */ + if(mode != OB_MODE_OBJECT) + WM_operator_name_call(C, object_mode_op_string(mode), WM_OP_EXEC_REGION_WIN, NULL); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 465aa281e25..8a8041abbff 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -5174,7 +5174,7 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) me->mtface= CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DEFAULT, NULL, me->totface); - paint_init(&scene->toolsettings->imapaint.paint, "Brush"); + paint_init(&scene->toolsettings->imapaint.paint, NULL); if(U.glreslimit != 0) GPU_free_images(); diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 41764a70686..c6c93026c44 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -50,6 +50,10 @@ struct PaintStroke *paint_stroke_new(bContext *C, StrokeTestStart test_start, StrokeUpdateStep update_step, StrokeDone done); int paint_stroke_modal(struct bContext *C, struct wmOperator *op, struct wmEvent *event); struct ViewContext *paint_stroke_view_context(struct PaintStroke *stroke); +void *paint_stroke_mode_data(struct PaintStroke *stroke); +void paint_stroke_set_mode_data(struct PaintStroke *stroke, void *mode_data); +int paint_poll(bContext *C); +void paint_cursor_start(struct bContext *C, int (*poll)(struct bContext *C)); /* paint_vertex.c */ void PAINT_OT_weight_paint_toggle(struct wmOperatorType *ot); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 63a6591d057..1ea612c0aa5 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -77,12 +77,6 @@ void BRUSH_OT_add(wmOperatorType *ot) RNA_def_enum(ot->srna, "type", brush_type_items, OB_MODE_VERTEX_PAINT, "Type", "Which paint mode to create the brush for."); } -/* Paint operators */ -static int paint_poll(bContext *C) -{ - return !!paint_get_active(CTX_data_scene(C)); -} - /**************************** registration **********************************/ void ED_operatortypes_paint(void) diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 634b82674b5..1167e011c86 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -43,6 +43,7 @@ #include "BLI_arithb.h" +#include "BIF_gl.h" #include "BIF_glutil.h" #include "ED_screen.h" @@ -54,6 +55,9 @@ #include typedef struct PaintStroke { + void *mode_data; + void *smooth_stroke_cursor; + /* Cached values */ ViewContext vc; bglMats mats; @@ -71,6 +75,42 @@ typedef struct PaintStroke { StrokeDone done; } PaintStroke; +/*** Cursor ***/ +static void paint_draw_smooth_stroke(bContext *C, int x, int y, void *customdata) +{ + Brush *brush = paint_brush(paint_get_active(CTX_data_scene(C))); + PaintStroke *stroke = customdata; + + glColor4ubv(paint_get_active(CTX_data_scene(C))->paint_cursor_col); + glEnable(GL_LINE_SMOOTH); + glEnable(GL_BLEND); + + if(stroke && brush && (brush->flag & BRUSH_SMOOTH_STROKE)) { + ARegion *ar = CTX_wm_region(C); + sdrawline(x, y, (int)stroke->last_mouse_position[0] - ar->winrct.xmin, + (int)stroke->last_mouse_position[1] - ar->winrct.ymin); + } + + glDisable(GL_BLEND); + glDisable(GL_LINE_SMOOTH); +} + +static void paint_draw_cursor(bContext *C, int x, int y, void *customdata) +{ + Brush *brush = paint_brush(paint_get_active(CTX_data_scene(C))); + + glColor4ubv(paint_get_active(CTX_data_scene(C))->paint_cursor_col); + glEnable(GL_LINE_SMOOTH); + glEnable(GL_BLEND); + + glTranslatef((float)x, (float)y, 0.0f); + glutil_draw_lined_arc(0.0, M_PI*2.0, brush->size, 40); + glTranslatef((float)-x, (float)-y, 0.0f); + + glDisable(GL_BLEND); + glDisable(GL_LINE_SMOOTH); +} + /* Put the location of the next stroke dot into the stroke RNA and apply it to the mesh */ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *event, float mouse[2]) { @@ -191,6 +231,11 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event) stroke->last_mouse_position[0] = event->x; stroke->last_mouse_position[1] = event->y; stroke->stroke_started = stroke->test_start(C, op, event); + + if(stroke->stroke_started) + stroke->smooth_stroke_cursor = + WM_paint_cursor_activate(CTX_wm_manager(C), paint_poll, paint_draw_smooth_stroke, stroke); + ED_region_tag_redraw(ar); } @@ -209,6 +254,9 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event) /* TODO: fix hardcoded event here */ if(event->type == LEFTMOUSE && event->val == 0) { + if(stroke->smooth_stroke_cursor) + WM_paint_cursor_end(CTX_wm_manager(C), stroke->smooth_stroke_cursor); + stroke->done(C, stroke); MEM_freeN(stroke); return OPERATOR_FINISHED; @@ -222,3 +270,31 @@ ViewContext *paint_stroke_view_context(PaintStroke *stroke) return &stroke->vc; } +void *paint_stroke_mode_data(struct PaintStroke *stroke) +{ + return stroke->mode_data; +} + +void paint_stroke_set_mode_data(PaintStroke *stroke, void *mode_data) +{ + stroke->mode_data = mode_data; +} + +int paint_poll(bContext *C) +{ + Paint *p = paint_get_active(CTX_data_scene(C)); + Object *ob = CTX_data_active_object(C); + + return p && ob && paint_brush(p) && + CTX_wm_area(C)->spacetype == SPACE_VIEW3D && + CTX_wm_region(C)->regiontype == RGN_TYPE_WINDOW; +} + +void paint_cursor_start(bContext *C, int (*poll)(bContext *C)) +{ + Paint *p = paint_get_active(CTX_data_scene(C)); + + if(p && !p->paint_cursor) + p->paint_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), poll, paint_draw_cursor, NULL); +} + diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 05faa47e0f4..19f0293c1b8 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -62,6 +62,7 @@ #include "DNA_userdef_types.h" #include "RNA_access.h" +#include "RNA_define.h" #include "BKE_armature.h" #include "BKE_brush.h" @@ -91,6 +92,8 @@ #include "ED_util.h" #include "ED_view3d.h" +#include "paint_intern.h" + /* vp->mode */ #define VP_MIX 0 #define VP_ADD 1 @@ -807,7 +810,7 @@ static int sample_backbuf_area(ViewContext *vc, int *indexar, int totface, int x return tot; } -static int calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], float *vert_nor, short *mval) +static int calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], float *vert_nor, float *mval) { Brush *brush = paint_brush(&vp->paint); float fac, dx, dy; @@ -1124,7 +1127,7 @@ static int set_wpaint(bContext *C, wmOperator *op) /* toggle */ if(wp==NULL) wp= scene->toolsettings->wpaint= new_vpaint(1); - paint_init(&wp->paint, "Brush"); + paint_init(&wp->paint, NULL); toggle_paint_cursor(C, 1); @@ -1329,7 +1332,7 @@ static int wpaint_modal(bContext *C, wmOperator *op, wmEvent *event) float paintweight= ts->vgroup_weight; int *indexar= wpd->indexar; int totindex, index, alpha, totw; - short mval[2]; + float mval[2]; view3d_operator_needs_opengl(C); @@ -1634,7 +1637,7 @@ static int set_vpaint(bContext *C, wmOperator *op) /* toggle */ toggle_paint_cursor(C, 0); - paint_init(&vp->paint, "Brush"); + paint_init(&vp->paint, NULL); } if (me) @@ -1693,25 +1696,47 @@ struct VPaintData { float vpimat[3][3]; }; -static void vpaint_exit(bContext *C, wmOperator *op) +static int vpaint_stroke_test_start(bContext *C, struct wmOperator *op, wmEvent *event) { ToolSettings *ts= CTX_data_tool_settings(C); - struct VPaintData *vpd= op->customdata; + struct PaintStroke *stroke = op->customdata; + VPaint *vp= ts->vpaint; + struct VPaintData *vpd; + Object *ob= CTX_data_active_object(C); + Mesh *me; + float mat[4][4], imat[4][4]; + + /* context checks could be a poll() */ + me= get_mesh(ob); + if(me==NULL || me->totface==0) return OPERATOR_PASS_THROUGH; - if(vpd->vertexcosnos) - MEM_freeN(vpd->vertexcosnos); - MEM_freeN(vpd->indexar); + if(me->mcol==NULL) make_vertexcol(CTX_data_scene(C), 0); + if(me->mcol==NULL) return OPERATOR_CANCELLED; - /* frees prev buffer */ - copy_vpaint_prev(ts->vpaint, NULL, 0); + /* make mode data storage */ + vpd= MEM_callocN(sizeof(struct VPaintData), "VPaintData"); + paint_stroke_set_mode_data(stroke, vpd); + view3d_set_viewcontext(C, &vpd->vc); - MEM_freeN(vpd); - op->customdata= NULL; + vpd->vertexcosnos= mesh_get_mapped_verts_nors(vpd->vc.scene, ob); + vpd->indexar= get_indexarray(); + vpd->paintcol= vpaint_get_current_col(vp); + + /* for filtering */ + copy_vpaint_prev(vp, (unsigned int *)me->mcol, me->totface); + + /* some old cruft to sort out later */ + Mat4MulMat4(mat, ob->obmat, vpd->vc.rv3d->viewmat); + Mat4Invert(imat, mat); + Mat3CpyMat4(vpd->vpimat, imat); + + return 1; } -static void vpaint_dot(bContext *C, struct VPaintData *vpd, wmEvent *event) +static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr) { ToolSettings *ts= CTX_data_tool_settings(C); + struct VPaintData *vpd = paint_stroke_mode_data(stroke); VPaint *vp= ts->vpaint; Brush *brush = paint_brush(&vp->paint); ViewContext *vc= &vpd->vc; @@ -1720,7 +1745,9 @@ static void vpaint_dot(bContext *C, struct VPaintData *vpd, wmEvent *event) float mat[4][4]; int *indexar= vpd->indexar; int totindex, index; - short mval[2]; + float mval[2]; + + RNA_float_get_array(itemptr, "mouse", mval); view3d_operator_needs_opengl(C); @@ -1728,10 +1755,11 @@ static void vpaint_dot(bContext *C, struct VPaintData *vpd, wmEvent *event) wmMultMatrix(ob->obmat); wmGetSingleMatrix(mat); wmLoadMatrix(vc->rv3d->viewmat); + + mval[0]-= vc->ar->winrct.xmin; + mval[1]-= vc->ar->winrct.ymin; + - mval[0]= event->x - vc->ar->winrct.xmin; - mval[1]= event->y - vc->ar->winrct.ymin; - /* which faces are involved */ if(vp->flag & VP_AREA) { totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], brush->size); @@ -1811,58 +1839,27 @@ static void vpaint_dot(bContext *C, struct VPaintData *vpd, wmEvent *event) DAG_object_flush_update(vc->scene, ob, OB_RECALC_DATA); } -static int vpaint_modal(bContext *C, wmOperator *op, wmEvent *event) +static void vpaint_stroke_done(bContext *C, struct PaintStroke *stroke) { - switch(event->type) { - case LEFTMOUSE: - if(event->val==0) { /* release */ - vpaint_exit(C, op); - return OPERATOR_FINISHED; - } - /* pass on, first press gets painted too */ - - case MOUSEMOVE: - vpaint_dot(C, op->customdata, event); - break; - } + ToolSettings *ts= CTX_data_tool_settings(C); + struct VPaintData *vpd= paint_stroke_mode_data(stroke); - return OPERATOR_RUNNING_MODAL; + if(vpd->vertexcosnos) + MEM_freeN(vpd->vertexcosnos); + MEM_freeN(vpd->indexar); + + /* frees prev buffer */ + copy_vpaint_prev(ts->vpaint, NULL, 0); + + MEM_freeN(vpd); } static int vpaint_invoke(bContext *C, wmOperator *op, wmEvent *event) { - ToolSettings *ts= CTX_data_tool_settings(C); - VPaint *vp= ts->vpaint; - struct VPaintData *vpd; - Object *ob= CTX_data_active_object(C); - Mesh *me; - float mat[4][4], imat[4][4]; - /* context checks could be a poll() */ - me= get_mesh(ob); - if(me==NULL || me->totface==0) return OPERATOR_PASS_THROUGH; - - if(me->mcol==NULL) make_vertexcol(CTX_data_scene(C), 0); - if(me->mcol==NULL) return OPERATOR_CANCELLED; - - /* make customdata storage */ - op->customdata= vpd= MEM_callocN(sizeof(struct VPaintData), "VPaintData"); - view3d_set_viewcontext(C, &vpd->vc); - - vpd->vertexcosnos= mesh_get_mapped_verts_nors(vpd->vc.scene, ob); - vpd->indexar= get_indexarray(); - vpd->paintcol= vpaint_get_current_col(vp); - - /* for filtering */ - copy_vpaint_prev(vp, (unsigned int *)me->mcol, me->totface); - - /* some old cruft to sort out later */ - Mat4MulMat4(mat, ob->obmat, vpd->vc.rv3d->viewmat); - Mat4Invert(imat, mat); - Mat3CpyMat4(vpd->vpimat, imat); - - /* do paint once for click only paint */ - vpaint_modal(C, op, event); + op->customdata = paint_stroke_new(C, vpaint_stroke_test_start, + vpaint_stroke_update_step, + vpaint_stroke_done); /* add modal handler */ WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op); @@ -1878,11 +1875,13 @@ void PAINT_OT_vertex_paint(wmOperatorType *ot) /* api callbacks */ ot->invoke= vpaint_invoke; - ot->modal= vpaint_modal; + ot->modal= paint_stroke_modal; /* ot->exec= vpaint_exec; <-- needs stroke property */ ot->poll= vp_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING; + + RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", ""); } diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index c01004f5b7e..94703dbe4ff 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -1042,47 +1042,7 @@ static int sculpt_mode_poll(bContext *C) static int sculpt_poll(bContext *C) { - return sculpt_mode_poll(C) && paint_brush(&CTX_data_tool_settings(C)->sculpt->paint) && - CTX_wm_area(C)->spacetype == SPACE_VIEW3D && - CTX_wm_region(C)->regiontype == RGN_TYPE_WINDOW; -} - -/*** Sculpt Cursor ***/ -static void draw_paint_cursor(bContext *C, int x, int y, void *customdata) -{ - Sculpt *sd= CTX_data_tool_settings(C)->sculpt; - SculptSession *ss= CTX_data_active_object(C)->sculpt; - Brush *brush = paint_brush(&sd->paint); - - glColor4ub(255, 100, 100, 128); - glEnable( GL_LINE_SMOOTH ); - glEnable(GL_BLEND); - - glTranslatef((float)x, (float)y, 0.0f); - glutil_draw_lined_arc(0.0, M_PI*2.0, brush->size, 40); - glTranslatef((float)-x, (float)-y, 0.0f); - - if(ss && ss->cache && brush && (brush->flag & BRUSH_SMOOTH_STROKE)) { - ARegion *ar = CTX_wm_region(C); - sdrawline(x, y, (int)ss->cache->mouse[0] - ar->winrct.xmin, (int)ss->cache->mouse[1] - ar->winrct.ymin); - } - - glDisable(GL_BLEND); - glDisable( GL_LINE_SMOOTH ); -} - -static void toggle_paint_cursor(bContext *C) -{ - Sculpt *s = CTX_data_scene(C)->toolsettings->sculpt; - - if(s->cursor) { - WM_paint_cursor_end(CTX_wm_manager(C), s->cursor); - s->cursor = NULL; - } - else { - s->cursor = - WM_paint_cursor_activate(CTX_wm_manager(C), sculpt_poll, draw_paint_cursor, NULL); - } + return sculpt_mode_poll(C) && paint_poll(C); } static void sculpt_undo_push(bContext *C, Sculpt *sd) @@ -1112,8 +1072,11 @@ static void sculpt_undo_push(bContext *C, Sculpt *sd) /**** Radial control ****/ static int sculpt_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event) { - Brush *brush = paint_brush(&CTX_data_tool_settings(C)->sculpt->paint); - toggle_paint_cursor(C); + Paint *p = paint_get_active(CTX_data_scene(C)); + Brush *brush = paint_brush(p); + + WM_paint_cursor_end(CTX_wm_manager(C), p->paint_cursor); + p->paint_cursor = NULL; brush_radial_control_invoke(op, brush, 1); return WM_radial_control_invoke(C, op, event); } @@ -1122,7 +1085,7 @@ static int sculpt_radial_control_modal(bContext *C, wmOperator *op, wmEvent *eve { int ret = WM_radial_control_modal(C, op, event); if(ret != OPERATOR_RUNNING_MODAL) - toggle_paint_cursor(C); + paint_cursor_start(C, sculpt_poll); return ret; } @@ -1592,6 +1555,8 @@ static int sculpt_toggle_mode(bContext *C, wmOperator *op) free_sculptsession(&ob->sculpt); } else { + const char col[3] = {255, 100, 100}; + /* Enter sculptmode */ ob->mode |= OB_MODE_SCULPT; @@ -1605,10 +1570,9 @@ static int sculpt_toggle_mode(bContext *C, wmOperator *op) free_sculptsession(&ob->sculpt); ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session"); - if(!ts->sculpt->cursor) - toggle_paint_cursor(C); - - paint_init(&ts->sculpt->paint, "Brush"); + paint_init(&ts->sculpt->paint, col); + + paint_cursor_start(C, sculpt_poll); WM_event_add_notifier(C, NC_SCENE|ND_MODE, CTX_data_scene(C)); } diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h index 1c6b8399422..00d0e3131e5 100644 --- a/source/blender/gpu/GPU_draw.h +++ b/source/blender/gpu/GPU_draw.h @@ -43,6 +43,7 @@ struct Object; struct Scene; struct View3D; struct RegionView3D; +struct SmokeModifierData; /* OpenGL drawing functions related to shading. These are also * shared with the game engine, where there were previously diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index f1a77d78b7b..9161157f597 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -455,8 +455,11 @@ typedef struct Paint { Brush **brushes; int active_brush_index, brush_count; - /* WM handle */ + /* WM Paint cursor */ void *paint_cursor; + unsigned char paint_cursor_col[4]; + + int pad; } Paint; typedef struct ImagePaintSettings { @@ -498,9 +501,6 @@ typedef struct TransformOrientation { typedef struct Sculpt { Paint paint; - - /* WM handle */ - void *cursor; /* For rotating around a pivot point */ float pivot[3]; diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index be0707390c4..fb71b297683 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -151,7 +151,7 @@ static void rna_SpaceImageEditor_paint_update(bContext *C, PointerRNA *ptr) Scene *scene= CTX_data_scene(C); if(scene) - paint_init(&scene->toolsettings->imapaint.paint, "Brush"); + paint_init(&scene->toolsettings->imapaint.paint, NULL); } static int rna_SpaceImageEditor_show_render_get(PointerRNA *ptr) diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index b717df8f61f..c400b6c9b20 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -287,6 +287,11 @@ typedef struct wmTimer { } wmTimer; +/* **************** Paint Cursor ******************* */ + +typedef void (*wmPaintCursorDraw)(struct bContext *C, int, int, void *customdata); + + /* ****************** Messages ********************* */ enum { diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 2e813bac37d..304da25017b 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1067,7 +1067,7 @@ static void WM_OT_exit_blender(wmOperatorType *ot) */ void *WM_paint_cursor_activate(wmWindowManager *wm, int (*poll)(bContext *C), - void (*draw)(bContext *C, int, int, void *customdata), void *customdata) + wmPaintCursorDraw draw, void *customdata) { wmPaintCursor *pc= MEM_callocN(sizeof(wmPaintCursor), "paint cursor"); From 210ef4c07c0f8fe602068bfc797ef8dd588a6204 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Thu, 20 Aug 2009 05:44:32 +0000 Subject: [PATCH 17/73] 2.5/Sculpt: * Fixed sculpt brush stroke exec (F4 operator) * Made a generic paint stroke exec --- .../blender/editors/sculpt_paint/paint_intern.h | 1 + .../blender/editors/sculpt_paint/paint_stroke.c | 15 +++++++++++++++ source/blender/editors/sculpt_paint/sculpt.c | 14 ++++---------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index c6c93026c44..a0187566c43 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -49,6 +49,7 @@ typedef void (*StrokeDone)(struct bContext *C, struct PaintStroke *stroke); struct PaintStroke *paint_stroke_new(bContext *C, StrokeTestStart test_start, StrokeUpdateStep update_step, StrokeDone done); int paint_stroke_modal(struct bContext *C, struct wmOperator *op, struct wmEvent *event); +int paint_stroke_exec(struct bContext *C, struct wmOperator *op); struct ViewContext *paint_stroke_view_context(struct PaintStroke *stroke); void *paint_stroke_mode_data(struct PaintStroke *stroke); void paint_stroke_set_mode_data(struct PaintStroke *stroke, void *mode_data); diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 1167e011c86..715399af888 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -265,6 +265,21 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_RUNNING_MODAL; } +int paint_stroke_exec(bContext *C, wmOperator *op) +{ + PaintStroke *stroke = op->customdata; + + RNA_BEGIN(op->ptr, itemptr, "stroke") { + stroke->update_step(C, stroke, &itemptr); + } + RNA_END; + + MEM_freeN(stroke); + op->customdata = NULL; + + return OPERATOR_FINISHED; +} + ViewContext *paint_stroke_view_context(PaintStroke *stroke) { return &stroke->vc; diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 94703dbe4ff..e0206210799 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -1410,7 +1410,7 @@ static void sculpt_stroke_update_step(bContext *C, struct PaintStroke *stroke, P do_symmetrical_brush_actions(sd, ss); /* Cleanup */ - sculpt_flush_update(C); // XXX: during exec, shouldn't do this every time + sculpt_flush_update(C); sculpt_post_stroke_free(ss); } @@ -1448,20 +1448,14 @@ static int sculpt_brush_stroke_exec(bContext *C, wmOperator *op) Sculpt *sd = CTX_data_tool_settings(C)->sculpt; SculptSession *ss = CTX_data_active_object(C)->sculpt; + op->customdata = paint_stroke_new(C, sculpt_stroke_test_start, sculpt_stroke_update_step, sculpt_stroke_done); + sculpt_brush_stroke_init(C); sculpt_update_cache_invariants(sd, ss, C, op); sculptmode_update_all_projverts(ss); - RNA_BEGIN(op->ptr, itemptr, "stroke") { - sculpt_update_cache_variants(sd, ss, &itemptr); - - sculpt_restore_mesh(sd, ss); - do_symmetrical_brush_actions(sd, ss); - - sculpt_post_stroke_free(ss); - } - RNA_END; + paint_stroke_exec(C, op); sculpt_flush_update(C); sculpt_cache_free(ss->cache); From e75bf81ac683cccb244c4be57b81d217d9f675db Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Thu, 20 Aug 2009 08:59:09 +0000 Subject: [PATCH 18/73] Smoke: * Fix OpenGL drawing resulting (at least on windows) in missing panels when switching fullscreen + back --- .../blender/editors/space_view3d/drawvolume.c | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c index 221003360f4..1fd17951e8a 100644 --- a/source/blender/editors/space_view3d/drawvolume.c +++ b/source/blender/editors/space_view3d/drawvolume.c @@ -203,17 +203,14 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture float *points = NULL; int numpoints = 0; float cor[3] = {1.,1.,1.}; + int gl_depth = 0, gl_blend = 0; - /* - res[0] = smd->domain->res[0]; - res[1] = smd->domain->res[1]; - res[2] = smd->domain->res[2]; - */ + glGetBooleanv(GL_BLEND, (GLboolean *)&gl_blend); + glGetBooleanv(GL_DEPTH_TEST, (GLboolean *)&gl_depth); wmLoadMatrix(rv3d->viewmat); glDepthMask(GL_FALSE); - glEnable(GL_TEXTURE_3D); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -296,9 +293,12 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture wmMultMatrix(ob->obmat); - glDisable(GL_TEXTURE_3D); - glDisable(GL_BLEND); - glEnable(GL_DEPTH_TEST); - glDepthMask(GL_TRUE); + if(gl_blend) + glDisable(GL_BLEND); + if(gl_depth) + { + glEnable(GL_DEPTH_TEST); + glDepthMask(GL_TRUE); + } } From bc4806579b3b8504ba09854f127d2a65f3dad405 Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Thu, 20 Aug 2009 09:00:23 +0000 Subject: [PATCH 19/73] Smoke: * Fixing my fix for opengl GL_BLEND --- source/blender/editors/space_view3d/drawvolume.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c index 1fd17951e8a..325997ebf4d 100644 --- a/source/blender/editors/space_view3d/drawvolume.c +++ b/source/blender/editors/space_view3d/drawvolume.c @@ -293,7 +293,7 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture wmMultMatrix(ob->obmat); - if(gl_blend) + if(!gl_blend) glDisable(GL_BLEND); if(gl_depth) { From 9f764ae36dbdf571778ec6fc8823ec7e721a2baf Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Thu, 20 Aug 2009 09:13:57 +0000 Subject: [PATCH 20/73] Smoke: * Fix for OpenGL domain scaling/rotating/translating reported by Wahooney --- source/blender/editors/space_view3d/drawvolume.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c index 325997ebf4d..53f193382bd 100644 --- a/source/blender/editors/space_view3d/drawvolume.c +++ b/source/blender/editors/space_view3d/drawvolume.c @@ -209,6 +209,7 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture glGetBooleanv(GL_DEPTH_TEST, (GLboolean *)&gl_depth); wmLoadMatrix(rv3d->viewmat); + wmMultMatrix(ob->obmat); glDepthMask(GL_FALSE); glDisable(GL_DEPTH_TEST); @@ -291,8 +292,6 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture MEM_freeN(points); - wmMultMatrix(ob->obmat); - if(!gl_blend) glDisable(GL_BLEND); if(gl_depth) From 6dbadb23ce26967608710412e9e74396e624c597 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Thu, 20 Aug 2009 09:18:55 +0000 Subject: [PATCH 21/73] update MSVC project files. --- extern/lzma/make/msvc_9_0/lzma.vcproj | 385 ++++++++++++++++++ extern/lzo/make/msvc_9_0/lzo.vcproj | 353 ++++++++++++++++ intern/audaspace/jack/AUD_JackDevice.cpp | 4 + intern/audaspace/jack/AUD_JackDevice.h | 4 + .../audaspace/make/msvc_9_0/audaspace.vcproj | 19 + intern/ghost/intern/GHOST_System.cpp | 4 +- projectfiles_vc9/blender/blender.sln | 53 +++ .../blender/blenkernel/BKE_blenkernel.vcproj | 24 +- .../blender/editors/ED_editors.vcproj | 36 +- 9 files changed, 870 insertions(+), 12 deletions(-) create mode 100644 extern/lzma/make/msvc_9_0/lzma.vcproj create mode 100644 extern/lzo/make/msvc_9_0/lzo.vcproj diff --git a/extern/lzma/make/msvc_9_0/lzma.vcproj b/extern/lzma/make/msvc_9_0/lzma.vcproj new file mode 100644 index 00000000000..ec0676f6ca6 --- /dev/null +++ b/extern/lzma/make/msvc_9_0/lzma.vcproj @@ -0,0 +1,385 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/extern/lzo/make/msvc_9_0/lzo.vcproj b/extern/lzo/make/msvc_9_0/lzo.vcproj new file mode 100644 index 00000000000..80516ef964e --- /dev/null +++ b/extern/lzo/make/msvc_9_0/lzo.vcproj @@ -0,0 +1,353 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/intern/audaspace/jack/AUD_JackDevice.cpp b/intern/audaspace/jack/AUD_JackDevice.cpp index 445e68e1a9a..1f2c6faa511 100644 --- a/intern/audaspace/jack/AUD_JackDevice.cpp +++ b/intern/audaspace/jack/AUD_JackDevice.cpp @@ -31,6 +31,8 @@ #include #include +#ifdef WITH_JACK + // AUD_XXX this is not realtime suitable! int AUD_JackDevice::jack_mix(jack_nframes_t length, void *data) { @@ -147,3 +149,5 @@ void AUD_JackDevice::playing(bool playing) { // Do nothing. } + +#endif diff --git a/intern/audaspace/jack/AUD_JackDevice.h b/intern/audaspace/jack/AUD_JackDevice.h index 0b09e20b354..e6d332e1160 100644 --- a/intern/audaspace/jack/AUD_JackDevice.h +++ b/intern/audaspace/jack/AUD_JackDevice.h @@ -26,6 +26,8 @@ #ifndef AUD_JACKDEVICE #define AUD_JACKDEVICE +#ifdef WITH_JACK + #include "AUD_SoftwareDevice.h" class AUD_Buffer; @@ -88,4 +90,6 @@ public: virtual ~AUD_JackDevice(); }; +#endif //WITH_JACK + #endif //AUD_JACKDEVICE diff --git a/intern/audaspace/make/msvc_9_0/audaspace.vcproj b/intern/audaspace/make/msvc_9_0/audaspace.vcproj index 2bb97502c4e..a4d775a415c 100644 --- a/intern/audaspace/make/msvc_9_0/audaspace.vcproj +++ b/intern/audaspace/make/msvc_9_0/audaspace.vcproj @@ -717,6 +717,25 @@ > + + + + + + + + + diff --git a/intern/ghost/intern/GHOST_System.cpp b/intern/ghost/intern/GHOST_System.cpp index 603452cfcbd..229744e2000 100644 --- a/intern/ghost/intern/GHOST_System.cpp +++ b/intern/ghost/intern/GHOST_System.cpp @@ -289,9 +289,9 @@ GHOST_TSuccess GHOST_System::init() #endif #ifdef GHOST_DEBUG - m_eventPrinter = new GHOST_EventPrinter(); if (m_eventManager) { - m_eventManager->addConsumer(m_eventPrinter); + m_eventPrinter = new GHOST_EventPrinter(); + //m_eventManager->addConsumer(m_eventPrinter); } #endif // GHOST_DEBUG diff --git a/projectfiles_vc9/blender/blender.sln b/projectfiles_vc9/blender/blender.sln index 602105dc501..1bd132ea223 100644 --- a/projectfiles_vc9/blender/blender.sln +++ b/projectfiles_vc9/blender/blender.sln @@ -10,6 +10,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "blender", "blender.vcproj", {C66F722C-46BE-40C9-ABAE-2EAC7A697EB8} = {C66F722C-46BE-40C9-ABAE-2EAC7A697EB8} {D1A9312F-4557-4982-A0F4-4D08508235F4} = {D1A9312F-4557-4982-A0F4-4D08508235F4} {884D8731-654C-4C7F-9A75-8F37A305BE1E} = {884D8731-654C-4C7F-9A75-8F37A305BE1E} + {79D0B232-208C-F208-DA71-79B4AC088602} = {79D0B232-208C-F208-DA71-79B4AC088602} {E645CC32-4823-463E-82F0-46ADDE664018} = {E645CC32-4823-463E-82F0-46ADDE664018} {7495FE37-933A-4AC1-BB2A-B3FDB4DE4284} = {7495FE37-933A-4AC1-BB2A-B3FDB4DE4284} {51FB3D48-2467-4BFA-A321-D848252B437E} = {51FB3D48-2467-4BFA-A321-D848252B437E} @@ -24,6 +25,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "blender", "blender.vcproj", {415BFD6E-64CF-422B-AF88-C07F040A7292} = {415BFD6E-64CF-422B-AF88-C07F040A7292} {106AE171-0083-41D6-A949-20DB0E8DC251} = {106AE171-0083-41D6-A949-20DB0E8DC251} {670EC17A-0548-4BBF-A27B-636C7C188139} = {670EC17A-0548-4BBF-A27B-636C7C188139} + {8BFA4082-773B-D100-BC24-659083BA023F} = {8BFA4082-773B-D100-BC24-659083BA023F} {4C3AB78A-52CA-4276-A041-39776E52D8C8} = {4C3AB78A-52CA-4276-A041-39776E52D8C8} {6B801390-5F95-4F07-81A7-97FBA046AACC} = {6B801390-5F95-4F07-81A7-97FBA046AACC} {CAE37E91-6570-43AC-A4B4-7A37A4B0FC94} = {CAE37E91-6570-43AC-A4B4-7A37A4B0FC94} @@ -84,6 +86,7 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DNA_makesdna", "makesdna\DNA_makesdna.vcproj", "{E013786A-9575-4F34-81B2-33290357EE87}" ProjectSection(ProjectDependencies) = postProject {31628053-825D-4C06-8A21-D13883489718} = {31628053-825D-4C06-8A21-D13883489718} + {1CC733F1-6AB5-4904-8F63-C08C46B79DD9} = {1CC733F1-6AB5-4904-8F63-C08C46B79DD9} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EXP_expressions", "..\gameengine\expression\EXP_expressions.vcproj", "{EADC3C5A-6C51-4F03-8038-1553E7D7F740}" @@ -220,7 +223,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EXT_glew", "..\..\extern\gl EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EXT_build_install_all", "..\..\extern\make\msvc_9_0\build_install_all.vcproj", "{9C71A793-C177-4CAB-8EC5-923D500B39F8}" ProjectSection(ProjectDependencies) = postProject + {79D0B232-208C-F208-DA71-79B4AC088602} = {79D0B232-208C-F208-DA71-79B4AC088602} {FFD3C64A-30E2-4BC7-BC8F-51818C320400} = {FFD3C64A-30E2-4BC7-BC8F-51818C320400} + {8BFA4082-773B-D100-BC24-659083BA023F} = {8BFA4082-773B-D100-BC24-659083BA023F} + {BAC615B0-F1AF-418B-8D23-A10FD8870D6A} = {BAC615B0-F1AF-418B-8D23-A10FD8870D6A} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "INT_boolop", "..\..\intern\boolop\make\msvc_9_0\boolop.vcproj", "{EB75F4D6-2970-4A3A-8D99-2BAD7201C0E9}" @@ -242,6 +248,9 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "INT_elbeem", "..\..\intern\elbeem\make\msvc_9_0\elbeem.vcproj", "{A90C4918-4B21-4277-93BD-AF65F30951D9}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "INT_ghost", "..\..\intern\ghost\make\msvc_9_0\ghost.vcproj", "{76D90B92-ECC7-409C-9F98-A8814B90F3C0}" + ProjectSection(ProjectDependencies) = postProject + {B789C2F3-279E-4A85-8F0A-7F7AC068E598} = {B789C2F3-279E-4A85-8F0A-7F7AC068E598} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "INT_guardedalloc", "..\..\intern\guardedalloc\make\msvc_9_0\guardedalloc.vcproj", "{1CC733F1-6AB5-4904-8F63-C08C46B79DD9}" EndProject @@ -301,6 +310,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "INT_smoke", "..\..\intern\s EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "INT_audaspace", "..\..\intern\audaspace\make\msvc_9_0\audaspace.vcproj", "{87032FD2-9BA0-6B43-BE33-8902BA8F9172}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EXT_lzma", "..\..\extern\lzma\make\msvc_9_0\lzma.vcproj", "{79D0B232-208C-F208-DA71-79B4AC088602}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EXT_lzo", "..\..\extern\lzo\make\msvc_9_0\lzo.vcproj", "{8BFA4082-773B-D100-BC24-659083BA023F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution 3D Plugin Debug|Win32 = 3D Plugin Debug|Win32 @@ -1443,6 +1456,46 @@ Global {87032FD2-9BA0-6B43-BE33-8902BA8F9172}.Debug|Win32.Build.0 = 3DPlugin Debug|Win32 {87032FD2-9BA0-6B43-BE33-8902BA8F9172}.Release|Win32.ActiveCfg = 3DPlugin Release|Win32 {87032FD2-9BA0-6B43-BE33-8902BA8F9172}.Release|Win32.Build.0 = 3DPlugin Release|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.3D Plugin Debug|Win32.ActiveCfg = 3D Plugin Debug|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.3D Plugin Debug|Win32.Build.0 = 3D Plugin Debug|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.3D Plugin Release|Win32.ActiveCfg = 3D Plugin Release|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.3D Plugin Release|Win32.Build.0 = 3D Plugin Release|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.3DPlugin Debug|Win32.ActiveCfg = 3D Plugin Release|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.3DPlugin Debug|Win32.Build.0 = 3D Plugin Release|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.3DPlugin Release|Win32.ActiveCfg = 3D Plugin Release|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.3DPlugin Release|Win32.Build.0 = 3D Plugin Release|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.Blender Debug|Win32.ActiveCfg = Blender Debug|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.Blender Debug|Win32.Build.0 = Blender Debug|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.Blender Release|Win32.ActiveCfg = Blender Release|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.Blender Release|Win32.Build.0 = Blender Release|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.BlenderPlayer Debug|Win32.ActiveCfg = Blender Release|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.BlenderPlayer Debug|Win32.Build.0 = Blender Release|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.BlenderPlayer Release|Win32.ActiveCfg = Blender Release|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.BlenderPlayer Release|Win32.Build.0 = Blender Release|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.Debug|Win32.ActiveCfg = 3D Plugin Debug|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.Debug|Win32.Build.0 = 3D Plugin Debug|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.Release|Win32.ActiveCfg = 3D Plugin Release|Win32 + {79D0B232-208C-F208-DA71-79B4AC088602}.Release|Win32.Build.0 = 3D Plugin Release|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.3D Plugin Debug|Win32.ActiveCfg = 3D Plugin Debug|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.3D Plugin Debug|Win32.Build.0 = 3D Plugin Debug|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.3D Plugin Release|Win32.ActiveCfg = 3D Plugin Release|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.3D Plugin Release|Win32.Build.0 = 3D Plugin Release|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.3DPlugin Debug|Win32.ActiveCfg = 3D Plugin Release|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.3DPlugin Debug|Win32.Build.0 = 3D Plugin Release|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.3DPlugin Release|Win32.ActiveCfg = 3D Plugin Release|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.3DPlugin Release|Win32.Build.0 = 3D Plugin Release|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.Blender Debug|Win32.ActiveCfg = Blender Debug|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.Blender Debug|Win32.Build.0 = Blender Debug|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.Blender Release|Win32.ActiveCfg = Blender Release|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.Blender Release|Win32.Build.0 = Blender Release|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.BlenderPlayer Debug|Win32.ActiveCfg = Blender Release|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.BlenderPlayer Debug|Win32.Build.0 = Blender Release|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.BlenderPlayer Release|Win32.ActiveCfg = Blender Release|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.BlenderPlayer Release|Win32.Build.0 = Blender Release|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.Debug|Win32.ActiveCfg = 3D Plugin Debug|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.Debug|Win32.Build.0 = 3D Plugin Debug|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.Release|Win32.ActiveCfg = 3D Plugin Release|Win32 + {8BFA4082-773B-D100-BC24-659083BA023F}.Release|Win32.Build.0 = 3D Plugin Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/projectfiles_vc9/blender/blenkernel/BKE_blenkernel.vcproj b/projectfiles_vc9/blender/blenkernel/BKE_blenkernel.vcproj index 7ba3aac65f0..7f0867cc7b6 100644 --- a/projectfiles_vc9/blender/blenkernel/BKE_blenkernel.vcproj +++ b/projectfiles_vc9/blender/blenkernel/BKE_blenkernel.vcproj @@ -43,7 +43,7 @@ + + @@ -757,6 +761,10 @@ RelativePath="..\..\..\source\blender\blenkernel\intern\smoke.c" > + + @@ -1018,6 +1026,10 @@ RelativePath="..\..\..\source\blender\blenkernel\BKE_packedFile.h" > + + diff --git a/projectfiles_vc9/blender/editors/ED_editors.vcproj b/projectfiles_vc9/blender/editors/ED_editors.vcproj index 174ceb5ca99..0482fa9067a 100644 --- a/projectfiles_vc9/blender/editors/ED_editors.vcproj +++ b/projectfiles_vc9/blender/editors/ED_editors.vcproj @@ -217,6 +217,10 @@ RelativePath="..\..\..\source\blender\editors\include\ED_image.h" > + + @@ -458,6 +462,10 @@ RelativePath="..\..\..\source\blender\editors\space_view3d\drawobject.c" > + + @@ -510,10 +518,6 @@ RelativePath="..\..\..\source\blender\editors\space_time\space_time.c" > - - @@ -806,6 +810,10 @@ RelativePath="..\..\..\source\blender\editors\space_info\info_ops.c" > + + @@ -1274,6 +1282,10 @@ RelativePath="..\..\..\source\blender\editors\sculpt_paint\paint_ops.c" > + + @@ -1467,6 +1479,22 @@ > + + + + + + + + From 1e0bd0752244961366ae0f5416c8c0cc57556e7c Mon Sep 17 00:00:00 2001 From: William Reynish Date: Thu, 20 Aug 2009 11:38:09 +0000 Subject: [PATCH 22/73] Swapped some icons in the node editor. The Render Layers menu was using wrong icon, for example. --- release/ui/space_node.py | 10 +++++----- source/blender/editors/space_node/drawnode.c | 6 +++--- source/blender/makesrna/intern/rna_space.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/release/ui/space_node.py b/release/ui/space_node.py index 2e28cfc2eed..fd5dd9e6ee7 100644 --- a/release/ui/space_node.py +++ b/release/ui/space_node.py @@ -27,7 +27,7 @@ class NODE_HT_header(bpy.types.Header): if ob: layout.template_ID(ob, "active_material", new="material.new") if id: - layout.itemR(id, "use_nodes", toggle=True) + layout.itemR(id, "use_nodes") elif snode.tree_type == 'TEXTURE': row.itemR(snode, "texture_type", text="", expand=True) @@ -37,14 +37,14 @@ class NODE_HT_header(bpy.types.Header): if id_from: layout.template_ID(id_from, "active_texture", new="texture.new") if id: - layout.itemR(id, "use_nodes", toggle=True) + layout.itemR(id, "use_nodes") elif snode.tree_type == 'COMPOSITING': id = snode.id - layout.itemR(id, "use_nodes", toggle=True) - layout.itemR(id.render_data, "free_unused_nodes", text="Free Unused", toggle=True) - layout.itemR(snode, "backdrop", toggle=True) + layout.itemR(id, "use_nodes") + layout.itemR(id.render_data, "free_unused_nodes", text="Free Unused") + layout.itemR(snode, "backdrop") class NODE_MT_view(bpy.types.Menu): __space_type__ = "NODE_EDITOR" diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 50cf193f37b..1fb8cb3452b 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -253,7 +253,7 @@ static int node_buts_mix_rgb(uiBlock *block, bNodeTree *ntree, bNode *node, rctf uiButSetFunc(bt, node_but_title_cb, node, bt); /* Alpha option, composite */ if(a_but) - uiDefButS(block, TOG, B_NODE_EXEC, "A", + uiDefIconButS(block, TOG, B_NODE_EXEC, ICON_IMAGE_RGB_ALPHA, (short)butr->xmax-20, (short)butr->ymin, 20, 20, &node->custom2, 0, 0, 0, 0, "Include Alpha of 2nd input in this operation"); } @@ -1077,7 +1077,7 @@ static int node_composit_buts_renderlayers(uiBlock *block, bNodeTree *ntree, bNo /* browse button layer */ strp= scene_layer_menu(node->id?(Scene *)node->id:scene); if(node->id) - bt= uiDefIconTextButS(block, MENU, B_NODE_EXEC, ICON_SCENE_DATA, strp, + bt= uiDefIconTextButS(block, MENU, B_NODE_EXEC, ICON_RENDERLAYERS, strp, butr->xmin+20, butr->ymin, (butr->xmax-butr->xmin)-40, 19, &node->custom1, 0, 0, 0, 0, "Choose Render Layer"); else @@ -1473,7 +1473,7 @@ static int node_composit_buts_vecblur(uiBlock *block, bNodeTree *ntree, bNode *n uiDefButS(block, NUM, B_NODE_EXEC, "MaxSpeed:", butr->xmin, dy+38, dx, 19, &nbd->maxspeed, 0, 1024, 0, 0, "If not zero, maximum speed in pixels"); - uiDefButF(block, NUM, B_NODE_EXEC, "BlurFac:", + uiDefButF(block, NUM, B_NODE_EXEC, "Blur:", butr->xmin, dy+19, dx, 19, &nbd->fac, 0.0f, 2.0f, 10, 2, "Scaling factor for motion vectors, actually 'shutter speed' in frames"); uiDefButS(block, TOG, B_NODE_EXEC, "Curved", diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index fb71b297683..d220c707143 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -1409,7 +1409,7 @@ static void rna_def_space_node(BlenderRNA *brna) static EnumPropertyItem tree_type_items[] = { {NTREE_SHADER, "MATERIAL", ICON_MATERIAL, "Material", "Material nodes."}, {NTREE_TEXTURE, "TEXTURE", ICON_TEXTURE, "Texture", "Texture nodes."}, - {NTREE_COMPOSIT, "COMPOSITING", ICON_RENDER_RESULT, "Compositing", "Compositing nodes."}, + {NTREE_COMPOSIT, "COMPOSITING", ICON_RENDERLAYERS, "Compositing", "Compositing nodes."}, {0, NULL, 0, NULL, NULL}}; static EnumPropertyItem texture_type_items[] = { From a54af8e3baa8b3b3698f4196f61a0b5453df6954 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Thu, 20 Aug 2009 15:25:12 +0000 Subject: [PATCH 23/73] 2.5 weight paint: * Refactored weight paint to use the new stroke code, now does smooth stroke and stroke spacing. Note: weight paint is failing to free it's MocNodes in 2.5, someone might want to look into that --- release/ui/space_view3d_toolbar.py | 4 +- .../editors/sculpt_paint/paint_vertex.c | 406 +++++++++--------- 2 files changed, 203 insertions(+), 207 deletions(-) diff --git a/release/ui/space_view3d_toolbar.py b/release/ui/space_view3d_toolbar.py index 5d882866e96..5f42ff1d8b8 100644 --- a/release/ui/space_view3d_toolbar.py +++ b/release/ui/space_view3d_toolbar.py @@ -429,7 +429,9 @@ class VIEW3D_PT_tools_brush_stroke(PaintPanel): def poll(self, context): settings = self.paint_settings(context) - return (settings and settings.brush and (context.sculpt_object or context.vertex_paint_object)) + return (settings and settings.brush and (context.sculpt_object or + context.vertex_paint_object or + context.weight_paint_object)) def draw(self, context): settings = self.paint_settings(context) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 19f0293c1b8..0d8213b28d6 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1273,207 +1273,10 @@ struct WPaintData { float wpimat[3][3]; }; -static void wpaint_exit(bContext *C, wmOperator *op) -{ - ToolSettings *ts= CTX_data_tool_settings(C); - Object *ob= CTX_data_active_object(C); - struct WPaintData *wpd= op->customdata; - - if(wpd->vertexcosnos) - MEM_freeN(wpd->vertexcosnos); - MEM_freeN(wpd->indexar); - - /* frees prev buffer */ - copy_wpaint_prev(ts->wpaint, NULL, 0); - - /* and particles too */ - if(ob->particlesystem.first) { - ParticleSystem *psys; - int i; - - for(psys= ob->particlesystem.first; psys; psys= psys->next) { - for(i=0; ivgroup[i]==ob->actdef) { - psys->recalc |= PSYS_RECALC_RESET; - break; - } - } - } - } - - DAG_object_flush_update(CTX_data_scene(C), ob, OB_RECALC_DATA); - - MEM_freeN(wpd); - op->customdata= NULL; -} - - -static int wpaint_modal(bContext *C, wmOperator *op, wmEvent *event) -{ - ToolSettings *ts= CTX_data_tool_settings(C); - VPaint *wp= ts->wpaint; - Brush *brush = paint_brush(&wp->paint); - - switch(event->type) { - case LEFTMOUSE: - if(event->val==0) { /* release */ - wpaint_exit(C, op); - return OPERATOR_FINISHED; - } - /* pass on, first press gets painted too */ - - case MOUSEMOVE: - { - struct WPaintData *wpd= op->customdata; - ViewContext *vc= &wpd->vc; - Object *ob= vc->obact; - Mesh *me= ob->data; - float mat[4][4]; - float paintweight= ts->vgroup_weight; - int *indexar= wpd->indexar; - int totindex, index, alpha, totw; - float mval[2]; - - view3d_operator_needs_opengl(C); - - /* load projection matrix */ - wmMultMatrix(ob->obmat); - wmGetSingleMatrix(mat); - wmLoadMatrix(wpd->vc.rv3d->viewmat); - - MTC_Mat4SwapMat4(wpd->vc.rv3d->persmat, mat); - - mval[0]= event->x - vc->ar->winrct.xmin; - mval[1]= event->y - vc->ar->winrct.ymin; - - /* which faces are involved */ - if(wp->flag & VP_AREA) { - totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], brush->size); - } - else { - indexar[0]= view3d_sample_backbuf(vc, mval[0], mval[1]); - if(indexar[0]) totindex= 1; - else totindex= 0; - } - - if(wp->flag & VP_COLINDEX) { - for(index=0; indextotface) { - MFace *mface= ((MFace *)me->mface) + (indexar[index]-1); - - if(mface->mat_nr!=ob->actcol-1) { - indexar[index]= 0; - } - } - } - } - - if((G.f & G_FACESELECT) && me->mface) { - for(index=0; indextotface) { - MFace *mface= ((MFace *)me->mface) + (indexar[index]-1); - - if((mface->flag & ME_FACE_SEL)==0) { - indexar[index]= 0; - } - } - } - } - - /* make sure each vertex gets treated only once */ - /* and calculate filter weight */ - totw= 0; - if(wp->mode==VP_BLUR) - paintweight= 0.0f; - else - paintweight= ts->vgroup_weight; - - for(index=0; indextotface) { - MFace *mface= me->mface + (indexar[index]-1); - - (me->dvert+mface->v1)->flag= 1; - (me->dvert+mface->v2)->flag= 1; - (me->dvert+mface->v3)->flag= 1; - if(mface->v4) (me->dvert+mface->v4)->flag= 1; - - if(wp->mode==VP_BLUR) { - MDeformWeight *dw, *(*dw_func)(MDeformVert *, int) = verify_defweight; - - if(wp->flag & VP_ONLYVGROUP) - dw_func= get_defweight; - - dw= dw_func(me->dvert+mface->v1, ob->actdef-1); - if(dw) {paintweight+= dw->weight; totw++;} - dw= dw_func(me->dvert+mface->v2, ob->actdef-1); - if(dw) {paintweight+= dw->weight; totw++;} - dw= dw_func(me->dvert+mface->v3, ob->actdef-1); - if(dw) {paintweight+= dw->weight; totw++;} - if(mface->v4) { - dw= dw_func(me->dvert+mface->v4, ob->actdef-1); - if(dw) {paintweight+= dw->weight; totw++;} - } - } - } - } - - if(wp->mode==VP_BLUR) - paintweight/= (float)totw; - - for(index=0; indextotface) { - MFace *mface= me->mface + (indexar[index]-1); - - if((me->dvert+mface->v1)->flag) { - alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v1, mval); - if(alpha) { - do_weight_paint_vertex(wp, ob, mface->v1, alpha, paintweight, wpd->vgroup_mirror); - } - (me->dvert+mface->v1)->flag= 0; - } - - if((me->dvert+mface->v2)->flag) { - alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v2, mval); - if(alpha) { - do_weight_paint_vertex(wp, ob, mface->v2, alpha, paintweight, wpd->vgroup_mirror); - } - (me->dvert+mface->v2)->flag= 0; - } - - if((me->dvert+mface->v3)->flag) { - alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v3, mval); - if(alpha) { - do_weight_paint_vertex(wp, ob, mface->v3, alpha, paintweight, wpd->vgroup_mirror); - } - (me->dvert+mface->v3)->flag= 0; - } - - if((me->dvert+mface->v4)->flag) { - if(mface->v4) { - alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v4, mval); - if(alpha) { - do_weight_paint_vertex(wp, ob, mface->v4, alpha, paintweight, wpd->vgroup_mirror); - } - (me->dvert+mface->v4)->flag= 0; - } - } - } - } - - MTC_Mat4SwapMat4(vc->rv3d->persmat, mat); - - DAG_object_flush_update(vc->scene, ob, OB_RECALC_DATA); - ED_region_tag_redraw(vc->ar); - } - } - - return OPERATOR_RUNNING_MODAL; -} - -static int wpaint_invoke(bContext *C, wmOperator *op, wmEvent *event) +static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *event) { Scene *scene= CTX_data_scene(C); + struct PaintStroke *stroke = op->customdata; ToolSettings *ts= CTX_data_tool_settings(C); VPaint *wp= ts->wpaint; Object *ob= CTX_data_active_object(C); @@ -1482,7 +1285,6 @@ static int wpaint_invoke(bContext *C, wmOperator *op, wmEvent *event) float mat[4][4], imat[4][4]; if(scene->obedit) return OPERATOR_CANCELLED; - // XXX if(multires_level1_test()) return; me= get_mesh(ob); if(me==NULL || me->totface==0) return OPERATOR_PASS_THROUGH; @@ -1491,8 +1293,9 @@ static int wpaint_invoke(bContext *C, wmOperator *op, wmEvent *event) if (!me->dvert) create_dverts(&me->id); - /* make customdata storage */ - op->customdata= wpd= MEM_callocN(sizeof(struct WPaintData), "WPaintData"); + /* make mode data storage */ + wpd= MEM_callocN(sizeof(struct WPaintData), "WPaintData"); + paint_stroke_set_mode_data(stroke, wpd); view3d_set_viewcontext(C, &wpd->vc); wpd->vgroup_mirror= -1; @@ -1564,8 +1367,198 @@ static int wpaint_invoke(bContext *C, wmOperator *op, wmEvent *event) } } - /* do paint once for click only paint */ - wpaint_modal(C, op, event); + return 1; +} + +static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr) +{ + ToolSettings *ts= CTX_data_tool_settings(C); + VPaint *wp= ts->wpaint; + Brush *brush = paint_brush(&wp->paint); + struct WPaintData *wpd= paint_stroke_mode_data(stroke); + ViewContext *vc= &wpd->vc; + Object *ob= vc->obact; + Mesh *me= ob->data; + float mat[4][4]; + float paintweight= ts->vgroup_weight; + int *indexar= wpd->indexar; + int totindex, index, alpha, totw; + float mval[2]; + + view3d_operator_needs_opengl(C); + + /* load projection matrix */ + wmMultMatrix(ob->obmat); + wmGetSingleMatrix(mat); + wmLoadMatrix(wpd->vc.rv3d->viewmat); + + RNA_float_get_array(itemptr, "mouse", mval); + mval[0]-= vc->ar->winrct.xmin; + mval[1]-= vc->ar->winrct.ymin; + + MTC_Mat4SwapMat4(wpd->vc.rv3d->persmat, mat); + + /* which faces are involved */ + if(wp->flag & VP_AREA) { + totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], brush->size); + } + else { + indexar[0]= view3d_sample_backbuf(vc, mval[0], mval[1]); + if(indexar[0]) totindex= 1; + else totindex= 0; + } + + if(wp->flag & VP_COLINDEX) { + for(index=0; indextotface) { + MFace *mface= ((MFace *)me->mface) + (indexar[index]-1); + + if(mface->mat_nr!=ob->actcol-1) { + indexar[index]= 0; + } + } + } + } + + if((G.f & G_FACESELECT) && me->mface) { + for(index=0; indextotface) { + MFace *mface= ((MFace *)me->mface) + (indexar[index]-1); + + if((mface->flag & ME_FACE_SEL)==0) { + indexar[index]= 0; + } + } + } + } + + /* make sure each vertex gets treated only once */ + /* and calculate filter weight */ + totw= 0; + if(wp->mode==VP_BLUR) + paintweight= 0.0f; + else + paintweight= ts->vgroup_weight; + + for(index=0; indextotface) { + MFace *mface= me->mface + (indexar[index]-1); + + (me->dvert+mface->v1)->flag= 1; + (me->dvert+mface->v2)->flag= 1; + (me->dvert+mface->v3)->flag= 1; + if(mface->v4) (me->dvert+mface->v4)->flag= 1; + + if(wp->mode==VP_BLUR) { + MDeformWeight *dw, *(*dw_func)(MDeformVert *, int) = verify_defweight; + + if(wp->flag & VP_ONLYVGROUP) + dw_func= get_defweight; + + dw= dw_func(me->dvert+mface->v1, ob->actdef-1); + if(dw) {paintweight+= dw->weight; totw++;} + dw= dw_func(me->dvert+mface->v2, ob->actdef-1); + if(dw) {paintweight+= dw->weight; totw++;} + dw= dw_func(me->dvert+mface->v3, ob->actdef-1); + if(dw) {paintweight+= dw->weight; totw++;} + if(mface->v4) { + dw= dw_func(me->dvert+mface->v4, ob->actdef-1); + if(dw) {paintweight+= dw->weight; totw++;} + } + } + } + } + + if(wp->mode==VP_BLUR) + paintweight/= (float)totw; + + for(index=0; indextotface) { + MFace *mface= me->mface + (indexar[index]-1); + + if((me->dvert+mface->v1)->flag) { + alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v1, mval); + if(alpha) { + do_weight_paint_vertex(wp, ob, mface->v1, alpha, paintweight, wpd->vgroup_mirror); + } + (me->dvert+mface->v1)->flag= 0; + } + + if((me->dvert+mface->v2)->flag) { + alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v2, mval); + if(alpha) { + do_weight_paint_vertex(wp, ob, mface->v2, alpha, paintweight, wpd->vgroup_mirror); + } + (me->dvert+mface->v2)->flag= 0; + } + + if((me->dvert+mface->v3)->flag) { + alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v3, mval); + if(alpha) { + do_weight_paint_vertex(wp, ob, mface->v3, alpha, paintweight, wpd->vgroup_mirror); + } + (me->dvert+mface->v3)->flag= 0; + } + + if((me->dvert+mface->v4)->flag) { + if(mface->v4) { + alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v4, mval); + if(alpha) { + do_weight_paint_vertex(wp, ob, mface->v4, alpha, paintweight, wpd->vgroup_mirror); + } + (me->dvert+mface->v4)->flag= 0; + } + } + } + } + + MTC_Mat4SwapMat4(vc->rv3d->persmat, mat); + + DAG_object_flush_update(vc->scene, ob, OB_RECALC_DATA); + ED_region_tag_redraw(vc->ar); +} + +static void wpaint_stroke_done(bContext *C, struct PaintStroke *stroke) +{ + ToolSettings *ts= CTX_data_tool_settings(C); + Object *ob= CTX_data_active_object(C); + struct WPaintData *wpd= paint_stroke_mode_data(stroke); + + if(wpd->vertexcosnos) + MEM_freeN(wpd->vertexcosnos); + MEM_freeN(wpd->indexar); + + /* frees prev buffer */ + copy_wpaint_prev(ts->wpaint, NULL, 0); + + /* and particles too */ + if(ob->particlesystem.first) { + ParticleSystem *psys; + int i; + + for(psys= ob->particlesystem.first; psys; psys= psys->next) { + for(i=0; ivgroup[i]==ob->actdef) { + psys->recalc |= PSYS_RECALC_RESET; + break; + } + } + } + } + + DAG_object_flush_update(CTX_data_scene(C), ob, OB_RECALC_DATA); + + MEM_freeN(wpd); +} + + +static int wpaint_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + + op->customdata = paint_stroke_new(C, wpaint_stroke_test_start, + wpaint_stroke_update_step, + wpaint_stroke_done); /* add modal handler */ WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op); @@ -1582,13 +1575,14 @@ void PAINT_OT_weight_paint(wmOperatorType *ot) /* api callbacks */ ot->invoke= wpaint_invoke; - ot->modal= wpaint_modal; + ot->modal= paint_stroke_modal; /* ot->exec= vpaint_exec; <-- needs stroke property */ ot->poll= wp_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING; - + + RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", ""); } /* ************ set / clear vertex paint mode ********** */ From ff27281f2e235ca5c7b776b390f0deb00799c97a Mon Sep 17 00:00:00 2001 From: William Reynish Date: Thu, 20 Aug 2009 15:58:28 +0000 Subject: [PATCH 24/73] changed layout of PovRay radiosity panel to be more consistent with other render panels --- release/io/engine_render_pov.py | 40 +++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/release/io/engine_render_pov.py b/release/io/engine_render_pov.py index 65add2baacb..539f705a6ee 100644 --- a/release/io/engine_render_pov.py +++ b/release/io/engine_render_pov.py @@ -821,21 +821,37 @@ class SCENE_PT_povray_radiosity(RenderButtonsPanel): col = split.column() - col.itemR(scene, "pov_radio_count") - col.itemR(scene, "pov_radio_recursion_limit") - col.itemR(scene, "pov_radio_error_bound") + col.itemR(scene, "pov_radio_count", text="Rays") + col.itemR(scene, "pov_radio_recursion_limit", text="Recursions") + col = split.column() + col.itemR(scene, "pov_radio_error_bound", text="Error") - col.itemR(scene, "pov_radio_display_advanced") + layout.itemR(scene, "pov_radio_display_advanced") if scene.pov_radio_display_advanced: - col.itemR(scene, "pov_radio_adc_bailout") + split = layout.split() + + col = split.column() + col.itemR(scene, "pov_radio_adc_bailout", slider=True) + col.itemR(scene, "pov_radio_gray_threshold", slider=True) + col.itemR(scene, "pov_radio_low_error_factor", slider=True) + + + + col = split.column() col.itemR(scene, "pov_radio_brightness") - col.itemR(scene, "pov_radio_gray_threshold") - col.itemR(scene, "pov_radio_low_error_factor") - col.itemR(scene, "pov_radio_minimum_reuse") - col.itemR(scene, "pov_radio_media") + col.itemR(scene, "pov_radio_minimum_reuse", text="Min Reuse") col.itemR(scene, "pov_radio_nearest_count") + + + split = layout.split() + + col = split.column() + col.itemL(text="Estimation Influence:") + col.itemR(scene, "pov_radio_media") col.itemR(scene, "pov_radio_normal") + + col = split.column() col.itemR(scene, "pov_radio_always_sample") @@ -885,17 +901,17 @@ FloatProperty( attr="pov_radio_error_bound", FloatProperty( attr="pov_radio_gray_threshold", name="Gray Threshold", description="one of the two main speed/quality tuning values, lower values are more accurate.", - min=0.0, max=1.0, default= 0.0) + min=0.0, max=1.0, soft_min=0, soft_max=1, default= 0.0) FloatProperty( attr="pov_radio_low_error_factor", name="Low Error Factor", description="If you calculate just enough samples, but no more, you will get an image which has slightly blotchy lighting.", - min=0.0, max=1.0, default= 0.5) + min=0.0, max=1.0, soft_min=0.0, soft_max=1.0, default= 0.5) # max_sample - not available yet BoolProperty( attr="pov_radio_media", - name="Use Media", + name="Media", description="Radiosity estimation can be affected by media.", default= False) From 4df4b17ed65331b39d77c319f98b7114c0f2ead0 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Thu, 20 Aug 2009 16:00:17 +0000 Subject: [PATCH 25/73] 2.5 Paint: * Weight paint and vertex paint now use the same cursor setup as sculpt --- source/blender/blenkernel/BKE_paint.h | 7 +- source/blender/blenkernel/intern/paint.c | 15 ++-- .../editors/sculpt_paint/paint_vertex.c | 86 ++++--------------- source/blender/editors/sculpt_paint/sculpt.c | 4 +- source/blender/makesrna/intern/rna_space.c | 2 +- 5 files changed, 31 insertions(+), 83 deletions(-) diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 45d2e24c7f6..4337d275776 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -33,7 +33,12 @@ struct Object; struct Paint; struct Scene; -void paint_init(struct Paint *p, const char *col); +extern const char PAINT_CURSOR_SCULPT[3]; +extern const char PAINT_CURSOR_VERTEX_PAINT[3]; +extern const char PAINT_CURSOR_WEIGHT_PAINT[3]; +extern const char PAINT_CURSOR_TEXTURE_PAINT[3]; + +void paint_init(struct Paint *p, const char col[3]); void free_paint(struct Paint *p); void copy_paint(struct Paint *orig, struct Paint *new); diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index f0893e058fa..7c5b2b82b4b 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -39,6 +39,11 @@ #include #include +const char PAINT_CURSOR_SCULPT[3] = {255, 100, 100}; +const char PAINT_CURSOR_VERTEX_PAINT[3] = {255, 255, 255}; +const char PAINT_CURSOR_WEIGHT_PAINT[3] = {200, 200, 255}; +const char PAINT_CURSOR_TEXTURE_PAINT[3] = {255, 255, 255}; + Paint *paint_get_active(Scene *sce) { if(sce && sce->basact && sce->basact->object) { @@ -154,7 +159,7 @@ int paint_facesel_test(Object *ob) } -void paint_init(Paint *p, const char *col) +void paint_init(Paint *p, const char col[3]) { Brush *brush; @@ -163,13 +168,7 @@ void paint_init(Paint *p, const char *col) brush_check_exists(&brush, "Brush"); paint_brush_set(p, brush); - if(col) - memcpy(p->paint_cursor_col, col, 3); - else { - p->paint_cursor_col[0] = 255; - p->paint_cursor_col[1] = 255; - p->paint_cursor_col[2] = 255; - } + memcpy(p->paint_cursor_col, col, 3); p->paint_cursor_col[3] = 128; } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 0d8213b28d6..704773795e8 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -142,56 +142,6 @@ static int wp_poll(bContext *C) return 0; } - -/* Cursors */ -static void vp_drawcursor(bContext *C, int x, int y, void *customdata) -{ - Brush *brush = paint_brush(&CTX_data_tool_settings(C)->vpaint->paint); - - glTranslatef((float)x, (float)y, 0.0f); - - glColor4ub(255, 255, 255, 128); - glEnable( GL_LINE_SMOOTH ); - glEnable(GL_BLEND); - glutil_draw_lined_arc(0.0, M_PI*2.0, brush->size, 40); - glDisable(GL_BLEND); - glDisable( GL_LINE_SMOOTH ); - - glTranslatef((float)-x, (float)-y, 0.0f); -} - -static void wp_drawcursor(bContext *C, int x, int y, void *customdata) -{ - Brush *brush = paint_brush(&CTX_data_tool_settings(C)->wpaint->paint); - - glTranslatef((float)x, (float)y, 0.0f); - - glColor4ub(200, 200, 255, 128); - glEnable( GL_LINE_SMOOTH ); - glEnable(GL_BLEND); - glutil_draw_lined_arc(0.0, M_PI*2.0, brush->size, 40); - glDisable(GL_BLEND); - glDisable( GL_LINE_SMOOTH ); - - glTranslatef((float)-x, (float)-y, 0.0f); -} - -static void toggle_paint_cursor(bContext *C, int wpaint) -{ - ToolSettings *ts = CTX_data_scene(C)->toolsettings; - VPaint *vp = wpaint ? ts->wpaint : ts->vpaint; - - if(vp->paintcursor) { - WM_paint_cursor_end(CTX_wm_manager(C), vp->paintcursor); - vp->paintcursor = NULL; - } - else { - vp->paintcursor = wpaint ? - WM_paint_cursor_activate(CTX_wm_manager(C), wp_poll, wp_drawcursor, NULL) : - WM_paint_cursor_activate(CTX_wm_manager(C), vp_poll, vp_drawcursor, NULL); - } -} - static VPaint *new_vpaint(int wpaint) { VPaint *vp= MEM_callocN(sizeof(VPaint), "VPaint"); @@ -1127,9 +1077,8 @@ static int set_wpaint(bContext *C, wmOperator *op) /* toggle */ if(wp==NULL) wp= scene->toolsettings->wpaint= new_vpaint(1); - paint_init(&wp->paint, NULL); - - toggle_paint_cursor(C, 1); + paint_init(&wp->paint, PAINT_CURSOR_WEIGHT_PAINT); + paint_cursor_start(C, wp_poll); mesh_octree_table(ob, NULL, NULL, 's'); @@ -1145,9 +1094,6 @@ static int set_wpaint(bContext *C, wmOperator *op) /* toggle */ } } else { - if(wp) - toggle_paint_cursor(C, 1); - mesh_octree_table(ob, NULL, NULL, 'e'); } @@ -1188,9 +1134,11 @@ void PAINT_OT_weight_paint_toggle(wmOperatorType *ot) static int vpaint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event) { - Brush *brush = paint_brush(&CTX_data_scene(C)->toolsettings->vpaint->paint); - - toggle_paint_cursor(C, 0); + Paint *p = paint_get_active(CTX_data_scene(C)); + Brush *brush = paint_brush(p); + + WM_paint_cursor_end(CTX_wm_manager(C), p->paint_cursor); + p->paint_cursor = NULL; brush_radial_control_invoke(op, brush, 1); return WM_radial_control_invoke(C, op, event); } @@ -1199,7 +1147,7 @@ static int vpaint_radial_control_modal(bContext *C, wmOperator *op, wmEvent *eve { int ret = WM_radial_control_modal(C, op, event); if(ret != OPERATOR_RUNNING_MODAL) - toggle_paint_cursor(C, 0); + paint_cursor_start(C, vp_poll); return ret; } @@ -1211,8 +1159,11 @@ static int vpaint_radial_control_exec(bContext *C, wmOperator *op) static int wpaint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event) { - Brush *brush = paint_brush(&CTX_data_scene(C)->toolsettings->wpaint->paint); - toggle_paint_cursor(C, 1); + Paint *p = paint_get_active(CTX_data_scene(C)); + Brush *brush = paint_brush(p); + + WM_paint_cursor_end(CTX_wm_manager(C), p->paint_cursor); + p->paint_cursor = NULL; brush_radial_control_invoke(op, brush, 1); return WM_radial_control_invoke(C, op, event); } @@ -1221,7 +1172,7 @@ static int wpaint_radial_control_modal(bContext *C, wmOperator *op, wmEvent *eve { int ret = WM_radial_control_modal(C, op, event); if(ret != OPERATOR_RUNNING_MODAL) - toggle_paint_cursor(C, 1); + paint_cursor_start(C, wp_poll); return ret; } @@ -1614,11 +1565,6 @@ static int set_vpaint(bContext *C, wmOperator *op) /* toggle */ if(ob->mode & OB_MODE_VERTEX_PAINT) { ob->mode &= ~OB_MODE_VERTEX_PAINT; - - if(vp) { - toggle_paint_cursor(C, 0); - vp->paintcursor= NULL; - } } else { ob->mode |= OB_MODE_VERTEX_PAINT; @@ -1629,9 +1575,9 @@ static int set_vpaint(bContext *C, wmOperator *op) /* toggle */ if(vp==NULL) vp= scene->toolsettings->vpaint= new_vpaint(0); - toggle_paint_cursor(C, 0); + paint_cursor_start(C, vp_poll); - paint_init(&vp->paint, NULL); + paint_init(&vp->paint, PAINT_CURSOR_VERTEX_PAINT); } if (me) diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index e0206210799..76c5c3504da 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -1549,8 +1549,6 @@ static int sculpt_toggle_mode(bContext *C, wmOperator *op) free_sculptsession(&ob->sculpt); } else { - const char col[3] = {255, 100, 100}; - /* Enter sculptmode */ ob->mode |= OB_MODE_SCULPT; @@ -1564,7 +1562,7 @@ static int sculpt_toggle_mode(bContext *C, wmOperator *op) free_sculptsession(&ob->sculpt); ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session"); - paint_init(&ts->sculpt->paint, col); + paint_init(&ts->sculpt->paint, PAINT_CURSOR_SCULPT); paint_cursor_start(C, sculpt_poll); diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index d220c707143..8e8c9a9837c 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -151,7 +151,7 @@ static void rna_SpaceImageEditor_paint_update(bContext *C, PointerRNA *ptr) Scene *scene= CTX_data_scene(C); if(scene) - paint_init(&scene->toolsettings->imapaint.paint, NULL); + paint_init(&scene->toolsettings->imapaint.paint, PAINT_CURSOR_TEXTURE_PAINT); } static int rna_SpaceImageEditor_show_render_get(PointerRNA *ptr) From ec6b14bb073fdd207b9cd2f93c8db4a8cfd9aaf3 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Thu, 20 Aug 2009 16:43:55 +0000 Subject: [PATCH 26/73] 2.5 texture paint: * Little bugfix, was passing an invalid pointer --- source/blender/editors/sculpt_paint/paint_image.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 8a8041abbff..2dcd7a64947 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -5174,7 +5174,7 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) me->mtface= CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DEFAULT, NULL, me->totface); - paint_init(&scene->toolsettings->imapaint.paint, NULL); + paint_init(&scene->toolsettings->imapaint.paint, PAINT_CURSOR_TEXTURE_PAINT); if(U.glreslimit != 0) GPU_free_images(); From fda97809bc6521e746e56341d5c7e7f19864d52c Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Thu, 20 Aug 2009 17:37:38 +0000 Subject: [PATCH 27/73] 2.5 Multires: * Fixed a memory corruption bug when deleting a multiresmodifier, was hanging on to a bad pointer. Reported on IRC by lusque --- source/blender/blenkernel/BKE_multires.h | 5 +-- .../blender/blenkernel/intern/cdderivedmesh.c | 36 ++++++++++++------- source/blender/blenkernel/intern/modifier.c | 3 +- source/blender/blenkernel/intern/multires.c | 21 ++++++----- source/blender/blenloader/intern/readfile.c | 2 +- 5 files changed, 41 insertions(+), 26 deletions(-) diff --git a/source/blender/blenkernel/BKE_multires.h b/source/blender/blenkernel/BKE_multires.h index 6558212519f..e7c7d92c955 100644 --- a/source/blender/blenkernel/BKE_multires.h +++ b/source/blender/blenkernel/BKE_multires.h @@ -35,10 +35,11 @@ struct Object; typedef struct MultiresSubsurf { struct MultiresModifierData *mmd; - struct Mesh *me; + struct Object *ob; } MultiresSubsurf; /* MultiresDM */ +struct Object *MultiresDM_get_object(struct DerivedMesh *dm); struct Mesh *MultiresDM_get_mesh(struct DerivedMesh *dm); struct DerivedMesh *MultiresDM_new(struct MultiresSubsurf *, struct DerivedMesh*, int, int, int); void *MultiresDM_get_vertnorm(struct DerivedMesh *); @@ -59,7 +60,7 @@ void multires_mark_as_modified(struct Object *ob); void multires_force_update(struct Object *ob); struct DerivedMesh *multires_dm_create_from_derived(struct MultiresModifierData*, struct DerivedMesh*, - struct Mesh *, int, int); + struct Object *, int, int); struct MultiresModifierData *find_multires_modifier(struct Object *ob); int multiresModifier_switch_level(struct Object *, const int); diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 706eece108c..4829be21ed8 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -1297,7 +1297,7 @@ typedef struct MultiresDM { IndexNode *vert_face_map_mem, *vert_edge_map_mem; int *face_offsets; - Mesh *me; + Object *ob; int modified; void (*update)(DerivedMesh*); @@ -1308,15 +1308,19 @@ static void MultiresDM_release(DerivedMesh *dm) MultiresDM *mrdm = (MultiresDM*)dm; int mvert_layer; + /* Check that mmd still exists */ + if(BLI_findindex(&mrdm->ob->modifiers, mrdm->mmd) < 0) + mrdm->mmd = NULL; + /* Before freeing, need to update the displacement map */ - if(dm->needsFree && mrdm->modified) + if(dm->needsFree && mrdm->modified && mrdm->mmd) mrdm->update(dm); /* If the MVert data is being used as the sculpt undo store, don't free it */ mvert_layer = CustomData_get_layer_index(&dm->vertData, CD_MVERT); if(mvert_layer != -1) { CustomDataLayer *cd = &dm->vertData.layers[mvert_layer]; - if(cd->data == mrdm->mmd->undo_verts) + if(mrdm->mmd && cd->data == mrdm->mmd->undo_verts) cd->flag |= CD_FLAG_NOFREE; } @@ -1348,7 +1352,7 @@ DerivedMesh *MultiresDM_new(MultiresSubsurf *ms, DerivedMesh *orig, int numVerts dm = &mrdm->cddm.dm; mrdm->mmd = ms->mmd; - mrdm->me = ms->me; + mrdm->ob = ms->ob; if(dm) { MDisps *disps; @@ -1391,7 +1395,12 @@ DerivedMesh *MultiresDM_new(MultiresSubsurf *ms, DerivedMesh *orig, int numVerts Mesh *MultiresDM_get_mesh(DerivedMesh *dm) { - return ((MultiresDM*)dm)->me; + return get_mesh(((MultiresDM*)dm)->ob); +} + +Object *MultiresDM_get_object(DerivedMesh *dm) +{ + return ((MultiresDM*)dm)->ob; } void *MultiresDM_get_orco(DerivedMesh *dm) @@ -1428,10 +1437,11 @@ void MultiresDM_set_update(DerivedMesh *dm, void (*update)(DerivedMesh*)) ListBase *MultiresDM_get_vert_face_map(DerivedMesh *dm) { MultiresDM *mrdm = (MultiresDM*)dm; + Mesh *me = mrdm->ob->data; if(!mrdm->vert_face_map) - create_vert_face_map(&mrdm->vert_face_map, &mrdm->vert_face_map_mem, mrdm->me->mface, - mrdm->me->totvert, mrdm->me->totface); + create_vert_face_map(&mrdm->vert_face_map, &mrdm->vert_face_map_mem, me->mface, + me->totvert, me->totface); return mrdm->vert_face_map; } @@ -1439,10 +1449,11 @@ ListBase *MultiresDM_get_vert_face_map(DerivedMesh *dm) ListBase *MultiresDM_get_vert_edge_map(DerivedMesh *dm) { MultiresDM *mrdm = (MultiresDM*)dm; + Mesh *me = mrdm->ob->data; if(!mrdm->vert_edge_map) - create_vert_edge_map(&mrdm->vert_edge_map, &mrdm->vert_edge_map_mem, mrdm->me->medge, - mrdm->me->totvert, mrdm->me->totedge); + create_vert_edge_map(&mrdm->vert_edge_map, &mrdm->vert_edge_map_mem, me->medge, + me->totvert, me->totedge); return mrdm->vert_edge_map; } @@ -1450,6 +1461,7 @@ ListBase *MultiresDM_get_vert_edge_map(DerivedMesh *dm) int *MultiresDM_get_face_offsets(DerivedMesh *dm) { MultiresDM *mrdm = (MultiresDM*)dm; + Mesh *me = mrdm->ob->data; int i, accum = 0; if(!mrdm->face_offsets) { @@ -1457,11 +1469,11 @@ int *MultiresDM_get_face_offsets(DerivedMesh *dm) int area = len * len; int t = 1 + len * 3 + area * 3, q = t + len + area; - mrdm->face_offsets = MEM_callocN(sizeof(int) * mrdm->me->totface, "mrdm face offsets"); - for(i = 0; i < mrdm->me->totface; ++i) { + mrdm->face_offsets = MEM_callocN(sizeof(int) * me->totface, "mrdm face offsets"); + for(i = 0; i < me->totface; ++i) { mrdm->face_offsets[i] = accum; - accum += (mrdm->me->mface[i].v4 ? q : t); + accum += (me->mface[i].v4 ? q : t); } } diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 1e2560bf809..4d567245ce1 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -8102,14 +8102,13 @@ static DerivedMesh *multiresModifier_applyModifier(ModifierData *md, Object *ob, int useRenderParams, int isFinalCalc) { MultiresModifierData *mmd = (MultiresModifierData*)md; - Mesh *me = get_mesh(ob); DerivedMesh *final; /* TODO: for now just skip a level1 mesh */ if(mmd->lvl == 1) return dm; - final = multires_dm_create_from_derived(mmd, dm, me, useRenderParams, isFinalCalc); + final = multires_dm_create_from_derived(mmd, dm, ob, useRenderParams, isFinalCalc); if(mmd->undo_signal && mmd->undo_verts && mmd->undo_verts_tot == final->getNumVerts(final)) { int i; MVert *dst = CDDM_get_verts(final); diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index e91f318adad..09a6c27a88c 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -204,10 +204,11 @@ static void VecAddUf(float a[3], float b[3]) a[2] += b[2]; } -static void multires_subdisp(DerivedMesh *orig, Mesh *me, DerivedMesh *final, int lvl, int totlvl, +static void multires_subdisp(DerivedMesh *orig, Object *ob, DerivedMesh *final, int lvl, int totlvl, int totsubvert, int totsubedge, int totsubface, int addverts) { DerivedMesh *mrdm; + Mesh *me = ob->data; MultiresModifierData mmd_sub; MVert *mvs = CDDM_get_verts(final); MVert *mvd, *mvd_f1, *mvs_f1, *mvd_f3, *mvd_f4; @@ -222,7 +223,7 @@ static void multires_subdisp(DerivedMesh *orig, Mesh *me, DerivedMesh *final, in memset(&mmd_sub, 0, sizeof(MultiresModifierData)); mmd_sub.lvl = mmd_sub.totlvl = totlvl; - mrdm = multires_dm_create_from_derived(&mmd_sub, orig, me, 0, 0); + mrdm = multires_dm_create_from_derived(&mmd_sub, orig, ob, 0, 0); mvd = CDDM_get_verts(mrdm); /* Need to map from ccg to mrdm */ @@ -395,7 +396,7 @@ static void multires_subdisp(DerivedMesh *orig, Mesh *me, DerivedMesh *final, in } } - final->needsFree = 1; + final->needsFree = 1; final->release(final); mrdm->needsFree = 1; MultiresDM_mark_as_modified(mrdm); @@ -468,7 +469,7 @@ void multiresModifier_subdivide(MultiresModifierData *mmd, Object *ob, int dista orig = CDDM_from_mesh(me, NULL); memset(&mmd_sub, 0, sizeof(MultiresModifierData)); mmd_sub.lvl = mmd_sub.totlvl = mmd->lvl; - mrdm = multires_dm_create_from_derived(&mmd_sub, orig, me, 0, 0); + mrdm = multires_dm_create_from_derived(&mmd_sub, orig, ob, 0, 0); totsubvert = mrdm->getNumVerts(mrdm); totsubedge = mrdm->getNumEdges(mrdm); totsubface = mrdm->getNumFaces(mrdm); @@ -497,7 +498,7 @@ void multiresModifier_subdivide(MultiresModifierData *mmd, Object *ob, int dista orig = CDDM_from_mesh(me, NULL); - multires_subdisp(orig, me, final, mmd->lvl, mmd->totlvl, totsubvert, totsubedge, totsubface, 0); + multires_subdisp(orig, ob, final, mmd->lvl, mmd->totlvl, totsubvert, totsubedge, totsubface, 0); orig->needsFree = 1; orig->release(orig); @@ -1166,9 +1167,11 @@ static void multiresModifier_disp_run(DerivedMesh *dm, MVert *subco, int invert) static void multiresModifier_update(DerivedMesh *dm) { + Object *ob; Mesh *me; MDisps *mdisps; + ob = MultiresDM_get_object(dm); me = MultiresDM_get_mesh(dm); mdisps = CustomData_get_layer(&me->fdata, CD_MDISPS); @@ -1189,7 +1192,7 @@ static void multiresModifier_update(DerivedMesh *dm) (includes older displacements but not new sculpts) */ mmd.totlvl = totlvl; mmd.lvl = lvl; - subco_dm = multires_dm_create_from_derived(&mmd, orig, me, 0, 0); + subco_dm = multires_dm_create_from_derived(&mmd, orig, ob, 0, 0); cur_lvl_orig_verts = CDDM_get_verts(subco_dm); /* Subtract the original vertex cos from the new vertex cos */ @@ -1199,7 +1202,7 @@ static void multiresModifier_update(DerivedMesh *dm) final = multires_subdisp_pre(dm, totlvl - lvl, 0); - multires_subdisp(orig, me, final, lvl, totlvl, dm->getNumVerts(dm), dm->getNumEdges(dm), + multires_subdisp(orig, ob, final, lvl, totlvl, dm->getNumVerts(dm), dm->getNumEdges(dm), dm->getNumFaces(dm), 1); subco_dm->release(subco_dm); @@ -1226,7 +1229,7 @@ void multires_force_update(Object *ob) } } -struct DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, DerivedMesh *dm, Mesh *me, +struct DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, DerivedMesh *dm, Object *ob, int useRenderParams, int isFinalCalc) { SubsurfModifierData smd; @@ -1235,7 +1238,7 @@ struct DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, D int i; ms.mmd = mmd; - ms.me = me; + ms.ob = ob; memset(&smd, 0, sizeof(SubsurfModifierData)); smd.levels = smd.renderLevels = mmd->lvl - 1; diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 71994b97521..58b439e4cb4 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -9416,7 +9416,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) mmd->lvl = mmd->totlvl; orig = CDDM_from_mesh(me, NULL); - dm = multires_dm_create_from_derived(mmd, orig, me, 0, 0); + dm = multires_dm_create_from_derived(mmd, orig, ob, 0, 0); multires_load_old(dm, me->mr); From f6dcd9376b2d2d0e0b126f6e12a7d83d21d81783 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Thu, 20 Aug 2009 17:59:37 +0000 Subject: [PATCH 28/73] 2.5 Texture RNA: Distorted Noise: "Distortion" Flag was swapped with "Basis". Reported by schuh in IRC. Thanks. --- source/blender/makesrna/intern/rna_texture.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/makesrna/intern/rna_texture.c b/source/blender/makesrna/intern/rna_texture.c index f82edee8ff1..69298fbb8a4 100644 --- a/source/blender/makesrna/intern/rna_texture.c +++ b/source/blender/makesrna/intern/rna_texture.c @@ -1286,13 +1286,13 @@ static void rna_def_texture_distorted_noise(BlenderRNA *brna) RNA_def_property_update(prop, NC_TEXTURE, NULL); prop= RNA_def_property(srna, "noise_basis", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_sdna(prop, NULL, "noisebasis"); + RNA_def_property_enum_sdna(prop, NULL, "noisebasis2"); RNA_def_property_enum_items(prop, prop_noise_basis_items); RNA_def_property_ui_text(prop, "Noise Basis", "Sets the noise basis used for turbulence"); RNA_def_property_update(prop, NC_TEXTURE, NULL); prop= RNA_def_property(srna, "noise_distortion", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_sdna(prop, NULL, "noisebasis2"); + RNA_def_property_enum_sdna(prop, NULL, "noisebasis"); RNA_def_property_enum_items(prop, prop_noise_basis_items); RNA_def_property_ui_text(prop, "Noise Distortion", "Sets the noise basis for the distortion"); RNA_def_property_update(prop, NC_TEXTURE, NULL); From 1772a0a62f86268f01540d4a3692c2bb4c7e6432 Mon Sep 17 00:00:00 2001 From: Diego Borghetti Date: Thu, 20 Aug 2009 18:34:14 +0000 Subject: [PATCH 29/73] Add unsigned char buffer to BLF_draw_buffer and update makefiles for lzo and lzma. I rename the original makefile of lzo (Makefile.bak) and a new one. Also four new option for user-def.mk: WITH_LZO, default true WITH_LZMA, default true NAN_LZO, default extern/lzo NAN_LZMA, default extern/lzma It's easy add support for system libs (using lzo and lzma from OS) but I don't know if it have much sense. Note that I can't test the "unsigned char" buffer because the OGL animation is not working (right ?), but is the same code that for float also the new Makefile work fine here (Linux), but maybe need some tweak on other OS. --- extern/Makefile | 8 ++ extern/lzma/Makefile | 46 ++++++++ extern/lzo/minilzo/Makefile | 131 +++++----------------- source/Makefile | 3 + source/blender/blenfont/intern/blf_font.c | 93 +++++++++------ source/blender/blenkernel/intern/Makefile | 5 + source/nan_definitions.mk | 5 +- 7 files changed, 156 insertions(+), 135 deletions(-) create mode 100644 extern/lzma/Makefile diff --git a/extern/Makefile b/extern/Makefile index 61499da8743..1bebf1e1994 100644 --- a/extern/Makefile +++ b/extern/Makefile @@ -54,6 +54,14 @@ ifeq ($(WITH_OPENJPEG), true) DIRS += libopenjpeg endif +ifeq ($(WITH_LZO), true) + DIRS += lzo/minilzo +endif + +ifeq ($(WITH_LZMA), true) + DIRS += lzma +endif + TARGET = solid all:: diff --git a/extern/lzma/Makefile b/extern/lzma/Makefile new file mode 100644 index 00000000000..11d70dc7847 --- /dev/null +++ b/extern/lzma/Makefile @@ -0,0 +1,46 @@ +# +# $Id$ +# +# ***** BEGIN GPL/BL DUAL 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. The Blender +# Foundation also sells licenses for use in proprietary software under +# the Blender License. See http://www.blender.org/BL/ for information +# about this. +# +# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. +# All rights reserved. +# +# The Original Code is: all of this file. +# +# Contributor(s): +# +# ***** END GPL/BL DUAL LICENSE BLOCK ***** +# +# + +LIBNAME = lzma +DIR = $(OCGDIR)/extern/$(LIBNAME) + +include nan_compile.mk + +install: $(ALL_OR_DEBUG) + @[ -d $(NAN_LZMA) ] || mkdir -p $(NAN_LZMA) + @[ -d $(NAN_LZMA)/lib/$(DEBUG_DIR) ] || mkdir -p $(NAN_LZMA)/lib/$(DEBUG_DIR) + @$(NANBLENDERHOME)/intern/tools/cpifdiff.sh $(DIR)/$(DEBUG_DIR)lib$(LIBNAME).a $(NAN_LZMA)/lib/$(DEBUG_DIR) +ifeq ($(OS),darwin) + ranlib $(NAN_LZMA)/lib/$(DEBUG_DIR)lib$(LIBNAME).a +endif + @$(NANBLENDERHOME)/intern/tools/cpifdiff.sh *.h $(NAN_LZMA) diff --git a/extern/lzo/minilzo/Makefile b/extern/lzo/minilzo/Makefile index a6ee373e8bc..8f3d5042579 100644 --- a/extern/lzo/minilzo/Makefile +++ b/extern/lzo/minilzo/Makefile @@ -1,113 +1,40 @@ # -# a very simple Makefile for miniLZO +# $Id: # -# Copyright (C) 1996-2008 Markus F.X.J. Oberhumer +# ***** BEGIN GPL LICENSE BLOCK ***** # - -PROGRAM = testmini -SOURCES = testmini.c minilzo.c - -default: - @echo "Please choose one of the following targets:" - @echo " gcc: gcc" - @echo " unix: hpux hpux9" - @echo " win32: win32-bc win32-cygwin win32-dm win32-lccwin32" - @echo " win32-intelc win32-mingw win32-vc win32-watcomc" - @echo " dos16: dos16-bc dos16-mc dos16-wc" - @echo " dos32: dos32-djgpp2 dos32-wc" - - -# Make sure that minilzo.h, lzoconf.h and lzodefs.h are in the -# current dircectory. Otherwise you may want to adjust CPPFLAGS. -##CPPFLAGS = -I../include/lzo -I. - -GCC_CFLAGS = -s -Wall -O2 -fomit-frame-pointer - - +# 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. # -# gcc (generic) +# 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. # - -gcc: - gcc $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM) $(SOURCES) - -cc: - cc $(CPPFLAGS) -o $(PROGRAM) $(SOURCES) - - +# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # -# UNIX +# The Original Code is Copyright (C) 2009 Blender Foundation +# All rights reserved. # - -hpux: - cc -Ae $(CPPFLAGS) -o $(PROGRAM) $(SOURCES) - -hpux9: - cc -Aa -D_HPUX_SOURCE $(CPPFLAGS) -o $(PROGRAM) $(SOURCES) - - -# -# Windows (32-bit) +# Contributor(s): none yet. # +# ***** END GPL LICENSE BLOCK ***** -win32-borlandc win32-bc: - bcc32 -O2 -d -w -w-aus $(CPPFLAGS) $(SOURCES) +LIBNAME = minilzo +DIR = $(OCGDIR)/extern/$(LIBNAME) -win32-cygwin32 win32-cygwin: - gcc -mcygwin $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM).exe $(SOURCES) - -win32-digitalmars win32-dm: - dmc -mn -o -w- $(CPPFLAGS) $(SOURCES) - -win32-intelc win32-ic: - icl -nologo -MD -W3 -O2 -GF $(CPPFLAGS) $(SOURCES) - -win32-lccwin32: - @echo "NOTE: need lcc 2002-07-25 or newer, older versions have bugs" - lc -A -unused -O $(CPPFLAGS) $(SOURCES) - -win32-mingw32 win32-mingw: - gcc -mno-cygwin $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM).exe $(SOURCES) - -win32-visualc win32-vc: - cl -nologo -MD -W3 -O2 -GF $(CPPFLAGS) $(SOURCES) - -win32-watcomc win32-wc: - wcl386 -bt=nt -zq -mf -5r -zc -w5 -oneatx $(CPPFLAGS) $(SOURCES) - - -# -# DOS (16-bit) -# - -dos16-borlandc dos16-bc: - bcc -ml -w -d -O -4 $(CPPFLAGS) $(SOURCES) - -dos16-microsoftc dos16-msc dos16-mc: - cl -nologo -f- -AL -O -G2 -W3 $(CPPFLAGS) $(SOURCES) - -dos16-watcomc dos16-wc: - wcl -zq -ml -bt=dos -l=dos -ox -w5 $(CPPFLAGS) $(SOURCES) - - -# -# DOS (32-bit) -# - -dos32-djgpp2 dos32-dj2: - gcc $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM).exe $(SOURCES) - -dos32-watcomc dos32-wc: - wcl386 -zq -mf -bt=dos -l=dos4g -5r -ox -zc $(CPPFLAGS) $(SOURCES) - - -# -# other targets -# - -clean: - rm -f $(PROGRAM) $(PROGRAM).exe $(PROGRAM).map $(PROGRAM).tds - rm -f *.err *.o *.obj - -.PHONY: default clean +include nan_compile.mk +install: $(ALL_OR_DEBUG) + @[ -d $(NAN_LZO) ] || mkdir -p $(NAN_LZO) + @[ -d $(NAN_LZO)/minilzo ] || mkdir -p $(NAN_LZO)/minilzo + @[ -d $(NAN_LZO)/lib/$(DEBUG_DIR) ] || mkdir -p $(NAN_LZO)/lib/$(DEBUG_DIR) + @$(NANBLENDERHOME)/intern/tools/cpifdiff.sh $(DIR)/$(DEBUG_DIR)lib$(LIBNAME).a $(NAN_LZO)/lib/$(DEBUG_DIR) +ifeq ($(OS),darwin) + ranlib $(NAN_LZO)/lib/$(DEBUG_DIR)lib$(LIBNAME).a +endif + @$(NANBLENDERHOME)/intern/tools/cpifdiff.sh *.h $(NAN_LZO)/minilzo diff --git a/source/Makefile b/source/Makefile index cd2e7cf75ba..8e9f66bbe42 100644 --- a/source/Makefile +++ b/source/Makefile @@ -110,6 +110,9 @@ COMLIB += $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaudaspace.a COMLIB += $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_src.a COMLIB += $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_fx.a COMLIB += $(NAN_SAMPLERATE)/lib/$(DEBUG_DIR)libsamplerate.a +COMLIB += $(NAN_LZO)/lib/$(DEBUG_DIR)libminilzo.a +COMLIB += $(NAN_LZMA)/lib/$(DEBUG_DIR)liblzma.a +COMLIB += $(NAN_SMOKE)/lib/$(DEBUG_DIR)/libsmoke.a ifneq ($(NAN_NO_KETSJI),true) COMLIB += $(OCGDIR)/gameengine/bloutines/$(DEBUG_DIR)libbloutines.a diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 432c3b5f854..2cd72809579 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -151,7 +151,7 @@ void blf_font_draw(FontBLF *font, char *str) void blf_font_buffer(FontBLF *font, char *str) { - unsigned char *data; + unsigned char *data, *cbuf; unsigned int c; GlyphBLF *g, *g_prev; FT_Vector delta; @@ -197,30 +197,27 @@ void blf_font_buffer(FontBLF *font, char *str) pen_x += delta.x >> 6; } - if (font->b_fbuf) { - chx= pen_x + ((int)g->pos_x); - - diff= g->height - ((int)g->pos_y); - - if (diff > 0) { - if (g->pitch < 0) - pen_y += diff; - else - pen_y -= diff; - } - else if (diff < 0) { - if (g->pitch < 0) - pen_y -= diff; - else - pen_y += diff; - } - - + chx= pen_x + ((int)g->pos_x); + diff= g->height - ((int)g->pos_y); + if (diff > 0) { if (g->pitch < 0) - chy= pen_y - ((int)g->pos_y); + pen_y += diff; else - chy= pen_y + ((int)g->pos_y); + pen_y -= diff; + } + else if (diff < 0) { + if (g->pitch < 0) + pen_y -= diff; + else + pen_y += diff; + } + if (g->pitch < 0) + chy= pen_y - ((int)g->pos_y); + else + chy= pen_y + ((int)g->pos_y); + + if (font->b_fbuf) { if (chx >= 0 && chx < font->bw && pen_y >= 0 && pen_y < font->bh) { if (g->pitch < 0) yb= 0; @@ -251,20 +248,52 @@ void blf_font_buffer(FontBLF *font, char *str) yb--; } } + } - if (diff > 0) { + if (font->b_cbuf) { + if (chx >= 0 && chx < font->bw && pen_y >= 0 && pen_y < font->bh) { if (g->pitch < 0) - pen_x -= diff; + yb= 0; else - pen_y += diff; - } - else if (diff < 0) { - if (g->pitch < 0) - pen_x += diff; - else - pen_y -= diff; - } + yb= g->height-1; + for (y= 0; y < g->height; y++) { + for (x= 0; x < g->width; x++) { + cbuf= font->b_cbuf + font->bch * ((chx + x) + ((pen_y + y)*font->bw)); + data= g->bitmap + x + (yb * g->pitch); + a= data[0]; + + if (a == 256) { + cbuf[0]= font->b_col[0]; + cbuf[1]= font->b_col[1]; + cbuf[2]= font->b_col[2]; + } + else { + cbuf[0]= (font->b_col[0]*a) + (cbuf[0] * (256-a)); + cbuf[1]= (font->b_col[1]*a) + (cbuf[1] * (256-a)); + cbuf[2]= (font->b_col[2]*a) + (cbuf[2] * (256-a)); + } + } + + if (g->pitch < 0) + yb++; + else + yb--; + } + } + } + + if (diff > 0) { + if (g->pitch < 0) + pen_x -= diff; + else + pen_y += diff; + } + else if (diff < 0) { + if (g->pitch < 0) + pen_x += diff; + else + pen_y -= diff; } pen_x += g->advance; diff --git a/source/blender/blenkernel/intern/Makefile b/source/blender/blenkernel/intern/Makefile index d6d41d6579e..6c2edc9e25f 100644 --- a/source/blender/blenkernel/intern/Makefile +++ b/source/blender/blenkernel/intern/Makefile @@ -90,6 +90,10 @@ CPPFLAGS += -I$(NAN_BULLET2)/include CPPFLAGS += -I$(NAN_FREETYPE)/include CPPFLAGS += -I$(NAN_FREETYPE)/include/freetype2 +# lzo and lzma, for pointcache +CPPFLAGS += -I$(NAN_LZO)/minilzo +CPPFLAGS += -I$(NAN_LZMA) + ifeq ($(WITH_FFMPEG),true) CPPFLAGS += -DWITH_FFMPEG CPPFLAGS += $(NAN_FFMPEGCFLAGS) @@ -111,3 +115,4 @@ ifeq ($(WITH_QUICKTIME), true) CPPFLAGS += -I../../quicktime CPPFLAGS += -DWITH_QUICKTIME endif + diff --git a/source/nan_definitions.mk b/source/nan_definitions.mk index b3f36dd3b5c..7fab61d5247 100644 --- a/source/nan_definitions.mk +++ b/source/nan_definitions.mk @@ -113,7 +113,10 @@ ifndef CONFIG_GUESS export WITH_OPENEXR ?= true export WITH_DDS ?= true export WITH_OPENJPEG ?= true - + export WITH_LZO ?= true + export WITH_LZMA ?= true + export NAN_LZO ?= $(LCGDIR)/lzo + export NAN_LZMA ?= $(LCGDIR)/lzma ifeq ($(NAN_USE_FFMPEG_CONFIG), true) export NAN_FFMPEG ?= $(shell ffmpeg-config --prefix) From c1100361e20ad174aea83160e2072427d12d4fd3 Mon Sep 17 00:00:00 2001 From: Andrea Weikert Date: Thu, 20 Aug 2009 18:39:25 +0000 Subject: [PATCH 30/73] 2.5 filebrowser * code cleanup: remove duplication in drawing, join list and preview drawing --- .../blender/editors/include/ED_fileselect.h | 1 + source/blender/editors/space_file/file_draw.c | 229 ++++++++---------- source/blender/editors/space_file/filesel.c | 1 + .../blender/editors/space_file/space_file.c | 7 +- 4 files changed, 98 insertions(+), 140 deletions(-) diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h index c56807ad09a..57ab6a5f8f6 100644 --- a/source/blender/editors/include/ED_fileselect.h +++ b/source/blender/editors/include/ED_fileselect.h @@ -65,6 +65,7 @@ typedef struct FileLayout short height; short flag; short dirty; + short textheight; float column_widths[MAX_FILE_COLUMN]; } FileLayout; diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 5a07c6a7550..00024ffa961 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -353,59 +353,9 @@ void file_calc_previews(const bContext *C, ARegion *ar) UI_view2d_totRect_set(v2d, sfile->layout->width, sfile->layout->height); } -void file_draw_previews(const bContext *C, ARegion *ar) +static void file_draw_preview(short sx, short sy, ImBuf *imb, FileLayout *layout, short dropshadow) { - SpaceFile *sfile= CTX_wm_space_file(C); - FileSelectParams* params= ED_fileselect_get_params(sfile); - FileLayout* layout= ED_fileselect_get_layout(sfile, ar); - View2D *v2d= &ar->v2d; - struct FileList* files = sfile->files; - int numfiles; - struct direntry *file; - short sx, sy; - ImBuf* imb=0; - int i; - int colorid = 0; - int offset; - int is_icon; - - if (!files) return; - - filelist_imgsize(files,sfile->layout->prv_w,sfile->layout->prv_h); - numfiles = filelist_numfiles(files); - - sx = v2d->cur.xmin + layout->tile_border_x; - sy = v2d->cur.ymax - layout->tile_border_y; - - offset = ED_fileselect_layout_offset(layout, 0, 0); - if (offset<0) offset=0; - for (i=offset; (i < numfiles) && (i < (offset+(layout->rows+2)*layout->columns)); ++i) - { - ED_fileselect_layout_tilepos(layout, i, &sx, &sy); - sx += v2d->tot.xmin+2; - sy = v2d->tot.ymax - sy; - file = filelist_file(files, i); - - if (file->flags & ACTIVE) { - colorid = TH_HILITE; - draw_tile(sx - 1, sy, sfile->layout->tile_w + 1, sfile->layout->tile_h, colorid,0); - } else if (params->active_file == i) { - colorid = TH_ACTIVE; - draw_tile(sx - 1, sy, sfile->layout->tile_w + 1, sfile->layout->tile_h, colorid,0); - } - - if ( (file->flags & IMAGEFILE) /* || (file->flags & MOVIEFILE) */) - { - filelist_loadimage(files, i); - } - is_icon = 0; - imb = filelist_getimage(files, i); - if (!imb) { - imb = filelist_geticon(files,i); - is_icon = 1; - } - - if (imb) { + if (imb) { float fx, fy; float dx, dy; short xco, yco; @@ -433,15 +383,15 @@ void file_draw_previews(const bContext *C, ARegion *ar) ey = (short)scaledy; fx = ((float)layout->prv_w - (float)ex)/2.0f; fy = ((float)layout->prv_h - (float)ey)/2.0f; - dx = (fx + 0.5f + sfile->layout->prv_border_x); - dy = (fy + 0.5f - sfile->layout->prv_border_y); + dx = (fx + 0.5f + layout->prv_border_x); + dy = (fy + 0.5f - layout->prv_border_y); xco = (float)sx + dx; - yco = (float)sy - sfile->layout->prv_h + dy; + yco = (float)sy - layout->prv_h + dy; glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* shadow */ - if (!is_icon && (file->flags & IMAGEFILE)) + if (dropshadow) uiDrawBoxShadow(220, xco, yco, xco + ex, yco + ey); glEnable(GL_BLEND); @@ -451,7 +401,7 @@ void file_draw_previews(const bContext *C, ARegion *ar) glaDrawPixelsTexScaled(xco, yco, imb->x, imb->y, GL_UNSIGNED_BYTE, imb->rect, scale, scale); /* border */ - if (!is_icon && (file->flags & IMAGEFILE)) { + if (dropshadow) { glColor4f(0.0f, 0.0f, 0.0f, 0.4f); fdrawbox(xco, yco, xco + ex, yco + ey); } @@ -459,41 +409,6 @@ void file_draw_previews(const bContext *C, ARegion *ar) glDisable(GL_BLEND); imb = 0; } - - /* shadow */ - UI_ThemeColorShade(TH_BACK, -20); - - - if (S_ISDIR(file->type)) { - glColor4f(1.0f, 1.0f, 0.9f, 1.0f); - } - else if (file->flags & IMAGEFILE) { - UI_ThemeColor(TH_SEQ_IMAGE); - } - else if (file->flags & MOVIEFILE) { - UI_ThemeColor(TH_SEQ_MOVIE); - } - else if (file->flags & BLENDERFILE) { - UI_ThemeColor(TH_SEQ_SCENE); - } - else { - if (params->active_file == i) { - UI_ThemeColor(TH_GRID); /* grid used for active text */ - } else if (file->flags & ACTIVE) { - UI_ThemeColor(TH_TEXT_HI); - } else { - UI_ThemeColor(TH_TEXT); - } - } - - file_draw_string(sx + layout->prv_border_x, sy+4, file->relname, layout->tile_w, layout->tile_h, FILE_SHORTEN_END); - - if (!sfile->loadimage_timer) - sfile->loadimage_timer= WM_event_add_window_timer(CTX_wm_window(C), TIMER1, 1.0/30.0); /* max 30 frames/sec. */ - - } - - uiSetRoundBox(0); } static void renamebutton_cb(bContext *C, void *arg1, char *oldname) @@ -523,6 +438,39 @@ static void renamebutton_cb(bContext *C, void *arg1, char *oldname) } } + +static void draw_background(FileLayout *layout, View2D *v2d) +{ + int i; + short sy; + + /* alternating flat shade background */ + for (i=0; (i <= layout->rows); i+=2) + { + sy = v2d->cur.ymax - i*(layout->tile_h+2*layout->tile_border_y) - layout->tile_border_y; + + UI_ThemeColorShade(TH_BACK, -7); + glRectf(v2d->cur.xmin, sy, v2d->cur.xmax, sy+layout->tile_h+2*layout->tile_border_y); + + } +} + +static void draw_dividers(FileLayout *layout, View2D *v2d) +{ + short sx; + + /* vertical column dividers */ + sx = v2d->tot.xmin; + while (sx < v2d->cur.xmax) { + sx += (layout->tile_w+2*layout->tile_border_x); + + UI_ThemeColorShade(TH_BACK, 30); + sdrawline(sx+1, v2d->cur.ymax - layout->tile_border_y , sx+1, v2d->cur.ymin); + UI_ThemeColorShade(TH_BACK, -30); + sdrawline(sx, v2d->cur.ymax - layout->tile_border_y , sx, v2d->cur.ymin); + } +} + void file_draw_list(const bContext *C, ARegion *ar) { SpaceFile *sfile= CTX_wm_space_file(C); @@ -531,6 +479,7 @@ void file_draw_list(const bContext *C, ARegion *ar) View2D *v2d= &ar->v2d; struct FileList* files = sfile->files; struct direntry *file; + ImBuf *imb; int numfiles; int numfiles_layout; int colorid = 0; @@ -538,6 +487,7 @@ void file_draw_list(const bContext *C, ARegion *ar) int offset; int i; float sw, spos; + short is_icon; numfiles = filelist_numfiles(files); @@ -547,26 +497,11 @@ void file_draw_list(const bContext *C, ARegion *ar) offset = ED_fileselect_layout_offset(layout, 0, 0); if (offset<0) offset=0; - /* alternating flat shade background */ - for (i=0; (i <= layout->rows); i+=2) - { - sx = v2d->cur.xmin; - sy = v2d->cur.ymax - i*(layout->tile_h+2*layout->tile_border_y) - layout->tile_border_y; + if (params->display != FILE_IMGDISPLAY) { - UI_ThemeColorShade(TH_BACK, -7); - glRectf(v2d->cur.xmin, sy, v2d->cur.xmax, sy+layout->tile_h+2*layout->tile_border_y); - - } + draw_background(layout, v2d); - /* vertical column dividers */ - sx = v2d->tot.xmin; - while (sx < ar->v2d.cur.xmax) { - sx += (sfile->layout->tile_w+2*sfile->layout->tile_border_x); - - UI_ThemeColorShade(TH_BACK, 30); - sdrawline(sx+1, ar->v2d.cur.ymax - layout->tile_border_y , sx+1, ar->v2d.cur.ymin); - UI_ThemeColorShade(TH_BACK, -30); - sdrawline(sx, ar->v2d.cur.ymax - layout->tile_border_y , sx, ar->v2d.cur.ymin); + draw_dividers(layout, v2d); } sx = ar->v2d.cur.xmin + layout->tile_border_x; @@ -594,16 +529,33 @@ void file_draw_list(const bContext *C, ARegion *ar) } spos = sx; - file_draw_icon(spos, sy-3, get_file_icon(file), ICON_DEFAULT_WIDTH, ICON_DEFAULT_WIDTH); - spos += ICON_DEFAULT_WIDTH + 4; - + + if ( FILE_IMGDISPLAY == params->display ) { + if ( (file->flags & IMAGEFILE) /* || (file->flags & MOVIEFILE) */) { + filelist_loadimage(files, i); + } + is_icon = 0; + imb = filelist_getimage(files, i); + if (!imb) { + imb = filelist_geticon(files,i); + is_icon = 1; + } + + file_draw_preview(sx, sy, imb, layout, !is_icon && (file->flags & IMAGEFILE)); + + } else { + file_draw_icon(spos, sy-3, get_file_icon(file), ICON_DEFAULT_WIDTH, ICON_DEFAULT_WIDTH); + spos += ICON_DEFAULT_WIDTH + 4; + } + UI_ThemeColor4(TH_TEXT); - + sw = file_string_width(file->relname); if (file->flags & EDITING) { + short but_width = (FILE_IMGDISPLAY == params->display) ? layout->tile_w : layout->column_widths[COLUMN_NAME]; uiBlock *block = uiBeginBlock(C, ar, "FileName", UI_EMBOSS); uiBut *but = uiDefBut(block, TEX, 1, "", spos, sy-layout->tile_h-3, - layout->column_widths[COLUMN_NAME], layout->tile_h, file->relname, 1.0f, (float)FILE_MAX,0,0,""); + but_width, layout->textheight*2, file->relname, 1.0f, (float)FILE_MAX,0,0,""); uiButSetRenameFunc(but, renamebutton_cb, file); if ( 0 == uiButActiveOnly(C, block, but)) { file->flags &= ~EDITING; @@ -611,36 +563,42 @@ void file_draw_list(const bContext *C, ARegion *ar) uiEndBlock(C, block); uiDrawBlock(C, block); } else { - file_draw_string(spos, sy, file->relname, sw, layout->tile_h, FILE_SHORTEN_END); + float name_width = (FILE_IMGDISPLAY == params->display) ? layout->tile_w : sw; + file_draw_string(spos, sy, file->relname, name_width, layout->tile_h, FILE_SHORTEN_END); } - spos += layout->column_widths[COLUMN_NAME] + 12; - if (params->display == FILE_SHOWSHORT) { + + uiSetRoundBox(0); + + if (params->display == FILE_SHORTDISPLAY) { + spos += layout->column_widths[COLUMN_NAME] + 12; if (!(file->type & S_IFDIR)) { sw = file_string_width(file->size); spos += layout->column_widths[COLUMN_SIZE] + 12 - sw; file_draw_string(spos, sy, file->size, sw+1, layout->tile_h, FILE_SHORTEN_END); } - } else { -#if 0 // XXX TODO: add this for non-windows systems + } else if (params->display == FILE_LONGDISPLAY) { + spos += layout->column_widths[COLUMN_NAME] + 12; + +#ifndef WIN32 /* rwx rwx rwx */ spos += 20; - sw = UI_GetStringWidth(file->mode1); - file_draw_string(spos, sy, file->mode1, sw, layout->tile_h); - - spos += 30; - sw = UI_GetStringWidth(file->mode2); - file_draw_string(spos, sy, file->mode2, sw, layout->tile_h); + sw = file_string_width(file->mode1); + file_draw_string(spos, sy, file->mode1, sw, layout->tile_h, FILE_SHORTEN_END); + spos += layout->column_widths[COLUMN_MODE1] + 12; - spos += 30; - sw = UI_GetStringWidth(file->mode3); - file_draw_string(spos, sy, file->mode3, sw, layout->tile_h); - - spos += 30; - sw = UI_GetStringWidth(file->owner); - file_draw_string(spos, sy, file->owner, sw, layout->tile_h); + sw = file_string_width(file->mode2); + file_draw_string(spos, sy, file->mode2, sw, layout->tile_h, FILE_SHORTEN_END); + spos += layout->column_widths[COLUMN_MODE2] + 12; + + sw = file_string_width(file->mode3); + file_draw_string(spos, sy, file->mode3, sw, layout->tile_h, FILE_SHORTEN_END); + spos += layout->column_widths[COLUMN_MODE3] + 12; + + sw = file_string_width(file->owner); + file_draw_string(spos, sy, file->owner, sw, layout->tile_h, FILE_SHORTEN_END); + spos += layout->column_widths[COLUMN_OWNER] + 12; #endif - sw = file_string_width(file->date); file_draw_string(spos, sy, file->date, sw, layout->tile_h, FILE_SHORTEN_END); spos += layout->column_widths[COLUMN_DATE] + 12; @@ -656,6 +614,9 @@ void file_draw_list(const bContext *C, ARegion *ar) } } } + + if (!sfile->loadimage_timer) + sfile->loadimage_timer= WM_event_add_window_timer(CTX_wm_window(C), TIMER1, 1.0/30.0); /* max 30 frames/sec. */ } diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 8ee7d3515b5..f300505933f 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -287,6 +287,7 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, struct ARegion *ar) numfiles = filelist_numfiles(sfile->files); textheight = file_font_pointsize(); layout = sfile->layout; + layout->textheight = textheight; if (params->display == FILE_IMGDISPLAY) { layout->prv_w = 96; diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index ea640eab090..22ad03f3523 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -310,12 +310,7 @@ static void file_main_area_draw(const bContext *C, ARegion *ar) file_hilight_set(sfile, ar, event->x, event->y); } - if (params->display == FILE_IMGDISPLAY) { - file_draw_previews(C, ar); - } else { - file_draw_list(C, ar); - } - + file_draw_list(C, ar); /* reset view matrix */ UI_view2d_view_restore(C); From 86e38ef6f7d9d1970826b8b5e944b189d0065fd9 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Thu, 20 Aug 2009 19:46:53 +0000 Subject: [PATCH 31/73] 2.5 Paint: * Evil backbuf drawing strikes again. In paint modes, it was causing the tool panel to flash black, bad glScissor. --- source/blender/editors/include/ED_screen.h | 1 + source/blender/editors/screen/area.c | 2 +- source/blender/editors/space_view3d/view3d_draw.c | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index 6cb7593e07d..22a3e737277 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -58,6 +58,7 @@ void ED_region_panels_init(struct wmWindowManager *wm, struct ARegion *ar); void ED_region_panels(const struct bContext *C, struct ARegion *ar, int vertical, char *context, int contextnr); void ED_region_header_init(struct ARegion *ar); void ED_region_header(const struct bContext *C, struct ARegion *ar); +void region_scissor_winrct(struct ARegion *ar, struct rcti *winrct); /* spaces */ void ED_spacetypes_init(void); diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index ea1541a4e02..320574fe8b3 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -249,7 +249,7 @@ void ED_area_overdraw(bContext *C) } /* get scissor rect, checking overlapping regions */ -static void region_scissor_winrct(ARegion *ar, rcti *winrct) +void region_scissor_winrct(ARegion *ar, rcti *winrct) { *winrct= ar->winrct; diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 3140ae76d4b..905657910b8 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -1092,6 +1092,7 @@ void backdrawview3d(Scene *scene, ARegion *ar, View3D *v3d) { RegionView3D *rv3d= ar->regiondata; struct Base *base = scene->basact; + rcti winrct; /*for 2.43 release, don't use glext and just define the constant. this to avoid possibly breaking platforms before release.*/ @@ -1137,6 +1138,9 @@ void backdrawview3d(Scene *scene, ARegion *ar, View3D *v3d) glDisable(GL_DITHER); + region_scissor_winrct(ar, &winrct); + glScissor(winrct.xmin, winrct.ymin, winrct.xmax - winrct.xmin, winrct.ymax - winrct.ymin); + glClearColor(0.0, 0.0, 0.0, 0.0); if(v3d->zbuf) { glEnable(GL_DEPTH_TEST); From 23d9b6bcec742307498d927738c8837458a212c1 Mon Sep 17 00:00:00 2001 From: Diego Borghetti Date: Thu, 20 Aug 2009 21:09:48 +0000 Subject: [PATCH 32/73] View3D: shift+c center the view but no the cursor like 2.4x Probably missing because is not inside view3d_home, it's in the main winqreadview3dspace function. --- source/blender/editors/space_view3d/view3d_edit.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 5ef64274e72..a7ea19e49f9 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -857,6 +857,7 @@ static int viewhome_exec(bContext *C, wmOperator *op) /* was view3d_home() in 2. RegionView3D *rv3d= CTX_wm_region_view3d(C); Scene *scene= CTX_data_scene(C); Base *base; + float *curs; int center= RNA_boolean_get(op->ptr, "center"); @@ -866,6 +867,10 @@ static int viewhome_exec(bContext *C, wmOperator *op) /* was view3d_home() in 2. if(center) { min[0]= min[1]= min[2]= 0.0f; max[0]= max[1]= max[2]= 0.0f; + + /* in 2.4x this also move the cursor to (0, 0, 0) (with shift+c). */ + curs= give_cursor(scene, v3d); + curs[0]= curs[1]= curs[2]= 0.0; } else { INIT_MINMAX(min, max); From 2881393fbb42cca81ee4d36895fc248a22c54823 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Fri, 21 Aug 2009 00:46:36 +0000 Subject: [PATCH 33/73] 2.5 Paint: * Added airbrush and airbrush rate options to paint stroke. Works for sculpt, vertex paint, and weight paint. --- release/ui/space_view3d_toolbar.py | 5 +++++ .../blender/editors/sculpt_paint/paint_stroke.c | 17 ++++++++++++++++- .../blender/editors/sculpt_paint/paint_vertex.c | 4 ++++ source/blender/editors/sculpt_paint/sculpt.c | 2 ++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/release/ui/space_view3d_toolbar.py b/release/ui/space_view3d_toolbar.py index 5f42ff1d8b8..35df4dc8b54 100644 --- a/release/ui/space_view3d_toolbar.py +++ b/release/ui/space_view3d_toolbar.py @@ -449,6 +449,11 @@ class VIEW3D_PT_tools_brush_stroke(PaintPanel): col.active = brush.space col.itemR(brush, "spacing", text="Distance", slider=True) + layout.itemR(brush, "airbrush") + col = layout.column() + col.active = brush.airbrush + col.itemR(brush, "rate", slider=True) + class VIEW3D_PT_tools_brush_curve(PaintPanel): __label__ = "Curve" diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 715399af888..bd9ea50e0f8 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -43,6 +43,8 @@ #include "BLI_arithb.h" +#include "PIL_time.h" + #include "BIF_gl.h" #include "BIF_glutil.h" @@ -57,6 +59,7 @@ typedef struct PaintStroke { void *mode_data; void *smooth_stroke_cursor; + wmTimer *timer; /* Cached values */ ViewContext vc; @@ -227,15 +230,22 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event) PaintStroke *stroke = op->customdata; float mouse[2]; + if(event->type == TIMER && (event->customdata != stroke->timer)) + return OPERATOR_RUNNING_MODAL; + if(!stroke->stroke_started) { stroke->last_mouse_position[0] = event->x; stroke->last_mouse_position[1] = event->y; stroke->stroke_started = stroke->test_start(C, op, event); - if(stroke->stroke_started) + if(stroke->stroke_started) { stroke->smooth_stroke_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), paint_poll, paint_draw_smooth_stroke, stroke); + if(stroke->brush->flag & BRUSH_AIRBRUSH) + stroke->timer = WM_event_add_window_timer(CTX_wm_window(C), TIMER, stroke->brush->rate); + } + ED_region_tag_redraw(ar); } @@ -254,9 +264,14 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event) /* TODO: fix hardcoded event here */ if(event->type == LEFTMOUSE && event->val == 0) { + /* Exit stroke, free data */ + if(stroke->smooth_stroke_cursor) WM_paint_cursor_end(CTX_wm_manager(C), stroke->smooth_stroke_cursor); + if(stroke->timer) + WM_event_remove_window_timer(CTX_wm_window(C), stroke->timer); + stroke->done(C, stroke); MEM_freeN(stroke); return OPERATOR_FINISHED; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 704773795e8..bc2ac480657 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1513,6 +1513,8 @@ static int wpaint_invoke(bContext *C, wmOperator *op, wmEvent *event) /* add modal handler */ WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op); + + op->type->modal(C, op, event); return OPERATOR_RUNNING_MODAL; } @@ -1803,6 +1805,8 @@ static int vpaint_invoke(bContext *C, wmOperator *op, wmEvent *event) /* add modal handler */ WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op); + + op->type->modal(C, op, event); return OPERATOR_RUNNING_MODAL; } diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 76c5c3504da..adaba804799 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -1439,6 +1439,8 @@ static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, wmEvent *even /* add modal handler */ WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op); + + op->type->modal(C, op, event); return OPERATOR_RUNNING_MODAL; } From 1be67b60fd08f640b56db23e08ad0469318f26b3 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 21 Aug 2009 02:51:56 +0000 Subject: [PATCH 34/73] 2.5: Modifiers & Menus * Popup menus now remember the last clicked item again. * Modifier and File Format menus are now organized in multiple columns with categories. * Hook, explode, uv project modifiers have all their buttons again with the relevant operators implemented. * Modifiers that can't be added by the user, or don't work on curves for example, are not in the menu anymore. * Fix search menu overlapping buttons when near the bottom of the screen. * Fix uv layers search menu not working in some modifiers. * Cleanup popup menu code a bit, layout engine is used in more cases now instead of ugly position calculation code. --- release/ui/buttons_data_mesh.py | 4 +- release/ui/buttons_data_modifier.py | 63 +- release/ui/buttons_material.py | 2 +- release/ui/space_image.py | 2 +- source/blender/blenkernel/BKE_modifier.h | 5 +- source/blender/blenkernel/intern/modifier.c | 5 +- source/blender/editors/include/UI_interface.h | 4 +- source/blender/editors/interface/interface.c | 25 +- .../editors/interface/interface_handlers.c | 21 +- .../editors/interface/interface_intern.h | 14 +- .../editors/interface/interface_layout.c | 62 +- .../editors/interface/interface_regions.c | 840 +++++------------- .../editors/interface/interface_templates.c | 4 +- source/blender/editors/object/object_edit.c | 9 +- source/blender/editors/object/object_intern.h | 11 +- .../blender/editors/object/object_modifier.c | 302 +++++-- source/blender/editors/object/object_ops.c | 7 +- source/blender/editors/screen/area.c | 5 - .../editors/space_view3d/view3d_header.c | 5 - source/blender/makesdna/DNA_modifier_types.h | 4 +- source/blender/makesrna/intern/rna_define.c | 10 +- source/blender/makesrna/intern/rna_modifier.c | 89 +- source/blender/makesrna/intern/rna_scene.c | 8 +- .../windowmanager/intern/wm_operators.c | 2 - 24 files changed, 708 insertions(+), 795 deletions(-) diff --git a/release/ui/buttons_data_mesh.py b/release/ui/buttons_data_mesh.py index b681218a8fe..c7663be1923 100644 --- a/release/ui/buttons_data_mesh.py +++ b/release/ui/buttons_data_mesh.py @@ -105,7 +105,7 @@ class DATA_PT_vertex_groups(DataButtonsPanel): row = layout.row() row.itemR(group, "name") - if context.edit_object: + if ob.mode == 'EDIT': row = layout.row() sub = row.row(align=True) @@ -180,7 +180,7 @@ class DATA_PT_shape_keys(DataButtonsPanel): layout.itemR(kb, "name") - if context.edit_object: + if ob.mode == 'EDIT': layout.enabled = False class DATA_PT_uv_texture(DataButtonsPanel): diff --git a/release/ui/buttons_data_modifier.py b/release/ui/buttons_data_modifier.py index 436baa540d4..cc50256f216 100644 --- a/release/ui/buttons_data_modifier.py +++ b/release/ui/buttons_data_modifier.py @@ -170,7 +170,7 @@ class DATA_PT_modifiers(DataButtonsPanel): if md.texture_coordinates == 'OBJECT': layout.itemR(md, "texture_coordinate_object", text="Object") elif md.texture_coordinates == 'UV' and ob.type == 'MESH': - layout.item_pointerR(md, "uv_layer", ob.data, "uv_layers") + layout.item_pointerR(md, "uv_layer", ob.data, "uv_textures") def EDGE_SPLIT(self, layout, ob, md): split = layout.split() @@ -187,21 +187,36 @@ class DATA_PT_modifiers(DataButtonsPanel): def EXPLODE(self, layout, ob, md): layout.item_pointerR(md, "vertex_group", ob, "vertex_groups") layout.itemR(md, "protect") - layout.itemR(md, "split_edges") - layout.itemR(md, "unborn") - layout.itemR(md, "alive") - layout.itemR(md, "dead") - # Missing: "Refresh" and "Clear Vertex Group" Operator + + flow = layout.column_flow(2) + flow.itemR(md, "split_edges") + flow.itemR(md, "unborn") + flow.itemR(md, "alive") + flow.itemR(md, "dead") + + layout.itemO("object.explode_refresh", text="Refresh"); def FLUID_SIMULATION(self, layout, ob, md): layout.itemL(text="See Fluid panel.") def HOOK(self, layout, ob, md): - layout.itemR(md, "falloff") - layout.itemR(md, "force", slider=True) layout.itemR(md, "object") layout.item_pointerR(md, "vertex_group", ob, "vertex_groups") - # Missing: "Reset" and "Recenter" Operator + + split = layout.split() + split.itemR(md, "falloff") + split.itemR(md, "force", slider=True) + + layout.itemS() + + row = layout.row() + row.itemO("object.hook_reset", text="Reset") + row.itemO("object.hook_recenter", text="Recenter") + + if ob.mode == 'EDIT': + row = layout.row() + row.itemO("object.hook_select", text="Select") + row.itemO("object.hook_assign", text="Assign") def LATTICE(self, layout, ob, md): layout.itemR(md, "object") @@ -222,7 +237,7 @@ class DATA_PT_modifiers(DataButtonsPanel): layout.itemS() - layout.itemO("object.modifier_mdef_bind", text="Bind") + layout.itemO("object.meshdeform_bind", text="Bind") row = layout.row() row.itemR(md, "precision") row.itemR(md, "dynamic") @@ -346,16 +361,26 @@ class DATA_PT_modifiers(DataButtonsPanel): def UV_PROJECT(self, layout, ob, md): if ob.type == 'MESH': - layout.item_pointerR(md, "uv_layer", ob.data, "uv_layers") - #layout.itemR(md, "projectors") + layout.item_pointerR(md, "uv_layer", ob.data, "uv_textures") layout.itemR(md, "image") layout.itemR(md, "override_image") - layout.itemL(text="Aspect Ratio:") - col = layout.column(align=True) - col.itemR(md, "horizontal_aspect_ratio", text="Horizontal") - col.itemR(md, "vertical_aspect_ratio", text="Vertical") - - #"Projectors" don't work. + + split = layout.split() + + col = split.column() + col.itemL(text="Aspect Ratio:") + + sub = col.column(align=True) + sub.itemR(md, "horizontal_aspect_ratio", text="Horizontal") + sub.itemR(md, "vertical_aspect_ratio", text="Vertical") + + col = split.column() + col.itemL(text="Projectors:") + + sub = col.column(align=True) + sub.itemR(md, "num_projectors", text="Number") + for proj in md.projectors: + sub.itemR(proj, "object", text="") def WAVE(self, layout, ob, md): split = layout.split() @@ -387,7 +412,7 @@ class DATA_PT_modifiers(DataButtonsPanel): layout.itemR(md, "texture") layout.itemR(md, "texture_coordinates") if md.texture_coordinates == 'MAP_UV' and ob.type == 'MESH': - layout.item_pointerR(md, "uv_layer", ob.data, "uv_layers") + layout.item_pointerR(md, "uv_layer", ob.data, "uv_textures") elif md.texture_coordinates == 'OBJECT': layout.itemR(md, "texture_coordinates_object") diff --git a/release/ui/buttons_material.py b/release/ui/buttons_material.py index b971a678926..ed3888ee4d8 100644 --- a/release/ui/buttons_material.py +++ b/release/ui/buttons_material.py @@ -48,7 +48,7 @@ class MATERIAL_PT_context_material(MaterialButtonsPanel): col.itemO("object.material_slot_add", icon="ICON_ZOOMIN", text="") col.itemO("object.material_slot_remove", icon="ICON_ZOOMOUT", text="") - if context.edit_object: + if ob.mode == 'EDIT': row = layout.row(align=True) row.itemO("object.material_slot_assign", text="Assign") row.itemO("object.material_slot_select", text="Select") diff --git a/release/ui/space_image.py b/release/ui/space_image.py index 090067120b1..888b46e060e 100644 --- a/release/ui/space_image.py +++ b/release/ui/space_image.py @@ -247,7 +247,7 @@ class IMAGE_HT_header(bpy.types.Header): """ mesh = context.edit_object.data - row.item_pointerR(mesh, "active_uv_layer", mesh, "uv_layers") + row.item_pointerR(mesh, "active_uv_layer", mesh, "uv_textures") """ if ima: diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index b65d77751e2..27c75126026 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -90,7 +90,10 @@ typedef enum { eModifierTypeFlag_UsesPointCache = (1<<6), /* For physics modifiers, max one per type */ - eModifierTypeFlag_Single = (1<<7) + eModifierTypeFlag_Single = (1<<7), + + /* Some modifier can't be added manually by user */ + eModifierTypeFlag_NoUserAdd = (1<<8) } ModifierTypeFlag; typedef void (*ObjectWalkFunc)(void *userData, struct Object *ob, struct Object **obpoin); diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 4d567245ce1..37cf427b897 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -8616,7 +8616,8 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type) mti->freeData = smokeHRModifier_freeData; mti->flags = eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_UsesPointCache - | eModifierTypeFlag_Single; + | eModifierTypeFlag_Single + | eModifierTypeFlag_NoUserAdd; mti->deformVerts = smokeHRModifier_deformVerts; mti->dependsOnTime = smokeHRModifier_dependsOnTime; mti->updateDepgraph = smokeHRModifier_updateDepgraph; @@ -8647,7 +8648,7 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type) mti = INIT_TYPE(Surface); mti->type = eModifierTypeType_OnlyDeform; mti->initData = surfaceModifier_initData; - mti->flags = eModifierTypeFlag_AcceptsMesh; + mti->flags = eModifierTypeFlag_AcceptsMesh|eModifierTypeFlag_NoUserAdd; mti->dependsOnTime = surfaceModifier_dependsOnTime; mti->freeData = surfaceModifier_freeData; mti->deformVerts = surfaceModifier_deformVerts; diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 42280ad17c9..5bf59b06bc4 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -100,6 +100,8 @@ typedef struct uiLayout uiLayout; #define UI_BLOCK_KEEP_OPEN 256 #define UI_BLOCK_POPUP 512 #define UI_BLOCK_OUT_1 1024 +#define UI_BLOCK_NO_FLIP 2048 +#define UI_BLOCK_POPUP_MEMORY 4096 /* uiPopupBlockHandle->menuretval */ #define UI_RETURN_CANCEL 1 /* cancel all menus cascading */ @@ -254,8 +256,6 @@ void uiPupMenuNotice(struct bContext *C, char *str, ...); void uiPupMenuError(struct bContext *C, char *str, ...); void uiPupMenuReports(struct bContext *C, struct ReportList *reports); -void uiPupMenuSetActive(int val); - /* Popup Blocks * * Functions used to create popup blocks. These are like popup menus diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 92a3a4cf841..9bd6c2577ff 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -225,6 +225,7 @@ static void ui_text_bounds_block(uiBlock *block, float offset) uiStyle *style= U.uistyles.first; // XXX pass on as arg uiBut *bt; int i = 0, j, x1addval= offset, nextcol; + int lastcol= 0, col= 0; uiStyleFontSet(&style->widget); @@ -237,18 +238,26 @@ static void ui_text_bounds_block(uiBlock *block, float offset) if(j > i) i = j; } + + if(bt->next && bt->x1 < bt->next->x1) + lastcol++; } /* cope with multi collumns */ bt= block->buttons.first; while(bt) { - if(bt->next && bt->x1 < bt->next->x1) + if(bt->next && bt->x1 < bt->next->x1) { nextcol= 1; + col++; + } else nextcol= 0; bt->x1 = x1addval; bt->x2 = bt->x1 + i + block->bounds; + if(col == lastcol) + bt->x2= MAX2(bt->x2, offset + block->minbounds); + ui_check_but(bt); // clips text again if(nextcol) @@ -281,7 +290,7 @@ void ui_bounds_block(uiBlock *block) if(bt->x2 > block->maxx) block->maxx= bt->x2; if(bt->y2 > block->maxy) block->maxy= bt->y2; - + bt= bt->next; } @@ -291,6 +300,8 @@ void ui_bounds_block(uiBlock *block) block->maxy += block->bounds; } + block->maxx= block->minx + MAX2(block->maxx - block->minx, block->minbounds); + /* hardcoded exception... but that one is annoying with larger safety */ bt= block->buttons.first; if(bt && strncmp(bt->str, "ERROR", 5)==0) xof= 10; @@ -2286,8 +2297,12 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1, dynstr= BLI_dynstr_new(); BLI_dynstr_appendf(dynstr, "%s%%t", RNA_property_ui_name(prop)); for(i=0; iflag & UI_BLOCK_NO_FLIP) + return; for(but= block->buttons.first; but; but= but->next) { if(but->flag & UI_BUT_ALIGN) return; diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index e3518b446ba..b69e8319956 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1720,6 +1720,7 @@ static void ui_blockopen_begin(bContext *C, uiBut *but, uiHandleButtonData *data uiBlockCreateFunc func= NULL; uiBlockHandleCreateFunc handlefunc= NULL; uiMenuCreateFunc menufunc= NULL; + char *menustr= NULL; void *arg= NULL; switch(but->type) { @@ -1744,16 +1745,15 @@ static void ui_blockopen_begin(bContext *C, uiBut *but, uiHandleButtonData *data data->value= data->origvalue; but->editval= &data->value; - handlefunc= ui_block_func_MENU; - arg= but; + menustr= but->str; } break; case ICONROW: - handlefunc= ui_block_func_ICONROW; + menufunc= ui_block_func_ICONROW; arg= but; break; case ICONTEXTROW: - handlefunc= ui_block_func_ICONTEXTROW; + menufunc= ui_block_func_ICONTEXTROW; arg= but; break; case COL: @@ -1771,8 +1771,8 @@ static void ui_blockopen_begin(bContext *C, uiBut *but, uiHandleButtonData *data if(but->block->handle) data->menu->popup= but->block->handle->popup; } - else if(menufunc) { - data->menu= ui_popup_menu_create(C, data->region, but, menufunc, arg); + else if(menufunc || menustr) { + data->menu= ui_popup_menu_create(C, data->region, but, menufunc, arg, menustr); if(but->block->handle) data->menu->popup= but->block->handle->popup; } @@ -3729,10 +3729,15 @@ static void button_activate_exit(bContext *C, uiHandleButtonData *data, uiBut *b } } - /* autokey & undo push */ - if(!data->cancel) + if(!data->cancel) { + /* autokey & undo push */ ui_apply_autokey_undo(C, but); + /* popup menu memory */ + if(block->flag & UI_BLOCK_POPUP_MEMORY) + ui_popup_menu_memory(block, but); + } + /* disable tooltips until mousemove + last active flag */ for(block=data->region->uiblocks.first; block; block=block->next) { for(bt=block->buttons.first; bt; bt=bt->next) diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 9ef5d65b69f..806b40b8646 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -287,7 +287,8 @@ struct uiBlock { char *lockstr; float xofs, yofs; // offset to parent button - int bounds, dobounds, mx, my; // for doing delayed + int dobounds, mx, my; // for doing delayed + int bounds, minbounds; // for doing delayed int endblock; // uiEndBlock done? rctf safety; // pulldowns, to detect outside, can differ per case how it is created @@ -297,6 +298,7 @@ struct uiBlock { int tooltipdisabled; // to avoid tooltip after click int active; // to keep blocks while drawing and free them afterwards + int puphash; // popup menu hash for memory void *evil_C; // XXX hack for dynamic operator enums }; @@ -372,14 +374,15 @@ struct uiPopupBlockHandle { float retvec[3]; }; -uiBlock *ui_block_func_MENU(struct bContext *C, uiPopupBlockHandle *handle, void *arg_but); -uiBlock *ui_block_func_ICONROW(struct bContext *C, uiPopupBlockHandle *handle, void *arg_but); -uiBlock *ui_block_func_ICONTEXTROW(struct bContext *C, uiPopupBlockHandle *handle, void *arg_but); uiBlock *ui_block_func_COL(struct bContext *C, uiPopupBlockHandle *handle, void *arg_but); +void ui_block_func_ICONROW(struct bContext *C, uiLayout *layout, void *arg_but); +void ui_block_func_ICONTEXTROW(struct bContext *C, uiLayout *layout, void *arg_but); struct ARegion *ui_tooltip_create(struct bContext *C, struct ARegion *butregion, uiBut *but); void ui_tooltip_free(struct bContext *C, struct ARegion *ar); +uiBut *ui_popup_menu_memory(uiBlock *block, uiBut *but); + /* searchbox for string button */ ARegion *ui_searchbox_create(struct bContext *C, struct ARegion *butregion, uiBut *but); int ui_searchbox_inside(struct ARegion *ar, int x, int y); @@ -394,7 +397,8 @@ typedef uiBlock* (*uiBlockHandleCreateFunc)(struct bContext *C, struct uiPopupBl uiPopupBlockHandle *ui_popup_block_create(struct bContext *C, struct ARegion *butregion, uiBut *but, uiBlockCreateFunc create_func, uiBlockHandleCreateFunc handle_create_func, void *arg); uiPopupBlockHandle *ui_popup_menu_create(struct bContext *C, struct ARegion *butregion, uiBut *but, - uiMenuCreateFunc create_func, void *arg); + uiMenuCreateFunc create_func, void *arg, char *str); + void ui_popup_block_free(struct bContext *C, uiPopupBlockHandle *handle); void ui_set_name_menu(uiBut *but, int value); diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index fc4f7da56d2..ab27f8fb0f6 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -619,6 +619,8 @@ void uiItemsEnumO(uiLayout *layout, char *opname, char *propname) wmOperatorType *ot= WM_operatortype_find(opname, 0); PointerRNA ptr; PropertyRNA *prop; + uiBut *bt; + uiBlock *block= layout->root->block; if(!ot || !ot->srna) { ui_item_disabled(layout, opname); @@ -631,14 +633,31 @@ void uiItemsEnumO(uiLayout *layout, char *opname, char *propname) if(prop && RNA_property_type(prop) == PROP_ENUM) { EnumPropertyItem *item; int totitem, i, free; + uiLayout *split= uiLayoutSplit(layout, 0); + uiLayout *column= uiLayoutColumn(split, 0); - RNA_property_enum_items(layout->root->block->evil_C, &ptr, prop, &item, &totitem, &free); + RNA_property_enum_items(block->evil_C, &ptr, prop, &item, &totitem, &free); - for(i=0; iflag |= UI_BLOCK_NO_FLIP; + } + + uiItemL(column, (char*)item[i].name, 0); + bt= block->buttons.last; + bt->flag= UI_TEXT_LEFT; + } + else + uiItemS(column); + } + } if(free) MEM_freeN(item); @@ -924,6 +943,8 @@ void uiItemEnumR_string(uiLayout *layout, char *name, int icon, struct PointerRN void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, char *propname) { PropertyRNA *prop; + uiBlock *block= layout->root->block; + uiBut *bt; prop= RNA_struct_find_property(ptr, propname); @@ -935,14 +956,31 @@ void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, char *propname) if(RNA_property_type(prop) == PROP_ENUM) { EnumPropertyItem *item; int totitem, i, free; + uiLayout *split= uiLayoutSplit(layout, 0); + uiLayout *column= uiLayoutColumn(split, 0); - RNA_property_enum_items(layout->root->block->evil_C, ptr, prop, &item, &totitem, &free); + RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free); - for(i=0; iflag |= UI_BLOCK_NO_FLIP; + } + + uiItemL(column, (char*)item[i].name, 0); + bt= block->buttons.last; + bt->flag= UI_TEXT_LEFT; + } + else + uiItemS(column); + } + } if(free) MEM_freeN(item); diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index bf921715524..e83dca5a500 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -38,6 +38,7 @@ #include "BLI_arithb.h" #include "BLI_blenlib.h" #include "BLI_dynstr.h" +#include "BLI_ghash.h" #include "BKE_context.h" #include "BKE_icons.h" @@ -75,13 +76,14 @@ /*********************** Menu Data Parsing ********************* */ -typedef struct { +typedef struct MenuEntry { char *str; int retval; int icon; + int sepr; } MenuEntry; -typedef struct { +typedef struct MenuData { char *instr; char *title; int titleicon; @@ -111,7 +113,7 @@ static void menudata_set_title(MenuData *md, char *title, int titleicon) md->titleicon= titleicon; } -static void menudata_add_item(MenuData *md, char *str, int retval, int icon) +static void menudata_add_item(MenuData *md, char *str, int retval, int icon, int sepr) { if (md->nitems==md->itemssize) { int nsize= md->itemssize?(md->itemssize<<1):1; @@ -129,6 +131,7 @@ static void menudata_add_item(MenuData *md, char *str, int retval, int icon) md->items[md->nitems].str= str; md->items[md->nitems].retval= retval; md->items[md->nitems].icon= icon; + md->items[md->nitems].sepr= sepr; md->nitems++; } @@ -142,12 +145,13 @@ void menudata_free(MenuData *md) /** * Parse menu description strings, string is of the - * form "[sss%t|]{(sss[%xNN]|), (%l|)}", ssss%t indicates the + * form "[sss%t|]{(sss[%xNN]|), (%l|), (sss%l|)}", ssss%t indicates the * menu title, sss or sss%xNN indicates an option, * if %xNN is given then NN is the return value if * that option is selected otherwise the return value * is the index of the option (starting with 1). %l - * indicates a seperator. + * indicates a seperator, sss%l indicates a label and + * new column. * * @param str String to be parsed. * @retval new menudata structure, free with menudata_free() @@ -157,7 +161,7 @@ MenuData *decompose_menu_string(char *str) char *instr= BLI_strdup(str); MenuData *md= menudata_new(instr); char *nitem= NULL, *s= instr; - int nicon=0, nretval= 1, nitem_is_title= 0; + int nicon=0, nretval= 1, nitem_is_title= 0, nitem_is_sepr= 0; while (1) { char c= *s; @@ -174,7 +178,10 @@ MenuData *decompose_menu_string(char *str) *s= '\0'; s++; } else if (s[1]=='l') { - nitem= "%l"; + nitem_is_sepr= 1; + if(!nitem) nitem= ""; + + *s= '\0'; s++; } else if (s[1]=='i') { nicon= atoi(s+2); @@ -186,15 +193,18 @@ MenuData *decompose_menu_string(char *str) if (nitem) { *s= '\0'; - if (nitem_is_title) { + if(nitem_is_title) { menudata_set_title(md, nitem, nicon); nitem_is_title= 0; - } else { + } + else if(nitem_is_sepr) { /* prevent separator to get a value */ - if(nitem[0]=='%' && nitem[1]=='l') - menudata_add_item(md, nitem, -1, nicon); - else - menudata_add_item(md, nitem, nretval, nicon); + menudata_add_item(md, nitem, -1, nicon, 1); + nretval= md->nitems+1; + nitem_is_sepr= 0; + } + else { + menudata_add_item(md, nitem, nretval, nicon, 0); nretval= md->nitems+1; } @@ -827,6 +837,8 @@ static void ui_searchbox_region_free(ARegion *ar) ar->regiondata= NULL; } +static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but, uiBlock *block); + ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) { uiStyle *style= U.uistyles.first; // XXX pass on as arg @@ -847,7 +859,7 @@ ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) /* create searchbox data */ data= MEM_callocN(sizeof(uiSearchboxData), "uiSearchboxData"); - + /* set font, get bb */ data->fstyle= style->widget; /* copy struct */ data->fstyle.align= UI_STYLE_TEXT_CENTER; @@ -929,10 +941,14 @@ ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but) } } if(y1 < 0) { - y1 += 36; - y2 += 36; + int newy1; + UI_view2d_to_region_no_clip(&butregion->v2d, 0, but->y2 + ofsy, 0, &newy1); + newy1 += butregion->winrct.ymin; + + y2= y2-y1 + newy1; + y1= newy1; } - + /* widget rect, in region coords */ data->bbox.xmin= MENU_SHADOW_SIDE; data->bbox.xmax= x2-x1 + MENU_SHADOW_SIDE; @@ -1310,24 +1326,21 @@ void ui_popup_block_free(bContext *C, uiPopupBlockHandle *handle) /***************************** Menu Button ***************************/ -uiBlock *ui_block_func_MENU(bContext *C, uiPopupBlockHandle *handle, void *arg_but) +static void ui_block_func_MENUSTR(bContext *C, uiLayout *layout, void *arg_str) { - uiBut *but= arg_but; - uiBlock *block; + uiBlock *block= uiLayoutGetBlock(layout); + uiPopupBlockHandle *handle= block->handle; + uiLayout *split, *column; uiBut *bt; MenuData *md; - ListBase lb; - float aspect; - int width, height, boxh, columns, rows, startx, starty, x1, y1, xmax, a; - - /* create the block */ - block= uiBeginBlock(C, handle->region, "menu", UI_EMBOSSP); - block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT; + MenuEntry *entry; + char *instr= arg_str; + int columns, rows, a, b; /* compute menu data */ - md= decompose_menu_string(but->str); + md= decompose_menu_string(instr); - /* columns and row calculation */ + /* columns and row estimation */ columns= (md->nitems+20)/20; if(columns<1) columns= 1; @@ -1339,180 +1352,114 @@ uiBlock *ui_block_func_MENU(bContext *C, uiPopupBlockHandle *handle, void *arg_b rows= 1; while(rows*columnsnitems) rows++; - - /* prevent scaling up of pupmenu */ - aspect= but->block->aspect; - if(aspect < 1.0f) - aspect = 1.0f; - /* size and location */ - if(md->title) - width= 1.5*aspect*strlen(md->title)+UI_GetStringWidth(md->title); - else - width= 0; - - for(a=0; anitems; a++) { - xmax= aspect*UI_GetStringWidth(md->items[a].str); - if(md->items[a].icon) - xmax += 20*aspect; - if(xmax>width) - width= xmax; - } - - width+= 10; - if(width < (but->x2 - but->x1)) - width = (but->x2 - but->x1); - if(width<50) - width=50; - - boxh= MENU_BUTTON_HEIGHT; - - height= rows*boxh; - if(md->title) - height+= boxh; - - /* here we go! */ - startx= but->x1; - starty= but->y1; - + /* create title */ if(md->title) { - uiBut *bt; - - if (md->titleicon) { - bt= uiDefIconTextBut(block, LABEL, 0, md->titleicon, md->title, startx, (short)(starty+rows*boxh), (short)width, (short)boxh, NULL, 0.0, 0.0, 0, 0, ""); - } else { - bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+rows*boxh), (short)width, (short)boxh, NULL, 0.0, 0.0, 0, 0, ""); + if(md->titleicon) { + uiItemL(layout, md->title, md->titleicon); + } + else { + uiItemL(layout, md->title, 0); + bt= block->buttons.last; bt->flag= UI_TEXT_LEFT; } } - for(a=0; anitems; a++) { - - x1= startx + width*((int)(md->nitems-a-1)/rows); - y1= starty - boxh*(rows - ((md->nitems - a - 1)%rows)) + (rows*boxh); + /* inconsistent, but menus with labels do not look good flipped */ + for(a=0, b=0; anitems; a++, b++) { + entry= &md->items[a]; - if (strcmp(md->items[md->nitems-a-1].str, "%l")==0) { - bt= uiDefBut(block, SEPR, B_NOP, "", x1, y1,(short)(width-(rows>1)), (short)(boxh-1), NULL, 0.0, 0.0, 0, 0, ""); + if(entry->sepr && entry->str[0]) + block->flag |= UI_BLOCK_NO_FLIP; + } + + /* create items */ + split= uiLayoutSplit(layout, 0); + + for(a=0, b=0; anitems; a++, b++) { + if(block->flag & UI_BLOCK_NO_FLIP) + entry= &md->items[a]; + else + entry= &md->items[md->nitems-a-1]; + + /* new column on N rows or on separation label */ + if((b % rows == 0) || (entry->sepr && entry->str[0])) { + column= uiLayoutColumn(split, 0); + b= 0; } - else if(md->items[md->nitems-a-1].icon) { - bt= uiDefIconTextButF(block, BUTM|FLO, B_NOP, md->items[md->nitems-a-1].icon ,md->items[md->nitems-a-1].str, x1, y1,(short)(width-(rows>1)), (short)(boxh-1), &handle->retvalue, (float) md->items[md->nitems-a-1].retval, 0.0, 0, 0, ""); + + if(entry->sepr) { + uiItemL(column, entry->str, entry->icon); + bt= block->buttons.last; + bt->flag= UI_TEXT_LEFT; + } + else if(entry->icon) { + uiDefIconTextButF(block, BUTM|FLO, B_NOP, entry->icon, entry->str, 0, 0, + UI_UNIT_X*5, UI_UNIT_Y, &handle->retvalue, (float) entry->retval, 0.0, 0, 0, ""); } else { - bt= uiDefButF(block, BUTM|FLO, B_NOP, md->items[md->nitems-a-1].str, x1, y1,(short)(width-(rows>1)), (short)(boxh-1), &handle->retvalue, (float) md->items[md->nitems-a-1].retval, 0.0, 0, 0, ""); + uiDefButF(block, BUTM|FLO, B_NOP, entry->str, 0, 0, + UI_UNIT_X*5, UI_UNIT_X, &handle->retvalue, (float) entry->retval, 0.0, 0, 0, ""); } } menudata_free(md); - - /* the code up here has flipped locations, because of change of preferred order */ - /* thats why we have to switch list order too, to make arrowkeys work */ - - lb.first= lb.last= NULL; - bt= block->buttons.first; - while(bt) { - uiBut *next= bt->next; - BLI_remlink(&block->buttons, bt); - BLI_addhead(&lb, bt); - bt= next; - } - block->buttons= lb; - - block->direction= UI_TOP; - uiEndBlock(C, block); - - return block; } -uiBlock *ui_block_func_ICONROW(bContext *C, uiPopupBlockHandle *handle, void *arg_but) +void ui_block_func_ICONROW(bContext *C, uiLayout *layout, void *arg_but) { + uiBlock *block= uiLayoutGetBlock(layout); + uiPopupBlockHandle *handle= block->handle; uiBut *but= arg_but; - uiBlock *block; int a; - block= uiBeginBlock(C, handle->region, "menu", UI_EMBOSSP); - block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT; - - for(a=(int)but->hardmin; a<=(int)but->hardmax; a++) { - uiDefIconButF(block, BUTM|FLO, B_NOP, but->icon+(a-but->hardmin), 0, (short)(18*a), (short)(but->x2-but->x1-4), 18, &handle->retvalue, (float)a, 0.0, 0, 0, ""); - } - - block->direction= UI_TOP; - - uiEndBlock(C, block); - - return block; + for(a=(int)but->hardmin; a<=(int)but->hardmax; a++) + uiDefIconButF(block, BUTM|FLO, B_NOP, but->icon+(a-but->hardmin), 0, 0, UI_UNIT_X*5, UI_UNIT_Y, + &handle->retvalue, (float)a, 0.0, 0, 0, ""); } -uiBlock *ui_block_func_ICONTEXTROW(bContext *C, uiPopupBlockHandle *handle, void *arg_but) +void ui_block_func_ICONTEXTROW(bContext *C, uiLayout *layout, void *arg_but) { - uiBut *but= arg_but; - uiBlock *block; + uiBlock *block= uiLayoutGetBlock(layout); + uiPopupBlockHandle *handle= block->handle; + uiBut *but= arg_but, *bt; MenuData *md; - int width, xmax, ypos, a; - - block= uiBeginBlock(C, handle->region, "menu", UI_EMBOSSP); - block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT; + MenuEntry *entry; + int a; md= decompose_menu_string(but->str); - /* size and location */ - /* expand menu width to fit labels */ - if(md->title) - width= 2*strlen(md->title)+UI_GetStringWidth(md->title); - else - width= 0; - - for(a=0; anitems; a++) { - xmax= UI_GetStringWidth(md->items[a].str); - if(xmax>width) width= xmax; + /* title */ + if(md->title) { + bt= uiDefBut(block, LABEL, 0, md->title, 0, 0, UI_UNIT_X*5, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); + bt->flag= UI_TEXT_LEFT; } - width+= 30; - if (width<50) width=50; - - ypos = 1; - /* loop through the menu options and draw them out with icons & text labels */ for(a=0; anitems; a++) { + entry= &md->items[md->nitems-a-1]; - /* add a space if there's a separator (%l) */ - if (strcmp(md->items[a].str, "%l")==0) { - ypos +=3; - } - else { - uiDefIconTextButF(block, BUTM|FLO, B_NOP, (short)((but->icon)+(md->items[a].retval-but->hardmin)), md->items[a].str, 0, ypos,(short)width, 19, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, ""); - ypos += 20; - } + if(entry->sepr) + uiItemS(layout); + else + uiDefIconTextButF(block, BUTM|FLO, B_NOP, (short)((but->icon)+(entry->retval-but->hardmin)), entry->str, + 0, 0, UI_UNIT_X*5, UI_UNIT_Y, &handle->retvalue, (float) entry->retval, 0.0, 0, 0, ""); } - - if(md->title) { - uiBut *bt; - bt= uiDefBut(block, LABEL, 0, md->title, 0, ypos, (short)width, 19, NULL, 0.0, 0.0, 0, 0, ""); - bt->flag= UI_TEXT_LEFT; - } - menudata_free(md); - - block->direction= UI_TOP; - - uiBoundsBlock(block, 3); - uiEndBlock(C, block); - - return block; } +#if 0 static void ui_warp_pointer(short x, short y) { /* XXX 2.50 which function to use for this? */ -#if 0 /* OSX has very poor mousewarp support, it sends events; this causes a menu being pressed immediately ... */ #ifndef __APPLE__ warp_pointer(x, y); #endif -#endif } +#endif /********************* Color Button ****************/ @@ -2158,406 +2105,115 @@ void uiBlockColorbandButtons(uiBlock *block, ColorBand *coba, rctf *butr, int ev } -/* ******************** PUPmenu ****************** */ +/************************ Popup Menu Memory ****************************/ -static int pupmenu_set= 0; - -void uiPupMenuSetActive(int val) +static int ui_popup_menu_hash(char *str) { - pupmenu_set= val; + return BLI_ghashutil_strhash(str); } -/* value== -1 read, otherwise set */ -static int pupmenu_memory(char *str, int value) +/* but == NULL read, otherwise set */ +uiBut *ui_popup_menu_memory(uiBlock *block, uiBut *but) { static char mem[256], first=1; - int val=0, nr=0; + int hash= block->puphash; if(first) { - memset(mem, 0, 256); + /* init */ + memset(mem, -1, sizeof(mem)); first= 0; } - while(str[nr]) { - val+= str[nr]; - nr++; - } - if(value >= 0) mem[ val & 255 ]= value; - else return mem[ val & 255 ]; - - return 0; + if(but) { + /* set */ + mem[hash & 255 ]= BLI_findindex(&block->buttons, but); + return NULL; + } + else { + /* get */ + return BLI_findlink(&block->buttons, mem[hash & 255]); + } } -#define PUP_LABELH 6 - -typedef struct uiPupMenuInfo { - char *instr; - int mx, my; - int startx, starty; - int maxrow; -} uiPupMenuInfo; - -uiBlock *ui_block_func_PUPMENU(bContext *C, uiPopupBlockHandle *handle, void *arg_info) -{ - uiBlock *block; - uiPupMenuInfo *info; - int columns, rows, mousemove[2]= {0, 0}, mousewarp= 0; - int width, height, xmax, ymax, maxrow; - int a, startx, starty, endx, endy, x1, y1; - int lastselected; - MenuData *md; - - info= arg_info; - maxrow= info->maxrow; - height= 0; - - /* block stuff first, need to know the font */ - block= uiBeginBlock(C, handle->region, "menu", UI_EMBOSSP); - uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1|UI_BLOCK_NUMSELECT); - block->direction= UI_DOWN; - - md= decompose_menu_string(info->instr); - - rows= md->nitems; - if(rows<1) - rows= 1; - - columns= 1; - - /* size and location, title slightly bigger for bold */ - if(md->title) { - width= 2*strlen(md->title)+UI_GetStringWidth(md->title); - width /= columns; - } - else width= 0; - - for(a=0; anitems; a++) { - xmax= UI_GetStringWidth(md->items[a].str); - if(xmax>width) width= xmax; - - if(strcmp(md->items[a].str, "%l")==0) height+= PUP_LABELH; - else height+= MENU_BUTTON_HEIGHT; - } - - width+= 10; - if (width<50) width=50; - - wm_window_get_size(CTX_wm_window(C), &xmax, &ymax); - - /* set first item */ - lastselected= 0; - if(pupmenu_set) { - lastselected= pupmenu_set-1; - pupmenu_set= 0; - } - else if(md->nitems>1) { - lastselected= pupmenu_memory(info->instr, -1); - } - - startx= info->mx-(0.8*(width)); - starty= info->my-height+MENU_BUTTON_HEIGHT/2; - if(lastselected>=0 && lastselectednitems) { - for(a=0; anitems; a++) { - if(a==lastselected) break; - if( strcmp(md->items[a].str, "%l")==0) starty+= PUP_LABELH; - else starty+=MENU_BUTTON_HEIGHT; - } - - //starty= info->my-height+MENU_BUTTON_HEIGHT/2+lastselected*MENU_BUTTON_HEIGHT; - } - - if(startx<10) { - startx= 10; - } - if(starty<10) { - mousemove[1]= 10-starty; - starty= 10; - } - - endx= startx+width*columns; - endy= starty+height; - - if(endx>xmax) { - endx= xmax-10; - startx= endx-width*columns; - } - if(endy>ymax-20) { - mousemove[1]= ymax-endy-20; - endy= ymax-20; - starty= endy-height; - } - - if(mousemove[0] || mousemove[1]) { - ui_warp_pointer(info->mx+mousemove[0], info->my+mousemove[1]); - mousemove[0]= info->mx; - mousemove[1]= info->my; - mousewarp= 1; - } - - /* here we go! */ - if(md->title) { - uiBut *bt; - char titlestr[256]; - - if(md->titleicon) { - width+= 20; - sprintf(titlestr, " %s", md->title); - uiDefIconTextBut(block, LABEL, 0, md->titleicon, titlestr, startx, (short)(starty+height), width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); - } - else { - bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+height), columns*width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); - bt->flag= UI_TEXT_LEFT; - } - - //uiDefBut(block, SEPR, 0, "", startx, (short)(starty+height)-MENU_SEPR_HEIGHT, width, MENU_SEPR_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); - } - - x1= startx + width*((int)a/rows); - y1= starty + height - MENU_BUTTON_HEIGHT; // - MENU_SEPR_HEIGHT; - - for(a=0; anitems; a++) { - char *name= md->items[a].str; - int icon = md->items[a].icon; - - if(strcmp(name, "%l")==0) { - uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, PUP_LABELH, NULL, 0, 0.0, 0, 0, ""); - y1 -= PUP_LABELH; - } - else if (icon) { - uiDefIconButF(block, BUTM, B_NOP, icon, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, ""); - y1 -= MENU_BUTTON_HEIGHT; - } - else { - uiDefButF(block, BUTM, B_NOP, name, x1, y1, width, MENU_BUTTON_HEIGHT-1, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, ""); - y1 -= MENU_BUTTON_HEIGHT; - } - } - - uiBoundsBlock(block, 1); - uiEndBlock(C, block); - - menudata_free(md); - - /* XXX 2.5 need to store last selected */ -#if 0 - /* calculate last selected */ - if(event & ui_return_ok) { - lastselected= 0; - for(a=0; anitems; a++) { - if(val==md->items[a].retval) lastselected= a; - } - - pupmenu_memory(info->instr, lastselected); - } -#endif - - /* XXX 2.5 need to warp back */ -#if 0 - if(mousemove[1] && (event & ui_return_out)==0) - ui_warp_pointer(mousemove[0], mousemove[1]); - return val; -#endif - - return block; -} - -uiBlock *ui_block_func_PUPMENUCOL(bContext *C, uiPopupBlockHandle *handle, void *arg_info) -{ - uiBlock *block; - uiPupMenuInfo *info; - int columns, rows, mousemove[2]= {0, 0}, mousewarp; - int width, height, xmax, ymax, maxrow; - int a, startx, starty, endx, endy, x1, y1; - float fvalue; - MenuData *md; - - info= arg_info; - maxrow= info->maxrow; - height= 0; - - /* block stuff first, need to know the font */ - block= uiBeginBlock(C, handle->region, "menu", UI_EMBOSSP); - uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1|UI_BLOCK_NUMSELECT); - block->direction= UI_DOWN; - - md= decompose_menu_string(info->instr); - - /* columns and row calculation */ - columns= (md->nitems+maxrow)/maxrow; - if (columns<1) columns= 1; - - if(columns > 8) { - maxrow += 5; - columns= (md->nitems+maxrow)/maxrow; - } - - rows= (int) md->nitems/columns; - if (rows<1) rows= 1; - - while (rows*columns<(md->nitems+columns) ) rows++; - - /* size and location, title slightly bigger for bold */ - if(md->title) { - width= 2*strlen(md->title)+UI_GetStringWidth(md->title); - width /= columns; - } - else width= 0; - - for(a=0; anitems; a++) { - xmax= UI_GetStringWidth(md->items[a].str); - if(xmax>width) width= xmax; - } - - width+= 10; - if (width<50) width=50; - - height= rows*MENU_BUTTON_HEIGHT; - if (md->title) height+= MENU_BUTTON_HEIGHT; - - wm_window_get_size(CTX_wm_window(C), &xmax, &ymax); - - /* find active item */ - fvalue= handle->retvalue; - for(a=0; anitems; a++) { - if( md->items[a].retval== (int)fvalue ) break; - } - - /* no active item? */ - if(a==md->nitems) { - if(md->title) a= -1; - else a= 0; - } - - if(a>0) - startx = info->mx-width/2 - ((int)(a)/rows)*width; - else - startx= info->mx-width/2; - starty = info->my-height + MENU_BUTTON_HEIGHT/2 + ((a)%rows)*MENU_BUTTON_HEIGHT; - - if (md->title) starty+= MENU_BUTTON_HEIGHT; - - if(startx<10) { - mousemove[0]= 10-startx; - startx= 10; - } - if(starty<10) { - mousemove[1]= 10-starty; - starty= 10; - } - - endx= startx+width*columns; - endy= starty+height; - - if(endx>xmax) { - mousemove[0]= xmax-endx-10; - endx= xmax-10; - startx= endx-width*columns; - } - if(endy>ymax) { - mousemove[1]= ymax-endy-10; - endy= ymax-10; - starty= endy-height; - } - - if(mousemove[0] || mousemove[1]) { - ui_warp_pointer(info->mx+mousemove[0], info->my+mousemove[1]); - mousemove[0]= info->mx; - mousemove[1]= info->my; - mousewarp= 1; - } - - /* here we go! */ - if(md->title) { - uiBut *bt; - - if(md->titleicon) { - } - else { - bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+rows*MENU_BUTTON_HEIGHT), columns*width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); - bt->flag= UI_TEXT_LEFT; - } - } - - for(a=0; anitems; a++) { - char *name= md->items[a].str; - int icon = md->items[a].icon; - - x1= startx + width*((int)a/rows); - y1= starty - MENU_BUTTON_HEIGHT*(a%rows) + (rows-1)*MENU_BUTTON_HEIGHT; - - if(strcmp(name, "%l")==0) { - uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, PUP_LABELH, NULL, 0, 0.0, 0, 0, ""); - y1 -= PUP_LABELH; - } - else if (icon) { - uiDefIconButF(block, BUTM, B_NOP, icon, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, ""); - y1 -= MENU_BUTTON_HEIGHT; - } - else { - uiDefButF(block, BUTM, B_NOP, name, x1, y1, width, MENU_BUTTON_HEIGHT-1, &handle->retvalue, (float) md->items[a].retval, 0.0, 0, 0, ""); - y1 -= MENU_BUTTON_HEIGHT; - } - } - - uiBoundsBlock(block, 1); - uiEndBlock(C, block); - - menudata_free(md); - - /* XXX 2.5 need to warp back */ -#if 0 - if((event & UI_RETURN_OUT)==0) - ui_warp_pointer(mousemove[0], mousemove[1]); -#endif - - return block; -} - -/************************** Menu Definitions ***************************/ - -/* prototype */ -static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiPopupBlockHandle *handle, void *arg_info); +/******************** Popup Menu with callback or string **********************/ struct uiPopupMenu { uiBlock *block; uiLayout *layout; + uiBut *but; + + int mx, my, popup, slideout; + int startx, starty, maxrow; + + uiMenuCreateFunc menu_func; + void *menu_arg; }; -typedef struct uiMenuInfo { - uiPopupMenu *pup; - int mx, my, popup, slideout; - int startx, starty; -} uiMenuInfo; - -/************************ Menu Definitions to uiBlocks ***********************/ - -static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiPopupBlockHandle *handle, void *arg_info) +static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, void *arg_pup) { uiBlock *block; - uiMenuInfo *info= arg_info; - uiPopupMenu *pup; + uiBut *bt; ScrArea *sa; ARegion *ar; - - pup= info->pup; + uiPopupMenu *pup= arg_pup; + int offset, direction, minwidth, flip; + + if(pup->menu_func) { + pup->block->handle= handle; + pup->menu_func(C, pup->layout, pup->menu_arg); + pup->block->handle= NULL; + } + + if(pup->but) { + /* minimum width to enforece */ + minwidth= pup->but->x2 - pup->but->x1; + + if(pup->but->type == PULLDOWN || pup->but->menu_create_func) { + direction= UI_DOWN; + flip= 1; + } + else { + direction= UI_TOP; + flip= 0; + } + } + else { + minwidth= 50; + direction= UI_DOWN; + flip= 1; + } + block= pup->block; - /* block stuff first, need to know the font */ - uiBlockSetRegion(block, handle->region); - block->direction= UI_DOWN; + /* in some cases we create the block before the region, + so we set it delayed here if necessary */ + if(BLI_findindex(&handle->region->uiblocks, block) == -1) + uiBlockSetRegion(block, handle->region); + + block->direction= direction; uiBlockLayoutResolve(C, block, NULL, NULL); - if(info->popup) { + if(pup->popup) { uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT|UI_BLOCK_RET_1); - uiBlockSetDirection(block, UI_DOWN); + uiBlockSetDirection(block, direction); - /* here we set an offset for the mouse position */ - uiMenuPopupBoundsBlock(block, 1, 0, 1.5*MENU_BUTTON_HEIGHT); + /* offset the mouse position, possibly based on earlier selection */ + offset= 1.5*MENU_BUTTON_HEIGHT; + + if(block->flag & UI_BLOCK_POPUP_MEMORY) { + bt= ui_popup_menu_memory(block, NULL); + + if(bt) + offset= -bt->y1 - 0.5f*MENU_BUTTON_HEIGHT; + } + + block->minbounds= minwidth; + uiMenuPopupBoundsBlock(block, 1, 20, offset); } else { /* for a header menu we set the direction automatic */ - if(!info->slideout) { + if(!pup->slideout && flip) { sa= CTX_wm_area(C); ar= CTX_wm_region(C); @@ -2569,59 +2225,77 @@ static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiPopupBlockHandle *handle, } } - uiTextBoundsBlock(block, 50); + block->minbounds= minwidth; + uiTextBoundsBlock(block, 40); } /* if menu slides out of other menu, override direction */ - if(info->slideout) + if(pup->slideout) uiBlockSetDirection(block, UI_RIGHT); uiEndBlock(C, block); - - return block; + + return pup->block; } -uiPopupBlockHandle *ui_popup_menu_create(bContext *C, ARegion *butregion, uiBut *but, uiMenuCreateFunc menu_func, void *arg) +uiPopupBlockHandle *ui_popup_menu_create(bContext *C, ARegion *butregion, uiBut *but, uiMenuCreateFunc menu_func, void *arg, char *str) { + wmWindow *window= CTX_wm_window(C); uiStyle *style= U.uistyles.first; uiPopupBlockHandle *handle; uiPopupMenu *pup; - uiMenuInfo info; pup= MEM_callocN(sizeof(uiPopupMenu), "menu dummy"); - pup->block= uiBeginBlock(C, NULL, "ui_popup_menu_create", UI_EMBOSSP); + pup->block= uiBeginBlock(C, NULL, "ui_button_menu_create", UI_EMBOSSP); pup->layout= uiBlockLayout(pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0, style); + pup->slideout= (but && (but->block->flag & UI_BLOCK_LOOP)); + pup->but= but; uiLayoutSetOperatorContext(pup->layout, WM_OP_INVOKE_REGION_WIN); - /* create in advance so we can let buttons point to retval already */ - pup->block->handle= MEM_callocN(sizeof(uiPopupBlockHandle), "uiPopupBlockHandle"); + if(!but) { + /* no button to start from, means we are a popup */ + pup->mx= window->eventstate->x; + pup->my= window->eventstate->y; + pup->popup= 1; + } - menu_func(C, pup->layout, arg); + if(str) { + /* menu is created from a string */ + pup->menu_func= ui_block_func_MENUSTR; + pup->menu_arg= str; + } + else { + /* menu is created from a callback */ + pup->menu_func= menu_func; + pup->menu_arg= arg; + } - memset(&info, 0, sizeof(info)); - info.pup= pup; - info.slideout= (but && (but->block->flag & UI_BLOCK_LOOP)); - - handle= ui_popup_block_create(C, butregion, but, NULL, ui_block_func_MENU_ITEM, &info); + handle= ui_popup_block_create(C, butregion, but, NULL, ui_block_func_POPUP, pup); + + if(!but) { + handle->popup= 1; + + UI_add_popup_handlers(C, &window->handlers, handle); + WM_event_add_mousemove(C); + } MEM_freeN(pup); return handle; } -/*************************** Menu Creating API **************************/ - - -/*************************** Popup Menu API **************************/ +/******************** Popup Menu API with begin and end ***********************/ /* only return handler, and set optional title */ uiPopupMenu *uiPupMenuBegin(bContext *C, const char *title, int icon) { uiStyle *style= U.uistyles.first; - uiPopupMenu *pup= MEM_callocN(sizeof(uiPopupMenu), "menu start"); + uiPopupMenu *pup= MEM_callocN(sizeof(uiPopupMenu), "popup menu"); uiBut *but; pup->block= uiBeginBlock(C, NULL, "uiPupMenuBegin", UI_EMBOSSP); + pup->block->flag |= UI_BLOCK_POPUP_MEMORY; + pup->block->puphash= ui_popup_menu_hash((char*)title); pup->layout= uiBlockLayout(pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0, style); uiLayoutSetOperatorContext(pup->layout, WM_OP_EXEC_REGION_WIN); @@ -2640,8 +2314,6 @@ uiPopupMenu *uiPupMenuBegin(bContext *C, const char *title, int icon) but= uiDefBut(pup->block, LABEL, 0, (char*)title, 0, 0, 200, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); but->flag= UI_TEXT_LEFT; } - - //uiDefBut(block, SEPR, 0, "", startx, (short)(starty+height)-MENU_SEPR_HEIGHT, width, MENU_SEPR_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); } return pup; @@ -2651,16 +2323,13 @@ uiPopupMenu *uiPupMenuBegin(bContext *C, const char *title, int icon) void uiPupMenuEnd(bContext *C, uiPopupMenu *pup) { wmWindow *window= CTX_wm_window(C); - uiMenuInfo info; uiPopupBlockHandle *menu; - memset(&info, 0, sizeof(info)); - info.popup= 1; - info.mx= window->eventstate->x; - info.my= window->eventstate->y; - info.pup= pup; + pup->popup= 1; + pup->mx= window->eventstate->x; + pup->my= window->eventstate->y; - menu= ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_MENU_ITEM, &info); + menu= ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_POPUP, pup); menu->popup= 1; UI_add_popup_handlers(C, &window->handlers, menu); @@ -2674,32 +2343,7 @@ uiLayout *uiPupMenuLayout(uiPopupMenu *pup) return pup->layout; } -/* ************** standard pupmenus *************** */ - -/* this one can called with operatortype name and operators */ -static uiPopupBlockHandle *ui_pup_menu(bContext *C, int maxrow, uiMenuHandleFunc func, void *arg, char *str, ...) -{ - wmWindow *window= CTX_wm_window(C); - uiPupMenuInfo info; - uiPopupBlockHandle *menu; - - memset(&info, 0, sizeof(info)); - info.mx= window->eventstate->x; - info.my= window->eventstate->y; - info.maxrow= maxrow; - info.instr= str; - - menu= ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_PUPMENU, &info); - menu->popup= 1; - - UI_add_popup_handlers(C, &window->handlers, menu); - WM_event_add_mousemove(C); - - menu->popup_func= func; - menu->popup_arg= arg; - - return menu; -} +/*************************** Standard Popup Menus ****************************/ static void operator_name_cb(bContext *C, void *arg, int retval) { @@ -2709,17 +2353,6 @@ static void operator_name_cb(bContext *C, void *arg, int retval) WM_operator_name_call(C, opname, WM_OP_EXEC_DEFAULT, NULL); } -static void vconfirm_opname(bContext *C, char *opname, char *title, char *itemfmt, va_list ap) -{ - char *s, buf[512]; - - s= buf; - if (title) s+= sprintf(s, "%s%%t|", title); - vsprintf(s, itemfmt, ap); - - ui_pup_menu(C, 0, operator_name_cb, opname, buf); -} - static void operator_cb(bContext *C, void *arg, int retval) { wmOperator *op= arg; @@ -2735,6 +2368,21 @@ static void confirm_cancel_operator(void *opv) WM_operator_free(opv); } +static void vconfirm_opname(bContext *C, char *opname, char *title, char *itemfmt, va_list ap) +{ + uiPopupBlockHandle *handle; + char *s, buf[512]; + + s= buf; + if (title) s+= sprintf(s, "%s%%t|", title); + vsprintf(s, itemfmt, ap); + + handle= ui_popup_menu_create(C, NULL, NULL, NULL, NULL, buf); + + handle->popup_func= operator_name_cb; + handle->popup_arg= opname; +} + static void confirm_operator(bContext *C, wmOperator *op, char *title, char *item) { uiPopupBlockHandle *handle; @@ -2743,11 +2391,13 @@ static void confirm_operator(bContext *C, wmOperator *op, char *title, char *ite s= buf; if (title) s+= sprintf(s, "%s%%t|%s", title, item); - handle= ui_pup_menu(C, 0, operator_cb, op, buf); + handle= ui_popup_menu_create(C, NULL, NULL, NULL, NULL, buf); + + handle->popup_func= operator_cb; + handle->popup_arg= op; handle->cancel_func= confirm_cancel_operator; } - void uiPupMenuOkee(bContext *C, char *opname, char *str, ...) { va_list ap; @@ -2760,7 +2410,6 @@ void uiPupMenuOkee(bContext *C, char *opname, char *str, ...) va_end(ap); } - void uiPupMenuSaveOver(bContext *C, wmOperator *op, char *filename) { size_t len= strlen(filename); @@ -2776,7 +2425,7 @@ void uiPupMenuSaveOver(bContext *C, wmOperator *op, char *filename) if(BLI_exists(filename)==0) operator_cb(C, op, 1); else - confirm_operator(C, op, "Save over", filename); + confirm_operator(C, op, "Save Over", filename); } void uiPupMenuNotice(bContext *C, char *str, ...) @@ -2826,7 +2475,7 @@ void uiPupMenuReports(bContext *C, ReportList *reports) } str= BLI_dynstr_get_cstring(ds); - ui_pup_menu(C, 0, NULL, NULL, str); + ui_popup_menu_create(C, NULL, NULL, NULL, NULL, str); MEM_freeN(str); BLI_dynstr_free(ds); @@ -2870,3 +2519,4 @@ void uiPupBlockOperator(bContext *C, uiBlockCreateFunc func, wmOperator *op, int UI_add_popup_handlers(C, &window->handlers, handle); WM_event_add_mousemove(C); } + diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 0557512cc2a..e7c99f10a66 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -237,11 +237,11 @@ static void template_ID(bContext *C, uiBlock *block, TemplateID *template, Struc int w= idptr.data?UI_UNIT_X:UI_UNIT_X*6; if(newop) { - but= uiDefIconTextButO(block, BUT, newop, WM_OP_INVOKE_REGION_WIN, ICON_ZOOMIN, "Add New", 0, 0, w, UI_UNIT_Y, NULL); + but= uiDefIconTextButO(block, BUT, newop, WM_OP_INVOKE_REGION_WIN, ICON_ZOOMIN, (idptr.data)? "": "Add New", 0, 0, w, UI_UNIT_Y, NULL); uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ADD_NEW)); } else { - but= uiDefIconTextBut(block, BUT, 0, ICON_ZOOMIN, "Add New", 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL); + but= uiDefIconTextBut(block, BUT, 0, ICON_ZOOMIN, (idptr.data)? "": "Add New", 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL); uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ADD_NEW)); } } diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 39fd6433548..2fb9835f833 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -1150,7 +1150,7 @@ void ED_object_apply_obmat(Object *ob) } -int hook_getIndexArray(Object *obedit, int *tot, int **indexar, char *name, float *cent_r) +int object_hook_index_array(Object *obedit, int *tot, int **indexar, char *name, float *cent_r) { *indexar= NULL; *tot= 0; @@ -1232,9 +1232,8 @@ static void select_editcurve_hook(Object *obedit, HookModifierData *hmd) } } -void obedit_hook_select(Object *ob, HookModifierData *hmd) +void object_hook_select(Object *ob, HookModifierData *hmd) { - if(ob->type==OB_MESH) select_editmesh_hook(ob, hmd); else if(ob->type==OB_LATTICE) select_editlattice_hook(ob, hmd); else if(ob->type==OB_CURVE) select_editcurve_hook(ob, hmd); @@ -1318,7 +1317,7 @@ void add_hook(Scene *scene, View3D *v3d, int mode) int tot, ok, *indexar; char name[32]; - ok = hook_getIndexArray(obedit, &tot, &indexar, name, cent); + ok = object_hook_index_array(obedit, &tot, &indexar, name, cent); if(ok==0) { error("Requires selected vertices or active Vertex Group"); @@ -1381,7 +1380,7 @@ void add_hook(Scene *scene, View3D *v3d, int mode) modifier_free(md); } else if(mode==5) { /* select */ - obedit_hook_select(obedit, hmd); + object_hook_select(obedit, hmd); } else if(mode==6) { /* clear offset */ where_is_object(scene, ob); /* ob is hook->parent */ diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index e47087a3c27..2f164102be2 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -34,6 +34,7 @@ struct Lattice; struct Curve; struct Object; struct Mesh; +struct HookModifierData; /* internal exports only */ @@ -80,6 +81,9 @@ void OBJECT_OT_armature_add(struct wmOperatorType *ot); /* only used as menu */ void OBJECT_OT_primitive_add(struct wmOperatorType *ot); +int object_hook_index_array(Object *obedit, int *tot, int **indexar, char *name, float *cent_r); +void object_hook_select(Object *obedit, struct HookModifierData *hmd); + /* editlattice.c */ void free_editLatt(Object *ob); void make_editLatt(Object *obedit); @@ -104,7 +108,12 @@ void OBJECT_OT_modifier_apply(struct wmOperatorType *ot); void OBJECT_OT_modifier_convert(struct wmOperatorType *ot); void OBJECT_OT_modifier_copy(struct wmOperatorType *ot); void OBJECT_OT_multires_subdivide(struct wmOperatorType *ot); -void OBJECT_OT_modifier_mdef_bind(struct wmOperatorType *ot); +void OBJECT_OT_meshdeform_bind(struct wmOperatorType *ot); +void OBJECT_OT_hook_reset(struct wmOperatorType *ot); +void OBJECT_OT_hook_recenter(struct wmOperatorType *ot); +void OBJECT_OT_hook_select(struct wmOperatorType *ot); +void OBJECT_OT_hook_assign(struct wmOperatorType *ot); +void OBJECT_OT_explode_refresh(struct wmOperatorType *ot); /* editconstraint.c */ void OBJECT_OT_constraint_add(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 16900d6d894..32a1297aaf4 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -39,6 +39,7 @@ #include "DNA_object_force.h" #include "DNA_scene_types.h" +#include "BLI_arithb.h" #include "BLI_listbase.h" #include "BKE_curve.h" @@ -410,6 +411,11 @@ int ED_object_modifier_copy(ReportList *reports, Object *ob, ModifierData *md) /***************************** OPERATORS ****************************/ +static int modifier_poll(bContext *C) +{ + return (CTX_data_pointer_get_type(C, "modifier", &RNA_Modifier).data != NULL); +} + /************************ add modifier operator *********************/ static int modifier_add_exec(bContext *C, wmOperator *op) @@ -426,8 +432,46 @@ static int modifier_add_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +static EnumPropertyItem *modifier_add_itemf(bContext *C, PointerRNA *ptr, int *free) +{ + EnumPropertyItem *item= NULL, *md_item; + ModifierTypeInfo *mti; + Object *ob; + int totitem= 0, a; + + if(!C) /* needed for docs */ + return modifier_type_items; + + ob= CTX_data_active_object(C); + + for(a=0; modifier_type_items[a].identifier; a++) { + md_item= &modifier_type_items[a]; + + if(md_item->identifier[0]) { + mti= modifierType_getInfo(md_item->value); + + if(mti->flags & eModifierTypeFlag_NoUserAdd) + continue; + + if(!((mti->flags & eModifierTypeFlag_AcceptsCVs) || + (ob->type==OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh)))) + continue; + } + + RNA_enum_item_add(&item, &totitem, md_item); + } + + RNA_enum_item_end(&item, &totitem); + + *free= 1; + + return item; +} + void OBJECT_OT_modifier_add(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name= "Add Modifier"; ot->description = "Add a modifier to the active object."; @@ -436,14 +480,14 @@ void OBJECT_OT_modifier_add(wmOperatorType *ot) /* api callbacks */ ot->invoke= WM_menu_invoke; ot->exec= modifier_add_exec; - ot->poll= ED_operator_object_active; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - /* XXX only some types should be here */ - RNA_def_enum(ot->srna, "type", modifier_type_items, 0, "Type", ""); + /* properties */ + prop= RNA_def_enum(ot->srna, "type", modifier_type_items, eModifierType_Subsurf, "Type", ""); + RNA_def_enum_funcs(prop, modifier_add_itemf); } /************************ remove modifier operator *********************/ @@ -455,7 +499,7 @@ static int modifier_remove_exec(bContext *C, wmOperator *op) Object *ob= ptr.id.data; ModifierData *md= ptr.data; - if(!ob || !md || !ED_object_modifier_remove(op->reports, scene, ob, md)) + if(!ED_object_modifier_remove(op->reports, scene, ob, md)) return OPERATOR_CANCELLED; WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); @@ -471,6 +515,7 @@ void OBJECT_OT_modifier_remove(wmOperatorType *ot) ot->poll= ED_operator_object_active; ot->exec= modifier_remove_exec; + ot->poll= modifier_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -485,7 +530,7 @@ static int modifier_move_up_exec(bContext *C, wmOperator *op) Object *ob= ptr.id.data; ModifierData *md= ptr.data; - if(!ob || !md || !ED_object_modifier_move_up(op->reports, ob, md)) + if(!ED_object_modifier_move_up(op->reports, ob, md)) return OPERATOR_CANCELLED; DAG_object_flush_update(scene, ob, OB_RECALC_DATA); @@ -502,6 +547,7 @@ void OBJECT_OT_modifier_move_up(wmOperatorType *ot) ot->poll= ED_operator_object_active; ot->exec= modifier_move_up_exec; + ot->poll= modifier_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -533,6 +579,7 @@ void OBJECT_OT_modifier_move_down(wmOperatorType *ot) ot->poll= ED_operator_object_active; ot->exec= modifier_move_down_exec; + ot->poll= modifier_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -564,6 +611,7 @@ void OBJECT_OT_modifier_apply(wmOperatorType *ot) ot->poll= ED_operator_object_active; ot->exec= modifier_apply_exec; + ot->poll= modifier_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -595,6 +643,7 @@ void OBJECT_OT_modifier_convert(wmOperatorType *ot) ot->poll= ED_operator_object_active; ot->exec= modifier_convert_exec; + ot->poll= modifier_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -626,6 +675,7 @@ void OBJECT_OT_modifier_copy(wmOperatorType *ot) ot->poll= ED_operator_object_active; ot->exec= modifier_copy_exec; + ot->poll= modifier_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -639,17 +689,15 @@ static int multires_subdivide_exec(bContext *C, wmOperator *op) Object *ob= ptr.id.data; MultiresModifierData *mmd= ptr.data; - if(mmd) { - multiresModifier_subdivide(mmd, ob, 1, 0, mmd->simple); - WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); - } + multiresModifier_subdivide(mmd, ob, 1, 0, mmd->simple); + WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); return OPERATOR_FINISHED; } static int multires_subdivide_poll(bContext *C) { - return NULL != CTX_data_active_object(C) && NULL == CTX_data_edit_object(C); + return (CTX_data_pointer_get_type(C, "modifier", &RNA_MultiresModifier).data != NULL); } void OBJECT_OT_multires_subdivide(wmOperatorType *ot) @@ -667,12 +715,12 @@ void OBJECT_OT_multires_subdivide(wmOperatorType *ot) /************************ mdef bind operator *********************/ -static int modifier_mdef_bind_poll(bContext *C) +static int meshdeform_poll(bContext *C) { return CTX_data_pointer_get_type(C, "modifier", &RNA_MeshDeformModifier).data != NULL; } -static int modifier_mdef_bind_exec(bContext *C, wmOperator *op) +static int meshdeform_bind_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); PointerRNA ptr= CTX_data_pointer_get(C, "modifier"); @@ -723,41 +771,22 @@ static int modifier_mdef_bind_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void OBJECT_OT_modifier_mdef_bind(wmOperatorType *ot) +void OBJECT_OT_meshdeform_bind(wmOperatorType *ot) { /* identifiers */ ot->name= "Mesh Deform Bind"; ot->description = "Bind mesh to cage in mesh deform modifier."; - ot->idname= "OBJECT_OT_modifier_mdef_bind"; + ot->idname= "OBJECT_OT_meshdeform_bind"; /* api callbacks */ - ot->poll= modifier_mdef_bind_poll; - ot->exec= modifier_mdef_bind_exec; + ot->poll= meshdeform_poll; + ot->exec= meshdeform_bind_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } #if 0 -static void modifiers_add(void *ob_v, int type) -{ - Object *ob = ob_v; - ModifierTypeInfo *mti = modifierType_getInfo(type); - - if (mti->flags&eModifierTypeFlag_RequiresOriginalData) { - ModifierData *md = ob->modifiers.first; - - while (md && modifierType_getInfo(md->type)->type==eModifierTypeType_OnlyDeform) { - md = md->next; - } - - BLI_insertlinkbefore(&ob->modifiers, md, modifier_new(type)); - } else { - BLI_addtail(&ob->modifiers, modifier_new(type)); - } - ED_undo_push("Add modifier"); -} - typedef struct MenuEntry { char *name; int ID; @@ -809,89 +838,176 @@ static uiBlock *modifiers_add_menu(void *ob_v) } #endif -#if 0 -static void modifiers_clearHookOffset(bContext *C, void *ob_v, void *md_v) +/******************** hook operators ************************/ + +static int hook_poll(bContext *C) { - Object *ob = ob_v; - ModifierData *md = md_v; - HookModifierData *hmd = (HookModifierData*) md; - - if (hmd->object) { + return CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier).data != NULL; +} + +static int hook_reset_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier); + Object *ob= ptr.id.data; + HookModifierData *hmd= ptr.data; + + if(hmd->object) { Mat4Invert(hmd->object->imat, hmd->object->obmat); Mat4MulSerie(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); - ED_undo_push(C, "Clear hook offset"); } -} -static void modifiers_cursorHookCenter(bContext *C, void *ob_v, void *md_v) -{ - /* XXX - Object *ob = ob_v; - ModifierData *md = md_v; - HookModifierData *hmd = (HookModifierData*) md; - - if(G.vd) { - float *curs = give_cursor(); - float bmat[3][3], imat[3][3]; - - where_is_object(ob); + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); - Mat3CpyMat4(bmat, ob->obmat); - Mat3Inv(imat, bmat); - - curs= give_cursor(); - hmd->cent[0]= curs[0]-ob->obmat[3][0]; - hmd->cent[1]= curs[1]-ob->obmat[3][1]; - hmd->cent[2]= curs[2]-ob->obmat[3][2]; - Mat3MulVecfl(imat, hmd->cent); - - ED_undo_push(C, "Hook cursor center"); - }*/ + return OPERATOR_FINISHED; } -static void modifiers_selectHook(bContext *C, void *ob_v, void *md_v) +void OBJECT_OT_hook_reset(wmOperatorType *ot) { - /* XXX ModifierData *md = md_v; - HookModifierData *hmd = (HookModifierData*) md; + ot->name= "Hook Reset"; + ot->description= "Recalculate and and clear offset transformation."; + ot->idname= "OBJECT_OT_hook_reset"; - hook_select(hmd);*/ + ot->exec= hook_reset_exec; + ot->poll= hook_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -static void modifiers_reassignHook(bContext *C, void *ob_v, void *md_v) +static int hook_recenter_exec(bContext *C, wmOperator *op) { - /* XXX ModifierData *md = md_v; - HookModifierData *hmd = (HookModifierData*) md; + Scene *scene= CTX_data_scene(C); + PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier); + Object *ob= ptr.id.data; + HookModifierData *hmd= ptr.data; + float bmat[3][3], imat[3][3]; + + Mat3CpyMat4(bmat, ob->obmat); + Mat3Inv(imat, bmat); + + VECSUB(hmd->cent, scene->cursor, ob->obmat[3]); + Mat3MulVecfl(imat, hmd->cent); + + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_hook_recenter(wmOperatorType *ot) +{ + ot->name= "Hook Recenter"; + ot->description= "Set hook center to cursor position."; + ot->idname= "OBJECT_OT_hook_recenter"; + + ot->exec= hook_recenter_exec; + ot->poll= hook_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int hook_select_exec(bContext *C, wmOperator *op) +{ + PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier); + Object *ob= ptr.id.data; + HookModifierData *hmd= ptr.data; + + object_hook_select(ob, hmd); + + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, ob); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_hook_select(wmOperatorType *ot) +{ + ot->name= "Hook Select"; + ot->description= "Selects effected vertices on mesh."; + ot->idname= "OBJECT_OT_hook_select"; + + ot->exec= hook_select_exec; + ot->poll= hook_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int hook_assign_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier); + Object *ob= ptr.id.data; + HookModifierData *hmd= ptr.data; float cent[3]; - int *indexar, tot, ok; char name[32]; + int *indexar, tot; - ok= hook_getIndexArray(&tot, &indexar, name, cent); + if(!object_hook_index_array(ob, &tot, &indexar, name, cent)) { + BKE_report(op->reports, RPT_WARNING, "Requires selected vertices or active vertex group"); + return OPERATOR_CANCELLED; + } - if (!ok) { - uiPupMenuError(C, "Requires selected vertices or active Vertex Group"); - } else { - if (hmd->indexar) { - MEM_freeN(hmd->indexar); - } + if(hmd->indexar) + MEM_freeN(hmd->indexar); - VECCOPY(hmd->cent, cent); - hmd->indexar = indexar; - hmd->totindex = tot; - }*/ + VECCOPY(hmd->cent, cent); + hmd->indexar= indexar; + hmd->totindex= tot; + + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); + + return OPERATOR_FINISHED; } -void modifiers_explodeFacepa(bContext *C, void *arg1, void *arg2) +void OBJECT_OT_hook_assign(wmOperatorType *ot) { - ExplodeModifierData *emd=arg1; + ot->name= "Hook Assign"; + ot->description= "Reassigns selected vertices to hook."; + ot->idname= "OBJECT_OT_hook_assign"; + + ot->exec= hook_assign_exec; + ot->poll= hook_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/****************** explode refresh operator *********************/ + +static int explode_refresh_poll(bContext *C) +{ + return CTX_data_pointer_get_type(C, "modifier", &RNA_ExplodeModifier).data != NULL; +} + +static int explode_refresh_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_ExplodeModifier); + Object *ob= ptr.id.data; + ExplodeModifierData *emd= ptr.data; emd->flag |= eExplodeFlag_CalcFaces; + + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); + + return OPERATOR_FINISHED; } -void modifiers_explodeDelVg(bContext *C, void *arg1, void *arg2) +void OBJECT_OT_explode_refresh(wmOperatorType *ot) { - ExplodeModifierData *emd=arg1; - emd->vgroup = 0; + ot->name= "Explode Refresh"; + ot->description= "Refresh data in the Explode modifier."; + ot->idname= "OBJECT_OT_explode_refresh"; + + ot->exec= explode_refresh_exec; + ot->poll= explode_refresh_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -#endif - diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index f2e048284f4..6f1a3b5f6cb 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -118,7 +118,12 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_modifier_convert); WM_operatortype_append(OBJECT_OT_modifier_copy); WM_operatortype_append(OBJECT_OT_multires_subdivide); - WM_operatortype_append(OBJECT_OT_modifier_mdef_bind); + WM_operatortype_append(OBJECT_OT_meshdeform_bind); + WM_operatortype_append(OBJECT_OT_hook_reset); + WM_operatortype_append(OBJECT_OT_hook_recenter); + WM_operatortype_append(OBJECT_OT_hook_select); + WM_operatortype_append(OBJECT_OT_hook_assign); + WM_operatortype_append(OBJECT_OT_explode_refresh); WM_operatortype_append(OBJECT_OT_constraint_add); WM_operatortype_append(OBJECT_OT_constraint_add_with_targets); diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 320574fe8b3..f714a291bd7 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -1044,7 +1044,6 @@ static char *windowtype_pup(void) "Window type:%t" "|3D View %x1" - "|%l" "|%l" "|Timeline %x15" @@ -1052,7 +1051,6 @@ static char *windowtype_pup(void) "|DopeSheet %x12" "|NLA Editor %x13" - "|%l" "|%l" "|UV/Image Editor %x6" @@ -1062,7 +1060,6 @@ static char *windowtype_pup(void) "|Node Editor %x16" "|Logic Editor %x17" - "|%l" "|%l" "|Properties %x4" @@ -1070,12 +1067,10 @@ static char *windowtype_pup(void) "|User Preferences %x19" "|Info%x7" - "|%l" "|%l" "|File Browser %x5" - "|%l" "|%l" "|Console %x18" diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 6c86c87302c..3487efc4218 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -3442,10 +3442,5 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) } } - - /* do not do view2d totrect set here, it's now a template */ - - uiEndBlock(C, block); - uiDrawBlock(C, block); } diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 33499574012..912d11dcc8c 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -318,7 +318,7 @@ typedef struct UVProjectModifierData { ModifierData modifier; /* the objects which do the projecting */ - struct Object *projectors[10]; + struct Object *projectors[10]; /* MOD_UVPROJECT_MAX */ struct Image *image; /* the image to project */ int flags; int num_projectors; @@ -669,4 +669,6 @@ typedef struct SimpleDeformModifierData { coordinates or global coordinates of origin */ #define MOD_SIMPLEDEFORM_ORIGIN_LOCAL (1<<0) +#define MOD_UVPROJECT_MAX 10 + #endif diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 9bdbc8baed7..3b0db949350 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -1173,8 +1173,14 @@ void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item defaultfound= 1; } - if(!defaultfound) - eprop->defaultvalue= item[0].value; + if(!defaultfound) { + for(i=0; item[i].identifier; i++) { + if(item[i].identifier[0]) { + eprop->defaultvalue= item[i].value; + break; + } + } + } break; } diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index f2c8e404a52..c080b88feaf 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -43,41 +43,43 @@ #include "WM_types.h" EnumPropertyItem modifier_type_items[] ={ - {eModifierType_Armature, "ARMATURE", ICON_MOD_ARMATURE, "Armature", ""}, + {0, "", 0, "Generate", ""}, {eModifierType_Array, "ARRAY", ICON_MOD_ARRAY, "Array", ""}, {eModifierType_Bevel, "BEVEL", ICON_MOD_BEVEL, "Bevel", ""}, {eModifierType_Boolean, "BOOLEAN", ICON_MOD_BOOLEAN, "Boolean", ""}, {eModifierType_Build, "BUILD", ICON_MOD_BUILD, "Build", ""}, - {eModifierType_Cast, "CAST", ICON_MOD_CAST, "Cast", ""}, - {eModifierType_Cloth, "CLOTH", ICON_MOD_CLOTH, "Cloth", ""}, - {eModifierType_Collision, "COLLISION", ICON_MOD_PHYSICS, "Collision", ""}, - {eModifierType_Curve, "CURVE", ICON_MOD_CURVE, "Curve", ""}, {eModifierType_Decimate, "DECIMATE", ICON_MOD_DECIM, "Decimate", ""}, - {eModifierType_Displace, "DISPLACE", ICON_MOD_DISPLACE, "Displace", ""}, {eModifierType_EdgeSplit, "EDGE_SPLIT", ICON_MOD_EDGESPLIT, "Edge Split", ""}, - {eModifierType_Explode, "EXPLODE", ICON_MOD_EXPLODE, "Explode", ""}, - {eModifierType_Fluidsim, "FLUID_SIMULATION", ICON_MOD_FLUIDSIM, "Fluid Simulation", ""}, - {eModifierType_Hook, "HOOK", ICON_HOOK, "Hook", ""}, - {eModifierType_Lattice, "LATTICE", ICON_MOD_LATTICE, "Lattice", ""}, {eModifierType_Mask, "MASK", ICON_MOD_MASK, "Mask", ""}, - {eModifierType_MeshDeform, "MESH_DEFORM", ICON_MOD_MESHDEFORM, "Mesh Deform", ""}, {eModifierType_Mirror, "MIRROR", ICON_MOD_MIRROR, "Mirror", ""}, {eModifierType_Multires, "MULTIRES", ICON_MOD_MULTIRES, "Multiresolution", ""}, - {eModifierType_ParticleInstance, "PARTICLE_INSTANCE", ICON_MOD_PARTICLES, "Particle Instance", ""}, - {eModifierType_ParticleSystem, "PARTICLE_SYSTEM", ICON_MOD_PARTICLES, "Particle System", ""}, + {eModifierType_Subsurf, "SUBSURF", ICON_MOD_SUBSURF, "Subdivision Surface", ""}, + {eModifierType_UVProject, "UV_PROJECT", ICON_MOD_UVPROJECT, "UV Project", ""}, + {0, "", 0, "Deformers", ""}, + {eModifierType_Armature, "ARMATURE", ICON_MOD_ARMATURE, "Armature", ""}, + {eModifierType_Cast, "CAST", ICON_MOD_CAST, "Cast", ""}, + {eModifierType_Curve, "CURVE", ICON_MOD_CURVE, "Curve", ""}, + {eModifierType_Displace, "DISPLACE", ICON_MOD_DISPLACE, "Displace", ""}, + {eModifierType_Hook, "HOOK", ICON_HOOK, "Hook", ""}, + {eModifierType_Lattice, "LATTICE", ICON_MOD_LATTICE, "Lattice", ""}, + {eModifierType_MeshDeform, "MESH_DEFORM", ICON_MOD_MESHDEFORM, "Mesh Deform", ""}, {eModifierType_Shrinkwrap, "SHRINKWRAP", ICON_MOD_SHRINKWRAP, "Shrinkwrap", ""}, {eModifierType_SimpleDeform, "SIMPLE_DEFORM", ICON_MOD_SIMPLEDEFORM, "Simple Deform", ""}, + {eModifierType_Smooth, "SMOOTH", ICON_MOD_SMOOTH, "Smooth", ""}, + {eModifierType_Wave, "WAVE", ICON_MOD_WAVE, "Wave", ""}, + {0, "", 0, "Physics", ""}, + {eModifierType_Cloth, "CLOTH", ICON_MOD_CLOTH, "Cloth", ""}, + {eModifierType_Collision, "COLLISION", ICON_MOD_PHYSICS, "Collision", ""}, + {eModifierType_Explode, "EXPLODE", ICON_MOD_EXPLODE, "Explode", ""}, + {eModifierType_Fluidsim, "FLUID_SIMULATION", ICON_MOD_FLUIDSIM, "Fluid Simulation", ""}, + {eModifierType_ParticleInstance, "PARTICLE_INSTANCE", ICON_MOD_PARTICLES, "Particle Instance", ""}, + {eModifierType_ParticleSystem, "PARTICLE_SYSTEM", ICON_MOD_PARTICLES, "Particle System", ""}, {eModifierType_Smoke, "SMOKE", 0, "Smoke", ""}, {eModifierType_SmokeHR, "SMOKE_HR", 0, "SmokeHR", ""}, - {eModifierType_Smooth, "SMOOTH", ICON_MOD_SMOOTH, "Smooth", ""}, {eModifierType_Softbody, "SOFT_BODY", ICON_MOD_SOFT, "Soft Body", ""}, - {eModifierType_Subsurf, "SUBSURF", ICON_MOD_SUBSURF, "Subdivision Surface", ""}, {eModifierType_Surface, "SURFACE", ICON_MOD_PHYSICS, "Surface", ""}, - {eModifierType_UVProject, "UV_PROJECT", ICON_MOD_UVPROJECT, "UV Project", ""}, - {eModifierType_Wave, "WAVE", ICON_MOD_WAVE, "Wave", ""}, {0, NULL, 0, NULL, NULL}}; - #ifdef RNA_RUNTIME #include "BKE_context.h" @@ -87,7 +89,7 @@ EnumPropertyItem modifier_type_items[] ={ static void rna_UVProject_projectors_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { UVProjectModifierData *uvp= (UVProjectModifierData*)ptr->data; - rna_iterator_array_begin(iter, (void*)uvp->projectors, sizeof(Object*), 10, 0, NULL); + rna_iterator_array_begin(iter, (void*)uvp->projectors, sizeof(Object*), uvp->num_projectors, 0, NULL); } static StructRNA* rna_Modifier_refine(struct PointerRNA *ptr) @@ -410,6 +412,34 @@ static PointerRNA rna_CollisionModifier_settings_get(PointerRNA *ptr) return rna_pointer_inherit_refine(ptr, &RNA_CollisionSettings, ob->pd); } +static PointerRNA rna_UVProjector_object_get(PointerRNA *ptr) +{ + Object **ob= (Object**)ptr->data; + return rna_pointer_inherit_refine(ptr, &RNA_Object, *ob); +} + +static void rna_UVProjector_object_set(PointerRNA *ptr, PointerRNA value) +{ + Object **ob= (Object**)ptr->data; + + if(*ob) + id_us_min((ID*)*ob); + if(value.data) + id_us_plus((ID*)value.data); + + *ob= value.data; +} + +static void rna_UVProjectModifier_num_projectors_set(PointerRNA *ptr, int value) +{ + UVProjectModifierData *md= (UVProjectModifierData*)ptr->data; + int a; + + md->num_projectors= CLAMPIS(value, 1, MOD_UVPROJECT_MAX); + for(a=md->num_projectors; aprojectors[a]= NULL; +} + #else static void rna_def_property_subdivision_common(StructRNA *srna, const char type[]) @@ -1150,7 +1180,7 @@ static void rna_def_modifier_uvproject(BlenderRNA *brna) PropertyRNA *prop; srna= RNA_def_struct(brna, "UVProjectModifier", "Modifier"); - RNA_def_struct_ui_text(srna, "UVProject Modifier", "UV projection modifier to sets UVs from a projector."); + RNA_def_struct_ui_text(srna, "UV Project Modifier", "UV projection modifier to sets UVs from a projector."); RNA_def_struct_sdna(srna, "UVProjectModifierData"); RNA_def_struct_ui_icon(srna, ICON_MOD_UVPROJECT); @@ -1160,9 +1190,15 @@ static void rna_def_modifier_uvproject(BlenderRNA *brna) RNA_def_property_string_funcs(prop, NULL, NULL, "rna_UVProjectModifier_uvlayer_set"); RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Modifier_update"); + prop= RNA_def_property(srna, "num_projectors", PROP_INT, PROP_NONE); + RNA_def_property_ui_text(prop, "Number of Projectors", "Number of projectors to use."); + RNA_def_property_int_funcs(prop, NULL, "rna_UVProjectModifier_num_projectors_set", NULL); + RNA_def_property_range(prop, 1, MOD_UVPROJECT_MAX); + RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Modifier_update"); + prop= RNA_def_property(srna, "projectors", PROP_COLLECTION, PROP_NONE); - RNA_def_property_struct_type(prop, "Object"); - RNA_def_property_collection_funcs(prop, "rna_UVProject_projectors_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_dereference_get", 0, 0, 0, 0, 0); + RNA_def_property_struct_type(prop, "UVProjector"); + RNA_def_property_collection_funcs(prop, "rna_UVProject_projectors_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", 0, 0, 0, 0, 0); RNA_def_property_ui_text(prop, "Projectors", ""); prop= RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE); @@ -1188,6 +1224,15 @@ static void rna_def_modifier_uvproject(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_UVPROJECT_OVERRIDEIMAGE); RNA_def_property_ui_text(prop, "Override Image", "Override faces' current images with the given image."); RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Modifier_update"); + + srna= RNA_def_struct(brna, "UVProjector", NULL); + RNA_def_struct_ui_text(srna, "UVProjector", "UV projector used by the UV project modifier."); + + prop= RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "Object"); + RNA_def_property_pointer_funcs(prop, "rna_UVProjector_object_get", "rna_UVProjector_object_set", NULL); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Object", "Object to use as projector transform."); } static void rna_def_modifier_smooth(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 0301932aef3..40e3efc9e46 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -1144,27 +1144,28 @@ static void rna_def_scene_render_data(BlenderRNA *brna) static EnumPropertyItem image_type_items[] = { + {0, "", 0, "Image", NULL}, {R_PNG, "PNG", 0, "PNG", ""}, {R_JPEG90, "JPEG", 0, "JPEG", ""}, #ifdef WITH_OPENJPEG {R_JP2, "JPEG2000", 0, "JPEG 2000", ""}, #endif - {R_TIFF, "TIFF", 0, "TIFF", ""}, // XXX only with G.have_libtiff {R_BMP, "BMP", 0, "BMP", ""}, {R_TARGA, "TARGA", 0, "Targa", ""}, {R_RAWTGA, "RAWTARGA", 0, "Targa Raw", ""}, //{R_DDS, "DDS", 0, "DDS", ""}, // XXX not yet implemented {R_HAMX, "HAMX", 0, "HamX", ""}, {R_IRIS, "IRIS", 0, "Iris", ""}, - {0, "", 0, NULL, NULL}, + {0, "", 0, " ", NULL}, #ifdef WITH_OPENEXR {R_OPENEXR, "OPENEXR", 0, "OpenEXR", ""}, {R_MULTILAYER, "MULTILAYER", 0, "MultiLayer", ""}, #endif + {R_TIFF, "TIFF", 0, "TIFF", ""}, // XXX only with G.have_libtiff {R_RADHDR, "RADHDR", 0, "Radiance HDR", ""}, {R_CINEON, "CINEON", 0, "Cineon", ""}, {R_DPX, "DPX", 0, "DPX", ""}, - {0, "", 0, NULL, NULL}, + {0, "", 0, "Movie", NULL}, {R_AVIRAW, "AVIRAW", 0, "AVI Raw", ""}, {R_AVIJPEG, "AVIJPEG", 0, "AVI JPEG", ""}, #ifdef _WIN32 @@ -1187,7 +1188,6 @@ static void rna_def_scene_render_data(BlenderRNA *brna) #endif {R_FFMPEG, "FFMPEG", 0, "FFMpeg", ""}, #endif - {0, "", 0, NULL, NULL}, {R_FRAMESERVER, "FRAMESERVER", 0, "Frame Server", ""}, {0, NULL, 0, NULL, NULL}}; diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 304da25017b..ab8dfeabe4f 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -741,7 +741,6 @@ static void WM_OT_window_duplicate(wmOperatorType *ot) ot->name= "Duplicate Window"; ot->idname= "WM_OT_window_duplicate"; - ot->invoke= WM_operator_confirm; ot->exec= wm_window_duplicate_op; ot->poll= WM_operator_winactive; } @@ -1035,7 +1034,6 @@ static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot) ot->name= "Toggle Fullscreen"; ot->idname= "WM_OT_window_fullscreen_toggle"; - ot->invoke= WM_operator_confirm; ot->exec= wm_window_fullscreen_toggle_op; ot->poll= WM_operator_winactive; } From 442ba39d49d9453f84791989c9149692b70ddad5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 21 Aug 2009 03:06:36 +0000 Subject: [PATCH 35/73] fix for own bug added since 2.49a, 2.49a tries to remove the object from the conversion list every time. Now remove from the conversion list directly without being apart of the remove object function. --- source/gameengine/Converter/BL_BlenderDataConversion.cpp | 3 +++ source/gameengine/Converter/KX_BlenderSceneConverter.cpp | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 5b03bbbbc4e..d2e6bbb43f7 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -2422,8 +2422,11 @@ void BL_ConvertBlenderObjects(struct Main* maggie, obj->Release(); } childrenlist->Release(); + // now destroy recursively + converter->UnregisterGameObject(childobj); // removing objects during conversion make sure this runs too kxscene->RemoveObject(childobj); + continue; } diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 59c073c2b1f..4f47ce7a036 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -492,10 +492,11 @@ void KX_BlenderSceneConverter::RegisterGameObject( m_map_blender_to_gameobject.insert(CHashedPtr(for_blenderobject),gameobject); } +/* only need to run this during conversion since + * m_map_blender_to_gameobject is freed after conversion */ void KX_BlenderSceneConverter::UnregisterGameObject( KX_GameObject *gameobject) { -#if 0 struct Object *bobp= gameobject->GetBlenderObject(); if (bobp) { CHashedPtr bptr(bobp); @@ -507,7 +508,6 @@ void KX_BlenderSceneConverter::UnregisterGameObject( m_map_blender_to_gameobject.remove(bptr); } } -#endif } KX_GameObject *KX_BlenderSceneConverter::FindGameObject( From 589ea76833778a37fe0ec93cc28de1102d9793b5 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Fri, 21 Aug 2009 06:23:38 +0000 Subject: [PATCH 36/73] 2.5/Paint: * Updated texture paint UI for stroke settings. * Removed duplicate brush blend types, just use the ones defined in imbuf instead --- release/ui/space_view3d_toolbar.py | 38 ++++++++----------- .../editors/sculpt_paint/paint_image.c | 2 +- source/blender/makesdna/DNA_brush_types.h | 10 ----- source/blender/makesrna/intern/rna_brush.c | 18 +++++---- 4 files changed, 27 insertions(+), 41 deletions(-) diff --git a/release/ui/space_view3d_toolbar.py b/release/ui/space_view3d_toolbar.py index 35df4dc8b54..d0f07c70657 100644 --- a/release/ui/space_view3d_toolbar.py +++ b/release/ui/space_view3d_toolbar.py @@ -369,7 +369,7 @@ class VIEW3D_PT_tools_brush(PaintPanel): col = layout.column() col.itemR(brush, "color", text="") - + row = col.row(align=True) row.itemR(brush, "size", slider=True) row.itemR(brush, "size_pressure", toggle=True, icon='ICON_BRUSH_DATA', text="") @@ -382,18 +382,7 @@ class VIEW3D_PT_tools_brush(PaintPanel): row.itemR(brush, "falloff", slider=True) row.itemR(brush, "falloff_pressure", toggle=True, icon='ICON_BRUSH_DATA', text="") - row = col.row(align=True) - row.itemR(brush, "space", text="") - rowsub = row.row(align=True) - rowsub.active = brush.space - rowsub.itemR(brush, "spacing", text="Spacing", slider=True) - rowsub.itemR(brush, "spacing_pressure", toggle=True, icon='ICON_BRUSH_DATA', text="") - - col = layout.column() - col.itemR(brush, "airbrush") - sub = col.column() - sub.active = brush.airbrush - sub.itemR(brush, "rate") + col.itemR(brush, "blend") # Weight Paint Mode # @@ -431,23 +420,28 @@ class VIEW3D_PT_tools_brush_stroke(PaintPanel): settings = self.paint_settings(context) return (settings and settings.brush and (context.sculpt_object or context.vertex_paint_object or - context.weight_paint_object)) + context.weight_paint_object or + context.texture_paint_object)) def draw(self, context): settings = self.paint_settings(context) brush = settings.brush + texture_paint = context.texture_paint_object layout = self.layout - layout.itemR(brush, "smooth_stroke") - col = layout.column() - col.active = brush.smooth_stroke - col.itemR(brush, "smooth_stroke_radius", text="Radius", slider=True) - col.itemR(brush, "smooth_stroke_factor", text="Factor", slider=True) + if not texture_paint: + layout.itemR(brush, "smooth_stroke") + col = layout.column() + col.active = brush.smooth_stroke + col.itemR(brush, "smooth_stroke_radius", text="Radius", slider=True) + col.itemR(brush, "smooth_stroke_factor", text="Factor", slider=True) layout.itemR(brush, "space") - col = layout.column() - col.active = brush.space - col.itemR(brush, "spacing", text="Distance", slider=True) + row = layout.row(align=True) + row.active = brush.space + row.itemR(brush, "spacing", text="Distance", slider=True) + if texture_paint: + row.itemR(brush, "spacing_pressure", toggle=True, icon='ICON_BRUSH_DATA', text="") layout.itemR(brush, "airbrush") col = layout.column() diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 2dcd7a64947..afd8336c2a9 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -4719,7 +4719,7 @@ static void paint_apply_event(bContext *C, wmOperator *op, wmEvent *event) tablet= (wmtab->Active != EVT_TABLET_NONE); pressure= wmtab->Pressure; if(wmtab->Active == EVT_TABLET_ERASER) - pop->s.blend= BRUSH_BLEND_ERASE_ALPHA; + pop->s.blend= IMB_BLEND_ERASE_ALPHA; } else pressure= 1.0f; diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h index 52ea298c110..a3a1a342584 100644 --- a/source/blender/makesdna/DNA_brush_types.h +++ b/source/blender/makesdna/DNA_brush_types.h @@ -86,16 +86,6 @@ typedef struct Brush { #define BRUSH_SMOOTH_STROKE 2048 #define BRUSH_PERSISTENT 4096 -/* Brush.blend */ -#define BRUSH_BLEND_MIX 0 -#define BRUSH_BLEND_ADD 1 -#define BRUSH_BLEND_SUB 2 -#define BRUSH_BLEND_MUL 3 -#define BRUSH_BLEND_LIGHTEN 4 -#define BRUSH_BLEND_DARKEN 5 -#define BRUSH_BLEND_ERASE_ALPHA 6 -#define BRUSH_BLEND_ADD_ALPHA 7 - /* Brush.sculpt_tool */ #define SCULPT_TOOL_DRAW 1 #define SCULPT_TOOL_SMOOTH 2 diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c index 03b5a44f52b..9c453ac44df 100644 --- a/source/blender/makesrna/intern/rna_brush.c +++ b/source/blender/makesrna/intern/rna_brush.c @@ -32,6 +32,8 @@ #include "DNA_brush_types.h" #include "DNA_texture_types.h" +#include "IMB_imbuf.h" + EnumPropertyItem brush_sculpt_tool_items[] = { {SCULPT_TOOL_DRAW, "DRAW", 0, "Draw", ""}, {SCULPT_TOOL_SMOOTH, "SMOOTH", 0, "Smooth", ""}, @@ -93,14 +95,14 @@ void rna_def_brush(BlenderRNA *brna) PropertyRNA *prop; static EnumPropertyItem prop_blend_items[] = { - {BRUSH_BLEND_MIX, "MIX", 0, "Mix", "Use mix blending mode while painting."}, - {BRUSH_BLEND_ADD, "ADD", 0, "Add", "Use add blending mode while painting."}, - {BRUSH_BLEND_SUB, "SUB", 0, "Subtract", "Use subtract blending mode while painting."}, - {BRUSH_BLEND_MUL, "MUL", 0, "Multiply", "Use multiply blending mode while painting."}, - {BRUSH_BLEND_LIGHTEN, "LIGHTEN", 0, "Lighten", "Use lighten blending mode while painting."}, - {BRUSH_BLEND_DARKEN, "DARKEN", 0, "Darken", "Use darken blending mode while painting."}, - {BRUSH_BLEND_ERASE_ALPHA, "ERASE_ALPHA", 0, "Erase Alpha", "Erase alpha while painting."}, - {BRUSH_BLEND_ADD_ALPHA, "ADD_ALPHA", 0, "Add Alpha", "Add alpha while painting."}, + {IMB_BLEND_MIX, "MIX", 0, "Mix", "Use mix blending mode while painting."}, + {IMB_BLEND_ADD, "ADD", 0, "Add", "Use add blending mode while painting."}, + {IMB_BLEND_SUB, "SUB", 0, "Subtract", "Use subtract blending mode while painting."}, + {IMB_BLEND_MUL, "MUL", 0, "Multiply", "Use multiply blending mode while painting."}, + {IMB_BLEND_LIGHTEN, "LIGHTEN", 0, "Lighten", "Use lighten blending mode while painting."}, + {IMB_BLEND_DARKEN, "DARKEN", 0, "Darken", "Use darken blending mode while painting."}, + {IMB_BLEND_ERASE_ALPHA, "ERASE_ALPHA", 0, "Erase Alpha", "Erase alpha while painting."}, + {IMB_BLEND_ADD_ALPHA, "ADD_ALPHA", 0, "Add Alpha", "Add alpha while painting."}, {0, NULL, 0, NULL, NULL}}; srna= RNA_def_struct(brna, "Brush", "ID"); From 46fb2d37e347b6ecbd0097aa662cd2fdc4b65f33 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 21 Aug 2009 07:19:06 +0000 Subject: [PATCH 37/73] have texture paint use the curve rather then the falloff setting (falloff gave ugly center area of 100% opacity) --- release/ui/space_view3d_toolbar.py | 4 ---- source/blender/blenkernel/BKE_brush.h | 1 - source/blender/blenkernel/intern/brush.c | 17 ----------------- .../blender/editors/sculpt_paint/paint_image.c | 7 ++++--- source/blender/windowmanager/intern/Makefile | 1 - 5 files changed, 4 insertions(+), 26 deletions(-) diff --git a/release/ui/space_view3d_toolbar.py b/release/ui/space_view3d_toolbar.py index d0f07c70657..254fb3fd560 100644 --- a/release/ui/space_view3d_toolbar.py +++ b/release/ui/space_view3d_toolbar.py @@ -378,10 +378,6 @@ class VIEW3D_PT_tools_brush(PaintPanel): row.itemR(brush, "strength", slider=True) row.itemR(brush, "strength_pressure", toggle=True, icon='ICON_BRUSH_DATA', text="") - row = col.row(align=True) - row.itemR(brush, "falloff", slider=True) - row.itemR(brush, "falloff_pressure", toggle=True, icon='ICON_BRUSH_DATA', text="") - col.itemR(brush, "blend") # Weight Paint Mode # diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h index 6ec988e111e..4d24a2433b3 100644 --- a/source/blender/blenkernel/BKE_brush.h +++ b/source/blender/blenkernel/BKE_brush.h @@ -64,7 +64,6 @@ float brush_curve_strength(struct Brush *br, float p, const float len); /* sampling */ float brush_sample_falloff(struct Brush *brush, float dist); -float brush_sample_falloff_noalpha(struct Brush *brush, float dist); void brush_sample_tex(struct Brush *brush, float *xy, float *rgba); void brush_imbuf_new(struct Brush *brush, short flt, short texfalloff, int size, struct ImBuf **imbuf); diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index a7b5a16d924..bce4e1120be 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -409,23 +409,6 @@ float brush_sample_falloff(Brush *brush, float dist) return 0.0f; } -float brush_sample_falloff_noalpha(Brush *brush, float dist) -{ - float outer, inner; - - outer = brush->size >> 1; - inner = outer*brush->innerradius; - - if (dist <= inner) { - return 1.0f; - } - else if ((dist < outer) && (inner < outer)) { - return 1.0f - sqrt((dist - inner)/(outer - inner)); - } - else - return 0.0f; -} - void brush_sample_tex(Brush *brush, float *xy, float *rgba) { MTex *mtex= brush->mtex[brush->texact]; diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index afd8336c2a9..d082e17cda3 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -3707,7 +3707,7 @@ static void *do_projectpaint_thread(void *ph_v) ProjPaintImage *last_projIma= NULL; ImagePaintPartialRedraw *last_partial_redraw_cell; - float rgba[4], alpha, dist_nosqrt; + float rgba[4], alpha, dist_nosqrt, dist; float brush_size_sqared; float falloff; @@ -3721,6 +3721,7 @@ static void *do_projectpaint_thread(void *ph_v) float co[2]; float mask = 1.0f; /* airbrush wont use mask */ unsigned short mask_short; + float size_half = ((float)ps->brush->size) * 0.5f; LinkNode *smearPixels = NULL; LinkNode *smearPixels_f = NULL; @@ -3755,8 +3756,8 @@ static void *do_projectpaint_thread(void *ph_v) dist_nosqrt = Vec2Lenf_nosqrt(projPixel->projCoSS, pos); /*if (dist < s->brush->size) {*/ /* correct but uses a sqrtf */ - if (dist_nosqrt < brush_size_sqared) { - falloff = brush_sample_falloff_noalpha(ps->brush, sqrtf(dist_nosqrt)); + if (dist_nosqrt < brush_size_sqared && (dist=sqrtf(dist_nosqrt)) < size_half) { + falloff = brush_curve_strength(ps->brush, dist, size_half); if (falloff > 0.0f) { if (ps->is_texbrush) { brush_sample_tex(ps->brush, projPixel->projCoSS, rgba); diff --git a/source/blender/windowmanager/intern/Makefile b/source/blender/windowmanager/intern/Makefile index 823423cc28b..f4d65975d43 100644 --- a/source/blender/windowmanager/intern/Makefile +++ b/source/blender/windowmanager/intern/Makefile @@ -58,7 +58,6 @@ CPPFLAGS += -I../../imbuf CPPFLAGS += -I../../blenloader CPPFLAGS += -I../../gpu CPPFLAGS += -I../../render/extern/include -CPPFLAGS += -I../../radiosity/extern/include CPPFLAGS += -I../../../kernel/gen_system CPPFLAGS += -I../../blenfont From 9125fe55fbe18d0fafdf388ce69f9bd29657da2f Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Fri, 21 Aug 2009 10:47:27 +0000 Subject: [PATCH 38/73] Hook Modifier - Bone Targets Made Hook Modifier be able to use bone targets. However, I haven't been able to verify that everything will work perfectly, since just creating a new Hook Modifier and assigning targets doesn't set hmd->indexar correctly. --- release/ui/buttons_data_modifier.py | 6 ++++- source/blender/blenkernel/intern/action.c | 5 ++-- source/blender/blenkernel/intern/modifier.c | 27 ++++++++++++++----- source/blender/editors/object/object_edit.c | 4 +++ .../blender/editors/object/object_modifier.c | 19 +++++++++++-- source/blender/makesdna/DNA_modifier_types.h | 2 ++ source/blender/makesrna/intern/rna_modifier.c | 5 ++++ 7 files changed, 56 insertions(+), 12 deletions(-) diff --git a/release/ui/buttons_data_modifier.py b/release/ui/buttons_data_modifier.py index cc50256f216..f5af26f8746 100644 --- a/release/ui/buttons_data_modifier.py +++ b/release/ui/buttons_data_modifier.py @@ -200,7 +200,11 @@ class DATA_PT_modifiers(DataButtonsPanel): layout.itemL(text="See Fluid panel.") def HOOK(self, layout, ob, md): - layout.itemR(md, "object") + col = layout.column() + col.itemR(md, "object") + if md.object and md.object.type == "ARMATURE": + layout.item_pointerR(md, "subtarget", md.object.data, "bones", text="Bone") + layout.item_pointerR(md, "vertex_group", ob, "vertex_groups") split = layout.split() diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index f4d4eb1cc9c..6a39139d250 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -410,8 +410,9 @@ bActionGroup *action_groups_find_named (bAction *act, const char name[]) bPoseChannel *get_pose_channel(const bPose *pose, const char *name) { bPoseChannel *chan; - - if (pose==NULL) return NULL; + + if (ELEM(NULL, pose, name) || (name[0] == 0)) + return NULL; for (chan=pose->chanbase.first; chan; chan=chan->next) { if (chan->name[0] == name[0]) { diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 37cf427b897..501638aba0d 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -5598,6 +5598,7 @@ static void hookModifier_copyData(ModifierData *md, ModifierData *target) thmd->indexar = MEM_dupallocN(hmd->indexar); memcpy(thmd->parentinv, hmd->parentinv, sizeof(hmd->parentinv)); strncpy(thmd->name, hmd->name, 32); + strncpy(thmd->subtarget, hmd->subtarget, 32); } CustomDataMask hookModifier_requiredDataMask(Object *ob, ModifierData *md) @@ -5642,9 +5643,11 @@ static void hookModifier_updateDepgraph(ModifierData *md, DagForest *forest, Sce if (hmd->object) { DagNode *curNode = dag_get_node(forest, hmd->object); - - dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA, - "Hook Modifier"); + + if (hmd->subtarget[0]) + dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA|DAG_RL_DATA_DATA, "Hook Modifier"); + else + dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA, "Hook Modifier"); } } @@ -5653,12 +5656,22 @@ static void hookModifier_deformVerts( float (*vertexCos)[3], int numVerts, int useRenderParams, int isFinalCalc) { HookModifierData *hmd = (HookModifierData*) md; - float vec[3], mat[4][4]; + bPoseChannel *pchan= get_pose_channel(hmd->object->pose, hmd->subtarget); + float vec[3], mat[4][4], dmat[4][4], imat[4][4]; int i; DerivedMesh *dm = derivedData; - - Mat4Invert(ob->imat, ob->obmat); - Mat4MulSerie(mat, ob->imat, hmd->object->obmat, hmd->parentinv, + + /* get world-space matrix of target, corrected for the space the verts are in */ + if (hmd->subtarget[0] && pchan) { + /* bone target if there's a matching pose-channel */ + Mat4MulMat4(dmat, pchan->pose_mat, hmd->object->obmat); + } + else { + /* just object target */ + Mat4CpyMat4(dmat, hmd->object->obmat); + } + Mat4Invert(imat, dmat); + Mat4MulSerie(mat, imat, dmat, hmd->parentinv, NULL, NULL, NULL, NULL, NULL); /* vertex indices? */ diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 2fb9835f833..e1b8858937c 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -979,6 +979,9 @@ static void select_editmesh_hook(Object *ob, HookModifierData *hmd) EditVert *eve; int index=0, nr=0; + if (hmd->indexar == NULL) + return; + for(eve= em->verts.first; eve; eve= eve->next, nr++) { if(nr==hmd->indexar[index]) { eve->f |= SELECT; @@ -1361,6 +1364,7 @@ void add_hook(Scene *scene, View3D *v3d, int mode) hmd->totindex= tot; BLI_strncpy(hmd->name, name, 32); + // TODO: need to take into account bone targets here too now... if(mode==1 || mode==2) { /* matrix calculus */ /* vert x (obmat x hook->imat) x hook->obmat x ob->imat */ diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 32a1297aaf4..3785e17f67c 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -31,6 +31,7 @@ #include "MEM_guardedalloc.h" +#include "DNA_action_types.h" #include "DNA_curve_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" @@ -42,6 +43,7 @@ #include "BLI_arithb.h" #include "BLI_listbase.h" +#include "BKE_action.h" #include "BKE_curve.h" #include "BKE_context.h" #include "BKE_depsgraph.h" @@ -853,8 +855,21 @@ static int hook_reset_exec(bContext *C, wmOperator *op) HookModifierData *hmd= ptr.data; if(hmd->object) { - Mat4Invert(hmd->object->imat, hmd->object->obmat); - Mat4MulSerie(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); + bPoseChannel *pchan= get_pose_channel(hmd->object->pose, hmd->subtarget); + + if(hmd->subtarget[0] && pchan) { + float imat[4][4], mat[4][4]; + + /* calculate the world-space matrix for the pose-channel target first, then carry on as usual */ + Mat4MulMat4(mat, pchan->pose_mat, hmd->object->obmat); + + Mat4Invert(imat, mat); + Mat4MulSerie(hmd->parentinv, imat, mat, NULL, NULL, NULL, NULL, NULL, NULL); + } + else { + Mat4Invert(hmd->object->imat, hmd->object->obmat); + Mat4MulSerie(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); + } } DAG_object_flush_update(scene, ob, OB_RECALC_DATA); diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 912d11dcc8c..a4587c34e89 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -426,6 +426,8 @@ typedef struct HookModifierData { ModifierData modifier; struct Object *object; + char subtarget[32]; /* optional name of bone target */ + float parentinv[4][4]; /* matrix making current transform unmodified */ float cent[3]; /* visualization of hook */ float falloff; /* if not zero, falloff is distance where influence zero */ diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index c080b88feaf..bfd93a4218b 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -912,6 +912,11 @@ static void rna_def_modifier_hook(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Object", "Parent Object for hook, also recalculates and clears offset"); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Modifier_dependency_update"); + + prop= RNA_def_property(srna, "subtarget", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "subtarget"); + RNA_def_property_ui_text(prop, "Sub-Target", "Name of Parent Bone for hook (if applicable), also recalculates and clears offset"); + RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Modifier_dependency_update"); prop= RNA_def_property(srna, "vertex_group", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "name"); From df61b5f9fd2d92777a9bd00cb7f5f94b130e8c42 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Fri, 21 Aug 2009 11:04:33 +0000 Subject: [PATCH 39/73] 2.5 - 2 Bugfixes * Alt-S in Object Mode would crash. Was caused by modal-keymaps for Pose Mode not being cleared when not in Pose Mode. Also fixed what appears to have been a copy+paste error for Armature Sketching keymaps. * Active KeyingSet menu in TimeLine header is now properly editable. Was using the wrong type of layout call to do this. --- release/ui/space_time.py | 2 +- source/blender/editors/space_view3d/drawobject.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/release/ui/space_time.py b/release/ui/space_time.py index d1c9f9806f3..17deb4c550f 100644 --- a/release/ui/space_time.py +++ b/release/ui/space_time.py @@ -63,7 +63,7 @@ class TIME_HT_header(bpy.types.Header): layout.itemS() row = layout.row(align=True) - row.itemR(scene, "active_keying_set", text="") + row.item_pointerR(scene, "active_keying_set", scene, "keying_sets", text="") row.itemO("anim.insert_keyframe", text="", icon="ICON_KEY_HLT") row.itemO("anim.delete_keyframe", text="", icon="ICON_KEY_DEHLT") diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 55565c83f5e..9fc9bf94cd7 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -5023,6 +5023,9 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) /* patch? children objects with a timeoffs change the parents. How to solve! */ /* if( ((int)ob->ctime) != F_(scene->r.cfra)) where_is_object(scene, ob); */ + + /* draw paths... */ + // TODO... /* multiply view with object matrix */ wmMultMatrix(ob->obmat); From d9283fc0cc9efc6b7aac8a5fc44c4790bdfba3c7 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Fri, 21 Aug 2009 11:22:38 +0000 Subject: [PATCH 40/73] Ack... committed wrong file before (fortunately it was just a harmless comment added) --- source/blender/editors/space_view3d/space_view3d.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 8b719dd2d80..3dd65a6f796 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -280,7 +280,7 @@ static void view3d_modal_keymaps(wmWindowManager *wm, ARegion *ar, int stype) /* copy last mode, then we can re-init the region maps */ rv3d->lastmode= stype; - + keymap= WM_keymap_listbase(wm, "Object Mode", 0, 0); if(ELEM(stype, 0, NS_MODE_OBJECT)) WM_event_add_keymap_handler(&ar->handlers, keymap); @@ -304,6 +304,12 @@ static void view3d_modal_keymaps(wmWindowManager *wm, ARegion *ar, int stype) WM_event_add_keymap_handler(&ar->handlers, keymap); else WM_event_remove_keymap_handler(&ar->handlers, keymap); + + keymap= WM_keymap_listbase(wm, "Pose", 0, 0); + if(stype==NS_MODE_POSE) + WM_event_add_keymap_handler(&ar->handlers, keymap); + else + WM_event_remove_keymap_handler(&ar->handlers, keymap); keymap= WM_keymap_listbase(wm, "Metaball", 0, 0); if(stype==NS_EDITMODE_MBALL) @@ -319,7 +325,7 @@ static void view3d_modal_keymaps(wmWindowManager *wm, ARegion *ar, int stype) /* armature sketching needs to take over mouse */ keymap= WM_keymap_listbase(wm, "Armature_Sketch", 0, 0); - if(stype==NS_EDITMODE_TEXT) + if(stype==NS_EDITMODE_ARMATURE) WM_event_add_keymap_handler_priority(&ar->handlers, keymap, 10); else WM_event_remove_keymap_handler(&ar->handlers, keymap); From 27797a45ee6cbc987350269e6827197f47daf036 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Fri, 21 Aug 2009 11:52:20 +0000 Subject: [PATCH 41/73] 2.5: * Deleted Help scripts, there are now operators in space_info.py. * Some code cleanup. --- release/scripts/help_getting_started.py | 50 ------------------------- release/scripts/help_manual.py | 48 ------------------------ release/scripts/help_release_notes.py | 47 ----------------------- release/scripts/help_tutorials.py | 47 ----------------------- release/scripts/help_web_blender.py | 48 ------------------------ release/scripts/help_web_devcomm.py | 47 ----------------------- release/scripts/help_web_eshop.py | 47 ----------------------- release/scripts/help_web_usercomm.py | 47 ----------------------- release/ui/space_filebrowser.py | 5 +-- release/ui/space_info.py | 20 +++++----- 10 files changed, 12 insertions(+), 394 deletions(-) delete mode 100644 release/scripts/help_getting_started.py delete mode 100644 release/scripts/help_manual.py delete mode 100644 release/scripts/help_release_notes.py delete mode 100644 release/scripts/help_tutorials.py delete mode 100644 release/scripts/help_web_blender.py delete mode 100644 release/scripts/help_web_devcomm.py delete mode 100644 release/scripts/help_web_eshop.py delete mode 100644 release/scripts/help_web_usercomm.py diff --git a/release/scripts/help_getting_started.py b/release/scripts/help_getting_started.py deleted file mode 100644 index 77dda2cf88f..00000000000 --- a/release/scripts/help_getting_started.py +++ /dev/null @@ -1,50 +0,0 @@ -#!BPY -""" -Name: 'Getting Started' -Blender: 248 -Group: 'Help' -Tooltip: 'Help for new users' -""" - -__author__ = "Matt Ebb" -__url__ = ("blender", "blenderartists.org") -__version__ = "1.0.1" -__bpydoc__ = """\ -This script opens the user's default web browser at www.blender.org's -"Getting Started" page. -""" - -# $Id$ -# -# -------------------------------------------------------------------------- -# Getting Started Help Menu Item -# -------------------------------------------------------------------------- -# ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# ***** END GPL LICENCE BLOCK ***** -# -------------------------------------------------------------------------- - -import Blender -try: import webbrowser -except: webbrowser = None - -if webbrowser: - webbrowser.open('http://www.blender.org/education-help/tutorials/getting-started/') -else: - Blender.Draw.PupMenu("Error%t|This script requires a full python installation") - - diff --git a/release/scripts/help_manual.py b/release/scripts/help_manual.py deleted file mode 100644 index 27900040eb4..00000000000 --- a/release/scripts/help_manual.py +++ /dev/null @@ -1,48 +0,0 @@ -#!BPY -""" -Name: 'Manual' -Blender: 248 -Group: 'Help' -Tooltip: 'The Blender Wiki manual' -""" - -__author__ = "Matt Ebb" -__url__ = ("blender", "blenderartists.org") -__version__ = "1.0.1" -__bpydoc__ = """\ -This script opens the user's default web browser at www.blender.org's -"Manual" page. -""" - -# -------------------------------------------------------------------------- -# Manual Help Menu Item -# -------------------------------------------------------------------------- -# ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# ***** END GPL LICENCE BLOCK ***** -# -------------------------------------------------------------------------- - -import Blender -try: import webbrowser -except: webbrowser = None - -if webbrowser: - webbrowser.open('http://wiki.blender.org/index.php/Manual') -else: - Blender.Draw.PupMenu("Error%t|This script requires a full python installation") - - diff --git a/release/scripts/help_release_notes.py b/release/scripts/help_release_notes.py deleted file mode 100644 index 870f2391487..00000000000 --- a/release/scripts/help_release_notes.py +++ /dev/null @@ -1,47 +0,0 @@ -#!BPY -""" -Name: 'Release Logs' -Blender: 248 -Group: 'Help' -Tooltip: 'Information about the changes in this version of Blender' -""" - -__author__ = "Matt Ebb" -__url__ = ("blender", "blenderartists.org") -__version__ = "1.0.1" -__bpydoc__ = """\ -This script opens the user's default web browser at www.blender.org's -"Release Logs" page. -""" - -# -------------------------------------------------------------------------- -# Release Notes Help Menu Item -# -------------------------------------------------------------------------- -# ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# ***** END GPL LICENCE BLOCK ***** -# -------------------------------------------------------------------------- - -import Blender -try: import webbrowser -except: webbrowser = None - -if webbrowser: - webbrowser.open('http://www.blender.org/development/release-logs/') -else: - Blender.Draw.PupMenu("Error%t|This script requires a full python installation") - diff --git a/release/scripts/help_tutorials.py b/release/scripts/help_tutorials.py deleted file mode 100644 index e0cef1abdbf..00000000000 --- a/release/scripts/help_tutorials.py +++ /dev/null @@ -1,47 +0,0 @@ -#!BPY - -""" -Name: 'Tutorials' -Blender: 248 -Group: 'Help' -Tooltip: 'Tutorials for learning to use Blender' -""" - -__author__ = "Matt Ebb" -__url__ = ("blender", "blenderartists.org") -__version__ = "1.0.1" -__bpydoc__ = """\ -This script opens the user's default web browser at www.blender.org's -"Tutorials" page. -""" - -# -------------------------------------------------------------------------- -# Tutorials Help Menu Item -# -------------------------------------------------------------------------- -# ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# ***** END GPL LICENCE BLOCK ***** -# -------------------------------------------------------------------------- - -import Blender -try: import webbrowser -except: webbrowser = None - -if webbrowser: - webbrowser.open('http://www.blender.org/education-help/tutorials/') -else: - Blender.Draw.PupMenu("Error%t|This script requires a full python installation") diff --git a/release/scripts/help_web_blender.py b/release/scripts/help_web_blender.py deleted file mode 100644 index 2a0f90844ae..00000000000 --- a/release/scripts/help_web_blender.py +++ /dev/null @@ -1,48 +0,0 @@ -#!BPY - -""" -Name: 'Blender Website' -Blender: 248 -Group: 'HelpWebsites' -Tooltip: 'The official Blender website' -""" - -__author__ = "Matt Ebb" -__url__ = ("blender", "blenderartists.org") -__version__ = "1.0.1" -__bpydoc__ = """\ -This script opens the user's default web browser at Blender's main site, -www.blender.org. -""" - - -# -------------------------------------------------------------------------- -# Blender Website Help Menu -> Websites Item -# -------------------------------------------------------------------------- -# ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# ***** END GPL LICENCE BLOCK ***** -# -------------------------------------------------------------------------- - -import Blender -try: import webbrowser -except: webbrowser = None - -if webbrowser: - webbrowser.open('http://www.blender.org/') -else: - Blender.Draw.PupMenu("Error%t|This script requires a full python installation") diff --git a/release/scripts/help_web_devcomm.py b/release/scripts/help_web_devcomm.py deleted file mode 100644 index 46fa2487a89..00000000000 --- a/release/scripts/help_web_devcomm.py +++ /dev/null @@ -1,47 +0,0 @@ -#!BPY - -""" -Name: 'Developer Community' -Blender: 248 -Group: 'HelpWebsites' -Tooltip: 'Get involved with Blender development' -""" - -__author__ = "Matt Ebb" -__url__ = ("blender", "blenderartists.org") -__version__ = "1.0.1" -__bpydoc__ = """\ -This script opens the user's default web browser at www.blender.org's -"Get Involved" page. -""" - -# -------------------------------------------------------------------------- -# Blender Website Help Menu -> Websites Item -# -------------------------------------------------------------------------- -# ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# ***** END GPL LICENCE BLOCK ***** -# -------------------------------------------------------------------------- - -import Blender -try: import webbrowser -except: webbrowser = None - -if webbrowser: - webbrowser.open('http://www.blender.org/community/get-involved/') -else: - Blender.Draw.PupMenu("Error%t|This script requires a full python installation") diff --git a/release/scripts/help_web_eshop.py b/release/scripts/help_web_eshop.py deleted file mode 100644 index e40795b3a0d..00000000000 --- a/release/scripts/help_web_eshop.py +++ /dev/null @@ -1,47 +0,0 @@ -#!BPY - -""" -Name: 'Blender E-Shop' -Blender: 248 -Group: 'HelpWebsites' -Tooltip: 'Buy official Blender resources and merchandise online' -""" - -__author__ = "Matt Ebb" -__url__ = ("blender", "blenderartists.org") -__version__ = "1.0.1" -__bpydoc__ = """\ -This script opens the user's default web browser at www.blender.org's -"E-Shop" section. -""" - -# -------------------------------------------------------------------------- -# Blender Website Help Menu -> Websites Item -# -------------------------------------------------------------------------- -# ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# ***** END GPL LICENCE BLOCK ***** -# -------------------------------------------------------------------------- - -import Blender -try: import webbrowser -except: webbrowser = None - -if webbrowser: - webbrowser.open('http://www.blender3d.org/e-shop') -else: - Blender.Draw.PupMenu("Error%t|This script requires a full python installation") diff --git a/release/scripts/help_web_usercomm.py b/release/scripts/help_web_usercomm.py deleted file mode 100644 index dda5e42f34e..00000000000 --- a/release/scripts/help_web_usercomm.py +++ /dev/null @@ -1,47 +0,0 @@ -#!BPY - -""" -Name: 'User Community' -Blender: 248 -Group: 'HelpWebsites' -Tooltip: 'Get involved with other Blender users' -""" - -__author__ = "Matt Ebb" -__url__ = ("blender", "blenderartists.org") -__version__ = "1.0.1" -__bpydoc__ = """\ -This script opens the user's default web browser at www.blender.org's -"User Community" page. -""" - -# -------------------------------------------------------------------------- -# Blender Website Help Menu -> Websites Item -# -------------------------------------------------------------------------- -# ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# ***** END GPL LICENCE BLOCK ***** -# -------------------------------------------------------------------------- - -import Blender -try: import webbrowser -except: webbrowser = None - -if webbrowser: - webbrowser.open('http://www.blender.org/community/user-community/') -else: - Blender.Draw.PupMenu("Error%t|This script requires a full python installation") diff --git a/release/ui/space_filebrowser.py b/release/ui/space_filebrowser.py index 51a8f3f78e8..a37b89e8db4 100644 --- a/release/ui/space_filebrowser.py +++ b/release/ui/space_filebrowser.py @@ -1,15 +1,15 @@ import bpy - class FILEBROWSER_HT_header(bpy.types.Header): __space_type__ = "FILE_BROWSER" def draw(self, context): - st = context.space_data layout = self.layout + st = context.space_data params = st.params + layout.template_header(menus=False) row = layout.row(align=True) @@ -39,5 +39,4 @@ class FILEBROWSER_HT_header(bpy.types.Header): row.active = params.do_filter - bpy.types.register(FILEBROWSER_HT_header) diff --git a/release/ui/space_info.py b/release/ui/space_info.py index 1a3f9a321ac..83eb2c75a2c 100644 --- a/release/ui/space_info.py +++ b/release/ui/space_info.py @@ -115,22 +115,22 @@ class INFO_MT_add(bpy.types.Menu): layout.operator_context = "EXEC_SCREEN" - layout.item_menu_enumO( "OBJECT_OT_mesh_add", "type", text="Mesh", icon='ICON_OUTLINER_OB_MESH') - layout.item_menu_enumO( "OBJECT_OT_curve_add", "type", text="Curve", icon='ICON_OUTLINER_OB_CURVE') - layout.item_menu_enumO( "OBJECT_OT_surface_add", "type", text="Surface", icon='ICON_OUTLINER_OB_SURFACE') - layout.item_menu_enumO( "OBJECT_OT_metaball_add", "type", 'META', icon='ICON_OUTLINER_OB_META') - layout.itemO("OBJECT_OT_text_add", text="Text", icon='ICON_OUTLINER_OB_FONT') + layout.item_menu_enumO( "object.mesh_add", "type", text="Mesh", icon='ICON_OUTLINER_OB_MESH') + layout.item_menu_enumO( "object.curve_add", "type", text="Curve", icon='ICON_OUTLINER_OB_CURVE') + layout.item_menu_enumO( "object.surface_add", "type", text="Surface", icon='ICON_OUTLINER_OB_SURFACE') + layout.item_menu_enumO( "object.metaball_add", "type", 'META', icon='ICON_OUTLINER_OB_META') + layout.itemO("object.text_add", text="Text", icon='ICON_OUTLINER_OB_FONT') layout.itemS() - layout.itemO("OBJECT_OT_armature_add", text="Armature", icon='ICON_OUTLINER_OB_ARMATURE') - layout.item_enumO("OBJECT_OT_object_add", "type", 'LATTICE', icon='ICON_OUTLINER_OB_LATTICE') - layout.item_enumO("OBJECT_OT_object_add", "type", 'EMPTY', icon='ICON_OUTLINER_OB_EMPTY') + layout.itemO("object.armature_add", text="Armature", icon='ICON_OUTLINER_OB_ARMATURE') + layout.item_enumO("object.object_add", "type", 'LATTICE', icon='ICON_OUTLINER_OB_LATTICE') + layout.item_enumO("object.object_add", "type", 'EMPTY', icon='ICON_OUTLINER_OB_EMPTY') layout.itemS() - layout.item_enumO("OBJECT_OT_object_add", "type", 'CAMERA', icon='ICON_OUTLINER_OB_CAMERA') - layout.item_enumO("OBJECT_OT_object_add", "type", 'LAMP', icon='ICON_OUTLINER_OB_LAMP') + layout.item_enumO("object.object_add", "type", 'CAMERA', icon='ICON_OUTLINER_OB_CAMERA') + layout.item_enumO("object.object_add", "type", 'LAMP', icon='ICON_OUTLINER_OB_LAMP') class INFO_MT_game(bpy.types.Menu): __space_type__ = "INFO" From 93dd95b6c2c9ed69916060aa438c13ba1ee6431f Mon Sep 17 00:00:00 2001 From: Jens Ole Wund Date: Fri, 21 Aug 2009 12:49:21 +0000 Subject: [PATCH 42/73] bug fix #18982 non mesh objects missing initializers --- source/blender/blenkernel/intern/softbody.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 25eb999cc4f..01fa3b544ff 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -867,7 +867,8 @@ static void renew_softbody(Object *ob, int totpoint, int totspring) bp->frozen = 1.0f; bp->colball = 0.0f; bp->flag = 0; - + bp->springweight = 1.0f; + bp->mass = sb->nodemass; } } } From 1c614f6cf63fb65622b855123d8db76898d3c9ca Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 21 Aug 2009 12:57:47 +0000 Subject: [PATCH 43/73] 2.5: layout.itemO now returns OperatorProperties to be filled in, when passing properties=True as argument. Other changes: * uiItemR, uiItemFullR, uiItemFullO now accept a flag argument rather than multiple different "boolean" arguments, but still exposed as booleans to python. * Fix RNA to support setting PROP_RNAPTR for return values. --- release/ui/space_view3d.py | 20 ++++-- .../blender/editors/animation/fmodifier_ui.c | 52 +++++++------- source/blender/editors/include/UI_interface.h | 15 +++-- .../editors/interface/interface_layout.c | 49 +++++++++----- .../editors/interface/interface_templates.c | 16 ++--- .../editors/interface/interface_utils.c | 2 +- source/blender/editors/object/object_edit.c | 20 ++---- .../editors/space_action/action_header.c | 6 +- .../blender/editors/space_file/file_panels.c | 2 +- .../editors/space_graph/graph_header.c | 6 +- .../blender/editors/space_nla/nla_buttons.c | 50 +++++++------- source/blender/editors/space_nla/nla_header.c | 4 +- .../editors/space_view3d/view3d_header.c | 67 ++----------------- .../editors/space_view3d/view3d_toolbar.c | 2 +- source/blender/makesrna/intern/makesrna.c | 12 +++- source/blender/makesrna/intern/rna_ui_api.c | 29 ++++++-- 16 files changed, 170 insertions(+), 182 deletions(-) diff --git a/release/ui/space_view3d.py b/release/ui/space_view3d.py index 44b1c82ff46..0b08b213cd4 100644 --- a/release/ui/space_view3d.py +++ b/release/ui/space_view3d.py @@ -157,7 +157,13 @@ class VIEW3D_MT_select_POSE(bpy.types.Menu): layout.itemS() - layout.view3d_select_posemenu() + props = layout.itemO("pose.select_hierarchy", properties=True, text="Extend Parent") + props.extend = True + props.direction = 'PARENT' + + props = layout.itemO("pose.select_hierarchy", properties=True, text="Extend Child") + props.extend = True + props.direction = 'CHILD' class VIEW3D_MT_select_PARTICLE(bpy.types.Menu): __space_type__ = "VIEW_3D" @@ -327,12 +333,18 @@ class VIEW3D_MT_select_EDIT_ARMATURE(bpy.types.Menu): layout.itemS() - layout.item_enumO("armature.select_hierarchy", "direction", 'PARENT') - layout.item_enumO("armature.select_hierarchy", "direction", 'CHILD') + layout.item_enumO("armature.select_hierarchy", "direction", 'PARENT', text="Parent") + layout.item_enumO("armature.select_hierarchy", "direction", 'CHILD', text="Child") layout.itemS() - layout.view3d_select_armaturemenu() + props = layout.itemO("armature.select_hierarchy", properties=True, text="Extend Parent") + props.extend = True + props.direction = 'PARENT' + + props = layout.itemO("armature.select_hierarchy", properties=True, text="Extend Child") + props.extend = True + props.direction = 'CHILD' class VIEW3D_MT_select_FACE(bpy.types.Menu):# XXX no matching enum __space_type__ = "VIEW_3D" diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c index 7a618f4d222..4aff26105f3 100644 --- a/source/blender/editors/animation/fmodifier_ui.c +++ b/source/blender/editors/animation/fmodifier_ui.c @@ -258,14 +258,14 @@ static void draw_modifier__fn_generator(uiLayout *layout, ID *id, FModifier *fcm /* add the settings */ col= uiLayoutColumn(layout, 1); - uiItemR(col, "", 0, &ptr, "type", 0, 0, 0); - uiItemR(col, NULL, 0, &ptr, "additive", 0, 0, 1); + uiItemR(col, "", 0, &ptr, "type", 0); + uiItemR(col, NULL, 0, &ptr, "additive", UI_ITEM_R_TOGGLE); col= uiLayoutColumn(layout, 0); // no grouping for now - uiItemR(col, NULL, 0, &ptr, "amplitude", 0, 0, 0); - uiItemR(col, NULL, 0, &ptr, "phase_multiplier", 0, 0, 0); - uiItemR(col, NULL, 0, &ptr, "phase_offset", 0, 0, 0); - uiItemR(col, NULL, 0, &ptr, "value_offset", 0, 0, 0); + uiItemR(col, NULL, 0, &ptr, "amplitude", 0); + uiItemR(col, NULL, 0, &ptr, "phase_multiplier", 0); + uiItemR(col, NULL, 0, &ptr, "phase_offset", 0); + uiItemR(col, NULL, 0, &ptr, "value_offset", 0); } /* --------------- */ @@ -287,14 +287,14 @@ static void draw_modifier__cycles(uiLayout *layout, ID *id, FModifier *fcm, shor /* before range */ col= uiLayoutColumn(split, 1); uiItemL(col, "Before:", 0); - uiItemR(col, "", 0, &ptr, "before_mode", 0, 0, 0); - uiItemR(col, NULL, 0, &ptr, "before_cycles", 0, 0, 0); + uiItemR(col, "", 0, &ptr, "before_mode", 0); + uiItemR(col, NULL, 0, &ptr, "before_cycles", 0); /* after range */ col= uiLayoutColumn(split, 1); uiItemL(col, "After:", 0); - uiItemR(col, "", 0, &ptr, "after_mode", 0, 0, 0); - uiItemR(col, NULL, 0, &ptr, "after_cycles", 0, 0, 0); + uiItemR(col, "", 0, &ptr, "after_mode", 0); + uiItemR(col, NULL, 0, &ptr, "after_cycles", 0); } /* --------------- */ @@ -309,20 +309,20 @@ static void draw_modifier__noise(uiLayout *layout, ID *id, FModifier *fcm, short RNA_pointer_create(id, &RNA_FModifierNoise, fcm, &ptr); /* blending mode */ - uiItemR(layout, NULL, 0, &ptr, "modification", 0, 0, 0); + uiItemR(layout, NULL, 0, &ptr, "modification", 0); /* split into 2 columns */ split= uiLayoutSplit(layout, 0.5f); /* col 1 */ col= uiLayoutColumn(split, 0); - uiItemR(col, NULL, 0, &ptr, "size", 0, 0, 0); - uiItemR(col, NULL, 0, &ptr, "strength", 0, 0, 0); + uiItemR(col, NULL, 0, &ptr, "size", 0); + uiItemR(col, NULL, 0, &ptr, "strength", 0); /* col 2 */ col= uiLayoutColumn(split, 0); - uiItemR(col, NULL, 0, &ptr, "phase", 0, 0, 0); - uiItemR(col, NULL, 0, &ptr, "depth", 0, 0, 0); + uiItemR(col, NULL, 0, &ptr, "phase", 0); + uiItemR(col, NULL, 0, &ptr, "depth", 0); } /* --------------- */ @@ -503,11 +503,11 @@ static void draw_modifier__envelope(uiLayout *layout, ID *id, FModifier *fcm, sh /* general settings */ col= uiLayoutColumn(layout, 1); uiItemL(col, "Envelope:", 0); - uiItemR(col, NULL, 0, &ptr, "reference_value", 0, 0, 0); + uiItemR(col, NULL, 0, &ptr, "reference_value", 0); row= uiLayoutRow(col, 1); - uiItemR(row, "Min", 0, &ptr, "default_minimum", 0, 0, 0); - uiItemR(row, "Max", 0, &ptr, "default_maximum", 0, 0, 0); + uiItemR(row, "Min", 0, &ptr, "default_minimum", 0); + uiItemR(row, "Max", 0, &ptr, "default_maximum", 0); /* control points header */ // TODO: move this control-point control stuff to using the new special widgets for lists @@ -559,13 +559,13 @@ static void draw_modifier__limits(uiLayout *layout, ID *id, FModifier *fcm, shor /* x-minimum */ col= uiLayoutColumn(split, 1); - uiItemR(col, NULL, 0, &ptr, "use_minimum_x", 0, 0, 0); - uiItemR(col, NULL, 0, &ptr, "minimum_x", 0, 0, 0); + uiItemR(col, NULL, 0, &ptr, "use_minimum_x", 0); + uiItemR(col, NULL, 0, &ptr, "minimum_x", 0); /* y-minimum*/ col= uiLayoutColumn(split, 1); - uiItemR(col, NULL, 0, &ptr, "use_minimum_y", 0, 0, 0); - uiItemR(col, NULL, 0, &ptr, "minimum_y", 0, 0, 0); + uiItemR(col, NULL, 0, &ptr, "use_minimum_y", 0); + uiItemR(col, NULL, 0, &ptr, "minimum_y", 0); } /* row 2: minimum */ @@ -577,13 +577,13 @@ static void draw_modifier__limits(uiLayout *layout, ID *id, FModifier *fcm, shor /* x-minimum */ col= uiLayoutColumn(split, 1); - uiItemR(col, NULL, 0, &ptr, "use_maximum_x", 0, 0, 0); - uiItemR(col, NULL, 0, &ptr, "maximum_x", 0, 0, 0); + uiItemR(col, NULL, 0, &ptr, "use_maximum_x", 0); + uiItemR(col, NULL, 0, &ptr, "maximum_x", 0); /* y-minimum*/ col= uiLayoutColumn(split, 1); - uiItemR(col, NULL, 0, &ptr, "use_maximum_y", 0, 0, 0); - uiItemR(col, NULL, 0, &ptr, "maximum_y", 0, 0, 0); + uiItemR(col, NULL, 0, &ptr, "use_maximum_y", 0); + uiItemR(col, NULL, 0, &ptr, "maximum_y", 0); } } diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 5bf59b06bc4..5f93743493a 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -585,16 +585,21 @@ void UI_exit(void); #define UI_LAYOUT_ALIGN_CENTER 2 #define UI_LAYOUT_ALIGN_RIGHT 3 +#define UI_ITEM_O_RETURN_PROPS 1 +#define UI_ITEM_R_EXPAND 2 +#define UI_ITEM_R_SLIDER 4 +#define UI_ITEM_R_TOGGLE 8 + uiLayout *uiBlockLayout(uiBlock *block, int dir, int type, int x, int y, int size, int em, struct uiStyle *style); void uiBlockSetCurLayout(uiBlock *block, uiLayout *layout); void uiBlockLayoutResolve(const struct bContext *C, uiBlock *block, int *x, int *y); uiBlock *uiLayoutGetBlock(uiLayout *layout); -void uiLayoutSetOperatorContext(uiLayout *layout, int opcontext); void uiLayoutSetFunc(uiLayout *layout, uiMenuHandleFunc handlefunc, void *argv); void uiLayoutSetContextPointer(uiLayout *layout, char *name, struct PointerRNA *ptr); +void uiLayoutSetOperatorContext(uiLayout *layout, int opcontext); void uiLayoutSetActive(uiLayout *layout, int active); void uiLayoutSetEnabled(uiLayout *layout, int enabled); void uiLayoutSetRedAlert(uiLayout *layout, int redalert); @@ -641,8 +646,6 @@ void uiTemplateRunningJobs(uiLayout *layout, struct bContext *C); void uiTemplateOperatorSearch(uiLayout *layout); void uiTemplateHeader3D(uiLayout *layout, struct bContext *C); void uiTemplate_view3d_select_metaballmenu(uiLayout *layout, struct bContext *C); -void uiTemplate_view3d_select_armaturemenu(uiLayout *layout, struct bContext *C); -void uiTemplate_view3d_select_posemenu(uiLayout *layout, struct bContext *C); void uiTemplate_view3d_select_faceselmenu(uiLayout *layout, struct bContext *C); void uiTemplateTextureImage(uiLayout *layout, struct bContext *C, struct Tex *tex); @@ -664,10 +667,10 @@ void uiItemBooleanO(uiLayout *layout, char *name, int icon, char *opname, char * void uiItemIntO(uiLayout *layout, char *name, int icon, char *opname, char *propname, int value); void uiItemFloatO(uiLayout *layout, char *name, int icon, char *opname, char *propname, float value); void uiItemStringO(uiLayout *layout, char *name, int icon, char *opname, char *propname, char *value); -void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, struct IDProperty *properties, int context); +PointerRNA uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, struct IDProperty *properties, int context, int flag); -void uiItemR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname, int expand, int slider, int toggle); -void uiItemFullR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, int value, int expand, int slider, int toggle); +void uiItemR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname, int flag); +void uiItemFullR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, int value, int flag); void uiItemEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname, int value); void uiItemEnumR_string(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname, char *value); void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, char *propname); diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index ab27f8fb0f6..8676fe62a3a 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -535,7 +535,7 @@ static void ui_item_disabled(uiLayout *layout, char *name) } /* operator items */ -void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, IDProperty *properties, int context) +PointerRNA uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, IDProperty *properties, int context, int flag) { uiBlock *block= layout->root->block; wmOperatorType *ot= WM_operatortype_find(idname, 0); @@ -544,7 +544,7 @@ void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, IDPropert if(!ot) { ui_item_disabled(layout, idname); - return; + return PointerRNA_NULL; } if(!name) @@ -565,10 +565,21 @@ void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, IDPropert but= uiDefButO(block, BUT, ot->idname, context, (char*)name, 0, 0, w, UI_UNIT_Y, NULL); /* assign properties */ - if(properties) { + if(properties || (flag & UI_ITEM_O_RETURN_PROPS)) { PointerRNA *opptr= uiButGetOperatorPtrRNA(but); - opptr->data= properties; + + if(properties) { + opptr->data= properties; + } + else { + IDPropertyTemplate val = {0}; + opptr->data= IDP_New(IDP_GROUP, val, "wmOperatorProperties"); + } + + return *opptr; } + + return PointerRNA_NULL; } static char *ui_menu_enumpropname(uiLayout *layout, char *opname, char *propname, int retval) @@ -611,7 +622,7 @@ void uiItemEnumO(uiLayout *layout, char *name, int icon, char *opname, char *pro if(!name) name= ui_menu_enumpropname(layout, opname, propname, value); - uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext); + uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext, 0); } void uiItemsEnumO(uiLayout *layout, char *opname, char *propname) @@ -699,7 +710,7 @@ void uiItemEnumO_string(uiLayout *layout, char *name, int icon, char *opname, ch if(!name) name= ui_menu_enumpropname(layout, opname, propname, value); - uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext); + uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext, 0); } void uiItemBooleanO(uiLayout *layout, char *name, int icon, char *opname, char *propname, int value) @@ -709,7 +720,7 @@ void uiItemBooleanO(uiLayout *layout, char *name, int icon, char *opname, char * WM_operator_properties_create(&ptr, opname); RNA_boolean_set(&ptr, propname, value); - uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext); + uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext, 0); } void uiItemIntO(uiLayout *layout, char *name, int icon, char *opname, char *propname, int value) @@ -719,7 +730,7 @@ void uiItemIntO(uiLayout *layout, char *name, int icon, char *opname, char *prop WM_operator_properties_create(&ptr, opname); RNA_int_set(&ptr, propname, value); - uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext); + uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext, 0); } void uiItemFloatO(uiLayout *layout, char *name, int icon, char *opname, char *propname, float value) @@ -729,7 +740,7 @@ void uiItemFloatO(uiLayout *layout, char *name, int icon, char *opname, char *pr WM_operator_properties_create(&ptr, opname); RNA_float_set(&ptr, propname, value); - uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext); + uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext, 0); } void uiItemStringO(uiLayout *layout, char *name, int icon, char *opname, char *propname, char *value) @@ -739,12 +750,12 @@ void uiItemStringO(uiLayout *layout, char *name, int icon, char *opname, char *p WM_operator_properties_create(&ptr, opname); RNA_string_set(&ptr, propname, value); - uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext); + uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext, 0); } void uiItemO(uiLayout *layout, char *name, int icon, char *opname) { - uiItemFullO(layout, name, icon, opname, NULL, layout->root->opcontext); + uiItemFullO(layout, name, icon, opname, NULL, layout->root->opcontext, 0); } /* RNA property items */ @@ -793,13 +804,13 @@ static void ui_item_rna_size(uiLayout *layout, char *name, int icon, PropertyRNA *r_h= h; } -void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, PropertyRNA *prop, int index, int value, int expand, int slider, int toggle) +void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, PropertyRNA *prop, int index, int value, int flag) { uiBlock *block= layout->root->block; uiBut *but; PropertyType type; char namestr[UI_MAX_NAME_STR]; - int len, w, h; + int len, w, h, slider, toggle, expand; if(!ptr->data || !prop) return; @@ -830,6 +841,10 @@ void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, Proper icon= (RNA_property_enum_get(ptr, prop) == value)? ICON_CHECKBOX_HLT: ICON_CHECKBOX_DEHLT; } + slider= (flag & UI_ITEM_R_SLIDER); + toggle= (flag & UI_ITEM_R_TOGGLE); + expand= (flag & UI_ITEM_R_EXPAND); + /* get size */ ui_item_rna_size(layout, name, icon, prop, index, &w, &h); @@ -867,7 +882,7 @@ void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, Proper } } -void uiItemR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, char *propname, int expand, int slider, int toggle) +void uiItemR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, char *propname, int flag) { PropertyRNA *prop; @@ -882,7 +897,7 @@ void uiItemR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, char *prop return; } - uiItemFullR(layout, name, icon, ptr, prop, RNA_NO_INDEX, 0, expand, slider, toggle); + uiItemFullR(layout, name, icon, ptr, prop, RNA_NO_INDEX, 0, flag); } void uiItemEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname, int value) @@ -900,7 +915,7 @@ void uiItemEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, return; } - uiItemFullR(layout, name, icon, ptr, prop, RNA_ENUM_VALUE, value, 0, 0, 0); + uiItemFullR(layout, name, icon, ptr, prop, RNA_ENUM_VALUE, value, 0); } void uiItemEnumR_string(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname, char *value) @@ -931,7 +946,7 @@ void uiItemEnumR_string(uiLayout *layout, char *name, int icon, struct PointerRN for(a=0; item[a].identifier; a++) { if(item[a].value == ivalue) { - uiItemFullR(layout, (char*)item[a].name, item[a].icon, ptr, prop, RNA_ENUM_VALUE, ivalue, 0, 0, 0); + uiItemFullR(layout, (char*)item[a].name, item[a].icon, ptr, prop, RNA_ENUM_VALUE, ivalue, 0); break; } } diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index e7c99f10a66..56badedaded 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -428,15 +428,15 @@ static uiLayout *draw_modifier(uiLayout *layout, Object *ob, ModifierData *md, i else { /* real modifier */ uiBlockBeginAlign(block); - uiItemR(row, "", 0, &ptr, "name", 0, 0, 0); + uiItemR(row, "", 0, &ptr, "name", 0); /* Softbody not allowed in this situation, enforce! */ if(((md->type!=eModifierType_Softbody && md->type!=eModifierType_Collision) || !(ob->pd && ob->pd->deflect)) && (md->type!=eModifierType_Surface)) { - uiItemR(row, "", ICON_SCENE, &ptr, "render", 0, 0, 0); - uiItemR(row, "", ICON_RESTRICT_VIEW_OFF, &ptr, "realtime", 0, 0, 0); + uiItemR(row, "", ICON_SCENE, &ptr, "render", 0); + uiItemR(row, "", ICON_RESTRICT_VIEW_OFF, &ptr, "realtime", 0); if(mti->flags & eModifierTypeFlag_SupportsEditmode) - uiItemR(row, "", ICON_EDITMODE_HLT, &ptr, "editmode", 0, 0, 0); + uiItemR(row, "", ICON_EDITMODE_HLT, &ptr, "editmode", 0); } @@ -1224,9 +1224,9 @@ void uiTemplateTriColorSet(uiLayout *layout, PointerRNA *ptr, char *propname) /* nselected, selected, active color swatches */ csPtr= RNA_property_pointer_get(ptr, prop); - uiItemR(row, "", 0, &csPtr, "normal", 0, 0, 0); - uiItemR(row, "", 0, &csPtr, "selected", 0, 0, 0); - uiItemR(row, "", 0, &csPtr, "active", 0, 0, 0); + uiItemR(row, "", 0, &csPtr, "normal", 0); + uiItemR(row, "", 0, &csPtr, "selected", 0); + uiItemR(row, "", 0, &csPtr, "active", 0); } /********************* Layer Buttons Template ************************/ @@ -1278,7 +1278,7 @@ void uiTemplateLayers(uiLayout *layout, PointerRNA *ptr, char *propname) /* add layers as toggle buts */ for (col= 0; (col < cols) && (layer < layers); col++, layer++) { int icon=0; // XXX - add some way of setting this... - uiItemFullR(uRow, "", icon, ptr, prop, layer, 0, 0, 0, 1); + uiItemFullR(uRow, "", icon, ptr, prop, layer, 0, UI_ITEM_R_TOGGLE); } } } diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index 4201850f5e4..b5cfbe19466 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -175,7 +175,7 @@ void uiDefAutoButsRNA(const bContext *C, uiLayout *layout, PointerRNA *ptr, int if(strcmp(name, "Axis")==0) { uiDefButR(uiLayoutGetBlock(col), BUT_NORMAL, 0, name, 0, 0, 100, 100, ptr, "axis", -1, 0, 0, -1, -1, NULL); } - else uiItemFullR(col, "", 0, ptr, prop, -1, 0, 0, 0, 0); + else uiItemFullR(col, "", 0, ptr, prop, -1, 0, 0); } RNA_STRUCT_END; } diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index e1b8858937c..47eaf1757ac 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -2759,13 +2759,10 @@ static void proxy_group_objects_menu (bContext *C, wmOperator *op, Object *ob, G if (go->ob) { PointerRNA props_ptr; - /* create operator properties, and assign the relevant pointers to that, - * and add a menu entry which uses these props - */ - WM_operator_properties_create(&props_ptr, op->idname); - RNA_string_set(&props_ptr, "object", go->ob->id.name+2); - RNA_string_set(&props_ptr, "group_object", go->ob->id.name+2); - uiItemFullO(layout, go->ob->id.name+2, 0, op->idname, props_ptr.data, WM_OP_EXEC_REGION_WIN); + /* create operator menu item with relevant properties filled in */ + props_ptr= uiItemFullO(layout, go->ob->id.name+2, 0, op->idname, NULL, WM_OP_EXEC_REGION_WIN, UI_ITEM_O_RETURN_PROPS); + RNA_string_set(&props_ptr, "object", go->ob->id.name+2); + RNA_string_set(&props_ptr, "group_object", go->ob->id.name+2); } } @@ -2793,12 +2790,9 @@ static int make_proxy_invoke (bContext *C, wmOperator *op, wmEvent *evt) uiLayout *layout= uiPupMenuLayout(pup); PointerRNA props_ptr; - /* create operator properties, and assign the relevant pointers to that, - * and add a menu entry which uses these props - */ - WM_operator_properties_create(&props_ptr, op->idname); - RNA_string_set(&props_ptr, "object", ob->id.name+2); - uiItemFullO(layout, op->type->name, 0, op->idname, props_ptr.data, WM_OP_EXEC_REGION_WIN); + /* create operator menu item with relevant properties filled in */ + props_ptr= uiItemFullO(layout, op->type->name, 0, op->idname, props_ptr.data, WM_OP_EXEC_REGION_WIN, UI_ITEM_O_RETURN_PROPS); + RNA_string_set(&props_ptr, "object", ob->id.name+2); /* present the menu and be done... */ uiPupMenuEnd(C, pup); diff --git a/source/blender/editors/space_action/action_header.c b/source/blender/editors/space_action/action_header.c index e4750bd0a37..375136d199e 100644 --- a/source/blender/editors/space_action/action_header.c +++ b/source/blender/editors/space_action/action_header.c @@ -88,9 +88,9 @@ static void act_viewmenu(bContext *C, uiLayout *layout, void *arg_unused) //uiItemS(layout); - uiItemR(layout, NULL, 0, &spaceptr, "show_cframe_indicator", 0, 0, 0); - uiItemR(layout, NULL, 0, &spaceptr, "show_sliders", 0, 0, 0); - uiItemR(layout, NULL, 0, &spaceptr, "automerge_keyframes", 0, 0, 0); + uiItemR(layout, NULL, 0, &spaceptr, "show_cframe_indicator", 0); + uiItemR(layout, NULL, 0, &spaceptr, "show_sliders", 0); + uiItemR(layout, NULL, 0, &spaceptr, "automerge_keyframes", 0); if (sact->flag & SACTION_DRAWTIME) uiItemO(layout, "Show Frames", 0, "ANIM_OT_time_toggle"); diff --git a/source/blender/editors/space_file/file_panels.c b/source/blender/editors/space_file/file_panels.c index 30598d39d58..c48b3529389 100644 --- a/source/blender/editors/space_file/file_panels.c +++ b/source/blender/editors/space_file/file_panels.c @@ -184,7 +184,7 @@ static void file_panel_operator(const bContext *C, Panel *pa) if(strncmp(RNA_property_identifier(prop), "filter", 6) == 0) continue; - uiItemFullR(pa->layout, NULL, 0, op->ptr, prop, -1, 0, 0, 0, 0); + uiItemFullR(pa->layout, NULL, 0, op->ptr, prop, -1, 0, 0); empty= 0; } RNA_STRUCT_END; diff --git a/source/blender/editors/space_graph/graph_header.c b/source/blender/editors/space_graph/graph_header.c index c4654972dcd..fc02cadb475 100644 --- a/source/blender/editors/space_graph/graph_header.c +++ b/source/blender/editors/space_graph/graph_header.c @@ -80,15 +80,15 @@ static void graph_viewmenu(bContext *C, uiLayout *layout, void *arg_unused) uiItemS(layout); - uiItemR(layout, NULL, 0, &spaceptr, "show_cframe_indicator", 0, 0, 0); + uiItemR(layout, NULL, 0, &spaceptr, "show_cframe_indicator", 0); if (sipo->flag & SIPO_NOHANDLES) uiItemO(layout, "Show Handles", ICON_CHECKBOX_DEHLT, "GRAPH_OT_handles_view_toggle"); else uiItemO(layout, "Show Handles", ICON_CHECKBOX_HLT, "GRAPH_OT_handles_view_toggle"); - uiItemR(layout, NULL, 0, &spaceptr, "only_selected_curves_handles", 0, 0, 0); - uiItemR(layout, NULL, 0, &spaceptr, "automerge_keyframes", 0, 0, 0); + uiItemR(layout, NULL, 0, &spaceptr, "only_selected_curves_handles", 0); + uiItemR(layout, NULL, 0, &spaceptr, "automerge_keyframes", 0); if (sipo->flag & SIPO_DRAWTIME) uiItemO(layout, "Show Frames", 0, "ANIM_OT_time_toggle"); diff --git a/source/blender/editors/space_nla/nla_buttons.c b/source/blender/editors/space_nla/nla_buttons.c index 7184737e0ba..2ffca5185f2 100644 --- a/source/blender/editors/space_nla/nla_buttons.c +++ b/source/blender/editors/space_nla/nla_buttons.c @@ -210,19 +210,19 @@ static void nla_panel_animdata (const bContext *C, Panel *pa) /* Active Action Properties ------------------------------------- */ /* action */ row= uiLayoutRow(layout, 1); - uiItemR(row, NULL, 0, &adt_ptr, "action", 0, 0, 0); + uiItemR(row, NULL, 0, &adt_ptr, "action", 0); /* extrapolation */ row= uiLayoutRow(layout, 1); - uiItemR(row, NULL, 0, &adt_ptr, "action_extrapolation", 0, 0, 0); + uiItemR(row, NULL, 0, &adt_ptr, "action_extrapolation", 0); /* blending */ row= uiLayoutRow(layout, 1); - uiItemR(row, NULL, 0, &adt_ptr, "action_blending", 0, 0, 0); + uiItemR(row, NULL, 0, &adt_ptr, "action_blending", 0); /* influence */ row= uiLayoutRow(layout, 1); - uiItemR(row, NULL, 0, &adt_ptr, "action_influence", 0, 0, 0); + uiItemR(row, NULL, 0, &adt_ptr, "action_influence", 0); } /* active NLA-Track */ @@ -242,7 +242,7 @@ static void nla_panel_track (const bContext *C, Panel *pa) /* Info - Active NLA-Context:Track ---------------------- */ row= uiLayoutRow(layout, 1); - uiItemR(row, NULL, ICON_NLA, &nlt_ptr, "name", 0, 0, 0); + uiItemR(row, NULL, ICON_NLA, &nlt_ptr, "name", 0); } /* generic settings for active NLA-Strip */ @@ -262,41 +262,41 @@ static void nla_panel_properties(const bContext *C, Panel *pa) /* Strip Properties ------------------------------------- */ /* strip type */ row= uiLayoutColumn(layout, 1); - uiItemR(row, NULL, ICON_NLA, &strip_ptr, "name", 0, 0, 0); // XXX icon? - uiItemR(row, NULL, 0, &strip_ptr, "type", 0, 0, 0); + uiItemR(row, NULL, ICON_NLA, &strip_ptr, "name", 0); // XXX icon? + uiItemR(row, NULL, 0, &strip_ptr, "type", 0); /* strip extents */ column= uiLayoutColumn(layout, 1); uiItemL(column, "Strip Extents:", 0); - uiItemR(column, NULL, 0, &strip_ptr, "start_frame", 0, 0, 0); - uiItemR(column, NULL, 0, &strip_ptr, "end_frame", 0, 0, 0); + uiItemR(column, NULL, 0, &strip_ptr, "start_frame", 0); + uiItemR(column, NULL, 0, &strip_ptr, "end_frame", 0); /* extrapolation */ row= uiLayoutRow(layout, 1); - uiItemR(row, NULL, 0, &strip_ptr, "extrapolation", 0, 0, 0); + uiItemR(row, NULL, 0, &strip_ptr, "extrapolation", 0); /* blending */ row= uiLayoutRow(layout, 1); - uiItemR(row, NULL, 0, &strip_ptr, "blending", 0, 0, 0); + uiItemR(row, NULL, 0, &strip_ptr, "blending", 0); /* blend in/out + autoblending * - blend in/out can only be set when autoblending is off */ column= uiLayoutColumn(layout, 1); uiLayoutSetActive(column, RNA_boolean_get(&strip_ptr, "animated_influence")==0); - uiItemR(column, NULL, 0, &strip_ptr, "auto_blending", 0, 0, 0); // XXX as toggle? + uiItemR(column, NULL, 0, &strip_ptr, "auto_blending", 0); // XXX as toggle? subcol= uiLayoutColumn(column, 1); uiLayoutSetActive(subcol, RNA_boolean_get(&strip_ptr, "auto_blending")==0); - uiItemR(subcol, NULL, 0, &strip_ptr, "blend_in", 0, 0, 0); - uiItemR(subcol, NULL, 0, &strip_ptr, "blend_out", 0, 0, 0); + uiItemR(subcol, NULL, 0, &strip_ptr, "blend_in", 0); + uiItemR(subcol, NULL, 0, &strip_ptr, "blend_out", 0); /* settings */ column= uiLayoutColumn(layout, 1); uiLayoutSetActive(column, !(RNA_boolean_get(&strip_ptr, "animated_influence") || RNA_boolean_get(&strip_ptr, "animated_time"))); uiItemL(column, "Playback Settings:", 0); - uiItemR(column, NULL, 0, &strip_ptr, "muted", 0, 0, 0); - uiItemR(column, NULL, 0, &strip_ptr, "reversed", 0, 0, 0); + uiItemR(column, NULL, 0, &strip_ptr, "muted", 0); + uiItemR(column, NULL, 0, &strip_ptr, "reversed", 0); } @@ -318,21 +318,21 @@ static void nla_panel_actclip(const bContext *C, Panel *pa) /* Strip Properties ------------------------------------- */ /* action pointer */ row= uiLayoutRow(layout, 1); - uiItemR(row, NULL, ICON_ACTION, &strip_ptr, "action", 0, 0, 0); + uiItemR(row, NULL, ICON_ACTION, &strip_ptr, "action", 0); /* action extents */ // XXX custom names were used here (to avoid the prefixes)... probably not necessary in future? column= uiLayoutColumn(layout, 1); uiItemL(column, "Action Extents:", 0); - uiItemR(column, "Start Frame", 0, &strip_ptr, "action_start_frame", 0, 0, 0); - uiItemR(column, "End Frame", 0, &strip_ptr, "action_end_frame", 0, 0, 0); + uiItemR(column, "Start Frame", 0, &strip_ptr, "action_start_frame", 0); + uiItemR(column, "End Frame", 0, &strip_ptr, "action_end_frame", 0); /* action usage */ column= uiLayoutColumn(layout, 1); uiLayoutSetActive(column, RNA_boolean_get(&strip_ptr, "animated_time")==0); uiItemL(column, "Playback Settings:", 0); - uiItemR(column, NULL, 0, &strip_ptr, "scale", 0, 0, 0); - uiItemR(column, NULL, 0, &strip_ptr, "repeat", 0, 0, 0); + uiItemR(column, NULL, 0, &strip_ptr, "scale", 0); + uiItemR(column, NULL, 0, &strip_ptr, "repeat", 0); } /* evaluation settings for active NLA-Strip */ @@ -351,19 +351,19 @@ static void nla_panel_evaluation(const bContext *C, Panel *pa) uiBlockSetHandleFunc(block, do_nla_region_buttons, NULL); column= uiLayoutColumn(layout, 1); - uiItemR(column, NULL, 0, &strip_ptr, "animated_influence", 0, 0, 0); + uiItemR(column, NULL, 0, &strip_ptr, "animated_influence", 0); subcolumn= uiLayoutColumn(column, 1); uiLayoutSetEnabled(subcolumn, RNA_boolean_get(&strip_ptr, "animated_influence")); - uiItemR(subcolumn, NULL, 0, &strip_ptr, "influence", 0, 0, 0); + uiItemR(subcolumn, NULL, 0, &strip_ptr, "influence", 0); column= uiLayoutColumn(layout, 1); - uiItemR(column, NULL, 0, &strip_ptr, "animated_time", 0, 0, 0); + uiItemR(column, NULL, 0, &strip_ptr, "animated_time", 0); subcolumn= uiLayoutColumn(column, 1); uiLayoutSetEnabled(subcolumn, RNA_boolean_get(&strip_ptr, "animated_time")); - uiItemR(subcolumn, NULL, 0, &strip_ptr, "strip_time", 0, 0, 0); + uiItemR(subcolumn, NULL, 0, &strip_ptr, "strip_time", 0); } /* F-Modifiers for active NLA-Strip */ diff --git a/source/blender/editors/space_nla/nla_header.c b/source/blender/editors/space_nla/nla_header.c index e507efb0a30..0d3bf2cb6b1 100644 --- a/source/blender/editors/space_nla/nla_header.c +++ b/source/blender/editors/space_nla/nla_header.c @@ -94,14 +94,14 @@ static void nla_viewmenu(bContext *C, uiLayout *layout, void *arg_unused) uiItemS(layout); - uiItemR(layout, NULL, 0, &spaceptr, "show_cframe_indicator", 0, 0, 0); + uiItemR(layout, NULL, 0, &spaceptr, "show_cframe_indicator", 0); if (snla->flag & SNLA_DRAWTIME) uiItemO(layout, "Show Frames", 0, "ANIM_OT_time_toggle"); else uiItemO(layout, "Show Seconds", 0, "ANIM_OT_time_toggle"); - uiItemR(layout, NULL, 0, &spaceptr, "show_strip_curves", 0, 0, 0); + uiItemR(layout, NULL, 0, &spaceptr, "show_strip_curves", 0); uiItemS(layout); diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 3487efc4218..9fa1b222868 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -949,65 +949,6 @@ void uiTemplate_view3d_select_metaballmenu(uiLayout *layout, bContext *C) view3d_select_metaballmenu(C, layout, arg_unused); } -static void view3d_select_armaturemenu(bContext *C, uiLayout *layout, void *arg_unused) -{ - PointerRNA ptr; - - /* this part of the menu has been moved to python */ - /*uiItemO(layout, NULL, 0, "VIEW3D_OT_select_border"); - - uiItemS(layout); - - uiItemO(layout, "Select/Deselect All", 0, "ARMATURE_OT_select_all_toggle"); - uiItemO(layout, "Inverse", 0, "ARMATURE_OT_select_inverse"); - - uiItemS(layout); - - uiItemEnumO(layout, "Parent", 0, "ARMATURE_OT_select_hierarchy", "direction", BONE_SELECT_PARENT); - uiItemEnumO(layout, "Child", 0, "ARMATURE_OT_select_hierarchy", "direction", BONE_SELECT_CHILD); - - uiItemS(layout);*/ - - WM_operator_properties_create(&ptr, "ARMATURE_OT_select_hierarchy"); - RNA_boolean_set(&ptr, "extend", 1); - RNA_enum_set(&ptr, "direction", BONE_SELECT_PARENT); - uiItemFullO(layout, "Extend Parent", 0, "ARMATURE_OT_select_hierarchy", ptr.data, WM_OP_EXEC_REGION_WIN); - - WM_operator_properties_create(&ptr, "ARMATURE_OT_select_hierarchy"); - RNA_boolean_set(&ptr, "extend", 1); - RNA_enum_set(&ptr, "direction", BONE_SELECT_CHILD); - uiItemFullO(layout, "Extend Child", 0, "ARMATURE_OT_select_hierarchy", ptr.data, WM_OP_EXEC_REGION_WIN); -} - -/* wrapper for python layouts */ -void uiTemplate_view3d_select_armaturemenu(uiLayout *layout, bContext *C) -{ - void *arg_unused = NULL; - view3d_select_armaturemenu(C, layout, arg_unused); -} - -static void view3d_select_posemenu(bContext *C, uiLayout *layout, void *arg_unused) -{ - PointerRNA ptr; - - WM_operator_properties_create(&ptr, "POSE_OT_select_hierarchy"); - RNA_boolean_set(&ptr, "extend", 1); - RNA_enum_set(&ptr, "direction", BONE_SELECT_PARENT); - uiItemFullO(layout, "Extend Parent", 0, "POSE_OT_select_hierarchy", ptr.data, WM_OP_EXEC_REGION_WIN); - - WM_operator_properties_create(&ptr, "POSE_OT_select_hierarchy"); - RNA_boolean_set(&ptr, "extend", 1); - RNA_enum_set(&ptr, "direction", BONE_SELECT_CHILD); - uiItemFullO(layout, "Extend Child", 0, "POSE_OT_select_hierarchy", ptr.data, WM_OP_EXEC_REGION_WIN); -} - -/* wrapper for python layouts */ -void uiTemplate_view3d_select_posemenu(uiLayout *layout, bContext *C) -{ - void *arg_unused = NULL; - view3d_select_posemenu(C, layout, arg_unused); -} - void do_view3d_select_faceselmenu(bContext *C, void *arg, int event) { #if 0 @@ -2120,8 +2061,8 @@ static void view3d_edit_meshmenu(bContext *C, uiLayout *layout, void *arg_unused uiItemS(layout); - uiItemR(layout, NULL, 0, &tsptr, "automerge_editing", 0, 0, 0); - uiItemR(layout, NULL, 0, &tsptr, "proportional_editing", 0, 0, 0); // |O + uiItemR(layout, NULL, 0, &tsptr, "automerge_editing", 0); + uiItemR(layout, NULL, 0, &tsptr, "proportional_editing", 0); // |O uiItemMenuEnumR(layout, NULL, 0, &tsptr, "proportional_editing_falloff"); // |Shift O uiItemS(layout); @@ -2204,7 +2145,7 @@ static void view3d_edit_curvemenu(bContext *C, uiLayout *layout, void *arg_unuse uiItemS(layout); - uiItemR(layout, NULL, 0, &tsptr, "proportional_editing", 0, 0, 0); // |O + uiItemR(layout, NULL, 0, &tsptr, "proportional_editing", 0); // |O uiItemMenuEnumR(layout, NULL, 0, &tsptr, "proportional_editing_falloff"); // |Shift O uiItemS(layout); @@ -2245,7 +2186,7 @@ static void view3d_edit_latticemenu(bContext *C, uiLayout *layout, void *arg_unu uiItemS(layout); - uiItemR(layout, NULL, 0, &tsptr, "proportional_editing", 0, 0, 0); // |O + uiItemR(layout, NULL, 0, &tsptr, "proportional_editing", 0); // |O uiItemMenuEnumR(layout, NULL, 0, &tsptr, "proportional_editing_falloff"); // |Shift O } #endif diff --git a/source/blender/editors/space_view3d/view3d_toolbar.c b/source/blender/editors/space_view3d/view3d_toolbar.c index 32378a915bd..c87dd0b7948 100644 --- a/source/blender/editors/space_view3d/view3d_toolbar.c +++ b/source/blender/editors/space_view3d/view3d_toolbar.c @@ -270,7 +270,7 @@ static void view3d_panel_tool_shelf(const bContext *C, Panel *pa) for(ct= st->toolshelf.first; ct; ct= ct->next) { if(0==strncmp(context, ct->context, OP_MAX_TYPENAME)) { col= uiLayoutColumn(pa->layout, 1); - uiItemFullO(col, NULL, 0, ct->opname, NULL, WM_OP_INVOKE_REGION_WIN); + uiItemFullO(col, NULL, 0, ct->opname, NULL, WM_OP_INVOKE_REGION_WIN, 0); } } } diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 05eac06de7f..83178f32d5f 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -1198,7 +1198,13 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA dparm= dfunc->cont.properties.first; for(; dparm; dparm= dparm->next) { - ptrstr= (dparm->prop->type == PROP_POINTER || dparm->prop->arraylength > 0)? "*" : ""; + if(dparm->prop->arraylength > 0) + ptrstr= "*"; + else if(dparm->prop==func->ret) + ptrstr= ((dparm->prop->type == PROP_POINTER) && !(dparm->prop->flag & PROP_RNAPTR))? "*": ""; + else + ptrstr= (dparm->prop->type == PROP_POINTER)? "*": ""; + fprintf(f, "\t%s%s %s%s;\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, dparm->prop->identifier); } @@ -1274,7 +1280,7 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA if(func->ret) { dparm= rna_find_parameter_def(func->ret); - ptrstr= dparm->prop->type == PROP_POINTER || dparm->prop->arraylength > 0 ? "*" : ""; + ptrstr= (((dparm->prop->type == PROP_POINTER) && !(dparm->prop->flag & PROP_RNAPTR)) || (dparm->prop->arraylength > 0))? "*": ""; fprintf(f, "\t*((%s%s%s*)_retdata)= %s;\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, func->ret->identifier); } } @@ -1516,7 +1522,7 @@ static void rna_generate_static_parameter_prototypes(BlenderRNA *brna, StructRNA if(dparm->prop==func->ret) { if(dparm->prop->arraylength) fprintf(f, "XXX no array return types yet"); /* XXX not supported */ - else if(dparm->prop->type == PROP_POINTER) + else if(dparm->prop->type == PROP_POINTER && !(dparm->prop->flag & PROP_RNAPTR)) fprintf(f, "%s%s *", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop)); else fprintf(f, "%s%s ", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop)); diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c index 82694098e69..587ff57a0b5 100644 --- a/source/blender/makesrna/intern/rna_ui_api.c +++ b/source/blender/makesrna/intern/rna_ui_api.c @@ -37,6 +37,23 @@ #ifdef RNA_RUNTIME +static void rna_uiItemR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, char *propname, int expand, int slider, int toggle) +{ + int flag= 0; + + flag |= (slider)? UI_ITEM_R_SLIDER: 0; + flag |= (expand)? UI_ITEM_R_EXPAND: 0; + flag |= (toggle)? UI_ITEM_R_TOGGLE: 0; + + uiItemR(layout, name, icon, ptr, propname, flag); +} + +static PointerRNA rna_uiItemO(uiLayout *layout, char *name, int icon, char *opname, int properties) +{ + int flag= (properties)? UI_ITEM_O_RETURN_PROPS: 0; + return uiItemFullO(layout, name, icon, opname, NULL, uiLayoutGetOperatorContext(layout), flag); +} + #else #define DEF_ICON(name) {name, #name, 0, #name, ""}, @@ -122,7 +139,7 @@ void RNA_api_ui_layout(StructRNA *srna) RNA_def_float(func, "percentage", 0.0f, 0.0f, 1.0f, "Percentage", "Percentage of width to split at.", 0.0f, 1.0f); /* items */ - func= RNA_def_function(srna, "itemR", "uiItemR"); + func= RNA_def_function(srna, "itemR", "rna_uiItemR"); api_ui_item_common(func); api_ui_item_rna_common(func); RNA_def_boolean(func, "expand", 0, "", "Expand button to show more detail."); @@ -150,8 +167,12 @@ void RNA_api_ui_layout(StructRNA *srna) parm= RNA_def_string(func, "search_property", "", 0, "", "Identifier of search collection property."); RNA_def_property_flag(parm, PROP_REQUIRED); - func= RNA_def_function(srna, "itemO", "uiItemO"); + func= RNA_def_function(srna, "itemO", "rna_uiItemO"); api_ui_item_op_common(func); + parm= RNA_def_boolean(func, "properties", 0, "Properties", "Return operator properties to fill in manually."); + parm= RNA_def_pointer(func, "return_properties", "OperatorProperties", "", "Operator properties to fill in, return when 'properties' is set to true."); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_RNAPTR); + RNA_def_function_return(func, parm); func= RNA_def_function(srna, "item_enumO", "uiItemEnumO_string"); api_ui_item_op_common(func); @@ -292,10 +313,6 @@ void RNA_api_ui_layout(StructRNA *srna) func= RNA_def_function(srna, "view3d_select_metaballmenu", "uiTemplate_view3d_select_metaballmenu"); RNA_def_function_flag(func, FUNC_USE_CONTEXT); - func= RNA_def_function(srna, "view3d_select_armaturemenu", "uiTemplate_view3d_select_armaturemenu"); - RNA_def_function_flag(func, FUNC_USE_CONTEXT); - func= RNA_def_function(srna, "view3d_select_posemenu", "uiTemplate_view3d_select_posemenu"); - RNA_def_function_flag(func, FUNC_USE_CONTEXT); func= RNA_def_function(srna, "view3d_select_faceselmenu", "uiTemplate_view3d_select_faceselmenu"); RNA_def_function_flag(func, FUNC_USE_CONTEXT); From f2e7ca0de39ef3ff83feb05e6bae949e12a9fb7b Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 21 Aug 2009 14:33:53 +0000 Subject: [PATCH 44/73] 2.5: Load UI is now an operator property, and a user preference to define what the default is, just like file compression for saving. --- release/ui/space_userpref.py | 1 + source/blender/makesdna/DNA_userdef_types.h | 1 + source/blender/makesrna/intern/rna_userdef.c | 4 ++++ .../blender/windowmanager/intern/wm_operators.c | 16 ++++++++++++++++ 4 files changed, 22 insertions(+) diff --git a/release/ui/space_userpref.py b/release/ui/space_userpref.py index 95054efcb25..bd963c65cd0 100644 --- a/release/ui/space_userpref.py +++ b/release/ui/space_userpref.py @@ -359,6 +359,7 @@ class USERPREF_PT_filepaths(bpy.types.Panel): sub2.itemL(text="Save & Load:") sub2.itemR(paths, "use_relative_paths") sub2.itemR(paths, "compress_file") + sub2.itemR(paths, "load_ui") sub2.itemL(text="Auto Save:") sub2.itemR(paths, "save_version") sub2.itemR(paths, "recent_files") diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index c2314e1e3a2..100f55ffe33 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -369,6 +369,7 @@ extern UserDef U; /* from blenkernel blender.c */ #define USER_RELPATHS (1 << 20) #define USER_DRAGIMMEDIATE (1 << 21) #define USER_DONT_DOSCRIPTLINKS (1 << 22) +#define USER_FILENOUI (1 << 23) /* viewzom */ #define USER_ZOOM_CONT 0 diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index d1245528100..b74dc6f757b 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -2199,6 +2199,10 @@ static void rna_def_userdef_filepaths(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "flag", USER_FILECOMPRESS); RNA_def_property_ui_text(prop, "Compress File", "Enable file compression when saving .blend files."); + prop= RNA_def_property(srna, "load_ui", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", USER_FILENOUI); + RNA_def_property_ui_text(prop, "Load UI", "Load user interface setup when loading .blend files."); + prop= RNA_def_property(srna, "fonts_directory", PROP_STRING, PROP_DIRPATH); RNA_def_property_string_sdna(prop, NULL, "fontdir"); RNA_def_property_ui_text(prop, "Fonts Directory", "The default directory to search for loading fonts."); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index ab8dfeabe4f..87a145ceee2 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -868,10 +868,17 @@ static void untitled(char *name) } } +static void load_set_load_ui(wmOperator *op) +{ + if(!RNA_property_is_set(op->ptr, "load_ui")) + RNA_boolean_set(op->ptr, "load_ui", !(U.flag & USER_FILENOUI)); +} static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event) { RNA_string_set(op->ptr, "filename", G.sce); + load_set_load_ui(op); + WM_event_add_fileselect(C, op); return OPERATOR_RUNNING_MODAL; @@ -880,7 +887,14 @@ static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event) static int wm_open_mainfile_exec(bContext *C, wmOperator *op) { char filename[FILE_MAX]; + RNA_string_get(op->ptr, "filename", filename); + load_set_load_ui(op); + + if(RNA_boolean_get(op->ptr, "load_ui")) + G.fileflags &= ~G_FILE_NO_UI; + else + G.fileflags |= G_FILE_NO_UI; // XXX wm in context is not set correctly after WM_read_file -> crash // do it before for now, but is this correct with multiple windows? @@ -901,6 +915,8 @@ static void WM_OT_open_mainfile(wmOperatorType *ot) ot->poll= WM_operator_winactive; WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE); + + RNA_def_boolean(ot->srna, "load_ui", 1, "Load UI", "Load user interface setup in the .blend file."); } static int wm_recover_last_session_exec(bContext *C, wmOperator *op) From bc41c845f355c0e4fed427bfa3ab7fc5f7e96660 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 21 Aug 2009 16:28:49 +0000 Subject: [PATCH 45/73] 2.5: Animation playback without sync option was slightly slower than expected time, even when it could keep up. Changed the WM timer logic a bit to always target the next frame time exactly, --- source/blender/windowmanager/WM_types.h | 2 ++ source/blender/windowmanager/intern/wm_window.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index c400b6c9b20..42ee6e926fc 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -283,6 +283,8 @@ typedef struct wmTimer { double delta; /* time since previous step in seconds */ double ltime; /* internal, last time timer was activated */ + double ntime; /* internal, next time we want to activate the timer */ + double stime; /* internal, when the timer started */ int sleep; /* internal, put timers to sleep when needed */ } wmTimer; diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index d6bde9a468c..27a1b076a28 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -26,6 +26,7 @@ * ***** END GPL LICENSE BLOCK ***** */ +#include #include #include #include @@ -690,12 +691,13 @@ static int wm_window_timer(const bContext *C) wmTimer *wt; for(wt= win->timers.first; wt; wt= wt->next) { if(wt->sleep==0) { - if(wt->timestep < time - wt->ltime) { + if(time > wt->ntime) { wmEvent event= *(win->eventstate); wt->delta= time - wt->ltime; wt->duration += wt->delta; wt->ltime= time; + wt->ntime= wt->stime + wt->timestep*ceil(wt->duration/wt->timestep); event.type= wt->event_type; event.custom= EVT_DATA_TIMER; @@ -790,6 +792,8 @@ wmTimer *WM_event_add_window_timer(wmWindow *win, int event_type, double timeste wt->event_type= event_type; wt->ltime= PIL_check_seconds_timer(); + wt->ntime= wt->ltime + timestep; + wt->stime= wt->ltime; wt->timestep= timestep; BLI_addtail(&win->timers, wt); From 5280c2884b3395376eec8c9b6f7521375b88f51c Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Fri, 21 Aug 2009 17:35:35 +0000 Subject: [PATCH 46/73] 2.5 Object mode: * Made object mode an enum, shows better in the debugger * Added a toggle mode to the set object mode operator * Toggling a mode on and off goes back to the previous mode, not just object mode * Changed the vertex mode and weight mode shortcuts to call the toggle mode operator --- source/blender/editors/object/object_edit.c | 27 ++++++++++++++----- .../blender/editors/space_view3d/view3d_ops.c | 8 ++++-- source/blender/makesdna/DNA_object_types.h | 26 +++++++++--------- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 47eaf1757ac..8ac12a5e3a4 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -7092,18 +7092,31 @@ static const char *object_mode_op_string(int mode) static int object_mode_set_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); - int mode = RNA_enum_get(op->ptr, "mode"); + ObjectMode mode = RNA_enum_get(op->ptr, "mode"); + ObjectMode restore_mode = ob->mode; + int toggle = RNA_boolean_get(op->ptr, "toggle"); if(!ob) return OPERATOR_CANCELLED; - /* Exit off current mode */ - if(ob->mode != OB_MODE_OBJECT) + /* Exit current mode if it's not the mode we're setting */ + if(ob->mode != OB_MODE_OBJECT && ob->mode != mode) WM_operator_name_call(C, object_mode_op_string(ob->mode), WM_OP_EXEC_REGION_WIN, NULL); - /* Enter new mode */ - if(mode != OB_MODE_OBJECT) - WM_operator_name_call(C, object_mode_op_string(mode), WM_OP_EXEC_REGION_WIN, NULL); + if(mode != OB_MODE_OBJECT) { + /* Enter new mode */ + if(ob->mode != mode || toggle) + WM_operator_name_call(C, object_mode_op_string(mode), WM_OP_EXEC_REGION_WIN, NULL); + + if(toggle) { + if(ob->mode == mode) + /* For toggling, store old mode so we know what to go back to */ + ob->restore_mode = restore_mode; + else if(ob->restore_mode != OB_MODE_OBJECT && ob->restore_mode != mode) { + WM_operator_name_call(C, object_mode_op_string(ob->restore_mode), WM_OP_EXEC_REGION_WIN, NULL); + } + } + } return OPERATOR_FINISHED; } @@ -7127,6 +7140,8 @@ void OBJECT_OT_mode_set(wmOperatorType *ot) prop= RNA_def_enum(ot->srna, "mode", object_mode_items, 0, "Mode", ""); RNA_def_enum_funcs(prop, object_mode_set_itemsf); + + RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", ""); } diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index 112847272e5..b0eabae3f5d 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -106,8 +106,12 @@ void view3d_keymap(wmWindowManager *wm) ListBase *keymap= WM_keymap_listbase(wm, "View3D Generic", SPACE_VIEW3D, 0); wmKeymapItem *km; - WM_keymap_add_item(keymap, "PAINT_OT_vertex_paint_toggle", VKEY, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "PAINT_OT_weight_paint_toggle", TABKEY, KM_PRESS, KM_CTRL, 0); + km = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", VKEY, KM_PRESS, 0, 0); + RNA_enum_set(km->ptr, "mode", OB_MODE_VERTEX_PAINT); + RNA_boolean_set(km->ptr, "toggle", 1); + km = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", TABKEY, KM_PRESS, KM_CTRL, 0); + RNA_enum_set(km->ptr, "mode", OB_MODE_WEIGHT_PAINT); + RNA_boolean_set(km->ptr, "toggle", 1); WM_keymap_add_item(keymap, "VIEW3D_OT_properties", NKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "VIEW3D_OT_toolbar", TKEY, KM_PRESS, 0, 0); diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h index 5c821b532fb..be43ae7f99d 100644 --- a/source/blender/makesdna/DNA_object_types.h +++ b/source/blender/makesdna/DNA_object_types.h @@ -116,8 +116,8 @@ typedef struct Object { ListBase defbase; ListBase modifiers; /* list of ModifierData structures */ - /* For now just a flag for sculpt mode, eventually we make the other modes local too */ - int mode, pad2; + int mode; /* Local object mode */ + int restore_mode; /* Keep track of what mode to return to after toggling a mode */ /* materials */ struct Material **mat; /* material slots */ @@ -234,7 +234,7 @@ typedef struct Object { unsigned int state; /* bit masks of game controllers that are active */ unsigned int init_state; /* bit masks of initial state as recorded by the users */ - int restore_mode; /* Keep track of what mode to return to after edit mode exits */ + int pad2; ListBase gpulamp; /* runtime, for lamps only */ } Object; @@ -511,16 +511,16 @@ extern Object workob; #define OB_LOCK_SCALE 448 /* ob->mode */ -#define OB_MODE_OBJECT 0 -#define OB_MODE_EDIT 1 -#define OB_MODE_SCULPT 2 -#define OB_MODE_VERTEX_PAINT 4 -#define OB_MODE_WEIGHT_PAINT 8 -#define OB_MODE_TEXTURE_PAINT 16 -#define OB_MODE_PARTICLE_EDIT 32 -#define OB_MODE_POSE 64 - -/* ob->softflag in DNA_object_force.h */ +typedef enum ObjectMode { + OB_MODE_OBJECT = 0, + OB_MODE_EDIT = 1, + OB_MODE_SCULPT = 2, + OB_MODE_VERTEX_PAINT = 4, + OB_MODE_WEIGHT_PAINT = 8, + OB_MODE_TEXTURE_PAINT = 16, + OB_MODE_PARTICLE_EDIT = 32, + OB_MODE_POSE = 64 +} ObjectMode; #ifdef __cplusplus } From fc5df351b30445e697f27aa815d956cc3e9c58ea Mon Sep 17 00:00:00 2001 From: William Reynish Date: Fri, 21 Aug 2009 17:53:27 +0000 Subject: [PATCH 47/73] Material buttons tweaks -Made Mirror and Transparency panels more consistent. -Improved greying out, and better communicated the fact that alpha settings do work even if Ztransp/Ray Transp are not enabled. The results of low alpha and no Ztransp/Ray Transp look weird though - is this supposed to be supported? -Added Flare panel for halo. -Improved SSS panel. --- release/ui/buttons_material.py | 114 ++++++++++++++++++++++----------- 1 file changed, 77 insertions(+), 37 deletions(-) diff --git a/release/ui/buttons_material.py b/release/ui/buttons_material.py index ed3888ee4d8..73d28d6964c 100644 --- a/release/ui/buttons_material.py +++ b/release/ui/buttons_material.py @@ -87,10 +87,12 @@ class MATERIAL_PT_shading(MaterialButtonsPanel): split = layout.split() col = split.column() - col.active = not mat.shadeless - col.itemR(mat, "ambient") - col.itemR(mat, "emit") - col.itemR(mat, "translucency") + sub = col.column() + sub.active = not mat.shadeless + sub.itemR(mat, "emit") + sub.itemR(mat, "ambient") + sub = col.column() + sub.itemR(mat, "translucency") col = split.column() col.itemR(mat, "shadeless") @@ -119,7 +121,7 @@ class MATERIAL_PT_strand(MaterialButtonsPanel): split = layout.split() - col = split.column() + col = split.column(align=True) col.itemL(text="Size:") col.itemR(tan, "start_size", text="Root") col.itemR(tan, "end_size", text="Tip") @@ -128,11 +130,13 @@ class MATERIAL_PT_strand(MaterialButtonsPanel): sub = col.column() sub.active = (not mat.shadeless) sub.itemR(tan, "tangent_shading") + col.itemR(tan, "shape") col = split.column() - col.itemR(tan, "shape") + col.itemL(text="Shading:") col.itemR(tan, "width_fade") col.itemR(tan, "uv_layer") + col.itemS() sub = col.column() sub.active = (not mat.shadeless) sub.itemR(tan, "surface_diffuse") @@ -343,7 +347,9 @@ class MATERIAL_PT_sss(MaterialButtonsPanel): def draw_header(self, context): layout = self.layout sss = context.material.subsurface_scattering - + mat = context.material + + layout.active = (not mat.shadeless) layout.itemR(sss, "enabled", text="") def draw(self, context): @@ -357,21 +363,22 @@ class MATERIAL_PT_sss(MaterialButtonsPanel): split = layout.split() split.active = (not mat.shadeless) - col = split.column(align=True) + col = split.column() + col.itemR(sss, "ior") + col.itemR(sss, "scale") col.itemR(sss, "color", text="") - col.itemL(text="Blend:") - col.itemR(sss, "color_factor", text="Color") - col.itemR(sss, "texture_factor", text="Texture") - col.itemL(text="Scattering Weight:") - col.itemR(sss, "front") - col.itemR(sss, "back") + col.itemR(sss, "radius", text="RGB Radius") col = split.column() sub = col.column(align=True) - sub.itemR(sss, "ior") - sub.itemR(sss, "scale") - col.itemR(sss, "radius", text="RGB Radius") - col.itemR(sss, "error_tolerance") + sub.itemL(text="Blend:") + sub.itemR(sss, "color_factor", text="Color") + sub.itemR(sss, "texture_factor", text="Texture") + sub.itemL(text="Scattering Weight:") + sub.itemR(sss, "front") + sub.itemR(sss, "back") + col.itemS() + col.itemR(sss, "error_tolerance", text="Error") class MATERIAL_PT_mirror(MaterialButtonsPanel): __label__ = "Mirror" @@ -402,20 +409,26 @@ class MATERIAL_PT_mirror(MaterialButtonsPanel): col = split.column() col.itemR(raym, "reflect", text="Reflectivity") col.itemR(mat, "mirror_color", text="") - col.itemL(text="Fresnel:") - col.itemR(raym, "fresnel", text="Amount") + + + col = split.column() + col.itemR(raym, "fresnel") sub = col.column() sub.active = raym.fresnel > 0 sub.itemR(raym, "fresnel_factor", text="Blend") + + split = layout.split() + + col = split.column() col.itemS() + col.itemR(raym, "distance", text="Max Dist") + col.itemR(raym, "depth") col.itemS() sub = col.split(percentage=0.4) sub.itemL(text="Fade To:") sub.itemR(raym, "fade_to", text="") col = split.column() - col.itemR(raym, "depth") - col.itemR(raym, "distance", text="Max Dist") col.itemL(text="Gloss:") col.itemR(raym, "gloss", text="Amount") sub = col.column() @@ -453,25 +466,24 @@ class MATERIAL_PT_transp(MaterialButtonsPanel): split = layout.split() col = split.column() - col.itemL(text="Transparency:") row = col.row() row.itemR(mat, "alpha") - row.active = mat.transparency row = col.row() - row.itemR(mat, "specular_alpha", text="Specular") row.active = mat.transparency and (not mat.shadeless) + row.itemR(mat, "specular_alpha", text="Specular") + col = split.column() - col.active = mat.transparency and (not mat.shadeless) - col.itemL(text="Fresnel:") - col.itemR(rayt, "fresnel", text="Amount") + col.active = (not mat.shadeless) + col.itemR(rayt, "fresnel") sub = col.column() sub.active = rayt.fresnel > 0 sub.itemR(rayt, "fresnel_factor", text="Blend") if mat.transparency_method == 'RAYTRACE': + layout.itemS() split = layout.split() - split.active = mat.transparency and (not mat.shadeless) + split.active = mat.transparency col = split.column() col.itemR(rayt, "ior") @@ -522,23 +534,50 @@ class MATERIAL_PT_halo(MaterialButtonsPanel): sub.active = halo.ring sub.itemR(halo, "rings") sub.itemR(mat, "mirror_color", text="") + col.itemS() col.itemR(halo, "lines") sub = col.column() sub.active = halo.lines sub.itemR(halo, "line_number", text="Lines") sub.itemR(mat, "specular_color", text="") + col.itemS() col.itemR(halo, "star") sub = col.column() sub.active = halo.star sub.itemR(halo, "star_tips") - col.itemR(halo, "flare_mode") - sub = col.column() - sub.active = halo.flare_mode - sub.itemR(halo, "flare_size", text="Size") - sub.itemR(halo, "flare_subsize", text="Subsize") - sub.itemR(halo, "flare_boost", text="Boost") - sub.itemR(halo, "flare_seed", text="Seed") - sub.itemR(halo, "flares_sub", text="Sub") + +class MATERIAL_PT_flare(MaterialButtonsPanel): + __label__= "Flare" + COMPAT_ENGINES = set(['BLENDER_RENDER']) + + def poll(self, context): + mat = context.material + return mat and (mat.type == 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES) + + def draw_header(self, context): + layout = self.layout + + mat = context.material + halo = mat.halo + layout.itemR(halo, "flare_mode", text="") + + def draw(self, context): + layout = self.layout + + mat = context.material + halo = mat.halo + + layout.active = halo.flare_mode + + split = layout.split() + + col = split.column() + col.itemR(halo, "flare_size", text="Size") + col.itemR(halo, "flare_boost", text="Boost") + col.itemR(halo, "flare_seed", text="Seed") + col = split.column() + col.itemR(halo, "flares_sub", text="Subflares") + col.itemR(halo, "flare_subsize", text="Subsize") bpy.types.register(MATERIAL_PT_context_material) bpy.types.register(MATERIAL_PT_preview) @@ -549,6 +588,7 @@ bpy.types.register(MATERIAL_PT_transp) bpy.types.register(MATERIAL_PT_mirror) bpy.types.register(MATERIAL_PT_sss) bpy.types.register(MATERIAL_PT_halo) +bpy.types.register(MATERIAL_PT_flare) bpy.types.register(MATERIAL_PT_physics) bpy.types.register(MATERIAL_PT_strand) bpy.types.register(MATERIAL_PT_options) From b6548c21c209516f9ec60e3a403274f20566680d Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Fri, 21 Aug 2009 18:15:50 +0000 Subject: [PATCH 48/73] 2.5/Multires: * Fixed multires subdivision of a sculpted object. Accidentally broke this when I fixed removing a multires modifier. --- source/blender/blenkernel/BKE_multires.h | 3 ++- source/blender/blenkernel/intern/cdderivedmesh.c | 15 +++++++++------ source/blender/blenkernel/intern/modifier.c | 2 +- source/blender/blenkernel/intern/multires.c | 9 +++++---- source/blender/blenloader/intern/readfile.c | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/source/blender/blenkernel/BKE_multires.h b/source/blender/blenkernel/BKE_multires.h index e7c7d92c955..a331479cad1 100644 --- a/source/blender/blenkernel/BKE_multires.h +++ b/source/blender/blenkernel/BKE_multires.h @@ -36,6 +36,7 @@ struct Object; typedef struct MultiresSubsurf { struct MultiresModifierData *mmd; struct Object *ob; + int local_mmd; } MultiresSubsurf; /* MultiresDM */ @@ -59,7 +60,7 @@ void multires_mark_as_modified(struct Object *ob); void multires_force_update(struct Object *ob); -struct DerivedMesh *multires_dm_create_from_derived(struct MultiresModifierData*, struct DerivedMesh*, +struct DerivedMesh *multires_dm_create_from_derived(struct MultiresModifierData*, int local_mmd, struct DerivedMesh*, struct Object *, int, int); struct MultiresModifierData *find_multires_modifier(struct Object *ob); diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 4829be21ed8..b20da0962a7 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -1288,6 +1288,7 @@ typedef struct MultiresDM { CDDerivedMesh cddm; MultiresModifierData *mmd; + int local_mmd; int lvl, totlvl; float (*orco)[3]; @@ -1308,13 +1309,14 @@ static void MultiresDM_release(DerivedMesh *dm) MultiresDM *mrdm = (MultiresDM*)dm; int mvert_layer; - /* Check that mmd still exists */ - if(BLI_findindex(&mrdm->ob->modifiers, mrdm->mmd) < 0) - mrdm->mmd = NULL; - /* Before freeing, need to update the displacement map */ - if(dm->needsFree && mrdm->modified && mrdm->mmd) - mrdm->update(dm); + if(dm->needsFree && mrdm->modified) { + /* Check that mmd still exists */ + if(!mrdm->local_mmd && BLI_findindex(&mrdm->ob->modifiers, mrdm->mmd) < 0) + mrdm->mmd = NULL; + if(mrdm->mmd) + mrdm->update(dm); + } /* If the MVert data is being used as the sculpt undo store, don't free it */ mvert_layer = CustomData_get_layer_index(&dm->vertData, CD_MVERT); @@ -1353,6 +1355,7 @@ DerivedMesh *MultiresDM_new(MultiresSubsurf *ms, DerivedMesh *orig, int numVerts mrdm->mmd = ms->mmd; mrdm->ob = ms->ob; + mrdm->local_mmd = ms->local_mmd; if(dm) { MDisps *disps; diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 501638aba0d..6da2c94fab8 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -8121,7 +8121,7 @@ static DerivedMesh *multiresModifier_applyModifier(ModifierData *md, Object *ob, if(mmd->lvl == 1) return dm; - final = multires_dm_create_from_derived(mmd, dm, ob, useRenderParams, isFinalCalc); + final = multires_dm_create_from_derived(mmd, 0, dm, ob, useRenderParams, isFinalCalc); if(mmd->undo_signal && mmd->undo_verts && mmd->undo_verts_tot == final->getNumVerts(final)) { int i; MVert *dst = CDDM_get_verts(final); diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 09a6c27a88c..0f3ab5be16e 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -223,7 +223,7 @@ static void multires_subdisp(DerivedMesh *orig, Object *ob, DerivedMesh *final, memset(&mmd_sub, 0, sizeof(MultiresModifierData)); mmd_sub.lvl = mmd_sub.totlvl = totlvl; - mrdm = multires_dm_create_from_derived(&mmd_sub, orig, ob, 0, 0); + mrdm = multires_dm_create_from_derived(&mmd_sub, 1, orig, ob, 0, 0); mvd = CDDM_get_verts(mrdm); /* Need to map from ccg to mrdm */ @@ -469,7 +469,7 @@ void multiresModifier_subdivide(MultiresModifierData *mmd, Object *ob, int dista orig = CDDM_from_mesh(me, NULL); memset(&mmd_sub, 0, sizeof(MultiresModifierData)); mmd_sub.lvl = mmd_sub.totlvl = mmd->lvl; - mrdm = multires_dm_create_from_derived(&mmd_sub, orig, ob, 0, 0); + mrdm = multires_dm_create_from_derived(&mmd_sub, 1, orig, ob, 0, 0); totsubvert = mrdm->getNumVerts(mrdm); totsubedge = mrdm->getNumEdges(mrdm); totsubface = mrdm->getNumFaces(mrdm); @@ -1192,7 +1192,7 @@ static void multiresModifier_update(DerivedMesh *dm) (includes older displacements but not new sculpts) */ mmd.totlvl = totlvl; mmd.lvl = lvl; - subco_dm = multires_dm_create_from_derived(&mmd, orig, ob, 0, 0); + subco_dm = multires_dm_create_from_derived(&mmd, 1, orig, ob, 0, 0); cur_lvl_orig_verts = CDDM_get_verts(subco_dm); /* Subtract the original vertex cos from the new vertex cos */ @@ -1229,7 +1229,7 @@ void multires_force_update(Object *ob) } } -struct DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, DerivedMesh *dm, Object *ob, +struct DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, int local_mmd, DerivedMesh *dm, Object *ob, int useRenderParams, int isFinalCalc) { SubsurfModifierData smd; @@ -1239,6 +1239,7 @@ struct DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, D ms.mmd = mmd; ms.ob = ob; + ms.local_mmd = local_mmd; memset(&smd, 0, sizeof(SubsurfModifierData)); smd.levels = smd.renderLevels = mmd->lvl - 1; diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 58b439e4cb4..72aba02f723 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -9416,7 +9416,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) mmd->lvl = mmd->totlvl; orig = CDDM_from_mesh(me, NULL); - dm = multires_dm_create_from_derived(mmd, orig, ob, 0, 0); + dm = multires_dm_create_from_derived(mmd, 0, orig, ob, 0, 0); multires_load_old(dm, me->mr); From 647fd95c7fc25170ec2f1c75137f4e6f39c66651 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Fri, 21 Aug 2009 18:35:40 +0000 Subject: [PATCH 49/73] 2.5 Multires: * Fixed doing a simple subdivide, rather than Catmull-Clark. Note that the first subdivision will still appear to be CC rather than simple, this is a bug we just have to live with for now. --- source/blender/blenkernel/intern/multires.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 0f3ab5be16e..9ba5769843f 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -469,6 +469,7 @@ void multiresModifier_subdivide(MultiresModifierData *mmd, Object *ob, int dista orig = CDDM_from_mesh(me, NULL); memset(&mmd_sub, 0, sizeof(MultiresModifierData)); mmd_sub.lvl = mmd_sub.totlvl = mmd->lvl; + mmd_sub.simple = simple; mrdm = multires_dm_create_from_derived(&mmd_sub, 1, orig, ob, 0, 0); totsubvert = mrdm->getNumVerts(mrdm); totsubedge = mrdm->getNumEdges(mrdm); From f248b25152db25c03c9e296ed965b6925924829a Mon Sep 17 00:00:00 2001 From: Joerg Mueller Date: Fri, 21 Aug 2009 19:39:28 +0000 Subject: [PATCH 50/73] Audio file loading backend libsndfile! --- CMake/macros.cmake | 6 + CMakeLists.txt | 22 ++ intern/audaspace/CMakeLists.txt | 8 +- intern/audaspace/ffmpeg/AUD_FFMPEGFactory.cpp | 49 +--- intern/audaspace/ffmpeg/AUD_FFMPEGFactory.h | 9 +- intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp | 9 +- intern/audaspace/ffmpeg/AUD_FFMPEGReader.h | 10 +- intern/audaspace/intern/AUD_C-API.cpp | 14 +- intern/audaspace/intern/AUD_FileFactory.cpp | 95 +++++++ intern/audaspace/intern/AUD_FileFactory.h | 71 ++++++ .../audaspace/sndfile/AUD_SndFileFactory.cpp | 67 +++++ intern/audaspace/sndfile/AUD_SndFileFactory.h | 71 ++++++ .../audaspace/sndfile/AUD_SndFileReader.cpp | 233 ++++++++++++++++++ intern/audaspace/sndfile/AUD_SndFileReader.h | 131 ++++++++++ 14 files changed, 735 insertions(+), 60 deletions(-) create mode 100644 intern/audaspace/intern/AUD_FileFactory.cpp create mode 100644 intern/audaspace/intern/AUD_FileFactory.h create mode 100644 intern/audaspace/sndfile/AUD_SndFileFactory.cpp create mode 100644 intern/audaspace/sndfile/AUD_SndFileFactory.h create mode 100644 intern/audaspace/sndfile/AUD_SndFileReader.cpp create mode 100644 intern/audaspace/sndfile/AUD_SndFileReader.h diff --git a/CMake/macros.cmake b/CMake/macros.cmake index 9ba33dfb158..6a337505c00 100644 --- a/CMake/macros.cmake +++ b/CMake/macros.cmake @@ -70,6 +70,9 @@ MACRO(SETUP_LIBDIRS) IF(WITH_JACK) LINK_DIRECTORIES(${JACK_LIBPATH}) ENDIF(WITH_JACK) + IF(WITH_SNDFILE) + LINK_DIRECTORIES(${SNDFILE_LIBPATH}) + ENDIF(WITH_SNDFILE) IF(WITH_FFTW3) LINK_DIRECTORIES(${FFTW3_LIBPATH}) ENDIF(WITH_FFTW3) @@ -118,6 +121,9 @@ MACRO(SETUP_LIBLINKS IF(WITH_JACK) TARGET_LINK_LIBRARIES(${target} ${JACK_LIB}) ENDIF(WITH_JACK) + IF(WITH_SNDFILE) + TARGET_LINK_LIBRARIES(${target} ${SNDFILE_LIB}) + ENDIF(WITH_SNDFILE) IF(WITH_SDL) TARGET_LINK_LIBRARIES(${target} ${SDL_LIBRARY}) ENDIF(WITH_SDL) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9db25115099..749284def28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,7 @@ OPTION(WITH_OPENMP "Enable OpenMP (has to be supported by the compiler)" OPTION(WITH_WEBPLUGIN "Enable Web Plugin (Unix only)" OFF) OPTION(WITH_FFTW3 "Enable FFTW3 support" OFF) OPTION(WITH_JACK "Enable Jack Support (http://www.jackaudio.org)" OFF) +OPTION(WITH_SNDFILE "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF) OPTION(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation" OFF) OPTION(WITH_INSTALL "Install accompanying scripts and language files needed to run blender" ON) @@ -109,6 +110,13 @@ IF(UNIX AND NOT APPLE) SET(JACK_LIBPATH ${JACK}/lib) ENDIF(WITH_JACK) + IF(WITH_SNDFILE) + SET(SNDFILE /usr) + SET(SNDFILE_INC ${SNDFILE}/include) + SET(SNDFILE_LIB sndfile) + SET(SNDFILE_LIBPATH ${SNDFILE}/lib) + ENDIF(WITH_SNDFILE) + FIND_LIBRARY(INTL_LIBRARY NAMES intl PATHS @@ -247,6 +255,13 @@ IF(WIN32) SET(JACK_LIBPATH ${JACK}/lib) ENDIF(WITH_JACK) + IF(WITH_SNDFILE) + SET(SNDFILE ${LIBDIR}/sndfile) + SET(SNDFILE_INC ${SNDFILE}/include) + SET(SNDFILE_LIB sndfile) + SET(SNDFILE_LIBPATH ${SNDFILE}/lib) + ENDIF(WITH_SNDFILE) + IF(CMAKE_CL_64) SET(PNG_LIBRARIES libpng) ELSE(CMAKE_CL_64) @@ -392,6 +407,13 @@ IF(APPLE) SET(JACK_LIBPATH ${JACK}/lib) ENDIF(WITH_JACK) + IF(WITH_SNDFILE) + SET(SNDFILE /usr) + SET(SNDFILE_INC ${SNDFILE}/include) + SET(SNDFILE_LIB sndfile) + SET(SNDFILE_LIBPATH ${SNDFILE}/lib) + ENDIF(WITH_SNDFILE) + SET(PYTHON_VERSION 3.1) IF(PYTHON_VERSION MATCHES 3.1) diff --git a/intern/audaspace/CMakeLists.txt b/intern/audaspace/CMakeLists.txt index 940a4b2bedc..1b48de3190b 100644 --- a/intern/audaspace/CMakeLists.txt +++ b/intern/audaspace/CMakeLists.txt @@ -53,6 +53,12 @@ IF(WITH_JACK) ADD_DEFINITIONS(-DWITH_JACK) ENDIF(WITH_JACK) -SET(SRC ${SRC} ${FFMPEGSRC} ${SDLSRC} ${OPENALSRC} ${JACKSRC}) +IF(WITH_SNDFILE) + SET(INC ${INC} sndfile ${SNDFILE_INC}) + FILE(GLOB SNDFILESRC sndfile/*.cpp) + ADD_DEFINITIONS(-DWITH_SNDFILE) +ENDIF(WITH_SNDFILE) + +SET(SRC ${SRC} ${FFMPEGSRC} ${SNDFILESRC} ${SDLSRC} ${OPENALSRC} ${JACKSRC}) BLENDERLIB(bf_audaspace "${SRC}" "${INC}") diff --git a/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.cpp b/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.cpp index 5f9006b0ec0..f67c819ff10 100644 --- a/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.cpp +++ b/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.cpp @@ -25,31 +25,24 @@ #include "AUD_FFMPEGFactory.h" #include "AUD_FFMPEGReader.h" -#include "AUD_Space.h" - -extern "C" { -#include -} +#include "AUD_Buffer.h" AUD_FFMPEGFactory::AUD_FFMPEGFactory(const char* filename) { - if(filename != 0) + if(filename != NULL) { m_filename = new char[strlen(filename)+1]; AUD_NEW("string") strcpy(m_filename, filename); } else - m_filename = 0; - m_buffer = 0; - m_size = 0; + m_filename = NULL; } AUD_FFMPEGFactory::AUD_FFMPEGFactory(unsigned char* buffer, int size) { - m_filename = 0; - m_buffer = (unsigned char*)av_malloc(size); AUD_NEW("buffer") - m_size = size; - memcpy(m_buffer, buffer, size); + m_filename = NULL; + m_buffer = AUD_Reference(new AUD_Buffer(size)); + memcpy(m_buffer.get()->getBuffer(), buffer, size); } AUD_FFMPEGFactory::~AUD_FFMPEGFactory() @@ -58,31 +51,15 @@ AUD_FFMPEGFactory::~AUD_FFMPEGFactory() { delete[] m_filename; AUD_DELETE("string") } - if(m_buffer) - { - av_free(m_buffer); AUD_DELETE("buffer") - } } AUD_IReader* AUD_FFMPEGFactory::createReader() { - try - { - AUD_IReader* reader; - if(m_filename) - reader = new AUD_FFMPEGReader(m_filename); - else - reader = new AUD_FFMPEGReader(m_buffer, m_size); - AUD_NEW("reader") - return reader; - } - catch(AUD_Exception e) - { - // return 0 if ffmpeg cannot read the file - if(e.error == AUD_ERROR_FFMPEG) - return 0; - // but throw an exception if the file doesn't exist - else - throw; - } + AUD_IReader* reader; + if(m_filename) + reader = new AUD_FFMPEGReader(m_filename); + else + reader = new AUD_FFMPEGReader(m_buffer); + AUD_NEW("reader") + return reader; } diff --git a/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.h b/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.h index 0a9fcc22c8b..22560303a73 100644 --- a/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.h +++ b/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.h @@ -27,6 +27,8 @@ #define AUD_FFMPEGFACTORY #include "AUD_IFactory.h" +#include "AUD_Reference.h" +class AUD_Buffer; /** * This factory reads a sound file via ffmpeg. @@ -44,12 +46,7 @@ private: /** * The buffer to read from. */ - unsigned char* m_buffer; - - /** - * The size of the buffer. - */ - int m_size; + AUD_Reference m_buffer; public: /** diff --git a/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp b/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp index b79375c2dc5..de0e47300f8 100644 --- a/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp +++ b/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp @@ -158,21 +158,22 @@ AUD_FFMPEGReader::AUD_FFMPEGReader(const char* filename) AUD_NEW("buffer") } -AUD_FFMPEGReader::AUD_FFMPEGReader(unsigned char* buffer, int size) +AUD_FFMPEGReader::AUD_FFMPEGReader(AUD_Reference buffer) { m_position = 0; m_pkgbuf_left = 0; m_byteiocontext = (ByteIOContext*)av_mallocz(sizeof(ByteIOContext)); AUD_NEW("byteiocontext") + m_membuffer = buffer; - if(init_put_byte(m_byteiocontext, buffer, size, 0, + if(init_put_byte(m_byteiocontext, buffer.get()->getBuffer(), buffer.get()->getSize(), 0, NULL, NULL, NULL, NULL) != 0) AUD_THROW(AUD_ERROR_FILE); AVProbeData probe_data; probe_data.filename = ""; - probe_data.buf = buffer; - probe_data.buf_size = size; + probe_data.buf = buffer.get()->getBuffer(); + probe_data.buf_size = buffer.get()->getSize(); AVInputFormat* fmt = av_probe_input_format(&probe_data, 1); // open stream diff --git a/intern/audaspace/ffmpeg/AUD_FFMPEGReader.h b/intern/audaspace/ffmpeg/AUD_FFMPEGReader.h index 645f5f356f0..6e303934f36 100644 --- a/intern/audaspace/ffmpeg/AUD_FFMPEGReader.h +++ b/intern/audaspace/ffmpeg/AUD_FFMPEGReader.h @@ -27,7 +27,9 @@ #define AUD_FFMPEGREADER #include "AUD_IReader.h" +#include "AUD_Reference.h" class AUD_Buffer; + struct AVCodecContext; extern "C" { #include @@ -89,6 +91,11 @@ private: */ int m_stream; + /** + * The memory file to read from, only saved to keep the buffer alive. + */ + AUD_Reference m_membuffer; + /** * Decodes a packet into the given buffer. * \param packet The AVPacket to decode. @@ -109,11 +116,10 @@ public: /** * Creates a new reader. * \param buffer The buffer to read from. - * \param size The size of the buffer. * \exception AUD_Exception Thrown if the buffer specified cannot be read * with ffmpeg. */ - AUD_FFMPEGReader(unsigned char* buffer, int size); + AUD_FFMPEGReader(AUD_Reference buffer); /** * Destroys the reader and closes the file. diff --git a/intern/audaspace/intern/AUD_C-API.cpp b/intern/audaspace/intern/AUD_C-API.cpp index d2c8e94c949..9481e2139e8 100644 --- a/intern/audaspace/intern/AUD_C-API.cpp +++ b/intern/audaspace/intern/AUD_C-API.cpp @@ -25,6 +25,7 @@ #include "AUD_NULLDevice.h" #include "AUD_I3DDevice.h" +#include "AUD_FileFactory.h" #include "AUD_StreamBufferFactory.h" #include "AUD_DelayFactory.h" #include "AUD_LimiterFactory.h" @@ -48,7 +49,6 @@ #endif #ifdef WITH_FFMPEG -#include "AUD_FFMPEGFactory.h" extern "C" { #include } @@ -187,21 +187,13 @@ AUD_SoundInfo AUD_getInfo(AUD_Sound* sound) AUD_Sound* AUD_load(const char* filename) { assert(filename); -#ifdef WITH_FFMPEG - return new AUD_FFMPEGFactory(filename); -#else - return NULL; -#endif + return new AUD_FileFactory(filename); } AUD_Sound* AUD_loadBuffer(unsigned char* buffer, int size) { assert(buffer); -#ifdef WITH_FFMPEG - return new AUD_FFMPEGFactory(buffer, size); -#else - return NULL; -#endif + return new AUD_FileFactory(buffer, size); } AUD_Sound* AUD_bufferSound(AUD_Sound* sound) diff --git a/intern/audaspace/intern/AUD_FileFactory.cpp b/intern/audaspace/intern/AUD_FileFactory.cpp new file mode 100644 index 00000000000..a1f81f49061 --- /dev/null +++ b/intern/audaspace/intern/AUD_FileFactory.cpp @@ -0,0 +1,95 @@ +/* + * $Id: AUD_FFMPEGFactory.cpp 22328 2009-08-09 23:23:19Z gsrb3d $ + * + * ***** BEGIN LGPL LICENSE BLOCK ***** + * + * Copyright 2009 Jörg Hermann Müller + * + * This file is part of AudaSpace. + * + * AudaSpace is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AudaSpace 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with AudaSpace. If not, see . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#include "AUD_FileFactory.h" +#include "AUD_Buffer.h" + +#include + +#ifdef WITH_FFMPEG +#include "AUD_FFMPEGReader.h" +#endif +#ifdef WITH_SNDFILE +#include "AUD_SndFileReader.h" +#endif + +AUD_FileFactory::AUD_FileFactory(const char* filename) +{ + if(filename != NULL) + { + m_filename = new char[strlen(filename)+1]; AUD_NEW("string") + strcpy(m_filename, filename); + } + else + m_filename = NULL; +} + +AUD_FileFactory::AUD_FileFactory(unsigned char* buffer, int size) +{ + m_filename = NULL; + m_buffer = AUD_Reference(new AUD_Buffer(size)); + memcpy(m_buffer.get()->getBuffer(), buffer, size); +} + +AUD_FileFactory::~AUD_FileFactory() +{ + if(m_filename) + { + delete[] m_filename; AUD_DELETE("string") + } +} + +AUD_IReader* AUD_FileFactory::createReader() +{ + AUD_IReader* reader = 0; + +#ifdef WITH_SNDFILE + try + { + if(m_filename) + reader = new AUD_SndFileReader(m_filename); + else + reader = new AUD_SndFileReader(m_buffer); + AUD_NEW("reader") + return reader; + } + catch(AUD_Exception e) {} +#endif + +#ifdef WITH_FFMPEG + try + { + if(m_filename) + reader = new AUD_FFMPEGReader(m_filename); + else + reader = new AUD_FFMPEGReader(m_buffer); + AUD_NEW("reader") + return reader; + } + catch(AUD_Exception e) {} +#endif + + return reader; +} diff --git a/intern/audaspace/intern/AUD_FileFactory.h b/intern/audaspace/intern/AUD_FileFactory.h new file mode 100644 index 00000000000..8badb4429df --- /dev/null +++ b/intern/audaspace/intern/AUD_FileFactory.h @@ -0,0 +1,71 @@ +/* + * $Id: AUD_FFMPEGFactory.h 22328 2009-08-09 23:23:19Z gsrb3d $ + * + * ***** BEGIN LGPL LICENSE BLOCK ***** + * + * Copyright 2009 Jörg Hermann Müller + * + * This file is part of AudaSpace. + * + * AudaSpace is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AudaSpace 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with AudaSpace. If not, see . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#ifndef AUD_FILEFACTORY +#define AUD_FILEFACTORY + +#include "AUD_IFactory.h" +#include "AUD_Reference.h" +class AUD_Buffer; + +/** + * This factory tries to read a sound file via all available file readers. + */ +class AUD_FileFactory : public AUD_IFactory +{ +private: + /** + * The filename of the sound source file. + */ + char* m_filename; + + /** + * The buffer to read from. + */ + AUD_Reference m_buffer; + +public: + /** + * Creates a new factory. + * \param filename The sound file path. + */ + AUD_FileFactory(const char* filename); + + /** + * Creates a new factory. + * \param buffer The buffer to read from. + * \param size The size of the buffer. + */ + AUD_FileFactory(unsigned char* buffer, int size); + + /** + * Destroys the factory. + */ + ~AUD_FileFactory(); + + virtual AUD_IReader* createReader(); +}; + +#endif //AUD_FILEFACTORY diff --git a/intern/audaspace/sndfile/AUD_SndFileFactory.cpp b/intern/audaspace/sndfile/AUD_SndFileFactory.cpp new file mode 100644 index 00000000000..d3c5ea8a273 --- /dev/null +++ b/intern/audaspace/sndfile/AUD_SndFileFactory.cpp @@ -0,0 +1,67 @@ +/* + * $Id: AUD_FFMPEGFactory.cpp 22328 2009-08-09 23:23:19Z gsrb3d $ + * + * ***** BEGIN LGPL LICENSE BLOCK ***** + * + * Copyright 2009 Jörg Hermann Müller + * + * This file is part of AudaSpace. + * + * AudaSpace is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AudaSpace 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with AudaSpace. If not, see . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#include "AUD_SndFileFactory.h" +#include "AUD_SndFileReader.h" +#include "AUD_Buffer.h" + +#include + +AUD_SndFileFactory::AUD_SndFileFactory(const char* filename) +{ + if(filename != NULL) + { + m_filename = new char[strlen(filename)+1]; AUD_NEW("string") + strcpy(m_filename, filename); + } + else + m_filename = NULL; +} + +AUD_SndFileFactory::AUD_SndFileFactory(unsigned char* buffer, int size) +{ + m_filename = NULL; + m_buffer = AUD_Reference(new AUD_Buffer(size)); + memcpy(m_buffer.get()->getBuffer(), buffer, size); +} + +AUD_SndFileFactory::~AUD_SndFileFactory() +{ + if(m_filename) + { + delete[] m_filename; AUD_DELETE("string") + } +} + +AUD_IReader* AUD_SndFileFactory::createReader() +{ + AUD_IReader* reader; + if(m_filename) + reader = new AUD_SndFileReader(m_filename); + else + reader = new AUD_SndFileReader(m_buffer); + AUD_NEW("reader") + return reader; +} diff --git a/intern/audaspace/sndfile/AUD_SndFileFactory.h b/intern/audaspace/sndfile/AUD_SndFileFactory.h new file mode 100644 index 00000000000..6e265a63abe --- /dev/null +++ b/intern/audaspace/sndfile/AUD_SndFileFactory.h @@ -0,0 +1,71 @@ +/* + * $Id: AUD_FFMPEGFactory.h 22328 2009-08-09 23:23:19Z gsrb3d $ + * + * ***** BEGIN LGPL LICENSE BLOCK ***** + * + * Copyright 2009 Jörg Hermann Müller + * + * This file is part of AudaSpace. + * + * AudaSpace is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AudaSpace 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with AudaSpace. If not, see . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#ifndef AUD_SNDFILEFACTORY +#define AUD_SNDFILEFACTORY + +#include "AUD_IFactory.h" +#include "AUD_Reference.h" +class AUD_Buffer; + +/** + * This factory reads a sound file via libsndfile. + */ +class AUD_SndFileFactory : public AUD_IFactory +{ +private: + /** + * The filename of the sound source file. + */ + char* m_filename; + + /** + * The buffer to read from. + */ + AUD_Reference m_buffer; + +public: + /** + * Creates a new factory. + * \param filename The sound file path. + */ + AUD_SndFileFactory(const char* filename); + + /** + * Creates a new factory. + * \param buffer The buffer to read from. + * \param size The size of the buffer. + */ + AUD_SndFileFactory(unsigned char* buffer, int size); + + /** + * Destroys the factory. + */ + ~AUD_SndFileFactory(); + + virtual AUD_IReader* createReader(); +}; + +#endif //AUD_SNDFILEFACTORY diff --git a/intern/audaspace/sndfile/AUD_SndFileReader.cpp b/intern/audaspace/sndfile/AUD_SndFileReader.cpp new file mode 100644 index 00000000000..8daef573d37 --- /dev/null +++ b/intern/audaspace/sndfile/AUD_SndFileReader.cpp @@ -0,0 +1,233 @@ +/* + * $Id: AUD_FFMPEGReader.cpp 22328 2009-08-09 23:23:19Z gsrb3d $ + * + * ***** BEGIN LGPL LICENSE BLOCK ***** + * + * Copyright 2009 Jörg Hermann Müller + * + * This file is part of AudaSpace. + * + * AudaSpace is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AudaSpace 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with AudaSpace. If not, see . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#include "AUD_SndFileReader.h" +#include "AUD_Buffer.h" + +#include + +// This function transforms a SampleFormat to our own sample format +static inline AUD_SampleFormat SNDFILE_TO_AUD(int fmt) +{ + switch(fmt & SF_FORMAT_SUBMASK) + { + // only read s16, s32 and double as they are + case SF_FORMAT_PCM_16: + return AUD_FORMAT_S16; + case SF_FORMAT_PCM_32: + return AUD_FORMAT_S32; + case SF_FORMAT_DOUBLE: + return AUD_FORMAT_FLOAT64; + // read all other formats as floats + default: + return AUD_FORMAT_FLOAT32; + } +} + +sf_count_t AUD_SndFileReader::vio_get_filelen(void *user_data) +{ + AUD_SndFileReader* reader = (AUD_SndFileReader*)user_data; + return reader->m_membuffer.get()->getSize(); +} + +sf_count_t AUD_SndFileReader::vio_seek(sf_count_t offset, int whence, void *user_data) +{ + AUD_SndFileReader* reader = (AUD_SndFileReader*)user_data; + + switch(whence) + { + case SEEK_SET: + reader->m_memoffset = offset; + break; + case SEEK_CUR: + reader->m_memoffset = reader->m_memoffset + offset; + break; + case SEEK_END: + reader->m_memoffset = reader->m_membuffer.get()->getSize() + offset; + break; + } + + return reader->m_memoffset; +} + +sf_count_t AUD_SndFileReader::vio_read(void *ptr, sf_count_t count, void *user_data) +{ + AUD_SndFileReader* reader = (AUD_SndFileReader*)user_data; + + if(reader->m_memoffset + count > reader->m_membuffer.get()->getSize()) + count = reader->m_membuffer.get()->getSize() - reader->m_memoffset; + + memcpy(ptr, reader->m_membuffer.get()->getBuffer() + reader->m_memoffset, count); + reader->m_memoffset += count; + + return count; +} + +sf_count_t AUD_SndFileReader::vio_tell(void *user_data) +{ + AUD_SndFileReader* reader = (AUD_SndFileReader*)user_data; + + return reader->m_memoffset; +} + +AUD_SndFileReader::AUD_SndFileReader(const char* filename) +{ + SF_INFO sfinfo; + + sfinfo.format = 0; + m_sndfile = sf_open(filename, SFM_READ, &sfinfo); + + if(!m_sndfile) + AUD_THROW(AUD_ERROR_FILE); + + m_specs.channels = (AUD_Channels) sfinfo.channels; + m_specs.format = SNDFILE_TO_AUD(sfinfo.format); + m_specs.rate = (AUD_SampleRate) sfinfo.samplerate; + m_length = sfinfo.frames; + m_seekable = sfinfo.seekable; + m_position = 0; + + switch(m_specs.format) + { + case AUD_FORMAT_S16: + m_read = (sf_read_f) sf_readf_short; + break; + case AUD_FORMAT_S32: + m_read = (sf_read_f) sf_readf_int; + break; + case AUD_FORMAT_FLOAT64: + m_read = (sf_read_f) sf_readf_double; + break; + default: + m_read = (sf_read_f) sf_readf_float; + } + + m_buffer = new AUD_Buffer(); AUD_NEW("buffer") +} + +AUD_SndFileReader::AUD_SndFileReader(AUD_Reference buffer) +{ + m_membuffer = buffer; + m_memoffset = 0; + + m_vio.get_filelen = vio_get_filelen; + m_vio.read = vio_read; + m_vio.seek = vio_seek; + m_vio.tell = vio_tell; + m_vio.write = NULL; + + SF_INFO sfinfo; + + sfinfo.format = 0; + m_sndfile = sf_open_virtual(&m_vio, SFM_READ, &sfinfo, this); + + if(!m_sndfile) + AUD_THROW(AUD_ERROR_FILE); + + m_specs.channels = (AUD_Channels) sfinfo.channels; + m_specs.format = SNDFILE_TO_AUD(sfinfo.format); + m_specs.rate = (AUD_SampleRate) sfinfo.samplerate; + m_length = sfinfo.frames; + m_seekable = sfinfo.seekable; + m_position = 0; + + switch(m_specs.format) + { + case AUD_FORMAT_S16: + m_read = (sf_read_f) sf_readf_short; + break; + case AUD_FORMAT_S32: + m_read = (sf_read_f) sf_readf_int; + break; + case AUD_FORMAT_FLOAT64: + m_read = (sf_read_f) sf_readf_double; + break; + default: + m_read = (sf_read_f) sf_readf_float; + } + + m_buffer = new AUD_Buffer(); AUD_NEW("buffer") +} + +AUD_SndFileReader::~AUD_SndFileReader() +{ + sf_close(m_sndfile); + + delete m_buffer; AUD_DELETE("buffer") +} + +bool AUD_SndFileReader::isSeekable() +{ + return m_seekable; +} + +void AUD_SndFileReader::seek(int position) +{ + if(m_seekable) + { + position = sf_seek(m_sndfile, position, SEEK_SET); + m_position = position; + } +} + +int AUD_SndFileReader::getLength() +{ + return m_length; +} + +int AUD_SndFileReader::getPosition() +{ + return m_position; +} + +AUD_Specs AUD_SndFileReader::getSpecs() +{ + return m_specs; +} + +AUD_ReaderType AUD_SndFileReader::getType() +{ + return AUD_TYPE_STREAM; +} + +bool AUD_SndFileReader::notify(AUD_Message &message) +{ + return false; +} + +void AUD_SndFileReader::read(int & length, sample_t* & buffer) +{ + int sample_size = AUD_SAMPLE_SIZE(m_specs); + + // resize output buffer if necessary + if(m_buffer->getSize() < length*sample_size) + m_buffer->resize(length*sample_size); + + buffer = m_buffer->getBuffer(); + + length = m_read(m_sndfile, buffer, length); + + m_position += length; +} diff --git a/intern/audaspace/sndfile/AUD_SndFileReader.h b/intern/audaspace/sndfile/AUD_SndFileReader.h new file mode 100644 index 00000000000..f55c36b47e8 --- /dev/null +++ b/intern/audaspace/sndfile/AUD_SndFileReader.h @@ -0,0 +1,131 @@ +/* + * $Id: AUD_FFMPEGReader.h 22328 2009-08-09 23:23:19Z gsrb3d $ + * + * ***** BEGIN LGPL LICENSE BLOCK ***** + * + * Copyright 2009 Jörg Hermann Müller + * + * This file is part of AudaSpace. + * + * AudaSpace is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AudaSpace 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with AudaSpace. If not, see . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#ifndef AUD_SNDFILEREADER +#define AUD_SNDFILEREADER + +#include "AUD_IReader.h" +#include "AUD_Reference.h" +class AUD_Buffer; + +#include + +typedef sf_count_t (*sf_read_f)(SNDFILE *sndfile, void *ptr, sf_count_t frames); + +/** + * This class reads a sound file via libsndfile. + */ +class AUD_SndFileReader : public AUD_IReader +{ +private: + /** + * The current position in samples. + */ + int m_position; + + /** + * The sample count in the file. + */ + int m_length; + + /** + * Whether the file is seekable. + */ + bool m_seekable; + + /** + * The specification of the audio data. + */ + AUD_Specs m_specs; + + /** + * The playback buffer. + */ + AUD_Buffer* m_buffer; + + /** + * The sndfile. + */ + SNDFILE* m_sndfile; + + /** + * The reading function. + */ + sf_read_f m_read; + + /** + * The virtual IO structure for memory file reading. + */ + SF_VIRTUAL_IO m_vio; + + /** + * The pointer to the memory file. + */ + AUD_Reference m_membuffer; + + /** + * The current reading pointer of the memory file. + */ + int m_memoffset; + + // Functions for libsndfile virtual IO functionality + static sf_count_t vio_get_filelen(void *user_data); + static sf_count_t vio_seek(sf_count_t offset, int whence, void *user_data); + static sf_count_t vio_read(void *ptr, sf_count_t count, void *user_data); + static sf_count_t vio_tell(void *user_data); + +public: + /** + * Creates a new reader. + * \param filename The path to the file to be read. + * \exception AUD_Exception Thrown if the file specified does not exist or + * cannot be read with libsndfile. + */ + AUD_SndFileReader(const char* filename); + + /** + * Creates a new reader. + * \param buffer The buffer to read from. + * \exception AUD_Exception Thrown if the buffer specified cannot be read + * with libsndfile. + */ + AUD_SndFileReader(AUD_Reference buffer); + + /** + * Destroys the reader and closes the file. + */ + virtual ~AUD_SndFileReader(); + + virtual bool isSeekable(); + virtual void seek(int position); + virtual int getLength(); + virtual int getPosition(); + virtual AUD_Specs getSpecs(); + virtual AUD_ReaderType getType(); + virtual bool notify(AUD_Message &message); + virtual void read(int & length, sample_t* & buffer); +}; + +#endif //AUD_SNDFILEREADER From d82935a327203e41da7913b75ab9981d61cdc927 Mon Sep 17 00:00:00 2001 From: "Guillermo S. Romero" Date: Fri, 21 Aug 2009 22:06:19 +0000 Subject: [PATCH 51/73] SVN maintenance. --- intern/audaspace/intern/AUD_FileFactory.cpp | 2 +- intern/audaspace/intern/AUD_FileFactory.h | 2 +- intern/audaspace/sndfile/AUD_SndFileFactory.cpp | 2 +- intern/audaspace/sndfile/AUD_SndFileFactory.h | 2 +- intern/audaspace/sndfile/AUD_SndFileReader.cpp | 2 +- intern/audaspace/sndfile/AUD_SndFileReader.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/intern/audaspace/intern/AUD_FileFactory.cpp b/intern/audaspace/intern/AUD_FileFactory.cpp index a1f81f49061..b63390803b1 100644 --- a/intern/audaspace/intern/AUD_FileFactory.cpp +++ b/intern/audaspace/intern/AUD_FileFactory.cpp @@ -1,5 +1,5 @@ /* - * $Id: AUD_FFMPEGFactory.cpp 22328 2009-08-09 23:23:19Z gsrb3d $ + * $Id$ * * ***** BEGIN LGPL LICENSE BLOCK ***** * diff --git a/intern/audaspace/intern/AUD_FileFactory.h b/intern/audaspace/intern/AUD_FileFactory.h index 8badb4429df..6ab8f280534 100644 --- a/intern/audaspace/intern/AUD_FileFactory.h +++ b/intern/audaspace/intern/AUD_FileFactory.h @@ -1,5 +1,5 @@ /* - * $Id: AUD_FFMPEGFactory.h 22328 2009-08-09 23:23:19Z gsrb3d $ + * $Id$ * * ***** BEGIN LGPL LICENSE BLOCK ***** * diff --git a/intern/audaspace/sndfile/AUD_SndFileFactory.cpp b/intern/audaspace/sndfile/AUD_SndFileFactory.cpp index d3c5ea8a273..bac6dc321f4 100644 --- a/intern/audaspace/sndfile/AUD_SndFileFactory.cpp +++ b/intern/audaspace/sndfile/AUD_SndFileFactory.cpp @@ -1,5 +1,5 @@ /* - * $Id: AUD_FFMPEGFactory.cpp 22328 2009-08-09 23:23:19Z gsrb3d $ + * $Id$ * * ***** BEGIN LGPL LICENSE BLOCK ***** * diff --git a/intern/audaspace/sndfile/AUD_SndFileFactory.h b/intern/audaspace/sndfile/AUD_SndFileFactory.h index 6e265a63abe..98187ff1590 100644 --- a/intern/audaspace/sndfile/AUD_SndFileFactory.h +++ b/intern/audaspace/sndfile/AUD_SndFileFactory.h @@ -1,5 +1,5 @@ /* - * $Id: AUD_FFMPEGFactory.h 22328 2009-08-09 23:23:19Z gsrb3d $ + * $Id$ * * ***** BEGIN LGPL LICENSE BLOCK ***** * diff --git a/intern/audaspace/sndfile/AUD_SndFileReader.cpp b/intern/audaspace/sndfile/AUD_SndFileReader.cpp index 8daef573d37..485818552bb 100644 --- a/intern/audaspace/sndfile/AUD_SndFileReader.cpp +++ b/intern/audaspace/sndfile/AUD_SndFileReader.cpp @@ -1,5 +1,5 @@ /* - * $Id: AUD_FFMPEGReader.cpp 22328 2009-08-09 23:23:19Z gsrb3d $ + * $Id$ * * ***** BEGIN LGPL LICENSE BLOCK ***** * diff --git a/intern/audaspace/sndfile/AUD_SndFileReader.h b/intern/audaspace/sndfile/AUD_SndFileReader.h index f55c36b47e8..da890ef53ca 100644 --- a/intern/audaspace/sndfile/AUD_SndFileReader.h +++ b/intern/audaspace/sndfile/AUD_SndFileReader.h @@ -1,5 +1,5 @@ /* - * $Id: AUD_FFMPEGReader.h 22328 2009-08-09 23:23:19Z gsrb3d $ + * $Id$ * * ***** BEGIN LGPL LICENSE BLOCK ***** * From 9202aaa2dc4b4bf70621c06bc82a5d836a4afc14 Mon Sep 17 00:00:00 2001 From: Diego Borghetti Date: Fri, 21 Aug 2009 22:56:26 +0000 Subject: [PATCH 52/73] Update Makefiles for audaspace. This add support for: sdl, ffmpeg, openal, jack and sndfile. We have new options: WITH_OPENAL, default false WITH_JACK, default false WITH_SNDFILE, default false and with this: NAN_OPENAL, default /usr NAN_JACK, default /usr NAN_JACKCFLAGS, default -I$(NAN_JACK)/include/jack NAN_JACKLIBS, default $(NAN_JACK)/lib/libjack.a NAN_SNDFILE, default /usr NAN_SNDFILECFLAGS, default -I$(NAN_SNDFILE)/include NAN_SNDFILELIBS, default $(NAN_SNDFILE)/lib/libsndfile. Also add two new option on source/Makefile for jack and sndfile libs, but only for linux, so let me know for other OS. --- intern/audaspace/Makefile | 50 +++++++++++++++++++++++++++++-- intern/audaspace/OpenAL/Makefile | 39 ++++++++++++++++++++++++ intern/audaspace/SDL/Makefile | 2 +- intern/audaspace/ffmpeg/Makefile | 2 +- intern/audaspace/intern/Makefile | 25 ++++++++++++++++ intern/audaspace/jack/Makefile | 4 +++ intern/audaspace/sndfile/Makefile | 40 +++++++++++++++++++++++++ source/Makefile | 36 ++++++++++++++++++---- source/nan_definitions.mk | 22 ++++++++++++-- 9 files changed, 207 insertions(+), 13 deletions(-) create mode 100644 intern/audaspace/OpenAL/Makefile create mode 100644 intern/audaspace/sndfile/Makefile diff --git a/intern/audaspace/Makefile b/intern/audaspace/Makefile index 2d66dcf67fa..474f53f0e0f 100644 --- a/intern/audaspace/Makefile +++ b/intern/audaspace/Makefile @@ -44,19 +44,63 @@ ifeq ($(WITH_FFMPEG),true) DIRS += ffmpeg endif +ifeq ($(WITH_OPENAL),true) + DIRS += OpenAL +endif + +ifeq ($(WITH_JACK),true) + DIRS += jack +endif + +ifeq ($(WITH_SNDFILE),true) + DIRS += sndfile +endif + include nan_subdirs.mk install: $(ALL_OR_DEBUG) @[ -d $(NAN_AUDASPACE) ] || mkdir $(NAN_AUDASPACE) @[ -d $(NAN_AUDASPACE)/include ] || mkdir $(NAN_AUDASPACE)/include @[ -d $(NAN_AUDASPACE)/lib/$(DEBUG_DIR) ] || mkdir $(NAN_AUDASPACE)/lib/$(DEBUG_DIR) - @../tools/cpifdiff.sh $(DIR)/$(DEBUG_DIR)libaudaspace.a $(DIR)/$(DEBUG_DIR)libaud_fx.a $(DIR)/$(DEBUG_DIR)libaud_src.a $(NAN_AUDASPACE)/lib/$(DEBUG_DIR) + @../tools/cpifdiff.sh $(DIR)/$(DEBUG_DIR)libaudaspace.a $(DIR)/$(DEBUG_DIR)libaud_sdl.a $(DIR)/$(DEBUG_DIR)libaud_fx.a $(DIR)/$(DEBUG_DIR)libaud_src.a $(NAN_AUDASPACE)/lib/$(DEBUG_DIR) + +ifeq ($(WITH_FFMPEG),true) + @../tools/cpifdiff.sh $(DIR)/$(DEBUG_DIR)libaud_ffmpeg.a $(NAN_AUDASPACE)/lib/$(DEBUG_DIR) +endif + +ifeq ($(WITH_OPENAL),true) + @../tools/cpifdiff.sh $(DIR)/$(DEBUG_DIR)libaud_openal.a $(NAN_AUDASPACE)/lib/$(DEBUG_DIR) +endif + +ifeq ($(WITH_JACK),true) + @../tools/cpifdiff.sh $(DIR)/$(DEBUG_DIR)libaud_jack.a $(NAN_AUDASPACE)/lib/$(DEBUG_DIR) +endif + +ifeq ($(WITH_SNDFILE),true) + @../tools/cpifdiff.sh $(DIR)/$(DEBUG_DIR)libaud_sndfile.a $(NAN_AUDASPACE)/lib/$(DEBUG_DIR) +endif ifeq ($(OS),darwin) ranlib $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaudaspace.a ranlib $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_src.a ranlib $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_fx.a + ranlib $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_sdl.a + +ifeq ($(WITH_FFMPEG),true) + ranlib $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_ffmpeg.a +endif + +ifeq ($(WITH_OPENAL),true) + ranlib $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_openal.a +endif + +ifeq ($(WITH_JACK),true) + ranlib $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_jack.a +endif + +ifeq ($(WITH_SNDFILE),true) + ranlib $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_sndfile.a +endif + endif @../tools/cpifdiff.sh intern/*.h $(NAN_AUDASPACE)/include/ - - diff --git a/intern/audaspace/OpenAL/Makefile b/intern/audaspace/OpenAL/Makefile new file mode 100644 index 00000000000..4cf9f66b06c --- /dev/null +++ b/intern/audaspace/OpenAL/Makefile @@ -0,0 +1,39 @@ +# +# $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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. +# All rights reserved. +# +# The Original Code is: all of this file. +# +# Contributor(s): none yet. +# +# ***** END GPL LICENSE BLOCK ***** +# +# + +LIBNAME = aud_openal +DIR = $(OCGDIR)/intern/audaspace + +include nan_compile.mk + +CCFLAGS += $(LEVEL_1_CPP_WARNINGS) + +CPPFLAGS += -I../intern +CPPFLAGS += -I. diff --git a/intern/audaspace/SDL/Makefile b/intern/audaspace/SDL/Makefile index e36b2de41fe..02a4068f3dc 100644 --- a/intern/audaspace/SDL/Makefile +++ b/intern/audaspace/SDL/Makefile @@ -29,7 +29,7 @@ # LIBNAME = aud_sdl -DIR = $(OCGDIR)/intern/$(LIBNAME) +DIR = $(OCGDIR)/intern/audaspace include nan_compile.mk diff --git a/intern/audaspace/ffmpeg/Makefile b/intern/audaspace/ffmpeg/Makefile index 0bfe6494559..492ac83f532 100644 --- a/intern/audaspace/ffmpeg/Makefile +++ b/intern/audaspace/ffmpeg/Makefile @@ -29,7 +29,7 @@ # LIBNAME = aud_ffmpeg -DIR = $(OCGDIR)/intern/$(LIBNAME) +DIR = $(OCGDIR)/intern/audaspace include nan_compile.mk diff --git a/intern/audaspace/intern/Makefile b/intern/audaspace/intern/Makefile index 2dcc7798f1c..a99f44c54d7 100644 --- a/intern/audaspace/intern/Makefile +++ b/intern/audaspace/intern/Makefile @@ -35,6 +35,31 @@ include nan_compile.mk CCFLAGS += $(LEVEL_1_CPP_WARNINGS) +ifeq ($(WITH_SDL),true) + CPPFLAGS += -DWITH_SDL + CPPFLAGS += $(NAN_SDLCFLAGS) +endif + +ifeq ($(WITH_OPENAL),true) + CPPFLAGS += -DWITH_OPENAL + CPPFLAGS += -I../OpenAL +endif + +ifeq ($(WITH_JACK),true) + CPPFLAGS += -DWITH_JACK + CPPFLAGS += -I$(NAN_JACKCFLAGS) + CPPFLAGS += -I../jack +endif + +ifeq ($(WITH_FFMPEG),true) + CPPFLAGS += -DWITH_FFMPEG + CPPFLAGS += $(NAN_FFMPEGCFLAGS) +endif + +ifeq ($(WITH_SNDFILE),true) + CPPFLAGS += -DWITH_SNDFILE +endif + CPPFLAGS += -I$(LCGDIR)/samplerate/include/ CPPFLAGS += -I../ffmpeg CPPFLAGS += -I../FX diff --git a/intern/audaspace/jack/Makefile b/intern/audaspace/jack/Makefile index a6cc9119c6d..23cadf559c0 100644 --- a/intern/audaspace/jack/Makefile +++ b/intern/audaspace/jack/Makefile @@ -35,6 +35,10 @@ include nan_compile.mk CCFLAGS += $(LEVEL_1_CPP_WARNINGS) +# If we are here, jack is enable. +CPPFLAGS += -DWITH_JACK +CPPFLAGS += $(NAN_JACKCFLAGS) + CPPFLAGS += -I../intern CPPFLAGS += -I.. CPPFLAGS += -I. diff --git a/intern/audaspace/sndfile/Makefile b/intern/audaspace/sndfile/Makefile new file mode 100644 index 00000000000..1cf0b2683fb --- /dev/null +++ b/intern/audaspace/sndfile/Makefile @@ -0,0 +1,40 @@ +# +# $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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. +# All rights reserved. +# +# The Original Code is: all of this file. +# +# Contributor(s): +# +# ***** END GPL LICENSE BLOCK ***** +# +# + +LIBNAME = aud_sndfile +DIR = $(OCGDIR)/intern/audaspace + +include nan_compile.mk + +CCFLAGS += $(LEVEL_1_CPP_WARNINGS) + +CPPFLAGS += -I../intern +CPPFLAGS += -I.. +CPPFLAGS += -I. diff --git a/source/Makefile b/source/Makefile index 8e9f66bbe42..93bd2e23903 100644 --- a/source/Makefile +++ b/source/Makefile @@ -109,11 +109,28 @@ COMLIB += $(OCGDIR)/blender/blenfont/$(DEBUG_DIR)libblenfont.a COMLIB += $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaudaspace.a COMLIB += $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_src.a COMLIB += $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_fx.a +COMLIB += $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_sdl.a COMLIB += $(NAN_SAMPLERATE)/lib/$(DEBUG_DIR)libsamplerate.a COMLIB += $(NAN_LZO)/lib/$(DEBUG_DIR)libminilzo.a COMLIB += $(NAN_LZMA)/lib/$(DEBUG_DIR)liblzma.a COMLIB += $(NAN_SMOKE)/lib/$(DEBUG_DIR)/libsmoke.a +ifeq ($(WITH_FFMPEG),true) + COMLIB += $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_ffmpeg.a +endif + +ifeq ($(WITH_OPENAL),true) + COMLIB += $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_openal.a +endif + +ifeq ($(WITH_JACK),true) + COMLIB += $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_jack.a +endif + +ifeq ($(WITH_SNDFILE),true) + COMLIB += $(NAN_AUDASPACE)/lib/$(DEBUG_DIR)libaud_sndfile.a +endif + ifneq ($(NAN_NO_KETSJI),true) COMLIB += $(OCGDIR)/gameengine/bloutines/$(DEBUG_DIR)libbloutines.a COMLIB += $(OCGDIR)/gameengine/blconverter/$(DEBUG_DIR)libblconverter.a @@ -356,12 +373,7 @@ ifeq ($(OS),solaris) SPLIB += $(NAN_ZLIB)/lib/libz.a endif -# OpenAL libs are already compiled as shared code! - -# Some kooky logic going on here ... -ifeq ($(NAN_NO_OPENAL), true) -# NAN_SND_LIBS = -else +ifeq ($(WITH_OPENAL),true) ifeq ($(OS),$(findstring $(OS), "freebsd linux windows")) ifeq ($(CPU),$(findstring $(CPU), "i386 powerpc x86_64 parisc64")) NAN_SND_LIBS += $(NAN_OPENAL)/lib/libopenal.a @@ -381,6 +393,18 @@ else endif endif +ifeq ($(WITH_JACK),true) + ifeq ($(OS),$(findstring $(OS), "linux")) + NAN_SND_LIBS += $(NAN_JACKLIBS) + endif +endif + +ifeq ($(WITH_SNDFILE),true) + ifeq ($(OS),$(findstring $(OS), "linux")) + NAN_SND_LIBS += $(NAN_SNDFILELIBS) + endif +endif + ifeq ($(OS),windows) # Might need to change this to $(NAN_MOZILLA_LIB)/nspr4.lib diff --git a/source/nan_definitions.mk b/source/nan_definitions.mk index 7fab61d5247..50a606496f5 100644 --- a/source/nan_definitions.mk +++ b/source/nan_definitions.mk @@ -117,6 +117,25 @@ ifndef CONFIG_GUESS export WITH_LZMA ?= true export NAN_LZO ?= $(LCGDIR)/lzo export NAN_LZMA ?= $(LCGDIR)/lzma + export WITH_OPENAL ?= false + export WITH_JACK ?= false + export WITH_SNDFILE ?= false + + ifeq ($(WITH_OPENAL), true) + export NAN_OPENAL ?= /usr + endif + + ifeq ($(WITH_JACK), true) + export NAN_JACK ?= /usr + export NAN_JACKCFLAGS ?= -I$(NAN_JACK)/include/jack + export NAN_JACKLIBS ?= $(NAN_JACK)/lib/libjack.a + endif + + ifeq ($(WITH_SNDFILE),true) + export NAN_SNDFILE ?= /usr + export NAN_SNDFILECFLAGS ?= -I$(NAN_SNDFILE)/include + export NAN_SNDFILELIBS ?= $(NAN_SNDFILE)/lib/libsndfile.a + endif ifeq ($(NAN_USE_FFMPEG_CONFIG), true) export NAN_FFMPEG ?= $(shell ffmpeg-config --prefix) @@ -175,7 +194,7 @@ ifndef CONFIG_GUESS export NAN_NO_KETSJI=false ifeq ($(CPU), i386) - export NAN_NO_OPENAL=true + export WITH_OPENAL=false endif # Location of MOZILLA/Netscape header files... @@ -535,5 +554,4 @@ endif # CONFIG_GUESS # Don't want to build the gameengine? ifeq ($(NAN_NO_KETSJI), true) export NAN_JUST_BLENDERDYNAMIC=true - export NAN_NO_OPENAL=true endif From 2355130c3a6c698eaccf279d2b626809e95a48d6 Mon Sep 17 00:00:00 2001 From: William Reynish Date: Sat, 22 Aug 2009 00:19:24 +0000 Subject: [PATCH 53/73] Added standard hotkeys for standard features like copying, cutting, pasting, saving, loading. Saving/Loading: Save - Ctrl S / Cmd S Save As - Ctrl+Shift S / Cmd+Shift S Open - Ctrl O / Cmd O Open Recent - Ctrl+Shift O / Cmd+Shift O New File - Ctrl N / Cmd N Text: Copy- Ctrl+C / Cmd+C Cut- Ctrl+C / Cmd+C Paste- Ctrl+V / Cmd+V Select text- Ctrl+A / Cmd+A Misc: Repeat Last Op - Ctrl+R / Cmd+R Render - Ctrl+Return / Cmd+Return Render Animation- Shift+Ctrl+Return / Shift+Cmd+Return User Preferences - Ctrl+Comma / Cmd+Comma Changed the important search menu to Space key. Old hotkeys are still preserved, at least for now. --- source/blender/editors/curve/curve_ops.c | 5 +++- source/blender/editors/screen/screen_ops.c | 14 +++++++++-- .../blender/editors/space_text/space_text.c | 8 +++++++ .../windowmanager/intern/wm_operators.c | 24 +++++++++++++------ 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c index 6006c7e656b..d3bcdcb69bb 100644 --- a/source/blender/editors/curve/curve_ops.c +++ b/source/blender/editors/curve/curve_ops.c @@ -202,8 +202,11 @@ void ED_keymap_curve(wmWindowManager *wm) RNA_int_set(WM_keymap_add_item(keymap, "FONT_OT_change_character", DOWNARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "delta", -1); WM_keymap_add_item(keymap, "FONT_OT_text_copy", CKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "FONT_OT_text_copy", CKEY, KM_PRESS, KM_OSKEY, 0); WM_keymap_add_item(keymap, "FONT_OT_text_cut", XKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_add_item(keymap, "FONT_OT_text_paste", PKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "FONT_OT_text_cut", XKEY, KM_PRESS, KM_OSKEY, 0); + WM_keymap_add_item(keymap, "FONT_OT_text_paste", VKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "FONT_OT_text_paste", VKEY, KM_PRESS, KM_OSKEY, 0); WM_keymap_add_item(keymap, "FONT_OT_line_break", RETKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "FONT_OT_text_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last! diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index fab4de50568..380390cf543 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -3298,6 +3298,7 @@ void ED_keymap_screen(wmWindowManager *wm) /* Screen General ------------------------------------------------ */ keymap= WM_keymap_listbase(wm, "Screen", 0, 0); + /* standard timers */ WM_keymap_add_item(keymap, "SCREEN_OT_animation_step", TIMER0, KM_ANY, KM_ANY, 0); @@ -3326,7 +3327,9 @@ void ED_keymap_screen(wmWindowManager *wm) WM_keymap_add_item(keymap, "SCREEN_OT_region_foursplit", SKEY, KM_PRESS, KM_CTRL|KM_ALT|KM_SHIFT, 0); WM_keymap_verify_item(keymap, "SCREEN_OT_repeat_history", F3KEY, KM_PRESS, 0, 0); - WM_keymap_verify_item(keymap, "SCREEN_OT_repeat_last", F4KEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "SCREEN_OT_repeat_last", RKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "SCREEN_OT_repeat_last", RKEY, KM_PRESS, KM_OSKEY, 0); + WM_keymap_add_item(keymap, "SCREEN_OT_repeat_last", F4KEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "SCREEN_OT_region_flip", F5KEY, KM_PRESS, 0, 0); WM_keymap_verify_item(keymap, "SCREEN_OT_redo_last", F6KEY, KM_PRESS, 0, 0); @@ -3345,11 +3348,17 @@ void ED_keymap_screen(wmWindowManager *wm) /* render */ WM_keymap_add_item(keymap, "SCREEN_OT_render", F12KEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "SCREEN_OT_render", RETKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "SCREEN_OT_render", RETKEY, KM_PRESS, KM_OSKEY, 0); RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_render", F12KEY, KM_PRESS, KM_CTRL, 0)->ptr, "animation", 1); + RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_render", RETKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "animation", 1); + RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_render", RETKEY, KM_PRESS, KM_OSKEY|KM_SHIFT, 0)->ptr, "animation", 1); WM_keymap_add_item(keymap, "SCREEN_OT_render_view_cancel", ESCKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "SCREEN_OT_render_view_show", F11KEY, KM_PRESS, 0, 0); /* user prefs */ + WM_keymap_add_item(keymap, "SCREEN_OT_userpref_show", COMMAKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "SCREEN_OT_userpref_show", COMMAKEY, KM_PRESS, KM_OSKEY, 0); WM_keymap_add_item(keymap, "SCREEN_OT_userpref_show", UKEY, KM_PRESS, KM_ALT, 0); /* Anim Playback ------------------------------------------------ */ @@ -3362,7 +3371,8 @@ void ED_keymap_screen(wmWindowManager *wm) RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_offset", RIGHTARROWKEY, KM_PRESS, 0, 0)->ptr, "delta", 1); WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", DOWNARROWKEY, KM_PRESS, KM_SHIFT, 0); - RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", UPARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "end", 1); + RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", RIGHTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "end", 1); + RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", LEFTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "end", 0); WM_keymap_add_item(keymap, "SCREEN_OT_keyframe_jump", PAGEUPKEY, KM_PRESS, KM_CTRL, 0); RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_keyframe_jump", PAGEDOWNKEY, KM_PRESS, KM_CTRL, 0)->ptr, "next", 0); diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index a9c0d3ff76b..4394fbfe1f5 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -210,21 +210,28 @@ static void text_keymap(struct wmWindowManager *wm) WM_keymap_add_item(keymap, "TEXT_OT_open", OKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "TEXT_OT_reload", RKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "TEXT_OT_save", SKEY, KM_PRESS, KM_ALT, 0); + WM_keymap_add_item(keymap, "TEXT_OT_save", SKEY, KM_PRESS, KM_ALT|KM_OSKEY, 0); + WM_keymap_add_item(keymap, "TEXT_OT_save_as", SKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_CTRL, 0); + WM_keymap_add_item(keymap, "TEXT_OT_save_as", SKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_OSKEY, 0); WM_keymap_add_item(keymap, "TEXT_OT_run_script", PKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "TEXT_OT_cut", XKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "TEXT_OT_cut", XKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "TEXT_OT_cut", XKEY, KM_PRESS, KM_OSKEY, 0); WM_keymap_add_item(keymap, "TEXT_OT_copy", CKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "TEXT_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "TEXT_OT_copy", CKEY, KM_PRESS, KM_OSKEY, 0); WM_keymap_add_item(keymap, "TEXT_OT_paste", VKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "TEXT_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "TEXT_OT_paste", VKEY, KM_PRESS, KM_OSKEY, 0); if(U.uiflag & USER_MMB_PASTE) // XXX not dynamic RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_paste", MIDDLEMOUSE, KM_PRESS, 0, 0)->ptr, "selection", 1); WM_keymap_add_item(keymap, "TEXT_OT_jump", JKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "TEXT_OT_find", FKEY, KM_PRESS, KM_ALT, 0); + WM_keymap_add_item(keymap, "TEXT_OT_find", FKEY, KM_PRESS, KM_OSKEY, 0); WM_keymap_add_item(keymap, "TEXT_OT_properties", FKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "TEXT_OT_properties", FKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "TEXT_OT_replace", HKEY, KM_PRESS, KM_ALT, 0); @@ -233,6 +240,7 @@ static void text_keymap(struct wmWindowManager *wm) WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_OSKEY, 0); WM_keymap_add_item(keymap, "TEXT_OT_indent", TABKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "TEXT_OT_unindent", TABKEY, KM_PRESS, KM_SHIFT, 0); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 87a145ceee2..22c7b6ae277 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1908,19 +1908,29 @@ void wm_window_keymap(wmWindowManager *wm) /* note, this doesn't replace existing keymap items */ WM_keymap_verify_item(keymap, "WM_OT_window_duplicate", WKEY, KM_PRESS, KM_CTRL|KM_ALT, 0); - WM_keymap_verify_item(keymap, "WM_OT_read_homefile", XKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_verify_item(keymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_verify_item(keymap, "WM_OT_open_recentfile", OKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_verify_item(keymap, "WM_OT_open_mainfile", F1KEY, KM_PRESS, 0, 0); - WM_keymap_verify_item(keymap, "WM_OT_save_mainfile", WKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_verify_item(keymap, "WM_OT_save_as_mainfile", F2KEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "WM_OT_read_homefile", NKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "WM_OT_read_homefile", NKEY, KM_PRESS, KM_OSKEY, 0); + WM_keymap_add_item(keymap, "WM_OT_read_homefile", XKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_OSKEY, 0); + WM_keymap_add_item(keymap, "WM_OT_open_recentfile", OKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0); + WM_keymap_add_item(keymap, "WM_OT_open_recentfile", OKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0); + WM_keymap_add_item(keymap, "WM_OT_open_mainfile", OKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "WM_OT_open_mainfile", OKEY, KM_PRESS, KM_OSKEY, 0); + WM_keymap_add_item(keymap, "WM_OT_open_mainfile", F1KEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "WM_OT_save_mainfile", SKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "WM_OT_save_mainfile", SKEY, KM_PRESS, KM_OSKEY, 0); + WM_keymap_add_item(keymap, "WM_OT_save_mainfile", WKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", SKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0); + WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", SKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0); + WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", F2KEY, KM_PRESS, 0, 0); WM_keymap_verify_item(keymap, "WM_OT_window_fullscreen_toggle", F11KEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_verify_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0); /* debug/testing */ WM_keymap_verify_item(keymap, "WM_OT_ten_timer", TKEY, KM_PRESS, KM_ALT|KM_CTRL, 0); WM_keymap_verify_item(keymap, "WM_OT_debug_menu", DKEY, KM_PRESS, KM_ALT|KM_CTRL, 0); - WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0); } From 095ec3a6e9357e6ce14fd200396ea221ac88e3b6 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sat, 22 Aug 2009 01:01:53 +0000 Subject: [PATCH 54/73] 2.5/Multires: * Disabled multires subdivide button in editmode (again) SVN weirdness: I already did this in r22447. Somehow it got changed back -- but I can't find any log of it getting reverted, either in my email or on p.b.o. This is extremely weird! --- source/blender/editors/object/object_modifier.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 3785e17f67c..1b20f90360a 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -699,7 +699,8 @@ static int multires_subdivide_exec(bContext *C, wmOperator *op) static int multires_subdivide_poll(bContext *C) { - return (CTX_data_pointer_get_type(C, "modifier", &RNA_MultiresModifier).data != NULL); + return (CTX_data_pointer_get_type(C, "modifier", &RNA_MultiresModifier).data != NULL) && + CTX_data_edit_object(C) == NULL; } void OBJECT_OT_multires_subdivide(wmOperatorType *ot) From 0be1e72dca48a6709c2ae8b3805387d4ef5bcdcb Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sat, 22 Aug 2009 02:27:37 +0000 Subject: [PATCH 55/73] 2.5/Vertex paint: * Added operator for filling vertex colors with the brush color * Pythonized the vertex paint menu --- release/ui/space_view3d.py | 28 ++++++-- .../editors/sculpt_paint/paint_intern.h | 3 + .../blender/editors/sculpt_paint/paint_ops.c | 27 +++++++ .../editors/sculpt_paint/paint_vertex.c | 42 +++-------- .../editors/space_view3d/view3d_header.c | 70 ------------------- 5 files changed, 65 insertions(+), 105 deletions(-) diff --git a/release/ui/space_view3d.py b/release/ui/space_view3d.py index 0b08b213cd4..ae04c8875ce 100644 --- a/release/ui/space_view3d.py +++ b/release/ui/space_view3d.py @@ -12,6 +12,7 @@ class VIEW3D_HT_header(bpy.types.Header): view = context.space_data mode_string = context.mode edit_object = context.edit_object + object = context.active_object row = layout.row(align=True) row.template_header() @@ -26,12 +27,14 @@ class VIEW3D_HT_header(bpy.types.Header): if mode_string not in ('EDIT_TEXT', 'SCULPT', 'PAINT_WEIGHT', 'PAINT_VERTEX', 'PAINT_TEXTURE', 'PARTICLE'): # XXX: Particle Mode has Select Menu. sub.itemM("VIEW3D_MT_select_%s" % mode_string) - - if mode_string == 'OBJECT': + + if object.mode == 'OBJECT': sub.itemM("VIEW3D_MT_object") - elif mode_string == 'SCULPT': + elif object.mode == 'SCULPT': sub.itemM("VIEW3D_MT_sculpt") - elif edit_object: + elif object.mode == 'VERTEX_PAINT': + sub.itemM("VIEW3D_MT_vertex_paint") + elif object.mode: sub.itemM("VIEW3D_MT_edit_%s" % edit_object.type) layout.template_header_3D() @@ -480,6 +483,21 @@ class VIEW3D_MT_object_show(bpy.types.Menu): layout.itemO("object.restrictview_set") layout.item_booleanO("object.restrictview_set", "unselected", True, text="Hide Unselected") +# ********** Vertex paint menu ********** + +class VIEW3D_MT_vertex_paint(bpy.types.Menu): + __space_type__ = "VIEW_3D" + __label__ = "Paint" + + def draw(self, context): + layout = self.layout + + sculpt = context.tool_settings.sculpt + + layout.itemO("paint.vertex_color_set") + props = layout.itemO("paint.vertex_color_set", text="Set Selected Vertex Colors", properties=True) + props.selected = True + # ********** Sculpt menu ********** class VIEW3D_MT_sculpt(bpy.types.Menu): @@ -1076,6 +1094,8 @@ bpy.types.register(VIEW3D_MT_object_show) bpy.types.register(VIEW3D_MT_sculpt) # Sculpt Menu +bpy.types.register(VIEW3D_MT_vertex_paint) + bpy.types.register(VIEW3D_MT_edit_snap) # Edit Menus bpy.types.register(VIEW3D_MT_edit_MESH) diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index a0187566c43..ba1b57a1bef 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -57,6 +57,9 @@ int paint_poll(bContext *C); void paint_cursor_start(struct bContext *C, int (*poll)(struct bContext *C)); /* paint_vertex.c */ +int vertex_paint_mode_poll(bContext *C); +void clear_vpaint(Scene *scene, int selected); + void PAINT_OT_weight_paint_toggle(struct wmOperatorType *ot); void PAINT_OT_weight_paint_radial_control(struct wmOperatorType *ot); void PAINT_OT_weight_paint(struct wmOperatorType *ot); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 1ea612c0aa5..c38b36007e9 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -77,6 +77,32 @@ void BRUSH_OT_add(wmOperatorType *ot) RNA_def_enum(ot->srna, "type", brush_type_items, OB_MODE_VERTEX_PAINT, "Type", "Which paint mode to create the brush for."); } +static int vertex_color_set_exec(bContext *C, wmOperator *op) +{ + int selected = RNA_boolean_get(op->ptr, "selected"); + Scene *scene = CTX_data_scene(C); + + clear_vpaint(scene, selected); + + return OPERATOR_FINISHED; +} + +void PAINT_OT_vertex_color_set(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Set Vertex Colors"; + ot->idname= "PAINT_OT_vertex_color_set"; + + /* api callbacks */ + ot->exec= vertex_color_set_exec; + ot->poll= vertex_paint_mode_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + RNA_def_boolean(ot->srna, "selected", 0, "Type", "Only color selected faces."); +} + /**************************** registration **********************************/ void ED_operatortypes_paint(void) @@ -103,5 +129,6 @@ void ED_operatortypes_paint(void) WM_operatortype_append(PAINT_OT_vertex_paint_radial_control); WM_operatortype_append(PAINT_OT_vertex_paint_toggle); WM_operatortype_append(PAINT_OT_vertex_paint); + WM_operatortype_append(PAINT_OT_vertex_color_set); } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index bc2ac480657..ee3d9e5baa1 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -110,11 +110,18 @@ static void error() {} /* polling - retrieve whether cursor should be set or operator should be done */ -static int vp_poll(bContext *C) + +/* Returns true if vertex paint mode is active */ +int vertex_paint_mode_poll(bContext *C) { Object *ob = CTX_data_active_object(C); - if(ob && ob->mode & OB_MODE_VERTEX_PAINT && + return ob && ob->mode == OB_MODE_VERTEX_PAINT; +} + +static int vp_poll(bContext *C) +{ + if(vertex_paint_mode_poll(C) && paint_brush(&CTX_data_tool_settings(C)->vpaint->paint)) { ScrArea *sa= CTX_wm_area(C); if(sa->spacetype==SPACE_VIEW3D) { @@ -323,34 +330,7 @@ static void copy_wpaint_prev (VPaint *wp, MDeformVert *dverts, int dcount) } -void clear_vpaint(Scene *scene) -{ - Mesh *me; - Object *ob; - unsigned int *to, paintcol; - int a; - - ob= OBACT; - me= get_mesh(ob); - if(!ob || ob->id.lib) return; - - if(!(ob->mode & OB_MODE_VERTEX_PAINT)) return; - - if(me==0 || me->mcol==0 || me->totface==0) return; - - paintcol= vpaint_get_current_col(scene->toolsettings->vpaint); - - to= (unsigned int *)me->mcol; - a= 4*me->totface; - while(a--) { - *to= paintcol; - to++; - } - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - -} - -void clear_vpaint_selectedfaces(Scene *scene) +void clear_vpaint(Scene *scene, int selected) { Mesh *me; MFace *mf; @@ -370,7 +350,7 @@ void clear_vpaint_selectedfaces(Scene *scene) mf = me->mface; mcol = (unsigned int*)me->mcol; for (i = 0; i < me->totface; i++, mf++, mcol+=4) { - if (mf->flag & ME_FACE_SEL) { + if (!selected || mf->flag & ME_FACE_SEL) { mcol[0] = paintcol; mcol[1] = paintcol; mcol[2] = paintcol; diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 9fa1b222868..73cd65cafcd 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -2426,71 +2426,6 @@ static void view3d_pose_armaturemenu(bContext *C, uiLayout *layout, void *arg_un #endif } - -/* vertex paint menu */ -static void do_view3d_vpaintmenu(bContext *C, void *arg, int event) -{ -#if 0 - /* events >= 3 are registered bpython scripts */ -#ifndef DISABLE_PYTHON - if (event >= 3) BPY_menu_do_python(PYMENU_VERTEXPAINT, event - 3); -#endif - switch(event) { - case 0: /* undo vertex painting */ - BIF_undo(); - break; - case 1: /* set vertex colors/weight */ - if(paint_facesel_test(CTX_data_active_object(C))) - clear_vpaint_selectedfaces(); - else /* we know were in vertex paint mode */ - clear_vpaint(); - break; - case 2: - make_vertexcol(1); - break; - } -#endif -} - -static uiBlock *view3d_vpaintmenu(bContext *C, ARegion *ar, void *arg_unused) -{ - uiBlock *block; - short yco= 0, menuwidth=120; -#ifndef DISABLE_PYTHON -// XXX BPyMenu *pym; -// int i=0; -#endif - - block= uiBeginBlock(C, ar, "view3d_paintmenu", UI_EMBOSSP); - uiBlockSetButmFunc(block, do_view3d_vpaintmenu, NULL); - - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Undo Vertex Painting|U", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set Vertex Colors|Shift K", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set Shaded Vertex Colors", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); - -#ifndef DISABLE_PYTHON - /* note that we account for the 3 previous entries with i+3: - even if the last item isnt displayed, it dosent matter */ -// for (pym = BPyMenuTable[PYMENU_VERTEXPAINT]; pym; pym = pym->next, i++) { -// uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, -// menuwidth, 19, NULL, 0.0, 0.0, 1, i+3, -// pym->tooltip?pym->tooltip:pym->filename); -// } -#endif - - if(ar->alignment==RGN_ALIGN_TOP) { - uiBlockSetDirection(block, UI_DOWN); - } - else { - uiBlockSetDirection(block, UI_TOP); - uiBlockFlipOrder(block); - } - - uiTextBoundsBlock(block, 50); - return block; -} - - /* texture paint menu (placeholder, no items yet??) */ static void do_view3d_tpaintmenu(bContext *C, void *arg, int event) { @@ -3050,11 +2985,6 @@ static void view3d_header_pulldowns(const bContext *C, uiBlock *block, Object *o uiDefPulldownBut(block, view3d_wpaintmenu, NULL, "Paint", xco,yco, xmax-3, 20, ""); xco+= xmax; } - else if (ob && ob->mode & OB_MODE_VERTEX_PAINT) { - xmax= GetButStringLength("Paint"); - uiDefPulldownBut(block, view3d_vpaintmenu, NULL, "Paint", xco,yco, xmax-3, 20, ""); - xco+= xmax; - } else if (ob && ob->mode & OB_MODE_TEXTURE_PAINT) { xmax= GetButStringLength("Paint"); uiDefPulldownBut(block, view3d_tpaintmenu, NULL, "Paint", xco,yco, xmax-3, 20, ""); From 98272a0138454311ada78f3a8b4e90e6f61aebc9 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Sat, 22 Aug 2009 02:53:14 +0000 Subject: [PATCH 56/73] 2.5 - Code shuffling Moved WeightPaint/VertexPaint toggling hotkeys to the same place that the ones for PoseMode/EditMode are defined. This means that the hotkey for toggling PoseMode works again (instead of being overwritten by WeightPaint). --- source/blender/editors/object/object_ops.c | 9 +++++++++ source/blender/editors/space_view3d/view3d_ops.c | 7 ------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index 6f1a3b5f6cb..239b162c14f 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -167,10 +167,19 @@ void ED_operatortypes_object(void) void ED_keymap_object(wmWindowManager *wm) { ListBase *keymap= WM_keymap_listbase(wm, "Object Non-modal", 0, 0); + wmKeymapItem *kmi; /* Note: this keymap works disregarding mode */ WM_keymap_add_item(keymap, "OBJECT_OT_editmode_toggle", TABKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "OBJECT_OT_posemode_toggle", TABKEY, KM_PRESS, KM_CTRL, 0); + + kmi = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", VKEY, KM_PRESS, 0, 0); + RNA_enum_set(kmi->ptr, "mode", OB_MODE_VERTEX_PAINT); + RNA_boolean_set(kmi->ptr, "toggle", 1); + kmi = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", TABKEY, KM_PRESS, KM_CTRL, 0); + RNA_enum_set(kmi->ptr, "mode", OB_MODE_WEIGHT_PAINT); + RNA_boolean_set(kmi->ptr, "toggle", 1); + WM_keymap_add_item(keymap, "OBJECT_OT_center_set", CKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_CTRL, 0); /* Note: this keymap gets disabled in non-objectmode, */ diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index b0eabae3f5d..929272bc066 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -106,13 +106,6 @@ void view3d_keymap(wmWindowManager *wm) ListBase *keymap= WM_keymap_listbase(wm, "View3D Generic", SPACE_VIEW3D, 0); wmKeymapItem *km; - km = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", VKEY, KM_PRESS, 0, 0); - RNA_enum_set(km->ptr, "mode", OB_MODE_VERTEX_PAINT); - RNA_boolean_set(km->ptr, "toggle", 1); - km = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", TABKEY, KM_PRESS, KM_CTRL, 0); - RNA_enum_set(km->ptr, "mode", OB_MODE_WEIGHT_PAINT); - RNA_boolean_set(km->ptr, "toggle", 1); - WM_keymap_add_item(keymap, "VIEW3D_OT_properties", NKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "VIEW3D_OT_toolbar", TKEY, KM_PRESS, 0, 0); From 17e3b09e88ad48c1659f2c586c33a725a3bd601f Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Sat, 22 Aug 2009 03:10:52 +0000 Subject: [PATCH 57/73] 2.5 - Timeline now updates correctly after keyframes have been edited --- source/blender/editors/space_time/space_time.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/blender/editors/space_time/space_time.c b/source/blender/editors/space_time/space_time.c index f18da93c35d..ce6846a4489 100644 --- a/source/blender/editors/space_time/space_time.c +++ b/source/blender/editors/space_time/space_time.c @@ -260,11 +260,15 @@ static void time_main_area_listener(ARegion *ar, wmNotifier *wmn) { /* context changes */ switch(wmn->category) { + case NC_ANIMATION: + ED_region_tag_redraw(ar); + break; case NC_SCENE: /* any scene change for now */ ED_region_tag_redraw(ar); break; + } } From d4407115faaf89061eed36cb69664f071db3fa31 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Sat, 22 Aug 2009 04:11:17 +0000 Subject: [PATCH 58/73] Hook Modifier Bugfixes: Fixed some typos made in previous commit. Hook Modifier should now work correctly again (and also for newly added Hook relationships) Notes: * To add a hook, you currently need to perform the following steps 1) add modifier from menu (no operator in EditMode) 2) specify the object (and/or bone to use as the hook target) 3a) in EditMode, select the vertices you wish to be affected by the hook, and press 'Assign' 3b) alternatively, fill in the vertex-group field for the Vertex Group which contains the vertices to be affected 4) press 'Reset' (to make sure hook will behave correctly) 5) optionally, also press 'Recenter' if the hook position isn't right... * BUG ALERT (Brecht/Ton): it is impossible to clear the vertexgroup/bone fields once you have assigned some value. Doing backspace+enter (or any other variation) will always result in the first item in the search menu being used. --- source/blender/blenkernel/intern/modifier.c | 9 +++-- source/blender/editors/object/object_edit.c | 40 ++++++++++--------- .../blender/editors/object/object_modifier.c | 2 +- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 6da2c94fab8..1cb163a4de7 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -5657,7 +5657,7 @@ static void hookModifier_deformVerts( { HookModifierData *hmd = (HookModifierData*) md; bPoseChannel *pchan= get_pose_channel(hmd->object->pose, hmd->subtarget); - float vec[3], mat[4][4], dmat[4][4], imat[4][4]; + float vec[3], mat[4][4], dmat[4][4]; int i; DerivedMesh *dm = derivedData; @@ -5670,8 +5670,8 @@ static void hookModifier_deformVerts( /* just object target */ Mat4CpyMat4(dmat, hmd->object->obmat); } - Mat4Invert(imat, dmat); - Mat4MulSerie(mat, imat, dmat, hmd->parentinv, + Mat4Invert(ob->imat, ob->obmat); + Mat4MulSerie(mat, ob->imat, dmat, hmd->parentinv, NULL, NULL, NULL, NULL, NULL); /* vertex indices? */ @@ -5728,7 +5728,8 @@ static void hookModifier_deformVerts( } } } - } else { /* vertex group hook */ + } + else if(hmd->name[0]) { /* vertex group hook */ bDeformGroup *curdef; Mesh *me = ob->data; int index = 0; diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 8ac12a5e3a4..3d2ddba3757 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -1384,9 +1384,11 @@ void add_hook(Scene *scene, View3D *v3d, int mode) modifier_free(md); } else if(mode==5) { /* select */ + // FIXME: this is now OBJECT_OT_hook_select object_hook_select(obedit, hmd); } else if(mode==6) { /* clear offset */ + // FIXME: this is now OBJECT_OT_hook_reset operator where_is_object(scene, ob); /* ob is hook->parent */ Mat4Invert(ob->imat, ob->obmat); @@ -1398,25 +1400,6 @@ void add_hook(Scene *scene, View3D *v3d, int mode) DAG_scene_sort(scene); } - -/* use this when the loc/size/rot of the parent has changed but the children should stay in the same place - * apply-size-rot or object center for eg */ -static void ignore_parent_tx(Scene *scene, Object *ob ) -{ - Object workob; - Object *ob_child; - - /* a change was made, adjust the children to compensate */ - for (ob_child=G.main->object.first; ob_child; ob_child=ob_child->id.next) { - if (ob_child->parent == ob) { - ED_object_apply_obmat(ob_child); - what_does_parent(scene, ob_child, &workob); - Mat4Invert(ob_child->parentinv, workob.obmat); - } - } -} - - void add_hook_menu(Scene *scene, View3D *v3d) { Object *obedit= scene->obedit; // XXX get from context @@ -1435,6 +1418,25 @@ void add_hook_menu(Scene *scene, View3D *v3d) add_hook(scene, v3d, mode); } + + +/* use this when the loc/size/rot of the parent has changed but the children should stay in the same place + * apply-size-rot or object center for eg */ +static void ignore_parent_tx(Scene *scene, Object *ob ) +{ + Object workob; + Object *ob_child; + + /* a change was made, adjust the children to compensate */ + for (ob_child=G.main->object.first; ob_child; ob_child=ob_child->id.next) { + if (ob_child->parent == ob) { + ED_object_apply_obmat(ob_child); + what_does_parent(scene, ob_child, &workob); + Mat4Invert(ob_child->parentinv, workob.obmat); + } + } +} + /* ******************** clear parent operator ******************* */ static EnumPropertyItem prop_clear_parent_types[] = { diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 1b20f90360a..ec46cea8e84 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -865,7 +865,7 @@ static int hook_reset_exec(bContext *C, wmOperator *op) Mat4MulMat4(mat, pchan->pose_mat, hmd->object->obmat); Mat4Invert(imat, mat); - Mat4MulSerie(hmd->parentinv, imat, mat, NULL, NULL, NULL, NULL, NULL, NULL); + Mat4MulSerie(hmd->parentinv, imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); } else { Mat4Invert(hmd->object->imat, hmd->object->obmat); From b20f4e46c686f9c9fb0043eb3b95f639773d4a41 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 22 Aug 2009 05:46:03 +0000 Subject: [PATCH 59/73] remove -Wnested-externs warning for CMake/unix, since this is used a lot, if we want to remove it can be re-enabled. fix view3d python errors with no object/edit object. --- CMakeLists.txt | 14 +++++++++++++- release/ui/space_view3d.py | 19 +++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 749284def28..8ef4296e266 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,7 @@ OPTION(WITH_FFTW3 "Enable FFTW3 support" OFF) OPTION(WITH_JACK "Enable Jack Support (http://www.jackaudio.org)" OFF) OPTION(WITH_SNDFILE "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF) OPTION(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation" OFF) +# OPTION(WITH_BUILDINFO "Include extra build details" ON) OPTION(WITH_INSTALL "Install accompanying scripts and language files needed to run blender" ON) IF(NOT WITH_GAMEENGINE AND WITH_PLAYER) @@ -212,7 +213,7 @@ IF(UNIX AND NOT APPLE) SET(PLATFORM_LINKFLAGS "-pthread") # Better warnings - SET(C_WARNINGS "-Wall -Wno-char-subscripts -Wpointer-arith -Wcast-align -Wnested-externs -Wdeclaration-after-statement") + SET(C_WARNINGS "-Wall -Wno-char-subscripts -Wpointer-arith -Wcast-align -Wdeclaration-after-statement") SET(CXX_WARNINGS "-Wall -Wno-invalid-offsetof -Wno-sign-compare") INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIR} ${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ) @@ -511,6 +512,17 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Linux") SET(BINRELOC_INC ${BINRELOC}/include) ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux") + +# TODO - buildinfo +# IF(UNIX) +# IF(WITH_BUILDINFO) +# EXEC_PROGRAM("date \"+%Y-%m-%d\"" OUTPUT_VARIABLE BUILD_DATE) +# EXEC_PROGRAM("date \"+%H:%M:%S\"" OUTPUT_VARIABLE BUILD_TIME) +# EXEC_PROGRAM("svnversion ${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE BUILD_REV) +# SET(BUILD_TYPE ${CMAKE_BUILD_TYPE}) +# ENDIF(WITH_BUILDINFO) +# ENDIF(UNIX) + #----------------------------------------------------------------------------- # Common. diff --git a/release/ui/space_view3d.py b/release/ui/space_view3d.py index ae04c8875ce..f9e185f44f2 100644 --- a/release/ui/space_view3d.py +++ b/release/ui/space_view3d.py @@ -27,15 +27,18 @@ class VIEW3D_HT_header(bpy.types.Header): if mode_string not in ('EDIT_TEXT', 'SCULPT', 'PAINT_WEIGHT', 'PAINT_VERTEX', 'PAINT_TEXTURE', 'PARTICLE'): # XXX: Particle Mode has Select Menu. sub.itemM("VIEW3D_MT_select_%s" % mode_string) - - if object.mode == 'OBJECT': - sub.itemM("VIEW3D_MT_object") - elif object.mode == 'SCULPT': - sub.itemM("VIEW3D_MT_sculpt") - elif object.mode == 'VERTEX_PAINT': - sub.itemM("VIEW3D_MT_vertex_paint") - elif object.mode: + + if edit_object: sub.itemM("VIEW3D_MT_edit_%s" % edit_object.type) + elif object: + ob_mode_string = object.mode + + if ob_mode_string == 'OBJECT': + sub.itemM("VIEW3D_MT_object") + elif ob_mode_string == 'SCULPT': + sub.itemM("VIEW3D_MT_sculpt") + elif ob_mode_string == 'VERTEX_PAINT': + sub.itemM("VIEW3D_MT_vertex_paint") layout.template_header_3D() From 9e3ac3c1f2cbd44cbb821d266400d70320ac6ccc Mon Sep 17 00:00:00 2001 From: William Reynish Date: Sat, 22 Aug 2009 08:06:54 +0000 Subject: [PATCH 60/73] Added extra padding for OS X at the top of the screen when opening user prefs. The window header was still getting clipped slightly behind the menu bar. --- source/blender/windowmanager/intern/wm_window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 27a1b076a28..d70516ef02e 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -91,7 +91,7 @@ static void wm_window_check_position(rcti *rect) wm_get_screensize(&width, &height); #ifdef __APPLE__ - height -= 42; + height -= 70; #endif if(rect->xmin < 0) { From 977a50ad77b8c31329a6fb6117741c83a984a763 Mon Sep 17 00:00:00 2001 From: Andrea Weikert Date: Sat, 22 Aug 2009 08:35:39 +0000 Subject: [PATCH 61/73] 2.5 MSVC projectfiles maintenance * AUD_filefactory added. * imbuf added to RNA include dirs. --- intern/audaspace/make/msvc_9_0/audaspace.vcproj | 15 ++++++++------- .../blender/makesrna/RNA_makesrna.vcproj | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/intern/audaspace/make/msvc_9_0/audaspace.vcproj b/intern/audaspace/make/msvc_9_0/audaspace.vcproj index a4d775a415c..67ab4d44d72 100644 --- a/intern/audaspace/make/msvc_9_0/audaspace.vcproj +++ b/intern/audaspace/make/msvc_9_0/audaspace.vcproj @@ -380,6 +380,14 @@ RelativePath="..\..\intern\AUD_ConverterReader.h" > + + + + @@ -723,13 +731,6 @@ - - - Date: Sat, 22 Aug 2009 08:48:01 +0000 Subject: [PATCH 62/73] use '' for enums rather then "" --- release/io/engine_render_pov.py | 4 +- release/ui/buttons_data_armature.py | 8 +- release/ui/buttons_data_bone.py | 6 +- release/ui/buttons_data_camera.py | 4 +- release/ui/buttons_data_curve.py | 8 +- release/ui/buttons_data_empty.py | 4 +- release/ui/buttons_data_lamp.py | 4 +- release/ui/buttons_data_lattice.py | 4 +- release/ui/buttons_data_mesh.py | 28 +++---- release/ui/buttons_data_metaball.py | 4 +- release/ui/buttons_data_modifier.py | 6 +- release/ui/buttons_data_text.py | 4 +- release/ui/buttons_game.py | 12 +-- release/ui/buttons_material.py | 8 +- release/ui/buttons_object.py | 8 +- release/ui/buttons_object_constraint.py | 8 +- release/ui/buttons_particle.py | 40 +++++----- release/ui/buttons_physics_cloth.py | 8 +- release/ui/buttons_physics_field.py | 14 ++-- release/ui/buttons_physics_fluid.py | 4 +- release/ui/buttons_physics_smoke.py | 12 +-- release/ui/buttons_physics_softbody.py | 8 +- release/ui/buttons_scene.py | 18 ++--- release/ui/buttons_texture.py | 4 +- release/ui/buttons_world.py | 4 +- release/ui/space_buttons.py | 4 +- release/ui/space_console.py | 6 +- release/ui/space_filebrowser.py | 2 +- release/ui/space_image.py | 40 +++++----- release/ui/space_info.py | 18 ++--- release/ui/space_logic.py | 4 +- release/ui/space_node.py | 8 +- release/ui/space_outliner.py | 4 +- release/ui/space_sequencer.py | 22 ++--- release/ui/space_text.py | 26 +++--- release/ui/space_time.py | 12 +-- release/ui/space_userpref.py | 18 ++--- release/ui/space_view3d.py | 102 ++++++++++++------------ release/ui/space_view3d_toolbar.py | 8 +- 39 files changed, 253 insertions(+), 253 deletions(-) diff --git a/release/io/engine_render_pov.py b/release/io/engine_render_pov.py index 539f705a6ee..51aa26f7fb9 100644 --- a/release/io/engine_render_pov.py +++ b/release/io/engine_render_pov.py @@ -791,8 +791,8 @@ for member in dir(buttons_material): del buttons_material class RenderButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "scene" # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here diff --git a/release/ui/buttons_data_armature.py b/release/ui/buttons_data_armature.py index 9b640776a9e..3a1de0d5f0b 100644 --- a/release/ui/buttons_data_armature.py +++ b/release/ui/buttons_data_armature.py @@ -2,8 +2,8 @@ import bpy class DataButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "data" def poll(self, context): @@ -90,8 +90,8 @@ class DATA_PT_bone_groups(DataButtonsPanel): col = row.column(align=True) col.active = (ob.proxy == None) - col.itemO("pose.group_add", icon="ICON_ZOOMIN", text="") - col.itemO("pose.group_remove", icon="ICON_ZOOMOUT", text="") + col.itemO("pose.group_add", icon='ICON_ZOOMIN', text="") + col.itemO("pose.group_remove", icon='ICON_ZOOMOUT', text="") group = pose.active_bone_group if group: diff --git a/release/ui/buttons_data_bone.py b/release/ui/buttons_data_bone.py index 1eb09377892..17c9c2d89d9 100644 --- a/release/ui/buttons_data_bone.py +++ b/release/ui/buttons_data_bone.py @@ -2,8 +2,8 @@ import bpy class BoneButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "bone" def poll(self, context): @@ -20,7 +20,7 @@ class BONE_PT_context_bone(BoneButtonsPanel): bone = context.edit_bone row = layout.row() - row.itemL(text="", icon="ICON_BONE_DATA") + row.itemL(text="", icon='ICON_BONE_DATA') row.itemR(bone, "name", text="") class BONE_PT_transform(BoneButtonsPanel): diff --git a/release/ui/buttons_data_camera.py b/release/ui/buttons_data_camera.py index f2fa4207ec8..0480897d641 100644 --- a/release/ui/buttons_data_camera.py +++ b/release/ui/buttons_data_camera.py @@ -2,8 +2,8 @@ import bpy class DataButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "data" def poll(self, context): diff --git a/release/ui/buttons_data_curve.py b/release/ui/buttons_data_curve.py index 35d557afe32..92e414ba2f3 100644 --- a/release/ui/buttons_data_curve.py +++ b/release/ui/buttons_data_curve.py @@ -2,8 +2,8 @@ import bpy class DataButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "data" def poll(self, context): @@ -80,13 +80,13 @@ class DATA_PT_geometry_curve(DataButtonsPanel): sub.itemL(text="Modification:") sub.itemR(curve, "width") sub.itemR(curve, "extrude") - sub.itemR(curve, "taper_object", icon="ICON_OUTLINER_OB_CURVE") + sub.itemR(curve, "taper_object", icon='ICON_OUTLINER_OB_CURVE') sub = split.column() sub.itemL(text="Bevel:") sub.itemR(curve, "bevel_depth", text="Depth") sub.itemR(curve, "bevel_resolution", text="Resolution") - sub.itemR(curve, "bevel_object", icon="ICON_OUTLINER_OB_CURVE") + sub.itemR(curve, "bevel_object", icon='ICON_OUTLINER_OB_CURVE') class DATA_PT_pathanim(DataButtonsPanel): __label__ = "Path Animation" diff --git a/release/ui/buttons_data_empty.py b/release/ui/buttons_data_empty.py index 2a2f51ed292..98c9b88e9f5 100644 --- a/release/ui/buttons_data_empty.py +++ b/release/ui/buttons_data_empty.py @@ -2,8 +2,8 @@ import bpy class DataButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "data" def poll(self, context): diff --git a/release/ui/buttons_data_lamp.py b/release/ui/buttons_data_lamp.py index a00bb23d5b5..c1873d934c4 100644 --- a/release/ui/buttons_data_lamp.py +++ b/release/ui/buttons_data_lamp.py @@ -2,8 +2,8 @@ import bpy class DataButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "data" def poll(self, context): diff --git a/release/ui/buttons_data_lattice.py b/release/ui/buttons_data_lattice.py index 5d8a07c7d44..5535f973b27 100644 --- a/release/ui/buttons_data_lattice.py +++ b/release/ui/buttons_data_lattice.py @@ -2,8 +2,8 @@ import bpy class DataButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "data" def poll(self, context): diff --git a/release/ui/buttons_data_mesh.py b/release/ui/buttons_data_mesh.py index c7663be1923..c1311b32180 100644 --- a/release/ui/buttons_data_mesh.py +++ b/release/ui/buttons_data_mesh.py @@ -2,8 +2,8 @@ import bpy class DataButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "data" def poll(self, context): @@ -93,12 +93,12 @@ class DATA_PT_vertex_groups(DataButtonsPanel): row.template_list(ob, "vertex_groups", ob, "active_vertex_group_index") col = row.column(align=True) - col.itemO("object.vertex_group_add", icon="ICON_ZOOMIN", text="") - col.itemO("object.vertex_group_remove", icon="ICON_ZOOMOUT", text="") + col.itemO("object.vertex_group_add", icon='ICON_ZOOMIN', text="") + col.itemO("object.vertex_group_remove", icon='ICON_ZOOMOUT', text="") - col.itemO("object.vertex_group_copy", icon="ICON_BLANK1", text="") + col.itemO("object.vertex_group_copy", icon='ICON_BLANK1', text="") if ob.data.users > 1: - col.itemO("object.vertex_group_copy_to_linked", icon="ICON_BLANK1", text="") + col.itemO("object.vertex_group_copy_to_linked", icon='ICON_BLANK1', text="") group = ob.active_vertex_group if group: @@ -137,15 +137,15 @@ class DATA_PT_shape_keys(DataButtonsPanel): col = row.column() subcol = col.column(align=True) - subcol.itemO("object.shape_key_add", icon="ICON_ZOOMIN", text="") - subcol.itemO("object.shape_key_remove", icon="ICON_ZOOMOUT", text="") + subcol.itemO("object.shape_key_add", icon='ICON_ZOOMIN', text="") + subcol.itemO("object.shape_key_remove", icon='ICON_ZOOMOUT', text="") if kb: col.itemS() subcol = col.column(align=True) - subcol.itemR(ob, "shape_key_lock", icon="ICON_UNPINNED", text="") - subcol.itemR(kb, "mute", icon="ICON_MUTE_IPO_ON", text="") + subcol.itemR(ob, "shape_key_lock", icon='ICON_UNPINNED', text="") + subcol.itemR(kb, "mute", icon='ICON_MUTE_IPO_ON', text="") if key.relative: row = layout.row() @@ -197,8 +197,8 @@ class DATA_PT_uv_texture(DataButtonsPanel): col.template_list(me, "uv_textures", me, "active_uv_texture_index", rows=2) col = row.column(align=True) - col.itemO("mesh.uv_texture_add", icon="ICON_ZOOMIN", text="") - col.itemO("mesh.uv_texture_remove", icon="ICON_ZOOMOUT", text="") + col.itemO("mesh.uv_texture_add", icon='ICON_ZOOMIN', text="") + col.itemO("mesh.uv_texture_remove", icon='ICON_ZOOMOUT', text="") lay = me.active_uv_texture if lay: @@ -218,8 +218,8 @@ class DATA_PT_vertex_colors(DataButtonsPanel): col.template_list(me, "vertex_colors", me, "active_vertex_color_index", rows=2) col = row.column(align=True) - col.itemO("mesh.vertex_color_add", icon="ICON_ZOOMIN", text="") - col.itemO("mesh.vertex_color_remove", icon="ICON_ZOOMOUT", text="") + col.itemO("mesh.vertex_color_add", icon='ICON_ZOOMIN', text="") + col.itemO("mesh.vertex_color_remove", icon='ICON_ZOOMOUT', text="") lay = me.active_vertex_color if lay: diff --git a/release/ui/buttons_data_metaball.py b/release/ui/buttons_data_metaball.py index e31c3d7fcd0..88c0066c67f 100644 --- a/release/ui/buttons_data_metaball.py +++ b/release/ui/buttons_data_metaball.py @@ -1,8 +1,8 @@ import bpy class DataButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "data" def poll(self, context): diff --git a/release/ui/buttons_data_modifier.py b/release/ui/buttons_data_modifier.py index f5af26f8746..9b2481b0195 100644 --- a/release/ui/buttons_data_modifier.py +++ b/release/ui/buttons_data_modifier.py @@ -2,8 +2,8 @@ import bpy class DataButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "modifier" class DATA_PT_modifiers(DataButtonsPanel): @@ -202,7 +202,7 @@ class DATA_PT_modifiers(DataButtonsPanel): def HOOK(self, layout, ob, md): col = layout.column() col.itemR(md, "object") - if md.object and md.object.type == "ARMATURE": + if md.object and md.object.type == 'ARMATURE': layout.item_pointerR(md, "subtarget", md.object.data, "bones", text="Bone") layout.item_pointerR(md, "vertex_group", ob, "vertex_groups") diff --git a/release/ui/buttons_data_text.py b/release/ui/buttons_data_text.py index 754d6fcda39..62d4d0a4d21 100644 --- a/release/ui/buttons_data_text.py +++ b/release/ui/buttons_data_text.py @@ -2,8 +2,8 @@ import bpy class DataButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "data" def poll(self, context): diff --git a/release/ui/buttons_game.py b/release/ui/buttons_game.py index 7334b453e91..e28e3fda2c6 100644 --- a/release/ui/buttons_game.py +++ b/release/ui/buttons_game.py @@ -2,8 +2,8 @@ import bpy class PhysicsButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "physics" def poll(self, context): @@ -171,8 +171,8 @@ bpy.types.register(PHYSICS_PT_game_physics) bpy.types.register(PHYSICS_PT_game_collision_bounds) class SceneButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "scene" def poll(self, context): @@ -322,8 +322,8 @@ bpy.types.register(SCENE_PT_game_shading) bpy.types.register(SCENE_PT_game_performance) class WorldButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "world" def poll(self, context): diff --git a/release/ui/buttons_material.py b/release/ui/buttons_material.py index 73d28d6964c..eaba26c7e51 100644 --- a/release/ui/buttons_material.py +++ b/release/ui/buttons_material.py @@ -2,8 +2,8 @@ import bpy class MaterialButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "material" # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here @@ -45,8 +45,8 @@ class MATERIAL_PT_context_material(MaterialButtonsPanel): row.template_list(ob, "materials", ob, "active_material_index", rows=2) col = row.column(align=True) - col.itemO("object.material_slot_add", icon="ICON_ZOOMIN", text="") - col.itemO("object.material_slot_remove", icon="ICON_ZOOMOUT", text="") + col.itemO("object.material_slot_add", icon='ICON_ZOOMIN', text="") + col.itemO("object.material_slot_remove", icon='ICON_ZOOMOUT', text="") if ob.mode == 'EDIT': row = layout.row(align=True) diff --git a/release/ui/buttons_object.py b/release/ui/buttons_object.py index 6b6d583e2ca..af2c7cfb58a 100644 --- a/release/ui/buttons_object.py +++ b/release/ui/buttons_object.py @@ -2,8 +2,8 @@ import bpy class ObjectButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "object" class OBJECT_PT_context_object(ObjectButtonsPanel): @@ -15,7 +15,7 @@ class OBJECT_PT_context_object(ObjectButtonsPanel): ob = context.object row = layout.row() - row.itemL(text="", icon="ICON_OBJECT_DATA") + row.itemL(text="", icon='ICON_OBJECT_DATA') row.itemR(ob, "name", text="") class OBJECT_PT_transform(ObjectButtonsPanel): @@ -79,7 +79,7 @@ class OBJECT_PT_groups(ObjectButtonsPanel): row = col.box().row() row.itemR(group, "name", text="") - row.itemO("object.group_remove", text="", icon="VICON_X") + row.itemO("object.group_remove", text="", icon='VICON_X') split = col.box().split() split.column().itemR(group, "layer", text="Dupli") diff --git a/release/ui/buttons_object_constraint.py b/release/ui/buttons_object_constraint.py index c67d6e40cfb..cdc18e3545c 100644 --- a/release/ui/buttons_object_constraint.py +++ b/release/ui/buttons_object_constraint.py @@ -2,8 +2,8 @@ import bpy class ConstraintButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "constraint" def draw_constraint(self, con): @@ -39,7 +39,7 @@ class ConstraintButtonsPanel(bpy.types.Panel): layout.itemR(con, "target") # XXX limiting settings for only 'curves' or some type of object if con.target and subtargets: - if con.target.type == "ARMATURE": + if con.target.type == 'ARMATURE': layout.item_pointerR(con, "subtarget", con.target.data, "bones", text="Bone") if con.type == 'COPY_LOCATION': @@ -478,7 +478,7 @@ class ConstraintButtonsPanel(bpy.types.Panel): layout.itemR(con, "distance") layout.itemR(con, "shrinkwrap_type") - if con.shrinkwrap_type == "PROJECT": + if con.shrinkwrap_type == 'PROJECT': row = layout.row(align=True) row.itemR(con, "axis_x") row.itemR(con, "axis_y") diff --git a/release/ui/buttons_particle.py b/release/ui/buttons_particle.py index 8bc84b734bf..0454f2a4023 100644 --- a/release/ui/buttons_particle.py +++ b/release/ui/buttons_particle.py @@ -11,8 +11,8 @@ def particle_panel_poll(context): return psys.settings.type in ('EMITTER', 'REACTOR', 'HAIR') class ParticleButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "particle" def poll(self, context): @@ -35,8 +35,8 @@ class PARTICLE_PT_particles(ParticleButtonsPanel): row.template_list(ob, "particle_systems", ob, "active_particle_system_index", rows=2) col = row.column(align=True) - col.itemO("object.particle_system_add", icon="ICON_ZOOMIN", text="") - col.itemO("object.particle_system_remove", icon="ICON_ZOOMOUT", text="") + col.itemO("object.particle_system_add", icon='ICON_ZOOMIN', text="") + col.itemO("object.particle_system_remove", icon='ICON_ZOOMOUT', text="") if psys: part = psys.settings @@ -156,8 +156,8 @@ class PARTICLE_PT_cache(ParticleButtonsPanel): row = layout.row() row.template_list(cache, "point_cache_list", cache, "active_point_cache_index", rows=2 ) col = row.column(align=True) - col.itemO("ptcache.add_new", icon="ICON_ZOOMIN", text="") - col.itemO("ptcache.remove", icon="ICON_ZOOMOUT", text="") + col.itemO("ptcache.add_new", icon='ICON_ZOOMIN', text="") + col.itemO("ptcache.remove", icon='ICON_ZOOMOUT', text="") row = layout.row() row.itemL(text="File Name:") @@ -400,12 +400,12 @@ class PARTICLE_PT_physics(ParticleButtonsPanel): col = row.column() subrow = col.row() subcol = subrow.column(align=True) - subcol.itemO("particle.new_target", icon="ICON_ZOOMIN", text="") - subcol.itemO("particle.remove_target", icon="ICON_ZOOMOUT", text="") + subcol.itemO("particle.new_target", icon='ICON_ZOOMIN', text="") + subcol.itemO("particle.remove_target", icon='ICON_ZOOMOUT', text="") subrow = col.row() subcol = subrow.column(align=True) - subcol.itemO("particle.target_move_up", icon="VICON_MOVE_UP", text="") - subcol.itemO("particle.target_move_down", icon="VICON_MOVE_DOWN", text="") + subcol.itemO("particle.target_move_up", icon='VICON_MOVE_UP', text="") + subcol.itemO("particle.target_move_down", icon='VICON_MOVE_DOWN', text="") key = psys.active_particle_target if key: @@ -450,11 +450,11 @@ class PARTICLE_PT_boidbrain(ParticleButtonsPanel): #row.template_list(boids, "states", boids, "active_boid_state_index", compact="True") #col = row.row() #subrow = col.row(align=True) - #subrow.itemO("boid.boidstate_add", icon="ICON_ZOOMIN", text="") - #subrow.itemO("boid.boidstate_del", icon="ICON_ZOOMOUT", text="") + #subrow.itemO("boid.boidstate_add", icon='ICON_ZOOMIN', text="") + #subrow.itemO("boid.boidstate_del", icon='ICON_ZOOMOUT', text="") #subrow = row.row(align=True) - #subrow.itemO("boid.boidstate_move_up", icon="VICON_MOVE_UP", text="") - #subrow.itemO("boid.boidstate_move_down", icon="VICON_MOVE_DOWN", text="") + #subrow.itemO("boid.boidstate_move_up", icon='VICON_MOVE_UP', text="") + #subrow.itemO("boid.boidstate_move_down", icon='VICON_MOVE_DOWN', text="") state = boids.active_boid_state @@ -473,12 +473,12 @@ class PARTICLE_PT_boidbrain(ParticleButtonsPanel): col = row.column() subrow = col.row() subcol = subrow.column(align=True) - subcol.item_menu_enumO("boid.boidrule_add", "type", icon="ICON_ZOOMIN", text="") - subcol.itemO("boid.boidrule_del", icon="ICON_ZOOMOUT", text="") + subcol.item_menu_enumO("boid.boidrule_add", "type", icon='ICON_ZOOMIN', text="") + subcol.itemO("boid.boidrule_del", icon='ICON_ZOOMOUT', text="") subrow = col.row() subcol = subrow.column(align=True) - subcol.itemO("boid.boidrule_move_up", icon="VICON_MOVE_UP", text="") - subcol.itemO("boid.boidrule_move_down", icon="VICON_MOVE_DOWN", text="") + subcol.itemO("boid.boidrule_move_up", icon='VICON_MOVE_UP', text="") + subcol.itemO("boid.boidrule_move_down", icon='VICON_MOVE_DOWN', text="") rule = state.active_boid_rule @@ -486,8 +486,8 @@ class PARTICLE_PT_boidbrain(ParticleButtonsPanel): row = layout.row() row.itemR(rule, "name", text="") #somebody make nice icons for boids here please! -jahka - row.itemR(rule, "in_air", icon="VICON_MOVE_UP", text="") - row.itemR(rule, "on_land", icon="VICON_MOVE_DOWN", text="") + row.itemR(rule, "in_air", icon='VICON_MOVE_UP', text="") + row.itemR(rule, "on_land", icon='VICON_MOVE_DOWN', text="") row = layout.row() diff --git a/release/ui/buttons_physics_cloth.py b/release/ui/buttons_physics_cloth.py index f34077c758a..6c499625685 100644 --- a/release/ui/buttons_physics_cloth.py +++ b/release/ui/buttons_physics_cloth.py @@ -2,8 +2,8 @@ import bpy class PhysicButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "physics" def poll(self, context): @@ -93,8 +93,8 @@ class PHYSICS_PT_cloth_cache(PhysicButtonsPanel): row = layout.row() row.template_list(cache, "point_cache_list", cache, "active_point_cache_index") col = row.column(align=True) - col.itemO("ptcache.add_new", icon="ICON_ZOOMIN", text="") - col.itemO("ptcache.remove", icon="ICON_ZOOMOUT", text="") + col.itemO("ptcache.add_new", icon='ICON_ZOOMIN', text="") + col.itemO("ptcache.remove", icon='ICON_ZOOMOUT', text="") row = layout.row() row.itemR(cache, "name") diff --git a/release/ui/buttons_physics_field.py b/release/ui/buttons_physics_field.py index fb29dd92833..3c68327ba79 100644 --- a/release/ui/buttons_physics_field.py +++ b/release/ui/buttons_physics_field.py @@ -2,8 +2,8 @@ import bpy class PhysicButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "physics" def poll(self, context): @@ -146,15 +146,15 @@ class PHYSICS_PT_field(PhysicButtonsPanel): sub.active = field.use_radial_max sub.itemR(field, "radial_maximum", text="Distance") - #if ob.type in "CURVE": - #if field.type == "GUIDE": + #if ob.type in 'CURVE': + #if field.type == 'GUIDE': #colsub = col.column(align=True) - #if field.type != "NONE": + #if field.type != 'NONE': #layout.itemR(field, "strength") - #if field.type in ("HARMONIC", "SPHERICAL", "CHARGE", "LENNARDj"): - #if ob.type in ("MESH", "SURFACE", "FONT", "CURVE"): + #if field.type in ('HARMONIC', 'SPHERICAL', 'CHARGE', "LENNARDj"): + #if ob.type in ('MESH', 'SURFACE', 'FONT', 'CURVE'): #layout.itemR(field, "surface") class PHYSICS_PT_collision(PhysicButtonsPanel): diff --git a/release/ui/buttons_physics_fluid.py b/release/ui/buttons_physics_fluid.py index 304d419b388..1d0a64c517a 100644 --- a/release/ui/buttons_physics_fluid.py +++ b/release/ui/buttons_physics_fluid.py @@ -2,8 +2,8 @@ import bpy class PhysicButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "physics" def poll(self, context): diff --git a/release/ui/buttons_physics_smoke.py b/release/ui/buttons_physics_smoke.py index d187e4c5901..5e1ec227080 100644 --- a/release/ui/buttons_physics_smoke.py +++ b/release/ui/buttons_physics_smoke.py @@ -7,8 +7,8 @@ def smoke_panel_enabled_low(smd): return True class PhysicButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "physics" def poll(self, context): @@ -144,8 +144,8 @@ class PHYSICS_PT_smoke_cache(PhysicButtonsPanel): row = layout.row() row.template_list(cache, "point_cache_list", cache, "active_point_cache_index") col = row.column(align=True) - col.itemO("ptcache.add_new", icon="ICON_ZOOMIN", text="") - col.itemO("ptcache.remove", icon="ICON_ZOOMOUT", text="") + col.itemO("ptcache.add_new", icon='ICON_ZOOMIN', text="") + col.itemO("ptcache.remove", icon='ICON_ZOOMOUT', text="") row = layout.row() row.itemR(cache, "name") @@ -239,8 +239,8 @@ class PHYSICS_PT_smoke_cache_highres(PhysicButtonsPanel): row = layout.row() row.template_list(cache, "point_cache_list", cache, "active_point_cache_index") col = row.column(align=True) - col.itemO("ptcache.add_new", icon="ICON_ZOOMIN", text="") - col.itemO("ptcache.remove", icon="ICON_ZOOMOUT", text="") + col.itemO("ptcache.add_new", icon='ICON_ZOOMIN', text="") + col.itemO("ptcache.remove", icon='ICON_ZOOMOUT', text="") row = layout.row() row.itemR(cache, "name") diff --git a/release/ui/buttons_physics_softbody.py b/release/ui/buttons_physics_softbody.py index 2613f9e8032..35c0c498436 100644 --- a/release/ui/buttons_physics_softbody.py +++ b/release/ui/buttons_physics_softbody.py @@ -2,8 +2,8 @@ import bpy class PhysicButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "physics" def poll(self, context): @@ -68,8 +68,8 @@ class PHYSICS_PT_softbody_cache(PhysicButtonsPanel): row = layout.row() row.template_list(cache, "point_cache_list", cache, "active_point_cache_index") col = row.column(align=True) - col.itemO("ptcache.add_new", icon="ICON_ZOOMIN", text="") - col.itemO("ptcache.remove", icon="ICON_ZOOMOUT", text="") + col.itemO("ptcache.add_new", icon='ICON_ZOOMIN', text="") + col.itemO("ptcache.remove", icon='ICON_ZOOMOUT', text="") row = layout.row() row.itemR(cache, "name") diff --git a/release/ui/buttons_scene.py b/release/ui/buttons_scene.py index e9ee97468e8..08eee7ef43a 100644 --- a/release/ui/buttons_scene.py +++ b/release/ui/buttons_scene.py @@ -2,8 +2,8 @@ import bpy class RenderButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "scene" # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here @@ -41,8 +41,8 @@ class SCENE_PT_layers(RenderButtonsPanel): row.template_list(rd, "layers", rd, "active_layer_index", rows=2) col = row.column(align=True) - col.itemO("scene.render_layer_add", icon="ICON_ZOOMIN", text="") - col.itemO("scene.render_layer_remove", icon="ICON_ZOOMOUT", text="") + col.itemO("scene.render_layer_add", icon='ICON_ZOOMIN', text="") + col.itemO("scene.render_layer_remove", icon='ICON_ZOOMOUT', text="") rl = rd.layers[rd.active_layer_index] @@ -103,19 +103,19 @@ class SCENE_PT_layers(RenderButtonsPanel): col.itemR(rl, "pass_diffuse") row = col.row() row.itemR(rl, "pass_specular") - row.itemR(rl, "pass_specular_exclude", text="", icon="ICON_X") + row.itemR(rl, "pass_specular_exclude", text="", icon='ICON_X') row = col.row() row.itemR(rl, "pass_shadow") - row.itemR(rl, "pass_shadow_exclude", text="", icon="ICON_X") + row.itemR(rl, "pass_shadow_exclude", text="", icon='ICON_X') row = col.row() row.itemR(rl, "pass_ao") - row.itemR(rl, "pass_ao_exclude", text="", icon="ICON_X") + row.itemR(rl, "pass_ao_exclude", text="", icon='ICON_X') row = col.row() row.itemR(rl, "pass_reflection") - row.itemR(rl, "pass_reflection_exclude", text="", icon="ICON_X") + row.itemR(rl, "pass_reflection_exclude", text="", icon='ICON_X') row = col.row() row.itemR(rl, "pass_refraction") - row.itemR(rl, "pass_refraction_exclude", text="", icon="ICON_X") + row.itemR(rl, "pass_refraction_exclude", text="", icon='ICON_X') class SCENE_PT_shading(RenderButtonsPanel): __label__ = "Shading" diff --git a/release/ui/buttons_texture.py b/release/ui/buttons_texture.py index 29e43981fd2..20b3c7bca3e 100644 --- a/release/ui/buttons_texture.py +++ b/release/ui/buttons_texture.py @@ -2,8 +2,8 @@ import bpy class TextureButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "texture" def poll(self, context): diff --git a/release/ui/buttons_world.py b/release/ui/buttons_world.py index 599f45d160b..342adfaf4af 100644 --- a/release/ui/buttons_world.py +++ b/release/ui/buttons_world.py @@ -2,8 +2,8 @@ import bpy class WorldButtonsPanel(bpy.types.Panel): - __space_type__ = "PROPERTIES" - __region_type__ = "WINDOW" + __space_type__ = 'PROPERTIES' + __region_type__ = 'WINDOW' __context__ = "world" # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here diff --git a/release/ui/space_buttons.py b/release/ui/space_buttons.py index 3cf782e615f..aa89c06ea08 100644 --- a/release/ui/space_buttons.py +++ b/release/ui/space_buttons.py @@ -2,7 +2,7 @@ import bpy class Buttons_HT_header(bpy.types.Header): - __space_type__ = "PROPERTIES" + __space_type__ = 'PROPERTIES' def draw(self, context): layout = self.layout @@ -22,7 +22,7 @@ class Buttons_HT_header(bpy.types.Header): row.itemR(scene, "current_frame") class Buttons_MT_view(bpy.types.Menu): - __space_type__ = "PROPERTIES" + __space_type__ = 'PROPERTIES' __label__ = "View" def draw(self, context): diff --git a/release/ui/space_console.py b/release/ui/space_console.py index 45cb2a856e1..f1038b5616a 100644 --- a/release/ui/space_console.py +++ b/release/ui/space_console.py @@ -5,7 +5,7 @@ import bpy_ops # XXX - should not need to do this del bpy_ops class CONSOLE_HT_header(bpy.types.Header): - __space_type__ = "CONSOLE" + __space_type__ = 'CONSOLE' def draw(self, context): sc = context.space_data @@ -39,7 +39,7 @@ class CONSOLE_HT_header(bpy.types.Header): row.itemO("console.report_replay") class CONSOLE_MT_console(bpy.types.Menu): - __space_type__ = "CONSOLE" + __space_type__ = 'CONSOLE' __label__ = "Console" def draw(self, context): @@ -52,7 +52,7 @@ class CONSOLE_MT_console(bpy.types.Menu): layout.itemO("console.paste") class CONSOLE_MT_report(bpy.types.Menu): - __space_type__ = "CONSOLE" + __space_type__ = 'CONSOLE' __label__ = "Report" def draw(self, context): diff --git a/release/ui/space_filebrowser.py b/release/ui/space_filebrowser.py index a37b89e8db4..f1ea5555787 100644 --- a/release/ui/space_filebrowser.py +++ b/release/ui/space_filebrowser.py @@ -2,7 +2,7 @@ import bpy class FILEBROWSER_HT_header(bpy.types.Header): - __space_type__ = "FILE_BROWSER" + __space_type__ = 'FILE_BROWSER' def draw(self, context): layout = self.layout diff --git a/release/ui/space_image.py b/release/ui/space_image.py index 888b46e060e..aa43b14b974 100644 --- a/release/ui/space_image.py +++ b/release/ui/space_image.py @@ -2,7 +2,7 @@ import bpy class IMAGE_MT_view(bpy.types.Menu): - __space_type__ = "IMAGE_EDITOR" + __space_type__ = 'IMAGE_EDITOR' __label__ = "View" def draw(self, context): @@ -13,7 +13,7 @@ class IMAGE_MT_view(bpy.types.Menu): show_uvedit = sima.show_uvedit - layout.itemO("image.properties", icon="ICON_MENU_PANEL") + layout.itemO("image.properties", icon='ICON_MENU_PANEL') layout.itemS() @@ -43,7 +43,7 @@ class IMAGE_MT_view(bpy.types.Menu): layout.itemO("screen.screen_full_area") class IMAGE_MT_select(bpy.types.Menu): - __space_type__ = "IMAGE_EDITOR" + __space_type__ = 'IMAGE_EDITOR' __label__ = "Select" def draw(self, context): @@ -64,7 +64,7 @@ class IMAGE_MT_select(bpy.types.Menu): layout.itemO("uv.select_linked") class IMAGE_MT_image(bpy.types.Menu): - __space_type__ = "IMAGE_EDITOR" + __space_type__ = 'IMAGE_EDITOR' __label__ = "Image" def draw(self, context): @@ -85,7 +85,7 @@ class IMAGE_MT_image(bpy.types.Menu): layout.itemO("image.save") layout.itemO("image.save_as") - if ima.source == "SEQUENCE": + if ima.source == 'SEQUENCE': layout.itemO("image.save_sequence") if not show_render: @@ -99,7 +99,7 @@ class IMAGE_MT_image(bpy.types.Menu): # only for dirty && specific image types, perhaps # this could be done in operator poll too if ima.dirty: - if ima.source in ("FILE", "GENERATED") and ima.type != "MULTILAYER": + if ima.source in ('FILE', 'GENERATED') and ima.type != 'MULTILAYER': layout.item_booleanO("image.pack", "as_png", True, text="Pack As PNG") layout.itemS() @@ -107,7 +107,7 @@ class IMAGE_MT_image(bpy.types.Menu): layout.itemR(sima, "image_painting") class IMAGE_MT_uvs_showhide(bpy.types.Menu): - __space_type__ = "IMAGE_EDITOR" + __space_type__ = 'IMAGE_EDITOR' __label__ = "Show/Hide Faces" def draw(self, context): @@ -118,7 +118,7 @@ class IMAGE_MT_uvs_showhide(bpy.types.Menu): layout.item_booleanO("uv.hide", "unselected", True) class IMAGE_MT_uvs_transform(bpy.types.Menu): - __space_type__ = "IMAGE_EDITOR" + __space_type__ = 'IMAGE_EDITOR' __label__ = "Transform" def draw(self, context): @@ -129,7 +129,7 @@ class IMAGE_MT_uvs_transform(bpy.types.Menu): layout.item_enumO("tfm.transform", "mode", 'RESIZE') class IMAGE_MT_uvs_mirror(bpy.types.Menu): - __space_type__ = "IMAGE_EDITOR" + __space_type__ = 'IMAGE_EDITOR' __label__ = "Mirror" def draw(self, context): @@ -139,7 +139,7 @@ class IMAGE_MT_uvs_mirror(bpy.types.Menu): layout.item_enumO("uv.mirror", "axis", 'MIRROR_Y') # "Y Axis", M, class IMAGE_MT_uvs_weldalign(bpy.types.Menu): - __space_type__ = "IMAGE_EDITOR" + __space_type__ = 'IMAGE_EDITOR' __label__ = "Weld/Align" def draw(self, context): @@ -150,7 +150,7 @@ class IMAGE_MT_uvs_weldalign(bpy.types.Menu): class IMAGE_MT_uvs(bpy.types.Menu): - __space_type__ = "IMAGE_EDITOR" + __space_type__ = 'IMAGE_EDITOR' __label__ = "UVs" def draw(self, context): @@ -192,7 +192,7 @@ class IMAGE_MT_uvs(bpy.types.Menu): layout.itemM("IMAGE_MT_uvs_showhide") class IMAGE_HT_header(bpy.types.Header): - __space_type__ = "IMAGE_EDITOR" + __space_type__ = 'IMAGE_EDITOR' def draw(self, context): sima = context.space_data @@ -262,17 +262,17 @@ class IMAGE_HT_header(bpy.types.Header): row.itemR(sima, "draw_channels", text="", expand=True) row = layout.row(align=True) - if ima.type == "COMPOSITE": - row.itemO("image.record_composite", icon="ICON_REC") - if ima.type == "COMPOSITE" and ima.source in ("MOVIE", "SEQUENCE"): - row.itemO("image.play_composite", icon="ICON_PLAY") + if ima.type == 'COMPOSITE': + row.itemO("image.record_composite", icon='ICON_REC') + if ima.type == 'COMPOSITE' and ima.source in ('MOVIE', 'SEQUENCE'): + row.itemO("image.play_composite", icon='ICON_PLAY') if show_uvedit or sima.image_painting: layout.itemR(sima, "update_automatically", text="") class IMAGE_PT_game_properties(bpy.types.Panel): - __space_type__ = "IMAGE_EDITOR" - __region_type__ = "UI" + __space_type__ = 'IMAGE_EDITOR' + __region_type__ = 'UI' __label__ = "Game Properties" def poll(self, context): @@ -315,8 +315,8 @@ class IMAGE_PT_game_properties(bpy.types.Panel): subrow.active = ima.tiles or ima.animated class IMAGE_PT_view_properties(bpy.types.Panel): - __space_type__ = "IMAGE_EDITOR" - __region_type__ = "UI" + __space_type__ = 'IMAGE_EDITOR' + __region_type__ = 'UI' __label__ = "View Properties" def poll(self, context): diff --git a/release/ui/space_info.py b/release/ui/space_info.py index 83eb2c75a2c..4188209e393 100644 --- a/release/ui/space_info.py +++ b/release/ui/space_info.py @@ -2,7 +2,7 @@ import bpy class INFO_HT_header(bpy.types.Header): - __space_type__ = "INFO" + __space_type__ = 'INFO' def draw(self, context): layout = self.layout @@ -38,7 +38,7 @@ class INFO_HT_header(bpy.types.Header): layout.itemL(text=scene.statistics()) class INFO_MT_file(bpy.types.Menu): - __space_type__ = "INFO" + __space_type__ = 'INFO' __label__ = "File" def draw(self, context): @@ -74,14 +74,14 @@ class INFO_MT_file(bpy.types.Menu): layout.itemO("wm.exit_blender", text="Quit") class INFO_MT_file_import(bpy.types.Menu): - __space_type__ = "INFO" + __space_type__ = 'INFO' __label__ = "Import" def draw(self, context): layout = self.layout class INFO_MT_file_export(bpy.types.Menu): - __space_type__ = "INFO" + __space_type__ = 'INFO' __label__ = "Export" def draw(self, context): @@ -90,7 +90,7 @@ class INFO_MT_file_export(bpy.types.Menu): layout.itemO("export.ply", text="PLY") class INFO_MT_file_external_data(bpy.types.Menu): - __space_type__ = "INFO" + __space_type__ = 'INFO' __label__ = "External Data" def draw(self, context): @@ -107,7 +107,7 @@ class INFO_MT_file_external_data(bpy.types.Menu): layout.itemO("file.find_missing_files") class INFO_MT_add(bpy.types.Menu): - __space_type__ = "INFO" + __space_type__ = 'INFO' __label__ = "Add" def draw(self, context): @@ -133,7 +133,7 @@ class INFO_MT_add(bpy.types.Menu): layout.item_enumO("object.object_add", "type", 'LAMP', icon='ICON_OUTLINER_OB_LAMP') class INFO_MT_game(bpy.types.Menu): - __space_type__ = "INFO" + __space_type__ = 'INFO' __label__ = "Game" def draw(self, context): @@ -151,7 +151,7 @@ class INFO_MT_game(bpy.types.Menu): layout.itemR(gs, "deprecation_warnings") class INFO_MT_render(bpy.types.Menu): - __space_type__ = "INFO" + __space_type__ = 'INFO' __label__ = "Render" def draw(self, context): @@ -167,7 +167,7 @@ class INFO_MT_render(bpy.types.Menu): layout.itemO("screen.render_view_show") class INFO_MT_help(bpy.types.Menu): - __space_type__ = "INFO" + __space_type__ = 'INFO' __label__ = "Help" def draw(self, context): diff --git a/release/ui/space_logic.py b/release/ui/space_logic.py index 728e5e6307b..68ddceb8534 100644 --- a/release/ui/space_logic.py +++ b/release/ui/space_logic.py @@ -1,8 +1,8 @@ import bpy class LOGIC_PT_properties(bpy.types.Panel): - __space_type__ = "LOGIC_EDITOR" - __region_type__ = "UI" + __space_type__ = 'LOGIC_EDITOR' + __region_type__ = 'UI' __label__ = "Properties" def poll(self, context): diff --git a/release/ui/space_node.py b/release/ui/space_node.py index fd5dd9e6ee7..875aca7fd82 100644 --- a/release/ui/space_node.py +++ b/release/ui/space_node.py @@ -2,7 +2,7 @@ import bpy class NODE_HT_header(bpy.types.Header): - __space_type__ = "NODE_EDITOR" + __space_type__ = 'NODE_EDITOR' def draw(self, context): layout = self.layout @@ -47,7 +47,7 @@ class NODE_HT_header(bpy.types.Header): layout.itemR(snode, "backdrop") class NODE_MT_view(bpy.types.Menu): - __space_type__ = "NODE_EDITOR" + __space_type__ = 'NODE_EDITOR' __label__ = "View" def draw(self, context): @@ -65,7 +65,7 @@ class NODE_MT_view(bpy.types.Menu): layout.itemO("screen.screen_full_area") class NODE_MT_select(bpy.types.Menu): - __space_type__ = "NODE_EDITOR" + __space_type__ = 'NODE_EDITOR' __label__ = "Select" def draw(self, context): @@ -80,7 +80,7 @@ class NODE_MT_select(bpy.types.Menu): # layout.itemO("node.select_linked_to") class NODE_MT_node(bpy.types.Menu): - __space_type__ = "NODE_EDITOR" + __space_type__ = 'NODE_EDITOR' __label__ = "Node" def draw(self, context): diff --git a/release/ui/space_outliner.py b/release/ui/space_outliner.py index f55f4633a7b..522b620e29d 100644 --- a/release/ui/space_outliner.py +++ b/release/ui/space_outliner.py @@ -2,7 +2,7 @@ import bpy class OUTLINER_HT_header(bpy.types.Header): - __space_type__ = "OUTLINER" + __space_type__ = 'OUTLINER' def draw(self, context): so = context.space_data @@ -36,7 +36,7 @@ class OUTLINER_HT_header(bpy.types.Header): class OUTLINER_MT_view(bpy.types.Menu): - __space_type__ = "OUTLINER" + __space_type__ = 'OUTLINER' __label__ = "View" def draw(self, context): diff --git a/release/ui/space_sequencer.py b/release/ui/space_sequencer.py index 1edcf32d3b5..1498c37d761 100644 --- a/release/ui/space_sequencer.py +++ b/release/ui/space_sequencer.py @@ -7,7 +7,7 @@ def act_strip(context): # Header class SEQUENCER_HT_header(bpy.types.Header): - __space_type__ = "SEQUENCE_EDITOR" + __space_type__ = 'SEQUENCE_EDITOR' def draw(self, context): layout = self.layout @@ -38,7 +38,7 @@ class SEQUENCER_HT_header(bpy.types.Header): layout.itemR(st, "display_channel", text="Channel") class SEQUENCER_MT_view(bpy.types.Menu): - __space_type__ = "SEQUENCE_EDITOR" + __space_type__ = 'SEQUENCE_EDITOR' __label__ = "View" def draw(self, context): @@ -106,7 +106,7 @@ class SEQUENCER_MT_view(bpy.types.Menu): """ class SEQUENCER_MT_select(bpy.types.Menu): - __space_type__ = "SEQUENCE_EDITOR" + __space_type__ = 'SEQUENCE_EDITOR' __label__ = "Select" def draw(self, context): @@ -127,7 +127,7 @@ class SEQUENCER_MT_select(bpy.types.Menu): layout.itemO("sequencer.select_inverse") class SEQUENCER_MT_marker(bpy.types.Menu): - __space_type__ = "SEQUENCE_EDITOR" + __space_type__ = 'SEQUENCE_EDITOR' __label__ = "Marker (TODO)" def draw(self, context): @@ -146,7 +146,7 @@ class SEQUENCER_MT_marker(bpy.types.Menu): #layout.itemO("sequencer.sound_strip_add", text="Transform Markers") # toggle, will be rna - (sseq->flag & SEQ_MARKER_TRANS) class SEQUENCER_MT_add(bpy.types.Menu): - __space_type__ = "SEQUENCE_EDITOR" + __space_type__ = 'SEQUENCE_EDITOR' __label__ = "Add" def draw(self, context): @@ -163,7 +163,7 @@ class SEQUENCER_MT_add(bpy.types.Menu): layout.itemM("SEQUENCER_MT_add_effect") class SEQUENCER_MT_add_effect(bpy.types.Menu): - __space_type__ = "SEQUENCE_EDITOR" + __space_type__ = 'SEQUENCE_EDITOR' __label__ = "Effect Strip..." def draw(self, context): @@ -187,7 +187,7 @@ class SEQUENCER_MT_add_effect(bpy.types.Menu): layout.item_enumO("sequencer.effect_strip_add", 'type', 'SPEED') class SEQUENCER_MT_strip(bpy.types.Menu): - __space_type__ = "SEQUENCE_EDITOR" + __space_type__ = 'SEQUENCE_EDITOR' __label__ = "Strip" def draw(self, context): @@ -254,15 +254,15 @@ class SEQUENCER_MT_strip(bpy.types.Menu): # Panels class SequencerButtonsPanel(bpy.types.Panel): - __space_type__ = "SEQUENCE_EDITOR" - __region_type__ = "UI" + __space_type__ = 'SEQUENCE_EDITOR' + __region_type__ = 'UI' def poll(self, context): return context.space_data.display_mode == 'SEQUENCER' and act_strip(context) != None class SequencerButtonsPanel_Output(bpy.types.Panel): - __space_type__ = "SEQUENCE_EDITOR" - __region_type__ = "UI" + __space_type__ = 'SEQUENCE_EDITOR' + __region_type__ = 'UI' def poll(self, context): return context.space_data.display_mode != 'SEQUENCER' diff --git a/release/ui/space_text.py b/release/ui/space_text.py index 61e8d3489a5..7b7ec176b72 100644 --- a/release/ui/space_text.py +++ b/release/ui/space_text.py @@ -2,7 +2,7 @@ import bpy class TEXT_HT_header(bpy.types.Header): - __space_type__ = "TEXT_EDITOR" + __space_type__ = 'TEXT_EDITOR' def draw(self, context): st = context.space_data @@ -45,8 +45,8 @@ class TEXT_HT_header(bpy.types.Header): row.itemL(text="Text: Internal") class TEXT_PT_properties(bpy.types.Panel): - __space_type__ = "TEXT_EDITOR" - __region_type__ = "UI" + __space_type__ = 'TEXT_EDITOR' + __region_type__ = 'UI' __label__ = "Properties" def draw(self, context): @@ -64,8 +64,8 @@ class TEXT_PT_properties(bpy.types.Panel): flow.itemR(st, "tab_width") class TEXT_PT_find(bpy.types.Panel): - __space_type__ = "TEXT_EDITOR" - __region_type__ = "UI" + __space_type__ = 'TEXT_EDITOR' + __region_type__ = 'UI' __label__ = "Find" def draw(self, context): @@ -95,7 +95,7 @@ class TEXT_PT_find(bpy.types.Panel): row.itemR(st, "find_all", text="All") class TEXT_MT_text(bpy.types.Menu): - __space_type__ = "TEXT_EDITOR" + __space_type__ = 'TEXT_EDITOR' __label__ = "Text" def draw(self, context): @@ -127,7 +127,7 @@ class TEXT_MT_text(bpy.types.Menu): layout.itemS() - layout.itemO("text.properties", icon="ICON_MENU_PANEL") + layout.itemO("text.properties", icon='ICON_MENU_PANEL') #ifndef DISABLE_PYTHON # XXX layout.column() @@ -136,7 +136,7 @@ class TEXT_MT_text(bpy.types.Menu): #endif class TEXT_MT_edit_view(bpy.types.Menu): - __space_type__ = "TEXT_EDITOR" + __space_type__ = 'TEXT_EDITOR' __label__ = "View" def draw(self, context): @@ -146,7 +146,7 @@ class TEXT_MT_edit_view(bpy.types.Menu): layout.item_enumO("text.move", "type", 'FILE_BOTTOM', text="Bottom of File") class TEXT_MT_edit_select(bpy.types.Menu): - __space_type__ = "TEXT_EDITOR" + __space_type__ = 'TEXT_EDITOR' __label__ = "Select" def draw(self, context): @@ -156,7 +156,7 @@ class TEXT_MT_edit_select(bpy.types.Menu): layout.itemO("text.select_line") class TEXT_MT_edit_markers(bpy.types.Menu): - __space_type__ = "TEXT_EDITOR" + __space_type__ = 'TEXT_EDITOR' __label__ = "Markers" def draw(self, context): @@ -167,7 +167,7 @@ class TEXT_MT_edit_markers(bpy.types.Menu): layout.itemO("text.previous_marker") class TEXT_MT_format(bpy.types.Menu): - __space_type__ = "TEXT_EDITOR" + __space_type__ = 'TEXT_EDITOR' __label__ = "Format" def draw(self, context): @@ -186,7 +186,7 @@ class TEXT_MT_format(bpy.types.Menu): layout.item_menu_enumO("text.convert_whitespace", "type") class TEXT_MT_edit_to3d(bpy.types.Menu): - __space_type__ = "TEXT_EDITOR" + __space_type__ = 'TEXT_EDITOR' __label__ = "Text To 3D Object" def draw(self, context): @@ -196,7 +196,7 @@ class TEXT_MT_edit_to3d(bpy.types.Menu): layout.item_booleanO("text.to_3d_object", "split_lines", True, text="One Object Per Line"); class TEXT_MT_edit(bpy.types.Menu): - __space_type__ = "TEXT_EDITOR" + __space_type__ = 'TEXT_EDITOR' __label__ = "Edit" def poll(self, context): diff --git a/release/ui/space_time.py b/release/ui/space_time.py index 17deb4c550f..bfa4d5b6485 100644 --- a/release/ui/space_time.py +++ b/release/ui/space_time.py @@ -2,7 +2,7 @@ import bpy class TIME_HT_header(bpy.types.Header): - __space_type__ = "TIMELINE" + __space_type__ = 'TIMELINE' def draw(self, context): layout = self.layout @@ -64,11 +64,11 @@ class TIME_HT_header(bpy.types.Header): row = layout.row(align=True) row.item_pointerR(scene, "active_keying_set", scene, "keying_sets", text="") - row.itemO("anim.insert_keyframe", text="", icon="ICON_KEY_HLT") - row.itemO("anim.delete_keyframe", text="", icon="ICON_KEY_DEHLT") + row.itemO("anim.insert_keyframe", text="", icon='ICON_KEY_HLT') + row.itemO("anim.delete_keyframe", text="", icon='ICON_KEY_DEHLT') class TIME_MT_view(bpy.types.Menu): - __space_type__ = "TIMELINE" + __space_type__ = 'TIMELINE' __label__ = "View" def draw(self, context): @@ -83,7 +83,7 @@ class TIME_MT_view(bpy.types.Menu): layout.itemR(st, "only_selected") class TIME_MT_frame(bpy.types.Menu): - __space_type__ = "TIMELINE" + __space_type__ = 'TIMELINE' __label__ = "Frame" def draw(self, context): @@ -101,7 +101,7 @@ class TIME_MT_frame(bpy.types.Menu): layout.itemO("time.end_frame_set") class TIME_MT_playback(bpy.types.Menu): - __space_type__ = "TIMELINE" + __space_type__ = 'TIMELINE' __label__ = "Playback" def draw(self, context): diff --git a/release/ui/space_userpref.py b/release/ui/space_userpref.py index bd963c65cd0..acd3d3eb44b 100644 --- a/release/ui/space_userpref.py +++ b/release/ui/space_userpref.py @@ -2,21 +2,21 @@ import bpy class USERPREF_HT_header(bpy.types.Header): - __space_type__ = "USER_PREFERENCES" + __space_type__ = 'USER_PREFERENCES' def draw(self, context): layout = self.layout layout.template_header(menus=False) class USERPREF_MT_view(bpy.types.Menu): - __space_type__ = "USER_PREFERENCES" + __space_type__ = 'USER_PREFERENCES' __label__ = "View" def draw(self, context): layout = self.layout class USERPREF_PT_tabs(bpy.types.Panel): - __space_type__ = "USER_PREFERENCES" + __space_type__ = 'USER_PREFERENCES' __show_header__ = False def draw(self, context): @@ -27,7 +27,7 @@ class USERPREF_PT_tabs(bpy.types.Panel): layout.itemR(userpref, "active_section", expand=True) class USERPREF_PT_view(bpy.types.Panel): - __space_type__ = "USER_PREFERENCES" + __space_type__ = 'USER_PREFERENCES' __label__ = "View" __show_header__ = False @@ -130,7 +130,7 @@ class USERPREF_PT_view(bpy.types.Panel): sub1.itemR(view, "open_right_mouse_delay", text="Hold RMB") class USERPREF_PT_edit(bpy.types.Panel): - __space_type__ = "USER_PREFERENCES" + __space_type__ = 'USER_PREFERENCES' __label__ = "Edit" __show_header__ = False @@ -227,7 +227,7 @@ class USERPREF_PT_edit(bpy.types.Panel): sub1.itemR(edit, "duplicate_action", text="Action") class USERPREF_PT_system(bpy.types.Panel): - __space_type__ = "USER_PREFERENCES" + __space_type__ = 'USER_PREFERENCES' __label__ = "System" __show_header__ = False @@ -308,7 +308,7 @@ class USERPREF_PT_system(bpy.types.Panel): sub1.itemR(system, "texture_collection_rate", text="Collection Rate") class USERPREF_PT_filepaths(bpy.types.Panel): - __space_type__ = "USER_PREFERENCES" + __space_type__ = 'USER_PREFERENCES' __label__ = "File Paths" __show_header__ = False @@ -370,7 +370,7 @@ class USERPREF_PT_filepaths(bpy.types.Panel): sub3.itemR(paths, "auto_save_time") class USERPREF_PT_language(bpy.types.Panel): - __space_type__ = "USER_PREFERENCES" + __space_type__ = 'USER_PREFERENCES' __label__ = "Language" __show_header__ = False @@ -394,7 +394,7 @@ class USERPREF_PT_language(bpy.types.Panel): col.itemR(lan, "use_textured_fonts") class USERPREF_PT_bottombar(bpy.types.Panel): - __space_type__ = "USER_PREFERENCES" + __space_type__ = 'USER_PREFERENCES' __label__ = " " __show_header__ = False diff --git a/release/ui/space_view3d.py b/release/ui/space_view3d.py index f9e185f44f2..8f37b34e3b4 100644 --- a/release/ui/space_view3d.py +++ b/release/ui/space_view3d.py @@ -4,7 +4,7 @@ import bpy # ********** Header ********** class VIEW3D_HT_header(bpy.types.Header): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' def draw(self, context): layout = self.layout @@ -47,14 +47,14 @@ class VIEW3D_HT_header(bpy.types.Header): # ********** View menus ********** class VIEW3D_MT_view(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "View" def draw(self, context): layout = self.layout - layout.itemO("view3d.properties", icon="ICON_MENU_PANEL") - layout.itemO("view3d.toolbar", icon="ICON_MENU_PANEL") + layout.itemO("view3d.properties", icon='ICON_MENU_PANEL') + layout.itemO("view3d.toolbar", icon='ICON_MENU_PANEL') layout.itemS() @@ -101,7 +101,7 @@ class VIEW3D_MT_view(bpy.types.Menu): layout.itemO("screen.screen_full_area", text="Toggle Full Screen") class VIEW3D_MT_view_navigation(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Navigation" def draw(self, context): @@ -124,7 +124,7 @@ class VIEW3D_MT_view_navigation(bpy.types.Menu): # ********** Select menus, suffix from context.mode ********** class VIEW3D_MT_select_OBJECT(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Select" def draw(self, context): @@ -142,7 +142,7 @@ class VIEW3D_MT_select_OBJECT(bpy.types.Menu): layout.itemO("object.select_grouped", text="Select Grouped") class VIEW3D_MT_select_POSE(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Select" def draw(self, context): @@ -172,7 +172,7 @@ class VIEW3D_MT_select_POSE(bpy.types.Menu): props.direction = 'CHILD' class VIEW3D_MT_select_PARTICLE(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Select" def draw(self, context): @@ -194,7 +194,7 @@ class VIEW3D_MT_select_PARTICLE(bpy.types.Menu): layout.itemO("particle.select_less") class VIEW3D_MT_select_EDIT_MESH(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Select" def draw(self, context): @@ -238,7 +238,7 @@ class VIEW3D_MT_select_EDIT_MESH(bpy.types.Menu): layout.itemO("mesh.region_to_loop") class VIEW3D_MT_select_EDIT_CURVE(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Select" def draw(self, context): @@ -267,7 +267,7 @@ class VIEW3D_MT_select_EDIT_CURVE(bpy.types.Menu): layout.itemO("curve.select_less") class VIEW3D_MT_select_EDIT_SURFACE(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Select" def draw(self, context): @@ -293,7 +293,7 @@ class VIEW3D_MT_select_EDIT_SURFACE(bpy.types.Menu): layout.itemO("curve.select_less") class VIEW3D_MT_select_EDIT_METABALL(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Select" def draw(self, context): @@ -311,7 +311,7 @@ class VIEW3D_MT_select_EDIT_METABALL(bpy.types.Menu): layout.itemL(text="Random") class VIEW3D_MT_select_EDIT_LATTICE(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Select" def draw(self, context): @@ -324,7 +324,7 @@ class VIEW3D_MT_select_EDIT_LATTICE(bpy.types.Menu): layout.itemO("lattice.select_all_toggle", text="Select/Deselect All") class VIEW3D_MT_select_EDIT_ARMATURE(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Select" def draw(self, context): @@ -353,7 +353,7 @@ class VIEW3D_MT_select_EDIT_ARMATURE(bpy.types.Menu): props.direction = 'CHILD' class VIEW3D_MT_select_FACE(bpy.types.Menu):# XXX no matching enum - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Select" def draw(self, context): @@ -364,7 +364,7 @@ class VIEW3D_MT_select_FACE(bpy.types.Menu):# XXX no matching enum # ********** Object menu ********** class VIEW3D_MT_object(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __context__ = "objectmode" __label__ = "Object" @@ -402,7 +402,7 @@ class VIEW3D_MT_object(bpy.types.Menu): layout.itemM("VIEW3D_MT_object_show") class VIEW3D_MT_object_clear(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Clear" def draw(self, context): @@ -414,7 +414,7 @@ class VIEW3D_MT_object_clear(bpy.types.Menu): layout.itemO("object.origin_clear") class VIEW3D_MT_object_snap(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Snap" def draw(self, context): @@ -431,7 +431,7 @@ class VIEW3D_MT_object_snap(bpy.types.Menu): layout.itemO("view3d.snap_cursor_to_active") class VIEW3D_MT_object_parent(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Parent" def draw(self, context): @@ -441,7 +441,7 @@ class VIEW3D_MT_object_parent(bpy.types.Menu): layout.itemO("object.parent_clear") class VIEW3D_MT_object_track(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Track" def draw(self, context): @@ -451,7 +451,7 @@ class VIEW3D_MT_object_track(bpy.types.Menu): layout.itemO("object.track_clear") class VIEW3D_MT_object_group(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Group" def draw(self, context): @@ -466,7 +466,7 @@ class VIEW3D_MT_object_group(bpy.types.Menu): layout.itemO("group.objects_remove_active") class VIEW3D_MT_object_constraints(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Constraints" def draw(self, context): @@ -476,7 +476,7 @@ class VIEW3D_MT_object_constraints(bpy.types.Menu): layout.itemO("object.constraints_clear") class VIEW3D_MT_object_show(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Show/Hide" def draw(self, context): @@ -489,7 +489,7 @@ class VIEW3D_MT_object_show(bpy.types.Menu): # ********** Vertex paint menu ********** class VIEW3D_MT_vertex_paint(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Paint" def draw(self, context): @@ -504,7 +504,7 @@ class VIEW3D_MT_vertex_paint(bpy.types.Menu): # ********** Sculpt menu ********** class VIEW3D_MT_sculpt(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Sculpt" def draw(self, context): @@ -540,7 +540,7 @@ class VIEW3D_MT_sculpt(bpy.types.Menu): # ********** Edit Menus, suffix from ob.type ********** class VIEW3D_MT_edit_snap(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Snap" def draw(self, context): @@ -558,7 +558,7 @@ class VIEW3D_MT_edit_snap(bpy.types.Menu): # Edit MESH class VIEW3D_MT_edit_MESH(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Mesh" def draw(self, context): @@ -601,7 +601,7 @@ class VIEW3D_MT_edit_MESH(bpy.types.Menu): layout.itemM("VIEW3D_MT_edit_MESH_showhide") class VIEW3D_MT_edit_MESH_vertices(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Vertices" def draw(self, context): @@ -618,7 +618,7 @@ class VIEW3D_MT_edit_MESH_vertices(bpy.types.Menu): layout.itemO("mesh.remove_doubles") class VIEW3D_MT_edit_MESH_edges(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Edges" def draw(self, context): @@ -644,7 +644,7 @@ class VIEW3D_MT_edit_MESH_edges(bpy.types.Menu): layout.item_enumO("mesh.edge_rotate", "direction", 'CCW', text="Rotate Edge CCW") class VIEW3D_MT_edit_MESH_faces(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Faces" def draw(self, context): @@ -666,7 +666,7 @@ class VIEW3D_MT_edit_MESH_faces(bpy.types.Menu): layout.itemO("mesh.faces_shade_flat") class VIEW3D_MT_edit_MESH_normals(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Normals" def draw(self, context): @@ -680,7 +680,7 @@ class VIEW3D_MT_edit_MESH_normals(bpy.types.Menu): layout.itemO("mesh.flip_normals") class VIEW3D_MT_edit_MESH_showhide(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Show/Hide" def draw(self, context): @@ -724,13 +724,13 @@ def draw_CURVE(self, context): layout.itemM("VIEW3D_MT_edit_CURVE_showhide") class VIEW3D_MT_edit_CURVE(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Curve" draw = draw_CURVE class VIEW3D_MT_edit_CURVE_ctrlpoints(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Control Points" def draw(self, context): @@ -748,7 +748,7 @@ class VIEW3D_MT_edit_CURVE_ctrlpoints(bpy.types.Menu): layout.item_menu_enumO("curve.handle_type_set", "type") class VIEW3D_MT_edit_CURVE_segments(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Segments" def draw(self, context): @@ -758,7 +758,7 @@ class VIEW3D_MT_edit_CURVE_segments(bpy.types.Menu): layout.itemO("curve.switch_direction") class VIEW3D_MT_edit_CURVE_showhide(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Show/Hide" def draw(self, context): @@ -770,14 +770,14 @@ class VIEW3D_MT_edit_CURVE_showhide(bpy.types.Menu): # Edit SURFACE class VIEW3D_MT_edit_SURFACE(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Surface" draw = draw_CURVE # Edit TEXT class VIEW3D_MT_edit_TEXT(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Text" def draw(self, context): @@ -790,7 +790,7 @@ class VIEW3D_MT_edit_TEXT(bpy.types.Menu): layout.itemM("VIEW3D_MT_edit_TEXT_chars") class VIEW3D_MT_edit_TEXT_chars(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Special Characters" def draw(self, context): @@ -825,7 +825,7 @@ class VIEW3D_MT_edit_TEXT_chars(bpy.types.Menu): # Edit META class VIEW3D_MT_edit_META(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Metaball" def draw(self, context): @@ -855,7 +855,7 @@ class VIEW3D_MT_edit_META(bpy.types.Menu): layout.itemM("VIEW3D_MT_edit_META_showhide") class VIEW3D_MT_edit_META_showhide(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Show/Hide" def draw(self, context): @@ -867,7 +867,7 @@ class VIEW3D_MT_edit_META_showhide(bpy.types.Menu): # Edit LATTICE class VIEW3D_MT_edit_LATTICE(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Lattice" def draw(self, context): @@ -888,7 +888,7 @@ class VIEW3D_MT_edit_LATTICE(bpy.types.Menu): # Edit ARMATURE class VIEW3D_MT_edit_ARMATURE(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Armature" def draw(self, context): @@ -944,7 +944,7 @@ class VIEW3D_MT_edit_ARMATURE(bpy.types.Menu): layout.item_menu_enumO("armature.flags_set", "mode", text="Bone Settings") class VIEW3D_MT_edit_ARMATURE_parent(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Parent" def draw(self, context): @@ -954,7 +954,7 @@ class VIEW3D_MT_edit_ARMATURE_parent(bpy.types.Menu): layout.itemO("armature.parent_clear") class VIEW3D_MT_edit_ARMATURE_roll(bpy.types.Menu): - __space_type__ = "VIEW_3D" + __space_type__ = 'VIEW_3D' __label__ = "Bone Roll" def draw(self, context): @@ -970,8 +970,8 @@ class VIEW3D_MT_edit_ARMATURE_roll(bpy.types.Menu): # ********** Panel ********** class VIEW3D_PT_3dview_properties(bpy.types.Panel): - __space_type__ = "VIEW_3D" - __region_type__ = "UI" + __space_type__ = 'VIEW_3D' + __region_type__ = 'UI' __label__ = "View" def poll(self, context): @@ -1002,8 +1002,8 @@ class VIEW3D_PT_3dview_properties(bpy.types.Panel): layout.column().itemR(scene, "cursor_location", text="3D Cursor:") class VIEW3D_PT_3dview_display(bpy.types.Panel): - __space_type__ = "VIEW_3D" - __region_type__ = "UI" + __space_type__ = 'VIEW_3D' + __region_type__ = 'UI' __label__ = "Display" def poll(self, context): @@ -1034,8 +1034,8 @@ class VIEW3D_PT_3dview_display(bpy.types.Panel): col.itemR(view, "box_clip") class VIEW3D_PT_background_image(bpy.types.Panel): - __space_type__ = "VIEW_3D" - __region_type__ = "UI" + __space_type__ = 'VIEW_3D' + __region_type__ = 'UI' __label__ = "Background Image" __default_closed__ = True diff --git a/release/ui/space_view3d_toolbar.py b/release/ui/space_view3d_toolbar.py index 254fb3fd560..bbca43279a7 100644 --- a/release/ui/space_view3d_toolbar.py +++ b/release/ui/space_view3d_toolbar.py @@ -2,8 +2,8 @@ import bpy class View3DPanel(bpy.types.Panel): - __space_type__ = "VIEW_3D" - __region_type__ = "TOOLS" + __space_type__ = 'VIEW_3D' + __region_type__ = 'TOOLS' # ********** default tools for objectmode **************** @@ -262,8 +262,8 @@ class VIEW3D_PT_tools_posemode(View3DPanel): # ********** default tools for paint modes **************** class PaintPanel(bpy.types.Panel): - __space_type__ = "VIEW_3D" - __region_type__ = "TOOLS" + __space_type__ = 'VIEW_3D' + __region_type__ = 'TOOLS' def paint_settings(self, context): ts = context.tool_settings From 2aa2512a43781f6ac8937c152398e9de731aef07 Mon Sep 17 00:00:00 2001 From: William Reynish Date: Sat, 22 Aug 2009 09:21:08 +0000 Subject: [PATCH 63/73] Tiny User Prefs tweaks. Also put the Save As Default button in header so it stays put. --- release/ui/space_userpref.py | 40 +++++++++++++++++------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/release/ui/space_userpref.py b/release/ui/space_userpref.py index acd3d3eb44b..82ed857c7ea 100644 --- a/release/ui/space_userpref.py +++ b/release/ui/space_userpref.py @@ -7,6 +7,11 @@ class USERPREF_HT_header(bpy.types.Header): def draw(self, context): layout = self.layout layout.template_header(menus=False) + + userpref = context.user_preferences + + layout.operator_context = "EXEC_AREA" + layout.itemO("wm.save_homefile", text="Save As Default") class USERPREF_MT_view(bpy.types.Menu): __space_type__ = 'USER_PREFERENCES' @@ -59,11 +64,11 @@ class USERPREF_PT_view(bpy.types.Panel): sub1.itemS() sub1.itemS() sub1.itemS() - sub1.itemR(view, "show_mini_axis") + sub1.itemR(view, "show_mini_axis", text="Display Mini Axis") sub2 = sub1.column() sub2.enabled = view.show_mini_axis - sub2.itemR(view, "mini_axis_size") - sub2.itemR(view, "mini_axis_brightness") + sub2.itemR(view, "mini_axis_size", text="Size") + sub2.itemR(view, "mini_axis_brightness", text="Brightness") col = split.column() sub = col.split(percentage=0.85) @@ -360,6 +365,8 @@ class USERPREF_PT_filepaths(bpy.types.Panel): sub2.itemR(paths, "use_relative_paths") sub2.itemR(paths, "compress_file") sub2.itemR(paths, "load_ui") + sub2.itemS() + sub2.itemS() sub2.itemL(text="Auto Save:") sub2.itemR(paths, "save_version") sub2.itemR(paths, "recent_files") @@ -367,7 +374,7 @@ class USERPREF_PT_filepaths(bpy.types.Panel): sub2.itemR(paths, "auto_save_temporary_files") sub3 = sub2.column() sub3.enabled = paths.auto_save_temporary_files - sub3.itemR(paths, "auto_save_time") + sub3.itemR(paths, "auto_save_time", text="Timer (mins)") class USERPREF_PT_language(bpy.types.Panel): __space_type__ = 'USER_PREFERENCES' @@ -388,24 +395,16 @@ class USERPREF_PT_language(bpy.types.Panel): col = split.column() col.itemR(lan, "language") - col.itemR(lan, "translate_tooltips") - col.itemR(lan, "translate_buttons") - col.itemR(lan, "translate_toolbox") + col.itemL(text="Translate:") + col.itemR(lan, "translate_tooltips", text="Tooltips") + col.itemR(lan, "translate_buttons", text="Labels") + col.itemR(lan, "translate_toolbox", text="Toolbox") + col.itemS() + col.itemS() col.itemR(lan, "use_textured_fonts") -class USERPREF_PT_bottombar(bpy.types.Panel): - __space_type__ = 'USER_PREFERENCES' - __label__ = " " - __show_header__ = False - - def draw(self, context): - layout = self.layout - userpref = context.user_preferences - - split = layout.split(percentage=0.8) - split.itemL(text="") - layout.operator_context = "EXEC_AREA" - split.itemO("wm.save_homefile", text="Save As Default") + col = split.column() + bpy.types.register(USERPREF_HT_header) bpy.types.register(USERPREF_MT_view) @@ -415,5 +414,4 @@ bpy.types.register(USERPREF_PT_edit) bpy.types.register(USERPREF_PT_system) bpy.types.register(USERPREF_PT_filepaths) bpy.types.register(USERPREF_PT_language) -bpy.types.register(USERPREF_PT_bottombar) From a4f3f5c23c4201bc885310aa17226d2ee3922a2a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 22 Aug 2009 10:51:21 +0000 Subject: [PATCH 64/73] - BGE, Some sensors, stored the event manager in 2 places (became confusing to do changes in this area) - Change compiler warnings for linux/scons/C++ --- config/linux2-config.py | 3 +- .../GameLogic/SCA_JoystickSensor.cpp | 33 +++++++++---------- .../gameengine/GameLogic/SCA_JoystickSensor.h | 1 - .../gameengine/GameLogic/SCA_MouseSensor.cpp | 5 ++- source/gameengine/GameLogic/SCA_MouseSensor.h | 1 - .../KXNetwork/KX_NetworkMessageSensor.cpp | 1 - .../KXNetwork/KX_NetworkMessageSensor.h | 1 - source/gameengine/Ketsji/KX_TouchSensor.cpp | 3 +- source/gameengine/Ketsji/KX_TouchSensor.h | 1 - 9 files changed, 21 insertions(+), 28 deletions(-) diff --git a/config/linux2-config.py b/config/linux2-config.py index b0ff0b89d3d..3e84070fabb 100644 --- a/config/linux2-config.py +++ b/config/linux2-config.py @@ -190,8 +190,9 @@ REL_CCFLAGS = ['-O2'] ##ARFLAGSQUIET = ru ## C_WARN = ['-Wno-char-subscripts', '-Wdeclaration-after-statement'] - CC_WARN = ['-Wall'] +CXX_WARN = ['-Wno-invalid-offsetof', '-Wno-sign-compare'] + ##FIX_STUBS_WARNINGS = -Wno-unused diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 336529667d7..81aa3020f49 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -49,7 +49,6 @@ SCA_JoystickSensor::SCA_JoystickSensor(class SCA_JoystickManager* eventmgr, int hat, int hatf, bool allevents, PyTypeObject* T ) :SCA_ISensor(gameobj,eventmgr,T), - m_pJoystickMgr(eventmgr), m_axis(axis), m_axisf(axisf), m_button(button), @@ -104,7 +103,7 @@ bool SCA_JoystickSensor::IsPositiveTrigger() bool SCA_JoystickSensor::Evaluate() { - SCA_Joystick *js = m_pJoystickMgr->GetJoystickDevice(m_joyindex); + SCA_Joystick *js = ((SCA_JoystickManager *)m_eventmgr)->GetJoystickDevice(m_joyindex); bool result = false; bool reset = m_reset && m_level; @@ -404,7 +403,7 @@ const char SCA_JoystickSensor::GetAxisValue_doc[] = "\tReturns a list of the values for the current state of each axis.\n"; PyObject* SCA_JoystickSensor::PyGetAxisValue( ) { ShowDeprecationWarning("getAxisValue()", "the axisPosition property"); - SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); + SCA_Joystick *joy = ((SCA_JoystickManager *)m_eventmgr)->GetJoystickDevice(m_joyindex); int axis_index= joy->GetNumberOfAxes(); PyObject *list= PyList_New(axis_index); @@ -479,7 +478,7 @@ const char SCA_JoystickSensor::GetButtonActiveList_doc[] = "getButtonActiveList\n" "\tReturns a list containing the indicies of the button currently pressed.\n"; PyObject* SCA_JoystickSensor::PyGetButtonActiveList( ) { - SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); + SCA_Joystick *joy = ((SCA_JoystickManager *)m_eventmgr)->GetJoystickDevice(m_joyindex); PyObject *ls = PyList_New(0); PyObject *value; int i; @@ -501,7 +500,7 @@ const char SCA_JoystickSensor::GetButtonStatus_doc[] = "getButtonStatus(buttonIndex)\n" "\tReturns a bool of the current pressed state of the specified button.\n"; PyObject* SCA_JoystickSensor::PyGetButtonStatus( PyObject* args ) { - SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); + SCA_Joystick *joy = ((SCA_JoystickManager *)m_eventmgr)->GetJoystickDevice(m_joyindex); int index; if(!PyArg_ParseTuple(args, "i:getButtonStatus", &index)){ @@ -547,7 +546,7 @@ const char SCA_JoystickSensor::NumberOfAxes_doc[] = "\tReturns the number of axes .\n"; PyObject* SCA_JoystickSensor::PyNumberOfAxes( ) { ShowDeprecationWarning("getNumAxes()", "the numAxis property"); - SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); + SCA_Joystick *joy = ((SCA_JoystickManager *)m_eventmgr)->GetJoystickDevice(m_joyindex); // when the joystick is null their is 0 exis still. dumb but scripters should use isConnected() return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 ); } @@ -558,7 +557,7 @@ const char SCA_JoystickSensor::NumberOfButtons_doc[] = "\tReturns the number of buttons .\n"; PyObject* SCA_JoystickSensor::PyNumberOfButtons( ) { ShowDeprecationWarning("getNumButtons()", "the numButtons property"); - SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); + SCA_Joystick *joy = ((SCA_JoystickManager *)m_eventmgr)->GetJoystickDevice(m_joyindex); return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 ); } @@ -568,7 +567,7 @@ const char SCA_JoystickSensor::NumberOfHats_doc[] = "\tReturns the number of hats .\n"; PyObject* SCA_JoystickSensor::PyNumberOfHats( ) { ShowDeprecationWarning("getNumHats()", "the numHats property"); - SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); + SCA_Joystick *joy = ((SCA_JoystickManager *)m_eventmgr)->GetJoystickDevice(m_joyindex); return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 ); } @@ -577,7 +576,7 @@ const char SCA_JoystickSensor::Connected_doc[] = "\tReturns True if a joystick is connected at this joysticks index.\n"; PyObject* SCA_JoystickSensor::PyConnected( ) { ShowDeprecationWarning("getConnected()", "the connected property"); - SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); + SCA_Joystick *joy = ((SCA_JoystickManager *)m_eventmgr)->GetJoystickDevice(m_joyindex); return PyBool_FromLong( joy ? joy->Connected() : 0 ); } @@ -585,7 +584,7 @@ PyObject* SCA_JoystickSensor::PyConnected( ) { PyObject* SCA_JoystickSensor::pyattr_get_axis_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { SCA_JoystickSensor* self= static_cast(self_v); - SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex); int axis_index= joy->GetNumberOfAxes(); PyObject *list= PyList_New(axis_index); @@ -600,7 +599,7 @@ PyObject* SCA_JoystickSensor::pyattr_get_axis_values(void *self_v, const KX_PYAT PyObject* SCA_JoystickSensor::pyattr_get_axis_single(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { SCA_JoystickSensor* self= static_cast(self_v); - SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex); if(self->m_joymode != KX_JOYSENSORMODE_AXIS_SINGLE) { PyErr_SetString(PyExc_TypeError, "val = sensor.axisSingle: Joystick Sensor, not 'Single Axis' type"); @@ -613,7 +612,7 @@ PyObject* SCA_JoystickSensor::pyattr_get_axis_single(void *self_v, const KX_PYAT PyObject* SCA_JoystickSensor::pyattr_get_hat_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { SCA_JoystickSensor* self= static_cast(self_v); - SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex); int hat_index= joy->GetNumberOfHats(); PyObject *list= PyList_New(hat_index); @@ -628,7 +627,7 @@ PyObject* SCA_JoystickSensor::pyattr_get_hat_values(void *self_v, const KX_PYATT PyObject* SCA_JoystickSensor::pyattr_get_hat_single(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { SCA_JoystickSensor* self= static_cast(self_v); - SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex); return PyInt_FromLong(joy->GetHat(self->m_hat-1)); } @@ -636,27 +635,27 @@ PyObject* SCA_JoystickSensor::pyattr_get_hat_single(void *self_v, const KX_PYATT PyObject* SCA_JoystickSensor::pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { SCA_JoystickSensor* self= static_cast(self_v); - SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex); return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 ); } PyObject* SCA_JoystickSensor::pyattr_get_num_buttons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { SCA_JoystickSensor* self= static_cast(self_v); - SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex); return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 ); } PyObject* SCA_JoystickSensor::pyattr_get_num_hats(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { SCA_JoystickSensor* self= static_cast(self_v); - SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex); return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 ); } PyObject* SCA_JoystickSensor::pyattr_get_connected(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { SCA_JoystickSensor* self= static_cast(self_v); - SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex); return PyBool_FromLong( joy ? joy->Connected() : 0 ); } diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.h b/source/gameengine/GameLogic/SCA_JoystickSensor.h index e6a1d2eef32..f5ff25c73dc 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.h +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.h @@ -35,7 +35,6 @@ class SCA_JoystickSensor :public SCA_ISensor { Py_Header; - class SCA_JoystickManager* m_pJoystickMgr; /** * Axis 1-JOYAXIS_MAX, MUST be followed by m_axisf diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index c5e1c3c0441..1a0a3939d54 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -52,7 +52,6 @@ SCA_MouseSensor::SCA_MouseSensor(SCA_MouseManager* eventmgr, SCA_IObject* gameobj, PyTypeObject* T) : SCA_ISensor(gameobj,eventmgr, T), - m_pMouseMgr(eventmgr), m_x(startx), m_y(starty) { @@ -148,7 +147,7 @@ bool SCA_MouseSensor::Evaluate() { bool result = false; bool reset = m_reset && m_level; - SCA_IInputDevice* mousedev = m_pMouseMgr->GetInputDevice(); + SCA_IInputDevice* mousedev = ((SCA_MouseManager *)m_eventmgr)->GetInputDevice(); m_reset = false; switch (m_mousemode) { @@ -283,7 +282,7 @@ KX_PYMETHODDEF_DOC_O(SCA_MouseSensor, getButtonStatus, return NULL; } - SCA_IInputDevice* mousedev = m_pMouseMgr->GetInputDevice(); + SCA_IInputDevice* mousedev = ((SCA_MouseManager *)m_eventmgr)->GetInputDevice(); const SCA_InputEvent& event = mousedev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) button); return PyInt_FromLong(event.m_status); } diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.h b/source/gameengine/GameLogic/SCA_MouseSensor.h index 6d6302b514a..14d3ace5408 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.h +++ b/source/gameengine/GameLogic/SCA_MouseSensor.h @@ -39,7 +39,6 @@ class SCA_MouseSensor : public SCA_ISensor { Py_Header; - class SCA_MouseManager* m_pMouseMgr; /** * Use SCA_IInputDevice values to encode the mouse mode for now. diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp index 8ddcd87b66f..014670dd76d 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp @@ -54,7 +54,6 @@ KX_NetworkMessageSensor::KX_NetworkMessageSensor( PyTypeObject* T ) : SCA_ISensor(gameobj,eventmgr,T), - m_Networkeventmgr(eventmgr), m_NetworkScene(NetworkScene), m_subject(subject), m_frame_message_count (0), diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h index 53183f33826..dd207230e0c 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h @@ -39,7 +39,6 @@ class KX_NetworkMessageSensor : public SCA_ISensor { // note: Py_Header MUST BE the first listed here Py_Header; - KX_NetworkEventManager *m_Networkeventmgr; NG_NetworkScene *m_NetworkScene; // The subject we filter on. diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index c06acd4a873..5b23a9d0e3e 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -101,8 +101,7 @@ KX_TouchSensor::KX_TouchSensor(SCA_EventManager* eventmgr,KX_GameObject* gameobj :SCA_ISensor(gameobj,eventmgr,T), m_touchedpropname(touchedpropname), m_bFindMaterial(bFindMaterial), -m_bTouchPulse(bTouchPulse), -m_eventmgr(eventmgr) +m_bTouchPulse(bTouchPulse) /*m_sumoObj(sumoObj),*/ { // KX_TouchEventManager* touchmgr = (KX_TouchEventManager*) eventmgr; diff --git a/source/gameengine/Ketsji/KX_TouchSensor.h b/source/gameengine/Ketsji/KX_TouchSensor.h index 476c63e89db..7ec8d1277aa 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.h +++ b/source/gameengine/Ketsji/KX_TouchSensor.h @@ -58,7 +58,6 @@ protected: STR_String m_touchedpropname; bool m_bFindMaterial; bool m_bTouchPulse; /* changes in the colliding objects trigger pulses */ - class SCA_EventManager* m_eventmgr; class PHY_IPhysicsController* m_physCtrl; From 580d38336481bcd9a149bd2e2dc9f0faaf872f49 Mon Sep 17 00:00:00 2001 From: William Reynish Date: Sat, 22 Aug 2009 11:51:26 +0000 Subject: [PATCH 65/73] Moved mesh display options to the 3D view n-key area, next to other display options. The DNA/RNA for these options should be changed to reflect this. --- release/ui/buttons_data_mesh.py | 31 ----------------------------- release/ui/space_view3d.py | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/release/ui/buttons_data_mesh.py b/release/ui/buttons_data_mesh.py index c1311b32180..f91d706ead7 100644 --- a/release/ui/buttons_data_mesh.py +++ b/release/ui/buttons_data_mesh.py @@ -48,36 +48,6 @@ class DATA_PT_normals(DataButtonsPanel): col.itemR(mesh, "vertex_normal_flip") col.itemR(mesh, "double_sided") -class DATA_PT_meshdraw(DataButtonsPanel): - __label__ = "Draw" - - def draw(self, context): - layout = self.layout - - mesh = context.mesh - - layout.itemL(text="Edit Mode only, WIP") - - split = layout.split() - - col = split.column() - col.itemR(mesh, "draw_edges", text="Edges") - col.itemR(mesh, "draw_faces", text="Faces") - col.itemR(mesh, "draw_creases", text="Creases") - col.itemR(mesh, "draw_bevel_weights", text="Bevel Weights") - col.itemR(mesh, "draw_seams", text="Seams") - col.itemR(mesh, "draw_sharp", text="Sharp") - - col = split.column() - col.itemR(mesh, "draw_normals", text="Face Normals") - col.itemR(mesh, "draw_vertex_normals", text="Vertex Normals") - - col.itemS() - - col.itemR(mesh, "draw_edge_lenght") - col.itemR(mesh, "draw_edge_angle") - col.itemR(mesh, "draw_face_area") - class DATA_PT_vertex_groups(DataButtonsPanel): __label__ = "Vertex Groups" @@ -227,7 +197,6 @@ class DATA_PT_vertex_colors(DataButtonsPanel): bpy.types.register(DATA_PT_context_mesh) bpy.types.register(DATA_PT_normals) -bpy.types.register(DATA_PT_meshdraw) bpy.types.register(DATA_PT_vertex_groups) bpy.types.register(DATA_PT_shape_keys) bpy.types.register(DATA_PT_uv_texture) diff --git a/release/ui/space_view3d.py b/release/ui/space_view3d.py index 8f37b34e3b4..8e5bc100af1 100644 --- a/release/ui/space_view3d.py +++ b/release/ui/space_view3d.py @@ -1032,6 +1032,40 @@ class VIEW3D_PT_3dview_display(bpy.types.Panel): col.itemR(view, "lock_rotation") col.itemR(view, "box_preview") col.itemR(view, "box_clip") + +class VIEW3D_PT_3dview_meshdisplay(bpy.types.Panel): + __space_type__ = 'VIEW_3D' + __region_type__ = 'UI' + __label__ = "Mesh Display" + + def poll(self, context): + editmesh = context.mode == 'EDIT_MESH' + return (editmesh) + + def draw(self, context): + layout = self.layout + + mesh = context.active_object.data + + col = layout.column() + col.itemL(text="Overlays:") + col.itemR(mesh, "draw_edges", text="Edges") + col.itemR(mesh, "draw_faces", text="Faces") + col.itemR(mesh, "draw_creases", text="Creases") + col.itemR(mesh, "draw_bevel_weights", text="Bevel Weights") + col.itemR(mesh, "draw_seams", text="Seams") + col.itemR(mesh, "draw_sharp", text="Sharp") + + col.itemS() + col.itemL(text="Normals:") + col.itemR(mesh, "draw_normals", text="Face") + col.itemR(mesh, "draw_vertex_normals", text="Vertex") + + col.itemS() + col.itemL(text="Numerics:") + col.itemR(mesh, "draw_edge_lenght") + col.itemR(mesh, "draw_edge_angle") + col.itemR(mesh, "draw_face_area") class VIEW3D_PT_background_image(bpy.types.Panel): __space_type__ = 'VIEW_3D' @@ -1129,4 +1163,5 @@ bpy.types.register(VIEW3D_MT_edit_ARMATURE_roll) bpy.types.register(VIEW3D_PT_3dview_properties) # Panels bpy.types.register(VIEW3D_PT_3dview_display) +bpy.types.register(VIEW3D_PT_3dview_meshdisplay) bpy.types.register(VIEW3D_PT_background_image) From f08a4c9719ac3d745dfcbae3acc3ca48c38777ad Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 22 Aug 2009 14:19:27 +0000 Subject: [PATCH 66/73] missed this in last commit. keyboard event manager was stored twice. --- .../gameengine/GameLogic/SCA_KeyboardSensor.cpp | 15 +++++++-------- source/gameengine/GameLogic/SCA_KeyboardSensor.h | 2 -- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index f8ee8ed8b41..a5581f0d987 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -51,7 +51,6 @@ SCA_KeyboardSensor::SCA_KeyboardSensor(SCA_KeyboardManager* keybdmgr, SCA_IObject* gameobj, PyTypeObject* T ) :SCA_ISensor(gameobj,keybdmgr,T), - m_pKeyboardMgr(keybdmgr), m_hotkey(hotkey), m_qual(qual), m_qual2(qual2), @@ -126,7 +125,7 @@ bool SCA_KeyboardSensor::Evaluate() bool qual_change = false; short int m_val_orig = m_val; - SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); + SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice(); // cerr << "SCA_KeyboardSensor::Eval event, sensing for "<< m_hotkey << " at device " << inputdev << "\n"; /* See if we need to do logging: togPropState exists and is @@ -361,7 +360,7 @@ void SCA_KeyboardSensor::AddToTargetProp(int keyIndex) */ bool SCA_KeyboardSensor::IsShifted(void) { - SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); + SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice(); if ( (inputdev->GetEventValue(SCA_IInputDevice::KX_RIGHTSHIFTKEY).m_status == SCA_InputEvent::KX_ACTIVE) @@ -380,7 +379,7 @@ bool SCA_KeyboardSensor::IsShifted(void) void SCA_KeyboardSensor::LogKeystrokes(void) { - SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); + SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice(); int num = inputdev->GetNumActiveEvents(); /* weird loop, this one... */ @@ -515,7 +514,7 @@ PyObject* SCA_KeyboardSensor::PyGetPressedKeys() { ShowDeprecationWarning("getPressedKeys()", "events"); - SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); + SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice(); int num = inputdev->GetNumJustEvents(); PyObject* resultlist = PyList_New(num); @@ -556,7 +555,7 @@ PyObject* SCA_KeyboardSensor::PyGetCurrentlyPressedKeys() { ShowDeprecationWarning("getCurrentlyPressedKeys()", "events"); - SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); + SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice(); int num = inputdev->GetNumActiveEvents(); PyObject* resultlist = PyList_New(num); @@ -605,7 +604,7 @@ KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus, return NULL; } - SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); + SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice(); const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) keycode); return PyInt_FromLong(inevent.m_status); } @@ -691,7 +690,7 @@ PyObject* SCA_KeyboardSensor::pyattr_get_events(void *self_v, const KX_PYATTRIBU { SCA_KeyboardSensor* self= static_cast(self_v); - SCA_IInputDevice* inputdev = self->m_pKeyboardMgr->GetInputDevice(); + SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)self->m_eventmgr)->GetInputDevice(); PyObject* resultlist = PyList_New(0); diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.h b/source/gameengine/GameLogic/SCA_KeyboardSensor.h index 033225cd9be..13fcc21ab7b 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.h +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.h @@ -43,8 +43,6 @@ class SCA_KeyboardSensor : public SCA_ISensor { Py_Header; - class SCA_KeyboardManager* m_pKeyboardMgr; - /** * the key this sensor is sensing for From 98e9ddbf5b2b9dcf8a6a2440126f928d4394a5f4 Mon Sep 17 00:00:00 2001 From: Joerg Mueller Date: Sat, 22 Aug 2009 16:54:18 +0000 Subject: [PATCH 67/73] Bugfixing. --- intern/audaspace/jack/AUD_JackDevice.cpp | 4 ---- intern/audaspace/jack/AUD_JackDevice.h | 3 --- source/blender/blenkernel/intern/blender.c | 3 +-- source/blender/blenkernel/intern/sound.c | 8 ++------ source/creator/creator.c | 1 - 5 files changed, 3 insertions(+), 16 deletions(-) diff --git a/intern/audaspace/jack/AUD_JackDevice.cpp b/intern/audaspace/jack/AUD_JackDevice.cpp index 1f2c6faa511..445e68e1a9a 100644 --- a/intern/audaspace/jack/AUD_JackDevice.cpp +++ b/intern/audaspace/jack/AUD_JackDevice.cpp @@ -31,8 +31,6 @@ #include #include -#ifdef WITH_JACK - // AUD_XXX this is not realtime suitable! int AUD_JackDevice::jack_mix(jack_nframes_t length, void *data) { @@ -149,5 +147,3 @@ void AUD_JackDevice::playing(bool playing) { // Do nothing. } - -#endif diff --git a/intern/audaspace/jack/AUD_JackDevice.h b/intern/audaspace/jack/AUD_JackDevice.h index e6d332e1160..f0c887a2f43 100644 --- a/intern/audaspace/jack/AUD_JackDevice.h +++ b/intern/audaspace/jack/AUD_JackDevice.h @@ -26,7 +26,6 @@ #ifndef AUD_JACKDEVICE #define AUD_JACKDEVICE -#ifdef WITH_JACK #include "AUD_SoftwareDevice.h" class AUD_Buffer; @@ -90,6 +89,4 @@ public: virtual ~AUD_JackDevice(); }; -#endif //WITH_JACK - #endif //AUD_JACKDEVICE diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 746dc6c59cc..f261b020717 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -626,8 +626,7 @@ void BKE_write_undo(bContext *C, char *name) } } -/* 1= an undo, -1 is a redo. we have to make sure 'curundo' remains at current situation - * Note, ALWAYS call sound_initialize_sounds after BKE_undo_step() */ +/* 1= an undo, -1 is a redo. we have to make sure 'curundo' remains at current situation */ void BKE_undo_step(bContext *C, int step) { diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index a3275792a85..74ab41ff577 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -319,8 +319,6 @@ void sound_stop_all(struct bContext *C) } } -#define SOUND_PLAYBACK_LAMBDA 1.0 - void sound_update_playing(struct bContext *C) { SoundHandle *handle; @@ -366,12 +364,10 @@ void sound_update_playing(struct bContext *C) action = 3; else { - float diff = AUD_getPosition(handle->handle) - (cfra - handle->startframe) / fps; -// AUD_XXX float diff = AUD_getPosition(handle->handle) * fps - cfra + handle->startframe + float diff = AUD_getPosition(handle->handle) * fps - cfra + handle->startframe; if(diff < 0.0) diff = -diff; - if(diff > SOUND_PLAYBACK_LAMBDA) -// AUD_XXX if(diff > 5.0f) + if(diff > 1.0f) { action = 2; } diff --git a/source/creator/creator.c b/source/creator/creator.c index 5ecd95ecc21..41b27b1c915 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -821,7 +821,6 @@ int main(int argc, char **argv) if (G.background) { int retval = BKE_read_file(C, argv[a], NULL, NULL); -// XXX sound_initialize_sounds(); /*we successfully loaded a blend file, get sure that pointcache works */ From 215f80361cfeb294aed9e93cb6899d18c28d8bbf Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 22 Aug 2009 17:06:10 +0000 Subject: [PATCH 68/73] bpy's __rna__ attribute doesnt work as it should, since the parent classes __rna__ overrides the subtypes. For now have pyrna_struct_as_srna look in the dict first for __rna__ before using PyDict_GetItemString. Somehow __rna__ is not calling the pyrna_struct_getattro function, python find it first. The only relyable way to get the rna from python currently is. bpy.types.SomeType.__dict__['__rna__'] --- source/blender/python/intern/bpy_rna.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index bece114d8bd..31648037346 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -2655,8 +2655,17 @@ PyObject *BPY_rna_props( void ) static StructRNA *pyrna_struct_as_srna(PyObject *self) { - BPy_StructRNA *py_srna= (BPy_StructRNA*)PyObject_GetAttrString(self, "__rna__"); + BPy_StructRNA *py_srna; StructRNA *srna; + + /* ack, PyObject_GetAttrString wont look up this types tp_dict first :/ */ + if(PyType_Check(self)) { + py_srna = (BPy_StructRNA *)PyDict_GetItemString(((PyTypeObject *)self)->tp_dict, "__rna__"); + Py_XINCREF(py_srna); + } + + if(py_srna==NULL) + py_srna = (BPy_StructRNA*)PyObject_GetAttrString(self, "__rna__"); if(py_srna==NULL) { PyErr_SetString(PyExc_SystemError, "internal error, self had no __rna__ attribute, should never happen."); From 4ca76ac543b2dff8e3c7bf796203d07033703983 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 22 Aug 2009 17:11:36 +0000 Subject: [PATCH 69/73] [#19229] 1 line fix resolves - segmentation Fault from Martin Frances (martinfrances) Added a scene check when appending objects so you can append data without a scene. --- source/blender/blenloader/intern/readfile.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 72aba02f723..77b51d950b9 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -3093,7 +3093,7 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles) psys->flag &= ~PSYS_KEYED; } - if(psys->particles->boid) { + if(psys->particles && psys->particles->boid) { pa = psys->particles; pa->boid = newdataadr(fd, pa->boid); for(a=1,pa++; atotpart; a++, pa++) @@ -10804,14 +10804,16 @@ static Library* library_append(Main *mainvar, Scene *scene, char* file, char *di fix_relpaths_library(G.sce, mainvar); /* make all relative paths, relative to the open blend file */ /* give a base to loose objects. If group append, do it for objects too */ - if(idcode==ID_GR) { - if (flag & FILE_LINK) { - give_base_to_objects(mainvar, scene, NULL, 0); + if(scene) { + if(idcode==ID_GR) { + if (flag & FILE_LINK) { + give_base_to_objects(mainvar, scene, NULL, 0); + } else { + give_base_to_objects(mainvar, scene, curlib, 1); + } } else { - give_base_to_objects(mainvar, scene, curlib, 1); - } - } else { - give_base_to_objects(mainvar, scene, NULL, 0); + give_base_to_objects(mainvar, scene, NULL, 0); + } } /* has been removed... erm, why? s..ton) */ /* 20040907: looks like they are give base already in append_named_part(); -Nathan L */ From 9cd19fd210d95d4442b47b05e7d550560bc17db8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 22 Aug 2009 17:19:31 +0000 Subject: [PATCH 70/73] [#19226] (2.5) blender uses deprecated 'strstream' STL class, causes warnings with gcc thanks to Mauro Toffanin (equilibrium) This is the only place where strstream were used. --- source/gameengine/VideoTexture/Exception.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/gameengine/VideoTexture/Exception.cpp b/source/gameengine/VideoTexture/Exception.cpp index 8704d49f2a7..35d335b5981 100644 --- a/source/gameengine/VideoTexture/Exception.cpp +++ b/source/gameengine/VideoTexture/Exception.cpp @@ -21,7 +21,7 @@ http://www.gnu.org/copyleft/lesser.txt. */ -#include +#include #include #include @@ -170,11 +170,11 @@ void Exception::setXptDesc (void) // length of result code const size_t rsltSize = 11; // delimit description - const char delimRslt[] = ": "; + //const char delimRslt[] = ": "; // set text of description char rsltTxt[rsltSize]; - std::ostrstream os(rsltTxt, rsltSize); - os << std::hex << m_hRslt << delimRslt << '\0'; + std::ostringstream os; + os << std::hex << m_hRslt << ": " << '\0'; // copy result to description m_desc.insert(0, rsltTxt); // copy exception description to last exception string From 45bb3293b418745d515f237b8d39308f0a574000 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 22 Aug 2009 17:30:47 +0000 Subject: [PATCH 71/73] 2.5: Python subclasses can now define RNA properties by making a __props__ list in the class, same as for operators. --- source/blender/python/intern/bpy_rna.c | 54 ++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 31648037346..70ff8e48084 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -2940,12 +2940,12 @@ static StructRNA *pointer_type_from_py(PyObject *value) srna= srna_from_self(value); if(!srna) { - PyErr_SetString(PyExc_SystemError, "expected an RNA type derived from IDPropertyGroup (1)"); + PyErr_SetString(PyExc_SystemError, "expected an RNA type derived from IDPropertyGroup"); return NULL; } if(!RNA_struct_is_a(srna, &RNA_IDPropertyGroup)) { - PyErr_SetString(PyExc_SystemError, "expected an RNA type derived from IDPropertyGroup (3)"); + PyErr_SetString(PyExc_SystemError, "expected an RNA type derived from IDPropertyGroup"); return NULL; } @@ -3022,6 +3022,52 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; } +static int deferred_register_props(PyObject *py_class, StructRNA *srna) +{ + PyObject *props, *dummy_args, *item; + int i; + + props= PyObject_GetAttrString(py_class, "__props__"); + + if(!props) { + PyErr_Clear(); + return 1; + } + + dummy_args = PyTuple_New(0); + + for(i=0; i Date: Sat, 22 Aug 2009 17:50:10 +0000 Subject: [PATCH 72/73] use class __props__ for povray settings. --- release/io/engine_render_pov.py | 156 ++++++++++++++++---------------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/release/io/engine_render_pov.py b/release/io/engine_render_pov.py index 51aa26f7fb9..f89bdd05e06 100644 --- a/release/io/engine_render_pov.py +++ b/release/io/engine_render_pov.py @@ -801,9 +801,87 @@ class RenderButtonsPanel(bpy.types.Panel): return (rd.use_game_engine==False) and (rd.engine in self.COMPAT_ENGINES) # Radiosity panel, use in the scene for now. +FloatProperty= bpy.types.Scene.FloatProperty +IntProperty= bpy.types.Scene.IntProperty +BoolProperty= bpy.types.Scene.BoolProperty + class SCENE_PT_povray_radiosity(RenderButtonsPanel): __label__ = "Radiosity" COMPAT_ENGINES = set(['POVRAY_RENDER']) + + __props__ = [ \ + # Not a real pov option, just to know if we should write + BoolProperty( attr="pov_radio_enable", + name="Enable Radiosity", + description="Enable povrays radiosity calculation.", + default= False), + BoolProperty( attr="pov_radio_display_advanced", + name="Advanced Options", + description="Show advanced options.", + default= False), + + # Real pov options + FloatProperty( attr="pov_radio_adc_bailout", + name="ADC Bailout", + description="The adc_bailout for radiosity rays. Use adc_bailout = 0.01 / brightest_ambient_object for good results.", + min=0.0, max=1000.0, soft_min=0.0, soft_max=1.0, default= 0.01), + + BoolProperty( attr="pov_radio_always_sample", + name="Always Sample", + description="Only use the data from the pretrace step and not gather any new samples during the final radiosity pass..", + default= True), + + FloatProperty( attr="pov_radio_brightness", + name="Brightness", + description="Ammount objects are brightened before being returned upwards to the rest of the system.", + min=0.0, max=1000.0, soft_min=0.0, soft_max=10.0, default= 1.0), + + IntProperty( attr="pov_radio_count", + name="Ray Count", + description="number of rays that are sent out whenever a new radiosity value has to be calculated.", + min=1, max=1600, default= 35), + + FloatProperty( attr="pov_radio_error_bound", + name="Error Bound", + description="one of the two main speed/quality tuning values, lower values are more accurate.", + min=0.0, max=1000.0, soft_min=0.1, soft_max=10.0, default= 1.8), + + FloatProperty( attr="pov_radio_gray_threshold", + name="Gray Threshold", + description="one of the two main speed/quality tuning values, lower values are more accurate.", + min=0.0, max=1.0, soft_min=0, soft_max=1, default= 0.0), + + FloatProperty( attr="pov_radio_low_error_factor", + name="Low Error Factor", + description="If you calculate just enough samples, but no more, you will get an image which has slightly blotchy lighting.", + min=0.0, max=1.0, soft_min=0.0, soft_max=1.0, default= 0.5), + + # max_sample - not available yet + BoolProperty( attr="pov_radio_media", + name="Media", + description="Radiosity estimation can be affected by media.", + default= False), + + FloatProperty( attr="pov_radio_minimum_reuse", + name="Minimum Reuse", + description="Fraction of the screen width which sets the minimum radius of reuse for each sample point (At values higher than 2% expect errors).", + min=0.0, max=1.0, soft_min=0.1, soft_max=0.1, default= 0.015), + + IntProperty( attr="pov_radio_nearest_count", + name="Nearest Count", + description="Number of old ambient values blended together to create a new interpolated value.", + min=1, max=20, default= 5), + + BoolProperty( attr="pov_radio_normal", + name="Normals", + description="Radiosity estimation can be affected by normals.", + default= False), + + IntProperty( attr="pov_radio_recursion_limit", + name="Recursion Limit", + description="how many recursion levels are used to calculate the diffuse inter-reflection.", + min=1, max=20, default= 3), + ] def draw_header(self, context): layout = self.layout @@ -856,81 +934,3 @@ class SCENE_PT_povray_radiosity(RenderButtonsPanel): bpy.types.register(SCENE_PT_povray_radiosity) - - -FloatProperty= bpy.types.Scene.FloatProperty -IntProperty= bpy.types.Scene.IntProperty -BoolProperty= bpy.types.Scene.BoolProperty - -# Not a real pov option, just to know if we should write -BoolProperty( attr="pov_radio_enable", - name="Enable Radiosity", - description="Enable povrays radiosity calculation.", - default= False) -BoolProperty( attr="pov_radio_display_advanced", - name="Advanced Options", - description="Show advanced options.", - default= False) - -# Real pov options -FloatProperty( attr="pov_radio_adc_bailout", - name="ADC Bailout", - description="The adc_bailout for radiosity rays. Use adc_bailout = 0.01 / brightest_ambient_object for good results.", - min=0.0, max=1000.0, soft_min=0.0, soft_max=1.0, default= 0.01) - -BoolProperty( attr="pov_radio_always_sample", - name="Always Sample", - description="Only use the data from the pretrace step and not gather any new samples during the final radiosity pass..", - default= True) - -FloatProperty( attr="pov_radio_brightness", - name="Brightness", - description="Ammount objects are brightened before being returned upwards to the rest of the system.", - min=0.0, max=1000.0, soft_min=0.0, soft_max=10.0, default= 1.0) - -IntProperty( attr="pov_radio_count", - name="Ray Count", - description="number of rays that are sent out whenever a new radiosity value has to be calculated.", - min=1, max=1600, default= 35) - -FloatProperty( attr="pov_radio_error_bound", - name="Error Bound", - description="one of the two main speed/quality tuning values, lower values are more accurate.", - min=0.0, max=1000.0, soft_min=0.1, soft_max=10.0, default= 1.8) - -FloatProperty( attr="pov_radio_gray_threshold", - name="Gray Threshold", - description="one of the two main speed/quality tuning values, lower values are more accurate.", - min=0.0, max=1.0, soft_min=0, soft_max=1, default= 0.0) - -FloatProperty( attr="pov_radio_low_error_factor", - name="Low Error Factor", - description="If you calculate just enough samples, but no more, you will get an image which has slightly blotchy lighting.", - min=0.0, max=1.0, soft_min=0.0, soft_max=1.0, default= 0.5) - -# max_sample - not available yet - -BoolProperty( attr="pov_radio_media", - name="Media", - description="Radiosity estimation can be affected by media.", - default= False) - -FloatProperty( attr="pov_radio_minimum_reuse", - name="Minimum Reuse", - description="Fraction of the screen width which sets the minimum radius of reuse for each sample point (At values higher than 2% expect errors).", - min=0.0, max=1.0, soft_min=0.1, soft_max=0.1, default= 0.015) - -IntProperty( attr="pov_radio_nearest_count", - name="Nearest Count", - description="Number of old ambient values blended together to create a new interpolated value.", - min=1, max=20, default= 5) - -BoolProperty( attr="pov_radio_normal", - name="Normals", - description="Radiosity estimation can be affected by normals.", - default= False) - -IntProperty( attr="pov_radio_recursion_limit", - name="Recursion Limit", - description="how many recursion levels are used to calculate the diffuse inter-reflection.", - min=1, max=20, default= 3) From f82ce68a9eda382fead176398b624f28b5c9945c Mon Sep 17 00:00:00 2001 From: Matt Ebb Date: Sun, 23 Aug 2009 02:59:18 +0000 Subject: [PATCH 73/73] * enable ztransp transparency type for new materials by default. --- source/blender/blenkernel/intern/material.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 50db2bfe706..62ec12349aa 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -170,7 +170,7 @@ void init_material(Material *ma) ma->sss_front= 1.0f; ma->sss_back= 1.0f; - ma->mode= MA_TRACEBLE|MA_SHADBUF|MA_SHADOW|MA_RAYBIAS|MA_TANGENT_STR; + ma->mode= MA_TRACEBLE|MA_SHADBUF|MA_SHADOW|MA_RAYBIAS|MA_TANGENT_STR|MA_ZTRANSP; ma->preview = NULL; }