[TOOL][WIP] Puzzlescript C++ Wrapper

528 views
Skip to first unread message

Xavier Direz

unread,
Feb 18, 2018, 9:48:16 AM2/18/18
to PuzzleScript
Hi,

I just started to create a C++ wrapper for puzzlescript so everyone could distribute their puzzlescript game as a standalone application.

If someone want to give it a try, the windows version can be downloaded from here: http://lafaceobscuredupixel.fr/puzzlescriptWrapper

And here is the github project: https://github.com/Narkhos/Puzzlescript-Wrapper


I encounter 2 main difficulties to bring the project to the next level:

  1. I tried to emulate puzzlescript sfx generator with the SDL sfxr version but can't make it to generate the same sounds.
  2. The javascript engine I am using is slow. That make real time puzzlescript games really slow if there is a lot of rules.
I need some help to fix the sound engine and to migrate to a more powerfull javascript engine like spidermonkey (I can't get it compiled with mingw) .

So if someone have some suggestion or some motivation, I would be gratefull !

Tell me if this project could be usefull to anyone :)

Thank you


Stephen Lavelle

unread,
Feb 18, 2018, 8:57:00 PM2/18/18
to Xavier Direz, PuzzleScript
the sound engine is based on bfxr rather than sfxr, which has some other wave types and filters that sfxr doesn't have.  There's no C version of bfxr, alas, but it should in principle be possible to compare the js bfxr code to the c sfxr code (stuff like sample rate might be harder to deal with), alas. the basic synth code is very similar though. it should be possible to mod it.

(it might interest you, though it's complicated and incomplete, I was working on a C exporter (going the code-generation route rather than the js interpreter route)  for the games at some point to generate games for the arduboy - https://github.com/increpare/PuzzleScript/blob/arduboy/arduboy/generated.h )

( I guess you don't just want to wrap them with electron and be done with it? :P )

--
You received this message because you are subscribed to the Google Groups "PuzzleScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puzzlescript+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Stephen Lavelle

unread,
Feb 19, 2018, 5:00:46 AM2/19/18
to Xavier Direz, PuzzleScript
the filters are to emulate low bitrate. you might be able to do this directly in sdl without filters (in webaudio in the browse it requires a sample rate of 22k or whatever, whereas I wanted one more around 4k)

2018-02-19 10:03 GMT+01:00 Xavier Direz <xavier...@gmail.com>:
Yes, I added the wave types in sfxr synth function. But I can't get the sound to be smooth. I assumed that this lines in your code

var filter1 = AUDIO_CONTEXT.createBiquadFilter();
// ...
filter1.connect(filter2);
// ...

are the main filters applied to the channel to smooth the sound but I'm not comfortable enough with sound programmation to emulate this with SDL

Like you said, the problem can come from sample rate.

SDL_AudioSpec des;
des.freq = 44100;
des.format = AUDIO_S16SYS; // or AUDIO_S8; or AUDIO_U8; ???

bufferLength = 512; // I tried 8 but the sound tend to be to high and last forever

Your project for arduboy is really interesting, I though a portable game console dedicated to puzzlescript games could be nice !

I don't know electron so I can't tell if it fits my goal. My first step is to run perfectly puzzlescript games as a standalone application. But after that, it will be possible to use game controllers, to inject puzzlescript code (adding levels or moding sprites dynamically for example). And it should not be a big deal to rewrite the display loop in C++ to add some more detailed sprites or using sound files.

To unsubscribe from this group and stop receiving emails from it, send an email to puzzlescript...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Xavier Direz

unread,
Feb 19, 2018, 6:00:59 AM2/19/18
to PuzzleScript
Ok. So 44100 should be correct ? I must have messed up something else... I will investigate.

Thank you for the help :)

Stephen Lavelle

unread,
Feb 19, 2018, 9:29:31 AM2/19/18
to Xavier Direz, PuzzleScript
No, in the older version of PS it was around 4k (you can maybe check older versions of sfxr.js in the github repository to see).  The filters are to make it sound like it's ~4k again even though it's 44k/22k or whatever now.

--

Stephen Lavelle

unread,
Feb 19, 2018, 9:29:51 AM2/19/18
to Xavier Direz, PuzzleScript
Though I'd say, so long as they sound broadly similar that it's ok :)

Xavier Direz

unread,
Feb 22, 2018, 5:53:13 PM2/22/18
to PuzzleScript
I managed to fix part of my audio problem (I messed up with callback function). Now, I have a similar sound but it's much faster than the puzzlescript version. I tried to adjust sample rate, bit depth, fperiod but I can't find any correct setting. I also try to use the old 44k sfxr.js file to generate sound parameters. But the parameters seems to be all the same, I can't ear any difference.

Do you have any idea or advice about this ?

Xavier Direz

unread,
Mar 3, 2018, 5:04:45 PM3/3/18
to PuzzleScript
I played some games with the wrapper and fixed some bugs. Here is the list of the games I successfully tried:

  • Always With The Magnets
  • Death Trap Tango
  • Filler
  • Flying Kick
  • Hack The Net
  • Hungry Kraken
  • Kiris Garden
  • Miss Direction
  • Paint The TownRed
  • Snek
  • Something Penguin Something
  • Space Shoot Em Puzzle
  • Atomix Demake
  • Boats Cars & Trains
  • Al's Egg Roll
  • Insey Winsey Spider
  • Quantum Child minding
  • Jesus Respawns
  • Pivotal
  • Sweet Hints
If you give it a try with one of your games, let me know if you find some bug.

Skalmantas Šimėnas

unread,
Mar 3, 2018, 5:20:30 PM3/3/18
to PuzzleScript
Throws some error if the prelude Youtube line is present, for example in Mirror Isles.

Skalmantas Šimėnas

unread,
Mar 3, 2018, 5:22:15 PM3/3/18
to PuzzleScript
Actually, if you load Mirror Isles (without the youtube line), it doesn't seem to produce any mirrors and one of the islands is deformed?

Skalmantas Šimėnas

unread,
Mar 3, 2018, 5:26:20 PM3/3/18
to PuzzleScript
How do I load games with Unicode characters in it? It seems to dislike Unicode encoded files (crashes).

Skalmantas Šimėnas

unread,
Mar 3, 2018, 6:00:51 PM3/3/18
to PuzzleScript
It very likely has something to do with the fact that the mirror is the backslash character '\', which is often a character that isn't interpreted normally.

Xavier Direz

unread,
Mar 4, 2018, 12:08:38 PM3/4/18
to PuzzleScript
You're right, that was the backslash. It's know fixed. The backslash should know work properly. I also disable the toutube feature in the wrapper to avoid the crash.
Thank you for your help. Tell me if you found anything else :)

leu...@gmail.com

unread,
Oct 2, 2018, 9:34:07 AM10/2/18
to PuzzleScript
On Sunday, February 18, 2018 at 9:48:16 AM UTC-5, Xavier Direz wrote:
> Hi,
>
>
> I just started to create a C++ wrapper for puzzlescript so everyone could distribute their puzzlescript game as a standalone application.
>
>
> If someone want to give it a try, the windows version can be downloaded from here: http://lafaceobscuredupixel.fr/puzzlescriptWrapper
>
>
> And here is the github project: https://github.com/Narkhos/Puzzlescript-Wrapper
>
>
>
>
>
> I encounter 2 main difficulties to bring the project to the next level:
>
>
> I tried to emulate puzzlescript sfx generator with the SDL sfxr version but can't make it to generate the same sounds.The javascript engine I am using is slow. That make real time puzzlescript games really slow if there is a lot of rules.
> I need some help to fix the sound engine and to migrate to a more powerfull javascript engine like spidermonkey (I can't get it compiled with mingw) .
>
>
> So if someone have some suggestion or some motivation, I would be gratefull !
>
>
> Tell me if this project could be usefull to anyone :)
>
>
> Thank you

This is great. I just tested it with my little puzzle game and it works flawlessly. Is this still being developed? It would be great to have a fullscreen option.

Xavier Direz

unread,
Oct 10, 2018, 5:28:34 AM10/10/18
to PuzzleScript


This is great. I just tested it with my little puzzle game and it works flawlessly. Is this still being developed? It would be great to have a fullscreen option.

Thanks, I'm glade to read that it works fine for you.

You can switch to fullscreen by editing the config.xml file. Just set <fullscreen value = "ON">

I currently don't have a lot of spare time but I will probably try to switch to V8 javascript engine for good performances in realtime games in a near future.

The ultimate aim is to allow some extra features:
- game controller support
- multiplayer
- additionnal special layers to add some hud info or feedback (explosion effect, life gauge...)

I'm always looking for someone who knows how to port v8 to mingw or how to port a mingw SDL2/opengl project to visual studio.
Then rewritting the wrapper with v8 will be straightforward and it will allow us to run our realtime puzzlescript games properly.


Xavier Direz

unread,
Oct 5, 2019, 10:31:29 AM10/5/19
to PuzzleScript
Hello,

I finally find the time to rewrite the c++ Puzzlescript Wrapper with google v8 engine and visual studio.

This new version is way faster and have basic game controller support. Real time games are now playable.

You can add some games in ./data/games folder and access game list in the application by hitting 'TAB' key

Be sure to save your game file in UTF8 format if it use special characters or some elements could never show up.



I would be glade to have some feedback about it.

Thanks


leu...@gmail.com

unread,
Oct 5, 2019, 8:01:28 PM10/5/19
to PuzzleScript
I just tested this with my game and so far it is working flawlessly. Although mine is not a real time game but still. I also have an Xbox 360 controller and it seems to work well. Any chance that the analog stick will ever be supported? I know it's not great for these types of games so it's not really that big of a deal. I also noticed that if you press the D-pad on a diagonal it kind of skips quickly and feels a bit awkward. I wonder if there was any way to detect it and just prevent it. Not sure if that would be desired or not, it might also depends on the type of game.

I think the more important features for this would be to provide the ability to an "options" or "settings" choice at the beginning of the game, where players can choose everything that is available in the config.json such as resolution, fullscreen/windowed, sound fx (perhaps sound fx volume as well). That would really transition puzzle script prototypes into games that end-users can interact with in a more desirable way.

Xavier Direz

unread,
Oct 6, 2019, 5:31:50 PM10/6/19
to PuzzleScript
Thank you for your feedback,

I probably can add analog stick support easily but I have to think more about it. I don't know if it could have some drawback due to sensitivity setting for example.

About the diagonal I encounter this problem but can't found a way to fix it. Like you said, I can't tell if there is a beaviour that fit with every game. Perhaps a parameter on this could do the trick ?

Indeed, you are right about the in-game options. The player should not have to deal with the config.json file.

leu...@gmail.com

unread,
Oct 6, 2019, 8:01:11 PM10/6/19
to PuzzleScript
Yeah I agree with everything you said. I think you're doing a fantastic job, keep up the good work. I unfortunately don't have much experience with C++ so I can't really help contribute in terms of coding, but I will certainly try out new features/builds whenever you update it. Thanks for your work!

Xavier Direz

unread,
Oct 11, 2019, 5:21:45 PM10/11/19
to PuzzleScript
Thanks, I'm doing my best :)

Here is a new release fixing bugs with recent games: http://lafaceobscuredupixel.fr/#/labo/puzzlescriptWrapper

- alt+enter to toggle fullscreen.
- integration of puzzlescript version 1.6
- changing background color and window title on game selection

Thanks to Pedropsi for bug reports.

For those who can't access my website for some reason, I created a sourceforge project with the releases : https://sourceforge.net/projects/puzzlescript-wrapper/files/

Pedro PSI

unread,
Oct 12, 2019, 4:35:18 AM10/12/19
to PuzzleScript
It's working like a charm now!
Thank you for the amazing work!!

Xavier Direz

unread,
Nov 2, 2019, 10:33:18 AM11/2/19
to PuzzleScript
I just uploaded a new version (v2.0.2):

https://sourceforge.net/projects/puzzlescript-wrapper/files/

- It's now possible to add music and sound from files (.wav, .ogg, .mp3...)
Music file has to be in ./data/music/ and be named after the youtube id used in your puzzlescript sourcecode.
Sound file has to be in ./data/sfx/ and be named after the seed of the sound you use in your game.

- Sound and music level can be setup in game (the HUD only appear when mouse is moving).
Reply all
Reply to author
Forward
0 new messages