Update Go sources
This commit is contained in:
parent
b126ec93ee
commit
70200c3151
10 changed files with 39 additions and 120 deletions
|
@ -12,12 +12,13 @@ func main() {
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
count := int32(0)
|
var count int
|
||||||
var droppedFiles []string
|
var droppedFiles []string
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if rl.IsFileDropped() {
|
if rl.IsFileDropped() {
|
||||||
droppedFiles = rl.GetDroppedFiles(&count)
|
droppedFiles = rl.LoadDroppedFiles()
|
||||||
|
count = len(droppedFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
@ -28,7 +29,7 @@ func main() {
|
||||||
} else {
|
} else {
|
||||||
rl.DrawText("Dropped files:", 100, 40, 20, rl.DarkGray)
|
rl.DrawText("Dropped files:", 100, 40, 20, rl.DarkGray)
|
||||||
|
|
||||||
for i := int32(0); i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
if i%2 == 0 {
|
if i%2 == 0 {
|
||||||
rl.DrawRectangle(0, int32(85+40*i), screenWidth, 40, rl.Fade(rl.LightGray, 0.5))
|
rl.DrawRectangle(0, int32(85+40*i), screenWidth, 40, rl.Fade(rl.LightGray, 0.5))
|
||||||
} else {
|
} else {
|
||||||
|
@ -44,7 +45,7 @@ func main() {
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.ClearDroppedFiles()
|
rl.UnloadDroppedFiles()
|
||||||
|
|
||||||
rl.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/gen2brain/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
storageScore = 0
|
|
||||||
storageHiscore = 1
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
rl.InitWindow(800, 450, "raylib [core] example - storage save/load values")
|
|
||||||
|
|
||||||
score := int32(0)
|
|
||||||
hiscore := int32(0)
|
|
||||||
|
|
||||||
framesCounter := 0
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
if rl.IsKeyPressed(rl.KeyR) {
|
|
||||||
score = rl.GetRandomValue(1000, 2000)
|
|
||||||
hiscore = rl.GetRandomValue(2000, 4000)
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyEnter) {
|
|
||||||
rl.SaveStorageValue(storageScore, score)
|
|
||||||
rl.SaveStorageValue(storageHiscore, hiscore)
|
|
||||||
} else if rl.IsKeyPressed(rl.KeySpace) {
|
|
||||||
// NOTE: If requested position could not be found, value 0 is returned
|
|
||||||
score = rl.LoadStorageValue(storageScore)
|
|
||||||
hiscore = rl.LoadStorageValue(storageHiscore)
|
|
||||||
}
|
|
||||||
|
|
||||||
framesCounter++
|
|
||||||
|
|
||||||
rl.BeginDrawing()
|
|
||||||
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
|
|
||||||
rl.DrawText(fmt.Sprintf("SCORE: %d", score), 280, 130, 40, rl.Maroon)
|
|
||||||
rl.DrawText(fmt.Sprintf("HI-SCORE: %d", hiscore), 210, 200, 50, rl.Black)
|
|
||||||
|
|
||||||
rl.DrawText(fmt.Sprintf("frames: %d", framesCounter), 10, 10, 20, rl.Lime)
|
|
||||||
|
|
||||||
rl.DrawText("Press R to generate random numbers", 220, 40, 20, rl.LightGray)
|
|
||||||
rl.DrawText("Press ENTER to SAVE values", 250, 310, 20, rl.LightGray)
|
|
||||||
rl.DrawText("Press SPACE to LOAD values", 252, 350, 20, rl.LightGray)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
|
@ -83,13 +83,13 @@ func IsFileDropped() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDroppedFiles - Retrieve dropped files into window
|
// LoadDroppedFiles - Load dropped filepaths
|
||||||
func GetDroppedFiles(count *int32) (files []string) {
|
func LoadDroppedFiles() (files []string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearDroppedFiles - Clear dropped files paths buffer
|
// UnloadDroppedFiles - Unload dropped filepaths
|
||||||
func ClearDroppedFiles() {
|
func UnloadDroppedFiles() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,13 +71,13 @@ func IsFileDropped() bool {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDroppedFiles - Retrieve dropped files into window
|
// LoadDroppedFiles - Load dropped filepaths
|
||||||
func GetDroppedFiles(count *int32) []string {
|
func LoadDroppedFiles() []string {
|
||||||
ccount := (*C.int)(unsafe.Pointer(count))
|
ret := C.LoadDroppedFiles()
|
||||||
ret := C.GetDroppedFiles(ccount)
|
defer C.UnloadDroppedFiles(ret)
|
||||||
|
|
||||||
tmpslice := (*[1 << 24]*C.char)(unsafe.Pointer(ret))[:*count:*count]
|
tmpslice := (*[1 << 24]*C.char)(unsafe.Pointer(ret.paths))[:ret.count:ret.count]
|
||||||
gostrings := make([]string, *count)
|
gostrings := make([]string, ret.count)
|
||||||
for i, s := range tmpslice {
|
for i, s := range tmpslice {
|
||||||
gostrings[i] = C.GoString(s)
|
gostrings[i] = C.GoString(s)
|
||||||
}
|
}
|
||||||
|
@ -85,9 +85,9 @@ func GetDroppedFiles(count *int32) []string {
|
||||||
return gostrings
|
return gostrings
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearDroppedFiles - Clear dropped files paths buffer
|
// UnloadDroppedFiles - Unload dropped filepaths
|
||||||
func ClearDroppedFiles() {
|
func UnloadDroppedFiles() {
|
||||||
C.ClearDroppedFiles()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenAsset - Open asset
|
// OpenAsset - Open asset
|
||||||
|
|
|
@ -69,13 +69,13 @@ func IsFileDropped() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDroppedFiles - Retrieve dropped files into window
|
// LoadDroppedFiles - Load dropped filepaths
|
||||||
func GetDroppedFiles(count *int32) (files []string) {
|
func LoadDroppedFiles() (files []string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearDroppedFiles - Clear dropped files paths buffer
|
// UnloadDroppedFiles - Unload dropped filepaths
|
||||||
func ClearDroppedFiles() {
|
func UnloadDroppedFiles() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,13 +69,13 @@ func IsFileDropped() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDroppedFiles - Retrieve dropped files into window
|
// LoadDroppedFiles - Load dropped filepaths
|
||||||
func GetDroppedFiles(count *int32) (files []string) {
|
func LoadDroppedFiles() (files []string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearDroppedFiles - Clear dropped files paths buffer
|
// UnloadDroppedFiles - Unload dropped filepaths
|
||||||
func ClearDroppedFiles() {
|
func UnloadDroppedFiles() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,8 +213,8 @@ func LoadWaveSamples(wave Wave) []float32 {
|
||||||
ret := C.LoadWaveSamples(*cwave)
|
ret := C.LoadWaveSamples(*cwave)
|
||||||
|
|
||||||
sliceHeader := (*reflect.SliceHeader)((unsafe.Pointer(&data)))
|
sliceHeader := (*reflect.SliceHeader)((unsafe.Pointer(&data)))
|
||||||
sliceHeader.Cap = int(wave.SampleCount)
|
sliceHeader.Cap = int(wave.FrameCount)
|
||||||
sliceHeader.Len = int(wave.SampleCount)
|
sliceHeader.Len = int(wave.FrameCount)
|
||||||
sliceHeader.Data = uintptr(unsafe.Pointer(ret))
|
sliceHeader.Data = uintptr(unsafe.Pointer(ret))
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -30,8 +30,6 @@ Example:
|
||||||
|
|
||||||
rl.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package rl
|
package rl
|
||||||
|
|
||||||
|
@ -56,7 +54,7 @@ func init() {
|
||||||
// Wave type, defines audio wave data
|
// Wave type, defines audio wave data
|
||||||
type Wave struct {
|
type Wave struct {
|
||||||
// Number of samples
|
// Number of samples
|
||||||
SampleCount uint32
|
FrameCount uint32
|
||||||
// Frequency (samples per second)
|
// Frequency (samples per second)
|
||||||
SampleRate uint32
|
SampleRate uint32
|
||||||
// Bit depth (bits per sample): 8, 16, 32 (24 not supported)
|
// Bit depth (bits per sample): 8, 16, 32 (24 not supported)
|
||||||
|
@ -80,9 +78,9 @@ func newWaveFromPointer(ptr unsafe.Pointer) Wave {
|
||||||
|
|
||||||
// Sound source type
|
// Sound source type
|
||||||
type Sound struct {
|
type Sound struct {
|
||||||
Stream AudioStream
|
Stream AudioStream
|
||||||
SampleCount uint32
|
FrameCount uint32
|
||||||
_ [4]byte
|
_ [4]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// newSoundFromPointer - Returns new Sound from pointer
|
// newSoundFromPointer - Returns new Sound from pointer
|
||||||
|
@ -93,11 +91,11 @@ func newSoundFromPointer(ptr unsafe.Pointer) Sound {
|
||||||
// Music type (file streaming from memory)
|
// Music type (file streaming from memory)
|
||||||
// NOTE: Anything longer than ~10 seconds should be streamed
|
// NOTE: Anything longer than ~10 seconds should be streamed
|
||||||
type Music struct {
|
type Music struct {
|
||||||
Stream AudioStream
|
Stream AudioStream
|
||||||
SampleCount uint32
|
FrameCount uint32
|
||||||
Looping bool
|
Looping bool
|
||||||
CtxType int32
|
CtxType int32
|
||||||
CtxData unsafe.Pointer
|
CtxData unsafe.Pointer
|
||||||
}
|
}
|
||||||
|
|
||||||
// newMusicFromPointer - Returns new Music from pointer
|
// newMusicFromPointer - Returns new Music from pointer
|
||||||
|
@ -110,6 +108,8 @@ func newMusicFromPointer(ptr unsafe.Pointer) Music {
|
||||||
type AudioStream struct {
|
type AudioStream struct {
|
||||||
// Buffer
|
// Buffer
|
||||||
Buffer *C.rAudioBuffer
|
Buffer *C.rAudioBuffer
|
||||||
|
// Processor
|
||||||
|
Processor *C.rAudioProcessor
|
||||||
// Frequency (samples per second)
|
// Frequency (samples per second)
|
||||||
SampleRate uint32
|
SampleRate uint32
|
||||||
// Bit depth (bits per sample): 8, 16, 32 (24 not supported)
|
// Bit depth (bits per sample): 8, 16, 32 (24 not supported)
|
||||||
|
|
|
@ -595,21 +595,6 @@ func TakeScreenshot(name string) {
|
||||||
C.TakeScreenshot(cname)
|
C.TakeScreenshot(cname)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveStorageValue - Storage save integer value (to defined position)
|
|
||||||
func SaveStorageValue(position, value int32) {
|
|
||||||
cposition := (C.uint)(position)
|
|
||||||
cvalue := (C.int)(value)
|
|
||||||
C.SaveStorageValue(cposition, cvalue)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LoadStorageValue - Storage load integer value (from defined position)
|
|
||||||
func LoadStorageValue(position int32) int32 {
|
|
||||||
cposition := (C.uint)(position)
|
|
||||||
ret := C.LoadStorageValue(cposition)
|
|
||||||
v := (int32)(ret)
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsKeyPressed - Detect if a key has been pressed once
|
// IsKeyPressed - Detect if a key has been pressed once
|
||||||
func IsKeyPressed(key int32) bool {
|
func IsKeyPressed(key int32) bool {
|
||||||
ckey := (C.int)(key)
|
ckey := (C.int)(key)
|
||||||
|
|
|
@ -558,15 +558,6 @@ func GetRayCollisionBox(ray Ray, box BoundingBox) RayCollision {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRayCollisionModel - Get collision info between ray and model
|
|
||||||
func GetRayCollisionModel(ray Ray, model Model) RayCollision {
|
|
||||||
cray := ray.cptr()
|
|
||||||
cmodel := model.cptr()
|
|
||||||
ret := C.GetRayCollisionModel(*cray, *cmodel)
|
|
||||||
v := newRayCollisionFromPointer(unsafe.Pointer(&ret))
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRayCollisionMesh - Get collision info between ray and mesh
|
// GetRayCollisionMesh - Get collision info between ray and mesh
|
||||||
func GetRayCollisionMesh(ray Ray, mesh Mesh, transform Matrix) RayCollision {
|
func GetRayCollisionMesh(ray Ray, mesh Mesh, transform Matrix) RayCollision {
|
||||||
cray := ray.cptr()
|
cray := ray.cptr()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue