Skip to content

Commit 634cc45

Browse files
authored
Merge pull request #820 from JiepengTan/pr_merge_next_frame
Feat: add nextFrame
2 parents aa653cd + 8cd5878 commit 634cc45

13 files changed

Lines changed: 53 additions & 0 deletions

File tree

cmd/gox/template/platform/web/game.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ class GameApp {
201201
funPtr()
202202
}
203203
}
204+
205+
stepNextFrame() {
206+
let funPtr = this.game.rtenv["_gdspx_ext_next_frame"]
207+
if(funPtr != null){
208+
funPtr()
209+
}
210+
}
204211
//------------------ misc ------------------
205212
onProgress(value) {
206213
if (this.config.onProgress != null) {

cmd/gox/template/platform/web/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<button id="screenshotBtn">Screenshot</button>
7171
<button id="pauseGameBtn">Pause</button>
7272
<button id="resumeGameBtn">Resume</button>
73+
<button id="stepNextFrameBtn">NextFrame</button>
7374
<progress id="progress-bar" value="0" max="1" style="display: none;"></progress>
7475
<div id="tabs">
7576
<div id="tab-loader">
@@ -115,6 +116,8 @@ <h2>Test Animation</h2>
115116
document.getElementById('screenshotBtn').addEventListener('click', takeScreenshot);
116117
document.getElementById('pauseGameBtn').addEventListener('click', pauseGame);
117118
document.getElementById('resumeGameBtn').addEventListener('click', resumeGame);
119+
document.getElementById('stepNextFrameBtn').addEventListener('click', stepNextFrame);
120+
118121
runnerWindow = document.getElementById('runnerFrame').contentWindow;
119122
function onProgress(value) {
120123
document.getElementById('progress-bar').value = value;
@@ -160,6 +163,14 @@ <h2>Test Animation</h2>
160163
console.warn("Resume function not available");
161164
}
162165
}
166+
167+
async function stepNextFrame() {
168+
if (runnerWindow.stepNextFrame) {
169+
runnerWindow.stepNextFrame();
170+
} else {
171+
console.warn("StepNextFrame function not available");
172+
}
173+
}
163174
async function takeScreenshot() {
164175
try {
165176
const blob = await runnerWindow.getScreenshot()

cmd/gox/template/platform/web/runner.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@
241241
gameApp.resume();
242242
}
243243

244+
window.stepNextFrame = () => {
245+
if (gameApp == null) {
246+
console.error("gameApp is null, should call startGame first")
247+
return
248+
}
249+
gameApp.stepNextFrame();
250+
}
251+
244252
// Inform the parent window that the runner is ready (methods on the window object are callable)
245253
window.dispatchEvent(new Event('runnerReady'));
246254
</script>

internal/enginewrap/sync.gen.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ func (pself *extMgrImpl) IsPaused() bool {
264264
})
265265
return _ret1
266266
}
267+
func (pself *extMgrImpl) NextFrame() {
268+
callInMainThread(func() {
269+
gdx.ExtMgr.NextFrame()
270+
})
271+
}
267272
func (pself *extMgrImpl) DestroyAllPens() {
268273
callInMainThread(func() {
269274
gdx.ExtMgr.DestroyAllPens()

internal/enginewrap/sync_pure.gen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ func (pself *extMgrImpl) IsPaused() bool {
164164
var _ret1 bool
165165
return _ret1
166166
}
167+
func (pself *extMgrImpl) NextFrame() {}
167168
func (pself *extMgrImpl) DestroyAllPens() {}
168169
func (pself *extMgrImpl) CreatePen() gdx.Object {
169170
var _ret1 gdx.Object

pkg/gdspx/internal/ffi/ffi.gen.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type GDExtensionInterface struct {
4646
SpxExtPause GDExtensionSpxExtPause
4747
SpxExtResume GDExtensionSpxExtResume
4848
SpxExtIsPaused GDExtensionSpxExtIsPaused
49+
SpxExtNextFrame GDExtensionSpxExtNextFrame
4950
SpxExtDestroyAllPens GDExtensionSpxExtDestroyAllPens
5051
SpxExtCreatePen GDExtensionSpxExtCreatePen
5152
SpxExtDestroyPen GDExtensionSpxExtDestroyPen
@@ -280,6 +281,7 @@ func (x *GDExtensionInterface) loadProcAddresses() {
280281
x.SpxExtPause = (GDExtensionSpxExtPause)(dlsymGD("spx_ext_pause"))
281282
x.SpxExtResume = (GDExtensionSpxExtResume)(dlsymGD("spx_ext_resume"))
282283
x.SpxExtIsPaused = (GDExtensionSpxExtIsPaused)(dlsymGD("spx_ext_is_paused"))
284+
x.SpxExtNextFrame = (GDExtensionSpxExtNextFrame)(dlsymGD("spx_ext_next_frame"))
283285
x.SpxExtDestroyAllPens = (GDExtensionSpxExtDestroyAllPens)(dlsymGD("spx_ext_destroy_all_pens"))
284286
x.SpxExtCreatePen = (GDExtensionSpxExtCreatePen)(dlsymGD("spx_ext_create_pen"))
285287
x.SpxExtDestroyPen = (GDExtensionSpxExtDestroyPen)(dlsymGD("spx_ext_destroy_pen"))

pkg/gdspx/internal/ffi/ffi_wrapper.gen.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ type GDExtensionSpxExtOnRuntimePanic C.GDExtensionSpxExtOnRuntimePanic
101101
type GDExtensionSpxExtPause C.GDExtensionSpxExtPause
102102
type GDExtensionSpxExtResume C.GDExtensionSpxExtResume
103103
type GDExtensionSpxExtIsPaused C.GDExtensionSpxExtIsPaused
104+
type GDExtensionSpxExtNextFrame C.GDExtensionSpxExtNextFrame
104105
type GDExtensionSpxExtDestroyAllPens C.GDExtensionSpxExtDestroyAllPens
105106
type GDExtensionSpxExtCreatePen C.GDExtensionSpxExtCreatePen
106107
type GDExtensionSpxExtDestroyPen C.GDExtensionSpxExtDestroyPen
@@ -550,6 +551,11 @@ func CallExtIsPaused() GdBool {
550551
C.cgo_callfn_GDExtensionSpxExtIsPaused(arg0, &ret_val)
551552
return (GdBool)(ret_val)
552553
}
554+
func CallExtNextFrame() {
555+
arg0 := (C.GDExtensionSpxExtNextFrame)(api.SpxExtNextFrame)
556+
557+
C.cgo_callfn_GDExtensionSpxExtNextFrame(arg0)
558+
}
553559
func CallExtDestroyAllPens() {
554560
arg0 := (C.GDExtensionSpxExtDestroyAllPens)(api.SpxExtDestroyAllPens)
555561

pkg/gdspx/internal/ffi/ffi_wrapper.gen.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ void cgo_callfn_GDExtensionSpxExtResume(const GDExtensionSpxExtResume fn) {
9696
void cgo_callfn_GDExtensionSpxExtIsPaused(const GDExtensionSpxExtIsPaused fn, GdBool* ret_val) {
9797
fn(ret_val);
9898
}
99+
void cgo_callfn_GDExtensionSpxExtNextFrame(const GDExtensionSpxExtNextFrame fn) {
100+
fn();
101+
}
99102
void cgo_callfn_GDExtensionSpxExtDestroyAllPens(const GDExtensionSpxExtDestroyAllPens fn) {
100103
fn();
101104
}

pkg/gdspx/internal/ffi/gdextension_spx_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ typedef void (*GDExtensionSpxExtOnRuntimePanic)(GdString msg);
228228
typedef void (*GDExtensionSpxExtPause)();
229229
typedef void (*GDExtensionSpxExtResume)();
230230
typedef void (*GDExtensionSpxExtIsPaused)(GdBool* ret_value);
231+
typedef void (*GDExtensionSpxExtNextFrame)();
231232
typedef void (*GDExtensionSpxExtDestroyAllPens)();
232233
typedef void (*GDExtensionSpxExtCreatePen)(GdObj* ret_value);
233234
typedef void (*GDExtensionSpxExtDestroyPen)(GdObj obj);

pkg/gdspx/internal/webffi/ffi.gen.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type GDExtensionInterface struct {
5050
SpxExtPause js.Value
5151
SpxExtResume js.Value
5252
SpxExtIsPaused js.Value
53+
SpxExtNextFrame js.Value
5354
SpxExtDestroyAllPens js.Value
5455
SpxExtCreatePen js.Value
5556
SpxExtDestroyPen js.Value
@@ -284,6 +285,7 @@ func (x *GDExtensionInterface) loadProcAddresses() {
284285
x.SpxExtPause = dlsymGD("gdspx_ext_pause")
285286
x.SpxExtResume = dlsymGD("gdspx_ext_resume")
286287
x.SpxExtIsPaused = dlsymGD("gdspx_ext_is_paused")
288+
x.SpxExtNextFrame = dlsymGD("gdspx_ext_next_frame")
287289
x.SpxExtDestroyAllPens = dlsymGD("gdspx_ext_destroy_all_pens")
288290
x.SpxExtCreatePen = dlsymGD("gdspx_ext_create_pen")
289291
x.SpxExtDestroyPen = dlsymGD("gdspx_ext_destroy_pen")

0 commit comments

Comments
 (0)