-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.hsp
339 lines (283 loc) · 6.85 KB
/
main.hsp
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
; HSP 3.4rc2
/*
#define CAPTION "Effector TV"
#define VERSION_S "1.01"
#define VERSION_I 101
#define AUTHOR "K-s"
#define WEBPAGE "http://uchitsukushi2.hatenablog.jp/entry/20141031/etv"
*/
#runtime "hsptv"
#regcmd 18
#cmd hsptv_send $00
#uselib "winmm"
#cfunc timer "timeGetTime"
#uselib "user32"
#func GetDC "GetDC" int
#func ReleaseDC "ReleaseDC" int, int
#func SetWindowLong "SetWindowLongA" int, int, int
#uselib "gdi32"
#cfunc ChoosePixelFormat "ChoosePixelFormat" int, var
#func SetPixelFormat "SetPixelFormat" int, int, var
#func SwapBuffers "SwapBuffers" int
#uselib "opengl32"
#func wglCreateContext "wglCreateContext" int
#func wglDeleteContext "wglDeleteContext" int
#func wglMakeCurrent "wglMakeCurrent" int, int
#func global wglGetProcAddress "wglGetProcAddress" sptr ; glfunc.hsp 内で使用
#func glClear "glClear" int
#func glRectd "glRectd" double, double, double, double
#func glReadPixels "glReadPixels" int, int, int, int, int, int, var
#define GL_COLOR_BUFFER_BIT 0x4000
#define GL_BGR 0x80E0
#define GL_UNSIGNED_BYTE 0x1401
#include "glfunc.hsp"
#include "glshader.hsp"
#const PDF_SIZE 40
#const PDF_VERSION 1
#const PFD_DRAW_TO_WINDOW $4
#const PFD_SUPPORT_OPENGL $20
#const PFD_DOUBLEBUFFER $1
#const PFD_TYPE_RGBA $0
#const PFD_COLOR_BIT 32
#const PFD_DEPTH_BIT 32
#const PDFINI1 PDF_SIZE | (PDF_VERSION << 16)
#const PDFINI2 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER
#const PDFINI3 PFD_TYPE_RGBA | (PFD_COLOR_BIT << 8)
#const PDFINI4 PFD_DEPTH_BIT << 24
#enum WIN_MAIN = 0
#enum WIN_EDIT
#enum WIN_LIST
#enum WIN_LOG
#enum WIN_TMPBUF
minus--
myDir = dir_cur
mainHwnd = hwnd
GetDC mainHwnd
wdc = stat
pfd = PDFINI1, PDFINI2, PDFINI3, 0, 0, PDFINI4
SetPixelFormat wdc, ChoosePixelFormat(wdc, pfd), pfd
wglCreateContext wdc
hrc = stat
wglMakeCurrent wdc, hrc
getFunc
if (stat) {
dialog "非対応です"
stop
}
vs = "void main(void){gl_Position=ftransform();}"
ls = "V void,B bool,I int,F float,B2 bvec2,B3 bvec3,B4 bvec4,I2 ivec2,I3 ivec3,I4 ivec4,V2 vec2,V3 vec3,V4 vec4,M2 mat2,M3 mat3,M4 mat4,PI 3.14159265359"
split ls, ",", ts
sdim fsb
repeat 17
fsb += "\n#define " + ts(cnt)
loop
fsb += "\nuniform I3 U;V2 VM=V2(U);F T=F(U.z)/1000.;V2 S=V2(640.,480.);V2 SS=V2(1.,-1.);V2 M=(VM*2.-S)/S.x*SS;V2 P=(gl_FragCoord.xy*2.-S)/S.x;V3 C=V3(0.);"
sdim fsrc, 256
fsrc = "F c=sin(P.x*cos(T*.27)*2.3)+cos(P.y*sin(T*.33)*2.6);F a=.01/abs(.5+.1*sin(T*.6)+.1*sin((atan(P.x,P.y)-length(M)+T*.5)*5.)-length(P));C=V3(a*.2+sin(T)*c,pow(a,sin(T+c)),c*.7)"
notesel fboard
hsptv_send fboard, minus
; 全ウィンドウ共通
onkey gosub *evKey
; スクリーンショット用
buffer WIN_TMPBUF, 640, 480
; HSPTVブラウザのウィンドウ(枠込)のサイズは 762x592
; 中のスクリーン(640x480)の左上座標は 64,81
makeWin WIN_LIST, 800, 365, 700, 100, 300
title "オンライン共有コードリスト"
sdim flist
objsize 800, 365
listbox flid, 0, flist
oncmd gosub *wmCommand, $111
gosub *setlist
makeWin WIN_LOG, 520, 100, , 580, 520
title "コンパイルログ"
sdim clog
mesbox clog, 520, 100, 0
makeWin WIN_EDIT, 800, 20, , 520, 800
title1 = "コードエディタ - 文字数:"
title title1
objmode 2
font msgothic, 14
input fsrc, 800, 20, 255
gosub *compile
if (succmp) {
sdim prefsrc
}
*mainLoop
glClear GL_COLOR_BUFFER_BIT
startShader
setUniform3 "U", mousex, mousey, timer() - stime
glRectd minus, minus, 1, 1
endShader
wglMakeCurrent wdc, hrc
SwapBuffers wdc
if (fsrc != prefsrc) {
prefsrc = fsrc
edited++
dim succmp
gosub *dispEditorTitle
}
await 15
goto *mainLoop
#deffunc makeWin int _id, int _sx, int _sy, int _x, int _y, int _ssx
gsel
screen _id, _sx, _sy, 11, limit(ginfo_wx1 + _x, 0, ginfo_dispx - 120), limit(ginfo_wy1 + _y, 0, ginfo_dispy - 120), _ssx
SetWindowLong hwnd, -16, $16c60000
return
*evKey
if (lparam >> 30) : return
getkey ctrl, 17 ; Ctrl
if (wparam == 13) { ; Enter
if (ctrl) {
if (edited) {
return
}
if (succmp) {
dialog "アップロードしますか?", 2
if (stat == 6) {
hsptv_send fboard, minus
noteget s ; ランキングトップのスコア取得
ts = fsrc
strrep ts, "&", "$"
dim cancel
repeat notemax / 3
noteget tss, cnt * 3 + 2
if (ts == tss) {
cancel++
}
loop
if (cancel) {
dialog "同じコードがあります"
} else {
hsptv_send fboard, 0 + s + 1, ts
gosub *setList
}
}
}
} else {
gosub *compile
}
}
if (wparam == 79) { ; O
if (ctrl) {
dialog "etvs", 16
if (stat) {
sdim fsrc, 256
bload refstr, fsrc
gosub *changeEditSrc_Cmp
}
}
}
if (wparam == 83) { ; S
if (ctrl) {
dialog "etvs", 17
if (stat) {
bsave refstr, fsrc, strlen(fsrc)
}
}
}
if (wparam == 120) { ; F9
gsel WIN_TMPBUF
mref vram, 66
glReadPixels , , 640, 480, GL_BGR, GL_UNSIGNED_BYTE, vram
if (ctrl) {
dialog "bmp", 17
if (stat) {
bmpsave refstr
}
} else {
bmpsave "shot.bmp"
}
gsel
}
return
*wmCommand
if (((wparam >> 16) & $ffff) == $2) {
getListFs_id = flid
gosub *getListFs
gosub *saveBackup
fsrc = getListFs_str
gosub *changeEditSrc_Cmp
if (succmp) {
sdim prefsrc
}
}
return
*saveBackup
bsave myDir + "\\backup.etvs", fsrc, strlen(fsrc)
return
*changeEditSrc_Cmp
gsel WIN_EDIT
objprm , fsrc
gosub *compile
return
*dispEditorTitle
gsel WIN_EDIT
ts = "アップロードOK (Ctrl+Enter)"
if (edited) {
ts = "変更あり"
} else {
if (succmp) : else {
ts = "コンパイルエラー"
}
}
title title1 + strlen(fsrc) + "/255 - 状態:" + ts
gsel
return
*compile
sdim fdst, 1024
dim sc
if (peek(fsrc) == '!') {
sdim sFunc
sc++
} else {
sFunc = "V main(V){"
}
dim p
repeat strlen(fsrc) - sc, sc
pc = peek(fsrc, cnt)
if (pc == 'R') {
c = peek(fsrc, cnt + 1)
n = strmid(fsrc, cnt + 2, 12)
ts = strf("for(F %c=0.;%c<%d.;%c++)", c, c, n, c)
poke fdst, p, ts
p += strsize
continue cnt + 2 + strlen(str(0 + n))
} else {
poke fdst, p, pc
p++
}
loop
fs = fsb + sFunc + fdst + ";gl_FragColor=V4(C,1.);}"
setprg vs, fs
succmp = stat
stime = timer()
prefsrc = fsrc
dim edited
gosub *dispEditorTitle
gsel WIN_LOG
objprm , getShaderLog()
gsel
return
*setList
sdim flist, 9000
repeat 30
noteget s, cnt * 3
getListFs_id = cnt
gosub *getListFs
flist += strf("#%s : %s\n", s, getListFs_str)
loop
gsel WIN_LIST
objprm , flist
gsel
return
*getListFs
noteget getListFs_str, getListFs_id * 3 + 2
strrep getListFs_str, "$", "&"
return
#deffunc _z onexit
wglMakeCurrent wdc
wglDeleteContext hrc
ReleaseDC mainHwnd, wdc
gosub *saveBackup
return