Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

control system in c++


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 giugio   Members   -  Reputation: 182

Like
0Likes
Like

Posted 20 October 2012 - 06:29 AM

hello.
I'm implementing a drawing system for inserting graph items on a opengl viewport.
For now i would insert a line and a point entity for semplicity , and more than anything else i'm search at a solid system.
A point or a line are CEntity and each CEntity has his controller(like MVC) that has all the functions that can modify the graphics properties of the CEntity owner.
This controller can be different from entity to entity
For ex:
class CControllerLine
{
public:
CControllerLine();
Move(int x, int y){...Line impl};
SetColor(int color){...line impl};
Scale(float toX, float toY){...Line impl}
Rotate(float angle){...Line impl}
  
};
class CControllerPoint
{
public:
CControllerLine();
Move(int x, int y){Point...impl};
SetColor(int color){Point...impl};
Scale(float toX, float toY){Point...impl}
//Rotate(float angle){WARNING In the point the Rotate function isn't implemented I disable the item of the context menu}
  
};
I wish manage all with the std::function of the c++11
I wish create a current view::func generic in the view (compatible after the std::bind of parameters with all the possible modifiers :x,y,color,scale,position ecc...)
The generic std::function "view::func" has a void return type and is a "placeholder"(like a polymorphic pointer) where will insert depending of the user choosing on the ui(with buttons and other widgets) any different but compatible std::function extracted from a current widget's property (that is inherited from the base widget with a std::function property "widgetfunction" that contains the correct generic std::function typical of the widget)
When i do an action pressing the "Action" button :
1)extract the widget's typical function from the "widgetfunction" property of the pressed button (and place it in the current std::function view::func)
2)bind the view::function on the controller class of the entity pointer (can be a point or a line entity that i extract with a picking system)with all the needed parameters like x,y, ecc...
3)launch the function with view::func()
I wish do only a thing :
is possible know if any controller(that can be CControllerLine or CControllerPoint) has or not has a the specific function extracted from the widget function property?
For example if the widget property is Rotate(float angle)
i do:
if the CurrentEnttity's controller HAS( Rotate(float angle) ) calls CurrentEntity::Rotate(angle)
else
disable pressed widget or do nothing
1)if the current entity is a line i can call the rotate function on the selected current entity.
2)if the current entity is a point i can't call the rotate function on the selected current entity and i disable the widget dinamically.

Sponsor:

#2 nox_pp   Members   -  Reputation: 427

Like
0Likes
Like

Posted 20 October 2012 - 07:54 AM

If I correctly understand what you are saying, there are a few ways to do this. For one, you should probably use polymorphism instead of trying to use introspection.

You can implement either a Controller interface or base class that your controllers can derive from. For a base class, just provide blank default implementations:
class Controller{
	 //...
	 virtual void Scale(float toX, float toY){}
	 virtual void Rotate(float angle){}
}

Then, you do not check for the presence of a particular function on the controller, just bind the function...it just won't do anything.

Otherwise, you can do as you inititially wanted using typeid or dynamic_cast:

if(typeid(CControllerLine) == typeid(current_entity->controller)){
	 current_entity->controller->Rotate(angle);
}





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS