Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support pause #44

Merged
merged 10 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

less spam

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 {
neophob marked this conversation as resolved.
Show resolved Hide resolved
logger.Debug("PAUSED")
return
}
engine.app.MainLoop(engine.counter)
engine.counter += 1
}
Expand Down
32 changes: 32 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,28 @@
<h1>
<img src="logo.png" alt="Gother World">
</h1>
<p>
Load Game Part
<a id="badge" href="?gamePart=0">0</a>
neophob marked this conversation as resolved.
Show resolved Hide resolved
<a id="badge" href="?gamePart=1">1</a>
<a id="badge" href="?gamePart=2">2</a>
<a id="badge" href="?gamePart=3">3</a>
<a id="badge" href="?gamePart=4">4</a>
<a id="badge" href="?gamePart=5">5</a>
<a id="badge" href="?gamePart=6">6</a>
<a id="badge" href="?gamePart=7">7</a>

//
<a id="badge" href="#" onclick="shutdown()">STOP</a>

// LOG
<a id="badge" href="#" onclick="setLogLevel(0)">DEBUG</a>
<a id="badge" href="#" onclick="setLogLevel(1)">INFO</a>
<a id="badge" href="#" onclick="setLogLevel(2)">WARN</a>
<a id="badge" href="#" onclick="setLogLevel(3)">ERROR</a>
<a id="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
17 changes: 0 additions & 17 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,22 +19,6 @@ 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)
}

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

red diff is a good diff!

func (c Canvas) blitIt(buffer [anotherworld.WIDTH * anotherworld.HEIGHT]int) {
var interfaceSlice []interface{} = make([]interface{}, len(buffer))
for i, d := range buffer {
Expand Down
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
}