Go で書き直した Ikemen
Revision | da016619bdedf5fdfbedd6769261c9a6718c0714 (tree) |
---|---|
Zeit | 2016-12-02 23:59:36 |
Autor | SUEHIRO <supersuehiro@user...> |
Commiter | SUEHIRO |
エラーになるところを書いていく
@@ -1,4 +1,7 @@ | ||
1 | 1 | package main |
2 | 2 | |
3 | -type CharGlobalInfo struct{ drawpalno int32 } | |
3 | +type CharGlobalInfo struct { | |
4 | + drawpalno int32 | |
5 | + wakewakaLength int | |
6 | +} | |
4 | 7 | type Char struct{} |
@@ -1,3 +1,4 @@ | ||
1 | 1 | package main |
2 | 2 | |
3 | +type ByteCode struct{} | |
3 | 4 | type Compiler struct{} |
@@ -70,12 +70,14 @@ const ( | ||
70 | 70 | var keySatate = make(map[glfw.Key]bool) |
71 | 71 | |
72 | 72 | func keyCallback(_ *glfw.Window, key glfw.Key, _ int, |
73 | - action glfw.Action, _ glfw.ModifierKey) { | |
73 | + action glfw.Action, mk glfw.ModifierKey) { | |
74 | 74 | switch action { |
75 | 75 | case glfw.Release: |
76 | 76 | keySatate[key] = false |
77 | 77 | case glfw.Press: |
78 | 78 | keySatate[key] = true |
79 | + sys.esc = sys.esc || | |
80 | + key == glfw.KeyEscape && mk&(glfw.ModControl|glfw.ModAlt) == 0 | |
79 | 81 | } |
80 | 82 | } |
81 | 83 |
@@ -130,6 +130,10 @@ func scriptCommonInit(l *lua.LState) { | ||
130 | 130 | sys.bgm.Open(strArg(l, 1)) |
131 | 131 | return 0 |
132 | 132 | }) |
133 | + luaRegister(l, "esc", func(l *lua.LState) int { | |
134 | + l.Push(lua.LBool(sys.esc)) | |
135 | + return 1 | |
136 | + }) | |
133 | 137 | luaRegister(l, "setRoundTime", func(l *lua.LState) int { |
134 | 138 | sys.roundTime = int32(numArg(l, 1)) |
135 | 139 | return 0 |
@@ -5,6 +5,7 @@ import ( | ||
5 | 5 | "github.com/go-gl/glfw/v3.2/glfw" |
6 | 6 | "github.com/timshannon/go-openal/openal" |
7 | 7 | "github.com/yuin/gopher-lua" |
8 | + "runtime" | |
8 | 9 | "strings" |
9 | 10 | "time" |
10 | 11 | ) |
@@ -30,7 +31,17 @@ var sys = System{ | ||
30 | 31 | match: 1, |
31 | 32 | inputRemap: [...]int{0, 1, 2, 3, 4, 5, 6, 7}, |
32 | 33 | listenPort: "7500", |
33 | - loader: *newLoader()} | |
34 | + loader: *newLoader(), | |
35 | + numSimul: [2]int{2, 2}, | |
36 | + numTurns: [2]int{2, 2}} | |
37 | + | |
38 | +type TeamMode int32 | |
39 | + | |
40 | +const ( | |
41 | + TM_Single TeamMode = iota | |
42 | + TM_Simul | |
43 | + TM_Turns | |
44 | +) | |
34 | 45 | |
35 | 46 | type System struct { |
36 | 47 | randseed int32 |
@@ -73,6 +84,10 @@ type System struct { | ||
73 | 84 | loader Loader |
74 | 85 | chars [MaxSimul * 2][]*Char |
75 | 86 | cgi [MaxSimul * 2]CharGlobalInfo |
87 | + tmode [2]TeamMode | |
88 | + numSimul [2]int | |
89 | + numTurns [2]int | |
90 | + esc bool | |
76 | 91 | } |
77 | 92 | |
78 | 93 | func (s *System) init(w, h int32) *lua.LState { |
@@ -133,6 +148,7 @@ func (s *System) await(fps int) { | ||
133 | 148 | } |
134 | 149 | s.frameSkip = true |
135 | 150 | } |
151 | + s.esc = false | |
136 | 152 | glfw.PollEvents() |
137 | 153 | s.gameEnd = s.window.ShouldClose() |
138 | 154 | if !s.frameSkip { |
@@ -280,7 +296,7 @@ func (s *Select) AddStage(def string) error { | ||
280 | 296 | return nil |
281 | 297 | } |
282 | 298 | func (s *Select) ClearSelected() { |
283 | - s.selected = [2][][2]int{[][2]int{}, [][2]int{}} | |
299 | + s.selected = [2][][2]int{} | |
284 | 300 | s.selectedStageNo = -1 |
285 | 301 | } |
286 | 302 |
@@ -299,11 +315,44 @@ type Loader struct { | ||
299 | 315 | loadExit chan LoaderState |
300 | 316 | compiler *Compiler |
301 | 317 | err error |
318 | + code [MaxSimul * 2]*ByteCode | |
302 | 319 | } |
303 | 320 | |
304 | 321 | func newLoader() *Loader { |
305 | 322 | return &Loader{state: LS_NotYet, loadExit: make(chan LoaderState, 1)} |
306 | 323 | } |
324 | +func (l *Loader) loadChar(pn int) int { | |
325 | + nsel := len(sys.sel.selected[pn&1]) | |
326 | + if sys.tmode[pn&1] == TM_Simul { | |
327 | + if pn>>1 >= sys.numSimul[pn&1] { | |
328 | + l.code[pn] = nil | |
329 | + sys.chars[pn] = nil | |
330 | + return 1 | |
331 | + } | |
332 | + } else if pn >= 2 { | |
333 | + return 0 | |
334 | + } | |
335 | + if sys.tmode[pn&1] == TM_Turns && nsel < sys.numTurns[pn&1] { | |
336 | + return 0 | |
337 | + } | |
338 | + memberNo := pn >> 1 | |
339 | + if sys.tmode[pn&1] == TM_Turns { | |
340 | + memberNo = int(sys.wins[^pn&1]) | |
341 | + } | |
342 | + if nsel <= memberNo { | |
343 | + return 0 | |
344 | + } | |
345 | + unimplemented() | |
346 | + return 1 | |
347 | +} | |
348 | +func (l *Loader) loadStage() bool { | |
349 | + unimplemented() | |
350 | + return true | |
351 | +} | |
352 | +func (l *Loader) stateCompile() bool { | |
353 | + unimplemented() | |
354 | + return true | |
355 | +} | |
307 | 356 | func (l *Loader) load() { |
308 | 357 | defer func() { l.loadExit <- l.state }() |
309 | 358 | charDone, codeDone, stageDone := make([]bool, len(sys.chars)), false, false |
@@ -316,7 +365,43 @@ func (l *Loader) load() { | ||
316 | 365 | return true |
317 | 366 | } |
318 | 367 | for !codeDone || !stageDone || !allCharDone() { |
319 | - unimplemented() | |
368 | + runtime.LockOSThread() | |
369 | + for i, b := range charDone { | |
370 | + if !b { | |
371 | + result := l.loadChar(i) | |
372 | + if result > 0 { | |
373 | + charDone[i] = true | |
374 | + } else if result < 0 { | |
375 | + l.state = LS_Error | |
376 | + return | |
377 | + } | |
378 | + } | |
379 | + } | |
380 | + for i := 0; i < 2; i++ { | |
381 | + if !charDone[i+2] && len(sys.sel.selected[i]) > 0 && | |
382 | + sys.tmode[i] != TM_Simul { | |
383 | + for j := i + 2; j < len(sys.chars); j += 2 { | |
384 | + sys.chars[j], l.code[j], charDone[j] = nil, nil, true | |
385 | + sys.cgi[j].wakewakaLength = 0 | |
386 | + } | |
387 | + } | |
388 | + } | |
389 | + if !stageDone && sys.sel.selectedStageNo >= 0 { | |
390 | + if !l.loadStage() { | |
391 | + l.state = LS_Error | |
392 | + return | |
393 | + } | |
394 | + stageDone = true | |
395 | + } | |
396 | + runtime.UnlockOSThread() | |
397 | + if !codeDone && allCharDone() { | |
398 | + if !l.stateCompile() { | |
399 | + l.state = LS_Error | |
400 | + return | |
401 | + } | |
402 | + codeDone = true | |
403 | + } | |
404 | + time.Sleep(10 * time.Millisecond) | |
320 | 405 | if sys.gameEnd { |
321 | 406 | l.state = LS_Cancel |
322 | 407 | } |