Skip to content

Commit

Permalink
Revert "Separate backend"
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 authored Nov 24, 2023
1 parent e9c342c commit 06f501d
Show file tree
Hide file tree
Showing 2,096 changed files with 1,169 additions and 1,188 deletions.
47 changes: 23 additions & 24 deletions backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"unsafe"
)

type VoidCallbackFunc func()
type voidCallbackFunc func()

var currentBackend backendCExpose

Expand All @@ -25,7 +25,7 @@ var textureManager TextureManager
//export loopCallback
func loopCallback() {
if currentBackend != nil {
if f := currentBackend.LoopFunc(); f != nil {
if f := currentBackend.loopFunc(); f != nil {
f()
}
}
Expand All @@ -34,7 +34,7 @@ func loopCallback() {
//export beforeRender
func beforeRender() {
if currentBackend != nil {
if f := currentBackend.BeforeRenderHook(); f != nil {
if f := currentBackend.beforeRenderHook(); f != nil {
f()
}
}
Expand All @@ -43,7 +43,7 @@ func beforeRender() {
//export afterRender
func afterRender() {
if currentBackend != nil {
if f := currentBackend.AfterRenderHook(); f != nil {
if f := currentBackend.afterRenderHook(); f != nil {
f()
}
}
Expand All @@ -52,7 +52,7 @@ func afterRender() {
//export afterCreateContext
func afterCreateContext() {
if currentBackend != nil {
if f := currentBackend.AfterCreateHook(); f != nil {
if f := currentBackend.afterCreateHook(); f != nil {
f()
}
}
Expand All @@ -61,7 +61,7 @@ func afterCreateContext() {
//export beforeDestoryContext
func beforeDestoryContext() {
if currentBackend != nil {
if f := currentBackend.BeforeDestroyHook(); f != nil {
if f := currentBackend.beforeDestroyHook(); f != nil {
f()
}
}
Expand All @@ -70,7 +70,7 @@ func beforeDestoryContext() {
//export keyCallback
func keyCallback(_ unsafe.Pointer, key, scanCode, action, mods C.int) {
if currentBackend != nil {
if f := currentBackend.KeyCallback(); f != nil {
if f := currentBackend.keyCallback(); f != nil {
f(int(key), int(scanCode), int(action), int(mods))
}
}
Expand All @@ -79,23 +79,21 @@ func keyCallback(_ unsafe.Pointer, key, scanCode, action, mods C.int) {
//export sizeCallback
func sizeCallback(_ unsafe.Pointer, w, h C.int) {
if currentBackend != nil {
if f := currentBackend.SizeCallback(); f != nil {
if f := currentBackend.sizeCallback(); f != nil {
f(int(w), int(h))
}
}
}

type (
DropCallback func([]string)
KeyCallback func(key, scanCode, action, mods int)
SizeChangeCallback func(w, h int)
)
type DropCallback func([]string)
type KeyCallback func(key, scanCode, action, mods int)
type SizeChangeCallback func(w, h int)

type WindowCloseCallback[BackendFlagsT ~int] func(b Backend[BackendFlagsT])

//export closeCallback
func closeCallback(wnd unsafe.Pointer) {
currentBackend.CloseCallback()(wnd)
currentBackend.closeCallback()(wnd)
}

//export dropCallback
Expand All @@ -107,7 +105,7 @@ func dropCallback(wnd unsafe.Pointer, count C.int, names **C.char) {
namesSlice[i] = C.GoString(*p)
}

currentBackend.DropCallback()(namesSlice)
currentBackend.dropCallback()(namesSlice)
}

// Backend is a special interface that implements all methods required
Expand Down Expand Up @@ -159,6 +157,7 @@ type TextureManager interface {
}

type backendCExpose interface {

// for C callbacks
// What happens here is a bit tricky:
// - user sets these callbacks via Set* methods of the backend
Expand All @@ -169,15 +168,15 @@ type backendCExpose interface {
// - backend implementation uses C references to Go callbacks to share them (again ;-) )
// into backend code.
// As you can see this is all to convert Go callback int C callback
AfterCreateHook() func()
BeforeRenderHook() func()
LoopFunc() func()
AfterRenderHook() func()
BeforeDestroyHook() func()
DropCallback() DropCallback
CloseCallback() func(window unsafe.Pointer)
KeyCallback() KeyCallback
SizeCallback() SizeChangeCallback
afterCreateHook() func()
beforeRenderHook() func()
loopFunc() func()
afterRenderHook() func()
beforeDestroyHook() func()
dropCallback() DropCallback
closeCallback() func(window unsafe.Pointer)
keyCallback() KeyCallback
sizeCallback() SizeChangeCallback
}

func CreateBackend[BackendFlagsT ~int](backend Backend[BackendFlagsT]) Backend[BackendFlagsT] {
Expand Down
10 changes: 0 additions & 10 deletions backend/cimgui.go

This file was deleted.

Loading

0 comments on commit 06f501d

Please sign in to comment.