Skip to content

Commit

Permalink
Some more redesign, basic audio support, raylib 3.7.
Browse files Browse the repository at this point in the history
  • Loading branch information
TSnake41 committed May 5, 2021
1 parent 5f1712f commit 3757a59
Show file tree
Hide file tree
Showing 31 changed files with 885 additions and 77 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[Wren](https://wren.io) binding for [raylib](https://www.raylib.com/), a simple
and easy-to-use library to learn videogames programming.

This binding supports raylib 3.1-dev, previous version may support raylib 2.6.
This binding supports raylib 3.7, previous version may support earlier versions.

## Usage (wray_s)

Expand All @@ -30,8 +30,8 @@ a project directory with a main.wren file.
./wray_e examples/core_basic_window
```

Currently, there is no support for loading embedded assets, so if your game
needs to use any of them, they must be provided externally.
Currently, there is a limited support for loading embedded assets.
All assets type are supported however music files must be provided externally.

## Use as a external library (advanced)

Expand Down Expand Up @@ -77,7 +77,7 @@ Raylib.initWindow(800, 450, "raylib [core] example - basic window")
while (!Raylib.windowShouldClose) {
Raylib.beginDrawing()
Raylib.clearBackground(RlColor.rayWhite)
Raylib.clearBackground(Color.rayWhite)
Raylib.drawText("Congrats! You created your first window!", 190, 200, 20, Color.lightGray)
Raylib.endDrawing()
Expand All @@ -88,7 +88,7 @@ Raylib.closeWindow()

## Compatibility

raylib-wren is currently compatible with raylib 3.1-dev API.
raylib-wren is currently compatible with raylib 3.7 API.
Only a subset of the API supported, any contribution on API is welcome.

There is currently no support for rlgl, physac and raygui.
Expand Down Expand Up @@ -118,7 +118,7 @@ and wray_CheckForeignType is no-op.

### Licence

Copyright (C) 2019-2020 Astie Teddy
Copyright (C) 2019-2021 Astie Teddy

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
51 changes: 39 additions & 12 deletions api/Audio.wren
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
foreign class RlWave {
foreign construct new()
foreign construct new(path)
Expand All @@ -14,13 +15,50 @@ foreign class RlWave {
clone { copy(new()) }
}
*/

foreign class Sound {
foreign construct new(path) /* TODO: Consider wave support */

foreign play()
foreign stop()
foreign pause()
foreign resume()

foreign playMulti()

foreign playing
foreign volume=(v)
foreign pitch=(p)
}

foreign class Music {
foreign construct new(path)

foreign update()

foreign play()
foreign stop()
foreign pause()
foreign resume()

foreign playing
foreign volume=(v)
foreign pitch=(p)

foreign length
foreign played
}


// NOTE: This has yet to be considered.
// raudio uses AudioStream as a common interface but with different
// fashions, so to reduce code redudancy and the multiplication of
// foreign classes, I will not repeat myself as much as possible.
// Only expose RlAudioStream as a foreign class, very specific methods
// will be implemented as foreign method on class.

/*
foreign class RlAudioStream {
foreign construct new(sampleRate, sampleSize, channels)
Expand All @@ -36,15 +74,4 @@ foreign class RlAudioStream {
foreign playing
foreign processed
}

class RlSound {
foreign construct new(path_or_wave)

play() { }
pause()
resume()
}

class RlMusicStream {

}
*/
9 changes: 9 additions & 0 deletions api/Raylib.wren
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ class Raylib {
foreign static frameTime
foreign static time

foreign static initAudioDevice()
foreign static closeAudioDevice()
foreign static isAudioDeviceReady

foreign static stopSoundMulti()
foreign static soundsPlaying

foreign static masterVolume=(v)

static screenSize { Vector2.new(screenWidth, screenHeight) }

// Low level draw functions
Expand Down
2 changes: 1 addition & 1 deletion api/Structures.wren
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ foreign class Image {
foreign mipmaps
}

foreign class Texture2D {
foreign class Texture {
foreign construct new(image)

foreign width
Expand Down
27 changes: 27 additions & 0 deletions examples/audio_music_stream.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import "raylib" for Raylib, Color, ConfigFlags, Music, Sound

// some basic setup
Raylib.configFlags = ConfigFlags.vsync
Raylib.targetFPS = 60

Raylib.initWindow(800, 450, "raylib-wren [audio] example - music stream")
Raylib.initAudioDevice()

var music = Music.new("ressources/mini1111.xm")
music.play()

while (!Raylib.windowShouldClose) {
music.update()

Raylib.beginDrawing()
Raylib.clearBackground(Color.rayWhite)

Raylib.drawFPS(10, 10)

Raylib.drawText("Playing some music !", 300, 200, 20, Color.lightGray)

Raylib.endDrawing()
}

Raylib.closeAudioDevice()
Raylib.closeWindow()
25 changes: 25 additions & 0 deletions examples/audio_sound.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import "raylib" for Raylib, Color, ConfigFlags, Music, Sound

// some basic setup
Raylib.configFlags = ConfigFlags.vsync
Raylib.targetFPS = 60

Raylib.initWindow(800, 450, "raylib-wren [audio] example - music stream")
Raylib.initAudioDevice()

var sound = Sound.new("ressources/mini1111.ogg")
sound.play()

while (!Raylib.windowShouldClose) {
Raylib.beginDrawing()
Raylib.clearBackground(Color.rayWhite)

Raylib.drawFPS(10, 10)

Raylib.drawText("Playing some music !", 300, 200, 20, Color.lightGray)

Raylib.endDrawing()
}

Raylib.closeAudioDevice()
Raylib.closeWindow()
2 changes: 2 additions & 0 deletions examples/core_basic_window.wren
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Raylib.initWindow(800, 450, "raylib [core] example - basic window")
while (!Raylib.windowShouldClose) {
Raylib.beginDrawing()
Raylib.clearBackground(Color.rayWhite)

Raylib.drawFPS(10, 10)

Raylib.drawText("Congrats! You created your first window!", 190, 200, 20, Color.lightGray)

Expand Down
4 changes: 2 additions & 2 deletions examples/ecs_benchmark.wren
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Inspired of Tjakka5/love-ecs-benchmarks
import "raylib" for Raylib, ConfigFlags, Color, Key, Vector2, Texture2D,
import "raylib" for Raylib, ConfigFlags, Color, Key, Vector2, Texture,
World, GameEntity, GameSystem

import "random" for Random
Expand Down Expand Up @@ -66,7 +66,7 @@ var Physics = GameSystem.new([Position, Velocity]) {|entities, event, dt|
}
}

var testSprite = Texture2D.new("resources/wabbit_alpha.png")
var testSprite = Texture.new("resources/wabbit_alpha.png")

var SpriteRenderer = GameSystem.new([Position, Sprite]) {|entities, event|
if (event == "draw") {
Expand Down
18 changes: 18 additions & 0 deletions examples/embedded/main.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import "raylib" for Raylib, Color, ConfigFlags, Texture

// Set config flags.
Raylib.configFlags = ConfigFlags.vsync
Raylib.targetFPS = 60

Raylib.initWindow(800, 450, "raylib [wren] example - basic window (embedded)")
var logo = Texture.new("logo.png")

while (!Raylib.windowShouldClose) {
Raylib.beginDrawing()

Raylib.clearBackground(Color.rayWhite)
Raylib.drawText("Congrats! You made a embedded wray executable!", 190, 200, 20, Color.lightGray)
Raylib.endDrawing()
}

Raylib.closeWindow()
Binary file added examples/ressources/mini1111.ogg
Binary file not shown.
Binary file added examples/ressources/mini1111.xm
Binary file not shown.
File renamed without changes
1 change: 0 additions & 1 deletion examples/shapes_logo_raylib.wren
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import "raylib" for Raylib, Color, ConfigFlags

var screenWidth = 800
Expand Down
4 changes: 2 additions & 2 deletions examples/texture_bunnymark.wren
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "raylib" for Raylib, Key, Color, Texture2D, Vector2
import "raylib" for Raylib, Key, Color, Texture, Vector2
import "random" for Random

var random = Random.new()
Expand All @@ -25,7 +25,7 @@ var screenHeight = 450
Raylib.initWindow(screenWidth, screenHeight, "raylib [textures] example - bunnymark")
Raylib.targetFPS = 60

var texBunny = Texture2D.new("resources/wabbit_alpha.png")
var texBunny = Texture.new("ressources/wabbit_alpha.png")
var bunnies = []
var bunniesCount = 0

Expand Down
6 changes: 3 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ AR ?= ar
LUA ?= luajit

CFLAGS += -Iinclude -Iwren/src/include -Iraylib/src
LDFLAGS += -Lwren/lib -L. -lwren -Lraylib/src -lraylib
LDFLAGS += -Lwren/lib -L. -lwren -Lraylib -Lraylib/src -lraylib

# wray settings
CFLAGS += -DWRAY_TYPE_CHECK
Expand All @@ -28,11 +28,11 @@ else
endif

WRAY_API := api/Raylib.wren api/Color.wren api/Key.wren api/Math.wren \
api/Structures.wren api/World.wren
api/Audio.wren api/Structures.wren api/World.wren

SRC := src/wray.c src/wray_funcs.c src/wray_api.c src/wray_typecheck.c \
src/wray_core.c src/wray_color.c src/wray_class.c src/wray_draw.c \
src/wray_image.c
src/wray_image.c src/wray_audio.c

OBJ := $(SRC:.c=.o)

Expand Down
2 changes: 1 addition & 1 deletion raylib
Submodule raylib updated 406 files
Loading

0 comments on commit 3757a59

Please sign in to comment.