• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Go で書き直した Ikemen


Commit MetaInfo

Revisión246d29c0aa4ff5b59a839d75c941cca29d05c0e3 (tree)
Tiempo2016-12-18 00:00:41
AutorSUEHIRO <supersuehiro@user...>
CommiterSUEHIRO

Log Message

煩雑になると思ったのでステートコントローラーの定数専用の処理をやめた

Cambiar Resumen

Diferencia incremental

--- a/src/bytecode.go
+++ b/src/bytecode.go
@@ -63,6 +63,7 @@ const (
6363 OC_int8
6464 OC_int
6565 OC_float
66+ OC_pop
6667 OC_dup
6768 OC_swap
6869 OC_jmp8
@@ -187,7 +188,6 @@ const (
187188 OC_hitvel_y
188189 OC_roundno
189190 OC_roundsexisted
190- OC_matchno
191191 OC_ishometeam
192192 OC_parent
193193 OC_root
@@ -359,6 +359,7 @@ const (
359359 OC_ex_loseko
360360 OC_ex_losetime
361361 OC_ex_drawgame
362+ OC_ex_matchno
362363 OC_ex_tickspersecond
363364 )
364365
@@ -425,6 +426,15 @@ func (bv *BytecodeValue) SetB(b bool) {
425426 func BytecodeSF() BytecodeValue {
426427 return BytecodeValue{VT_SFalse, math.NaN()}
427428 }
429+func BytecodeFloat(f float32) BytecodeValue {
430+ return BytecodeValue{VT_Float, float64(f)}
431+}
432+func BytecodeInt(i int32) BytecodeValue {
433+ return BytecodeValue{VT_Int, float64(i)}
434+}
435+func BytecodeBool(b bool) BytecodeValue {
436+ return BytecodeValue{VT_Bool, float64(Btoi(b))}
437+}
428438
429439 type BytecodeStack []BytecodeValue
430440
@@ -449,29 +459,19 @@ type BytecodeExp []OpCode
449459 func (be *BytecodeExp) append(op ...OpCode) {
450460 *be = append(*be, op...)
451461 }
452-func (be *BytecodeExp) appendFloat(f float32) {
453- be.append((*(*[4]OpCode)(unsafe.Pointer(&f)))[:]...)
454-}
455-func (be *BytecodeExp) appendInt(i int32) {
456- be.append((*(*[4]OpCode)(unsafe.Pointer(&i)))[:]...)
457-}
458-func (be BytecodeExp) toF() float32 {
459- return *(*float32)(unsafe.Pointer(&be[0]))
460-}
461-func (be BytecodeExp) toI() int32 {
462- return *(*int32)(unsafe.Pointer(&be[0]))
463-}
464462 func (be *BytecodeExp) appendValue(bv BytecodeValue) (ok bool) {
465463 switch bv.t {
466464 case VT_Float:
467465 be.append(OC_float)
468- be.appendFloat(float32(bv.v))
466+ f := float32(bv.v)
467+ be.append((*(*[4]OpCode)(unsafe.Pointer(&f)))[:]...)
469468 case VT_Int:
470469 if bv.v >= -128 || bv.v <= 127 {
471470 be.append(OC_int8, OpCode(bv.v))
472471 } else {
473472 be.append(OC_int)
474- be.appendInt(int32(bv.v))
473+ i := int32(bv.v)
474+ be.append((*(*[4]OpCode)(unsafe.Pointer(&i)))[:]...)
475475 }
476476 case VT_Bool:
477477 if bv.v != 0 {
@@ -484,6 +484,10 @@ func (be *BytecodeExp) appendValue(bv BytecodeValue) (ok bool) {
484484 }
485485 return true
486486 }
487+func (be *BytecodeExp) appendJmp(op OpCode, addr int32) {
488+ be.append(OC_int)
489+ be.append((*(*[4]OpCode)(unsafe.Pointer(&addr)))[:]...)
490+}
487491 func (_ BytecodeExp) blnot(v *BytecodeValue) {
488492 if v.ToB() {
489493 v.v = 0
@@ -624,14 +628,36 @@ func (be BytecodeExp) run(c *Char, scpn int) BytecodeValue {
624628 sys.bcStack.Clear()
625629 for i := 1; i <= len(be); i++ {
626630 switch be[i-1] {
631+ case OC_jz8, OC_jnz8:
632+ if sys.bcStack.Top().ToB() == (be[i-1] == OC_jz8) {
633+ i++
634+ break
635+ }
636+ fallthrough
637+ case OC_jmp8:
638+ if be[i] == 0 {
639+ i = len(be)
640+ } else {
641+ i += int(uint8(be[i])) + 1
642+ }
643+ case OC_jz, OC_jnz:
644+ if sys.bcStack.Top().ToB() == (be[i-1] == OC_jz) {
645+ i += 4
646+ break
647+ }
648+ fallthrough
649+ case OC_jmp:
650+ i += int(*(*int32)(unsafe.Pointer(&be[i]))) + 4
627651 case OC_int8:
628652 sys.bcStack.Push(BytecodeValue{VT_Int, float64(int8(be[i]))})
629653 i++
630654 case OC_int:
631- sys.bcStack.Push(BytecodeValue{VT_Int, float64(be[i:].toI())})
655+ sys.bcStack.Push(BytecodeValue{VT_Int,
656+ float64(*(*int32)(unsafe.Pointer(&be[i])))})
632657 i += 4
633658 case OC_float:
634- sys.bcStack.Push(BytecodeValue{VT_Float, float64(be[i:].toF())})
659+ sys.bcStack.Push(BytecodeValue{VT_Float,
660+ float64(*(*float32)(unsafe.Pointer(&be[i])))})
635661 i += 4
636662 case OC_blnot:
637663 be.blnot(sys.bcStack.Top())
@@ -689,10 +715,14 @@ func (be BytecodeExp) run(c *Char, scpn int) BytecodeValue {
689715 case OC_blor:
690716 v2 := sys.bcStack.Pop()
691717 be.blor(sys.bcStack.Top(), v2)
718+ case OC_pop:
719+ sys.bcStack.Pop()
692720 case OC_dup:
693721 sys.bcStack.Dup()
694722 case OC_swap:
695723 sys.bcStack.Swap()
724+ case OC_time:
725+ sys.bcStack.Push(BytecodeInt(c.time()))
696726 default:
697727 unimplemented()
698728 }
@@ -710,13 +740,10 @@ func (be BytecodeExp) evalB(c *Char, scpn int) bool {
710740 }
711741
712742 type StateController interface {
713- Run(c *Char, scpn int) (changeState bool)
743+ Run(c *Char, ps *int32) (changeState bool)
714744 }
715745
716-const (
717- SCID_trigger byte = 0
718- SCID_const byte = 128
719-)
746+const SCID_trigger byte = 255
720747
721748 type StateControllerBase struct {
722749 playerNo int
@@ -728,21 +755,21 @@ type StateControllerBase struct {
728755 func newStateControllerBase(pn int) *StateControllerBase {
729756 return &StateControllerBase{playerNo: pn, persistent: 1}
730757 }
731-func (scb StateControllerBase) beToExp(be ...BytecodeExp) []BytecodeExp {
758+func (_ StateControllerBase) beToExp(be ...BytecodeExp) []BytecodeExp {
732759 return be
733760 }
734-func (scb StateControllerBase) fToExp(f ...float32) (exp []BytecodeExp) {
761+func (_ StateControllerBase) fToExp(f ...float32) (exp []BytecodeExp) {
735762 for _, v := range f {
736763 var be BytecodeExp
737- be.appendFloat(v)
764+ be.appendValue(BytecodeFloat(v))
738765 exp = append(exp, be)
739766 }
740767 return
741768 }
742-func (scb StateControllerBase) iToExp(i ...int32) (exp []BytecodeExp) {
769+func (_ StateControllerBase) iToExp(i ...int32) (exp []BytecodeExp) {
743770 for _, v := range i {
744771 var be BytecodeExp
745- be.appendInt(v)
772+ be.appendValue(BytecodeInt(v))
746773 exp = append(exp, be)
747774 }
748775 return
@@ -755,7 +782,12 @@ func (scb *StateControllerBase) add(id byte, exp []BytecodeExp) {
755782 scb.code = append(scb.code, (*(*[]byte)(unsafe.Pointer(&e)))...)
756783 }
757784 }
758-func (scb StateControllerBase) run(f func(byte, []BytecodeExp) bool) bool {
785+func (scb StateControllerBase) run(c *Char, ps *int32,
786+ f func(byte, []BytecodeExp)) bool {
787+ (*ps)--
788+ if *ps > 0 {
789+ return false
790+ }
759791 for i := 0; i < len(scb.code); {
760792 id := scb.code[i]
761793 i++
@@ -768,17 +800,22 @@ func (scb StateControllerBase) run(f func(byte, []BytecodeExp) bool) bool {
768800 exp[m] = (*(*BytecodeExp)(unsafe.Pointer(&scb.code)))[i : i+int(l)]
769801 i += int(l)
770802 }
771- if !f(id, exp) {
772- return false
803+ if id == SCID_trigger {
804+ if !exp[0].evalB(c, scb.playerNo) {
805+ return false
806+ }
807+ } else {
808+ f(id, exp)
773809 }
774810 }
811+ *ps = scb.persistent
775812 return true
776813 }
777814
778815 type stateDef StateControllerBase
779816
780817 const (
781- stateDef_hitcountpersist byte = iota + 1
818+ stateDef_hitcountpersist byte = iota
782819 stateDef_movehitpersist
783820 stateDef_hitdefpersist
784821 stateDef_sprpriority
@@ -788,72 +825,46 @@ const (
788825 stateDef_anim
789826 stateDef_ctrl
790827 stateDef_poweradd
791- stateDef_hitcountpersist_c = stateDef_hitcountpersist + SCID_const
792- stateDef_movehitpersist_c = stateDef_movehitpersist + SCID_const
793- stateDef_hitdefpersist_c = stateDef_hitdefpersist + SCID_const
794- stateDef_sprpriority_c = stateDef_sprpriority + SCID_const
795- stateDef_facep2_c = stateDef_facep2 + SCID_const
796- stateDef_juggle_c = stateDef_juggle + SCID_const
797- stateDef_velset_c = stateDef_velset + SCID_const
798- stateDef_anim_c = stateDef_anim + SCID_const
799- stateDef_ctrl_c = stateDef_ctrl + SCID_const
800- stateDef_poweradd_c = stateDef_poweradd + SCID_const
801828 )
802829
803-func (sd stateDef) Run(c *Char, scpn int) bool {
804- StateControllerBase(sd).run(func(id byte, exp []BytecodeExp) bool {
830+func (sc stateDef) Run(c *Char, ps *int32) bool {
831+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) {
805832 switch id {
806- case stateDef_hitcountpersist, stateDef_hitcountpersist_c:
807- if id == stateDef_hitcountpersist_c || !exp[0].evalB(c, scpn) {
833+ case stateDef_hitcountpersist:
834+ if !exp[0].evalB(c, sc.playerNo) {
808835 c.clearHitCount()
809836 }
810- case stateDef_movehitpersist, stateDef_movehitpersist_c:
811- if id == stateDef_movehitpersist_c || !exp[0].evalB(c, scpn) {
837+ case stateDef_movehitpersist:
838+ if !exp[0].evalB(c, sc.playerNo) {
812839 c.clearMoveHit()
813840 }
814- case stateDef_hitdefpersist, stateDef_hitdefpersist_c:
815- if id == stateDef_hitdefpersist_c || !exp[0].evalB(c, scpn) {
841+ case stateDef_hitdefpersist:
842+ if !exp[0].evalB(c, sc.playerNo) {
816843 c.clearHitDef()
817844 }
818845 case stateDef_sprpriority:
819- c.setSprPriority(exp[0].evalI(c, scpn))
820- case stateDef_sprpriority_c:
821- c.setSprPriority(exp[0].toI())
822- case stateDef_facep2, stateDef_facep2_c:
823- if id == stateDef_facep2_c || exp[0].evalB(c, scpn) {
846+ c.setSprPriority(exp[0].evalI(c, sc.playerNo))
847+ case stateDef_facep2:
848+ if exp[0].evalB(c, sc.playerNo) {
824849 c.faceP2()
825850 }
826851 case stateDef_juggle:
827- c.setJuggle(exp[0].evalI(c, scpn))
828- case stateDef_juggle_c:
829- c.setJuggle(exp[0].toI())
852+ c.setJuggle(exp[0].evalI(c, sc.playerNo))
830853 case stateDef_velset:
831- c.setXV(exp[0].evalF(c, scpn))
854+ c.setXV(exp[0].evalF(c, sc.playerNo))
832855 if len(exp) > 1 {
833- c.setYV(exp[1].evalF(c, scpn))
856+ c.setYV(exp[1].evalF(c, sc.playerNo))
834857 if len(exp) > 2 {
835- exp[2].run(c, scpn)
858+ exp[2].run(c, sc.playerNo)
836859 }
837860 }
838- case stateDef_velset_c:
839- c.setXV(exp[0].toF())
840- if len(exp) > 1 {
841- c.setYV(exp[1].toF())
842- }
843861 case stateDef_anim:
844- c.changeAnim(exp[0].evalI(c, scpn))
845- case stateDef_anim_c:
846- c.changeAnim(exp[0].toI())
862+ c.changeAnim(exp[0].evalI(c, sc.playerNo))
847863 case stateDef_ctrl:
848- c.setCtrl(exp[0].evalB(c, scpn))
849- case stateDef_ctrl_c:
850- c.setCtrl(exp[0].toI() != 0)
864+ c.setCtrl(exp[0].evalB(c, sc.playerNo))
851865 case stateDef_poweradd:
852- c.addPower(exp[0].evalI(c, scpn))
853- case stateDef_poweradd_c:
854- c.addPower(exp[0].toI())
866+ c.addPower(exp[0].evalI(c, sc.playerNo))
855867 }
856- return true
857868 })
858869 return false
859870 }
@@ -861,23 +872,49 @@ func (sd stateDef) Run(c *Char, scpn int) bool {
861872 type hitBy StateControllerBase
862873
863874 const (
864- _hitBy_value byte = iota
865- _hitBy_value2
875+ hitBy_value byte = iota
876+ hitBy_value2
866877 hitBy_time
867- hitBy_value_c = _hitBy_value + SCID_const
868- hitBy_value2_c = _hitBy_value2 + SCID_const
869- hitBy_time_c = hitBy_time + SCID_const
870878 )
871879
872-func (nhb hitBy) Run(c *Char, scpn int) bool {
873- unimplemented()
880+func (sc hitBy) Run(c *Char, ps *int32) bool {
881+ time := int32(1)
882+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) {
883+ switch id {
884+ case hitBy_time:
885+ time = exp[0].evalI(c, sc.playerNo)
886+ case hitBy_value:
887+ unimplemented()
888+ case hitBy_value2:
889+ unimplemented()
890+ }
891+ })
874892 return false
875893 }
876894
877895 type notHitBy hitBy
878896
879-func (nhb notHitBy) Run(c *Char, scpn int) bool {
880- unimplemented()
897+func (sc notHitBy) Run(c *Char, ps *int32) bool {
898+ time := int32(1)
899+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) {
900+ switch id {
901+ case hitBy_time:
902+ time = exp[0].evalI(c, sc.playerNo)
903+ case hitBy_value:
904+ unimplemented()
905+ case hitBy_value2:
906+ unimplemented()
907+ }
908+ })
909+ return false
910+}
911+
912+type assertSpecial StateControllerBase
913+
914+func (sc assertSpecial) Run(c *Char, ps *int32) bool {
915+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) {
916+ unimplemented()
917+ })
881918 return false
882919 }
883920
--- a/src/char.go
+++ b/src/char.go
@@ -568,3 +568,7 @@ func (c *Char) setCtrl(ctrl bool) {
568568 func (c *Char) addPower(power int32) {
569569 unimplemented()
570570 }
571+func (c *Char) time() int32 {
572+ unimplemented()
573+ return 0
574+}
--- a/src/common.go
+++ b/src/common.go
@@ -149,6 +149,14 @@ func Atof(str string) float64 {
149149 }
150150 return f
151151 }
152+func readDigit(d string) (int32, bool) {
153+ for _, c := range d {
154+ if c < '0' || c > '9' {
155+ return 0, false
156+ }
157+ }
158+ return int32(Atof(d)), true
159+}
152160 func Btoi(b bool) int32 {
153161 if b {
154162 return 1
--- a/src/compiler.go
+++ b/src/compiler.go
@@ -324,7 +324,13 @@ func (c *Compiler) expValue(out *BytecodeExp, in *string) (BytecodeValue,
324324 if !sys.ignoreMostErrors {
325325 defer func() { c.usiroOp = false }()
326326 }
327- unimplemented()
327+ switch c.token {
328+ case "time":
329+ out.append(OC_time)
330+ default:
331+ println(c.token)
332+ unimplemented()
333+ }
328334 c.token = c.tokenizer(in)
329335 return bv, nil
330336 }
@@ -704,42 +710,47 @@ func (c *Compiler) expBoolOr(out *BytecodeExp, in *string) (BytecodeValue,
704710 return c.expOneOp(out, in, c.expBoolXor, "||", out.blor, OC_blor)
705711 }
706712 func (c *Compiler) typedExp(ef ExpFunc, in *string,
707- vt ValueType) (BytecodeExp, BytecodeValue, error) {
713+ vt ValueType) (BytecodeExp, error) {
708714 c.token = c.tokenizer(in)
709715 var be BytecodeExp
710716 bv, err := ef(&be, in)
711717 if err != nil {
712- return nil, BytecodeSF(), err
718+ return nil, err
713719 }
714720 if !bv.IsSF() {
715- if vt == VT_Bool {
721+ switch vt {
722+ case VT_Float:
723+ bv.SetF(bv.ToF())
724+ case VT_Int:
725+ bv.SetI(bv.ToI())
726+ case VT_Bool:
716727 bv.SetB(bv.ToB())
717728 }
718- return nil, bv, nil
729+ be.appendValue(bv)
719730 }
720- return be, BytecodeSF(), nil
731+ return be, nil
721732 }
722-func (c *Compiler) argExpression(in *string,
723- vt ValueType) (BytecodeExp, BytecodeValue, error) {
724- be, v, err := c.typedExp(c.expBoolOr, in, vt)
733+func (c *Compiler) argExpression(in *string, vt ValueType) (BytecodeExp,
734+ error) {
735+ be, err := c.typedExp(c.expBoolOr, in, vt)
725736 if err != nil {
726- return nil, BytecodeSF(), err
737+ return nil, err
727738 }
728739 if len(c.token) > 0 && c.token != "," {
729- return nil, BytecodeSF(), Error(c.token + "が不正です")
740+ return nil, Error(c.token + "が不正です")
730741 }
731- return be, v, nil
742+ return be, nil
732743 }
733-func (c *Compiler) fullExpression(in *string,
734- vt ValueType) (BytecodeExp, BytecodeValue, error) {
735- be, v, err := c.typedExp(c.expBoolOr, in, vt)
744+func (c *Compiler) fullExpression(in *string, vt ValueType) (BytecodeExp,
745+ error) {
746+ be, err := c.typedExp(c.expBoolOr, in, vt)
736747 if err != nil {
737- return nil, BytecodeSF(), err
748+ return nil, err
738749 }
739750 if len(c.token) > 0 {
740- return nil, BytecodeSF(), Error(c.token + "が不正です")
751+ return nil, Error(c.token + "が不正です")
741752 }
742- return be, v, nil
753+ return be, nil
743754 }
744755 func (c *Compiler) parseSection(lines []string, i *int,
745756 sctrl func(name, data string) error) (IniSection, error) {
@@ -843,50 +854,24 @@ func (c *Compiler) stateParam(is IniSection, name string,
843854 }
844855 func (c *Compiler) scAdd(sc *StateControllerBase, id byte,
845856 data string, vt ValueType, numArg int) error {
846- bes, vs := []BytecodeExp{}, []BytecodeValue{}
857+ bes := []BytecodeExp{}
847858 for n := 1; n <= numArg; n++ {
848859 var be BytecodeExp
849- var v BytecodeValue
850860 var err error
851861 if n < numArg {
852- be, v, err = c.argExpression(&data, vt)
862+ be, err = c.argExpression(&data, vt)
853863 } else {
854- be, v, err = c.fullExpression(&data, vt)
864+ be, err = c.fullExpression(&data, vt)
855865 }
856866 if err != nil {
857867 return err
858868 }
859869 bes = append(bes, be)
860- vs = append(vs, v)
861- if n < numArg && c.token != "," {
870+ if c.token != "," {
862871 break
863872 }
864873 }
865- cns := true
866- for i, v := range vs {
867- if v.IsSF() {
868- cns = false
869- } else {
870- bes[i].appendValue(v)
871- }
872- }
873- if cns {
874- if vt == VT_Float {
875- floats := make([]float32, len(vs))
876- for i := range floats {
877- floats[i] = float32(vs[i].v)
878- }
879- sc.add(id+SCID_const, sc.fToExp(floats...))
880- } else {
881- ints := make([]int32, len(vs))
882- for i := range ints {
883- ints[i] = int32(vs[i].v)
884- }
885- sc.add(id+SCID_const, sc.iToExp(ints...))
886- }
887- } else {
888- sc.add(id, bes)
889- }
874+ sc.add(id, bes)
890875 return nil
891876 }
892877 func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error {
@@ -959,59 +944,32 @@ func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error {
959944 b := false
960945 if err := c.stateParam(is, "hitcountpersist", func(data string) error {
961946 b = true
962- be, v, err := c.fullExpression(&data, VT_Bool)
963- if err != nil {
964- return err
965- }
966- if v.IsSF() {
967- sc.add(stateDef_hitcountpersist, sc.beToExp(be))
968- } else if !v.ToB() { // falseのときだけクリアする
969- sc.add(stateDef_hitcountpersist_c, nil)
970- }
971- return nil
947+ return c.scAdd(sc, stateDef_hitcountpersist, data, VT_Bool, 1)
972948 }); err != nil {
973949 return err
974950 }
975951 if !b {
976- sc.add(stateDef_hitcountpersist_c, nil)
952+ sc.add(stateDef_hitcountpersist, sc.iToExp(0))
977953 }
978954 b = false
979955 if err := c.stateParam(is, "movehitpersist", func(data string) error {
980956 b = true
981- be, v, err := c.fullExpression(&data, VT_Bool)
982- if err != nil {
983- return err
984- }
985- if v.IsSF() {
986- sc.add(stateDef_movehitpersist, sc.beToExp(be))
987- } else if !v.ToB() { // falseのときだけクリアする
988- sc.add(stateDef_movehitpersist_c, nil)
989- }
990- return nil
957+ return c.scAdd(sc, stateDef_movehitpersist, data, VT_Bool, 1)
991958 }); err != nil {
992959 return err
993960 }
994961 if !b {
995- sc.add(stateDef_movehitpersist_c, nil)
962+ sc.add(stateDef_movehitpersist, sc.iToExp(0))
996963 }
997964 b = false
998965 if err := c.stateParam(is, "hitdefpersist", func(data string) error {
999966 b = true
1000- be, v, err := c.fullExpression(&data, VT_Bool)
1001- if err != nil {
1002- return err
1003- }
1004- if v.IsSF() {
1005- sc.add(stateDef_hitdefpersist, sc.beToExp(be))
1006- } else if !v.ToB() { // falseのときだけクリアする
1007- sc.add(stateDef_hitdefpersist_c, nil)
1008- }
1009- return nil
967+ return c.scAdd(sc, stateDef_hitdefpersist, data, VT_Bool, 1)
1010968 }); err != nil {
1011969 return err
1012970 }
1013971 if !b {
1014- sc.add(stateDef_hitdefpersist_c, nil)
972+ sc.add(stateDef_hitdefpersist, sc.iToExp(0))
1015973 }
1016974 if err := c.stateParam(is, "sprpriority", func(data string) error {
1017975 return c.scAdd(sc, stateDef_sprpriority, data, VT_Int, 1)
@@ -1019,16 +977,7 @@ func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error {
1019977 return err
1020978 }
1021979 if err := c.stateParam(is, "facep2", func(data string) error {
1022- be, v, err := c.fullExpression(&data, VT_Bool)
1023- if err != nil {
1024- return err
1025- }
1026- if v.IsSF() {
1027- sc.add(stateDef_facep2, sc.beToExp(be))
1028- } else if v.ToB() {
1029- sc.add(stateDef_facep2_c, nil)
1030- }
1031- return nil
980+ return c.scAdd(sc, stateDef_facep2, data, VT_Bool, 1)
1032981 }); err != nil {
1033982 return err
1034983 }
@@ -1040,7 +989,7 @@ func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error {
1040989 return err
1041990 }
1042991 if !b {
1043- sc.add(stateDef_juggle_c, sc.iToExp(0))
992+ sc.add(stateDef_juggle, sc.iToExp(0))
1044993 }
1045994 if err := c.stateParam(is, "velset", func(data string) error {
1046995 return c.scAdd(sc, stateDef_velset, data, VT_Float, 3)
@@ -1066,14 +1015,14 @@ func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error {
10661015 return nil
10671016 })
10681017 }
1069-func (c *Compiler) hitBySub(is IniSection) (attr int32,
1070- timebe BytecodeExp, timev BytecodeValue, two bool, err error) {
1071- attr = -1
1018+func (c *Compiler) hitBySub(is IniSection, sc *StateControllerBase) error {
1019+ attr, two := int32(-1), false
1020+ var err error
10721021 if err = c.stateParam(is, "value", func(data string) error {
10731022 attr, err = c.attr(data, false)
10741023 return err
10751024 }); err != nil {
1076- return
1025+ return err
10771026 }
10781027 if attr == -1 {
10791028 if err = c.stateParam(is, "value2", func(data string) error {
@@ -1081,43 +1030,39 @@ func (c *Compiler) hitBySub(is IniSection) (attr int32,
10811030 attr, err = c.attr(data, false)
10821031 return err
10831032 }); err != nil {
1084- return
1033+ return err
10851034 }
10861035 }
10871036 if attr == -1 {
1088- err = Error("valueが指定されていません")
1089- return
1037+ return Error("valueが指定されていません")
10901038 }
1091- timev = BytecodeSF()
10921039 if err = c.stateParam(is, "time", func(data string) error {
1093- timebe, timev, err = c.fullExpression(&data, VT_Int)
1094- return err
1040+ return c.scAdd(sc, hitBy_time, data, VT_Int, 1)
10951041 }); err != nil {
1096- return
1042+ return err
10971043 }
1098- if len(timebe) == 0 && timev.IsSF() {
1099- timev.SetI(1)
1044+ if two {
1045+ sc.add(hitBy_value2, sc.iToExp(attr))
1046+ } else {
1047+ sc.add(hitBy_value, sc.iToExp(attr))
11001048 }
1101- return
1049+ return nil
11021050 }
11031051 func (c *Compiler) hitBy(is IniSection, sbc *StateBytecode,
11041052 sc *StateControllerBase) (StateController, error) {
11051053 return hitBy(*sc), c.stateSec(is, func() error {
1106- attr, timebe, timev, two, err := c.hitBySub(is)
1107- if err != nil {
1108- return err
1109- }
1110- unimplemented()
1111- return nil
1054+ return c.hitBySub(is, sc)
11121055 })
11131056 }
11141057 func (c *Compiler) notHitBy(is IniSection, sbc *StateBytecode,
11151058 sc *StateControllerBase) (StateController, error) {
11161059 return notHitBy(*sc), c.stateSec(is, func() error {
1117- attr, timebe, timev, two, err := c.hitBySub(is)
1118- if err != nil {
1119- return err
1120- }
1060+ return c.hitBySub(is, sc)
1061+ })
1062+}
1063+func (c *Compiler) assertSpecial(is IniSection, sbc *StateBytecode,
1064+ sc *StateControllerBase) (StateController, error) {
1065+ return assertSpecial(*sc), c.stateSec(is, func() error {
11211066 unimplemented()
11221067 return nil
11231068 })
@@ -1171,6 +1116,10 @@ func (c *Compiler) stateCompile(bc *Bytecode, filename, def string) error {
11711116 sc := newStateControllerBase(c.playerNo)
11721117 var scf func(is IniSection, sbc *StateBytecode,
11731118 sc *StateControllerBase) (StateController, error)
1119+ var triggerall []BytecodeExp
1120+ allUtikiri := false
1121+ var trigger [][]BytecodeExp
1122+ var trexist []int8
11741123 is, err := c.parseSection(lines, &i, func(name, data string) error {
11751124 switch name {
11761125 case "type":
@@ -1179,6 +1128,8 @@ func (c *Compiler) stateCompile(bc *Bytecode, filename, def string) error {
11791128 scf = c.hitBy
11801129 case "nothitby":
11811130 scf = c.notHitBy
1131+ case "assertspecial":
1132+ scf = c.assertSpecial
11821133 default:
11831134 println(data)
11841135 unimplemented()
@@ -1188,12 +1139,61 @@ func (c *Compiler) stateCompile(bc *Bytecode, filename, def string) error {
11881139 sc.persistent = Atoi(data)
11891140 if sc.persistent > 128 {
11901141 sc.persistent = 1
1142+ } else if sc.persistent <= 0 {
1143+ sc.persistent = math.MaxInt32
11911144 }
11921145 }
11931146 case "ignorehitpause":
11941147 sc.ignorehitpause = Atoi(data) != 0
1148+ case "triggerall":
1149+ be, err := c.fullExpression(&data, VT_Bool)
1150+ if err != nil {
1151+ return err
1152+ }
1153+ if len(be) == 2 && be[0] == OC_int8 {
1154+ if be[1] == 0 {
1155+ allUtikiri = true
1156+ }
1157+ } else if !allUtikiri {
1158+ triggerall = append(triggerall, be)
1159+ }
11951160 default:
1196- unimplemented()
1161+ tn, ok := readDigit(name[7:])
1162+ if !ok || tn <= 0 || tn > 65536 {
1163+ errmes(Error("トリガー名 (" + name + ") が不正です"))
1164+ }
1165+ if len(trigger) < int(tn) {
1166+ trigger = append(trigger, make([][]BytecodeExp,
1167+ int(tn)-len(trigger))...)
1168+ trexist = append(trexist, make([]int8, int(tn)-len(trexist))...)
1169+ }
1170+ tn--
1171+ be, err := c.fullExpression(&data, VT_Bool)
1172+ if err != nil {
1173+ if sys.ignoreMostErrors {
1174+ _break := false
1175+ for i := 0; i < int(tn); i++ {
1176+ if trexist[i] == 0 {
1177+ _break = true
1178+ break
1179+ }
1180+ }
1181+ if _break {
1182+ break
1183+ }
1184+ }
1185+ return err
1186+ }
1187+ if len(be) == 2 && be[0] == OC_int8 {
1188+ if be[1] == 0 {
1189+ trexist[tn] = -1
1190+ } else if trexist[tn] == 0 {
1191+ trexist[tn] = 1
1192+ }
1193+ } else if !allUtikiri && trexist[tn] >= 0 {
1194+ trigger[tn] = append(trigger[tn], be)
1195+ trexist[tn] = 1
1196+ }
11971197 }
11981198 return nil
11991199 })
@@ -1203,11 +1203,92 @@ func (c *Compiler) stateCompile(bc *Bytecode, filename, def string) error {
12031203 if scf == nil {
12041204 return errmes(Error("typeが指定されていません"))
12051205 }
1206+ if len(trexist) == 0 || trexist[0] == 0 {
1207+ return errmes(Error("trigger1がありません"))
1208+ }
1209+ var texp BytecodeExp
1210+ for i, e := range triggerall {
1211+ if len(e) > 0 {
1212+ texp.append(e...)
1213+ if i < len(triggerall)-1 {
1214+ texp.append(OC_jz8, 0)
1215+ texp.append(OC_pop)
1216+ }
1217+ }
1218+ }
1219+ if allUtikiri {
1220+ if len(texp) > 0 {
1221+ texp.appendValue(BytecodeBool(false))
1222+ }
1223+ } else {
1224+ for i, tr := range trigger {
1225+ if trexist[i] == 0 {
1226+ break
1227+ }
1228+ var te BytecodeExp
1229+ if trexist[i] < 0 {
1230+ te.appendValue(BytecodeBool(false))
1231+ }
1232+ oldlen := len(te)
1233+ for j := len(tr) - 1; j >= 0; j-- {
1234+ tmp := tr[j]
1235+ if len(tmp) > 0 {
1236+ if j < len(tr)-1 {
1237+ if len(te) > int(math.MaxUint8-1) {
1238+ tmp.appendJmp(OC_jz, int32(len(te)+1))
1239+ tmp.append(OC_pop)
1240+ } else {
1241+ tmp.append(OC_jz8, OpCode(len(te)+1))
1242+ tmp.append(OC_pop)
1243+ }
1244+ }
1245+ te = append(tmp, te...)
1246+ }
1247+ }
1248+ if len(te) == oldlen {
1249+ te = nil
1250+ }
1251+ if len(te) == 0 {
1252+ if trexist[i] > 0 {
1253+ if len(texp) > 0 {
1254+ texp.appendValue(BytecodeBool(true))
1255+ }
1256+ break
1257+ }
1258+ } else {
1259+ texp.append(te...)
1260+ if i < len(trigger)-1 {
1261+ texp.append(OC_jnz8, 0)
1262+ texp.append(OC_pop)
1263+ }
1264+ }
1265+ }
1266+ }
1267+ if len(texp) > 0 {
1268+ sc.add(SCID_trigger, sc.beToExp(texp))
1269+ }
12061270 sctrl, err := scf(is, sbc, sc)
12071271 if err != nil {
12081272 return errmes(err)
12091273 }
1210- sbc.ctrls = append(sbc.ctrls, sctrl)
1274+ appending := true
1275+ if len(texp) > 0 {
1276+ } else if allUtikiri {
1277+ appending = false
1278+ } else {
1279+ appending = false
1280+ for _, te := range trexist {
1281+ if te >= 0 {
1282+ if te > 0 {
1283+ appending = true
1284+ }
1285+ break
1286+ }
1287+ }
1288+ }
1289+ if appending {
1290+ sbc.ctrls = append(sbc.ctrls, sctrl)
1291+ }
12111292 }
12121293 _, ok := bc.states[n]
12131294 if !ok {