BGE: Removing the touch sensor and converting all touch sensors to collision sensors.
authorMitchell Stokes <mogurijin@gmail.com>
Wed, 4 Sep 2013 22:14:14 +0000 (22:14 +0000)
committerMitchell Stokes <mogurijin@gmail.com>
Wed, 4 Sep 2013 22:14:14 +0000 (22:14 +0000)
source/blender/blenkernel/intern/sca.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/space_logic/logic_window.c
source/blender/makesdna/DNA_sensor_types.h
source/blender/makesrna/RNA_access.h
source/blender/makesrna/intern/rna_sensor.c
source/gameengine/Converter/KX_ConvertSensors.cpp

index 091b5f337c6d59d515cefe415eee04d9529e8929..7c374fd5d7825cf59ee402b72b6f9d1b273eeb26 100644 (file)
@@ -112,9 +112,6 @@ void init_sensor(bSensor *sens)
        case SENS_ALWAYS:
                sens->pulse = 0;
                break;
-       case SENS_TOUCH:
-               sens->data= MEM_callocN(sizeof(bTouchSensor), "touchsens");
-               break;
        case SENS_NEAR:
                ns=sens->data= MEM_callocN(sizeof(bNearSensor), "nearsens");
                ns->dist= 1.0;
index 2d61ef09a02bbcb35cf870d0b930b6ffe30e3abc..0cd473fd74d31bae01286b6da6f8b787acca0ea8 100644 (file)
@@ -4367,12 +4367,8 @@ static void lib_link_object(FileData *fd, Main *main)
                        for (sens = ob->sensors.first; sens; sens = sens->next) {
                                for (a = 0; a < sens->totlinks; a++)
                                        sens->links[a] = newglobadr(fd, sens->links[a]);
-                               
-                               if (sens->type == SENS_TOUCH) {
-                                       bTouchSensor *ts = sens->data;
-                                       ts->ma = newlibadr(fd, ob->id.lib, ts->ma);
-                               }
-                               else if (sens->type == SENS_MESSAGE) {
+
+                               if (sens->type == SENS_MESSAGE) {
                                        bMessageSensor *ms = sens->data;
                                        ms->fromObject =
                                                newlibadr(fd, ob->id.lib, ms->fromObject);
@@ -9616,6 +9612,32 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                }
                        }
                }
+
+               for (ob = main->object.first; ob; ob = ob->id.next) {
+                       bSensor *sens;
+                       bTouchSensor *ts;
+                       bCollisionSensor *cs;
+                       Material *ma;
+
+                       for (sens = ob->sensors.first; sens; sens = sens->next) {
+                               if (sens->type == SENS_TOUCH) {
+                                       ts = sens->data;
+                                       cs = MEM_callocN(sizeof(bCollisionSensor), "touch -> collision sensor do_version");
+
+                                       if (ts->ma) {
+                                               ma = blo_do_versions_newlibadr(fd, ob->id.lib, ts->ma);
+                                               BLI_strncpy(cs->materialName, ma->id.name+2, sizeof(cs->materialName));
+                                       }
+
+                                       cs->mode = SENS_COLLISION_MATERIAL;
+
+                                       MEM_freeN(ts);
+
+                                       sens->data = cs;
+                                       sens->type = sens->otype = SENS_COLLISION;
+                               }
+                       }
+               }
        }
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
@@ -10517,11 +10539,7 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob)
                expand_doit(fd, mainvar, psys->part);
        
        for (sens = ob->sensors.first; sens; sens = sens->next) {
-               if (sens->type == SENS_TOUCH) {
-                       bTouchSensor *ts = sens->data;
-                       expand_doit(fd, mainvar, ts->ma);
-               }
-               else if (sens->type == SENS_MESSAGE) {
+               if (sens->type == SENS_MESSAGE) {
                        bMessageSensor *ms = sens->data;
                        expand_doit(fd, mainvar, ms->fromObject);
                }
index 83982781d8c9bfbd8ff5b206accd72c3abbd6691..90405583544ddee9d35b05488c19fa62c308df7a 100644 (file)
@@ -1108,9 +1108,6 @@ static void write_sensors(WriteData *wd, ListBase *lb)
                case SENS_MOUSE:
                        writestruct(wd, DATA, "bMouseSensor", 1, sens->data);
                        break;
-               case SENS_TOUCH:
-                       writestruct(wd, DATA, "bTouchSensor", 1, sens->data);
-                       break;
                case SENS_KEYBOARD:
                        writestruct(wd, DATA, "bKeyboardSensor", 1, sens->data);
                        break;
index aed5699a9d7940e3be308dde471f93efa22f2b29..2c89d6f644881a6cf148e9de8cc96dc2c9b6991e 100644 (file)
@@ -427,8 +427,6 @@ static const char *sensor_name(int type)
        switch (type) {
        case SENS_ALWAYS:
                return "Always";
-       case SENS_TOUCH:
-               return "Touch";
        case SENS_NEAR:
                return "Near";
        case SENS_KEYBOARD:
@@ -1233,11 +1231,6 @@ static void draw_sensor_ray(uiLayout *layout, PointerRNA *ptr, bContext *C)
        uiItemR(row, ptr, "use_x_ray", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
 }
 
-static void draw_sensor_touch(uiLayout *layout, PointerRNA *ptr)
-{
-       uiItemR(layout, ptr, "material", 0, NULL, ICON_NONE);
-}
-
 static void draw_brick_sensor(uiLayout *layout, PointerRNA *ptr, bContext *C)
 {
        uiLayout *box;
@@ -1292,9 +1285,6 @@ static void draw_brick_sensor(uiLayout *layout, PointerRNA *ptr, bContext *C)
                case SENS_RAY:
                        draw_sensor_ray(box, ptr, C);
                        break;
-               case SENS_TOUCH:
-                       draw_sensor_touch(box, ptr);
-                       break;
        }
 }
 
index d8cf80d047b149117e5be9de4394ea7ea9280889..1b946c829fdcf49ec6437acaa6514a0fff46bfc9 100644 (file)
@@ -60,6 +60,7 @@ typedef struct bMouseSensor {
        short pad2;
 } bMouseSensor;
 
+/* DEPRECATED */
 typedef struct bTouchSensor {
        char name[64];  /* MAX_NAME */
        struct Material *ma;
@@ -235,7 +236,7 @@ typedef struct bJoystickSensor {
 
 /* sensor->type */
 #define SENS_ALWAYS            0
-#define SENS_TOUCH             1
+#define SENS_TOUCH             1  /* DEPRECATED */
 #define SENS_NEAR              2
 #define SENS_KEYBOARD  3
 #define SENS_PROPERTY  4
index 9ba30ec03502add7c269ff84bd9580edb02da503..b6152c4a4bf822ae1e2df9451dcd5795157887ef 100644 (file)
@@ -622,7 +622,6 @@ extern StructRNA RNA_ThemeWidgetStateColors;
 extern StructRNA RNA_TimelineMarker;
 extern StructRNA RNA_Timer;
 extern StructRNA RNA_ToolSettings;
-extern StructRNA RNA_TouchSensor;
 extern StructRNA RNA_TrackToConstraint;
 extern StructRNA RNA_TransformConstraint;
 extern StructRNA RNA_TransformSequence;
index 278dc074c509f44e4b75e7c763edf05d882eaf1a..5a3ec8f1f1d38d46acdb4aa7054bb67a7d2d0696 100644 (file)
@@ -58,7 +58,6 @@ EnumPropertyItem sensor_type_items[] = {
        {SENS_RADAR, "RADAR", 0, "Radar", ""},
        {SENS_RANDOM, "RANDOM", 0, "Random", ""},
        {SENS_RAY, "RAY", 0, "Ray", ""},
-       {SENS_TOUCH, "TOUCH", 0, "Touch", ""},
        {0, NULL, 0, NULL, NULL}
 };
 
@@ -74,8 +73,6 @@ static StructRNA *rna_Sensor_refine(struct PointerRNA *ptr)
        switch (sensor->type) {
                case SENS_ALWAYS:
                        return &RNA_AlwaysSensor;
-               case SENS_TOUCH:
-                       return &RNA_TouchSensor;
                case SENS_NEAR:
                        return &RNA_NearSensor;
                case SENS_KEYBOARD:
@@ -267,15 +264,6 @@ static void rna_Sensor_Armature_update(Main *UNUSED(bmain), Scene *UNUSED(scene)
        posechannel[0] = 0;
        constraint[0] = 0;
 }
-
-/* note: the following set functions exists only to avoid id refcounting */
-static void rna_Sensor_touch_material_set(PointerRNA *ptr, PointerRNA value)
-{
-       bSensor *sens = (bSensor *)ptr->data;
-       bTouchSensor *ts = (bTouchSensor *) sens->data;
-
-       ts->ma = value.data;
-}
 #else
 
 static void rna_def_sensor(BlenderRNA *brna)
@@ -427,25 +415,6 @@ static void rna_def_mouse_sensor(BlenderRNA *brna)
        RNA_def_property_update(prop, NC_LOGIC, NULL);
 }
 
-static void rna_def_touch_sensor(BlenderRNA *brna)
-{
-       StructRNA *srna;
-       PropertyRNA *prop;
-
-       srna = RNA_def_struct(brna, "TouchSensor", "Sensor");
-       RNA_def_struct_ui_text(srna, "Touch Sensor", "Sensor to detect objects colliding with the current object");
-       RNA_def_struct_sdna_from(srna, "bTouchSensor", "data");
-
-       prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
-       RNA_def_property_struct_type(prop, "Material");
-       RNA_def_property_pointer_sdna(prop, NULL, "ma");
-       RNA_def_property_flag(prop, PROP_EDITABLE);
-       RNA_def_property_ui_text(prop, "Material", "Only look for objects with this material (blank = all objects)");
-       /* note: custom set function is ONLY to avoid rna setting a user for this. */
-       RNA_def_property_pointer_funcs(prop, NULL, "rna_Sensor_touch_material_set", NULL, NULL);
-       RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
 static void rna_def_keyboard_sensor(BlenderRNA *brna)
 {
        StructRNA *srna;
@@ -917,7 +886,6 @@ void RNA_def_sensor(BlenderRNA *brna)
        rna_def_always_sensor(brna);
        rna_def_near_sensor(brna);
        rna_def_mouse_sensor(brna);
-       rna_def_touch_sensor(brna);
        rna_def_keyboard_sensor(brna);
        rna_def_property_sensor(brna);
        rna_def_armature_sensor(brna);
index 1aae2738311ab153b26baea15dd9a2d05adb9fd1..3bb12c12cd11f34d2b5349092a3ce6bd7a60fa6b 100644 (file)
@@ -192,30 +192,6 @@ void BL_ConvertSensors(struct Object* blenderobject,
                                        
                                }
                                
-                               break;
-                       }
-               case SENS_TOUCH:
-                       {
-                               SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::TOUCH_EVENTMGR);
-                               if (eventmgr)
-                               {
-                                       STR_String touchpropertyname;
-                                       bTouchSensor* blendertouchsensor = (bTouchSensor*)sens->data;
-                                       
-                                       if (blendertouchsensor->ma)
-                                       {
-                                               touchpropertyname = (char*) (blendertouchsensor->ma->id.name+2);
-                                       }
-                                       bool bFindMaterial = true;
-                                       if (gameobj->GetPhysicsController())
-                                       {
-                                               gamesensor = new KX_TouchSensor(eventmgr,
-                                                       gameobj,
-                                                       bFindMaterial,
-                                                       false,
-                                                       touchpropertyname);
-                                       }
-                               }
                                break;
                        }
                case SENS_MESSAGE: