January 26, 2021, 12:33:31 PM

Author Topic: Modules  (Read 1184 times)

Offline chrisws

  • Jr. Member
  • **
  • Posts: 66
    • SmallBASIC
Modules
« on: November 01, 2020, 02:27:04 AM »
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

Offline round157

  • Sr. Member
  • ****
  • Posts: 407
Re: Modules
« Reply #1 on: November 02, 2020, 03:43:03 PM »
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.


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


Offline chrisws

  • Jr. Member
  • **
  • Posts: 66
    • SmallBASIC
Re: Modules
« Reply #2 on: November 07, 2020, 08:14:13 PM »
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.

Offline round157

  • Sr. Member
  • ****
  • Posts: 407
Re: Modules
« Reply #3 on: November 12, 2020, 08:09:43 AM »
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.

Offline chrisws

  • Jr. Member
  • **
  • Posts: 66
    • SmallBASIC
Re: Modules
« Reply #4 on: November 15, 2020, 12:08:34 AM »
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.





Offline round157

  • Sr. Member
  • ****
  • Posts: 407
Re: Modules
« Reply #5 on: November 19, 2020, 03:21:20 AM »
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.

Offline bplus

  • Full Member
  • ***
  • Posts: 151
Re: Modules
« Reply #6 on: November 26, 2020, 07:26:14 PM »
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.

Offline round157

  • Sr. Member
  • ****
  • Posts: 407
Re: Modules
« Reply #7 on: December 02, 2020, 08:44:07 AM »
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.


Offline chrisws

  • Jr. Member
  • **
  • Posts: 66
    • SmallBASIC
Re: Modules
« Reply #8 on: December 05, 2020, 08:49:32 PM »
I've made a bit more progress with raylib. Here's the SmallBASIC version of physics_demo from the raylib examples.

Code: [Select]
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


Offline round157

  • Sr. Member
  • ****
  • Posts: 407
Re: Modules
« Reply #9 on: December 13, 2020, 02:48:28 PM »
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.

Offline chrisws

  • Jr. Member
  • **
  • Posts: 66
    • SmallBASIC
Re: Modules
« Reply #10 on: January 09, 2021, 10:36:54 AM »
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

Offline round157

  • Sr. Member
  • ****
  • Posts: 407
Re: Modules
« Reply #11 on: January 13, 2021, 12:11:37 AM »
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?


Offline chrisws

  • Jr. Member
  • **
  • Posts: 66
    • SmallBASIC
Re: Modules
« Reply #12 on: January 13, 2021, 11:46:38 PM »
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:

Code: [Select]
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


Offline chrisws

  • Jr. Member
  • **
  • Posts: 66
    • SmallBASIC
Re: Modules
« Reply #13 on: January 16, 2021, 03:16:30 AM »
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!


Offline round157

  • Sr. Member
  • ****
  • Posts: 407
Re: Modules
« Reply #14 on: January 17, 2021, 02:37:05 PM »


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!

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal