gvars icon indicating copy to clipboard operation
gvars copied to clipboard

GUICommandCallBack Usage?

Open ghost opened this issue 11 years ago • 4 comments

Hey,

I am curious about the usage and mechanism of GUICommandCallBack.

If I define that method in a class. Will Gvars call it autonomously? How does that work? Really need some guide about Gvars.

Best regards, Tyler

ghost avatar Apr 08 '14 17:04 ghost

The sCommand is issued by CVD::GLWindow. For example KeyPress

ghost avatar Apr 08 '14 17:04 ghost

I find the GUI instance in src/inst.cc.

But still confused about how does GUICommandCallBack work?

Can I define that function in any class I created? How will Gvars call this function?

ghost avatar Apr 08 '14 18:04 ghost

I read the source code of Gvars3 and some other examples.

Now I thought I understand.

I need the first call that in my class

GUI.RegisterCommand("KeyPress", GUICommandCallBack, this)

In the GLWindow when a key is pressed, I need to call:

GUI.ParseLine("try KeyPress")

My question is why can I call GUI.RegisterCommand in a class which runs in another thread?

ghost avatar Apr 08 '14 18:04 ghost

Seems you have the rest figures out.

On 8 April 2014 19:34, Tyler Zhu [email protected] wrote:

I read the source code of Gvars3 and some other examples.

Now I thought I understand.

I need the first call that in my class

GUI.RegisterCommand("KeyPress", GUICommandCallBack, this)

In the GLWindow when a key is pressed, I need to call:

GUI.ParseLine("try KeyPress")

My question is why can I call GUI.RegisterCommand in a class which runs in another thread?

Well, the GVars stuff is all global to all threads, so a command registered in one thread will be usable in another. However, there isn't much by the way of locking in GVars, so you can wind up with obscure thread related bugs without care. If RegisterCommand is called before the other threads are spawned, then all will be OK.

If other threads are spawned but never call RegisterCommand or parseLine, the neverything should also be fine.

-Ed

Reply to this email directly or view it on GitHubhttps://github.com/edrosten/gvars/issues/1#issuecomment-39884791 .

edrosten avatar Apr 09 '14 09:04 edrosten