A "weak reference" (in the sense that I'm referring to) is a
feature in some programming languages for a reference to an
object that doesn't prevent the GC from destroying that object.
My current understanding is that D doesn't have weak references,
though I've found some posts in this forum
On Wednesday, 8 May 2024 at 12:29:05 UTC, Rene Zwanenburg wrote:
Interestingly enough C# used to have the same behaviour but MS
decided to go for a breaking change in C# 5; now it behaves as
most people expect.
Wow! I wonder if D would be willing to allow such a breaking
change with the
On Monday, 6 May 2024 at 16:41:38 UTC, Steven Schveighoffer wrote:
On Monday, 6 May 2024 at 06:29:49 UTC, Liam McGillivray wrote:
Delegates can be a pain, as they often have results different
from what one would intuitively expect. This can easily result
in bugs.
Here's a line that caused a
Delegates can be a pain, as they often have results different
from what one would intuitively expect. This can easily result in
bugs.
Here's a line that caused a bug that took me awhile to find:
```
foreach(card; unitCards) card.submitted = delegate() =>
selectUnit(card.unit);
```
Each
On Wednesday, 1 May 2024 at 01:24:55 UTC, Lance Bachmeier wrote:
Does filter do what you need?
https://dlang.org/phobos/std_algorithm_iteration.html#.filter
It seems to do it with the following line:
```
allObjects = allObjects.filter!(element => element !is
this).array;
```
So I've found
On Friday, 19 April 2024 at 22:24:17 UTC, Liam McGillivray wrote:
```
template enumMixin(alias Enum) {
static foreach(m; __traits(allMembers, Enum)) static if
(!__traits(isDeprecated, __traits(getMember, Enum, m)))
{
mixin("alias "~m~" = __traits(getMember, Enum, m);");
}
Well, someone on the Discord server has been helping me attempt
this, but while I managed to get a solution that compiles without
errors, I still get the deprecation warning.
Here is what I ended up with:
```
template enumMixin(alias Enum) {
static foreach(m; __traits(allMembers, Enum))
I know that DStep generates CTFE functions to automatically make
aliases for enum members so that the can be used without the enum
name, as is done in C. DStep does it with a CTFE function, though
it should also be possible with a mixin template.
Here is my attempt so far, using a mixin
On Wednesday, 17 April 2024 at 02:39:25 UTC, Paul Backus wrote:
This is called [row polymorphism][1], and it does not exist in
D.
You could approximate it by making `someFunction` a template,
and accepting any type `T` that has the necessary members
instead of only accepting `typeB`. But
I have two structs that serve roughly the same purpose, and I
would like one to be accepted when the other is declared as a
function parameter.
To better understand what I mean, take the following example,
where I have a function, and two structs.
```
struct typeA {
// Some member
On Friday, 12 April 2024 at 15:24:38 UTC, Steven Schveighoffer
wrote:
```d
void InitWindow(int width, int height, ref string title) {
InitWindow(width, height, cast(const(char)*)title);
}
```
This is invalid, a string may not be zero-terminated. You can't
just cast.
Well, it did work
On Tuesday, 9 April 2024 at 12:45:55 UTC, Richard (Rikki) Andrew
Cattermole wrote:
On 09/04/2024 12:48 PM, Liam McGillivray wrote:
I suppose this was a good new thing to learn, though I'm still
quite far from being able to construct a function from another
function using a template.
I
On Tuesday, 9 April 2024 at 23:50:36 UTC, Richard (Rikki) Andrew
Cattermole wrote:
The string mixin triggers CTFE, if ``EnumPrefixes`` wasn't
templated, that would cause codegen and hence error. If you
called it in a context that wasn't CTFE only, it would codegen
even with template and would
On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew
Cattermole wrote:
Unfortunately runtime and CTFE are the same target in the
compiler.
So that function is being used for both, and hence uses GC
(appending).
Are you sure that string appending was really the problem that
On Tuesday, 9 April 2024 at 00:02:02 UTC, Richard (Rikki) Andrew
Cattermole wrote:
```d
enum Value = (a, b) {
return a + b;
}(1, 2);
```
This alone should be a CTFE only function.
But if we want template parameters, we'd need to wrap it with
the template.
```d
template Value(int a,
On Monday, 8 April 2024 at 08:12:22 UTC, Richard (Rikki) Andrew
Cattermole wrote:
```d
template Foo(Args) {
enum Foo = () {
return Args.init;
}();
}
```
Something like that should work instead.
I'm sorry, but I can't comprehend any of your example. What
would be fed into
On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew
Cattermole wrote:
Unfortunately runtime and CTFE are the same target in the
compiler.
:-(
Will this ever be changed?
```d
template Foo(Args) {
enum Foo = () {
return Args.init;
}();
}
```
I'm making a modification to a D binding for a C library. I made
a CTFE function which takes a function declaration with one or
more `const(char)*` or `char*` parameters and makes an overload
that accepts D strings. While this function is only used during
compile time, unfortunately, I have
For my tactical role-playing game, I want to finally implement
items and weapons. These are objects that a `Unit` object can
make use of. Just as tools are often said to be an extension of
their user, I want items to be an extension of the unit who uses
them. I'm trying to figure out how to
On Friday, 29 March 2024 at 01:18:22 UTC, H. S. Teoh wrote:
Take a look at the docs for core.memory.GC. There *is* a
method GC.free that you can use to manually deallocate
GC-allocated memory if you so wish. Keep in mind, though, that
manually managing memory in this way invites
On Thursday, 28 March 2024 at 04:46:27 UTC, H. S. Teoh wrote:
The whole point of a GC is that you leave everything up to it
to clean up. If you want to manage your own memory, don't use
the GC. D does not force you to use it; you can import
core.stdc.stdlib and use malloc/free to your heart's
On Wednesday, 27 March 2024 at 22:14:16 UTC, H. S. Teoh wrote:
What's the definition of this.map, this.faction, and
this.currentTile?
As was said, and can be found on the linked repository, they are
references to class objects.
On Thursday, 28 March 2024 at 01:47:27 UTC, Steven
In my current [game
project](https://github.com/LiamM32/Open_Emblem), [something
strange](https://github.com/LiamM32/Open_Emblem/issues/20) has
happened as of a recent commit. When running `dub test`, all the
unittests appear to pass, but then after the last unittest has
concluded an "Invalid
Unfortunately there's no "edit" option here, but the library I
was referring to is actually "libdparse".
On Thursday, 7 March 2024 at 22:18:40 UTC, Richard (Rikki) Andrew
Cattermole wrote:
There are two ways to do this.
1. Use templates.
https://tour.dlang.org/tour/en/basics/templates
Thank you for teaching me how to do this. This is where I first
learned to use templates in D, and I have been
On Saturday, 23 March 2024 at 04:32:29 UTC, harakim wrote:
* You should probably not do this, but it might give you some
ideas for later. What I would do is make a separate thread for
managing the UI state and push events to that thread through
the mailbox. I have done this once (on my third
On Saturday, 23 March 2024 at 23:59:18 UTC, Liam McGillivray
wrote:
I replaced `destroy(unit)` with `map.deleteUnit(unit)`, and it
solved the problem.
Nevermind. It turns out this was because the call to the Unit
destructor was missing in `Map.deleteUnit`. The segfault happens
whenever a
On Saturday, 23 March 2024 at 04:32:29 UTC, harakim wrote:
This comment points to a symptom of the circular
dependency: //Always set `destroy` to false when calling from
the Unit destructor, to avoid an infinite loop.
I was just doing some work on the AI system, and I had a segfault
every
On Saturday, 23 March 2024 at 04:32:29 UTC, harakim wrote:
You should engineer the system in a way that makes sense to
you. The currency of finishing programs is motivation and that
comes from success and believing you will succeed. If you're
implementing XYZ pattern from someone else, if you
On Friday, 22 March 2024 at 07:34:33 UTC, monkyyy wrote:
Is one option more efficient than the other?
You should probaly do the lazyest thing, factor out your
"ispassable" logic, like what your walking n of 3, n of 8, n of
15? so long as you dont do something insane it will be fast on
a
In the [game I am currently
making](https://github.com/LiamM32/Open_Emblem/blob/master/oe-raylib/source/app.d), I have a `Map` class (actually a combination of an interface & class template, but I'll call it a "class" for simplicity), in which there will probably be only one instance running at a
On Thursday, 21 March 2024 at 16:48:39 UTC, Steven Schveighoffer
wrote:
On Sunday, 17 March 2024 at 00:14:55 UTC, Liam McGillivray
wrote:
As many of you know, I have been trying to write a tactical
role-playing game (a mix of turn-based stategy & RPG) in D.
This is the furthest I have ever
As many of you know, I have been trying to write a tactical
role-playing game (a mix of turn-based stategy & RPG) in D. This
is the furthest I have ever gotten in making an interactive
program from the main function up. Right now, it is not yet
playable as a game, but you can interact with it
On Friday, 15 March 2024 at 17:25:09 UTC, Daniel N wrote:
On Tuesday, 12 March 2024 at 05:38:03 UTC, Liam McGillivray
wrote:
I am in need of a data type for holding direction information;
one of 8 directions on a single axis. They are named in terms
of compass directions. If D had a 4-bit
On Friday, 15 March 2024 at 00:21:42 UTC, H. S. Teoh wrote:
On Thu, Mar 14, 2024 at 11:39:33PM +, Liam McGillivray via
Digitalmars-d-learn wrote: [...]
I tried to rework the functions to use bitwise operations, but
it was difficult to figure out the correct logic. I decided
that it's
On Thursday, 14 March 2024 at 01:58:46 UTC, Richard (Rikki)
Andrew Cattermole wrote:
The cost of an add + increment then a bitwise and is only 2-4
cycles on a Haswell cpu. Depending upon if its working solely
in registers (via inlining) or its operating on ram.
Whereas if you need to do
On Tuesday, 12 March 2024 at 06:38:28 UTC, Richard (Rikki) Andrew
Cattermole wrote:
By taking advantage of integer wrapping and a bitwise and, its
quite a simple problem to solve!
Challenge for the reader: add support for binary operations and
toString support.
Last night I pushed the
On Tuesday, 12 March 2024 at 06:38:28 UTC, Richard (Rikki) Andrew
Cattermole wrote:
By taking advantage of integer wrapping and a bitwise and, its
quite a simple problem to solve!
Challenge for the reader: add support for binary operations and
toString support.
I am in need of a data type for holding direction information;
one of 8 directions on a single axis. They are named in terms of
compass directions. If D had a 4-bit datatype, I would just use
this and do `+=2` whenever I want to change the datatype, but it
doesn't.
Perhaps this would be a
On Sunday, 10 March 2024 at 04:39:33 UTC, Liam McGillivray wrote:
https://github.com/LiamM32/Open_Emblem/tree/templates-interfaces
I will probably merge it into master soon.
I have put up a merge request for these changes I have made to
the library and the Raylib front-end. I would be
I have made a new branch of my project called
"templates-interfaces" which reworks some things, and turns the
Map class into an interface and template. It is now functioning
like the master branch, but I think the code should now be
(arguably) easier to follow. At least that's true for the
Update on two things:
One is that I now better understand what it means that D objects
are "reference by default". This means that references *can* be
null if they are declared with a class. In my commits last night,
I have changed many pointers into references. I think my time
will be
On Saturday, 9 March 2024 at 07:49:52 UTC, Liam McGillivray wrote:
But that begs the question; why? Don't dynamic arrays always
start with a length of 0? If the array was only extended when
valid objects were appended using the append operator `~=`, and
none of those objects were deleted (as I
On Saturday, 9 March 2024 at 06:37:02 UTC, Richard (Rikki) Andrew
Cattermole wrote:
Something that I have noticed that you are still doing that was
pointed out previously is having a pointer to a class reference.
Stuff like ``Tile* currentTile;`` when it should be ``Tile
currentTile;``
A
With [my game project](https://github.com/LiamM32/Open_Emblem), I
have been getting segmentation faults that are unexplainable at
my knowledge level. They seem to happen when doing a "foreach"
loop through an array of references.
Skip to the bolded text if you don't want to read too much, as
On Friday, 8 March 2024 at 16:54:48 UTC, cc wrote:
If you don't want Unit to be a template, you can just have Map
derive from a basic interface or abstract class. You can also
have every relevant class share similar templates, you just
need to remember to supply the template arguments
On Friday, 8 March 2024 at 03:19:59 UTC, Richard (Rikki) Andrew
Cattermole wrote:
On 08/03/2024 4:09 PM, Liam McGillivray wrote:
Thank you. Is this first example you gave the template? Is the
syntax `(ATile : Tile)` saying that ATile must be a derived
class of Tile? If this isn't worse in
On Thursday, 7 March 2024 at 22:18:40 UTC, Richard (Rikki) Andrew
Cattermole wrote:
There are two ways to do this.
1. Use templates.
https://tour.dlang.org/tour/en/basics/templates
2. Use a factory function.
https://tour.dlang.org/tour/en/basics/delegates
```d
class Map(ATile : Tile) {
In a source library written in D, is it possible to have some
objects, variables, pointers etc which are determined by the
program using the library?
An example of where this would be useful is in the library I am
currently writing. I have a class called `Map`, which holds an
array of
There's something that I'm trying to do that D may or may not be
capable of.
In the Map class, there is a 2-dimensional array called `grid`,
where the Tile objects are stored. The Mission class inherits the
Map class.
In the Mission class, I want the `grid` array to instead be
composed of
I have made some progress on this. For the raylib front-end, I
tried making a class called `Mission` which inherits `Map`. This
class handles the graphics, input, and other game events. The
program now compiles without errors, and there are some graphics.
I have pushed these updates to the
I now have the Raylib functions working by using `toStrinz`.
I pushed some updates to the repository. I made the main project
a source library so that I can experiment with different graphics
library front-ends. I put have the front-end using Raylib in the
`raylib_frontend` directory. It
There's something very strange going on when using Raylib-D.
I tried using the raylib function `LoadTexture` like this:
```
tileSprites[i] = LoadTexture("../sprites/" ~ spriteName);
```
I got the following error:
```
Error: function `raylib.LoadTexture(const(char)* fileName)` is
not callable
In D, it appears that dynamic arrays (at least by default) use a
ulong as their key type. They are declared like this:
```
string[] dynamicArray;
```
I imagine that using a 64-bit value as the key would be slower
than using 32 bits or 16 bits, and 64 bits is way overkill for
nearly
On Tuesday, 27 February 2024 at 03:43:56 UTC, Liam McGillivray
wrote:
Raylib looks promising. I installed it along with your
Raylib-d. I managed to build the example you provided with dub,
but trying to use it in it's own dub project in a separate
directory isn't working. Just copying and
On Tuesday, 27 February 2024 at 03:06:19 UTC, Steven
Schveighoffer wrote:
If you are going for game development, I would recommend
raylib-d (https://code.dlang.org/packages/raylib-d), which is
my wrapper around the very good raylib library.
For doing GUI, raygui is supported, but I also can
I don't know whether I should continue this topic or start a new
one now that the problem mentioned in the title is fixed. I have
now uploaded some of the code to [a GitHub
repository](https://github.com/LiamM32/Open_Emblem).
To make this game usable, I will need a library for graphics and
On Sunday, 25 February 2024 at 03:23:03 UTC, Paul Backus wrote:
You can't give a class the same name as the file it's in. If
you do, then when you try to use it from another file, the
compiler will get confused and think you're referring to the
file instead of the class (that's what "import is
On Saturday, 24 February 2024 at 10:34:25 UTC, Richard (Rikki)
Andrew Cattermole wrote:
A few things.
Module names should be lower case.
I capitalised the first letter in the class names so that I can
make instances of them in lowercase. Should I rename the classes,
modules, and filenames
I am trying to make a tactical role-playing game which I am
likely to open-source. Right now the code is very simple, with
only 3 files each containing a class with the same name.
The files are `Map.d`, `Tile.d`, and `Unit.d`. Each of these
files contains an `import` line to access one of the
60 matches
Mail list logo