瀏覽代碼

Minor updates to the mouse tracking architecture.

legacy
Sam Hocevar sam 14 年之前
父節點
當前提交
9c08082263
共有 3 個檔案被更改,包括 47 行新增11 行删除
  1. +42
    -9
      src/input.cpp
  2. +2
    -2
      src/input.h
  3. +3
    -0
      src/worldentity.h

+ 42
- 9
src/input.cpp 查看文件

@@ -31,11 +31,17 @@ static class InputData
public:
InputData()
: mouse(-1, -1),
buttons(0, 0, 0)
buttons(0, 0, 0),
nentities(0)
{ }

private:
int2 mouse;
int3 buttons;

static int const MAX_ENTITIES = 100;
WorldEntity *entities[MAX_ENTITIES];
int nentities;
}
inputdata;

@@ -62,28 +68,55 @@ float2 Input::GetAxis(int axis)
return f;
}

void Input::SetMousePos(int2 coord)
int2 Input::GetMousePos()
{
data->mouse = coord;
return data->mouse;
}

int2 Input::GetMousePos()
int3 Input::GetMouseButtons()
{
return data->mouse;
return data->buttons;
}

void Input::TrackMouse(WorldEntity *e)
{
if (data->nentities >= InputData::MAX_ENTITIES)
return;
data->entities[data->nentities] = e;
data->nentities++;
}

void Input::UntrackMouse(WorldEntity *e)
{
for (int n = 0; n < data->nentities; n++)
{
if (data->entities[n] != e)
continue;

data->entities[n] = data->entities[data->nentities - 1];
data->nentities--;
n--;
}
}

void Input::SetMousePos(int2 coord)
{
data->mouse = coord;

/* FIXME: parse all subscribed entities and update them */
}

void Input::SetMouseButton(int index)
{
data->buttons[index] = 1;

/* FIXME: parse all subscribed entities and update them */
}

void Input::UnsetMouseButton(int index)
{
data->buttons[index] = 0;
}

int3 Input::GetMouseButtons()
{
return data->buttons;
/* FIXME: parse all subscribed entities and update them */
}


+ 2
- 2
src/input.h 查看文件

@@ -29,8 +29,8 @@ public:
static int3 GetMouseButtons();

/* Entities can subscribe to events */
static void ListenMouse(WorldEntity *e);
static void UnlistenMouse(WorldEntity *e);
static void TrackMouse(WorldEntity *e);
static void UntrackMouse(WorldEntity *e);

/* These methods are called by the underlying input listeners */
static void SetMousePos(int2 coord);


+ 3
- 0
src/worldentity.h 查看文件

@@ -26,6 +26,9 @@ public:
float3 velocity;
float3 bbox[2];

int2 mousepos;
int3 mousebuttons;

protected:
WorldEntity();
virtual ~WorldEntity();


Loading…
取消
儲存