-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathworld.h
124 lines (98 loc) · 2.89 KB
/
world.h
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef WORLD_H
#define WORLD_H
#include <vector>
#include <array>
#include <map>
#include <memory>
#include <deque>
#include <GLFW/glfw3.h>
#include <mutex>
#include "vec2d.h"
//--プロトタイプ宣言--
class Fish;
class Shark;
class TexImage;
class FishLoader;
class WaterSurface;
class IPCom;
class MyShader;
class Food;
class Noise;
//--魚等の管理クラス--
class World
{
//画面の幅・高さ
int width, height;
//魚を保管するvector
std::vector<Fish*> fishes;
std::vector<Shark*> sharks;
//領域の分割(動作負荷軽減のため)
std::vector<std::map<int, Fish*>> partitons;
//partitions
const int parti_w = 50, //分割領域の大きさ
parti_h = 50;
const int parti_nx, parti_ny; //分割数(大きさにより決定)
//エサ
std::deque<Food*> foods;
std::vector<std::map<int, Food*>> parti_foods;
//騒音
std::deque<Noise*> noises;
std::vector<std::map<int, Noise*>> parti_noises;
std::vector<vec2d> future_noise_list; //ノイズ追加リスト
//マウス用
vec2d mouse_pos;
bool mouse_state = false; //押されているかどうか
bool mouse_state_right = false; //押されているかどうか
bool click_right = false; //レフトクリック
//タッチ用
std::array<vec2d, 10> touch_pos; //正規化座標
int touch_maxidx = 0;
//ステップカウンタ
unsigned int step = 0;
//魚ローダー
std::unique_ptr<FishLoader> fish_loader;
//フレームバッファ
GLuint frame_buf;
//水中テクスチャ
GLuint underwater_tex;
//水面
std::unique_ptr<WaterSurface> water_surface;
//通信用クラス
std::unique_ptr<IPCom> ip_com;
//描画用シェーダ
std::unique_ptr<MyShader> simple_shd;
//mutex
std::mutex world_mtx;
//デバッグモード
//bool debug_mode = true;
public:
World(int w, int h);
~World();
void update();
void opengl_update(); //OPENGL関連の処理
void render();
//エンティティ(魚・ターゲット)のアップデート
void update_entities();
//ノイズのリスト追加
void add_to_noise_list(vec2d pos);
//アクセサ
std::vector<Shark*>& get_sharks(){ return sharks; }
//std::vector<Target*>& get_targets(){ return targets; }
//分割された領域周辺にいるfishの配列を得る
std::vector<Fish*> get_neighborfishes(int idx);
std::vector<Food*> get_neighborfoods(int idx);
std::vector<Noise*> get_neighbornoises(int idx);
int get_width(){ return width; }
int get_height(){ return height; }
void set_mouse_pos(vec2d mp){ mouse_pos = mp; }
void set_mouse_state(bool ms){ mouse_state = ms; }
void set_click_state_right(bool ms){ click_right = ms; }
void add_fish_to_world(Fish* fish);
void add_food_to_world(Food* food);
void add_noise_to_world(Noise * food);
void set_touch_data(std::array<vec2d, 10>& pos_arr, int midx){ touch_pos = pos_arr; touch_maxidx = midx; }
GLuint get_shader();
//std::mutex& get_mtx(){ return world_mtx; }
};
#endif