edrosten / gvars

Lightweight and simple configuration library for C++ programs.
Other
29 stars 22 forks source link

GUICommandCallBack Usage? #1

Open ghost opened 10 years ago

ghost commented 10 years ago

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 commented 10 years ago

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

ghost commented 10 years ago

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 commented 10 years ago

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?

edrosten commented 10 years ago

Seems you have the rest figures out.

On 8 April 2014 19:34, Tyler Zhu notifications@github.com 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 .