Go で書き直した Ikemen
Révision | 759a5d72082ae15d9556f4bcff615c604d352920 (tree) |
---|---|
l'heure | 2016-12-10 23:54:48 |
Auteur | SUEHIRO <supersuehiro@user...> |
Commiter | SUEHIRO |
式のバイトコードを考えた
@@ -0,0 +1,433 @@ | ||
1 | +package main | |
2 | + | |
3 | +import ( | |
4 | + "math" | |
5 | + "unsafe" | |
6 | +) | |
7 | + | |
8 | +type StateType int32 | |
9 | + | |
10 | +const ( | |
11 | + ST_S StateType = 1 << iota | |
12 | + ST_C | |
13 | + ST_A | |
14 | + ST_L | |
15 | + ST_N | |
16 | + ST_U | |
17 | + ST_D = ST_L | |
18 | + ST_F = ST_N | |
19 | + ST_P = ST_U | |
20 | +) | |
21 | + | |
22 | +type AttackType int32 | |
23 | + | |
24 | +const ( | |
25 | + AT_NA AttackType = 1 << (iota + 6) | |
26 | + AT_NT | |
27 | + AT_NP | |
28 | + AT_SA | |
29 | + AT_ST | |
30 | + AT_SP | |
31 | + AT_HA | |
32 | + AT_HT | |
33 | + AT_HP | |
34 | +) | |
35 | + | |
36 | +type MoveType int32 | |
37 | + | |
38 | +const ( | |
39 | + MT_I MoveType = 1 << (iota + 15) | |
40 | + MT_H | |
41 | + MT_A = MT_I + 1 | |
42 | + MT_U = MT_H + 1 | |
43 | + MT_MNS = MT_I | |
44 | + MT_PLS = MT_H | |
45 | +) | |
46 | + | |
47 | +type ValueType int | |
48 | + | |
49 | +const ( | |
50 | + VT_Variant ValueType = iota | |
51 | + VT_Float | |
52 | + VT_Int | |
53 | + VT_Bool | |
54 | +) | |
55 | + | |
56 | +type OpCode byte | |
57 | + | |
58 | +const ( | |
59 | + OC_var0 OpCode = 0 | |
60 | + OC_sysvar0 OpCode = 60 | |
61 | + OC_fvar0 OpCode = 65 | |
62 | + OC_sysfvar0 OpCode = 105 | |
63 | + OC_var OpCode = iota + 110 | |
64 | + OC_sysvar | |
65 | + OC_fvar | |
66 | + OC_sysfvar | |
67 | + OC_int8 | |
68 | + OC_int | |
69 | + OC_float | |
70 | + OC_dup | |
71 | + OC_jmp8 | |
72 | + OC_jz8 | |
73 | + OC_jnz8 | |
74 | + OC_jmp | |
75 | + OC_jz | |
76 | + OC_jnz | |
77 | + OC_eq | |
78 | + OC_ne | |
79 | + OC_gt | |
80 | + OC_le | |
81 | + OC_lt | |
82 | + OC_ge | |
83 | + OC_blnot | |
84 | + OC_bland | |
85 | + OC_blxor | |
86 | + OC_blor | |
87 | + OC_not | |
88 | + OC_and | |
89 | + OC_xor | |
90 | + OC_or | |
91 | + OC_shl | |
92 | + OC_shr | |
93 | + OC_add | |
94 | + OC_sub | |
95 | + OC_mul | |
96 | + OC_div | |
97 | + OC_mod | |
98 | + OC_pow | |
99 | + OC_abs | |
100 | + OC_exp | |
101 | + OC_ln | |
102 | + OC_log | |
103 | + OC_cos | |
104 | + OC_sin | |
105 | + OC_tan | |
106 | + OC_acos | |
107 | + OC_asin | |
108 | + OC_atan | |
109 | + OC_floor | |
110 | + OC_ceil | |
111 | + OC_ifelse | |
112 | + OC_time | |
113 | + OC_animtime | |
114 | + OC_animelemtime | |
115 | + OC_animelemno | |
116 | + OC_statetype | |
117 | + OC_movetype | |
118 | + OC_ctrl | |
119 | + OC_command | |
120 | + OC_random | |
121 | + OC_pos_x | |
122 | + OC_pos_y | |
123 | + OC_vel_x | |
124 | + OC_vel_y | |
125 | + OC_screenpos_x | |
126 | + OC_screenpos_y | |
127 | + OC_facing | |
128 | + OC_anim | |
129 | + OC_animexist | |
130 | + OC_selfanimexist | |
131 | + OC_alive | |
132 | + OC_life | |
133 | + OC_lifemax | |
134 | + OC_power | |
135 | + OC_powermax | |
136 | + OC_canrecover | |
137 | + OC_roundstate | |
138 | + OC_ishelper | |
139 | + OC_numhelper | |
140 | + OC_numexplod | |
141 | + OC_numprojid | |
142 | + OC_numproj | |
143 | + OC_teammode | |
144 | + OC_teamside | |
145 | + OC_hitdefattr | |
146 | + OC_inguarddist | |
147 | + OC_movecontact | |
148 | + OC_movehit | |
149 | + OC_moveguarded | |
150 | + OC_movereversed | |
151 | + OC_projcontacttime | |
152 | + OC_projhittime | |
153 | + OC_projguardedtime | |
154 | + OC_projcanceltime | |
155 | + OC_backedge | |
156 | + OC_backedgedist | |
157 | + OC_backedgebodydist | |
158 | + OC_frontedge | |
159 | + OC_frontedgedist | |
160 | + OC_frontedgebodydist | |
161 | + OC_leftedge | |
162 | + OC_rightedge | |
163 | + OC_topedge | |
164 | + OC_bottomedge | |
165 | + OC_camerapos_x | |
166 | + OC_camerapos_y | |
167 | + OC_camerazoom | |
168 | + OC_gamewidth | |
169 | + OC_gameheight | |
170 | + OC_screenwidth | |
171 | + OC_screenheight | |
172 | + OC_stateno | |
173 | + OC_prevstateno | |
174 | + OC_id | |
175 | + OC_playeridexist | |
176 | + OC_gametime | |
177 | + OC_numtarget | |
178 | + OC_numenemy | |
179 | + OC_numpartner | |
180 | + OC_ailevel | |
181 | + OC_palno | |
182 | + OC_matchover | |
183 | + OC_hitcount | |
184 | + OC_uniqhitcount | |
185 | + OC_hitpausetime | |
186 | + OC_hitover | |
187 | + OC_hitshakeover | |
188 | + OC_hitfall | |
189 | + OC_hitvel_x | |
190 | + OC_hitvel_y | |
191 | + OC_roundno | |
192 | + OC_roundsexisted | |
193 | + OC_parent | |
194 | + OC_root | |
195 | + OC_helper | |
196 | + OC_target | |
197 | + OC_partner | |
198 | + OC_enemy | |
199 | + OC_enemynear | |
200 | + OC_playerid | |
201 | + OC_p2 | |
202 | + OC_const_ | |
203 | + OC_gethitvar_ | |
204 | + OC_ex_ | |
205 | +) | |
206 | +const ( | |
207 | + OC_const_data_life OpCode = iota | |
208 | + OC_const_data_power | |
209 | + OC_const_data_attack | |
210 | + OC_const_data_defence | |
211 | + OC_const_data_fall_defence_mul | |
212 | + OC_const_data_liedown_time | |
213 | + OC_const_data_airjuggle | |
214 | + OC_const_data_sparkno | |
215 | + OC_const_data_guard_sparkno | |
216 | + OC_const_data_ko_echo | |
217 | + OC_const_data_intpersistindex | |
218 | + OC_const_data_floatpersistindex | |
219 | + OC_const_size_xscale | |
220 | + OC_const_size_yscale | |
221 | + OC_const_size_ground_back | |
222 | + OC_const_size_ground_front | |
223 | + OC_const_size_air_back | |
224 | + OC_const_size_air_front | |
225 | + OC_const_size_z_width | |
226 | + OC_const_size_height | |
227 | + OC_const_size_attack_dist | |
228 | + OC_const_size_attack_z_width_back | |
229 | + OC_const_size_attack_z_width_front | |
230 | + OC_const_size_proj_attack_dist | |
231 | + OC_const_size_proj_doscale | |
232 | + OC_const_size_head_pos_x | |
233 | + OC_const_size_head_pos_y | |
234 | + OC_const_size_mid_pos_x | |
235 | + OC_const_size_mid_pos_y | |
236 | + OC_const_size_shadowoffset | |
237 | + OC_const_size_draw_offset_x | |
238 | + OC_const_size_draw_offset_y | |
239 | + OC_const_velocity_walk_fwd_x | |
240 | + OC_const_velocity_walk_back_x | |
241 | + OC_const_velocity_walk_up_x | |
242 | + OC_const_velocity_walk_down_x | |
243 | + OC_const_velocity_run_fwd_x | |
244 | + OC_const_velocity_run_fwd_y | |
245 | + OC_const_velocity_run_back_x | |
246 | + OC_const_velocity_run_back_y | |
247 | + OC_const_velocity_run_up_x | |
248 | + OC_const_velocity_run_up_y | |
249 | + OC_const_velocity_run_down_x | |
250 | + OC_const_velocity_run_down_y | |
251 | + OC_const_velocity_jump_y | |
252 | + OC_const_velocity_jump_neu_x | |
253 | + OC_const_velocity_jump_back_x | |
254 | + OC_const_velocity_jump_fwd_x | |
255 | + OC_const_velocity_jump_up_x | |
256 | + OC_const_velocity_jump_down_x | |
257 | + OC_const_velocity_runjump_back_x | |
258 | + OC_const_velocity_runjump_back_y | |
259 | + OC_const_velocity_runjump_fwd_x | |
260 | + OC_const_velocity_runjump_fwd_y | |
261 | + OC_const_velocity_runjump_up_x | |
262 | + OC_const_velocity_runjump_down_x | |
263 | + OC_const_velocity_airjump_y | |
264 | + OC_const_velocity_airjump_neu_x | |
265 | + OC_const_velocity_airjump_back_x | |
266 | + OC_const_velocity_airjump_fwd_x | |
267 | + OC_const_velocity_airjump_up_x | |
268 | + OC_const_velocity_airjump_down_x | |
269 | + OC_const_velocity_air_gethit_groundrecover_x | |
270 | + OC_const_velocity_air_gethit_groundrecover_y | |
271 | + OC_const_velocity_air_gethit_airrecover_mul_x | |
272 | + OC_const_velocity_air_gethit_airrecover_mul_y | |
273 | + OC_const_velocity_air_gethit_airrecover_add_x | |
274 | + OC_const_velocity_air_gethit_airrecover_add_y | |
275 | + OC_const_velocity_air_gethit_airrecover_back | |
276 | + OC_const_velocity_air_gethit_airrecover_fwd | |
277 | + OC_const_velocity_air_gethit_airrecover_up | |
278 | + OC_const_velocity_air_gethit_airrecover_down | |
279 | + OC_const_movement_airjump_num | |
280 | + OC_const_movement_airjump_height | |
281 | + OC_const_movement_yaccel | |
282 | + OC_const_movement_stand_friction | |
283 | + OC_const_movement_crouch_friction | |
284 | + OC_const_movement_stand_friction_threshold | |
285 | + OC_const_movement_crouch_friction_threshold | |
286 | + OC_const_movement_jump_changeanim_threshold | |
287 | + OC_const_movement_air_gethit_groundlevel | |
288 | + OC_const_movement_air_gethit_groundrecover_ground_threshold | |
289 | + OC_const_movement_air_gethit_groundrecover_groundlevel | |
290 | + OC_const_movement_air_gethit_airrecover_threshold | |
291 | + OC_const_movement_air_gethit_airrecover_yaccel | |
292 | + OC_const_movement_air_gethit_trip_groundlevel | |
293 | + OC_const_movement_down_bounce_offset_x | |
294 | + OC_const_movement_down_bounce_offset_y | |
295 | + OC_const_movement_down_bounce_yaccel | |
296 | + OC_const_movement_down_bounce_groundlevel | |
297 | + OC_const_movement_down_friction_threshold | |
298 | +) | |
299 | +const ( | |
300 | + OC_gethitvar_animtype OpCode = iota | |
301 | + OC_gethitvar_airtype | |
302 | + OC_gethitvar_groundtype | |
303 | + OC_gethitvar_damage | |
304 | + OC_gethitvar_hitcount | |
305 | + OC_gethitvar_fallcount | |
306 | + OC_gethitvar_hitshaketime | |
307 | + OC_gethitvar_hittime | |
308 | + OC_gethitvar_slidetime | |
309 | + OC_gethitvar_ctrltime | |
310 | + OC_gethitvar_recovertime | |
311 | + OC_gethitvar_xoff | |
312 | + OC_gethitvar_yoff | |
313 | + OC_gethitvar_xvel | |
314 | + OC_gethitvar_yvel | |
315 | + OC_gethitvar_yaccel | |
316 | + OC_gethitvar_chainid | |
317 | + OC_gethitvar_guarded | |
318 | + OC_gethitvar_isbound | |
319 | + OC_gethitvar_fall | |
320 | + OC_gethitvar_fall_damage | |
321 | + OC_gethitvar_fall_xvel | |
322 | + OC_gethitvar_fall_yvel | |
323 | + OC_gethitvar_fall_recover | |
324 | + OC_gethitvar_fall_recovertime | |
325 | + OC_gethitvar_fall_kill | |
326 | + OC_gethitvar_fall_envshake_time | |
327 | + OC_gethitvar_fall_envshake_freq | |
328 | + OC_gethitvar_fall_envshake_ampl | |
329 | + OC_gethitvar_fall_envshake_phase | |
330 | +) | |
331 | +const ( | |
332 | + OC_ex_name OpCode = iota | |
333 | + OC_ex_authorname | |
334 | + OC_ex_p2name | |
335 | + OC_ex_p3name | |
336 | + OC_ex_p4name | |
337 | + OC_ex_p2dist_x | |
338 | + OC_ex_p2dist_y | |
339 | + OC_ex_p2bodydist_x | |
340 | + OC_ex_p2bodydist_y | |
341 | + OC_ex_parentdist_x | |
342 | + OC_ex_parentdist_y | |
343 | + OC_ex_rootdist_x | |
344 | + OC_ex_rootdist_y | |
345 | + OC_ex_win | |
346 | + OC_ex_winko | |
347 | + OC_ex_wintime | |
348 | + OC_ex_winperfect | |
349 | + OC_ex_lose | |
350 | + OC_ex_loseko | |
351 | + OC_ex_losetime | |
352 | + OC_ex_drawgame | |
353 | + OC_ex_matchno | |
354 | + OC_ex_ishometeam | |
355 | + OC_ex_tickspersecond | |
356 | + OC_ex_stagevar_ | |
357 | +) | |
358 | +const ( | |
359 | + OC_ex_stagevar_info_author OpCode = iota | |
360 | + OC_ex_stagevar_info_displayname | |
361 | + OC_ex_stagevar_info_name | |
362 | +) | |
363 | + | |
364 | +type StringPool struct { | |
365 | + List []string | |
366 | + Map map[string]int | |
367 | +} | |
368 | + | |
369 | +func NewStringPool() *StringPool { | |
370 | + return &StringPool{Map: make(map[string]int)} | |
371 | +} | |
372 | +func (sp *StringPool) Clear(s string) { | |
373 | + sp.List, sp.Map = nil, make(map[string]int) | |
374 | +} | |
375 | +func (sp *StringPool) Add(s string) int { | |
376 | + i, ok := sp.Map[s] | |
377 | + if !ok { | |
378 | + i = len(sp.List) | |
379 | + sp.List = append(sp.List, s) | |
380 | + sp.Map[s] = i | |
381 | + } | |
382 | + return i | |
383 | +} | |
384 | + | |
385 | +type BytecodeExp []OpCode | |
386 | + | |
387 | +func (be *BytecodeExp) appendFloat(f float32) { | |
388 | + *be = append(append(*be, OC_float), | |
389 | + (*(*[4]OpCode)(unsafe.Pointer(&f)))[:]...) | |
390 | +} | |
391 | +func (be *BytecodeExp) appendInt(i int32) { | |
392 | + *be = append(append(*be, OC_int), (*(*[4]OpCode)(unsafe.Pointer(&i)))[:]...) | |
393 | +} | |
394 | +func (be *BytecodeExp) AppendValue(t ValueType, v float64) (ok bool) { | |
395 | + if math.IsNaN(v) { | |
396 | + return false | |
397 | + } | |
398 | + switch t { | |
399 | + case VT_Float: | |
400 | + be.appendFloat(float32(v)) | |
401 | + case VT_Int: | |
402 | + if v >= -128 || v <= 127 { | |
403 | + *be = append(*be, OC_int8, OpCode(v)) | |
404 | + } else { | |
405 | + be.appendInt(int32(v)) | |
406 | + } | |
407 | + case VT_Bool: | |
408 | + if v != 0 { | |
409 | + *be = append(*be, OC_int8, 1) | |
410 | + } else { | |
411 | + *be = append(*be, OC_int8, 0) | |
412 | + } | |
413 | + default: | |
414 | + return false | |
415 | + } | |
416 | + return true | |
417 | +} | |
418 | + | |
419 | +type StateBytecode struct { | |
420 | + stateType StateType | |
421 | + moveType MoveType | |
422 | + physics StateType | |
423 | +} | |
424 | + | |
425 | +func newStateBytecode() *StateBytecode { | |
426 | + return &StateBytecode{stateType: ST_S, moveType: MT_I, physics: ST_N} | |
427 | +} | |
428 | + | |
429 | +type Bytecode struct{ states map[int32]StateBytecode } | |
430 | + | |
431 | +func newBytecode() *Bytecode { | |
432 | + return &Bytecode{states: make(map[int32]StateBytecode)} | |
433 | +} |
@@ -2,77 +2,13 @@ package main | ||
2 | 2 | |
3 | 3 | import ( |
4 | 4 | "fmt" |
5 | + "math" | |
5 | 6 | "strings" |
6 | 7 | ) |
7 | 8 | |
8 | 9 | const kuuhaktokigou = " !=<>()|&+-*/%,[]^|:\"\t\r\n" |
9 | 10 | |
10 | -type StateType int32 | |
11 | - | |
12 | -const ( | |
13 | - ST_S StateType = 1 << iota | |
14 | - ST_C | |
15 | - ST_A | |
16 | - ST_L | |
17 | - ST_N | |
18 | - ST_U | |
19 | - ST_D = ST_L | |
20 | - ST_F = ST_N | |
21 | - ST_P = ST_U | |
22 | -) | |
23 | - | |
24 | -type AttackType int32 | |
25 | - | |
26 | -const ( | |
27 | - AT_NA AttackType = 1 << (iota + 6) | |
28 | - AT_NT | |
29 | - AT_NP | |
30 | - AT_SA | |
31 | - AT_ST | |
32 | - AT_SP | |
33 | - AT_HA | |
34 | - AT_HT | |
35 | - AT_HP | |
36 | -) | |
37 | - | |
38 | -type MoveType int32 | |
39 | - | |
40 | -const ( | |
41 | - MT_I MoveType = 1 << (iota + 15) | |
42 | - MT_H | |
43 | - MT_A = MT_I + 1 | |
44 | - MT_U = MT_H + 1 | |
45 | - MT_MNS = MT_I | |
46 | - MT_PLS = MT_H | |
47 | -) | |
48 | - | |
49 | -type ValueType int | |
50 | - | |
51 | -const ( | |
52 | - VT_Any ValueType = iota | |
53 | - VT_Float | |
54 | - VT_Int | |
55 | - VT_Bool | |
56 | -) | |
57 | - | |
58 | -type ByteExp []byte | |
59 | -type StateByteCode struct { | |
60 | - stateType StateType | |
61 | - moveType MoveType | |
62 | - physics StateType | |
63 | -} | |
64 | - | |
65 | -func newStateByteCode() *StateByteCode { | |
66 | - return &StateByteCode{stateType: ST_S, moveType: MT_I, physics: ST_N} | |
67 | -} | |
68 | - | |
69 | -type ByteCode struct{ states map[int32]StateByteCode } | |
70 | - | |
71 | -func newByteCode() *ByteCode { | |
72 | - return &ByteCode{states: make(map[int32]StateByteCode)} | |
73 | -} | |
74 | - | |
75 | -type ExpFunc func(out *ByteExp, in *string) (ValueType, error) | |
11 | +type ExpFunc func(out *BytecodeExp, in *string) (ValueType, float64, error) | |
76 | 12 | type Compiler struct{ cmdl *CommandList } |
77 | 13 | |
78 | 14 | func newCompiler() *Compiler { |
@@ -185,28 +121,42 @@ func (c *Compiler) tokenizer(in *string) string { | ||
185 | 121 | *in = (*in)[ia:] |
186 | 122 | return token |
187 | 123 | } |
188 | -func (c *Compiler) expBoolOr(out *ByteExp, in *string) (ValueType, error) { | |
124 | +func (c *Compiler) expBoolOr(out *BytecodeExp, in *string) (ValueType, | |
125 | + float64, error) { | |
189 | 126 | unimplemented() |
190 | - return 0, nil | |
127 | + return 0, 0, nil | |
191 | 128 | } |
192 | -func (c *Compiler) typedExp(ef ExpFunc, out *ByteExp, in *string, | |
193 | - vt ValueType) error { | |
194 | - t, err := ef(out, in) | |
129 | +func (c *Compiler) typedExp(ef ExpFunc, out *BytecodeExp, in *string, | |
130 | + vt ValueType) (float64, error) { | |
131 | + var be BytecodeExp | |
132 | + t, v, err := ef(&be, in) | |
195 | 133 | if err != nil { |
196 | - return err | |
134 | + return 0, err | |
197 | 135 | } |
198 | - unimplemented() | |
199 | - return nil | |
136 | + if len(be) == 0 && vt != VT_Variant { | |
137 | + if vt == VT_Bool { | |
138 | + if v != 0 { | |
139 | + v = 1 | |
140 | + } else { | |
141 | + v = 0 | |
142 | + } | |
143 | + } | |
144 | + return v, nil | |
145 | + } | |
146 | + *out = append(*out, be...) | |
147 | + out.AppendValue(t, v) | |
148 | + return math.NaN(), nil | |
200 | 149 | } |
201 | -func (c *Compiler) fullExpression(out *ByteExp, in *string, | |
202 | - vt ValueType) error { | |
203 | - if err := c.typedExp(c.expBoolOr, out, in, vt); err != nil { | |
204 | - return err | |
150 | +func (c *Compiler) fullExpression(out *BytecodeExp, in *string, | |
151 | + vt ValueType) (float64, error) { | |
152 | + v, err := c.typedExp(c.expBoolOr, out, in, vt) | |
153 | + if err != nil { | |
154 | + return 0, err | |
205 | 155 | } |
206 | 156 | if token := c.tokenizer(in); len(token) > 0 { |
207 | - return Error(token + "が不正です") | |
157 | + return 0, Error(token + "が不正です") | |
208 | 158 | } |
209 | - return nil | |
159 | + return v, nil | |
210 | 160 | } |
211 | 161 | func (c *Compiler) parseSection(lines []string, i *int, |
212 | 162 | sctrl func(name, data string) error) (IniSection, error) { |
@@ -293,7 +243,7 @@ func (c *Compiler) stateParam(is IniSection, name string, | ||
293 | 243 | } |
294 | 244 | return nil |
295 | 245 | } |
296 | -func (c *Compiler) stateDef(is IniSection, sbc *StateByteCode) error { | |
246 | +func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error { | |
297 | 247 | return c.stateSec(is, func() error { |
298 | 248 | if err := c.stateParam(is, "type", func(data string) error { |
299 | 249 | if len(data) == 0 { |
@@ -360,6 +310,8 @@ func (c *Compiler) stateDef(is IniSection, sbc *StateByteCode) error { | ||
360 | 310 | return err |
361 | 311 | } |
362 | 312 | if err := c.stateParam(is, "hitcountpersist", func(data string) error { |
313 | + var be BytecodeExp | |
314 | + v, err := c.fullExpression(&be, &data, VT_Bool) | |
363 | 315 | unimplemented() |
364 | 316 | return nil |
365 | 317 | }); err != nil { |
@@ -369,7 +321,7 @@ func (c *Compiler) stateDef(is IniSection, sbc *StateByteCode) error { | ||
369 | 321 | return nil |
370 | 322 | }) |
371 | 323 | } |
372 | -func (c *Compiler) stateCompile(bc *ByteCode, filename, def string) error { | |
324 | +func (c *Compiler) stateCompile(bc *Bytecode, filename, def string) error { | |
373 | 325 | var lines []string |
374 | 326 | if err := LoadFile(&filename, def, func(filename string) error { |
375 | 327 | str, err := LoadText(filename) |
@@ -403,7 +355,7 @@ func (c *Compiler) stateCompile(bc *ByteCode, filename, def string) error { | ||
403 | 355 | if err != nil { |
404 | 356 | return errmes(err) |
405 | 357 | } |
406 | - sbc := newStateByteCode() | |
358 | + sbc := newStateBytecode() | |
407 | 359 | if err := c.stateDef(is, sbc); err != nil { |
408 | 360 | return errmes(err) |
409 | 361 | } |
@@ -411,8 +363,8 @@ func (c *Compiler) stateCompile(bc *ByteCode, filename, def string) error { | ||
411 | 363 | } |
412 | 364 | return nil |
413 | 365 | } |
414 | -func (c *Compiler) Compile(n int, def string) (*ByteCode, error) { | |
415 | - bc := newByteCode() | |
366 | +func (c *Compiler) Compile(n int, def string) (*Bytecode, error) { | |
367 | + bc := newBytecode() | |
416 | 368 | str, err := LoadText(def) |
417 | 369 | if err != nil { |
418 | 370 | return nil, err |
@@ -30,7 +30,6 @@ var sys = System{ | ||
30 | 30 | allPalFX: *NewPalFX(), |
31 | 31 | sel: *newSelect(), |
32 | 32 | match: 1, |
33 | - inputRemap: [...]int{0, 1, 2, 3, 4, 5, 6, 7}, | |
34 | 33 | listenPort: "7500", |
35 | 34 | loader: *newLoader(), |
36 | 35 | numSimul: [2]int{2, 2}, |
@@ -93,6 +92,7 @@ type System struct { | ||
93 | 92 | esc bool |
94 | 93 | loadMutex sync.Mutex |
95 | 94 | ignoreMostErrors bool |
95 | + stringPool [MaxSimul * 2]StringPool | |
96 | 96 | } |
97 | 97 | |
98 | 98 | func (s *System) init(w, h int32) *lua.LState { |
@@ -116,6 +116,12 @@ func (s *System) init(w, h int32) *lua.LState { | ||
116 | 116 | s.audioOpen() |
117 | 117 | l := lua.NewState() |
118 | 118 | l.OpenLibs() |
119 | + for i := range s.inputRemap { | |
120 | + s.inputRemap[i] = i | |
121 | + } | |
122 | + for i := range s.stringPool { | |
123 | + s.stringPool[i] = *NewStringPool() | |
124 | + } | |
119 | 125 | systemScriptInit(l) |
120 | 126 | return l |
121 | 127 | } |
@@ -374,7 +380,7 @@ type Loader struct { | ||
374 | 380 | state LoaderState |
375 | 381 | loadExit chan LoaderState |
376 | 382 | err error |
377 | - code [MaxSimul * 2]*ByteCode | |
383 | + code [MaxSimul * 2]*Bytecode | |
378 | 384 | } |
379 | 385 | |
380 | 386 | func newLoader() *Loader { |