, . , . , , .
, . :
keycallback(GLFWwindow *window, int key, int scancode, int action, int mods);
-, , . void,
void GLFWCALL keycallback(
GLFWwindow *window,
int key,
int scancode,
int action,
int mods);
GLFWCALL - , . , , . , ,
class FooState
{
void GLFWCALL keycallback(
GLFWwindow *window,
int key,
int scancode,
int action,
int mods);
};
? , ,
void GLFWCALL FooState::keycallback(
GLFWwindow *window,
int key,
int scancode,
int action,
int mods);
FooState::. . . ( ), ( ++) . this. , C- ( ), GLFW C,
void GLFWCALL keycallback(
FooState *this,
GLFWwindow *window,
int key,
int scancode,
int action,
int mods);
, GLFW. - , . ? , , .
. static , , , ( C ).
,
class StateBase
{
virtual void keycallback(
GLFWwindow *window,
int key,
int scancode,
int action,
int mods) = 0;
static StateBase *event_handling_instance;
virtual void setEventHandling() { event_handling_instance = this; }
static void GLFWCALL keycallback_dispatch(
GLFWwindow *window,
int key,
int scancode,
int action,
int mods)
{
if(event_handling_instance)
event_handling_instance->keycallback(window,key,scancode,action,mods);
}
};
#include "statebase.h"
StateBase * StateBase::event_handling_instance;
- : , StateBase, event_handling_instance , .
, FooState StateBase ( GLFWCALL)
class FooState : BaseState
{
virtual void keycallback(
GLFWwindow *window,
int key,
int scancode,
int action,
int mods);
};
void FooState::keycallback(
GLFWwindow *window,
int key,
int scancode,
int action,
int mods)
{
}
GLFW,
glfwSetKeyCallback(window, StateBase::keycallback_dispatcher);
, void StateBase::setEventHandling().
FooState state;
state.setEventHandling();
:
++ , . - , , , ++, .
: , , . structs - ( ), . , , , .