-
Notifications
You must be signed in to change notification settings - Fork 33
Move coord convert from c++ => go (invert y) #973
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,297 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package enginewrap | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // This file provides coordinate system adapters for all managers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SPX uses Y-axis pointing up, while Godot uses Y-axis pointing down. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // All coordinate conversions are handled here by overriding manager methods. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| . "github.com/goplus/spbase/mathf" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gdx "github.com/goplus/spx/v2/pkg/gdspx/pkg/engine" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // flipY flips the Y coordinate to convert between SPX and Godot coordinate systems | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func flipY(pos Vec2) Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Vec2{X: pos.X, Y: -pos.Y} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Sprite Coordinate Adapters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) SetPosition(pos Vec2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.Sprite.SetPosition(flipY(pos)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) GetPosition() Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.Sprite.GetPosition()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) SetChildPosition(path string, pos Vec2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.Sprite.SetChildPosition(path, flipY(pos)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) GetChildPosition(path string) Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.Sprite.GetChildPosition(path)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) SetVelocity(velocity Vec2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.Sprite.SetVelocity(flipY(velocity)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) GetVelocity() Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.Sprite.GetVelocity()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) SetPivot(pivot Vec2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.Sprite.SetPivot(flipY(pivot)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) GetPivot() Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.Sprite.GetPivot()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) CheckCollisionWithPoint(point Vec2, isTrigger bool) bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return pself.Sprite.CheckCollisionWithPoint(flipY(point), isTrigger) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // extra wrap functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) GetLastMotion() Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.Sprite.GetLastMotion()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) GetPositionDelta() Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.Sprite.GetPositionDelta()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) GetFloorNormal() Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.Sprite.GetFloorNormal()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) GetWallNormal() Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.Sprite.GetWallNormal()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) GetRealVelocity() Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.Sprite.GetRealVelocity()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) SetAnimOffset(offset Vec2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.Sprite.SetAnimOffset(flipY(offset)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *Sprite) GetAnimOffset() Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.Sprite.GetAnimOffset()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SpriteMgr Coordinate Adapters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) SetPosition(obj gdx.Object, pos Vec2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.spriteMgrImpl.SetPosition(obj, flipY(pos)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) GetPosition(obj gdx.Object) Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.spriteMgrImpl.GetPosition(obj)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) SetChildPosition(obj gdx.Object, path string, pos Vec2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.spriteMgrImpl.SetChildPosition(obj, path, flipY(pos)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) GetChildPosition(obj gdx.Object, path string) Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.spriteMgrImpl.GetChildPosition(obj, path)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) SetVelocity(obj gdx.Object, velocity Vec2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.spriteMgrImpl.SetVelocity(obj, flipY(velocity)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) GetVelocity(obj gdx.Object) Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.spriteMgrImpl.GetVelocity(obj)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) SetPivot(obj gdx.Object, pivot Vec2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.spriteMgrImpl.SetPivot(obj, flipY(pivot)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) GetPivot(obj gdx.Object) Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.spriteMgrImpl.GetPivot(obj)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) CheckCollisionWithPoint(obj gdx.Object, point Vec2, isTrigger bool) bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return pself.spriteMgrImpl.CheckCollisionWithPoint(obj, flipY(point), isTrigger) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // extra wrap functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) GetLastMotion(obj gdx.Object) Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.spriteMgrImpl.GetLastMotion(obj)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) GetPositionDelta(obj gdx.Object) Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.spriteMgrImpl.GetPositionDelta(obj)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) GetFloorNormal(obj gdx.Object) Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.spriteMgrImpl.GetFloorNormal(obj)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) GetWallNormal(obj gdx.Object) Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.spriteMgrImpl.GetWallNormal(obj)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) GetRealVelocity(obj gdx.Object) Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.spriteMgrImpl.GetRealVelocity(obj)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) SetAnimOffset(obj gdx.Object, offset Vec2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.spriteMgrImpl.SetAnimOffset(obj, flipY(offset)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) GetAnimOffset(obj gdx.Object) Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.spriteMgrImpl.GetAnimOffset(obj)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) AddImpulse(obj gdx.Object, impulse Vec2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.spriteMgrImpl.AddImpulse(obj, flipY(impulse)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) GetGravity(obj gdx.Object) float64 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing Documentation Gravity negation requires explanation. Unlike vectors, gravity is a scalar, so the sign flip is conceptually different. Add a comment: // GetGravity returns gravity with inverted sign to match SPX's upward Y-axis convention.
// In SPX, positive Y is up, so positive gravity means upward force. In Godot, positive
// Y is down, so positive gravity means downward force. The sign inversion maintains
// consistent physical behavior across both coordinate systems.
func (pself *SpriteMgrImpl) GetGravity(obj gdx.Object) float64 {
return -pself.spriteMgrImpl.GetGravity(obj)
} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return -pself.spriteMgrImpl.GetGravity(obj) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SpriteMgrImpl) SetGravity(obj gdx.Object, gravity float64) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.spriteMgrImpl.SetGravity(obj, -gravity) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SceneMgr Coordinate Adapters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SceneMgrImpl) CreateRenderSprite(texturePath string, pos Vec2, degree float64, scale Vec2, zindex int64, pivot Vec2) gdx.Object { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return pself.sceneMgrImpl.CreateRenderSprite(texturePath, flipY(pos), degree, scale, zindex, flipY(pivot)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *SceneMgrImpl) CreateStaticSprite(texturePath string, pos Vec2, degree float64, scale Vec2, zindex int64, pivot Vec2, colliderType int64, colliderPivot Vec2, colliderParams gdx.Array) gdx.Object { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return pself.sceneMgrImpl.CreateStaticSprite(texturePath, flipY(pos), degree, scale, zindex, flipY(pivot), colliderType, flipY(colliderPivot), colliderParams) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // PhysicMgr Coordinate Adapters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *PhysicMgrImpl) Raycast(from Vec2, to Vec2, collisionMask int64) gdx.Object { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return pself.physicMgrImpl.Raycast(flipY(from), flipY(to), collisionMask) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // RaycastWithDetails returns array: [collide, sprite_gid, pos.x, pos.y, normal.x, normal.y] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // This conversion should be handled at upper layer due to gdx.Array access limitations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Misleading documentation The comment is confusing. Input coordinates ARE converted here via
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation Issue: Incomplete Comment The comment is accurate that output conversion happens at the upper layer, but should clarify that only INPUT coordinates are converted here. The returned array's Y-coordinates (indices 3 and 5) must be handled by the caller: // RaycastWithDetails returns array: [collide, sprite_gid, pos.x, pos.y, normal.x, normal.y]
// Note: Input coordinates (from, to) are converted here, but the returned array
// Y-coordinates (pos.y at index 3, normal.y at index 5) must be converted by the
// caller due to gdx.Array access limitations. See physic.go:tryRaycastResult(). |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *PhysicMgrImpl) RaycastWithDetails(from Vec2, to Vec2, ignoreSprites gdx.Array, collisionMask int64, collideWithAreas bool, collideWithBodies bool) gdx.Array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return pself.physicMgrImpl.RaycastWithDetails(flipY(from), flipY(to), ignoreSprites, collisionMask, collideWithAreas, collideWithBodies) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+189
to
+191
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency with
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *PhysicMgrImpl) CheckCollisionRect(pos Vec2, size Vec2, collisionMask int64) gdx.Array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return pself.physicMgrImpl.CheckCollisionRect(flipY(pos), size, collisionMask) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *PhysicMgrImpl) CheckCollisionCircle(pos Vec2, radius float64, collisionMask int64) gdx.Array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return pself.physicMgrImpl.CheckCollisionCircle(flipY(pos), radius, collisionMask) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // InputMgr Coordinate Adapters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *InputMgrImpl) SyncGetGlobalMousePos() Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(gdx.InputMgr.GetGlobalMousePos()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *InputMgrImpl) GetGlobalMousePos() Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.inputMgrImpl.GetGlobalMousePos()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // CameraMgr Coordinate Adapters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *CameraMgrImpl) GetCameraPosition() Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.cameraMgrImpl.GetCameraPosition()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *CameraMgrImpl) SetCameraPosition(position Vec2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.cameraMgrImpl.SetCameraPosition(flipY(position)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *CameraMgrImpl) SyncGetCameraPosition() Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(gdx.CameraMgr.GetCameraPosition()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *CameraMgrImpl) SyncSetCameraPosition(position Vec2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gdx.CameraMgr.SetCameraPosition(flipY(position)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // DebugMgr Coordinate Adapters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *DebugMgrImpl) DebugDrawCircle(pos Vec2, radius float64, color Color) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.debugMgrImpl.DebugDrawCircle(flipY(pos), radius, color) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *DebugMgrImpl) DebugDrawRect(pos Vec2, size Vec2, color Color) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.debugMgrImpl.DebugDrawRect(flipY(pos), size, color) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *DebugMgrImpl) DebugDrawLine(from Vec2, to Vec2, color Color) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.debugMgrImpl.DebugDrawLine(flipY(from), flipY(to), color) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TilemapMgr Coordinate Adapters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *TilemapMgrImpl) PlaceTile(pos Vec2, texturePath string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.tilemapMgrImpl.PlaceTile(flipY(pos), texturePath) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *TilemapMgrImpl) PlaceTileWithLayer(pos Vec2, texturePath string, layerIndex int64) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.tilemapMgrImpl.PlaceTileWithLayer(flipY(pos), texturePath, layerIndex) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *TilemapMgrImpl) EraseTile(pos Vec2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.tilemapMgrImpl.EraseTile(flipY(pos)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *TilemapMgrImpl) EraseTileWithLayer(pos Vec2, layerIndex int64) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.tilemapMgrImpl.EraseTileWithLayer(flipY(pos), layerIndex) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *TilemapMgrImpl) GetTile(pos Vec2) string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return pself.tilemapMgrImpl.GetTile(flipY(pos)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *TilemapMgrImpl) GetTileWithLayer(pos Vec2, layerIndex int64) string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return pself.tilemapMgrImpl.GetTileWithLayer(flipY(pos), layerIndex) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *TilemapMgrImpl) SetLayerOffset(index int64, offset Vec2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pself.tilemapMgrImpl.SetLayerOffset(index, flipY(offset)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *TilemapMgrImpl) GetLayerOffset(index int64) Vec2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flipY(pself.tilemapMgrImpl.GetLayerOffset(index)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // NavigationMgr Coordinate Adapters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // FindPath returns array: [x0, y0, x1, y1, x2, y2, ...] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // This conversion should be handled at upper layer due to gdx.Array access limitations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation inaccuracy This comment states "conversion should be handled at upper layer" but the conversion IS done here (lines 163-165). Unlike
Suggested change
Comment on lines
+284
to
+285
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is misleading. The coordinate conversion is handled within this function, not at an upper layer. Please update the comment to accurately describe the function's behavior.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation Issue: Misleading Comment The comment states "This conversion should be handled at upper layer" but the function actually DOES perform output array conversion in lines 293-294. The comment from RaycastWithDetails was likely copied but doesn't apply here. Consider: // FindPath returns array: [x0, y0, x1, y1, x2, y2, ...]
// Both input and output coordinates are converted here.
// Output Y-coordinates (at odd indices) are inverted to convert from Godot to SPX coordinate system. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (pself *NavigationMgrImpl) FindPath(from Vec2, to Vec2, withJump bool) gdx.Array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var arr = pself.navigationMgrImpl.FindPath(flipY(from), flipY(to), withJump) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result := arr.([]float32) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. <!-- codeagent-review-id: pr-973 --> Critical: Type assertion panic risk This unsafe type assertion will panic if
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security/Reliability Issue: Unchecked Type Assertion This unchecked type assertion will panic if the underlying type is not result, ok := arr.([]float32)
if !ok || result == nil {
return nil
} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if result == nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+287
to
+291
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type assertion arr := pself.navigationMgrImpl.FindPath(flipY(from), flipY(to), withJump)
if arr == nil {
return nil
}
result, ok := arr.([]float32)
if !ok || result == nil {
return nil
} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // flipY to convert godot coord to spx coord | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i := 0; i+1 < len(result); i += 2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent approach + minor optimization This inline Y-negation is inconsistent with the Also, simplify the loop to start at index 1 to avoid the addition in the condition:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result[i+1] = -result[i+1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+285
to
+297
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type assertion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -85,9 +85,9 @@ func (p *rayCastResult) ToArray() engine.Array { | |||||||||||||||||||
| } | ||||||||||||||||||||
| ary[1] = p.SpriteId | ||||||||||||||||||||
| ary[2] = engine.ConvertToInt64(p.PosX) | ||||||||||||||||||||
| ary[3] = engine.ConvertToInt64(p.PosY) | ||||||||||||||||||||
| ary[3] = -engine.ConvertToInt64(p.PosY) // here need flipY to convert spx coord to godot coord | ||||||||||||||||||||
| ary[4] = engine.ConvertToInt64(p.NormalX) | ||||||||||||||||||||
| ary[5] = engine.ConvertToInt64(p.NormalY) | ||||||||||||||||||||
| ary[5] = -engine.ConvertToInt64(p.NormalY) | ||||||||||||||||||||
|
Comment on lines
+88
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment on line 88 is a bit informal. Also,
Suggested change
|
||||||||||||||||||||
| return ary | ||||||||||||||||||||
| } | ||||||||||||||||||||
| func tryRaycastResult(ary engine.Array) (*rayCastResult, error) { | ||||||||||||||||||||
|
|
@@ -103,9 +103,9 @@ func tryRaycastResult(ary engine.Array) (*rayCastResult, error) { | |||||||||||||||||||
| p.Hited = dataAry[0] != 0 | ||||||||||||||||||||
| p.SpriteId = dataAry[1] | ||||||||||||||||||||
| p.PosX = engine.ConvertToFloat64(dataAry[2]) | ||||||||||||||||||||
| p.PosY = engine.ConvertToFloat64(dataAry[3]) | ||||||||||||||||||||
| p.PosY = -engine.ConvertToFloat64(dataAry[3]) // here need flipY to convert to godot coord to spx coord | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Grammar error in comment
Suggested change
|
||||||||||||||||||||
| p.NormalX = engine.ConvertToFloat64(dataAry[4]) | ||||||||||||||||||||
| p.NormalY = engine.ConvertToFloat64(dataAry[5]) | ||||||||||||||||||||
| p.NormalY = -engine.ConvertToFloat64(dataAry[5]) | ||||||||||||||||||||
|
Comment on lines
+106
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment on line 106 has a typo ("to godot coord to spx coord") and is a bit informal. The same conversion is done for
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same grammar fix needed
Suggested change
|
||||||||||||||||||||
| return p, nil | ||||||||||||||||||||
| } | ||||||||||||||||||||
| func raycast(from, to mathf.Vec2, ignoreSprites []int64, mask int64) *rayCastResult { | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance Concern: Frequent Allocations in Hot Path
The
flipYfunction creates a newVec2struct on every call. Since this is called for every position/velocity operation (in rendering and physics updates), this creates significant memory pressure. At 60 FPS with 100 sprites, this could generate ~15,000-25,000 allocations/sec (~6-8 KB/frame).Consider optimizing for hot paths. One approach is to modify the copy in-place:
Or consider pointer-based APIs for frequently-called methods like GetPosition/SetPosition to avoid repeated allocations in Get-Modify-Set patterns (e.g., AddPos calls GetPosition then SetPosition).