-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobals.hpp
99 lines (94 loc) · 2.65 KB
/
globals.hpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <SDL_opengles2.h>
#include <SDL.h>
#include "v2d.h"
#include <emscripten.h>
#include <functional>
#include <iostream>
#include <filesystem>
#include <limits>
#include <fstream>
#include <iterator>
#include <vector>
#include <list>
#include <numeric>
#pragma once
// class Gene;
uint16_t screen_width, screen_height;
float zoomPhysics[3], scale;
v2d panPhysics[3], offset;
bool isMouseDown;
bool firefox;
GLuint gridProgram, tilesProgram, tiles2Program, fbo, textureID;
SDL_Window *window;
std::list<float> frameAvg;
bool randDensity(int number){
return (rand() % number) == number/2;
}
void getScreenSize(){
screen_width = (uint16_t)EM_ASM_INT({
var width = window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;
return width;
});
screen_height = (uint16_t)EM_ASM_INT({
var height = window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
return height;
});
// screen_width = screen_width > stg.init_width ? stg.init_width : screen_width;
// screen_height = screen_height > stg.init_height? stg.init_height : screen_height;
}
void getBrowser(){
firefox = (uint16_t)EM_ASM_INT({
// var browser = bowser.detect
var browser = bowser.getParser(window.navigator.userAgent);
var name = browser.getBrowser().name;
return name=="Firefox";
});
}
constexpr int64_t ipow(int64_t base, int exp, int64_t result = 1) {
return exp < 1 ? result : ipow(base*base, exp/2, (exp % 2) ? result*base : result);
}
constexpr int power = 8;
// constexpr int tilesX = ipow(2, power) * 2;
// constexpr int tilesY = ipow(2, power);
// int tilesX;// = screen_width * 2;
// int tilesY;// = screen_height * 2;
GLubyte *pixels;//[tilesX*tilesY*3] = {255};
struct Settings{
uint16_t screen_width, screen_height;
uint16_t map_width, map_height;
// const uint16_t tilesX, tilesY;
// uint16_t init_width, init_height;
float scale, drag;
bool trails;
float speed;
};
Settings stg = {
0, 0, // Screen Dimensions (init to zero, set later)
0, 0, // Map Dimensions
0, // Scale
1.3f, // Drag Factor
false,
1
};
struct Grid{
Grid(Grid _src, Settings _stg):
xDivs(_src.xDivs),
yDivs(_src.yDivs),
tWidth(_stg.map_width / _src.xDivs),
tHeight(_stg.map_height / _src.yDivs){
}
Grid(uint32_t _xDivs, uint32_t _yDivs, Settings _stg):
xDivs(_xDivs),
yDivs(_yDivs),
tWidth(_stg.map_width / xDivs),
tHeight(_stg.map_height / yDivs){
}
uint32_t xDivs;
uint32_t yDivs;
uint32_t tWidth;
uint32_t tHeight;
};