Go で書き直した Ikemen
修订版 | 6c1e69841e14f57b0fdebc368ea727263d822e88 (tree) |
---|---|
时间 | 2016-12-16 00:10:07 |
作者 | SUEHIRO <supersuehiro@user...> |
Commiter | SUEHIRO |
見直しやミスの修正などをした
@@ -458,9 +458,6 @@ func (be BytecodeExp) toI() int32 { | ||
458 | 458 | return *(*int32)(unsafe.Pointer(&be[0])) |
459 | 459 | } |
460 | 460 | func (be *BytecodeExp) appendValue(bv BytecodeValue) (ok bool) { |
461 | - if bv.IsSF() { | |
462 | - return false | |
463 | - } | |
464 | 461 | switch bv.t { |
465 | 462 | case VT_Float: |
466 | 463 | be.append(OC_float) |
@@ -492,16 +489,14 @@ func (_ BytecodeExp) blnot(v *BytecodeValue) { | ||
492 | 489 | v.t = VT_Int |
493 | 490 | } |
494 | 491 | func (_ BytecodeExp) pow(v1 *BytecodeValue, v2 BytecodeValue, pn int) { |
495 | - t := ValueType(Min(int32(v1.t), int32(v2.t))) | |
496 | - if t == VT_Float { | |
492 | + if ValueType(Min(int32(v1.t), int32(v2.t))) == VT_Float { | |
497 | 493 | v1.SetF(float32(math.Pow(float64(v1.ToF()), float64(v2.ToF())))) |
498 | 494 | } else if v2.ToF() < 0 { |
499 | 495 | if sys.cgi[pn].ver[0] == 1 { |
500 | 496 | v1.SetF(float32(math.Pow(float64(v1.ToI()), float64(v2.ToI())))) |
501 | 497 | } else { |
502 | 498 | f := float32(math.Pow(float64(v1.ToI()), float64(v2.ToI()))) |
503 | - i := *(*int32)(unsafe.Pointer(&f)) | |
504 | - v1.SetI(i << 29) | |
499 | + v1.SetI(*(*int32)(unsafe.Pointer(&f)) << 29) | |
505 | 500 | } |
506 | 501 | } else { |
507 | 502 | i1, i2, hb := v1.ToI(), v2.ToI(), int32(-1) |
@@ -524,7 +519,30 @@ func (_ BytecodeExp) pow(v1 *BytecodeValue, v2 BytecodeValue, pn int) { | ||
524 | 519 | v1.SetI(i) |
525 | 520 | } |
526 | 521 | } |
527 | -func (be BytecodeExp) run(c *Char) BytecodeValue { | |
522 | +func (_ BytecodeExp) mul(v1 *BytecodeValue, v2 BytecodeValue) { | |
523 | + if ValueType(Min(int32(v1.t), int32(v2.t))) == VT_Float { | |
524 | + v1.SetF(v1.ToF() * v2.ToF()) | |
525 | + } else { | |
526 | + v1.SetI(v1.ToI() * v2.ToI()) | |
527 | + } | |
528 | +} | |
529 | +func (_ BytecodeExp) div(v1 *BytecodeValue, v2 BytecodeValue) { | |
530 | + if ValueType(Min(int32(v1.t), int32(v2.t))) == VT_Float { | |
531 | + v1.SetF(v1.ToF() / v2.ToF()) | |
532 | + } else if v2.ToI() == 0 { | |
533 | + *v1 = BytecodeSF() | |
534 | + } else { | |
535 | + v1.SetI(v1.ToI() / v2.ToI()) | |
536 | + } | |
537 | +} | |
538 | +func (_ BytecodeExp) mod(v1 *BytecodeValue, v2 BytecodeValue) { | |
539 | + if v2.ToI() == 0 { | |
540 | + *v1 = BytecodeSF() | |
541 | + } else { | |
542 | + v1.SetI(v1.ToI() % v2.ToI()) | |
543 | + } | |
544 | +} | |
545 | +func (be BytecodeExp) run(c *Char, scpn int) BytecodeValue { | |
528 | 546 | sys.bcStack.Clear() |
529 | 547 | for i := 1; i <= len(be); i++ { |
530 | 548 | switch be[i-1] { |
@@ -541,17 +559,34 @@ func (be BytecodeExp) run(c *Char) BytecodeValue { | ||
541 | 559 | be.blnot(sys.bcStack.Top()) |
542 | 560 | case OC_pow: |
543 | 561 | v2 := sys.bcStack.Pop() |
544 | - be.pow(sys.bcStack.Top(), v2, c.playerno) | |
562 | + be.pow(sys.bcStack.Top(), v2, scpn) | |
563 | + case OC_mul: | |
564 | + v2 := sys.bcStack.Pop() | |
565 | + be.mul(sys.bcStack.Top(), v2) | |
566 | + case OC_div: | |
567 | + v2 := sys.bcStack.Pop() | |
568 | + be.div(sys.bcStack.Top(), v2) | |
569 | + case OC_mod: | |
570 | + v2 := sys.bcStack.Pop() | |
571 | + be.mod(sys.bcStack.Top(), v2) | |
545 | 572 | default: |
546 | 573 | unimplemented() |
547 | 574 | } |
548 | 575 | } |
549 | 576 | return sys.bcStack.Pop() |
550 | 577 | } |
551 | -func (be BytecodeExp) eval(c *Char) float64 { return be.run(c).v } | |
578 | +func (be BytecodeExp) evalF(c *Char, scpn int) float32 { | |
579 | + return be.run(c, scpn).ToF() | |
580 | +} | |
581 | +func (be BytecodeExp) evalI(c *Char, scpn int) int32 { | |
582 | + return be.run(c, scpn).ToI() | |
583 | +} | |
584 | +func (be BytecodeExp) evalB(c *Char, scpn int) bool { | |
585 | + return be.run(c, scpn).ToB() | |
586 | +} | |
552 | 587 | |
553 | 588 | type StateController interface { |
554 | - Run(c *Char) (changeState bool) | |
589 | + Run(c *Char, scpn int) (changeState bool) | |
555 | 590 | } |
556 | 591 | |
557 | 592 | const ( |
@@ -559,8 +594,14 @@ const ( | ||
559 | 594 | SCID_const byte = 128 |
560 | 595 | ) |
561 | 596 | |
562 | -type StateControllerBase []byte | |
597 | +type StateControllerBase struct { | |
598 | + playerNo int | |
599 | + code []byte | |
600 | +} | |
563 | 601 | |
602 | +func newStateControllerBase(pn int) *StateControllerBase { | |
603 | + return &StateControllerBase{playerNo: pn} | |
604 | +} | |
564 | 605 | func (scb StateControllerBase) beToExp(be ...BytecodeExp) []BytecodeExp { |
565 | 606 | return be |
566 | 607 | } |
@@ -581,24 +622,24 @@ func (scb StateControllerBase) iToExp(i ...int32) (exp []BytecodeExp) { | ||
581 | 622 | return |
582 | 623 | } |
583 | 624 | func (scb *StateControllerBase) add(id byte, exp []BytecodeExp) { |
584 | - *scb = append(*scb, id, byte(len(exp))) | |
625 | + scb.code = append(scb.code, id, byte(len(exp))) | |
585 | 626 | for _, e := range exp { |
586 | 627 | l := int32(len(e)) |
587 | - *scb = append(*scb, (*(*[4]byte)(unsafe.Pointer(&l)))[:]...) | |
588 | - *scb = append(*scb, (*(*[]byte)(unsafe.Pointer(&e)))...) | |
628 | + scb.code = append(scb.code, (*(*[4]byte)(unsafe.Pointer(&l)))[:]...) | |
629 | + scb.code = append(scb.code, (*(*[]byte)(unsafe.Pointer(&e)))...) | |
589 | 630 | } |
590 | 631 | } |
591 | 632 | func (scb StateControllerBase) run(f func(byte, []BytecodeExp) bool) bool { |
592 | - for i := 0; i < len(scb); { | |
593 | - id := scb[i] | |
633 | + for i := 0; i < len(scb.code); { | |
634 | + id := scb.code[i] | |
594 | 635 | i++ |
595 | - n := scb[i] | |
636 | + n := scb.code[i] | |
596 | 637 | i++ |
597 | 638 | exp := make([]BytecodeExp, n) |
598 | - for m := byte(0); m < n; m++ { | |
599 | - l := *(*int32)(unsafe.Pointer(&scb[i])) | |
639 | + for m := 0; m < int(n); m++ { | |
640 | + l := *(*int32)(unsafe.Pointer(&scb.code[i])) | |
600 | 641 | i += 4 |
601 | - exp[m] = (*(*BytecodeExp)(unsafe.Pointer(&scb)))[i : i+int(l)] | |
642 | + exp[m] = (*(*BytecodeExp)(unsafe.Pointer(&scb.code)))[i : i+int(l)] | |
602 | 643 | i += int(l) |
603 | 644 | } |
604 | 645 | if !f(id, exp) { |
@@ -633,39 +674,39 @@ const ( | ||
633 | 674 | stateDef_poweradd_c = stateDef_poweradd + SCID_const |
634 | 675 | ) |
635 | 676 | |
636 | -func (sd stateDef) Run(c *Char) bool { | |
677 | +func (sd stateDef) Run(c *Char, scpn int) bool { | |
637 | 678 | StateControllerBase(sd).run(func(id byte, exp []BytecodeExp) bool { |
638 | 679 | switch id { |
639 | 680 | case stateDef_hitcountpersist, stateDef_hitcountpersist_c: |
640 | - if id == stateDef_hitcountpersist_c || exp[0].eval(c) == 0 { | |
681 | + if id == stateDef_hitcountpersist_c || !exp[0].evalB(c, scpn) { | |
641 | 682 | c.clearHitCount() |
642 | 683 | } |
643 | 684 | case stateDef_movehitpersist, stateDef_movehitpersist_c: |
644 | - if id == stateDef_movehitpersist_c || exp[0].eval(c) == 0 { | |
685 | + if id == stateDef_movehitpersist_c || !exp[0].evalB(c, scpn) { | |
645 | 686 | c.clearMoveHit() |
646 | 687 | } |
647 | 688 | case stateDef_hitdefpersist, stateDef_hitdefpersist_c: |
648 | - if id == stateDef_hitdefpersist_c || exp[0].eval(c) == 0 { | |
689 | + if id == stateDef_hitdefpersist_c || !exp[0].evalB(c, scpn) { | |
649 | 690 | c.clearHitDef() |
650 | 691 | } |
651 | 692 | case stateDef_sprpriority: |
652 | - c.setSprPriority(int32(exp[0].eval(c))) | |
693 | + c.setSprPriority(exp[0].evalI(c, scpn)) | |
653 | 694 | case stateDef_sprpriority_c: |
654 | 695 | c.setSprPriority(exp[0].toI()) |
655 | 696 | case stateDef_facep2, stateDef_facep2_c: |
656 | - if id == stateDef_facep2_c || exp[0].eval(c) != 0 { | |
697 | + if id == stateDef_facep2_c || exp[0].evalB(c, scpn) { | |
657 | 698 | c.faceP2() |
658 | 699 | } |
659 | 700 | case stateDef_juggle: |
660 | - c.setJuggle(int32(exp[0].eval(c))) | |
701 | + c.setJuggle(exp[0].evalI(c, scpn)) | |
661 | 702 | case stateDef_juggle_c: |
662 | 703 | c.setJuggle(exp[0].toI()) |
663 | 704 | case stateDef_velset: |
664 | - c.setXV(float32(exp[0].eval(c))) | |
705 | + c.setXV(exp[0].evalF(c, scpn)) | |
665 | 706 | if len(exp) > 1 { |
666 | - c.setYV(float32(exp[1].eval(c))) | |
707 | + c.setYV(exp[1].evalF(c, scpn)) | |
667 | 708 | if len(exp) > 2 { |
668 | - exp[2].run(c) | |
709 | + exp[2].run(c, scpn) | |
669 | 710 | } |
670 | 711 | } |
671 | 712 | case stateDef_velset_c: |
@@ -674,15 +715,15 @@ func (sd stateDef) Run(c *Char) bool { | ||
674 | 715 | c.setYV(exp[1].toF()) |
675 | 716 | } |
676 | 717 | case stateDef_anim: |
677 | - c.changeAnim(int32(exp[0].eval(c))) | |
718 | + c.changeAnim(exp[0].evalI(c, scpn)) | |
678 | 719 | case stateDef_anim_c: |
679 | 720 | c.changeAnim(exp[0].toI()) |
680 | 721 | case stateDef_ctrl: |
681 | - c.setCtrl(exp[0].eval(c) != 0) | |
722 | + c.setCtrl(exp[0].evalB(c, scpn)) | |
682 | 723 | case stateDef_ctrl_c: |
683 | 724 | c.setCtrl(exp[0].toI() != 0) |
684 | 725 | case stateDef_poweradd: |
685 | - c.addPower(int32(exp[0].eval(c))) | |
726 | + c.addPower(exp[0].evalI(c, scpn)) | |
686 | 727 | case stateDef_poweradd_c: |
687 | 728 | c.addPower(exp[0].toI()) |
688 | 729 | } |
@@ -272,8 +272,8 @@ type Char struct { | ||
272 | 272 | name string |
273 | 273 | cmd []CommandList |
274 | 274 | key int |
275 | - helperindex int | |
276 | - playerno int | |
275 | + helperIndex int | |
276 | + playerNo int | |
277 | 277 | keyctrl bool |
278 | 278 | player bool |
279 | 279 | sprpriority int32 |
@@ -287,8 +287,8 @@ func newChar(n, idx int) (c *Char) { | ||
287 | 287 | return c |
288 | 288 | } |
289 | 289 | func (c *Char) init(n, idx int) { |
290 | - c.playerno, c.helperindex = n, idx | |
291 | - if c.helperindex == 0 { | |
290 | + c.playerNo, c.helperIndex = n, idx | |
291 | + if c.helperIndex == 0 { | |
292 | 292 | c.keyctrl, c.player = true, true |
293 | 293 | } |
294 | 294 | c.key = n |
@@ -297,7 +297,7 @@ func (c *Char) init(n, idx int) { | ||
297 | 297 | } |
298 | 298 | } |
299 | 299 | func (c *Char) load(def string) error { |
300 | - gi := &sys.cgi[c.playerno] | |
300 | + gi := &sys.cgi[c.playerNo] | |
301 | 301 | gi.displayname, gi.author, gi.sff, gi.snd = "", "", nil, nil |
302 | 302 | gi.anim = NewAnimationTable() |
303 | 303 | for i := range gi.palkeymap { |
@@ -12,12 +12,11 @@ const kuuhaktokigou = " !=<>()|&+-*/%,[]^|:\"\t\r\n" | ||
12 | 12 | type ExpFunc func(out *BytecodeExp, in *string) (BytecodeValue, error) |
13 | 13 | type Compiler struct { |
14 | 14 | cmdl *CommandList |
15 | - valCnt int | |
16 | 15 | maeOp string |
17 | 16 | usiroOp bool |
18 | 17 | norange bool |
19 | 18 | token string |
20 | - playerno int | |
19 | + playerNo int | |
21 | 20 | } |
22 | 21 | |
23 | 22 | func newCompiler() *Compiler { |
@@ -181,13 +180,13 @@ func (_ *Compiler) isOperator(token string) int { | ||
181 | 180 | } |
182 | 181 | return 0 |
183 | 182 | } |
184 | -func (c *Compiler) operator(in *string) (string, error) { | |
183 | +func (c *Compiler) operator(in *string) error { | |
185 | 184 | if len(c.maeOp) > 0 { |
186 | 185 | if opp := c.isOperator(c.token); opp <= c.isOperator(c.maeOp) { |
187 | 186 | if opp < 0 || ((!c.usiroOp || c.token[0] != '(') && |
188 | 187 | (c.token[0] < 'A' || c.token[0] > 'Z') && |
189 | 188 | (c.token[0] < 'a' || c.token[0] > 'z')) { |
190 | - return "", Error(c.maeOp + "が不正です") | |
189 | + return Error(c.maeOp + "が不正です") | |
191 | 190 | } |
192 | 191 | *in = c.token + " " + *in |
193 | 192 | c.token = c.maeOp |
@@ -195,7 +194,7 @@ func (c *Compiler) operator(in *string) (string, error) { | ||
195 | 194 | c.norange = true |
196 | 195 | } |
197 | 196 | } |
198 | - return c.token, nil | |
197 | + return nil | |
199 | 198 | } |
200 | 199 | func (c *Compiler) number(token string) BytecodeValue { |
201 | 200 | f, err := strconv.ParseFloat(token, 64) |
@@ -223,7 +222,6 @@ func (c *Compiler) expValue(out *BytecodeExp, in *string) (BytecodeValue, | ||
223 | 222 | c.usiroOp, c.norange = true, false |
224 | 223 | bv := c.number(c.token) |
225 | 224 | if !bv.IsSF() { |
226 | - c.valCnt++ | |
227 | 225 | c.token = c.tokenizer(in) |
228 | 226 | return bv, nil |
229 | 227 | } |
@@ -231,11 +229,10 @@ func (c *Compiler) expValue(out *BytecodeExp, in *string) (BytecodeValue, | ||
231 | 229 | defer func() { c.usiroOp = false }() |
232 | 230 | } |
233 | 231 | unimplemented() |
234 | - c.valCnt++ | |
235 | 232 | c.token = c.tokenizer(in) |
236 | 233 | return bv, nil |
237 | 234 | } |
238 | -func (c *Compiler) renzikuEnzansihaError(in *string) error { | |
235 | +func (c *Compiler) renzokuEnzansihaError(in *string) error { | |
239 | 236 | *in = strings.TrimSpace(*in) |
240 | 237 | if len(*in) > 0 { |
241 | 238 | switch (*in)[0] { |
@@ -265,14 +262,13 @@ func (c *Compiler) expPostNot(out *BytecodeExp, in *string) (BytecodeValue, | ||
265 | 262 | } |
266 | 263 | c.token = c.tokenizer(in) |
267 | 264 | } |
268 | - | |
269 | 265 | if len(c.maeOp) == 0 { |
270 | 266 | opp := c.isOperator(c.token) |
271 | 267 | if opp == 0 { |
272 | 268 | if !c.usiroOp && c.token == "(" { |
273 | 269 | return BytecodeSF(), Error("演算子がありません") |
274 | 270 | } |
275 | - oldin := *in | |
271 | + oldtoken, oldin := c.token, *in | |
276 | 272 | var dummyout BytecodeExp |
277 | 273 | if _, err := c.expValue(&dummyout, in); err != nil { |
278 | 274 | return BytecodeSF(), err |
@@ -280,13 +276,14 @@ func (c *Compiler) expPostNot(out *BytecodeExp, in *string) (BytecodeValue, | ||
280 | 276 | if c.isOperator(c.token) <= 0 { |
281 | 277 | return BytecodeSF(), Error("演算子がありません") |
282 | 278 | } |
283 | - if err := c.renzikuEnzansihaError(in); err != nil { | |
279 | + if err := c.renzokuEnzansihaError(in); err != nil { | |
284 | 280 | return BytecodeSF(), err |
285 | 281 | } |
286 | 282 | oldin = oldin[:len(oldin)-len(*in)] |
287 | - *in = "(" + oldin[:strings.LastIndex(oldin, c.token)] + *in | |
283 | + *in = oldtoken + " " + oldin[:strings.LastIndex(oldin, c.token)] + " " + | |
284 | + *in | |
288 | 285 | } else if opp > 0 { |
289 | - if err := c.renzikuEnzansihaError(in); err != nil { | |
286 | + if err := c.renzokuEnzansihaError(in); err != nil { | |
290 | 287 | return BytecodeSF(), err |
291 | 288 | } |
292 | 289 | } |
@@ -300,31 +297,27 @@ func (c *Compiler) expPow(out *BytecodeExp, in *string) (BytecodeValue, | ||
300 | 297 | return BytecodeSF(), err |
301 | 298 | } |
302 | 299 | for { |
303 | - op, err := c.operator(in) | |
304 | - if err != nil { | |
300 | + if err := c.operator(in); err != nil { | |
305 | 301 | return BytecodeSF(), err |
306 | 302 | } |
307 | - if op == "**" { | |
303 | + if c.token == "**" { | |
308 | 304 | var be BytecodeExp |
309 | 305 | bv2, err := c.expPostNot(&be, in) |
310 | 306 | if err != nil { |
311 | 307 | return BytecodeSF(), err |
312 | 308 | } |
313 | - if !bv.IsSF() && !bv.IsSF() { | |
314 | - out.pow(&bv, bv, c.playerno) | |
309 | + if !bv.IsSF() && !bv2.IsSF() { | |
310 | + out.pow(&bv, bv2, c.playerNo) | |
315 | 311 | } else { |
316 | - if !bv.IsSF() { | |
317 | - out.appendValue(bv) | |
318 | - } | |
312 | + out.appendValue(bv) | |
319 | 313 | out.append(be...) |
320 | - if !bv.IsSF() { | |
321 | - out.appendValue(bv2) | |
322 | - } | |
314 | + out.appendValue(bv2) | |
323 | 315 | out.append(OC_pow) |
324 | 316 | bv = BytecodeSF() |
325 | 317 | } |
318 | + } else { | |
319 | + break | |
326 | 320 | } |
327 | - unimplemented() | |
328 | 321 | } |
329 | 322 | return bv, nil |
330 | 323 | } |
@@ -334,8 +327,44 @@ func (c *Compiler) expMldv(out *BytecodeExp, in *string) (BytecodeValue, | ||
334 | 327 | if err != nil { |
335 | 328 | return BytecodeSF(), err |
336 | 329 | } |
337 | - unimplemented() | |
338 | - return bv, nil | |
330 | + for { | |
331 | + if err := c.operator(in); err != nil { | |
332 | + return BytecodeSF(), err | |
333 | + } | |
334 | + switch c.token { | |
335 | + case "*", "/", "%": | |
336 | + default: | |
337 | + return bv, nil | |
338 | + } | |
339 | + var be BytecodeExp | |
340 | + bv2, err := c.expPow(&be, in) | |
341 | + if err != nil { | |
342 | + return BytecodeSF(), err | |
343 | + } | |
344 | + if !bv.IsSF() && !bv2.IsSF() { | |
345 | + switch c.token { | |
346 | + case "*": | |
347 | + out.mul(&bv, bv2) | |
348 | + case "/": | |
349 | + out.div(&bv, bv2) | |
350 | + case "%": | |
351 | + out.mod(&bv, bv2) | |
352 | + } | |
353 | + } else { | |
354 | + out.appendValue(bv) | |
355 | + out.append(be...) | |
356 | + out.appendValue(bv2) | |
357 | + switch c.token { | |
358 | + case "*": | |
359 | + out.append(OC_mul) | |
360 | + case "/": | |
361 | + out.append(OC_div) | |
362 | + case "%": | |
363 | + out.append(OC_mod) | |
364 | + } | |
365 | + bv = BytecodeSF() | |
366 | + } | |
367 | + } | |
339 | 368 | } |
340 | 369 | func (c *Compiler) expAdsb(out *BytecodeExp, in *string) (BytecodeValue, |
341 | 370 | error) { |
@@ -410,9 +439,7 @@ func (c *Compiler) expBoolXor(out *BytecodeExp, in *string) (BytecodeValue, | ||
410 | 439 | } |
411 | 440 | func (c *Compiler) expBoolOr(out *BytecodeExp, in *string) (BytecodeValue, |
412 | 441 | error) { |
413 | - defer func(ovc int, omp string) { | |
414 | - c.valCnt, c.maeOp = ovc, omp | |
415 | - }(c.valCnt, c.maeOp) | |
442 | + defer func(omp string) { c.maeOp = omp }(c.maeOp) | |
416 | 443 | bv, err := c.expBoolXor(out, in) |
417 | 444 | if err != nil { |
418 | 445 | return BytecodeSF(), err |
@@ -430,11 +457,7 @@ func (c *Compiler) typedExp(ef ExpFunc, in *string, | ||
430 | 457 | } |
431 | 458 | if !bv.IsSF() { |
432 | 459 | if vt == VT_Bool { |
433 | - if bv.v != 0 { | |
434 | - bv.v = 1 | |
435 | - } else { | |
436 | - bv.v = 0 | |
437 | - } | |
460 | + bv.SetB(bv.ToB()) | |
438 | 461 | } |
439 | 462 | return nil, bv, nil |
440 | 463 | } |
@@ -569,9 +592,11 @@ func (c *Compiler) scAdd(sc *StateControllerBase, id byte, | ||
569 | 592 | } |
570 | 593 | } |
571 | 594 | cns := true |
572 | - for _, v := range vs { | |
595 | + for i, v := range vs { | |
573 | 596 | if v.IsSF() { |
574 | 597 | cns = false |
598 | + } else { | |
599 | + bes[i].appendValue(v) | |
575 | 600 | } |
576 | 601 | } |
577 | 602 | if cns { |
@@ -595,7 +620,7 @@ func (c *Compiler) scAdd(sc *StateControllerBase, id byte, | ||
595 | 620 | } |
596 | 621 | func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error { |
597 | 622 | return c.stateSec(is, func() error { |
598 | - var sc StateControllerBase | |
623 | + sc := newStateControllerBase(c.playerNo) | |
599 | 624 | if err := c.stateParam(is, "type", func(data string) error { |
600 | 625 | if len(data) == 0 { |
601 | 626 | return Error("値が指定されていません") |
@@ -669,7 +694,7 @@ func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error { | ||
669 | 694 | } |
670 | 695 | if v.IsSF() { |
671 | 696 | sc.add(stateDef_hitcountpersist, sc.beToExp(be)) |
672 | - } else if v.v == 0 { // falseのときだけクリアする | |
697 | + } else if !v.ToB() { // falseのときだけクリアする | |
673 | 698 | sc.add(stateDef_hitcountpersist_c, nil) |
674 | 699 | } |
675 | 700 | return nil |
@@ -688,7 +713,7 @@ func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error { | ||
688 | 713 | } |
689 | 714 | if v.IsSF() { |
690 | 715 | sc.add(stateDef_movehitpersist, sc.beToExp(be)) |
691 | - } else if v.v == 0 { // falseのときだけクリアする | |
716 | + } else if !v.ToB() { // falseのときだけクリアする | |
692 | 717 | sc.add(stateDef_movehitpersist_c, nil) |
693 | 718 | } |
694 | 719 | return nil |
@@ -707,7 +732,7 @@ func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error { | ||
707 | 732 | } |
708 | 733 | if v.IsSF() { |
709 | 734 | sc.add(stateDef_hitdefpersist, sc.beToExp(be)) |
710 | - } else if v.v == 0 { // falseのときだけクリアする | |
735 | + } else if !v.ToB() { // falseのときだけクリアする | |
711 | 736 | sc.add(stateDef_hitdefpersist_c, nil) |
712 | 737 | } |
713 | 738 | return nil |
@@ -718,7 +743,7 @@ func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error { | ||
718 | 743 | sc.add(stateDef_hitdefpersist_c, nil) |
719 | 744 | } |
720 | 745 | if err := c.stateParam(is, "sprpriority", func(data string) error { |
721 | - return c.scAdd(&sc, stateDef_sprpriority, data, VT_Int, 1) | |
746 | + return c.scAdd(sc, stateDef_sprpriority, data, VT_Int, 1) | |
722 | 747 | }); err != nil { |
723 | 748 | return err |
724 | 749 | } |
@@ -729,7 +754,7 @@ func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error { | ||
729 | 754 | } |
730 | 755 | if v.IsSF() { |
731 | 756 | sc.add(stateDef_facep2, sc.beToExp(be)) |
732 | - } else if v.v != 0 { | |
757 | + } else if v.ToB() { | |
733 | 758 | sc.add(stateDef_facep2_c, nil) |
734 | 759 | } |
735 | 760 | return nil |
@@ -739,7 +764,7 @@ func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error { | ||
739 | 764 | b = false |
740 | 765 | if err := c.stateParam(is, "juggle", func(data string) error { |
741 | 766 | b = true |
742 | - return c.scAdd(&sc, stateDef_juggle, data, VT_Int, 1) | |
767 | + return c.scAdd(sc, stateDef_juggle, data, VT_Int, 1) | |
743 | 768 | }); err != nil { |
744 | 769 | return err |
745 | 770 | } |
@@ -747,26 +772,26 @@ func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error { | ||
747 | 772 | sc.add(stateDef_juggle_c, sc.iToExp(0)) |
748 | 773 | } |
749 | 774 | if err := c.stateParam(is, "velset", func(data string) error { |
750 | - return c.scAdd(&sc, stateDef_velset, data, VT_Float, 3) | |
775 | + return c.scAdd(sc, stateDef_velset, data, VT_Float, 3) | |
751 | 776 | }); err != nil { |
752 | 777 | return err |
753 | 778 | } |
754 | 779 | if err := c.stateParam(is, "anim", func(data string) error { |
755 | - return c.scAdd(&sc, stateDef_anim, data, VT_Int, 1) | |
780 | + return c.scAdd(sc, stateDef_anim, data, VT_Int, 1) | |
756 | 781 | }); err != nil { |
757 | 782 | return err |
758 | 783 | } |
759 | 784 | if err := c.stateParam(is, "ctrl", func(data string) error { |
760 | - return c.scAdd(&sc, stateDef_ctrl, data, VT_Bool, 1) | |
785 | + return c.scAdd(sc, stateDef_ctrl, data, VT_Bool, 1) | |
761 | 786 | }); err != nil { |
762 | 787 | return err |
763 | 788 | } |
764 | 789 | if err := c.stateParam(is, "poweradd", func(data string) error { |
765 | - return c.scAdd(&sc, stateDef_poweradd, data, VT_Int, 1) | |
790 | + return c.scAdd(sc, stateDef_poweradd, data, VT_Int, 1) | |
766 | 791 | }); err != nil { |
767 | 792 | return err |
768 | 793 | } |
769 | - sbc.stateDef = stateDef(sc) | |
794 | + sbc.stateDef = stateDef(*sc) | |
770 | 795 | return nil |
771 | 796 | }) |
772 | 797 | } |
@@ -813,7 +838,7 @@ func (c *Compiler) stateCompile(bc *Bytecode, filename, def string) error { | ||
813 | 838 | return nil |
814 | 839 | } |
815 | 840 | func (c *Compiler) Compile(n int, def string) (*Bytecode, error) { |
816 | - c.playerno = n | |
841 | + c.playerNo = n | |
817 | 842 | bc := newBytecode() |
818 | 843 | str, err := LoadText(def) |
819 | 844 | if err != nil { |
@@ -437,7 +437,7 @@ func (l *Loader) loadChar(pn int) int { | ||
437 | 437 | sys.cgi[pn].palno = pal |
438 | 438 | } |
439 | 439 | if sys.cgi[pn].sff == nil { |
440 | - if l.code[pn], l.err = newCompiler().Compile(p.playerno, cdef); l.err != nil { | |
440 | + if l.code[pn], l.err = newCompiler().Compile(p.playerNo, cdef); l.err != nil { | |
441 | 441 | sys.chars[pn] = nil |
442 | 442 | return -1 |
443 | 443 | } |