Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix command provider. This fixes several broken behaviours.
- Loading branch information
Showing
2 changed files
with
26 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,42 @@ | ||
#include "command_provider.h" | ||
|
||
#include "logging.h" | ||
|
||
CommandProvider::CommandProvider(std::string name, std::string description, std::function<bool(void)> begin_func, std::function<bool(void)> continue_func, std::function<bool(void)> end_func) | ||
: begin_func(std::move(begin_func)) | ||
, continue_func(std::move(continue_func)) | ||
, end_func(std::move(end_func)) | ||
{ | ||
cr = XPLMCreateCommand(name.c_str(), description.c_str()); | ||
|
||
if(bool(this->begin_func)) { | ||
XPLMRegisterCommandHandler(cr, CommandProvider::begin_handler, 1, static_cast<void *>(this)); | ||
} | ||
|
||
if(bool(this->continue_func)) { | ||
XPLMRegisterCommandHandler(cr, CommandProvider::continue_handler, 1, static_cast<void *>(this)); | ||
} | ||
|
||
if(bool(this->end_func)) { | ||
XPLMRegisterCommandHandler(cr, CommandProvider::end_handler, 1, static_cast<void *>(this)); | ||
} | ||
XPLMRegisterCommandHandler(cr, CommandProvider::handler, 0, static_cast<void *>(this)); | ||
} | ||
|
||
CommandProvider::~CommandProvider() { | ||
if(bool(begin_func)) { | ||
XPLMUnregisterCommandHandler(cr, CommandProvider::begin_handler, 1, static_cast<void *>(this)); | ||
} | ||
|
||
if(bool(continue_func)) { | ||
XPLMUnregisterCommandHandler(cr, CommandProvider::continue_handler, 1, static_cast<void *>(this)); | ||
} | ||
|
||
if(bool(end_func)) { | ||
XPLMUnregisterCommandHandler(cr, CommandProvider::end_handler, 1, static_cast<void *>(this)); | ||
} | ||
XPLMUnregisterCommandHandler(cr, CommandProvider::handler, 0, static_cast<void *>(this)); | ||
} | ||
|
||
|
||
int CommandProvider::begin_handler(XPLMCommandRef /* inCommand */, XPLMCommandPhase /* inPhase */, void * inRefcon) { | ||
CommandProvider * pthis = static_cast<CommandProvider *>(inRefcon); | ||
return pthis->begin_func() ? 1 : 0; | ||
} | ||
int CommandProvider::handler(XPLMCommandRef /* inCommand */, XPLMCommandPhase phase, void * inRefcon) { | ||
|
||
int CommandProvider::continue_handler(XPLMCommandRef /* inCommand */, XPLMCommandPhase /* inPhase */, void * inRefcon) { | ||
CommandProvider * pthis = static_cast<CommandProvider *>(inRefcon); | ||
return pthis->continue_func() ? 1 : 0; | ||
} | ||
switch(phase) { | ||
case xplm_CommandBegin: | ||
if(bool(pthis->begin_func)) { | ||
return pthis->begin_func() ? 1 : 0; | ||
} | ||
break; | ||
case xplm_CommandContinue: | ||
if(bool(pthis->continue_func)) { | ||
return pthis->continue_func() ? 1 : 0; | ||
} | ||
break; | ||
case xplm_CommandEnd: | ||
if(bool(pthis->end_func)) { | ||
return pthis->end_func() ? 1 : 0; | ||
} | ||
break; | ||
} | ||
|
||
int CommandProvider::end_handler(XPLMCommandRef /* inCommand */, XPLMCommandPhase /* inPhase */, void * inRefcon ) { | ||
CommandProvider * pthis = static_cast<CommandProvider *>(inRefcon); | ||
return pthis->end_func() ? 1 : 0; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters