GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
Common.hh
Go to the documentation of this file.
1#include <string>
2#include <vector>
3#include "GameApi_h.hh"
4
5
6class HV : public HandleValue<std::pair<Vector,unsigned int> >
7{
8public:
9 HV(std::vector<float> &points, std::vector<unsigned int> &colors) : points(points), colors(colors) { }
10 void Handle(std::pair<Vector,unsigned int> p)
11 {
12 points.push_back(p.first.dx);
13 points.push_back(p.first.dy);
14 points.push_back(p.first.dz);
15 colors.push_back(p.second);
16 }
17private:
18 std::vector<float> &points;
19 std::vector<unsigned int> &colors;
20};
21
22
23
24struct CacheItem
25{
26public:
27 std::string filename;
28 GameApi::P obj;
29 int filesize;
30 int obj_count;
31};
32class Splitter;
34std::string cache_id(std::string filename, int obj_count);
35bool invalidate(CacheItem *item, std::string filename, int obj_count);
36void splitter_iter2(void *arg);
37void blocker_iter(void *arg);
38
39int FindProgressVal();
40int FindProgressMax();
41extern int g_shows_hundred;
42
43extern int hidden_score;
44
45extern int score;
46extern bool g_transparent;
47void ProgressBar(int num, int val, int max, std::string label);
48void InstallProgress(int num, std::string label, int max=15);
49unsigned int swap_color(unsigned int c);
50std::vector<unsigned char> load_from_url(std::string url);
51extern std::vector<std::pair<std::string,int> > prepare_cache_data;
52int find_data(std::string id);
53extern int thread_counter;
54extern ThreadInfo *ti_global;
55extern std::vector<int> g_hide_container;
56extern int no_draw_count;
58extern int score;
59extern int hidden_score;
60extern int async_pending_count;
62extern std::string gameapi_homepageurl;
63extern std::string gameapi_seamless_url;
64extern int async_is_done;
66void P_cb(void *data);
67
68void combparse(std::string comb, std::vector<std::string> &vec)
69{
70 std::string s;
71 int ss = comb.size();
72 for(int i=0;i<ss;i++)
73 {
74 char c = comb[i];
75 if (c==':')
76 {
77 vec.push_back(s);
78 s="";
79 }
80 else
81 {
82 s+=c;
83 }
84 }
85 if (s!="")
86 {
87 vec.push_back(s);
88 }
89}
90
91
92std::vector<std::string> parse_sep(std::string s, char sep)
93{
94 int ss = s.size();
95 int pos = 0;
96 std::vector<std::string> vec;
97 for(int i=0;i<ss;i++)
98 {
99 if (s[i]==sep) {
100 std::string beg = s.substr(pos, i-pos);
101 vec.push_back(beg);
102 pos = i+1;
103 }
104 }
105 std::string beg = s.substr(pos,s.size()-pos);
106 vec.push_back(beg);
107 //std::cout << "Parse sep: ";
108 //int s2 = vec.size();
109 //for(int i=0;i<s2;i++) std::cout << vec[i] << "::";
110 //std::cout << std::endl;
111 return vec;
112}
113
114
115int find_str(std::string val, std::string repl)
116{
117 std::size_t pos = val.find(repl);
118 if (pos==std::string::npos) return -1;
119 return pos;
120}
121
122std::string replace_str(std::string val, std::string repl, std::string subst)
123{
124 std::string s = "";
125 int p = 0;
126 while(1) {
127 int pos = find_str(val,repl);
128 if (pos==-1) { s+=val.substr(p,val.size()-p); return s; }
129 s+=val.substr(p,pos-p);
130 s+=subst;
131 val[pos]='X'; // remove %N
132 p=pos+repl.size();
133 }
134
135 while(1) {
136 int pos = find_str(val, repl);
137 if (pos==-1) return val;
138 val.replace(pos,pos+repl.size()-1,subst);
139 }
140 return "ERROR";
141}
142
143
144struct Envi_2 {
145 GameApi::EveryApi *ev;
146 GameApi::MN move;
147 GameApi::ML mainloop;
148 float pos_x=0.0, pos_y=0.0;
149 float rot_y=0.0;
150 float speed = 10.0;
151 float rot_speed = 1.0*3.14159*2.0/360.0;
152 float speed_x = 1.0;
153 float speed_y = 1.0;
154 GameApi::InteractionApi::Quake_data data;
155 bool logo_shown = true;
156 bool fpscounter = false;
157 float start_time = 0.0f;
158 GameApi::SH color_sh;
159 GameApi::SH texture_sh;
160 GameApi::SH arr_texture_sh;
161 bool exit = false;
162 float timeout = 100000.0f;
163 int screen_width=800;
164 int screen_height=600;
165};
166
167class MaterialForward : public Material
168{
169public:
171 {
172 GameApi::ML ml;
173 ml.id = mat(p.id);
174 return ml;
175 }
177 {
178 GameApi::ML ml;
179 ml.id = mat_inst(p.id,pts.id);
180 return ml;
181 }
182 int mat(int p) const
183 {
184 GameApi::P p2;
185 p2.id = p;
186 GameApi::ML ml = mat2(p2);
187 return ml.id;
188 }
189 int mat_inst(int p, int pts) const
190 {
191 GameApi::P p2;
192 p2.id = p;
193 GameApi::PTS p3;
194 p3.id = pts;
195 GameApi::ML ml = mat2_inst(p2,p3);
196 return ml.id;
197 }
198 int mat_inst2(int p, int pta) const
199 {
200 GameApi::P p2;
201 p2.id = p;
202 GameApi::PTA p3;
203 p3.id = pta;
204 GameApi::ML ml = mat2_inst2(p2,p3);
205 return ml.id;
206
207 }
208 int mat_inst_fade(int p, int pts, bool flip, float start_time, float end_time) const
209 {
210 GameApi::P p2;
211 p2.id = p;
212 GameApi::PTS p3;
213 p3.id = pts;
214 GameApi::ML ml = mat_inst_fade(p2,p3, flip, start_time, end_time);
215 return ml.id;
216
217 }
218 virtual GameApi::ML mat2(GameApi::P p) const=0;
221 virtual GameApi::ML mat_inst_fade(GameApi::P p, GameApi::PTS pts, bool flip, float start_time, float end_time) const=0;
222};
223
225struct LogoEnv
226{
233};
235
236std::vector<std::pair<std::string,int> > bitmap_prepare_cache_data;
237int bitmap_find_data(std::string data) {
238 int s = bitmap_prepare_cache_data.size();
239 for(int i=0;i<s;i++)
240 {
241 std::pair<std::string,int> p = bitmap_prepare_cache_data[i];
242 if (p.first==data) return p.second;
243 }
244 return -1;
245}
EveryApi ev(e)
Color2 colors[]
Definition Effect.cc:56
int g_shows_hundred
Definition GameApi.cc:1609
Splitter * splitter_current
Definition GameApi.cc:19458
std::vector< std::pair< std::string, int > > bitmap_prepare_cache_data
Definition GameApi_bm.cc:1010
std::vector< int > g_hide_container
Definition GameApi.cc:32929
int hidden_score
Definition GameApi.cc:19120
bool async_is_done
Definition GameApi.cc:17950
int no_draw_count
Definition GameApi.cc:18145
int async_pending_count_previous
Definition GameApi.cc:18143
std::string gameapi_seamless_url
Definition GameApi_main.cc:3362
int score
Definition GameApi.cc:19119
LogoEnv * logo_env
Definition GameApi_main.cc:2846
int frame_count
Definition GameApi_main.cc:2836
std::vector< std::pair< std::string, int > > prepare_cache_data
Definition GameApi_pl.cc:1259
ThreadInfo volatile * ti_global
Definition VertexArray.cc:4055
float arg(Complex z)
Definition GameApi_pl.cc:31413
volatile int thread_counter
Definition VertexArray.cc:4056
find_data()
Definition action_new_mesh.php:14
Definition GameApi_vo.cc:665
Point p
Definition HierarchyObject.cc:17
void Handle(std::pair< Vector, unsigned int > p)
Definition Common.hh:10
HV(std::vector< float > &points, std::vector< unsigned int > &colors)
Definition Common.hh:9
Definition GraphI.hh:1200
Definition cpushader.cc:936
GameApi::ML call(GameApi::P p) const
Definition Common.hh:170
virtual GameApi::ML mat2_inst2(GameApi::P p, GameApi::PTA pta) const =0
GameApi::ML call_inst(GameApi::P p, GameApi::PTS pts)
Definition Common.hh:176
int mat_inst(int p, int pts) const
Definition cpushader.cc:964
virtual GameApi::ML mat2_inst(GameApi::P p, GameApi::PTS pts) const =0
virtual GameApi::ML mat_inst_fade(GameApi::P p, GameApi::PTS pts, bool flip, float start_time, float end_time) const =0
int mat_inst_fade(int p, int pts, bool flip, float start_time, float end_time) const
Definition Common.hh:208
virtual GameApi::ML mat2(GameApi::P p) const =0
int mat_inst2(int p, int pta) const
Definition Common.hh:198
int mat(int p) const
Definition cpushader.cc:957
Definition GraphI.hh:1959
Definition GraphI.hh:2130
IMPORT int g_event_screen_y
Definition GameApi.cc:18167
IMPORT Low_SDL_Window * sdl_window
Definition GameApi.cc:38469
IMPORT bool g_transparent
Definition GameApi_gui.cc:1693
IMPORT int g_event_screen_x
Definition GameApi.cc:18166
IMPORT std::string gameapi_homepageurl
Definition GameApi_bm.cc:1942
int async_pending_count
Definition GameApi.cc:18142
background color
Definition gameapi_example.php:46
lazy data
Definition meshpage.php:1583
url
Definition meshpage.php:1781
void ProgressBar(int num, int val, int max, std::string label)
Definition GameApi_dep_env.cc:4198
void P_cb(void *data)
void combparse(std::string comb, std::vector< std::string > &vec)
Definition Common.hh:68
int FindProgressVal()
Definition GameApi_dep_env.cc:4023
int FindProgressMax()
Definition GameApi_dep_env.cc:4091
std::vector< unsigned char > load_from_url(std::string url)
bool invalidate(CacheItem *item, std::string filename, int obj_count)
Definition GameApi_pl.cc:14766
void splitter_iter2(void *arg)
Definition GameApi.cc:19459
void InstallProgress(int num, std::string label, int max=15)
Definition GameApi_dep_env.cc:3971
int bitmap_find_data(std::string data)
Definition Common.hh:237
unsigned int swap_color(unsigned int c)
Definition GameApi_pts.cc:597
void blocker_iter(void *arg)
Definition GameApi.cc:17977
std::string cache_id(std::string filename, int obj_count)
Definition GameApi_pl.cc:14795
int find_str(std::string val, std::string repl)
Definition Common.hh:115
std::string replace_str(std::string val, std::string repl, std::string subst)
Definition Common.hh:122
std::vector< std::string > parse_sep(std::string s, char sep)
Definition Common.hh:92
Definition GameApi_gltf.cc:6047
int obj_count
Definition GameApi_pl.cc:14755
GameApi::P obj
Definition GameApi_pl.cc:14753
std::string filename
Definition GameApi_pl.cc:14752
int filesize
Definition GameApi_pl.cc:14754
Definition GameApi.cc:17927
GameApi::SH color_sh
Definition GameApi.cc:17941
float start_time
Definition GameApi.cc:17940
bool exit
Definition GameApi.cc:17944
float pos_y
Definition GameApi.cc:17931
int screen_width
Definition GameApi.cc:17946
float rot_speed
Definition GameApi.cc:17934
GameApi::SH arr_texture_sh
Definition GameApi.cc:17943
float speed_x
Definition GameApi.cc:17935
bool logo_shown
Definition GameApi.cc:17938
float rot_y
Definition GameApi.cc:17932
GameApi::ML mainloop
Definition GameApi.cc:17930
GameApi::InteractionApi::Quake_data data
Definition GameApi.cc:17937
GameApi::SH texture_sh
Definition GameApi.cc:17942
float speed_y
Definition GameApi.cc:17936
GameApi::MN move
Definition GameApi.cc:17929
float speed
Definition GameApi.cc:17933
float timeout
Definition GameApi.cc:17945
float pos_x
Definition GameApi.cc:17931
bool fpscounter
Definition GameApi.cc:17939
int screen_height
Definition GameApi.cc:17947
GameApi::EveryApi * ev
Definition GameApi.cc:17928
Definition GameApi.hh:4664
Definition Common.hh:156
int id
Definition Common.hh:156
Definition Common.hh:145
int id
Definition Common.hh:145
Definition Common.hh:144
int id
Definition Common.hh:144
Definition Common.hh:86
int id
Definition Common.hh:86
Definition Common.hh:92
Definition GameApi_main.cc:2838
GameApi::SH texture
Definition GameApi_main.cc:2842
GameApi::SH texture_2d
Definition GameApi_main.cc:2843
GameApi::ML res
Definition GameApi_main.cc:2840
GameApi::SH arr
Definition GameApi_main.cc:2844
Definition GameApi_low.hh:680
Definition VertexArray.hh:498
num
Definition view.php:2821