Jump to content

controls class


photo

Recommended Posts

1. ControlsPtr controls = Game::get()->getPlayer()->getControls();

2. ControlsPtr controls = Controls::create(Controls::CONTROLS_DUMMY);

3. ControlsDummyPtr controls = ControlsDummy::create();

 

 

What is the difference between these three?

is it ok using one of the three when processing input?

 

and the controlsApp class is not a child class of the Controls class.

"ControlsPtr controls = Controls::create(Controls::CONTROLS_APP)"  is  same " ControlsApp::get()" ?

 

 

Link to comment

Hi Dongju!
 

ControlsPtr controls = Game::get()->getPlayer()->getControls();

The Player::getControls() function returns a pointer to the Controls instance currently relevant to the player. It is mostly suitable for keyboard input handling, just the way it is described in the Getting and Managing User Inputs article.

 

ControlsPtr controls = Controls::create(Controls::CONTROLS_DUMMY);

ControlsDummyPtr controls = ControlsDummy::create();

The functions above are the same — they create a new instance of the ControlsDummy class. The only difference between them is the type of the returned pointer, as you can see, it is ControlsPtr for the first one and ControlsDummyPtr for the second one.

The ControlsDummy class is intended for custom input handling (for example, AI-controlled input), you can find description of this use case in the Controls article.

 

Quote

"ControlsPtr controls = Controls::create(Controls::CONTROLS_APP)"  is  same " ControlsApp::get()" ?

These functions do the same due to the nature of the ControlsApp object, which is a singleton within the engine. So these pieces of code both return a pointer to the ControlsApp instance, that is why it is not and should not be a child of the Controls class.

Thank you!

  • Like 1
Link to comment

if  "ControlsPtr controls = Controls::create(Controls::CONTROLS_APP)" is same pointer with "ControlsApp::get()", in this case  ControlsPtr is same ControlsApp*?

or

 should I use it this way? ->   ControlsApp* control = Controls::create(Controls::CONTROLS_APP); 

 

 

 

 

 

 

Link to comment

I've checked this issue.

Indeed, there is inconsistency in the Controls::create(int type) function in a case the parameter is given as Controls::CONTROLS_APP. It shouldn't be used this way (however, other constants are ok) as it may lead to unexpected behaviour or just will not work.

So, the recommended way to get a pointer to the ControlsApp instance is as the following:

ControlsApp *capp = ControlsApp::get();

The mistake has been added to known issues and will be examined in upcoming releases.

Thank you for noticing!

Link to comment
×
×
  • Create New...