code cleanup:
authorCampbell Barton <ideasman42@gmail.com>
Fri, 3 Aug 2012 22:12:57 +0000 (22:12 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 3 Aug 2012 22:12:57 +0000 (22:12 +0000)
- replace (strcmp(vfont->name, FO_BUILTIN_NAME) == 0)  with  (BKE_vfont_is_builtin(vfont)).
- reduce some double promotions.

14 files changed:
source/blender/blenkernel/BKE_customdata.h
source/blender/blenkernel/BKE_font.h
source/blender/blenkernel/intern/customdata.c
source/blender/blenkernel/intern/font.c
source/blender/blenkernel/intern/packedFile.c
source/blender/blenlib/intern/bpath.c
source/blender/editors/curve/editfont.c
source/blender/editors/interface/interface_draw.c
source/blender/makesrna/intern/rna_ID.c
source/blender/makesrna/intern/rna_vfont.c
source/blender/windowmanager/intern/wm_operators.c
source/gameengine/Ketsji/KX_FontObject.cpp
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
source/gameengine/VideoTexture/ImageRender.cpp

index 3dc68edf12b37a09856c6b5ff6919fbcca8b7a13..8d486218d21cce73d09c7294bf571bda7c45b9a6 100644 (file)
@@ -310,7 +310,7 @@ int         CustomData_layertype_is_singleton(int type);
 /* make sure the name of layer at index is unique */
 void CustomData_set_layer_unique_name(struct CustomData *data, int index);
 
-void CustomData_validate_layer_name(const struct CustomData *data, int type, char *name, char *outname);
+void CustomData_validate_layer_name(const struct CustomData *data, int type, const char *name, char *outname);
 
 /* for file reading compatibility, returns false if the layer was freed,
  * only after this test passes, layer->data should be assigned */
index d1f0f8c8c2335ca7eb06459be4485cdc9b337542..69e8a6f0653c72dc6e11214792591395652e1ff6 100644 (file)
@@ -71,9 +71,10 @@ typedef struct EditFont {
 } EditFont;
 
 
+int  BKE_vfont_is_builtin(struct VFont *vfont);
 void BKE_vfont_builtin_register(void *mem, int size);
 
-void BKE_vfont_free_data(struct VFont *vf);
+void BKE_vfont_free_data(struct VFont *vfont);
 void BKE_vfont_free(struct VFont *sc); 
 void BKE_vfont_free_global_ttf(void);
 struct VFont *BKE_vfont_builtin_get(void);
index 8dd3b3da705e5d108695876ba2623fe21716d7f8..d92c4ca863255eedbccc621e2f7b8e176b5ac7be 100644 (file)
@@ -2793,7 +2793,7 @@ void CustomData_set_layer_unique_name(CustomData *data, int index)
        BLI_uniquename_cb(customdata_unique_check, &data_arg, typeInfo->defaultname, '.', nlayer->name, sizeof(nlayer->name));
 }
 
-void CustomData_validate_layer_name(const CustomData *data, int type, char *name, char *outname)
+void CustomData_validate_layer_name(const CustomData *data, int type, const char *name, char *outname)
 {
        int index = -1;
 
index 1ea8291adb1f7e936b93207262fceeb145fa8aec..74a8751b26a04cf687f4f069ef83662ba607d147 100644 (file)
@@ -64,11 +64,11 @@ static ListBase ttfdata = {NULL, NULL};
 
 /* The vfont code */
 
-void BKE_vfont_free_data(struct VFont *vf)
+void BKE_vfont_free_data(struct VFont *vfont)
 {
-       if (vf->data) {
-               while (vf->data->characters.first) {
-                       VChar *che = vf->data->characters.first;
+       if (vfont->data) {
+               while (vfont->data->characters.first) {
+                       VChar *che = vfont->data->characters.first;
 
                        while (che->nurbsbase.first) {
                                Nurb *nu = che->nurbsbase.first;
@@ -76,14 +76,14 @@ void BKE_vfont_free_data(struct VFont *vf)
                                BLI_freelinkN(&che->nurbsbase, nu);
                        }
 
-                       BLI_freelinkN(&vf->data->characters, che);
+                       BLI_freelinkN(&vfont->data->characters, che);
                }
 
-               MEM_freeN(vf->data);
-               vf->data = NULL;
+               MEM_freeN(vfont->data);
+               vfont->data = NULL;
        }
 
-       BKE_vfont_tmpfont_remove(vf);
+       BKE_vfont_tmpfont_remove(vfont);
 }
 
 void BKE_vfont_free(struct VFont *vf)
@@ -101,6 +101,11 @@ void BKE_vfont_free(struct VFont *vf)
 static void *builtin_font_data = NULL;
 static int builtin_font_size = 0;
 
+int  BKE_vfont_is_builtin(struct VFont *vfont)
+{
+       return (strcmp(vfont->name, FO_BUILTIN_NAME) == 0);
+}
+
 void BKE_vfont_builtin_register(void *mem, int size)
 {
        builtin_font_data = mem;
@@ -185,7 +190,7 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
        if (!vfont->data) {
                PackedFile *pf;
 
-               if (strcmp(vfont->name, FO_BUILTIN_NAME) == 0) {
+               if (BKE_vfont_is_builtin(vfont)) {
                        pf = get_builtin_packedfile();
                }
                else {
@@ -324,11 +329,13 @@ static VFont *which_vfont(Curve *cu, CharInfo *info)
 
 VFont *BKE_vfont_builtin_get(void)
 {
-       VFont *vf;
+       VFont *vfont;
        
-       for (vf = G.main->vfont.first; vf; vf = vf->id.next)
-               if (strcmp(vf->name, FO_BUILTIN_NAME) == 0)
-                       return vf;
+       for (vfont = G.main->vfont.first; vfont; vfont = vfont->id.next) {
+               if (BKE_vfont_is_builtin(vfont)) {
+                       return vfont;
+               }
+       }
        
        return BKE_vfont_load(G.main, FO_BUILTIN_NAME);
 }
@@ -663,10 +670,10 @@ makebreak:
 
                /*
                 * The character wasn't in the current curve base so load it
-                * But if the font is FO_BUILTIN_NAME then do not try loading since
+                * But if the font is built-in then do not try loading since
                 * whole font is in the memory already
                 */
-               if (che == NULL && strcmp(vfont->name, FO_BUILTIN_NAME)) {
+               if (che == NULL && BKE_vfont_is_builtin(vfont) == FALSE) {
                        BLI_vfontchar_from_freetypefont(vfont, ascii);
                }
 
index 52acbeb94e58bbae0d2f64150dd9a4b3c0d0d835..f115a41d4192278d2935a92f0d935a75bc38583c 100644 (file)
 #include "BLI_blenlib.h"
 #include "BLI_utildefines.h"
 
-#include "BKE_utildefines.h"
+#include "BKE_font.h"
 #include "BKE_global.h"
-#include "BKE_main.h"
-#include "BKE_sound.h"
 #include "BKE_image.h"
+#include "BKE_main.h"
 #include "BKE_packedFile.h"
 #include "BKE_report.h"
+#include "BKE_sound.h"
+#include "BKE_utildefines.h"
 
 #ifdef _WIN32
 #define open _open
@@ -219,7 +220,7 @@ PackedFile *newPackedFile(ReportList *reports, const char *filename, const char
 void packAll(Main *bmain, ReportList *reports)
 {
        Image *ima;
-       VFont *vf;
+       VFont *vfont;
        bSound *sound;
        
        for (ima = bmain->image.first; ima; ima = ima->id.next) {
@@ -233,9 +234,9 @@ void packAll(Main *bmain, ReportList *reports)
                }
        }
 
-       for (vf = bmain->vfont.first; vf; vf = vf->id.next)
-               if (vf->packedfile == NULL && vf->id.lib == NULL && strcmp(vf->name, FO_BUILTIN_NAME) != 0)
-                       vf->packedfile = newPackedFile(reports, vf->name, bmain->name);
+       for (vfont = bmain->vfont.first; vfont; vfont = vfont->id.next)
+               if (vfont->packedfile == NULL && vfont->id.lib == NULL && BKE_vfont_is_builtin(vfont) == FALSE)
+                       vfont->packedfile = newPackedFile(reports, vfont->name, bmain->name);
 
        for (sound = bmain->sound.first; sound; sound = sound->id.next)
                if (sound->packedfile == NULL && sound->id.lib == NULL)
index ed2684befb15b33dcb435e27fb0a19f3ab5589dc..6d95b07834007b8ab5e74682f70ec9eb7d88f895 100644 (file)
@@ -73,6 +73,7 @@
 #include "BLI_bpath.h"
 #include "BLI_utildefines.h"
 
+#include "BKE_font.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_report.h"
@@ -484,9 +485,9 @@ void BLI_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int
                        break;
                case ID_VF:
                {
-                       VFont *vf = (VFont *)id;
-                       if (vf->packedfile == NULL || (flag & BLI_BPATH_TRAVERSE_SKIP_PACKED) == 0) {
-                               if (strcmp(vf->name, FO_BUILTIN_NAME) != 0) {
+                       VFont *vfont = (VFont *)id;
+                       if (vfont->packedfile == NULL || (flag & BLI_BPATH_TRAVERSE_SKIP_PACKED) == 0) {
+                               if (BKE_vfont_is_builtin(vfont) == FALSE) {
                                        rewrite_path_fixed(((VFont *)id)->name, visit_cb, absbase, bpath_user_data);
                                }
                        }
index bb66b1f434755eaad69ff73550b80c33d5043a6e..eb9246db31e0ae38f05bd18d7b5152e97458934b 100644 (file)
@@ -1665,7 +1665,7 @@ static int font_open_exec(bContext *C, wmOperator *op)
 
 static int open_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 {
-       VFont *font = NULL;
+       VFont *vfont = NULL;
        char *path;
 
        PointerRNA idptr;
@@ -1678,10 +1678,10 @@ static int open_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 
        if (pprop->prop) {
                idptr = RNA_property_pointer_get((PointerRNA *)pprop, pprop->prop);
-               font = idptr.id.data;
+               vfont = idptr.id.data;
        }
 
-       path = (font && strcmp(font->name, FO_BUILTIN_NAME) != 0) ? font->name : U.fontdir;
+       path = (vfont && !BKE_vfont_is_builtin(vfont)) ? vfont->name : U.fontdir;
 
        if (RNA_struct_property_is_set(op->ptr, "filepath"))
                return font_open_exec(C, op);
index d8eb1b011bd9f45bd97f0946b6b5ed0cf2d19e9f..f7eff2cb22b4939d163e0a847aedb4f21f936a2b 100644 (file)
@@ -479,7 +479,7 @@ static void ui_draw_but_CHARTAB(uiBut *but)
        int charmax = G.charmax;
        
        /* FO_BUILTIN_NAME font in use. There are TTF FO_BUILTIN_NAME and non-TTF FO_BUILTIN_NAME fonts */
-       if (!strcmp(G.selfont->name, FO_BUILTIN_NAME)) {
+       if (BKE_vfont_is_builtin(G.selfont)) {
                if (G.ui_international == TRUE) {
                        charmax = 0xff;
                }
@@ -508,7 +508,7 @@ static void ui_draw_but_CHARTAB(uiBut *but)
        cs = G.charstart;
 
        /* Set the font, in case it is not FO_BUILTIN_NAME font */
-       if (G.selfont && strcmp(G.selfont->name, FO_BUILTIN_NAME)) {
+       if (G.selfont && BKE_vfont_is_builtin(G.selfont) == FALSE) {
                /* Is the font file packed, if so then use the packed file */
                if (G.selfont->packedfile) {
                        pf = G.selfont->packedfile;             
@@ -559,7 +559,7 @@ static void ui_draw_but_CHARTAB(uiBut *but)
 
                        /* Set the font to be either unicode or FO_BUILTIN_NAME */
                        wstr[0] = cs;
-                       if (strcmp(G.selfont->name, FO_BUILTIN_NAME)) {
+                       if (BKE_vfont_is_builtin(G.selfont) == FALSE) {
                                BLI_strncpy_wchar_as_utf8((char *)ustr, (wchar_t *)wstr, sizeof(ustr));
                        }
                        else {
@@ -572,8 +572,8 @@ static void ui_draw_but_CHARTAB(uiBut *but)
                                }
                        }
 
-                       if ((G.selfont && strcmp(G.selfont->name, FO_BUILTIN_NAME)) ||
-                           (G.selfont && !strcmp(G.selfont->name, FO_BUILTIN_NAME) && G.ui_international == TRUE))
+                       if ((G.selfont && (BKE_vfont_is_builtin(G.selfont) == FALSE)) ||
+                           (G.selfont && (BKE_vfont_is_builtin(G.selfont) == TRUE) && G.ui_international == TRUE))
                        {
                                float wid;
                                float llx, lly, llz, urx, ury, urz;
index 7f851c939d295dd20d2c7ac9045db2eb7b77e842..5151170defe05e7e9e481924bb59d906c000b03c 100644 (file)
@@ -109,12 +109,12 @@ static int rna_ID_name_editable(PointerRNA *ptr)
        ID *id = (ID *)ptr->data;
        
        if (GS(id->name) == ID_VF) {
-               VFont *vf = (VFont *)id;
-               if (strcmp(vf->name, FO_BUILTIN_NAME) == 0)
-                       return 0;
+               VFont *vfont = (VFont *)id;
+               if (BKE_vfont_is_builtin(vfont))
+                       return FALSE;
        }
        
-       return 1;
+       return TRUE;
 }
 
 short RNA_type_to_ID_code(StructRNA *type)
index b65db1c809caaa5bf29a28b2c9966e7bff8dafe2..ff9469550d91ced4cfe47d7c523dc7c85f14444e 100644 (file)
 /* matching fnction in rna_ID.c */
 static int rna_VectorFont_filepath_editable(PointerRNA *ptr)
 {
-       VFont *vf = ptr->id.data;
-       if (strcmp(vf->name, FO_BUILTIN_NAME) == 0) {
-               return 0;
+       VFont *vfont = ptr->id.data;
+       if (BKE_vfont_is_builtin(vfont)) {
+               return FALSE;
        }
-       return 1;
+       return TRUE;
 }
 
 static void rna_VectorFont_reload_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
index a55efc0b216f217837adb141f5199a22df1f4509..dcb6407b66861faa7bf8461cd29dfa230b479b42 100644 (file)
@@ -1950,15 +1950,15 @@ static void WM_OT_recover_auto_save(wmOperatorType *ot)
 
 /* *************** save file as **************** */
 
-static void untitled(char *name)
+static void untitled(char *filepath)
 {
-       if (G.save_over == 0 && strlen(name) < FILE_MAX - 16) {
-               char *c = BLI_last_slash(name);
+       if (G.save_over == 0 && strlen(filepath) < FILE_MAX - 16) {
+               char *c = BLI_last_slash(filepath);
                
                if (c)
                        strcpy(&c[1], "untitled.blend");
                else
-                       strcpy(name, "untitled.blend");
+                       strcpy(filepath, "untitled.blend");
        }
 }
 
index 308154d8ebcb01ea74fec239e5d5ae9b00a71e50..931eac7a974c97d1d0c15b2f16974ed6d7e47ff3 100644 (file)
@@ -117,25 +117,25 @@ void KX_FontObject::ProcessReplica()
        KX_GetActiveScene()->AddFont(this);
 }
 
-int GetFontId (VFont *font)
+int GetFontId (VFont *vfont)
 {
        PackedFile *packedfile=NULL;
        int fontid = -1;
 
-       if (font->packedfile) {
-               packedfile= font->packedfile;
-               fontid= BLF_load_mem(font->name, (unsigned char*)packedfile->data, packedfile->size);
+       if (vfont->packedfile) {
+               packedfile= vfont->packedfile;
+               fontid= BLF_load_mem(vfont->name, (unsigned char*)packedfile->data, packedfile->size);
                
                if (fontid == -1) {
-                       printf("ERROR: packed font \"%s\" could not be loaded.\n", font->name);
+                       printf("ERROR: packed font \"%s\" could not be loaded.\n", vfont->name);
                        fontid = BLF_load("default");
                }
                return fontid;
        }
        
-       /* once we have packed working we can load the FO_BUILTIN_NAME font     */
-       const char *filepath = font->name;
-       if (strcmp(FO_BUILTIN_NAME, filepath) == 0) {
+       /* once we have packed working we can load the builtin font     */
+       const char *filepath = vfont->name;
+       if (BKE_vfont_is_builtin(vfont)) {
                fontid = BLF_load("default");
                
                /* XXX the following code is supposed to work (after you add get_builtin_packedfile to BKE_font.h )
index 76d1a64a4c0b9e72690104fad21e2394cdd493a2..b769fc4b70351bc1af9c51e24053ad28cdf2063c 100644 (file)
@@ -962,10 +962,10 @@ void RAS_OpenGLRasterizer::IndexPrimitivesInternal(RAS_MeshSlot& ms, bool multi)
 void RAS_OpenGLRasterizer::SetProjectionMatrix(MT_CmMatrix4x4 &mat)
 {
        glMatrixMode(GL_PROJECTION);
-       double* matrix = &mat(0,0);
+       double* matrix = &mat(0, 0);
        glLoadMatrixd(matrix);
 
-       m_camortho= (mat(3, 3) != 0.0f);
+       m_camortho = (mat(3, 3) != 0.0);
 }
 
 void RAS_OpenGLRasterizer::SetProjectionMatrix(const MT_Matrix4x4 & mat)
@@ -977,7 +977,7 @@ void RAS_OpenGLRasterizer::SetProjectionMatrix(const MT_Matrix4x4 & mat)
        /* Internally, MT_Matrix4x4 uses doubles (MT_Scalar). */
        glLoadMatrixd(matrix);  
 
-       m_camortho= (mat[3][3] != 0.0f);
+       m_camortho= (mat[3][3] != 0.0);
 }
 
 MT_Matrix4x4 RAS_OpenGLRasterizer::GetFrustumMatrix(
@@ -1002,11 +1002,11 @@ MT_Matrix4x4 RAS_OpenGLRasterizer::GetFrustumMatrix(
                        // if Rasterizer.setFocalLength is not called we use the camera focallength
                        if (!m_setfocallength)
                                // if focallength is null we use a value known to be reasonable
-                               m_focallength = (focallength == 0.f) ? m_eyeseparation * 30.0
+                               m_focallength = (focallength == 0.f) ? m_eyeseparation * 30.0f
                                        : focallength;
 
                        near_div_focallength = frustnear / m_focallength;
-                       offset = 0.5 * m_eyeseparation * near_div_focallength;
+                       offset = 0.5f * m_eyeseparation * near_div_focallength;
                        switch(m_curreye)
                        {
                                case RAS_STEREO_LEFTEYE:
index 9fdd0cd393becb13d070224e3837b33b82df6cc4..c8763671dd1d169c15fa129e8d1e879e2871a271 100644 (file)
@@ -138,7 +138,7 @@ void ImageRender::Render()
                // compute distance of observer to mirror = D - observerPos . normal
                MT_Scalar observerDistance = mirrorPlaneDTerm - observerWorldPos.dot(mirrorWorldZ);
                // if distance < 0.01 => observer is on wrong side of mirror, don't render
-               if (observerDistance < 0.01f)
+               if (observerDistance < 0.01)
                        return;
                // set camera world position = observerPos + normal * 2 * distance
                MT_Point3 cameraWorldPos = observerWorldPos + (MT_Scalar(2.0)*observerDistance)*mirrorWorldZ;