Re: Help playing sounds using arsd.simpleaudio

2019-09-28 Thread Murilo via Digitalmars-d-learn
On Saturday, 28 September 2019 at 14:03:53 UTC, Adam D. Ruppe 
wrote:

On Saturday, 28 September 2019 at 03:21:38 UTC, Murilo wrote:
Can anyone just please show me how to play a background 
sound(like those in games) using arsd.simpleaudio? I'd like 
something simple with a code snippet please.


it is really minimal be warned

but at the beginning of main() set it up with


auto audio = new AudioPcmOutThread();
audio.start();
scope(exit) {
audio.stop();
audio.join();
}


and then when you want it to make sounds, call its functions 
like


audio.beep();

or

audio.playOgg("my-file.ogg");

you can convert things like wav and mp3 into the ogg format 
with various tools of the internet.




that's about all it does.


Thanks. Now, I would like to know if I could just use it like 
this instead:


import arsd.simpleaudio;

void main()
{
AudioPcmOutThread audio = new AudioPcmOutThread;
audio.start;
audio.playOgg("shock.ogg");
audio.join;
audio.stop;
}



Re: How to use Dbus to detect application uniqueness in D?

2019-09-28 Thread Hossain Adnan via Digitalmars-d-learn

On Saturday, 28 September 2019 at 13:37:12 UTC, Kagamin wrote:

https://ddbus.dpldocs.info/ddbus.bus.requestName.html


It requires a Connection type which I cannot find in the API.


Re: Help playing sounds using arsd.simpleaudio

2019-09-28 Thread Murilo via Digitalmars-d-learn
On Saturday, 28 September 2019 at 14:03:53 UTC, Adam D. Ruppe 
wrote:

On Saturday, 28 September 2019 at 03:21:38 UTC, Murilo wrote:
Can anyone just please show me how to play a background 
sound(like those in games) using arsd.simpleaudio? I'd like 
something simple with a code snippet please.


it is really minimal be warned

but at the beginning of main() set it up with


auto audio = new AudioPcmOutThread();
audio.start();
scope(exit) {
audio.stop();
audio.join();
}


and then when you want it to make sounds, call its functions 
like


audio.beep();

or

audio.playOgg("my-file.ogg");

you can convert things like wav and mp3 into the ogg format 
with various tools of the internet.




that's about all it does.


Thank you sooo much. Now it works. That is pretty much what I was 
looking for.


Re: Help making a game with transparency

2019-09-28 Thread Murilo via Digitalmars-d-learn

On Saturday, 28 September 2019 at 05:57:55 UTC, Mike Parker wrote:

On Friday, 27 September 2019 at 22:55:22 UTC, Murilo wrote:
You might consider using SDL and SDL_image:


Thank you very much. But I want to use only the arsd library.


Re: Packaging and Distributing Dlang Applications with GtkD Dependency?

2019-09-28 Thread snow jhon via Digitalmars-d-learn
On Thursday, 26 September 2019 at 10:07:34 UTC, bioinfornatics 
wrote:
On Wednesday, 25 September 2019 at 17:03:51 UTC, Ron Tarrant 
wrote:
On Wednesday, 25 September 2019 at 13:52:48 UTC, 
bioinfornatics wrote:


I think I misunderstood your need but are lo looking for dub 
tool with its repository https://code.dlang.org/


I don't think so, but I could be wrong. I tried reading up on 
dub, but got lost in the docs, so I really don't understand 
what all it can do.


dub is more or less like pip from python, npm from javascript 
and so on ...

The code source is here: https://github.com/dlang/dub

you can open an issue there or open a thread about how to write 
package file for dub doc: https://dub.pm/package-format-json)


have a nice day


To be more precise, gtkd is a wrapper for GTK. Gtkd is not 
interesting in this context, but the dependency on gtk. On 
windows you have the possibility to either publish your 
application with GTK dlls or to run gtk setup routine as part of 
your application setup routine or just say in your readme that 
the customer needs to run GTK setup on there own.




Re: Looking for a Simple Doubly Linked List Implementation

2019-09-28 Thread snow jhon via Digitalmars-d-learn

On Saturday, 21 September 2019 at 18:52:23 UTC, Dennis wrote:
On Saturday, 21 September 2019 at 08:34:09 UTC, Ron Tarrant 
wrote:
Thanks, Dennis. Not performant... It doesn't work? I was 
hoping for a complete, working example, but maybe this'll help.


Bad word choice (it appears it's debatable whether 'performant' 
even is a word), I meant it was a simple implementation not 
optimized for speed / memory efficiency.
Making it 'complete' is a bit hard since I can think of tens of 
methods and operator overloads you could use, but if I include 
them all it's no longer minimal and it just becomes 
std.container.dlist.


Does a doubly-linked list always have to be done with structs? 
Can it be classes instead?


My example originally included classes actually. It was mostly 
the same, except that Node!T* was just Node!T. The only problem 
was with const:


```
size_t length() const {
size_t result = 0;
for(auto a = head; a !is null; a = a.next) result++;
return result;
}

```

Since I marked the method as const, `auto a = head` got the 
type const(Node!T) and `a = a.next` no longer compiled. With 
structs you can declare a const(Node!T)* (mutable pointer to 
const node), but I don't know if I can declare a mutable 
reference to a const class, so I switched to structs.


Below is a simple doubly linked list with Garbage Collected 
memory.
It's not performant or complete by any means, just a minimal 
example in D like you wanted.
You probably also want methods for removing nodes or inserting in 
the middle (else why don't you use an array?), I think you can 
think of an implementation for those yourself (or look them up, 
there should be plenty examples online).


Re: Help making a game with transparency

2019-09-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 28 September 2019 at 08:06:02 UTC, GreatSam4sure 
wrote:
The last time I try this library on windows 10 it throws 
errors. Have you try it recently on windows


What errors? I sometimes break it with careless pushes to master 
but it usually works for me.


I want to know can the windows be customized and does it 
support styling like JavaFX


simpledisplay creates a blank window, what goes in it is entirely 
up to you (you can even do a flag to skip the titlebar if you 
want, though I recommend against that generally as I find it 
user-hostile). There's three ways to draw in it:


1) the basic functions ScreenPainter provides (drawImage, 
drawRectangle, drawLine, etc), none of which do alpha blending 
and probably never will (though they might do mask-based 
single-color transparent pixels at some point when I get around 
to it or if someone sends me a PR). Nothing fancy here.


2) OpenGL functions. The simplewindow constructor can create a 
context for you for various opengl versions. Old style 
glBegin/glEnd is the default and has prototypes included inline. 
Newer style stuff is opt-in and you may need to load functions 
via an additional library (for example, the nanovega.d lib in 
there does this and includes its own vector graphics API, 
including alpha blending btw) or by dynamically loading them 
yourself (all the pieces are in simpledisplay it just doesn't do 
it all by default). These can get as fancy as you want.


3) Operating system functions. You can get at the window 
id/handle via the impl member of the window and hook the native 
event loop, call native functions, etc. to your heart's desire. 
If you do something that is generally useful and can be done at 
reasonable cost on X11 (Windows and Macintosh are both quite 
capable, it is usually X that ends up being the lowest common 
denominator), send me a PR and I might add it to screenpainter's 
api.



If you're looking for UI widgets like buttons and such, again you 
can DIY or my minigui.d contains a bunch of them. But they only 
contain the ones I have personally used so far and only do the 
styles I personally like and can implement cheaply and easily. 
There's no fancy CSS or animations or anything like that. I 
sometimes consider it but I'm personally pretty meh on them so 
don't expect it any time soon.



But if you all want that, on your schedule, smash that like 
button, comment, subscribe, and be sure to ring that bell so you 
get a notification every time I parrot what people say on Youtube 
at the end of their videos. Then head on over my patreon page and 
give me all your money today. If everyone who downloaded my 
libraries contributed just $3 / month, I'd be able to devote 
myself to expanding these libraries to support more use cases.


But until then, I write these for myself (or, in rare cases, 
someone else writes them for me and contributes it like with 
nanovega) so the functionality tend to focus on what I have used 
myself in the past. Then I post them online since it is easy to 
do so... then if you find them useful, great, and if you don't, 
oh well, there's always SDL or gtkD or html5 in electron (LOL) to 
cover more cases.


Re: Help playing sounds using arsd.simpleaudio

2019-09-28 Thread Adam D. Ruppe via Digitalmars-d-learn

On Saturday, 28 September 2019 at 03:21:38 UTC, Murilo wrote:
Can anyone just please show me how to play a background 
sound(like those in games) using arsd.simpleaudio? I'd like 
something simple with a code snippet please.


it is really minimal be warned

but at the beginning of main() set it up with


auto audio = new AudioPcmOutThread();
audio.start();
scope(exit) {
audio.stop();
audio.join();
}


and then when you want it to make sounds, call its functions like

audio.beep();

or

audio.playOgg("my-file.ogg");

you can convert things like wav and mp3 into the ogg format with 
various tools of the internet.




that's about all it does.


Re: Help making a game with transparency

2019-09-28 Thread Mike Parker via Digitalmars-d-learn

On Saturday, 28 September 2019 at 13:41:24 UTC, matheus wrote:
Ok, I took a look over my old projects and I found exactly what 
you want, by the way it's from 2012.


It uses Derelict 2.0 bindings and will draw a PNG image where 
you can move around with cursor keys.


Murilo, if you do decide to use this example as a basis for your 
project, please don't use DerelictSDL2. I'm not maintaining it 
anymore. bindbc-sdl, which I linked in my previous post, is what 
you should prefer. The API to load the library and handle errors 
is different, but the SDL API calls will all be the same.


Re: Help making a game with transparency

2019-09-28 Thread matheus via Digitalmars-d-learn
Ok, I took a look over my old projects and I found exactly what 
you want, by the way it's from 2012.


It uses Derelict 2.0 bindings and will draw a PNG image where you 
can move around with cursor keys.


If you want I can send you the whole project (Makefile, DLL's) 
and everything else to build it.


Code:

/* 02/10/2012 */
import std.stdio;
import derelict.sdl.sdl;
import derelict.sdl.image;

pragma(lib, "DerelictSDL.lib");
pragma(lib, "DerelictUtil.lib");
pragma(lib, "DerelictSDLImage.lib");

void main(){
// Screen width, height and bit per pixel AKA color
int width = 600, height = 480, bpp = 24;
short xPos, yPos;

// Load Derelict SDL bindings
DerelictSDL.load();
DerelictSDLImage.load();

SDL_Surface* screen;
SDL_Rect rScreen;

// Pointing to an Array of the current key state
Uint8 *keystate = SDL_GetKeyState(null);

// Try initiate SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0){
throw new Exception("Failed: Can not initialize SDL!");
}

	screen = SDL_SetVideoMode(width, height, bpp, SDL_ANYFORMAT);// 
SDL_HWSURFACE);


IMG_Init(IMG_INIT_PNG);
auto img = IMG_Load("caco.png");
if(img is null){
throw new Exception("Image not found!");
}

	writeln(" - w: ",img.w, " - h: ", img.h, " - bpp:", 
img.format.BitsPerPixel);


if (screen is null){
throw new Exception("Failed: Can not set video! ");
}

SDL_WM_SetCaption("Simple Example", null);

xPos = cast(short)(width   / 2 - 128);
yPos = cast(short)(height  / 2 - 128);

// Game loop
while(!keystate[SDLK_ESCAPE]){
SDL_Delay(2); // To not stress CPU

// Fill screen with RED
SDL_FillRect(screen, null, 0xFF);

// Update key state array
SDL_PumpEvents();

// User's control
yPos += keystate[SDLK_DOWN]-keystate[SDLK_UP];
xPos += keystate[SDLK_RIGHT]-keystate[SDLK_LEFT];

// Where to plot the image on the screen
rScreen.x = xPos;
rScreen.y = yPos;
rScreen.w = rScreen.h = 256;

SDL_BlitSurface(img,null,screen,); // Draw Image
SDL_Flip(screen); // Update Screen
}
IMG_Quit();
SDL_FreeSurface(img);
SDL_Quit();
}


Matheus.


Re: How to use Dbus to detect application uniqueness in D?

2019-09-28 Thread Kagamin via Digitalmars-d-learn

https://ddbus.dpldocs.info/ddbus.bus.requestName.html


Re: Packaging and Distributing Dlang Applications with GtkD Dependency?

2019-09-28 Thread Ron Tarrant via Digitalmars-d-learn

On Saturday, 28 September 2019 at 08:52:36 UTC, Jordi Sayol wrote:

On Bebian/Ubuntu/Linux Mint, You have "d-apt" 



This sounds so appropriate for a D application. :)

If you static links your d program, you don't need any package 
from it at runtime.
But if you dynamic links it, you've runtime libraries for GtkD 
"libgtkd3-nn" and TkD "libtkd-nn" on "d-apt".
"nn" on library name should be replaced with the DMD major 
version (without initial zero).

i.e. For the last DMD version, "libgtkd3-88" or "libtkd-88".


Thank you for filling in some blanks for me.


Re: Packaging and Distributing Dlang Applications with GtkD Dependency?

2019-09-28 Thread Ron Tarrant via Digitalmars-d-learn
On Saturday, 28 September 2019 at 02:15:42 UTC, Hossain Adnan 
wrote:



For Linux there are 3 new options:

(things omitted)
There are tutorials for using all of those three online, but 
not specific to Dlang. But if you use the Meson build system 
there are plenty of tutorials available.


Thanks Hossian. This helps a lot.


Re: Packaging and Distributing Dlang Applications with GtkD Dependency?

2019-09-28 Thread Ron Tarrant via Digitalmars-d-learn
On Friday, 27 September 2019 at 12:42:56 UTC, Jacob Carlborg 
wrote:


For macOS you should distribute a GUI application for end users 
as an application bundle [1]. That's basically a directory 
containing a specific structure. Any dependencies and resources 
like libraries (GTK), images and so on should be bundled inside 
the application bundle. Then package the application bundle 
inside an archive, ideally a Disk Image (DMG) [2]. The 
application would be completely self contained and the user can 
install it by dragging it to the Application directory.


There might be some specific documentation how to bundle a GTK 
application on macOS. I found this [3], don't know if it's good 
or not.


Ideally the application should be distributed on the Mac App 
Store. But that requires a developer account that costs money. 
It also has some restrictions that distribution outside of the 
Mac App Store doesn't have. If you cannot distribute using the 
Mac App Store the next best thing is to notarize the 
application (also requires a paid developer account, as far as 
I can see) before distributing it. Otherwise the user will get 
a dialog complaining that the application is from an unknown 
developer and the user need to explicitly go into System 
Preferences to allow it.


[1] 
https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/1123i-CH101-SW1


[2] https://en.wikipedia.org/wiki/Apple_Disk_Image
[3] https://gitlab.gnome.org/GNOME/gtk-mac-bundler

--
/Jacob Carlborg


Excellent, Jacob. Thanks for all that.


Re: Packaging and Distributing Dlang Applications with GtkD Dependency?

2019-09-28 Thread bachmeier via Digitalmars-d-learn

On Saturday, 28 September 2019 at 09:00:51 UTC, drug wrote:

28.09.2019 5:15, Hossain Adnan пишет:
On Wednesday, 25 September 2019 at 11:46:04 UTC, Ron Tarrant 
wrote:

Hi y'all,

I've been Googling how to do this, but coming up with nothing 
definitive. Are there any articles for how to do this for:



Linux?


For Linux there are 3 new options:

1. Appimages (https://appimage.org/): This is very similar to 
Window's msi installer. You can host the app installer binary 
in bintray or in your website.


2. Flatpaks (https://flatpak.org/): Flatpak is quickly 
becoming more and more popular as it provides higher level 
customization for desktop applications in Linux. The flatpak 
API is not trivial but there are tutorials available to use 
flatpak and meson. A well known Linux application named Tilix 
(https://github.com/gnunn1/tilix) has a flatpak repo 
(https://github.com/gnunn1/tilix/tree/master/experimental/flatpak).


3. Snap (https://snapcraft.io/): Backed by Cannonical, snap 
provides a really easy way to distribute applications in 
Linux. I personally think Snaps are easier to create although 
I haven't invested time in distributing an app using snap. 
DMD, Dub and LDC are also shipped with it.


There are tutorials for using all of those three online, but 
not specific to Dlang. But if you use the Meson build system 
there are plenty of tutorials available.



don't you consider deb and rpm as options?


My understanding is that the goal is to move away from 
distribution-specific packaging with these projects.


Re: Howto create bindings?

2019-09-28 Thread bachmeier via Digitalmars-d-learn
On Saturday, 28 September 2019 at 09:18:24 UTC, Martin Brezeln 
wrote:

Hello everyone,

i have a rather general question about how to approach the 
attempt to create a binding for a foreign system, for which 
bindings already exists for other languages than dlang.


To be more concrete: There is this Database i am using in some 
recent projects: "Apache Cassandra" / "ScyllaDB" - 
unfortunately, there is no binding for D (afaik "cassandra-d" 
is incomplete and the development stands still).
However, There are some up to date bindings for other 
programming languages 
(https://docs.scylladb.com/using-scylla/scylla_drivers/).


Can someone with experience in this field give some advice?
Would it be possible to use (e.g.) the C++ Project to build 
$SOMETHING for D?
Or would it be better to try to implement it yourself (based on 
a paper or a existing binding)?


Looking forward for an interesting read :)


If this is a C library (I can't really tell for sure from the 
linked page) you can use DStep to automatically create bindings:

https://github.com/jacob-carlborg/dstep

If you don't want bindings, but just want to #include the header 
files, you can use dpp

https://github.com/atilaneves/dpp

For the most part, if you want to use C libraries in a project, 
you shouldn't need to do much work. To do it manually, there's 
this page

https://dlang.org/spec/interfaceToC.html


Howto create bindings?

2019-09-28 Thread Martin Brezeln via Digitalmars-d-learn

Hello everyone,

i have a rather general question about how to approach the 
attempt to create a binding for a foreign system, for which 
bindings already exists for other languages than dlang.


To be more concrete: There is this Database i am using in some 
recent projects: "Apache Cassandra" / "ScyllaDB" - unfortunately, 
there is no binding for D (afaik "cassandra-d" is incomplete and 
the development stands still).
However, There are some up to date bindings for other programming 
languages 
(https://docs.scylladb.com/using-scylla/scylla_drivers/).


Can someone with experience in this field give some advice?
Would it be possible to use (e.g.) the C++ Project to build 
$SOMETHING for D?
Or would it be better to try to implement it yourself (based on a 
paper or a existing binding)?


Looking forward for an interesting read :)


Re: Packaging and Distributing Dlang Applications with GtkD Dependency?

2019-09-28 Thread drug via Digitalmars-d-learn

28.09.2019 5:15, Hossain Adnan пишет:

On Wednesday, 25 September 2019 at 11:46:04 UTC, Ron Tarrant wrote:

Hi y'all,

I've been Googling how to do this, but coming up with nothing 
definitive. Are there any articles for how to do this for:



Linux?


For Linux there are 3 new options:

1. Appimages (https://appimage.org/): This is very similar to Window's 
msi installer. You can host the app installer binary in bintray or in 
your website.


2. Flatpaks (https://flatpak.org/): Flatpak is quickly becoming more and 
more popular as it provides higher level customization for desktop 
applications in Linux. The flatpak API is not trivial but there are 
tutorials available to use flatpak and meson. A well known Linux 
application named Tilix (https://github.com/gnunn1/tilix) has a flatpak 
repo (https://github.com/gnunn1/tilix/tree/master/experimental/flatpak).


3. Snap (https://snapcraft.io/): Backed by Cannonical, snap provides a 
really easy way to distribute applications in Linux. I personally think 
Snaps are easier to create although I haven't invested time in 
distributing an app using snap. DMD, Dub and LDC are also shipped with it.


There are tutorials for using all of those three online, but not 
specific to Dlang. But if you use the Meson build system there are 
plenty of tutorials available.



don't you consider deb and rpm as options?


Re: Packaging and Distributing Dlang Applications with GtkD Dependency?

2019-09-28 Thread Jordi Sayol via Digitalmars-d-learn
El 25/9/19 a les 13:46, Ron Tarrant via Digitalmars-d-learn ha escrit:
> Hi y'all,
> 
> I've been Googling how to do this, but coming up with nothing definitive. Are 
> there any articles for how to do this for:
> 
> Windows?
> Linux?
> other UNIX-alike OSs?

On Bebian/Ubuntu/Linux Mint, You have "d-apt" 

If you static links your d program, you don't need any package from it at 
runtime.
But if you dynamic links it, you've runtime libraries for GtkD "libgtkd3-nn" 
and TkD "libtkd-nn" on "d-apt".
"nn" on library name should be replaced with the DMD major version (without 
initial zero). 
i.e. For the last DMD version, "libgtkd3-88" or "libtkd-88".


Re: Help making a game with transparency

2019-09-28 Thread GreatSam4sure via Digitalmars-d-learn

On Friday, 27 September 2019 at 11:32:53 UTC, Adam D. Ruppe wrote:

On Friday, 27 September 2019 at 11:28:35 UTC, matheus wrote:
Sorry this is a bit vague. I suppose you're using engine.d or 
screen.d directly right?


those two are obsolete, new stuff should use simpledisplay

but with simpledisplay you need to use opengl for transparency 
since the xlib/gdi+ impl doesn't support it (though they 
probably could if someone wanted to write some code)


i just am doing 4 other things at once right now and can't do 
it myself at the moment






The last time I try this library on windows 10 it throws errors. 
Have you try it recently on windows


I want to know can the windows be customized and does it support 
styling like JavaFX


Re: Help making a game with transparency

2019-09-28 Thread Mike Parker via Digitalmars-d-learn

On Friday, 27 September 2019 at 22:55:22 UTC, Murilo wrote:

Ahhh, that clears everything up. I will then leave the program 
without the transparency and wait until you get around to 
implement the fixes to it, I am not a developer, I am a 
scientist, I only use libraries, I don't know how to make them 
properly.


You might consider using SDL and SDL_image:

https://libsdl.org/download-2.0.php
https://www.libsdl.org/projects/SDL_image/

D bindings for both are available here:

https://code.dlang.org/packages/bindbc-sdl

You don't actually *need* SDL_image, as core SDL can load images 
in the BITMAP format, and you can then use the API to create 
transparency from a specific color. But if you want to load PNG 
files with alpha, you'll want SDL_image.


There are numerous tutorials online for SDL, though if you're 
searching, make sure to look for SDL 2 tutorials and ignore 
anything for SDL 1.x.


The tutorials will all be in either C or C++, but the SDL API 
using the D bindings is the same. The Lazy Foo tutorials are 
often recommended:


https://lazyfoo.net/tutorials/SDL/

But again, these are C++, so you have to consider the differences 
in D and C++ when porting the code over. For example, he uses 
class destructors to free resources. Do that in D and you'll run 
into trouble. So just ignore how he structures his programs and 
focus on the main concepts of using SDL: how to acquire/release 
resources, how to render, etc. You can adapt that to any 
architecture you want. There's no need for classes at all, for 
example.


Some tutorials out there will show you how to use SDL with 
OpenGL. Please ignore those. SDL's 2D Rendering API is what you 
want when you're learning, so focus on tutorials tat show you how 
to use it.


The SDL Wiki has API documentation:

http://wiki.libsdl.org/APIByCategory