-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.go
77 lines (60 loc) · 1.35 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (C) 2012-2014 by krepa098. All rights reserved.
// Use of this source code is governed by a zlib-style
// license that can be found in the license.txt file.
package gosfml2
/*
#include <SFML/System.h>
#include <string.h> //memcpy
void nextChar(sfUint32** ptr)
{
++(*ptr);
}
*/
import "C"
import (
"errors"
"sync"
"unsafe"
)
var (
globalCtx = NewContext()
globalMutex sync.Mutex
//As SFML does not provide useful error codes, we just return a generic error message
genericError = errors.New("Error: See stderr for more details")
)
/////////////////////////////////////
/// WRAPPING HELPERS
/////////////////////////////////////
func sfBool2Go(b C.sfBool) bool {
return b == 1
}
func goBool2C(b bool) C.sfBool {
if b {
return C.sfBool(1)
}
return C.sfBool(0)
}
// Convert a utf32 C string to a go string
func utf32CString2Go(cstr *C.sfUint32) string {
var str string
for ptr := cstr; *ptr != 0; C.nextChar(&ptr) {
str += string(rune(uint32(*ptr)))
}
return str
}
// Returns a null terminated UTF32 representation of str.
func strToRunes(str string) []rune {
return append([]rune(str), rune(0))
}
func globalCtxSetActive(active bool) {
if active {
globalMutex.Lock()
}
globalCtx.SetActive(active)
if !active {
globalMutex.Unlock()
}
}
func memcopy(dest, src unsafe.Pointer, size int) {
C.memcpy(dest, src, C.size_t(size))
}