Modules

Started by chrisws, November 01, 2020, 02:27:04

Previous topic - Next topic

chrisws

I've been working on a few different extension modules for SmallBASIC.

A few years ago I mentioned the "nuklear" library for writing GUIs.  The new modules are: glfw, clipboard, websocket (see https://en.wikipedia.org/wiki/WebSocket) and raylib.

With the glfw module you can create a window and then call the usual SB drawing funcs like circle, arc, line etc. This is using the old-school OpenGL apis, nothing fancy.

The raylib module (https://www.raylib.com/) is still a work in progress.

These modules are currently only working in linux with the console version.

see: https://github.com/smallbasic/smallbasic.plugins

round157

SmallBASIC is entering a new era.

Moreover, the following module looks interesting. SmallBASIC users will be able to write interesting programs with this useful module.

Quote from: chrisws on November 01, 2020, 02:27:04

The raylib module (https://www.raylib.com/) is still a work in progress.


chrisws

#2
I've been having fun with raylib. Kudos to Ramon for making such a wonderful thing.

Here's a list of the implemented APIs:

https://github.com/smallbasic/smallbasic.plugins/tree/master/raylib

I just need to tweak the build script to make this compile in windows.

round157

Quote from: chrisws on November 07, 2020, 20:14:13
Here's a list of the implemented APIs:

https://github.com/smallbasic/smallbasic.plugins/tree/master/raylib


Good.

It may be really simple to get results very fast with Raylib module. Raylib module may effectively encourage newcomers to try or learn SmallBASIC. Strong motivation.

chrisws

I've managed to build each of the modules as DLLs now (except glfw).

The only snag with the raylib DLL is it depends on some mingw DLLs. This is in spite of attempting all the suggestions I could find online to link statically.





round157

Quote from: chrisws on November 15, 2020, 00:08:34
I've managed to build each of the modules as DLLs now (except glfw).

The only snag with the raylib DLL is it depends on some mingw DLLs. This is in spite of attempting all the suggestions I could find online to link statically.

Wow. the progress looks rapid. 

I can imagine that some creative users will write
very nice programs with these new modules. Bplus
may write very entertaining games with the Raylib
module. I look forward to the games made by
Bplus.

bplus

#6
I just took a glance at what Raylib might be, I have one word for it, WOW!

Man Chris, if you can get that going in SmallBASIC for Windows... :)

Meanwhile, I have to say, just ported Bowling to QB64
https://www.qb64.org/forum/index.php?topic=3291.msg125753#msg125753
and what Wright brothers these 2 Basics seem to be! The editor with QB64 has me absolutely spoiled with it's formatting, automatic indenting, option explicit and syntax checking.
1 person likes this

round157

Quote from: bplus on November 26, 2020, 19:26:14
I just took a glance at what Raylib might be, I have one word for it, WOW!


The library looks cool and fun. It has a lot of language and platform bindings.

Quote

and what Wright brothers these 2 Basics seem to be! The editor with QB64 has me absolutely spoiled with it's formatting,

QB64's user base looks huge. It is a so successful language.


chrisws

I've made a bit more progress with raylib. Here's the SmallBASIC version of physics_demo from the raylib examples.


REM /*******************************************************************************************
REM *
REM *   Physac - Physics demo
REM *
REM *   Copyright (c) 2016-2018 Victor Fisac
REM *
REM ********************************************************************************************/

import raylib as rl
import raylibc as c

const screenWidth = 800
const screenHeight = 450

rl.SetConfigFlags(c.FLAG_MSAA_4X_HINT)
rl.InitWindow(screenWidth, screenHeight, "SmallBASIC Physac [raylib] - Physics demo")

' Physac logo drawing position
logoX = screenWidth - rl.MeasureText("Physac", 30) - 10
logoY = 15
needsReset = false

' Initialize physics and default physics bodies
rl.InitPhysics()

' Create floor rectangle physics body
phy_floor = rl.CreatePhysicsBodyRectangle([screenWidth/2, screenHeight], 500, 100, 10)

' Create obstacle circle physics body
phy_circle = rl.CreatePhysicsBodyCircle([screenWidth / 2, screenHeight / 2], 45, 10)

' Disable body state to convert it to static (no dynamics, but collisions)
rl.enablePhysicsBody(phy_floor, false)
rl.enablePhysicsBody(phy_circle, false)

rl.SetTargetFPS(60)                ' Set our game to run at 60 frames-per-second
while (!rl.WindowShouldClose())
  rl.RunPhysicsStep()
  if (needsReset) then
    phy_floor = rl.CreatePhysicsBodyRectangle([screenWidth/2, screenHeight], 500, 100, 10)
    phy_circle = rl.CreatePhysicsBodyCircle([screenWidth/2, screenHeight/2], 45, 10)
    rl.enablePhysicsBody(phy_floor, false)
    rl.enablePhysicsBody(phy_circle, false)
    needsReset = false
  endif

  ' Reset physics input
  if (rl.IsKeyPressed(asc("R"))) then
    rl.ResetPhysics()
    needsReset = true
  endif

  ' Physics body creation inputs
  if (rl.isMouseButtonPressed(c.MOUSE_LEFT_BUTTON)) then
    n = rl.CreatePhysicsBodyPolygon(rl.GetMousePosition(), rl.GetRandomValue(20, 80), rl.GetRandomValue(3, 8), 10)
  elseif (rl.IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) then
    n = rl.CreatePhysicsBodyCircle(rl.GetMousePosition(), rl.GetRandomValue(10, 45), 10)
  endif

  ' Destroy falling physics bodies
  bodiesCount = rl.GetPhysicsBodiesCount()
  for i = bodiesCount - 1  to 0 step -1
    body = rl.GetPhysicsBody(i)
    if (body.position.y > screenHeight*2) then
      rl.DestroyPhysicsBody(body)
    endif
  next i

  rl.BeginDrawing()
  rl.ClearBackground(c.BLACK)
  rl.DrawFPS(screenWidth - 90, screenHeight - 30)

  ' Draw created physics bodies
  bodiesCount = rl.GetPhysicsBodiesCount()
  for i = 0 to bodiesCount - 1
    body = rl.GetPhysicsBody(i)
    if (ismap(body)) then
      vertexCount = rl.GetPhysicsShapeVerticesCount(i)
      for j = 0 to vertexCount -1
        ' Get physics bodies shape vertices to draw lines
        ' Note: GetPhysicsShapeVertex() already calculates rotation transformations
        vertexA = rl.GetPhysicsShapeVertex(body, j)
        jj = iff(j + 1 < vertexCount, j + 1, 0)    ' Get next vertex or first to close the shape
        vertexB = rl.GetPhysicsShapeVertex(body, jj)
        rl.DrawLineV(vertexA, vertexB, c.GREEN)     ' Draw a line between two vertex positions
      next j
    endif
  next i

  rl.DrawText("Left mouse button to create a polygon", 10, 10, 10, c.WHITE)
  rl.DrawText("Right mouse button to create a circle", 10, 25, 10, c.WHITE)
  rl.DrawText("Press 'R' to reset example", 10, 40, 10, c.WHITE)
  rl.DrawText("Physac", logoX, logoY, 30, c.WHITE)
  rl.DrawText("Powered by", logoX + 50, logoY - 7, 10, c.WHITE)
  rl.EndDrawing()
wend

rl.ClosePhysics()        ' Unitialize physics
rl.CloseWindow()         ' Close window and OpenGL context



You can play with raylib examples online here: https://www.raylib.com/examples.html


round157

Quote from: chrisws on December 05, 2020, 20:49:32
Here's the SmallBASIC version of physics_demo from the raylib examples.

We are excited and you are so diligent.

Quote
You can play with raylib examples online here: https://www.raylib.com/examples.html

So many nice examples there. Quite interesting. Full potential of Raylib.

chrisws

I've uploaded version 12.20 for Windows (64 bit only). This includes a bunch of DLLs for the above mentioned modules.

For best results, use the console version with the modules/DLLs either by giving the path via the -m switch or the SBASICPATH environment variable.

The SDL version has a few tweaks to the editor.

https://github.com/smallbasic/SmallBASIC/releases/download/v12.20/smallbasic_12.20.zip

Cheers,
Chris

round157

Quote from: chrisws on January 09, 2021, 10:36:54
I've uploaded version 12.20 for Windows (64 bit only).

Oh, 32-bit Windows is used in my main computer. Will a 32-bit version 12.20 be released in the near future?


chrisws

#12
For sure... I will take a look on the week end.

I'll just create a separate zip file with 32 bit exe's. I'm assuming 32 bit Mingw supports DLL's will be available.

Here's another raylib sample:


REM /*******************************************************************************************
REM *
REM *   raylib [textures] example - sprite explosion
REM *
REM *   This example has been created using raylib 2.5 (www.raylib.com)
REM *   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
REM *
REM *   Copyright (c) 2019 Anata and Ramon Santamaria (@raysan5)
REM *
REM ********************************************************************************************/

import raylib as rl
import raylibc as c

const NUM_FRAMES_PER_LINE =   5
const NUM_LINES =             5

const screenWidth = 800
const screenHeight = 450

rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - sprite explosion")
rl.InitAudioDevice()

' Load explosion sound
const resources = CWD + "raylib/examples/textures/resources/"
fxBoom = rl.LoadSound(resources + "boom.wav")

' Load explosion texture
explosion = rl.LoadTexture(resources + "explosion.png")

' Init variables for animation
frameWidth = explosion.width / NUM_FRAMES_PER_LINE   ' Sprite one frame rectangle width
frameHeight = explosion.height / NUM_LINES           ' Sprite one frame rectangle height
currentFrame = 0
currentLine = 0

frameRec = [0, 0, frameWidth, frameHeight]
position = [0.0, 0.0]
active = true
framesCounter = 0

rl.SetTargetFPS(120)
while (!rl.WindowShouldClose())    ' Detect window close button or ESC key
  ' Check for mouse button pressed and activate explosion (if not active)
  if (rl.IsMouseButtonPressed(c.MOUSE_LEFT_BUTTON) && !active) then
    position = rl.GetMousePosition()
    active = true
    position.x -= frameWidth/2
    position.y -= frameHeight/2
    rl.PlaySound(fxBoom)
  endif

  ' Compute explosion animation frames
  if (active) then
    framesCounter++
    if (framesCounter > 2) then
      currentFrame++
      if (currentFrame >= NUM_FRAMES_PER_LINE) then
        currentFrame = 0
        currentLine++
        if (currentLine >= NUM_LINES) then
          currentLine = 0
          active = false
        endif
      endif
      framesCounter = 0
    endif
  endif

  frameRec[0] = frameWidth * currentFrame
  frameRec[1] = frameHeight * currentLine

  rl.BeginDrawing()
  rl.ClearBackground(c.RAYWHITE)

  ' Draw explosion required frame rectangle
  if (active) then
    rl.DrawTextureRec(explosion, frameRec, position, c.WHITE)
  endif

  rl.EndDrawing()
wend

rl.UnloadTexture(explosion)   ' Unload texture
rl.UnloadSound(fxBoom)        ' Unload sound
rl.CloseAudioDevice()
rl.CloseWindow()              ' Close window and OpenGL context



chrisws

Quote from: round157 on January 13, 2021, 00:11:37
Quote from: chrisws on January 09, 2021, 10:36:54
I've uploaded version 12.20 for Windows (64 bit only).

Oh, 32-bit Windows is used in my main computer. Will a 32-bit version 12.20 be released in the near future?

Here is the 32-bit package of builds, please let me know if you find any issues

https://github.com/smallbasic/SmallBASIC/releases/download/v12.20/smallbasic_12_20_i686.zip

Enjoy!


round157

Quote from: chrisws on January 16, 2021, 03:16:30


Here is the 32-bit package of builds, please let me know if you find any issues

https://github.com/smallbasic/SmallBASIC/releases/download/v12.20/smallbasic_12_20_i686.zip

Enjoy!

I will try it. Thank you!