Changeset 1046


Ignore:
Timestamp:
Nov 1, 2011, 6:55:19 PM (11 years ago)
Author:
sam
Message:

core: split vector operations into linear and non-linear so that we can
reuse the linear operations in quaternions. Also mark some constructors
explicit to better spot coding errors.

Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/deushax/debugsprite.cpp

    r1035 r1046  
    4141    Ticker::Ref(game);
    4242    data->tileset = Tiler::Register("deushax/art/test/character-dress.png",
    43                                     32, 0, sqrtf(2));
     43                                    ivec2(32), ivec2(0), sqrtf(2));
    4444    data->pos = vec3(320, 206, 0);
    4545}
  • trunk/monsterz/board.cpp

    r866 r1046  
    9494    {
    9595    case GAME_HUNT:
    96         data->size = 48;
     96        data->size = ivec2(48);
    9797        break;
    9898    }
     
    102102    data->npieces = minnpieces;
    103103    data->maxnpieces = maxnpieces;
    104     data->screen = Tiler::Register(PNG_BACKGROUND, ivec2(640, 480), 0, 1.0f);
    105     data->board = Tiler::Register(PNG_BOARD, 384, 0, 1.0f);
    106     data->tiles = Tiler::Register(PNG_TILES, data->size, 0, 1.0f);
    107     data->icons = Tiler::Register(PNG_ICONS, 24, 0, 1.0f);
     104    data->screen = Tiler::Register(PNG_BACKGROUND, ivec2(640, 480), ivec2(0), 1.0f);
     105    data->board = Tiler::Register(PNG_BOARD, ivec2(384), ivec2(0), 1.0f);
     106    data->tiles = Tiler::Register(PNG_TILES, data->size, ivec2(0), 1.0f);
     107    data->icons = Tiler::Register(PNG_ICONS, ivec2(24), ivec2(0), 1.0f);
    108108    data->click = Sampler::Register(WAV_CLICK);
    109109    data->whip = Sampler::Register(WAV_WHIP);
  • trunk/monsterz/interface.cpp

    r1035 r1046  
    5757    data->title = NULL;
    5858    data->board = NULL;
    59     data->tiles = Tiler::Register(PNG_TILES, 48, 0, 1.0f);
     59    data->tiles = Tiler::Register(PNG_TILES, ivec2(48), ivec2(0), 1.0f);
    6060    data->state = InterfaceData::INIT;
    6161
  • trunk/monsterz/piece.cpp

    r958 r1046  
    9393    {
    9494    case PIECE_HUNT:
    95         data->size = 48;
    96         data->tileset = Tiler::Register(PNG_TILES, data->size, 0, 1.0f);
     95        data->size = ivec2(48);
     96        data->tileset = Tiler::Register(PNG_TILES, data->size, ivec2(0), 1.0f);
    9797        data->pieceid = 80 + 20 * pieceid;
    9898        break;
     
    100100
    101101    data->pos = data->cell * data->size;
    102     data->off = 0;
     102    data->off = ivec2(0);
    103103}
    104104
     
    281281        if (t >= 1.0f)
    282282            t = 1.0f;
    283         data->pos = data->pos_src + (t * trip + 0.5f);
     283        data->pos = data->pos_src + t * vec2(trip) + vec2(0.5f);
    284284
    285285        float off_time = data->off_src.len() / data->speed;
  • trunk/monsterz/thumbs.cpp

    r866 r1046  
    4747  : data(new ThumbsData())
    4848{
    49     data->icons = Tiler::Register(PNG_ICONS, 24, 0, 1.0f);
     49    data->icons = Tiler::Register(PNG_ICONS, ivec2(24), ivec2(0), 1.0f);
    5050
    5151    data->npieces = 0;
  • trunk/monsterz/title.cpp

    r1035 r1046  
    139139    srand(rand() ^ time(NULL));
    140140
    141     data->logo = Tiler::Register(PNG_TITLE_LOGO, ivec2(380, 181), 0, 1.0f);
     141    data->logo = Tiler::Register(PNG_TITLE_LOGO, ivec2(380, 181), ivec2(0), 1.0f);
    142142    data->logo_sprite = new Sprite(data->logo, 0);
    143143    data->logo_sprite->position = vec3(640 / 2 - 380 / 2, 250, 10);
    144144    Ticker::Ref(data->logo_sprite);
    145145
    146     data->ground = Tiler::Register(PNG_TITLE_GROUND, ivec2(384, 80), 0, 1.0f);
     146    data->ground = Tiler::Register(PNG_TITLE_GROUND, ivec2(384, 80), ivec2(0), 1.0f);
    147147    data->ground_pos = ivec2((bbox[1] - bbox[0]).xy() / ivec2(2, 4))
    148148                     - ivec2(192, 80);
    149149
    150     data->rocks = Tiler::Register(PNG_TITLE_ROCKS, ivec2(640, 155), 0, 1.0f);
     150    data->rocks = Tiler::Register(PNG_TITLE_ROCKS, ivec2(640, 155), ivec2(0), 1.0f);
    151151    data->rocks_pos = ivec2((bbox[1] - bbox[0]).xy() / ivec2(2, 2))
    152152                    - ivec2(320, 240);
    153153
    154     data->title = Tiler::Register(PNG_TITLE, 384, 0, 1.0f);
    155     data->stars = Tiler::Register(PNG_STARS, ivec2(384, 144), 0, 1.0f);
    156     data->clouds = Tiler::Register(PNG_CLOUDS, ivec2(160, 32), 0, 1.0f);
    157     data->eagle.tiles = Tiler::Register(PNG_EAGLE, 16, 0, 1.0f);
     154    data->title = Tiler::Register(PNG_TITLE, ivec2(384), ivec2(0), 1.0f);
     155    data->stars = Tiler::Register(PNG_STARS, ivec2(384, 144), ivec2(0), 1.0f);
     156    data->clouds = Tiler::Register(PNG_CLOUDS, ivec2(160, 32), ivec2(0), 1.0f);
     157    data->eagle.tiles = Tiler::Register(PNG_EAGLE, ivec2(16), ivec2(0), 1.0f);
    158158    for (int n = 0; n < 6; n++)
    159159        data->anim[n] = Tiler::Register(PNG_TITLEANIM[n],
    160                                         animsize[n], 0, 1.0f);
     160                                        animsize[n], ivec2(0), 1.0f);
    161161    for (int n = 0; n < 7; n++)
    162162        data->event[n] = Tiler::Register(PNG_TITLEEVENT[n],
    163                                          eventsize[n], 0, 1.0f);
     163                                         eventsize[n], ivec2(0), 1.0f);
    164164    data->state = TitleData::IDLE;
    165165    data->period = TitleData::DAY;
     
    174174        data->cloudpos[n] = vec2(RandF((bbox[1] - bbox[0]).x),
    175175                                 RandF(80) + (bbox[1] - bbox[0]).y - 300);
    176         data->cloudspeed[n] = RandF(-0.01f, 0.01f);
     176        data->cloudspeed[n] = vec2(RandF(-0.01f, 0.01f));
    177177    }
    178178
     
    362362    TileSet *tiler = NULL;
    363363    int tileid = 0;
    364     ivec2 pos = 0;
     364    ivec2 pos = ivec2(0);
    365365
    366366    switch (data->state)
  • trunk/src/debug/record.cpp

    r863 r1046  
    5454
    5555    data->path = strdup(path);
    56     data->size = 0;
     56    data->size = ivec2(0);
    5757    data->fps = (int)(fps + 0.5f);
    5858#if defined USE_PIPI
  • trunk/src/font.cpp

    r866 r1046  
    4747    sprintf(data->name, "<font> %s", path);
    4848
    49     data->tileset = Tiler::Register(path, 0, 16, 1.0f);
     49    data->tileset = Tiler::Register(path, ivec2(0), ivec2(16), 1.0f);
    5050    data->size = data->tileset->GetSize(0);
    5151
  • trunk/src/image/codec/dummy-image.cpp

    r962 r1046  
    4545bool DummyImageData::Open(char const *path)
    4646{
    47     size = 256;
     47    size = ivec2(256);
    4848    format = Image::FORMAT_RGBA;
    4949    pixels = (uint8_t *)malloc(256 * 256 * 4 * sizeof(*pixels));
  • trunk/src/input.cpp

    r1037 r1046  
    139139                data->entities[n]->pressed = data->buttons;
    140140            else
    141                 data->entities[n]->clicked = 0;
     141                data->entities[n]->clicked = ivec3(0);
    142142        }
    143143        else
     
    145145            data->entities[n]->mousepos = ivec2(-1);
    146146            /* FIXME */
    147             data->entities[n]->released = 0;
    148             data->entities[n]->pressed = 0;
    149             data->entities[n]->clicked = 0;
     147            data->entities[n]->released = ivec3(0);
     148            data->entities[n]->pressed = ivec3(0);
     149            data->entities[n]->clicked = ivec3(0);
    150150        }
    151151    }
  • trunk/src/map.cpp

    r810 r1046  
    136136        {
    137137            /* This is a tileset image file. Associate it with firstgid. */
    138             data->tilesets[data->ntilers] = Tiler::Register(str, 32, 0,
    139                                                           sqrtf(2));
     138            data->tilesets[data->ntilers] = Tiler::Register(str, ivec2(32),
     139                                                            ivec2(0), sqrtf(2));
    140140            data->ntilers++;
    141141            //Log::Debug("new tiler %s\n", str);
  • trunk/src/matrix.cpp

    r1044 r1046  
    7474    float norm = v.len();
    7575    if (!norm)
    76         return vec4(0);
     76        return vec4(0.0f);
    7777    return v / norm;
    7878}
     
    127127}
    128128
     129template<> void ivec2::printf() const
     130{
     131    Log::Debug("[ %i %i ]\n", x, y);
     132}
     133
    129134template<> void vec3::printf() const
    130135{
     
    132137}
    133138
     139template<> void ivec3::printf() const
     140{
     141    Log::Debug("[ %i %i %i ]\n", x, y, z);
     142}
     143
    134144template<> void vec4::printf() const
    135145{
    136146    Log::Debug("[ %6.6f %6.6f %6.6f %6.6f ]\n", x, y, z, w);
     147}
     148
     149template<> void ivec4::printf() const
     150{
     151    Log::Debug("[ %i %i %i %i ]\n", x, y, z, w);
    137152}
    138153
  • trunk/src/matrix.h

    r1044 r1046  
    6464    }
    6565
    66 #define OPERATORS(elems) \
     66#define LINEAR_OPS(elems) \
    6767    inline T& operator[](int n) { return *(&x + n); } \
    6868    inline T const& operator[](int n) const { return *(&x + n); } \
     
    7070    VECTOR_OP(elems, -) \
    7171    VECTOR_OP(elems, +) \
     72    \
     73    BOOL_OP(elems, ==, ==, true) \
     74    BOOL_OP(elems, !=, ==, false) \
     75    \
     76    SCALAR_OP(elems, *) \
     77    SCALAR_OP(elems, /) \
     78    \
     79    inline Vec##elems<T> operator -() const \
     80    { \
     81        Vec##elems<T> ret; \
     82        for (int n = 0; n < elems; n++) \
     83            ret[n] = -(*this)[n]; \
     84        return ret; \
     85    } \
     86    \
     87    inline T sqlen() const \
     88    { \
     89        T acc = 0; \
     90        for (int n = 0; n < elems; n++) \
     91            acc += (*this)[n] * (*this)[n]; \
     92        return acc; \
     93    } \
     94    \
     95    inline float len() const \
     96    { \
     97        using namespace std; \
     98        return sqrtf((float)sqlen()); \
     99    } \
     100    \
     101    template<typename U> \
     102    friend Vec##elems<U> normalize(Vec##elems<U>); \
     103    \
     104    void printf() const;
     105
     106#define OTHER_OPS(elems) \
    72107    VECTOR_OP(elems, *) \
    73108    VECTOR_OP(elems, /) \
    74109    \
    75     BOOL_OP(elems, ==, ==, true) \
    76     BOOL_OP(elems, !=, ==, false) \
    77110    BOOL_OP(elems, <=, <=, true) \
    78111    BOOL_OP(elems, >=, >=, true) \
     
    80113    BOOL_OP(elems, >, >, true) \
    81114    \
    82     SCALAR_OP(elems, -) \
    83     SCALAR_OP(elems, +) \
    84     SCALAR_OP(elems, *) \
    85     SCALAR_OP(elems, /) \
    86     \
    87115    template<typename U> \
    88116    inline operator Vec##elems<U>() const \
     
    94122    } \
    95123    \
    96     inline Vec##elems<T> operator -() const \
    97     { \
    98         Vec##elems<T> ret; \
    99         for (int n = 0; n < elems; n++) \
    100             ret[n] = -(*this)[n]; \
    101         return ret; \
    102     } \
    103     \
    104     inline T sqlen() const \
    105     { \
    106         T acc = 0; \
    107         for (int n = 0; n < elems; n++) \
    108             acc += (*this)[n] * (*this)[n]; \
    109         return acc; \
    110     } \
    111     \
    112     inline float len() const \
    113     { \
    114         using namespace std; \
    115         return sqrtf((float)sqlen()); \
    116     } \
    117     \
    118124    template<typename U> \
    119     friend U dot(Vec##elems<U>, Vec##elems<U>); \
    120     template<typename U> \
    121     friend Vec##elems<U> normalize(Vec##elems<U>); \
    122     \
    123     void printf() const;
     125    friend U dot(Vec##elems<U>, Vec##elems<U>);
    124126
    125127#define SWIZZLE2(e1, e2) \
    126128    inline Vec2<T> e1##e2() const \
    127129    { \
    128         return Vec2<T>(e1, e2); \
     130        return Vec2<T>(this->e1, this->e2); \
    129131    }
    130132
     
    132134    inline Vec3<T> e1##e2##e3() const \
    133135    { \
    134         return Vec3<T>(e1, e2, e3); \
     136        return Vec3<T>(this->e1, this->e2, this->e3); \
    135137    }
    136138
     
    138140    inline Vec4<T> e1##e2##e3##e4() const \
    139141    { \
    140         return Vec4<T>(e1, e2, e3, e4); \
     142        return Vec4<T>(this->e1, this->e2, this->e3, this->e4); \
    141143    }
    142144
     
    195197{
    196198    inline Vec2() { }
    197     inline Vec2(T val) { x = y = val; }
     199    explicit inline Vec2(T val) { x = y = val; }
    198200    inline Vec2(T _x, T _y) { x = _x; y = _y; }
    199201
    200     OPERATORS(2)
     202    LINEAR_OPS(2)
     203    OTHER_OPS(2)
    201204
    202205    SWIZZLE22(x); SWIZZLE22(y);
     
    231234{
    232235    inline Vec3() { }
    233     inline Vec3(T val) { x = y = z = val; }
     236    explicit inline Vec3(T val) { x = y = z = val; }
    234237    inline Vec3(T _x, T _y, T _z) { x = _x; y = _y; z = _z; }
    235238    inline Vec3(Vec2<T> _xy, T _z) { x = _xy.x; y = _xy.y; z = _z; }
    236239    inline Vec3(T _x, Vec2<T> _yz) { x = _x; y = _yz.x; z = _yz.y; }
    237240
    238     OPERATORS(3)
     241    LINEAR_OPS(3)
     242    OTHER_OPS(3)
    239243
    240244    SWIZZLE23(x); SWIZZLE23(y); SWIZZLE23(z);
     
    273277{
    274278    inline Vec4() { }
    275     inline Vec4(T val) { x = y = z = w = val; }
    276     inline Vec4(T _x, T _y, T _z, T _w) { x = _x; y = _y; z = _z; w = _w; }
    277     inline Vec4(Vec2<T> _xy, T _z, T _w) { x = _xy.x; y = _xy.y; z = _z; w = _w; }
    278     inline Vec4(T _x, Vec2<T> _yz, T _w) { x = _x; y = _yz.x; z = _yz.y; w = _w; }
    279     inline Vec4(T _x, T _y, Vec2<T> _zw) { x = _x; y = _y; z = _zw.x; w = _zw.y; }
    280     inline Vec4(Vec2<T> _xy, Vec2<T> _zw) { x = _xy.x; y = _xy.y; z = _zw.x; w = _zw.y; }
    281     inline Vec4(Vec3<T> _xyz, T _w) { x = _xyz.x; y = _xyz.y; z = _xyz.z; w = _w; }
    282     inline Vec4(T _x, Vec3<T> _yzw) { x = _x; y = _yzw.x; z = _yzw.y; w = _yzw.z; }
    283 
    284     OPERATORS(4)
     279    explicit inline Vec4(T val) : x(val), y(val), z(val), w(val) { }
     280    inline Vec4(T _x, T _y, T _z, T _w) : x(_x), y(_y), z(_z), w(_w) { }
     281    inline Vec4(Vec2<T> _xy, T _z, T _w) : x(_xy.x), y(_xy.y), z(_z), w(_w) { }
     282    inline Vec4(T _x, Vec2<T> _yz, T _w) : x(_x), y(_yz.x), z(_yz.y), w(_w) { }
     283    inline Vec4(T _x, T _y, Vec2<T> _zw) : x(_x), y(_y), z(_zw.x), w(_zw.y) { }
     284    inline Vec4(Vec2<T> _xy, Vec2<T> _zw) : x(_xy.x), y(_xy.y), z(_zw.x), w(_zw.y) { }
     285    inline Vec4(Vec3<T> _xyz, T _w) : x(_xyz.x), y(_xyz.y), z(_xyz.z), w(_w) { }
     286    inline Vec4(T _x, Vec3<T> _yzw) : x(_x), y(_yzw.x), z(_yzw.y), w(_yzw.z) { }
     287
     288    LINEAR_OPS(4)
     289    OTHER_OPS(4)
    285290
    286291    SWIZZLE24(x); SWIZZLE24(y); SWIZZLE24(z); SWIZZLE24(w);
     
    342347{
    343348    inline Mat4() { }
    344     inline Mat4(T val)
     349    explicit inline Mat4(T val)
    345350    {
    346351        for (int j = 0; j < 4; j++)
  • trunk/src/text.cpp

    r866 r1046  
    8888    {
    8989        Font *font = Forge::GetFont(data->font);
    90         vec3 delta = 0;
     90        vec3 delta(0.0f);
    9191        if (data->align == ALIGN_RIGHT)
    9292            delta.x -= data->length * font->GetSize().x;
  • trunk/src/tileset.cpp

    r968 r1046  
    7373    {
    7474        if (size.x <= 0 || size.y <= 0)
    75             size = 32;
     75            size = ivec2(32, 32);
    7676        data->count.i = data->isize.x > size.i ? data->isize.x / size.i : 1;
    7777        data->count.j = data->isize.y > size.j ? data->isize.y / size.j : 1;
  • trunk/src/worldentity.cpp

    r735 r1046  
    2626WorldEntity::WorldEntity()
    2727{
    28     position = 0;
    29     rotation = 0;
    30     velocity = 0;
    31     bbox[0] = bbox[1] = 0;
     28    position = vec3(0);
     29    rotation = vec3(0);
     30    velocity = vec3(0);
     31    bbox[0] = bbox[1] = vec3(0);
    3232
    33     mousepos = 0;
    34     mousebuttons = 0;
    35     pressed = 0;
    36     clicked = 0;
    37     released = 0;
     33    mousepos = ivec2(0);
     34    mousebuttons = ivec3(0);
     35    pressed = ivec3(0);
     36    clicked = ivec3(0);
     37    released = ivec3(0);
    3838}
    3939
Note: See TracChangeset for help on using the changeset viewer.