Skip to content

Commit

Permalink
Merge pull request #44 from neophob/feature/supportPause
Browse files Browse the repository at this point in the history
Feature/support pause
  • Loading branch information
neophob authored May 12, 2020
2 parents a10d2ad + 6a868f5 commit 03a2832
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 24 deletions.
2 changes: 1 addition & 1 deletion anotherworld/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (assets StaticGameAssets) LoadEntryFromBank(index int) []uint8 {
//LoadResource return a resource
func (assets *StaticGameAssets) LoadResource(id int) {
if len(assets.LoadedResources[id]) > 0 {
logger.Info("resource [%d] already loaded", id)
logger.Debug("resource [%d] already loaded", id)
return
}
assets.LoadedResources[id] = assets.LoadEntryFromBank(id)
Expand Down
2 changes: 1 addition & 1 deletion anotherworld/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (video *Video) PlaySound(resNum, freq, vol, channel int) {
return
}

logger.Info("playSound resNum %d", resNum)
logger.Debug("playSound resNum %d", resNum)
video.Hal.PlaySound(resNum, freq, vol, channel)
}

Expand Down
4 changes: 4 additions & 0 deletions wasm/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func (engine *Engine) initGame(memlist []byte, bankFilesMap map[int][]byte) {
}

func (engine *Engine) mainLoop() {
if engine.keyMap[anotherworld.KeyPause] == true {
logger.Debug("PAUSED")
return
}
engine.app.MainLoop(engine.counter)
engine.counter += 1
}
Expand Down
33 changes: 33 additions & 0 deletions wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
text-align: center;
font-family: "Monaco", "Andale Mono", "Lucida Console", "FreeMono", monospace;
}
.badge {
color: #fff;
background-color: #000;
display: inline-block;
padding: .25em .3em;
line-height: 1;
border-radius: .25rem;
font-weight: 700;
text-decoration: none;
}
#gotherworld {
width: 960px;
height: 600px;
Expand All @@ -32,6 +42,29 @@
<h1>
<img src="logo.png" alt="Gother World">
</h1>
<p>
<a class="badge" href="#" onclick="shutdown()">STOP</a>
<a class="badge" href="#" onclick="handleKeyEvent('l', 76, 'keydown'); setTimeout(() => handleKeyEvent('l', 76, 'keyup'), 50);">LOAD</a>
<a class="badge" href="#" onclick="handleKeyEvent('s', 83, 'keydown'); setTimeout(() => handleKeyEvent('s', 83, 'keyup'), 50);">SAVE</a>

// Game Part
<a class="badge" href="?gamePart=0">0</a>
<a class="badge" href="?gamePart=1">1</a>
<a class="badge" href="?gamePart=2">2</a>
<a class="badge" href="?gamePart=3">3</a>
<a class="badge" href="?gamePart=4">4</a>
<a class="badge" href="?gamePart=5">5</a>
<a class="badge" href="?gamePart=6">6</a>
<a class="badge" href="?gamePart=7">7</a>

// LOG
<a class="badge" href="#" onclick="setLogLevel(0)">DEBUG</a>
<a class="badge" href="#" onclick="setLogLevel(1)">INFO</a>
<a class="badge" href="#" onclick="setLogLevel(2)">WARN</a>
<a class="badge" href="#" onclick="setLogLevel(3)">ERROR</a>
<a class="badge" href="#" onclick="setLogLevel(4)">FATAL</a>

</p>
<p>
<canvas id="gotherworld" width="320" height="200"/>
</p>
Expand Down
3 changes: 1 addition & 2 deletions wasm/js-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func startGameFromPartWrapper(engine *Engine, inputs []js.Value) {
js.Global().Call("requestAnimationFrame", renderFrame)
}

//TODO move to hal-wasm
func handleKeyEventWrapper(engine *Engine, inputs []js.Value) {
if len(inputs) != 3 {
logger.Error("Ignoring incomplete key event", inputs)
Expand Down Expand Up @@ -109,7 +108,7 @@ func parseGamePartOffset(gamePartOffset js.Value) int {
}
parsedOffset := gamePartOffset.Int()
if parsedOffset >= minStartPartOffset && parsedOffset <= maxStartPartOffset {
logger.Info("Parsed gamePartOffset %v", gamePartOffset)
logger.Info("Parsed gamePartOffset %d", parsedOffset)
return parsedOffset
}
logger.Error("Out of range gamePart offset %v, using default.", parsedOffset)
Expand Down
21 changes: 2 additions & 19 deletions wasm/js-canvas.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"syscall/js"

"github.com/neophob/ganother-world/anotherworld"
Expand All @@ -20,26 +19,10 @@ func GetCanvas(domElementId string) Canvas {
}
}

func (c Canvas) SetColor(color anotherworld.Color) {
c.context2d.Set("fillStyle", fmt.Sprintf("rgb(%d, %d, %d)", color.R, color.G, color.B))
}

func (c Canvas) DrawPoint(x, y int) {
c.context2d.Call("fillRect", x, y, 1, 1)
}

func (c Canvas) fillStyle(style string) {
c.context2d.Set("fillStyle", style)
}

func (c Canvas) fillRect(x, y, width, height int) {
c.context2d.Call("fillRect", x, y, width, height)
}

func (c Canvas) blitIt(buffer [anotherworld.WIDTH * anotherworld.HEIGHT]int) {
var interfaceSlice []interface{} = make([]interface{}, len(buffer))
for i, d := range buffer {
interfaceSlice[i] = d
for index, pixelData := range buffer {
interfaceSlice[index] = pixelData
}
c.context2d.Call("blit", interfaceSlice)
}
3 changes: 2 additions & 1 deletion wasm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
)

func init() {
logger.SetLogLevel(logger.LEVEL_INFO)
logger.DisableColors()
logger.SetLogLevel(logger.LEVEL_INFO)
logger.Info("WASM Gother-World initializing...")
}

func main() {
engine := buildEngine()
RegisterCallbacks(&engine)
logger.Info("Registered Callbacks")
<-engine.shutdownChannel
}

0 comments on commit 03a2832

Please sign in to comment.