OpenGTA/util/map_helper.h

62 lines
1.6 KiB
C
Raw Normal View History

2015-12-03 00:37:37 +00:00
#ifndef MAP_HELPER_H
#define MAP_HELPER_H
#include <list>
2015-12-03 00:38:22 +00:00
#include <map>
2015-12-03 00:37:37 +00:00
#include <SDL_video.h>
2015-12-03 00:38:22 +00:00
#include <cassert> // yasli/random.h needs it
#include "math3d.h"
2015-12-03 00:37:37 +00:00
#include "yasli/random.h"
namespace Util {
typedef std::pair<SDL_Rect, SDL_Rect> TupleOfRects;
typedef std::pair<uint8_t, uint8_t> TupleOfUint8;
typedef std::list< TupleOfRects > ListOfTupleOfRects;
class SpriteCreationArea {
public:
//ListOfTupleOfRects validTuple;
TupleOfRects validRects;
void setRects(const SDL_Rect & allowed, const SDL_Rect & denied);
TupleOfUint8 getValidCoord();
Random rnd;
2015-12-03 00:38:22 +00:00
bool isOnScreen(const Vector3D & p);
bool isOffScreen(const Vector3D & p);
private:
SDL_Rect onScreen;
2015-12-03 00:37:37 +00:00
};
2015-12-03 00:38:22 +00:00
/** lesser than comparison of two std::pair<int, int>.
*/
template <typename T>
struct lt_pair {
bool operator() (const T & a, const T & b) {
if (a.first < b.first)
return true;
if (a.first > b.first)
return false;
return (a.second < b.second);
}
};
typedef std::pair<int, int> Pair2Int;
typedef lt_pair<std::pair<int, int> > cmp_Pair2Int;
typedef std::map<Pair2Int, int, cmp_Pair2Int> MapOfPair2Int;
/** count of Pair2Int(a,b) in the map.
* @return 0 if no entry at that \e position
* @return count otherwise
*/
int item_count(MapOfPair2Int & m, int a, int b);
/** insert (may overwrite) count 1 at Pair2Int(a, b).
*/
void register_item1(MapOfPair2Int & m, int a, int b);
/** register and count Pair2Int(a, b).
*/
void register_item(MapOfPair2Int & m, int a, int b);
2015-12-03 00:37:37 +00:00
}
#endif