• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags

Frequently used words (click to add to your profile)

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

Go で書き直した Ikemen


Commit MetaInfo

Revisão55383ba195aa1b57a7a0c075af5d0340e9bde634 (tree)
Hora2016-12-01 23:59:31
AutorSUEHIRO <supersuehiro@user...>
CommiterSUEHIRO

Mensagem de Log

作ってないところにでunimplementedを呼ぶようにした

Mudança Sumário

Diff

--- a/script/main.lua
+++ b/script/main.lua
@@ -327,7 +327,7 @@ function p1SelSub()
327327 p1SelEnd = true
328328 if p2In == 1 then
329329 p2Task = p2TmSub
330- commandBufReset(p2Cmd, p2In)
330+ commandBufReset(p2Cmd)
331331 end
332332 end
333333 end
@@ -404,7 +404,7 @@ function p2SelSub()
404404 p2SelEnd = true
405405 if p1In == 2 then
406406 p1Task = p1TmSub
407- commandBufReset(p1Cmd, p1In)
407+ commandBufReset(p1Cmd)
408408 end
409409 end
410410 end
@@ -519,8 +519,8 @@ function main()
519519
520520 refresh()
521521
522- commandBufReset(p1Cmd, p1In)
523- commandBufReset(p2Cmd, p2In)
522+ commandBufReset(p1Cmd)
523+ commandBufReset(p2Cmd)
524524
525525 selMode = true
526526 selectStart()
@@ -587,7 +587,7 @@ function modeSel()
587587 textImgSetText(portChange, 'Port Change(' .. getListenPort() .. ')')
588588
589589 refresh()
590- commandBufReset(p1Cmd, 1)
590+ commandBufReset(p1Cmd)
591591
592592 while btnPalNo(p1Cmd) <= 0 do
593593 if commandGetState(p1Cmd, 'u') then
--- /dev/null
+++ b/src/char.go
@@ -0,0 +1,4 @@
1+package main
2+
3+type CharGlobalInfo struct{ drawpalno int32 }
4+type Char struct{}
--- /dev/null
+++ b/src/compiler.go
@@ -0,0 +1,3 @@
1+package main
2+
3+type Compiler struct{}
--- a/src/image.go
+++ b/src/image.go
@@ -32,18 +32,27 @@ type PalFX struct {
3232 Remap []int
3333 }
3434
35-func NewPalFX() *PalFX { return &PalFX{} }
36-func (pfx *PalFX) GetFxPal(pal []uint32, neg bool) []uint32 { return pal }
35+func NewPalFX() *PalFX { return &PalFX{} }
36+func (pfx *PalFX) GetFxPal(pal []uint32, neg bool) []uint32 {
37+ if pfx == nil || pfx.Time == 0 {
38+ return pal
39+ }
40+ unimplemented()
41+ return nil
42+}
3743 func (pfx *PalFX) GetFcPalFx(trans int32) (neg bool, color float32,
3844 add, mul [3]float32) {
39- neg = false
40- color = 1
41- for i := range add {
42- add[i] = 0
43- }
44- for i := range mul {
45- mul[i] = 1
45+ if pfx == nil || pfx.Time == 0 {
46+ neg = false
47+ color = 1
48+ for i := range add {
49+ add[i] = 0
50+ }
51+ for i := range mul {
52+ mul[i] = 1
53+ }
4654 }
55+ unimplemented()
4756 return
4857 }
4958
--- a/src/input.go
+++ b/src/input.go
@@ -422,11 +422,17 @@ type NetBuffer struct {
422422 }
423423 type NetInput struct{ buf []NetBuffer }
424424
425-func (ni *NetInput) Close() {}
425+func (ni *NetInput) Close() { unimplemented() }
426+func (ni *NetInput) Input(cb *CommandBuffer, i, facing int32) {
427+ unimplemented()
428+}
426429
427430 type FileInput struct{ ib []InputBits }
428431
429-func (ni *FileInput) Close() {}
432+func (ni *FileInput) Close() { unimplemented() }
433+func (ni *FileInput) Input(cb *CommandBuffer, i, facing int32) {
434+ unimplemented()
435+}
430436
431437 type AiInput struct {
432438 dir, dt, at, bt, ct, xt, yt, zt, st int32
@@ -902,7 +908,7 @@ func (c *Command) bufTest(cbuf *CommandBuffer, ai bool,
902908 }
903909 }
904910 foo := false
905- for _, k := range c.cmd[c.cmdi-1].key {
911+ for _, k := range c.cmd[c.cmdi].key {
906912 n := cbuf.State2(k)
907913 if c.cmd[c.cmdi].slash {
908914 foo = foo || n > 0
@@ -966,8 +972,81 @@ type CommandList struct {
966972 DefaultBufferTime int32
967973 }
968974
969-func NewCommandList() *CommandList {
970- return &CommandList{Names: make(map[string]int)}
975+func NewCommandList(cb *CommandBuffer) *CommandList {
976+ return &CommandList{Buffer: cb, Names: make(map[string]int)}
977+}
978+func (cl *CommandList) Input(i, facing int32) bool {
979+ if cl.Buffer == nil {
980+ return false
981+ }
982+ step := cl.Buffer.Bb != 0
983+ if i < 0 && int(^i) < len(sys.aiInput) {
984+ sys.aiInput[^i].Update() // 乱数を使うので同期がずれないようここで
985+ }
986+ _else := i < 0
987+ if _else {
988+ } else if sys.fileInput != nil {
989+ sys.fileInput.Input(cl.Buffer, i, facing)
990+ } else if sys.netInput != nil {
991+ sys.netInput.Input(cl.Buffer, i, facing)
992+ } else {
993+ _else = true
994+ }
995+ if _else {
996+ var l, r, u, d, a, b, c, x, y, z, s bool
997+ if i < 0 {
998+ i = ^i
999+ if int(i) < len(sys.aiInput) {
1000+ l = sys.aiInput[i].L()
1001+ r = sys.aiInput[i].R()
1002+ u = sys.aiInput[i].U()
1003+ d = sys.aiInput[i].D()
1004+ a = sys.aiInput[i].A()
1005+ b = sys.aiInput[i].B()
1006+ c = sys.aiInput[i].C()
1007+ x = sys.aiInput[i].X()
1008+ y = sys.aiInput[i].Y()
1009+ z = sys.aiInput[i].Z()
1010+ s = sys.aiInput[i].S()
1011+ }
1012+ } else if int(i) < len(sys.inputRemap) {
1013+ in := sys.inputRemap[i]
1014+ if in < len(sys.keyConfig) {
1015+ joy := sys.keyConfig[in].Joy
1016+ if joy >= -1 {
1017+ l = JoystickState(joy, sys.keyConfig[in].L)
1018+ r = JoystickState(joy, sys.keyConfig[in].R)
1019+ u = JoystickState(joy, sys.keyConfig[in].U)
1020+ d = JoystickState(joy, sys.keyConfig[in].D)
1021+ a = JoystickState(joy, sys.keyConfig[in].A)
1022+ b = JoystickState(joy, sys.keyConfig[in].B)
1023+ c = JoystickState(joy, sys.keyConfig[in].C)
1024+ x = JoystickState(joy, sys.keyConfig[in].X)
1025+ y = JoystickState(joy, sys.keyConfig[in].Y)
1026+ z = JoystickState(joy, sys.keyConfig[in].Z)
1027+ s = JoystickState(joy, sys.keyConfig[in].S)
1028+ }
1029+ }
1030+ }
1031+ var B, F bool
1032+ if facing < 0 {
1033+ B, F = r, l
1034+ } else {
1035+ B, F = l, r
1036+ }
1037+ cl.Buffer.Input(B, d, F, u, a, b, c, x, y, z, s)
1038+ }
1039+ return step
1040+}
1041+func (cl *CommandList) Step(facing int32, ai, hitpause bool,
1042+ buftime int32) {
1043+ if cl.Buffer != nil {
1044+ for i := range cl.Commands {
1045+ for j := range cl.Commands[i] {
1046+ cl.Commands[i][j].Step(cl.Buffer, ai, hitpause, buftime)
1047+ }
1048+ }
1049+ }
9711050 }
9721051 func (cl *CommandList) BufReset() {
9731052 if cl.Buffer != nil {
@@ -988,3 +1067,24 @@ func (cl *CommandList) Add(c Command) {
9881067 cl.Commands[i] = append(cl.Commands[i], c)
9891068 cl.Names[c.name] = i
9901069 }
1070+func (cl *CommandList) At(i int) []Command {
1071+ if i < 0 || i >= len(cl.Commands) {
1072+ return []Command{}
1073+ }
1074+ return cl.Commands[i]
1075+}
1076+func (cl *CommandList) Get(name string) []Command {
1077+ i, ok := cl.Names[name]
1078+ if !ok {
1079+ return []Command{}
1080+ }
1081+ return cl.At(i)
1082+}
1083+func (cl *CommandList) GetState(name string) bool {
1084+ for _, c := range cl.Get(name) {
1085+ if c.curbuftime > 0 {
1086+ return true
1087+ }
1088+ }
1089+ return false
1090+}
--- a/src/main.go
+++ b/src/main.go
@@ -1,6 +1,7 @@
11 package main
22
33 import (
4+ "fmt"
45 "github.com/go-gl/glfw/v3.2/glfw"
56 "github.com/yuin/gopher-lua"
67 "runtime"
@@ -15,6 +16,10 @@ func chk(err error) {
1516 panic(err)
1617 }
1718 }
19+func unimplemented() {
20+ _, fn, line, _ := runtime.Caller(1)
21+ panic(Error(fmt.Sprintf("%v:%v: unimplemented", fn, line)))
22+}
1823 func main() {
1924 chk(glfw.Init())
2025 defer glfw.Terminate()
--- a/src/script.go
+++ b/src/script.go
@@ -73,7 +73,7 @@ func scriptCommonInit(l *lua.LState) {
7373 return 1
7474 })
7575 luaRegister(l, "commandNew", func(l *lua.LState) int {
76- l.Push(newUserData(l, NewCommandList()))
76+ l.Push(newUserData(l, NewCommandList(&CommandBuffer{})))
7777 return 1
7878 })
7979 luaRegister(l, "commandAdd", func(l *lua.LState) int {
@@ -88,6 +88,24 @@ func scriptCommonInit(l *lua.LState) {
8888 cl.Add(*c)
8989 return 0
9090 })
91+ luaRegister(l, "commandGetState", func(l *lua.LState) int {
92+ cl, ok := toUserData(l, 1).(*CommandList)
93+ if !ok {
94+ userDataError(l, 1, cl)
95+ }
96+ l.Push(lua.LBool(cl.GetState(strArg(l, 2))))
97+ return 1
98+ })
99+ luaRegister(l, "commandInput", func(l *lua.LState) int {
100+ cl, ok := toUserData(l, 1).(*CommandList)
101+ if !ok {
102+ userDataError(l, 1, cl)
103+ }
104+ if cl.Input(int32(numArg(l, 2))-1, 1) {
105+ cl.Step(1, false, false, 0)
106+ }
107+ return 0
108+ })
91109 luaRegister(l, "commandBufReset", func(l *lua.LState) int {
92110 cl, ok := toUserData(l, 1).(*CommandList)
93111 if !ok {
@@ -356,7 +374,7 @@ func systemScriptInit(l *lua.LState) {
356374 return 0
357375 })
358376 luaRegister(l, "setStage", func(*lua.LState) int {
359- l.Push(lua.LNumber(sys.sel.setStageNo(int(numArg(l, 1)))))
377+ l.Push(lua.LNumber(sys.sel.SetStageNo(int(numArg(l, 1)))))
360378 return 1
361379 })
362380 luaRegister(l, "refresh", func(*lua.LState) int {
@@ -418,4 +436,13 @@ func systemScriptInit(l *lua.LState) {
418436 sys.resetRemapInput()
419437 return 0
420438 })
439+ luaRegister(l, "loadStart", func(l *lua.LState) int {
440+ sys.loadStart()
441+ return 0
442+ })
443+ luaRegister(l, "selectStart", func(l *lua.LState) int {
444+ sys.sel.ClearSelected()
445+ sys.loadStart()
446+ return 0
447+ })
421448 }
--- a/src/system.go
+++ b/src/system.go
@@ -17,8 +17,8 @@ var sys = System{
1717 gameWidth: 320, gameHeight: 240,
1818 widthScale: 1, heightScale: 1,
1919 brightness: 256,
20- introTime: 0, roundTime: -1,
21- lifeMul: 1, team1VS2Life: 1,
20+ roundTime: -1,
21+ lifeMul: 1, team1VS2Life: 1,
2222 turnsRecoveryRate: 1.0 / 300,
2323 zoomMin: 1, zoomMax: 1, zoomSpeed: 1,
2424 lifebarFontScale: 1,
@@ -29,7 +29,8 @@ var sys = System{
2929 sel: *newSelect(),
3030 match: 1,
3131 inputRemap: [...]int{0, 1, 2, 3, 4, 5, 6, 7},
32- listenPort: "7500"}
32+ listenPort: "7500",
33+ loader: *newLoader()}
3334
3435 type System struct {
3536 randseed int32
@@ -58,7 +59,7 @@ type System struct {
5859 sel Select
5960 netInput *NetInput
6061 fileInput *FileInput
61- aiInput []AiInput
62+ aiInput [MaxSimul * 2]AiInput
6263 keyConfig []*KeyConfig
6364 com [MaxSimul * 2]int32
6465 autolevel bool
@@ -66,6 +67,12 @@ type System struct {
6667 match int32
6768 inputRemap [MaxSimul * 2]int
6869 listenPort string
70+ round int32
71+ wins [2]int32
72+ rexisted [2]int32
73+ loader Loader
74+ chars [MaxSimul * 2][]*Char
75+ cgi [MaxSimul * 2]CharGlobalInfo
6976 }
7077
7178 func (s *System) init(w, h int32) *lua.LState {
@@ -138,6 +145,14 @@ func (s *System) resetRemapInput() {
138145 s.inputRemap[i] = i
139146 }
140147 }
148+func (s *System) loaderReset() {
149+ s.round, s.wins, s.rexisted = 1, [2]int32{0, 0}, [2]int32{0, 0}
150+ s.loader.reset()
151+}
152+func (s *System) loadStart() {
153+ s.loaderReset()
154+ s.loader.runTread()
155+}
141156
142157 type SelectChar struct {
143158 def, name string
@@ -147,27 +162,31 @@ type SelectStage struct {
147162 def, name string
148163 }
149164 type Select struct {
150- columns, rows int32
151- cellsize [2]float32
152- cellscale [2]float32
153- randomspr *Sprite
154- randomscl [2]float32
155- charlist []SelectChar
156- stagelist []SelectStage
157- curStageNo int
165+ columns, rows int32
166+ cellsize [2]float32
167+ cellscale [2]float32
168+ randomspr *Sprite
169+ randomscl [2]float32
170+ charlist []SelectChar
171+ stagelist []SelectStage
172+ curStageNo int
173+ selected [2][][2]int
174+ selectedStageNo int
158175 }
159176
160177 func newSelect() *Select {
161178 return &Select{columns: 5, rows: 2, randomscl: [2]float32{1, 1},
162- cellsize: [2]float32{29, 29}, cellscale: [2]float32{1, 1}}
179+ cellsize: [2]float32{29, 29}, cellscale: [2]float32{1, 1},
180+ selectedStageNo: -1}
163181 }
164-func (s *Select) setStageNo(n int) int {
182+func (s *Select) SetStageNo(n int) int {
165183 s.curStageNo = n % (len(s.stagelist) + 1)
166184 if s.curStageNo < 0 {
167185 s.curStageNo += len(s.stagelist) + 1
168186 }
169187 return s.curStageNo
170188 }
189+func (s *Select) SelectStage(n int) { s.selectedStageNo = n }
171190 func (s *Select) AddCahr(def string) {
172191 s.charlist = append(s.charlist, SelectChar{})
173192 sc := &s.charlist[len(s.charlist)-1]
@@ -260,3 +279,71 @@ func (s *Select) AddStage(def string) error {
260279 }
261280 return nil
262281 }
282+func (s *Select) ClearSelected() {
283+ s.selected = [2][][2]int{[][2]int{}, [][2]int{}}
284+ s.selectedStageNo = -1
285+}
286+
287+type LoaderState int32
288+
289+const (
290+ LS_NotYet LoaderState = iota
291+ LS_Loading
292+ LS_Complete
293+ LS_Error
294+ LS_Cancel
295+)
296+
297+type Loader struct {
298+ state LoaderState
299+ loadExit chan LoaderState
300+ compiler *Compiler
301+ err error
302+}
303+
304+func newLoader() *Loader {
305+ return &Loader{state: LS_NotYet, loadExit: make(chan LoaderState, 1)}
306+}
307+func (l *Loader) load() {
308+ defer func() { l.loadExit <- l.state }()
309+ charDone, codeDone, stageDone := make([]bool, len(sys.chars)), false, false
310+ allCharDone := func() bool {
311+ for _, b := range charDone {
312+ if !b {
313+ return false
314+ }
315+ }
316+ return true
317+ }
318+ for !codeDone || !stageDone || !allCharDone() {
319+ unimplemented()
320+ if sys.gameEnd {
321+ l.state = LS_Cancel
322+ }
323+ if l.state == LS_Cancel {
324+ return
325+ }
326+ }
327+ l.state = LS_Complete
328+}
329+func (l *Loader) reset() {
330+ if l.state != LS_NotYet {
331+ l.state = LS_Cancel
332+ <-l.loadExit
333+ l.state = LS_NotYet
334+ }
335+ l.compiler, l.err = nil, nil
336+ for i := range sys.cgi {
337+ if sys.rexisted[i&1] == 0 {
338+ sys.cgi[i].drawpalno = -1
339+ }
340+ }
341+}
342+func (l *Loader) runTread() bool {
343+ if l.state != LS_NotYet {
344+ return false
345+ }
346+ l.state = LS_Loading
347+ go l.load()
348+ return true
349+}