BGE Button types panel, can edit existing buttons but not add new ones yet.
authorCampbell Barton <ideasman42@gmail.com>
Mon, 20 Jul 2009 16:21:55 +0000 (16:21 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 20 Jul 2009 16:21:55 +0000 (16:21 +0000)
World Physics panel too though Im not sure if we'll eventually move this into another struct.

release/ui/buttons_world.py
release/ui/space_logic.py
source/blender/blenkernel/BKE_property.h
source/blender/blenkernel/intern/property.c
source/blender/editors/space_logic/logic_buttons.c
source/blender/editors/space_logic/logic_window.c
source/blender/makesdna/DNA_property_types.h
source/blender/makesrna/intern/rna_object.c
source/blender/makesrna/intern/rna_property.c
source/blender/makesrna/intern/rna_world.c

index 6e233f86765214890627f0293f453d4216e711a9..0f16c847c5d9179e68ad45e60db51c8720e4a65c 100644 (file)
@@ -175,6 +175,26 @@ class WORLD_PT_ambient_occlusion(WorldButtonsPanel):
                col.row().itemR(ao, "blend_mode", expand=True)
                col.row().itemR(ao, "color", expand=True)
                col.itemR(ao, "energy")
+               
+class WORLD_PT_game(WorldButtonsPanel):
+       __label__ = "Game Settings"
+
+       def draw(self, context):
+               layout = self.layout
+               world = context.world
+               
+               flow = layout.column_flow()
+               flow.itemR(world, "physics_engine")
+               flow.itemR(world, "physics_gravity")
+               
+               flow.itemR(world, "game_fps")
+               flow.itemR(world, "game_logic_step_max")
+               flow.itemR(world, "game_physics_substep")
+               flow.itemR(world, "game_physics_step_max")
+               
+               flow.itemR(world, "game_use_occlusion_culling", text="Enable Occlusion Culling")
+               flow.itemR(world, "game_occlusion_culling_resolution")
+               
 
 bpy.types.register(WORLD_PT_context_world)     
 bpy.types.register(WORLD_PT_preview)
@@ -183,3 +203,4 @@ bpy.types.register(WORLD_PT_ambient_occlusion)
 bpy.types.register(WORLD_PT_mist)
 bpy.types.register(WORLD_PT_stars)
 bpy.types.register(WORLD_PT_color_correction)
+bpy.types.register(WORLD_PT_game)
index f862f6e26675232a3b5f6490d8d434ffedba82f7..bb7f22c7c5e669c69bdfb95023fb4a57b621a61b 100644 (file)
@@ -75,7 +75,7 @@ class LOGIC_PT_collision_bounds(bpy.types.Panel):
        def draw(self, context):
                layout = self.layout
                
-               ob = context.scene.objects[0]
+               ob = context.active_object
                game = ob.game
                
                flow = layout.column_flow()
@@ -84,5 +84,28 @@ class LOGIC_PT_collision_bounds(bpy.types.Panel):
                flow.itemR(game, "collision_compound")
                flow.itemR(game, "collision_margin")
 
+class LOGIC_PT_properties(bpy.types.Panel):
+       __space_type__ = "LOGIC_EDITOR"
+       __region_type__ = "UI"
+       __label__ = "Properties"
+
+       def poll(self, context):
+               ob = context.active_object
+               return ob and ob.game
+       
+       def draw(self, context):
+               layout = self.layout
+               
+               ob = context.active_object
+               game = ob.game
+               
+               for prop in game.properties:
+                       flow = layout.row()
+                       flow.itemR(prop, "name", text="")
+                       flow.itemR(prop, "type", text="")
+                       flow.itemR(prop, "value", text="") # we dont care about the type. rna will display correctly
+                       flow.itemR(prop, "debug")
+
 bpy.types.register(LOGIC_PT_physics)
 bpy.types.register(LOGIC_PT_collision_bounds)
+bpy.types.register(LOGIC_PT_properties)
index 6af1deda72705d49359b719b76eab0912b24348c..78a9ecddaaca8807824f167d517094dfccff1d8c 100644 (file)
@@ -41,6 +41,7 @@ struct bProperty *copy_property(struct bProperty *prop);
 void copy_properties(struct ListBase *lbn, struct ListBase *lbo);
 void init_property(struct bProperty *prop);
 struct bProperty *new_property(int type);
+void unique_property(struct bProperty *first, struct  bProperty *prop, int force);
 struct bProperty *get_ob_property(struct Object *ob, char *name);
 void set_ob_property(struct Object *ob, struct bProperty *propc);
 int compare_property(struct bProperty *prop, char *str);
index 261b58454bde3c9a752e07010db1a0d987bf9a51..5cae527957bc12e351751872130444a395c64e23 100644 (file)
@@ -33,6 +33,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -99,25 +100,18 @@ void init_property(bProperty *prop)
        if(prop->poin && prop->poin != &prop->data) MEM_freeN(prop->poin);
        prop->poin= 0;
        
-       prop->otype= prop->type;
        prop->data= 0;
        
        switch(prop->type) {
        case GPROP_BOOL:
-               prop->poin= &prop->data;
-               break;
        case GPROP_INT:
-               prop->poin= &prop->data;
-               break;
        case GPROP_FLOAT:
+       case GPROP_TIME:
                prop->poin= &prop->data;
                break;
        case GPROP_STRING:
                prop->poin= MEM_callocN(MAX_PROPSTRING, "property string");
                break;
-       case GPROP_TIME:
-               prop->poin= &prop->data;
-               break;
        }
 }
 
@@ -136,6 +130,60 @@ bProperty *new_property(int type)
        return prop;
 }
 
+/* used by unique_property() only */
+static bProperty *get_property__internal(bProperty *first, bProperty *self, const char *name)
+{
+       bProperty *p;
+       for(p= first; p; p= p->next) {
+               if (p!=self && (strcmp(p->name, name)==0))
+                       return p;
+       }
+       return NULL;
+}
+void unique_property(bProperty *first, bProperty *prop, int force)
+{
+       bProperty *p;
+
+       /* set the first if its not set */
+       if(first==NULL) {
+               first= prop;
+               while(first->prev) {
+                       first= first->prev;
+               }
+       }
+
+       if(force) {
+               /* change other names to make them unique */
+               while((p = get_property__internal(first, prop, prop->name))) {
+                       unique_property(first, p, 0);
+               }
+       }else {
+               /* change our own name until its unique */
+               if(get_property__internal(first, prop, prop->name)) {
+                       /* there is a collision */
+                       char new_name[sizeof(prop->name)];
+                       char base_name[sizeof(prop->name)];
+                       char num[sizeof(prop->name)];
+                       int i= 0;
+
+                       /* strip numbers */
+                       strcpy(base_name, prop->name);
+                       for(i= strlen(base_name)-1; (i>=0 && isdigit(base_name[i])); i--) {
+                               base_name[i]= '\0';
+                       }
+                       i= 0;
+
+                       do { /* ensure we have enough chars for the new number in the name */
+                               sprintf(num, "%d", i++);
+                               BLI_strncpy(new_name, base_name, sizeof(prop->name) - strlen(num));
+                               strcat(new_name, num);
+                       } while(get_property__internal(first, prop, new_name));
+
+                       strcpy(prop->name, new_name);
+               }
+       }
+}
+
 bProperty *get_ob_property(Object *ob, char *name)
 {
        bProperty *prop;
index b082d5d6ae25dcb39838cef6b0663395b314d21f..db6922f304ce87994ab6093c52d8dab48d3cb960 100644 (file)
@@ -66,6 +66,7 @@
 
 #include "logic_intern.h"
 
+#if 0
 static void do_logic_panel_events(bContext *C, void *arg, int event)
 {
        
@@ -96,12 +97,12 @@ static void logic_panel_view_properties(const bContext *C, Panel *pa)
        uiBlockSetHandleFunc(block, do_logic_panel_events, NULL);
        
 }      
-
+#endif
 
 void logic_buttons_register(ARegionType *art)
 {
        PanelType *pt;
-
+#if 0
        pt= MEM_callocN(sizeof(PanelType), "spacetype logic panel properties");
        strcpy(pt->idname, "LOGIC_PT_properties");
        strcpy(pt->label, "Logic Properties");
@@ -113,6 +114,7 @@ void logic_buttons_register(ARegionType *art)
        strcpy(pt->label, "View Properties");
        pt->draw= logic_panel_view_properties;
        BLI_addtail(&art->paneltypes, pt);
+#endif
 
 }
 
index 55e21561c34a45e43248bd7e9acd970a29af5ff1..ab4574d59408985b90ec663920c0c02e14c9bf10 100644 (file)
@@ -393,7 +393,7 @@ void do_logic_buts(bContext *C, void *arg, int event)
                BLI_addtail(&ob->prop, prop);
                ED_undo_push(C, "Add property");
                break;
-       
+#if 0 // XXX Now done in python
        case B_CHANGE_PROP:
                prop= ob->prop.first;
                while(prop) {
@@ -403,7 +403,7 @@ void do_logic_buts(bContext *C, void *arg, int event)
                        prop= prop->next;
                }
                break;
-       
+#endif
        case B_ADD_SENS:
                for(ob=G.main->object.first; ob; ob=ob->id.next) {
                        if(ob->scaflag & OB_ADDSENS) {
index 7cc365a9ebcac10a984e44138a96b2add0fee786..af79b2e0a22a9f1a5bc84e03c5cf151d00415530 100644 (file)
 typedef struct bProperty {
        struct bProperty *next, *prev;
        char name[32];
-       short type, otype;              /* otype is for buttons, when a property type changes */
+       short type, flag;
        int data;                               /* data should be 4 bytes to store int,float stuff */
-       int old;                                /* old is for simul */
-       short flag, pad;
-       void *poin;
-       void *oldpoin;                  /* oldpoin is for simul */
+       void *poin;                             /* references data unless its a string which is malloc'd */
        
 } bProperty;
 
index 05a60f3c0f9575a90d6e6332f01e3cfc0a045e6c..32a97d2c86a785a45a97f9c5892b1b3552db7fc9 100644 (file)
@@ -705,7 +705,7 @@ static void rna_def_object_game_settings(BlenderRNA *brna)
 
        prop= RNA_def_property(srna, "properties", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_collection_sdna(prop, NULL, "prop", NULL);
-       RNA_def_property_struct_type(prop, "GameProperty");
+       RNA_def_property_struct_type(prop, "GameProperty"); /* rna_property.c */
        RNA_def_property_ui_text(prop, "Properties", "Game engine properties.");
 
        prop= RNA_def_property(srna, "show_sensors", PROP_BOOLEAN, PROP_NONE);
index a840552b86f62932e300a4d6f6dc02c0c2f2e2eb..a1fcbac274e782aaed6d34a5152e2666cccd014c 100644 (file)
@@ -33,6 +33,8 @@
 
 #ifdef RNA_RUNTIME
 
+#include "BKE_property.h"
+
 static StructRNA* rna_GameProperty_refine(struct PointerRNA *ptr)
 {
        bProperty *property= (bProperty*)ptr->data;
@@ -67,6 +69,24 @@ static void rna_GameFloatProperty_value_set(PointerRNA *ptr, float value)
        *(float*)(&prop->data)= value;
 }
 
+static void rna_GameProperty_type_set(PointerRNA *ptr, int value)
+{
+       bProperty *prop= (bProperty*)(ptr->data);
+
+       if(prop->type != value) {
+               prop->type= value;
+               init_property(prop);
+       }
+}
+
+static void rna_GameProperty_name_set(PointerRNA *ptr, const char *value)
+{
+       bProperty *prop= (bProperty*)(ptr->data);
+       BLI_strncpy(prop->name, value, sizeof(prop->name));
+       unique_property(NULL, prop, 1);
+}
+
+
 #else
 
 void RNA_def_gameproperty(BlenderRNA *brna)
@@ -89,14 +109,14 @@ void RNA_def_gameproperty(BlenderRNA *brna)
        RNA_def_struct_refine_func(srna, "rna_GameProperty_refine");
 
        prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
-       RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* must be unique */
        RNA_def_property_ui_text(prop, "Name", "Available as as GameObject attributes in the game engines python api");
        RNA_def_struct_name_property(srna, prop);
+       RNA_def_property_string_funcs(prop, NULL, NULL, "rna_GameProperty_name_set");
 
        prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
-       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_enum_items(prop, gameproperty_type_items);
        RNA_def_property_ui_text(prop, "Type", "");
+       RNA_def_property_enum_funcs(prop, NULL, "rna_GameProperty_type_set", NULL);
 
        prop= RNA_def_property(srna, "debug", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", PROP_DEBUG);
index c93d18d401718f248220866925b0ceff26082e94..773037176deb0193a7a33564a48807da432cf44e 100644 (file)
@@ -422,6 +422,38 @@ void RNA_def_world(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Real Sky", "Render background with a real horizon, relative to the camera angle.");
        RNA_def_property_update(prop, NC_WORLD, NULL);
 
+       /* game settings */
+       /* should go in a fake substruct however not sure if they move about */
+       prop= RNA_def_property(srna, "game_fps", PROP_INT, PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "ticrate");
+       RNA_def_property_range(prop, 1, 120);
+       RNA_def_property_ui_text(prop, "Frames Per Second", "The nominal number of game frames per second. Physics fixed timestep = 1/fps, independently of actual frame rate.");
+
+       prop= RNA_def_property(srna, "game_logic_step_max", PROP_INT, PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "maxlogicstep");
+       RNA_def_property_range(prop, 1, 5);
+       RNA_def_property_ui_text(prop, "Max Logic Steps", "The maxmimum number of logic frame per game frame if graphics slows down the game, higher value allows better synchronization with physics.");
+
+       prop= RNA_def_property(srna, "game_physics_substep", PROP_INT, PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "physubstep");
+       RNA_def_property_range(prop, 1, 5);
+       RNA_def_property_ui_text(prop, "Physics Sub Steps", "The maximum number of physics step per game frame if graphics slows down the game, higher value allows physics to keep up with realtime.");
+
+       prop= RNA_def_property(srna, "game_physics_step_max", PROP_INT, PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "maxphystep");
+       RNA_def_property_range(prop, 1, 5);
+       RNA_def_property_ui_text(prop, "Max Physics Steps", "The number of simulation substep per physic timestep, higher value give better physics precision.");
+
+       prop= RNA_def_property(srna, "game_use_occlusion_culling", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "mode", WO_DBVT_CULLING);
+       RNA_def_property_ui_text(prop, "Enabled", "Use optimized Bullet DBVT tree for view frustrum and occlusion culling");
+
+       prop= RNA_def_property(srna, "game_occlusion_culling_resolution", PROP_INT, PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "occlusionRes");
+       RNA_def_property_range(prop, 128, 1024);
+       RNA_def_property_ui_text(prop, "Occlusion Resolution", "The size of the occlusion buffer in pixel, use higher value for better precsion (slower).");
+
+
        /* physics */
        prop= RNA_def_property(srna, "physics_engine", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "physicsEngine");