[Bf-committers] Temporary "global" storage

Campbell Barton ideasman42 at gmail.com
Fri Jun 22 11:50:00 CEST 2012


to avoid extens in a few areas of blender we just use a function which
returns a static var...


uiState *state = UI_state_get();
if (state->last_tip < sometime) { ... }


... or if this us just 2-3 items you could use functions which return
static vars...

double time = UI_state_get_last_tiptime();

... then do ...

static double last_tiptime = -1.0;
double UI_state_get_last_tiptime(void)
{
    return last_tiptime;
}

Then use functions to these too, or set them locally in the file where
they are defined & written to.

On Fri, Jun 22, 2012 at 11:32 AM, Jorge Rodriguez
<jorge at lunarworkshop.com> wrote:
> I agree, of course. What's bad is "extern float" like you said, and what's
> also bad is putting it in RNA, so I ended up putting it the G struct. If
> someone tells me that's not the right place for it then he better come up
> with a better one or I'll just have to throw my hands up.
>
> On Fri, Jun 22, 2012 at 1:35 AM, Jason Wilkins <jason.a.wilkins at gmail.com>wrote:
>
>> Think about it for a couple of seconds though.  Something like "last
>> button pressed" and "tooltip close time" really are globals.
>>
>> In what parallel dimension did another button get pressed last?
>>
>> In what other timeline did a tooltip close?
>>
>> I get that somebody once told you that global variables are bad but
>> they are not.  What is bad is exposing the internal workings of
>> something to another module that does not need to know.  This happens
>> at all levels of code.
>>
>> So, don't just make an "extern float last_tooltip_close_time", but
>> write a sensible interface for it like the other thousands of "global"
>> functions in Blender.
>>
>> Even if someday we add dimensional sliding and time travel libraries
>> to Blender I don't think it will be a big deal to modify the interface
>> you make :-)
>>
>>
>> On Thu, Jun 21, 2012 at 6:50 PM, Jorge Rodriguez
>> <jorge at lunarworkshop.com> wrote:
>> > Uncle_Entity suggested in IRC that I should try G or G.main. G has a lot
>> of
>> > assorted, almost random stuff in it. It's not the best place for it since
>> > it's still a glorified global, but it's not serialized to disk and it
>> > wouldn't have other averse consequences like exposing to Python scripts.
>> I
>> > think I'm going to try with this if others don't object.
>> >
>> > --
>> > Jorge "Vino" Rodriguez
>> > jorge at lunarworkshop.com
>> > [ Tweet <http://twitter.com/vinobs> | Like <
>> http://www.facebook.com/bsvino>|
>> > Plus <http://www.google.com/profiles/bs.vino> ]
>> > 919.757.3066
>> > _______________________________________________
>> > Bf-committers mailing list
>> > Bf-committers at blender.org
>> > http://lists.blender.org/mailman/listinfo/bf-committers
>> _______________________________________________
>> Bf-committers mailing list
>> Bf-committers at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-committers
>>
>
>
>
> --
> Jorge "Vino" Rodriguez
> jorge at lunarworkshop.com
> [ Tweet <http://twitter.com/vinobs> | Like <http://www.facebook.com/bsvino>|
> Plus <http://www.google.com/profiles/bs.vino> ]
> 919.757.3066
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers



-- 
- Campbell


More information about the Bf-committers mailing list