Comments (4)
Golang's Int on 64 bit machines is 8 bytes.
Methods which return or accept an Integer could be changed easily.
Structures which are passed to SDL need to adhere to the ABI of the C structures.
Otherwise all structs would need to go through a translation layer.
I recently fixed (almost) all struct ABIs, see: https://github.com/veandco/go-sdl2/blob/master/sdl/struct_test.go
In general I agree that reducing type casts would be nice. On the other hand go ints do have different width on 32 and 64 bit systems.
from go-sdl2.
I see. I was mistakenly under the assumption that C ints would be 64bits on a 64bit machines. I missed that you were doing casting into and out of Go ints in parameters and return values. I guess translating structs would be too much a performance hit? And its not clear making everything int32 (parameters and return values) would be less casting or more convenient even if that might make the api more consistent.
from go-sdl2.
I contributed the unit tests and fixes because I ran into some misaligned structures while developing some little test applications.
From an architectural point of view I believe that a translation layer would make a lot of sense.
For example I did not fix the 'AudioCVT' structure because CGO has a hard time dealing with packed structures.
Since I only fixed existing code I did not add real struct translations (purely out of laziness :) )
My measurement so far have shown that crossing the barrier between C and GO through CGO is quite expensive. More than a very few thousand calls per frame is unrealistic.
So I believe that a translation layer would add few enough overhead to be noise against the CGO call overhead. Of course benchmarks would be required to verify this.
This could be a nice place to try out go:generate :)
@jackyb: Do you have any design in mind for this or similar issues?
from go-sdl2.
I actually would suggest, to chage the API to int whenever possible. For example in timer.go
GetTicks and Delay could be changed to use int
instead of uint32
. For the Rect API, I do suggest, to implement both Rect
and C compatible non exported rect32
for communication. I think a rectangle is small enough to be casted back and forth on calls, where it matters. All functions that do clipping and other calculations on rectangles should be ported to native go, to prevent CGO calls.
from go-sdl2.
Related Issues (20)
- Is it possible to compile to .app on macOS? Also, is there a way to hide terminal when building HOT 4
- No way to get enter key event when using sdl.WaitEvent() HOT 1
- WASI Support
- Not compatible with Go 1.21.0 HOT 7
- SDL/SDL.h: No such file or directory HOT 2
- How to ship release version HOT 4
- Surface panics on color conversions due to nonidiomatic color models HOT 4
- Windows release crashing likely because C.CString deallocated with C.SDL_free HOT 3
- Getting an errror when compiling to wasm HOT 2
- impossible type switch case: sdl.QuitEvent HOT 4
- Cannot find -lsdl2 HOT 10
- SDL_AudioStreamAvailable not correctly wrapped HOT 2
- Missing functions in gamecontroller.go HOT 6
- Readme Example Fix typo HOT 2
- Running readme example yields 30% CPU usage HOT 13
- Fails to link with musl libc HOT 1
- feature req: img.LoadSizedSVG HOT 2
- SdlSetTextureScaleMode HOT 7
- Window Doesn't Show HOT 9
- How to SDL on 64bit Windows Instructions Unclear HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-sdl2.