Changeset 329


Ignore:
Timestamp:
Feb 1, 2011, 8:23:49 PM (10 years ago)
Author:
sam
Message:

Minor updates to the mouse tracking architecture.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/input.cpp

    r295 r329  
    3232    InputData()
    3333      : mouse(-1, -1),
    34         buttons(0, 0, 0)
     34        buttons(0, 0, 0),
     35        nentities(0)
    3536    { }
    3637
     38private:
    3739    int2 mouse;
    3840    int3 buttons;
     41
     42    static int const MAX_ENTITIES = 100;
     43    WorldEntity *entities[MAX_ENTITIES];
     44    int nentities;
    3945}
    4046inputdata;
     
    6369}
    6470
    65 void Input::SetMousePos(int2 coord)
    66 {
    67     data->mouse = coord;
    68 }
    69 
    7071int2 Input::GetMousePos()
    7172{
    7273    return data->mouse;
    73 }
    74 
    75 void Input::SetMouseButton(int index)
    76 {
    77     data->buttons[index] = 1;
    78 }
    79 
    80 void Input::UnsetMouseButton(int index)
    81 {
    82     data->buttons[index] = 0;
    8374}
    8475
     
    8879}
    8980
     81void Input::TrackMouse(WorldEntity *e)
     82{
     83    if (data->nentities >= InputData::MAX_ENTITIES)
     84        return;
     85    data->entities[data->nentities] = e;
     86    data->nentities++;
     87}
     88
     89void Input::UntrackMouse(WorldEntity *e)
     90{
     91    for (int n = 0; n < data->nentities; n++)
     92    {
     93        if (data->entities[n] != e)
     94            continue;
     95
     96        data->entities[n] = data->entities[data->nentities - 1];
     97        data->nentities--;
     98        n--;
     99    }
     100}
     101
     102void Input::SetMousePos(int2 coord)
     103{
     104    data->mouse = coord;
     105
     106    /* FIXME: parse all subscribed entities and update them */
     107}
     108
     109void Input::SetMouseButton(int index)
     110{
     111    data->buttons[index] = 1;
     112
     113    /* FIXME: parse all subscribed entities and update them */
     114}
     115
     116void Input::UnsetMouseButton(int index)
     117{
     118    data->buttons[index] = 0;
     119
     120    /* FIXME: parse all subscribed entities and update them */
     121}
     122
  • trunk/src/input.h

    r326 r329  
    3030
    3131    /* Entities can subscribe to events */
    32     static void ListenMouse(WorldEntity *e);
    33     static void UnlistenMouse(WorldEntity *e);
     32    static void TrackMouse(WorldEntity *e);
     33    static void UntrackMouse(WorldEntity *e);
    3434
    3535    /* These methods are called by the underlying input listeners */
  • trunk/src/worldentity.h

    r312 r329  
    2727    float3 bbox[2];
    2828
     29    int2 mousepos;
     30    int3 mousebuttons;
     31
    2932protected:
    3033    WorldEntity();
Note: See TracChangeset for help on using the changeset viewer.