src/proto2/Dimension.hh
author terom
Mon, 10 Nov 2008 16:49:09 +0000
branchno-netsession
changeset 31 d0d7489d4e8b
parent 25 af75a1894a32
child 42 eb1a93a38cde
permissions -rw-r--r--
add initial code written so far
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
     1
#ifndef DIMENSION_HH
5a209a8585c9 proto p2
terom
parents:
diff changeset
     2
#define DIMENSION_HH
5a209a8585c9 proto p2
terom
parents:
diff changeset
     3
23
8d802b573cf0 fixed more network code, there's actually a high probability of it working now
terom
parents: 6
diff changeset
     4
#include <iostream>
6
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
     5
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
     6
class Dimension {
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
     7
    public:
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
     8
        uint32_t w;
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
     9
        uint32_t h;
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    10
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    11
        Dimension (uint32_t w, uint32_t h) : w(w), h(h) { }
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    12
};
5a209a8585c9 proto p2
terom
parents:
diff changeset
    13
6
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
    14
class PositionDelta {
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    15
    public:
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    16
        int32_t dx;
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    17
        int32_t dy;
6
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
    18
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    19
        PositionDelta (int32_t dx, int32_t dy) : dx(dx), dy(dy) { }
6
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
    20
};
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
    21
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    22
class Coordinate {
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    23
    public:
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    24
        uint32_t x;
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    25
        uint32_t y;
6
faa4e777cc6e fiddle with cmake, fix some compile errors
terom
parents: 5
diff changeset
    26
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    27
        Coordinate (uint32_t x, uint32_t y) : x(x), y(y) { }
4
e28b28b8817c Drawer lis?tty. Pari metodia gamestateen ja dimensioniin.
ekku
parents: 3
diff changeset
    28
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    29
        Coordinate &operator+= (const PositionDelta &d) {
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    30
            this->x += d.dx;
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    31
            this->y += d.dy;
4
e28b28b8817c Drawer lis?tty. Pari metodia gamestateen ja dimensioniin.
ekku
parents: 3
diff changeset
    32
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    33
            return *this;
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    34
        }
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    35
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    36
        Coordinate operator+ (const PositionDelta &d) {
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    37
            return Coordinate(x + d.dx, y + d.dy);
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    38
        }
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    39
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    40
        // Scale the coordinate so that it matches the pixel resolution
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    41
        uint32_t scaledX() { return x; }
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    42
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    43
        uint32_t scaledY() { return y; }
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    44
};
5a209a8585c9 proto p2
terom
parents:
diff changeset
    45
23
8d802b573cf0 fixed more network code, there's actually a high probability of it working now
terom
parents: 6
diff changeset
    46
std::ostream& operator<< (std::ostream &s, const Coordinate &c);
8d802b573cf0 fixed more network code, there's actually a high probability of it working now
terom
parents: 6
diff changeset
    47
std::ostream& operator<< (std::ostream &s, const PositionDelta &c);
8d802b573cf0 fixed more network code, there's actually a high probability of it working now
terom
parents: 6
diff changeset
    48
3
5a209a8585c9 proto p2
terom
parents:
diff changeset
    49
#endif