-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.hh
44 lines (31 loc) · 1.32 KB
/
helpers.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef _GRAVITY_STREAMS_HH_
#define _GRAVITY_STREAMS_HH_
#include "renderer.hh"
#include <box2d/box2d.h>
#include <SDL2/SDL.h>
#include <iostream>
#include <map>
using namespace std;
#define WRITE(DATA, STREAM) (STREAM).write((const char*) &DATA, sizeof(DATA))
#define READ(DATA, STREAM) (STREAM).read((char*) &DATA, sizeof(DATA))
extern bool mute;
inline float frand() {
return rand() / (float) RAND_MAX;
}
extern void SaveVec2(const b2Vec2 &v, ostream &s);
extern void LoadVec2(b2Vec2 &v, istream &s);
extern void SaveString(const string &str, ostream &s);
extern void LoadString(string &str, istream &s);
extern void SaveMap(const map<string, string> &m, ostream &s);
extern void LoadMap(map<string, string> &m, istream &s);
extern void GetTextWidthP(string text, float hp, SDL_Window *window, float &wp);
extern string ReadFile(const string &filename);
/// Converts the window coordinate (x, y) to relative coordinates (xp,
/// yp), i.e. xp and yp in range [0.0, 1.0], for a widget with the
/// given width and height in the given window.
extern void GetRelativeCoords(int x, int y,
SDL_Window *window,
TextAnchor xanchor, TextAnchor yanchor,
float &xp, float &yp);
extern void PlaySound(const string &name);
#endif /* _GRAVITY_STREAMS_HH_ */