D game engine -- Any suggestions?

2013-11-20 Thread Mineko
Yo, I'm starting off a new game engine designed around D, and I 
just wanted to know if some of you might be kind enough to review 
some of my base code and tell me if I need to change anything in 
it.. While it's small. ;_;


I'm still learning D, I quite like it, the power of C++ in some 
parts, and the ease of Java in others. (Good job Walter!)


Anyway here, check it out, only ones you really need to pay 
attention to are main.d, time.d, and input.d.


https://github.com/ICGCC/Breaker-3D-Game-Engine

Thanks for helping out a newbie, and if you want to contribute to 
it, even better!


..That and if I'm using the GPL right. >_>"


Re: Linking to a library via the linker on Windows?

2013-11-20 Thread Jeremy DeHaan

On Wednesday, 20 November 2013 at 07:47:39 UTC, Ali Çehreli wrote:

On 11/19/2013 11:18 PM, Jeremy DeHaan wrote:
Like I said in the title, this is related to Windows. 
Basically, I'm
looking to put a command line together to keep things 
consistent between

Windows, OSX and Linux.

On OSX and Linux I would do -L-lLibraryName, but is there 
something
similar that one can do on Windows? Or do I have to add 
LibraryName.lib

to the file list? Just wondering!


It looks like it is -L on Windows as well:

  http://dlang.org/dmd-windows.html

Ali


The -L switch is just for sending switches to the linker. On OSX 
and Linux, it is -L-lLibraryName, like I mention before, where 
-lLibraryName is what actually gets passed to the linker. 
Basically I'm wondering of Optlink has a switch that does the 
same thing as the -l switch for linking to a library.


Re: D game engine -- Any suggestions?

2013-11-20 Thread ponce

On Wednesday, 20 November 2013 at 07:48:21 UTC, Mineko wrote:
Yo, I'm starting off a new game engine designed around D, and I 
just wanted to know if some of you might be kind enough to 
review some of my base code and tell me if I need to change 
anything in it.. While it's small. ;_;


I'm still learning D, I quite like it, the power of C++ in some 
parts, and the ease of Java in others. (Good job Walter!)


Anyway here, check it out, only ones you really need to pay 
attention to are main.d, time.d, and input.d.


https://github.com/ICGCC/Breaker-3D-Game-Engine

Thanks for helping out a newbie, and if you want to contribute 
to it, even better!


..That and if I'm using the GPL right. >_>"


- Well for a start, 600 lines of license headers is a bit too 
much. You can just refer to your license file in a two-line 
header (+copyright).


- PI is defined in std.math

- a class is public by default unless noted otherwise, unlike Java



Red-Black tree storing color without additional memory requirements

2013-11-20 Thread simendsjo
Wikipedia states that the color bit can be stored without taking 
additional space: "In many cases the additional bit of 
information can be stored at no additional memory cost."


Looking at the Phobos implementation, it stores it as a regular 
byte: 
https://github.com/D-Programming-Language/phobos/blob/master/std/container.d#L4945


The only way I can see it storing a bit without taking additional 
space is by storing the color in the pointer to a node instead of 
in the node by using the tagged pointer trick: 
http://en.wikipedia.org/wiki/Pointer_tagging


But I would think this trick would break the GC, as well as 
making code less portable.


So.. Is the RBTree article a bit off here, or are there other 
techniques to reduce memory overhead?


Re: D game engine -- Any suggestions?

2013-11-20 Thread simendsjo

On Wednesday, 20 November 2013 at 07:48:21 UTC, Mineko wrote:
(...)

..That and if I'm using the GPL right. >_>"


Do you really plan on using 677 lines per file on the license 
header..?


Re: D game engine -- Any suggestions?

2013-11-20 Thread Paulo Pinto

On Wednesday, 20 November 2013 at 07:48:21 UTC, Mineko wrote:
Yo, I'm starting off a new game engine designed around D, and I 
just wanted to know if some of you might be kind enough to 
review some of my base code and tell me if I need to change 
anything in it.. While it's small. ;_;


I'm still learning D, I quite like it, the power of C++ in some 
parts, and the ease of Java in others. (Good job Walter!)


Anyway here, check it out, only ones you really need to pay 
attention to are main.d, time.d, and input.d.


https://github.com/ICGCC/Breaker-3D-Game-Engine

Thanks for helping out a newbie, and if you want to contribute 
to it, even better!


..That and if I'm using the GPL right. >_>"


You don't need to include the full GPL license in each file. Look 
here for an example.


https://github.com/pjmlp/queue-d

Don't use the legacy OpenGL functions. Fixed pipeline is dead.

--
Paulo


Re: D game engine -- Any suggestions?

2013-11-20 Thread Rene Zwanenburg

On Wednesday, 20 November 2013 at 07:48:21 UTC, Mineko wrote:
Yo, I'm starting off a new game engine designed around D, and I 
just wanted to know if some of you might be kind enough to 
review some of my base code and tell me if I need to change 
anything in it.. While it's small. ;_;


I'm still learning D, I quite like it, the power of C++ in some 
parts, and the ease of Java in others. (Good job Walter!)


Anyway here, check it out, only ones you really need to pay 
attention to are main.d, time.d, and input.d.


https://github.com/ICGCC/Breaker-3D-Game-Engine

Thanks for helping out a newbie, and if you want to contribute 
to it, even better!


..That and if I'm using the GPL right. >_>"


Hi,

A few things jumped out at me:

Camera.d:

- The use of x, y, z and rx, ry, rz. These should really be in 
some vector struct. Since you're using Dub, you can easily use 
gl3n [1][2]. While it's still pretty basic, should be more than 
enough to get you started.


- Use Quaternions to store your rotations instead of euler angles.

- You can use @property instead of trivial getters and setters

- You may want to store your camera matrices in the camera class, 
and pass them to OpenGL when rendering. These matrices can be 
useful, and you don't want to use glGet* functions ever if you 
care about performance ;). gl3n provides matrix structs and 
facilities to create projection matrices and the like.


Oops, I have to run.. Will take a look at the rest later.

[1] http://dav1dde.github.io/gl3n/index.html
[2] http://code.dlang.org/packages/gl3n


Re: pure-ifying my code

2013-11-20 Thread Kenji Hara
On Monday, 18 November 2013 at 19:52:42 UTC, Jonathan M Davis 
wrote:

On Monday, November 18, 2013 19:16:11 Daniel Davidson wrote:

On Sunday, 17 November 2013 at 10:56:16 UTC, Jonathan M Davis

wrote:
> I think that the typical approach at this point is to just 
> drop

> purity for the
> moment, but if you want you really want it, you are indeed
> going to have to
> implement it yourself. But we'll get there with Phobos
> eventually. The primary
> holdup is some compiler improvements, and we'll get them. 
> It's

> just a question
> of when.
> 
> - Jonathan M Davis


Why is it that compiler improvements are the holdup? Honest
question. Is it more that the approach taken for the specific
implementation went beyond the capabilities of the compiler at
the time (like its inferencing capabilities)? Maybe purity was
not a focus at the time of writing a lot of phobos and there 
are

not loads of testing on it where purity was a factor.


Attribute inferrence was added to the language specifically in 
order to make it
possible for pure, nothrow, and @safe to work with templates 
and therefore
make it possible to use them with Phobos. Without it, they 
don't, because
you're stuck either requiring a specific set of attributes 
(limiting what the
templates work with) or duplicating the templates with 
different combinations
of attributes. We got enough attribute inferrence to reduce the 
problem, but
the feature has yet to be implemented enough to fully fix the 
problem. It's
compiler improvements which made using pure with std.algorithm 
possible at

all.


If so,
isn't an alternative implementation now an improvement over
waiting for the compiler updates. A corollary question would be
are the benefits of Voldermort types in phobos worth the purity
issues they cause?


Voldemort types are just part of the problem. Attribute 
inferrence is just
plain too primitive right now, and really needs to be improved. 
The problem is

reduced if you don't used Voldemort types, but it's not fixed.


Noble goal - maybe. But maybe not as noble as users' efforts to
realize benefits of purity now. Purity/const/immutable when
broken spread virally.


It's also the case that none of that has ever worked with pure, 
so we haven't
lost anything. We just haven't yet gained what we should have 
gained. But the
push really needs to be to improve the compiler IMHO, because 
without that,
attribute inferrence in general just isn't going to be good 
enough, and if
Phobos' current situation highlights how poor the attribute 
inferrence is, all

the better, because that puts more pressure on getting it fixed.

Some of the newer functions have not used Voldemort types in 
order to fix
similar problems, but I don't think that it's worth going and 
changing them
all just to work around a problem with the compiler. The 
compiler needs to be
fixed. At best, what you're talking about doing is contorting 
Phobos'
implementation in order to make it work better with the 
half-implemented
feature of attribute inferrence, but since it's that feature 
that makes it
possible at all, and it really needs to be fully implemented 
regardless, it
makes by far the most sense IMHO to just finish implementing 
it. But when that
happens is up to the compiler devs, and at this point, I'm a 
library dev, not

a compiler dev.

- Jonathan M Davis



I opened a new pull request to fix the compiler issue.

https://github.com/D-Programming-Language/dmd/pull/2832

Kenji Hara


Re: Red-Black tree storing color without additional memory requirements

2013-11-20 Thread bearophile

simendsjo:


But I would think this trick would break the GC,


If the tree manages its memory manually, using C heap memory, 
then the pointer tagging becomes possible.


Bye,
bearophile


Re: returning different types via function

2013-11-20 Thread bearophile

Meta:


import std.typecons;

Nullable!(string[]) func(string[] zz) pure nothrow
{
return Nullable!(string[])();
}

void main()
{
//AssertError thrown for trying to get
//a value that is null. Might as well
//return null at this point
auto x = func(["test"]) ~ ["test"];
}




This code doesn't throw, so the behavour is different:

string[] func(string[] zz) pure nothrow {
 return []; // This calls the runtime!
}
void main() {
 auto x = func(["test"]) ~ ["test"];
}


In this case you are saying that an empty string[] is a correct
output for func, while in the case with Nullable you are saying
that it can't return an empty result.

But I agree that the design of a language like Whiley is better,
with its Flow Typing:
http://whiley.org/guide/typing/flow-typing/

In such case Whiley forces you to analyse the return of func(),
and after the analysis the type of such return value changes
according to if the branch you are seeing. So exceptions happen,
and less programmer mistakes.

Bye,
bearophile


Re: D game engine -- Any suggestions?

2013-11-20 Thread Rene Zwanenburg
On Wednesday, 20 November 2013 at 09:15:41 UTC, Rene Zwanenburg 
wrote:

Hi,

A few things jumped out at me:

Camera.d:

...

Oops, I have to run.. Will take a look at the rest later.


Still regarding camera.d:

- The glfw3 import appears to be unused and can be removed.

- the call to Math.perspectiveGL modifies OpenGL state. Your math 
functions _really_ shouldn't interact with OpenGL.


- Taking the previous point a bit further, your Camera class 
doesn't need to know about OpenGL either. In your rendering 
routine, get the camera matrices from a camera and pass them to 
OpenGL.


- Like Paulo said, don't use the fixed function pipeline. If 
you're not familiar with 3D yet the FFP is easier to use at 
first, but using modern OpenGL will pay for itself in the long 
run. I don't know where to find a good introduction to modern 
OpenGL though, perhaps someone else around here..


- rotate, move are unnecessary. Once you switch to gl3n, move 
becomes:

camera.position += someVector;
Same thing with rotate, only you multiply:
camera.rotation *= someQuaternion;


math.d:

- D allows free functions. There's no need to use hacks like 
completely static classes. You can remove the Math class and put 
it's functions in the module.


- I'd also make std.math a public import, so you only have to 
import your math to get both in another module.


- perspectiveGL doesn't belong here, but this is fixed by using 
gl3n.



time.d

- Same thing with the statics as in math. Though personally I'd 
call Time Timer, and make instances. You'll probably want to have 
more than one timer.


- Sleeping doesn't belong in the timer. It should only calculate 
total running time and delta time in update. Later on you'll 
probably find out it needs more features, but these two will be 
fine for now. If anywhere, sleeping belongs in the game loop. 
That being said I'd advise against sleeping at all. It's usually 
better to use vsync, or run at max fps if the user disables it.



That's all I could find during a quick peek.. If you'd like me to 
clarify some of these points, please don't hesitate to ask!


Re: Alocating memory depending of a variable value INT variable

2013-11-20 Thread Namespace

On Wednesday, 20 November 2013 at 00:02:42 UTC, bearophile wrote:

Ali Çehreli:


That is a VLA.


That are currently not present in D. The most common and safe 
alternatives in D are allocating the memory on the heap with 
'new', or over-allocating on the stack a fixed size and then 
slicing.


That's why I use a Stack and a Heap struct in combination with an 
Array struct:

Heap heap;
Stack stack;
byte[] arr = Array!byte(&stack, &heap).of(Num);
or even more naturally:
byte[] arr = Array!byte(&stack, &heap)[Num];

Stack has a buffer of e.g. 4096 and tries to allocate there, if 
it fails, it returns null. If this happens, the Heap struct 
allocates on the GC or C heap.
And if the Stack / Heap struct gets destroyed, the stored memory 
is freed.


But VLA's were really desirable. :(



Re: pure-ifying my code

2013-11-20 Thread Jonathan M Davis
On Wednesday, November 20, 2013 10:20:35 Kenji Hara wrote:
> I opened a new pull request to fix the compiler issue.
> 
> https://github.com/D-Programming-Language/dmd/pull/2832

Yay! Go Kenji. I don't know what we'd do without you.

- Jonathan M Davis


typedef '?

2013-11-20 Thread seany

is typedef gone?
http://forum.dlang.org/thread/aqsjjrtzfzslcopab...@forum.dlang.org?page=2

so If I want to define a new type as typedef string[] 
surrealNumber, then it does not work?


Re: typedef '?

2013-11-20 Thread evilrat

On Wednesday, 20 November 2013 at 10:49:19 UTC, seany wrote:

is typedef gone?
http://forum.dlang.org/thread/aqsjjrtzfzslcopab...@forum.dlang.org?page=2

so If I want to define a new type as typedef string[] 
surrealNumber, then it does not work?


it is replaced with alias.
so for ur case this would looks like "alias string[] 
surrealNumber;" or "alias surrealNumber = string[];"


Entry point pqueue_size in libeay32.dll did not founded

2013-11-20 Thread Suliman

Here is my code: http://www.everfall.com/paste/id.php?1si5bl7yymec

It's compile ok, but when I run App. I got next error: "Entry 
point pqueue_size in libeay32.dll did not founded"


I had download OpenSSL, and put this lib to system32 and App 
folder. And it's did not help.


mixed type list?

2013-11-20 Thread seany
Is there any way to represent mixed data (of various types) as a 
single array?


In scilab, we have list, and you can do list(integer, stringvar 
) etc.


Can you do something similar in D?  An idea is to use a struct 
wil all possible data types, but think that is inefficient.


Any other ideas?


Re: typedef '?

2013-11-20 Thread bearophile

seany:


is typedef gone?
http://forum.dlang.org/thread/aqsjjrtzfzslcopab...@forum.dlang.org?page=2


Right.


so If I want to define a new type as typedef string[] 
surrealNumber, then it does not work?


There is a Typedef implemented in Phobos. In some cases it works, 
but it's still buggy (search for it in Bugzilla if you want to 
know).


Bye,
bearophile


Re: mixed type list?

2013-11-20 Thread QAston

On Wednesday, 20 November 2013 at 11:07:27 UTC, seany wrote:
Is there any way to represent mixed data (of various types) as 
a single array?


In scilab, we have list, and you can do list(integer, stringvar 
) etc.


Can you do something similar in D?  An idea is to use a struct 
wil all possible data types, but think that is inefficient.


Any other ideas?


You can use an array of http://dlang.org/phobos/std_variant.html .


Re: mixed type list?

2013-11-20 Thread Jonathan M Davis
On Wednesday, November 20, 2013 12:07:25 seany wrote:
> Is there any way to represent mixed data (of various types) as a
> single array?
> 
> In scilab, we have list, and you can do list(integer, stringvar
> ) etc.
> 
> Can you do something similar in D?  An idea is to use a struct
> wil all possible data types, but think that is inefficient.
> 
> Any other ideas?

That sounds more like a tuple rather than a list, as lists normally are 
supposed to contain values which all have the same type. So, the normal thing 
to do would probably be to use std.typecons.Tuple. e.g.

auto t = tuple(1, 3.7, "foo");

But that's definitely a tuple and not a list, so you can't append to it or 
remove anything from it or anything like that. If you want an actual list, you 
need a way to make all of the items in the list be the same type. And if they 
don't all share a base type (which pretty much only happens with classes), 
then you'd probably have to use std.variant.Variant, which is essentially a 
typed union. However, I'd advise against using anything like that unless you 
actually need it. You should favor static typing as much as possible rather 
than trying to hold differing types in the same list, as that's just begging 
for bugs, particularly when you then try and use some of those items as a type 
other than what they are.

- Jonathan M Davis


Re: typedef '?

2013-11-20 Thread Dicebot

On Wednesday, 20 November 2013 at 10:54:31 UTC, evilrat wrote:

On Wednesday, 20 November 2013 at 10:49:19 UTC, seany wrote:

is typedef gone?
http://forum.dlang.org/thread/aqsjjrtzfzslcopab...@forum.dlang.org?page=2

so If I want to define a new type as typedef string[] 
surrealNumber, then it does not work?


it is replaced with alias.
so for ur case this would looks like "alias string[] 
surrealNumber;" or "alias surrealNumber = string[];"


Those are not equivalent. Alias does not create new type.


Re: D game engine -- Any suggestions?

2013-11-20 Thread Mike Parker

On 11/20/2013 4:48 PM, Mineko wrote:



Thanks for helping out a newbie, and if you want to contribute to it,
even better!



You don't need to list derelict-util as a dependency in your 
package.json. The other Derelict packages already depend on it so it 
will be pulled in anyway.




Re: Linking to a library via the linker on Windows?

2013-11-20 Thread Mike Parker

On 11/20/2013 5:01 PM, Jeremy DeHaan wrote:


The -L switch is just for sending switches to the linker. On OSX and
Linux, it is -L-lLibraryName, like I mention before, where -lLibraryName
is what actually gets passed to the linker. Basically I'm wondering of
Optlink has a switch that does the same thing as the -l switch for
linking to a library.


I don't believe there is anything like that. You just pass the lib name.

dmd foo.d bar.lib

You also pass a library path like so:

dmd foo.d bar.lib -L+../path/to/libs

This difference between Windows and other platforms creates a minor 
annoyance when making cross-platform build scripts for D (which, since 
dub came along, I don't worry about anymore). I vaguely recall a 
discussion around here somewhere about having DMD hide all of that 
behind a uniform syntax on the command line, for the library stuff at 
least. But it obviously didn't go anywhere.


Re: std.json

2013-11-20 Thread Craig Dillabaugh

On Monday, 26 March 2012 at 07:14:50 UTC, Ali Çehreli wrote:

On 03/25/2012 08:26 AM, AaronP wrote:
Could I get a "hello, world" example of parsing json? The docs 
look

simple enough, but I could still use an example.


For what it's worth, I've just sent the following program to a 
friend before seeing this thread.


1) Save this sample text to a file named "json_file"

{
  "employees": [
 { "firstName":"John" , "lastName":"Doe" },
 { "firstName":"Anna" , "lastName":"Smith" },
 { "firstName":"Peter" , "lastName":"Jones" }
  ]
}

2) The following program makes struct Employee objects from 
that file:


import std.stdio;
import std.json;
import std.conv;
import std.file;

struct Employee
{
string firstName;
string lastName;
}

void main()
{
// Assumes UTF-8 file
auto content = to!string(read("json_file"));

JSONValue[string] document = parseJSON(content).object;
JSONValue[] employees = document["employees"].array;

foreach (employeeJson; employees) {
JSONValue[string] employee = employeeJson.object;

string firstName = employee["firstName"].str;
string lastName = employee["lastName"].str;

auto e = Employee(firstName, lastName);
writeln("Constructed: ", e);
}
}

The output of the program:

Constructed: Employee("John", "Doe")
Constructed: Employee("Anna", "Smith")
Constructed: Employee("Peter", "Jones")

Ali


So I was thinking of adding an example to the std.json documents,
and was going to ask to rip-off Ali's example here.  However, I
thought I would be nice to have an example going the other way
(ie. taking some data structure and converting to JSON format).
I came up with the following using Ali's Employee struct:

/**
  * Generate a JSON string from an array of employees using
std.json,
  * even though the code to generate the same by hand would be
shorter
  * and easier to follow :o)
  */
string employeesToJSON( Employee[] employees )
{
 JSONValue emp_array;
 emp_array.type = JSON_TYPE.ARRAY;
 emp_array.array = [];

 foreach( e; employees ) {
JSONValue emp_object;
emp_object.type = JSON_TYPE.OBJECT;
emp_object.object = null;

JSONValue first_name;
first_name.str = e.firstName;
first_name.type = JSON_TYPE.STRING;

JSONValue last_name;
last_name.str = e.lastName;
last_name.type = JSON_TYPE.STRING;

emp_object.object["firstName"] = first_name;
emp_object.object["lastName"] = last_name;

emp_array.array ~= emp_object;
 }

 JSONValue root;
 root.type = JSON_TYPE.OBJECT;
 root.object[""] = emp_array;

 return toJSON( &root );
}

Then if I call it using the following code:

Employee[] employees =  [ { "Walter", "Bright" },
  { "Andrei", "Alexandrescu"},
  { "Celine", "Dion" } ];

writeln( employeesToJSON( employees ) );

It prints out:

{"":[{"lastName":"Bright","firstName":"Walter"},{"lastName":"Alexandrescu","firstName":"Andrei"},{"lastName":"Dion","firstName":"Celine"}]}

Which isn't exactly what I want as I have the extra "" at the
start.

So I have two questions:

1. Is there a nicer way to generate my JSONValue tree.

2. How do I insert my JSONValue.array of employees into my root
JSONValue.
I tried:
   root.object[""] = emp_array; // generates { "": [ ... }
   root.object[null] = emp_array; // generates { "": [ ... }
   root.object = emp_array; //Syntax error
 //Error: cannot implicitly convert expression
 //(emp_array) of type JSONValue to JSONValue[string]
I want my returned string as { [ ... ] }

Cheers,

Craig






Re: std.json

2013-11-20 Thread Dicebot
For tasks that imply conversion between D types and JSON text 
(alike to serialization), vibe.d module is really much superior 
because it provides functions like 
http://vibed.org/api/vibe.data.json/serializeToJson which "just 
work" on many user types.


Re: std.json

2013-11-20 Thread Craig Dillabaugh

On Wednesday, 20 November 2013 at 13:20:48 UTC, Dicebot wrote:
For tasks that imply conversion between D types and JSON text 
(alike to serialization), vibe.d module is really much superior 
because it provides functions like 
http://vibed.org/api/vibe.data.json/serializeToJson which "just 
work" on many user types.


I absolutely agree.  However, I wanted to come up with an example
for std.json, and this mess was the best I could do.  I was
curious if someone could come up with a nicer mess than mine.

Also for small jobs it might be preferable to use std.json - if
you don't want the vibe.d dependency.


Re: std.json

2013-11-20 Thread Dicebot
What I mean is that std.json does not seem to be written with 
such usage mode in mind, it is more about direct DOM 
manipulation/construction. So probably examples should probably 
not highlight how bad it is at tasks it is really bad at :P


Re: std.json

2013-11-20 Thread Craig Dillabaugh

On Wednesday, 20 November 2013 at 13:29:54 UTC, Dicebot wrote:
What I mean is that std.json does not seem to be written with 
such usage mode in mind, it is more about direct DOM 
manipulation/construction. So probably examples should probably 
not highlight how bad it is at tasks it is really bad at :P


So I was basically wasting my time trying to figure out how to
drive a nail with a screwdriver :o)


Re: Red-Black tree storing color without additional memory requirements

2013-11-20 Thread safety0ff

On Wednesday, 20 November 2013 at 08:48:33 UTC, simendsjo wrote:
But I would think this trick would break the GC, as well as 
making code less portable.


Since the GC supports interior pointers, I think you can justify 
using the least significant bits as long as the size and 
alignment of the pointed object guarantee that the pointer + tag 
will always lie inside the memory block.


Re: std.json

2013-11-20 Thread Orvid King
On 11/20/13, Craig Dillabaugh  wrote:
> On Wednesday, 20 November 2013 at 13:29:54 UTC, Dicebot wrote:
>> What I mean is that std.json does not seem to be written with
>> such usage mode in mind, it is more about direct DOM
>> manipulation/construction. So probably examples should probably
>> not highlight how bad it is at tasks it is really bad at :P
>
> So I was basically wasting my time trying to figure out how to
> drive a nail with a screwdriver :o)
>

But driving a nail with a screwdriver works very well! Or at least it
does if you have a large enough screwdriver :P

Regardless, if your looking to avoid the vibe.d dependency, my
serialization framework does support JSON, and still has the simple
API that vibe.d's module does.
https://github.com/Orvid/JSONSerialization


Re: D game engine -- Any suggestions?

2013-11-20 Thread Mineko

Wow!

You guys are really helpful, I wouldn't have thought about a lot 
of that, I'll pounce on all of this right after breakfast! 
Thanks! :D


Re: Red-Black tree storing color without additional memory requirements

2013-11-20 Thread bearophile

safety0ff:

Since the GC supports interior pointers, I think you can 
justify using the least significant bits as long as the size 
and alignment of the pointed object guarantee that the pointer 
+ tag will always lie inside the memory block.


From:
http://dlang.org/garbage.html

Do not take advantage of alignment of pointers to store bit 
flags in the low order bits:


Bye,
bearophile


Re: D game engine -- Any suggestions?

2013-11-20 Thread Henning Pohl
Feel free to take a look at https://github.com/hpohl/ext/. Maybe 
you can find something useful.


Re: Entry point pqueue_size in libeay32.dll did not founded

2013-11-20 Thread Suliman

On Wednesday, 20 November 2013 at 11:00:07 UTC, Suliman wrote:
Here is my code: 
http://www.everfall.com/paste/id.php?1si5bl7yymec


It's compile ok, but when I run App. I got next error: "Entry 
point pqueue_size in libeay32.dll did not founded"


I had download OpenSSL, and put this lib to system32 and App 
folder. And it's did not help.


I can't reproduce error on Windows 7 machine. Probably it's issue 
with installation of DMD on XP.


Re: D game engine -- Any suggestions?

2013-11-20 Thread Geancarlo Rocha
You should fix your LICENSE following these instructions 
http://www.gnu.org/licenses/gpl-howto.html. I hope you understand 
the virality of GPL and why most people won't touch your code for 
real work.



On Wednesday, 20 November 2013 at 07:48:21 UTC, Mineko wrote:
Yo, I'm starting off a new game engine designed around D, and I 
just wanted to know if some of you might be kind enough to 
review some of my base code and tell me if I need to change 
anything in it.. While it's small. ;_;


I'm still learning D, I quite like it, the power of C++ in some 
parts, and the ease of Java in others. (Good job Walter!)


Anyway here, check it out, only ones you really need to pay 
attention to are main.d, time.d, and input.d.


https://github.com/ICGCC/Breaker-3D-Game-Engine

Thanks for helping out a newbie, and if you want to contribute 
to it, even better!


..That and if I'm using the GPL right. >_>"


Re: mixed type list?

2013-11-20 Thread seany
On Wednesday, 20 November 2013 at 11:25:24 UTC, Jonathan M Davis 
wrote:

On Wednesday, November 20, 2013 12:07:25 seany wrote:
Is there any way to represent mixed data (of various types) as 
a

single array?

In scilab, we have list, and you can do list(integer, stringvar
) etc.

Can you do something similar in D?  An idea is to use a struct
wil all possible data types, but think that is inefficient.

Any other ideas?


That sounds more like a tuple rather than a list, as lists 
normally are
supposed to contain values which all have the same type. So, 
the normal thing

to do would probably be to use std.typecons.Tuple. e.g.

auto t = tuple(1, 3.7, "foo");

But that's definitely a tuple and not a list, so you can't 
append to it or
remove anything from it or anything like that. If you want an 
actual list, you
need a way to make all of the items in the list be the same 
type. And if they
don't all share a base type (which pretty much only happens 
with classes),
then you'd probably have to use std.variant.Variant, which is 
essentially a
typed union. However, I'd advise against using anything like 
that unless you
actually need it. You should favor static typing as much as 
possible rather
than trying to hold differing types in the same list, as that's 
just begging
for bugs, particularly when you then try and use some of those 
items as a type

other than what they are.

- Jonathan M Davis



okey, i was thinking of dynamically generating variables, and 
returning their addresses to a int []. Ofcourse i first need to 
cast it to int.


I have the following cases :

I have a string, this string may take the form of

a.b.c.d.e ...
The function should return
depending on another parameter,one of the following:

1. an array with [a, b, c, d, e]
2. the original string

the original string may also take the form of
(a.(b.c).(((d.e.f).(g.h) .. etc

and depending on the other parameter, we may have
1. array with [a,b,c,d, .. ]
2. array with [1, [b.c] , [[[d,e,f]],[g,h]]
...
n. the string itself

Now, i was trying the first, i used the std.algorithms.splitter, 
and the result is of type *Result* and not string[], nonetheless 
I can cast (how does this work? isn't typedef removed, and alias 
should preserve underlaying types)


Morover while getting the addresses of the array elements, and 
putting them in the integer array, all of them returns the same 
address : the address of the array. (obviously). hence, i am also 
wondering, is there something in D, which can


1. either return the individual addresses of an element of an 
array or any type of objects...

2. generate variable names on the fly in RUNTIME?



Re: mixed type list?

2013-11-20 Thread bearophile

seany:

Now, i was trying the first, i used the 
std.algorithms.splitter, and the result is of type *Result* and 
not string[], nonetheless I can cast (how does this work? isn't 
typedef removed, and alias should preserve underlaying types)


cast() should be used only when you know what you are doing, and 
here you don't know it. I suggest to use "split" instead.



1. either return the individual addresses of an element of an 
array or any type of objects...


To get the address of an object just cast its pointer to 
something like a size_t. To get the address of array items, use 
&myarray[idx].




2. generate variable names on the fly in RUNTIME?


You probably need an associative array.

Bye,
bearophile


Re: D game engine -- Any suggestions?

2013-11-20 Thread Paulo Pinto
On Wednesday, 20 November 2013 at 10:20:06 UTC, Rene Zwanenburg 
wrote:
On Wednesday, 20 November 2013 at 09:15:41 UTC, Rene Zwanenburg 
wrote:

Hi,

A few things jumped out at me:

Camera.d:

...

Oops, I have to run.. Will take a look at the rest later.


Still regarding camera.d:

- The glfw3 import appears to be unused and can be removed.

- the call to Math.perspectiveGL modifies OpenGL state. Your 
math functions _really_ shouldn't interact with OpenGL.


- Taking the previous point a bit further, your Camera class 
doesn't need to know about OpenGL either. In your rendering 
routine, get the camera matrices from a camera and pass them to 
OpenGL.


- Like Paulo said, don't use the fixed function pipeline. If 
you're not familiar with 3D yet the FFP is easier to use at 
first, but using modern OpenGL will pay for itself in the long 
run. I don't know where to find a good introduction to modern 
OpenGL though, perhaps someone else around here..


...


Here are two possibilities using modern pipeline:

http://www.mbsoftworks.sk/index.php?page=tutorials&series=1

http://www.swiftless.com/opengl4tuts.html

Both of them are Windows based though, but it should be enough to 
get started.


--
Paulo


Re: MSG_WAITALL for Sockets

2013-11-20 Thread Jeroen Bollen

On Tuesday, 19 November 2013 at 23:36:57 UTC, Rob T wrote:
On Tuesday, 19 November 2013 at 18:35:08 UTC, Jeroen Bollen 
wrote:
Is there a way I can call a receive method on a socket with 
MSG_WAITALL as a flag? There doesn't seem to be an enum for 
that.


module core.sys.posix.sys.socket;

enum : uint
{
MSG_CTRUNC  = 0x08,
MSG_DONTROUTE   = 0x04,
MSG_EOR = 0x80,
MSG_OOB = 0x01,
MSG_PEEK= 0x02,
MSG_TRUNC   = 0x20,
MSG_WAITALL = 0x100
}


Use SocketFlags to set the flag.

If using Windows, you can set up your own enum, as I don't 
think one is pre-defined.


--rt


Thanks! I don't really get how this is working though, isn't the 
point of using an enum as a type, preventing any values that's 
not listed in the enum definition?


Re: Linking to a library via the linker on Windows?

2013-11-20 Thread Jeremy DeHaan

On Wednesday, 20 November 2013 at 12:02:36 UTC, Mike Parker wrote:

On 11/20/2013 5:01 PM, Jeremy DeHaan wrote:


The -L switch is just for sending switches to the linker. On 
OSX and
Linux, it is -L-lLibraryName, like I mention before, where 
-lLibraryName
is what actually gets passed to the linker. Basically I'm 
wondering of
Optlink has a switch that does the same thing as the -l switch 
for

linking to a library.


I don't believe there is anything like that. You just pass the 
lib name.


dmd foo.d bar.lib

You also pass a library path like so:

dmd foo.d bar.lib -L+../path/to/libs

This difference between Windows and other platforms creates a 
minor annoyance when making cross-platform build scripts for D 
(which, since dub came along, I don't worry about anymore). I 
vaguely recall a discussion around here somewhere about having 
DMD hide all of that behind a uniform syntax on the command 
line, for the library stuff at least. But it obviously didn't 
go anywhere.


Ok, thanks. I kind of figured that was the case, but I posted in 
in hopes that there was something that I had missed.




Re: Class References

2013-11-20 Thread Jeroen Bollen

On Monday, 18 November 2013 at 19:12:03 UTC, Ali Çehreli wrote:

On 11/18/2013 10:28 AM, Jeroen Bollen wrote:

Is it possible to do something like:

TestInterface testi = new classReferenceList[integer];


We still don't know what the use case is :) but it is possible 
to store types in a TypeTuple:


import std.stdio;
import std.typetuple;

interface I
{}

class C1 : I
{}

class C2 : I
{}

I makeObject(T)()
{
return new T();
}

I[] makeObjects(Ts...)()
{
I[] objects;

foreach (T; Ts) {
objects ~= makeObject!T();
}

return objects;
}

void main()
{
alias typeList = TypeTuple!(C1, C2);

auto objects = makeObjects!typeList();
writeln(objects);
}

The output:

[deneme.C1, deneme.C2]

Ali


I was more looking for a way to just access a type/class by 
specifying an index... I don't really get your code.


Re: D game engine -- Any suggestions?

2013-11-20 Thread Mineko
On Wednesday, 20 November 2013 at 15:30:32 UTC, Geancarlo Rocha 
wrote:
You should fix your LICENSE following these instructions 
http://www.gnu.org/licenses/gpl-howto.html. I hope you 
understand the virality of GPL and why most people won't touch 
your code for real work.




Yeah I know, have any better ideas that is at least similar 
enough to the GPL?


Encode text as QuotedPrintable

2013-11-20 Thread Andre

Hi,

is there a library function for encoding text as QuotedPrintable?
I found an old post from 2005:
http://forum.dlang.org/thread/cv98ti$1sf8$1...@digitaldaemon.com

The used function toHex throws errors. I also not found
an alternative way to convert a char to a hex as replacement
for the toHex function.

Kind regards
André


Re: Encode text as QuotedPrintable

2013-11-20 Thread Adam D. Ruppe

On Wednesday, 20 November 2013 at 16:53:47 UTC, Andre wrote:
is there a library function for encoding text as 
QuotedPrintable?


I fixed the function in that post:


char[] generateQuotedPrintable(in char[] string, in char[] 
charset =

"UTF-8")
{
char[] output;
bool special = false;

char[] toHex(char value)
{
char[2] buffer;

ubyte a = value % 16, b = value / 16;

buffer[0] = cast(char)(a < 10 ? a + '0' : a - 10 + 'A');
buffer[1] = cast(char)((b < 10) ? b + '0' : b - 10 + 'A');

return buffer.dup;
}

for (int i = 0; i < string.length; i++)
{
if (string[i] < 128 && string[i] != '=' && string[i] != '?' &&
string[i] != '_')
output ~= string[i];
else
{
output ~= "=" ~ toHex(string[i]);
special = true;
}
}

if (special)
output = "=?" ~ charset ~ "?Q?" ~ output ~ "?=";

return output;
}



There were two problems: one is a cast was needed due to a 
language change since it was written that is now more strict 
about narrowing conversions, and the other is it said i +=2 and i 
don't know why it did that and am pretty sure it is just wrong, 
so I removed that.


This function should work now.

If you need more email related stuff, I wrote a file that can 
send html email and such and can also read mbox messages:


https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/email.d


Re: Encode text as QuotedPrintable

2013-11-20 Thread Andre

On Wednesday, 20 November 2013 at 17:04:07 UTC, Adam D. Ruppe
wrote:

On Wednesday, 20 November 2013 at 16:53:47 UTC, Andre wrote:
is there a library function for encoding text as 
QuotedPrintable?


I fixed the function in that post:


char[] generateQuotedPrintable(in char[] string, in char[] ...

There were two problems: one is a cast was needed due to a 
language change since it was written that is now more strict 
about narrowing conversions, and the other is it said i +=2 and 
i don't know why it did that and am pretty sure it is just 
wrong, so I removed that.


This function should work now.

If you need more email related stuff, I wrote a file that can 
send html email and such and can also read mbox messages:


https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/email.d


Thanks a lot for the fix. Also the file is great.

Kind regards
André


Re: typedef '?

2013-11-20 Thread Jesse Phillips

On Wednesday, 20 November 2013 at 10:49:19 UTC, seany wrote:

is typedef gone?
http://forum.dlang.org/thread/aqsjjrtzfzslcopab...@forum.dlang.org?page=2

so If I want to define a new type as typedef string[] 
surrealNumber, then it does not work?


typedef was removed from the language, there were reasonable 
arguments for the type to act as a "base" or "child" type and 
could not satisfy both.


alias operates as the C typedef does, it just gives another 
symbol to refer to the same thing, generally better for complex 
type names than need simplified.


Re: D game engine -- Any suggestions?

2013-11-20 Thread Mineko
On Wednesday, 20 November 2013 at 10:20:06 UTC, Rene Zwanenburg 
wrote:
On Wednesday, 20 November 2013 at 09:15:41 UTC, Rene Zwanenburg 
wrote:

Hi,

A few things jumped out at me:

Camera.d:

...

Oops, I have to run.. Will take a look at the rest later.


Still regarding camera.d:

- The glfw3 import appears to be unused and can be removed.

- the call to Math.perspectiveGL modifies OpenGL state. Your 
math functions _really_ shouldn't interact with OpenGL.


- Taking the previous point a bit further, your Camera class 
doesn't need to know about OpenGL either. In your rendering 
routine, get the camera matrices from a camera and pass them to 
OpenGL.


- Like Paulo said, don't use the fixed function pipeline. If 
you're not familiar with 3D yet the FFP is easier to use at 
first, but using modern OpenGL will pay for itself in the long 
run. I don't know where to find a good introduction to modern 
OpenGL though, perhaps someone else around here..


- rotate, move are unnecessary. Once you switch to gl3n, move 
becomes:

camera.position += someVector;
Same thing with rotate, only you multiply:
camera.rotation *= someQuaternion;


math.d:

- D allows free functions. There's no need to use hacks like 
completely static classes. You can remove the Math class and 
put it's functions in the module.


- I'd also make std.math a public import, so you only have to 
import your math to get both in another module.


- perspectiveGL doesn't belong here, but this is fixed by using 
gl3n.



time.d

- Same thing with the statics as in math. Though personally I'd 
call Time Timer, and make instances. You'll probably want to 
have more than one timer.


- Sleeping doesn't belong in the timer. It should only 
calculate total running time and delta time in update. Later on 
you'll probably find out it needs more features, but these two 
will be fine for now. If anywhere, sleeping belongs in the game 
loop. That being said I'd advise against sleeping at all. It's 
usually better to use vsync, or run at max fps if the user 
disables it.



That's all I could find during a quick peek.. If you'd like me 
to clarify some of these points, please don't hesitate to ask!


Interesting, would you give me an example of the @property and 
the timer stuff, if that's all right with you?


I've attempted doing the @property stuff, but I run into lots of 
problems, so maybe your example will show me what I've done wrong.


Class Array in D?

2013-11-20 Thread Jeroen Bollen

is there a way I can pass a TypeTulip to a function?
Something like:

Can I create a class array in D? Something like:

interface A {}
class AA: A {}
class AB: A {}
class AC: A {}

ClassList!A list = new ClassList!A {AA, AB, AC};

void testf(ulong testv) {
A a = new list[testv];
}

I know about TypeTuple but that doesn't allow setting a 
requirement does it?


Re: Class References

2013-11-20 Thread Ali Çehreli

On 11/20/2013 08:35 AM, Jeroen Bollen wrote:


I was more looking for a way to just access a type/class by specifying
an index... I don't really get your code.


TypeTuple can contain types. Do you know the index at compile time or at 
run time? Here is a program that demonstrates constructing an object for 
both of those cases:


module deneme;

import std.stdio;
import std.typetuple;
import std.string;

interface I
{}

class C1 : I
{}

class C2 : I
{}

// Question: Is there a way to determine the name of this module?
string moduleName = "deneme";
static const typeNames = [ "C1", "C2" ];

void makeWithCompileTimeIndex(size_t index)()
{
alias typeList = TypeTuple!(C1, C2);

alias Type = typeList[index];
auto o = new Type();

writefln("I made an object by using a compile-time index: %s", o);
}

void makeWithRunTimeIndex(size_t index)
{
string fullTypeName = format("%s.%s", moduleName, typeNames[index]);
auto o = cast(I)Object.factory(fullTypeName);
writefln("I made an object by using a run-time index: %s", o);
}

void main()
{
makeWithCompileTimeIndex!1();

writefln("I can make an object of these types: %s", typeNames);
write("Please enter the index of the type that you want: ");
size_t index;
readf(" %s", &index);
makeWithRunTimeIndex(index);
}

Ali



Re: Class Array in D?

2013-11-20 Thread Ali Çehreli

On 11/20/2013 10:12 AM, Jeroen Bollen wrote:

> is there a way I can pass a TypeTulip to a function?

alias TypeTulip = TypeTuple;

;)

> Something like:
>
> Can I create a class array in D? Something like:
>
> interface A {}
> class AA: A {}
> class AB: A {}
> class AC: A {}
>
> ClassList!A list = new ClassList!A {AA, AB, AC};
>
> void testf(ulong testv) {
>  A a = new list[testv];
> }
>
> I know about TypeTuple but that doesn't allow setting a requirement does
> it?

import std.stdio;
import std.typetuple;

interface A {}
class AA: A {}
class AB: A {}
class AC: A {}

alias TypeTulip = TypeTuple;
alias list = TypeTuple!(AA, AB, AC);

void testf(ulong testv) {
// NOTE: This is a compile-time foreach
foreach (i, Type; list) {
if (i == testv) {
A a = new Type();
writefln("I made it: %s", a);
}
}
}

void main()
{
testf(1);
}

Note that the foreach loop above is not a loop that gets executed at run 
time. Its body is expanded inline as code multiple times as needed. I 
try to explain this a little under the "Compile-time foreach" and 
"foreach with TypeTuple" sections here:


  http://ddili.org/ders/d.en/tuples.html

Ali



Re: Class Array in D?

2013-11-20 Thread Jeroen Bollen

On Wednesday, 20 November 2013 at 18:23:37 UTC, Ali Çehreli wrote:

On 11/20/2013 10:12 AM, Jeroen Bollen wrote:

> is there a way I can pass a TypeTulip to a function?

alias TypeTulip = TypeTuple;

;)

> Something like:
>
> Can I create a class array in D? Something like:
>
> interface A {}
> class AA: A {}
> class AB: A {}
> class AC: A {}
>
> ClassList!A list = new ClassList!A {AA, AB, AC};
>
> void testf(ulong testv) {
>  A a = new list[testv];
> }
>
> I know about TypeTuple but that doesn't allow setting a
requirement does
> it?

import std.stdio;
import std.typetuple;

interface A {}
class AA: A {}
class AB: A {}
class AC: A {}

alias TypeTulip = TypeTuple;
alias list = TypeTuple!(AA, AB, AC);

void testf(ulong testv) {
// NOTE: This is a compile-time foreach
foreach (i, Type; list) {
if (i == testv) {
A a = new Type();
writefln("I made it: %s", a);
}
}
}

void main()
{
testf(1);
}

Note that the foreach loop above is not a loop that gets 
executed at run time. Its body is expanded inline as code 
multiple times as needed. I try to explain this a little under 
the "Compile-time foreach" and "foreach with TypeTuple" 
sections here:


  http://ddili.org/ders/d.en/tuples.html

Ali


That doesn't allow specifying a base class all members should be 
a part of though, or does it?


Re: Class Array in D?

2013-11-20 Thread Adam D. Ruppe
On Wednesday, 20 November 2013 at 18:31:37 UTC, Jeroen Bollen 
wrote:
That doesn't allow specifying a base class all members should 
be a part of though, or does it?


You could write your own tuple template for it, or just let the 
compile fail on the factory function: the A a = new T(); will 
fail if A isn't a base class or interface of T.


Putting the check in the list could look like this:

bool checkClassList(Base, T...)() {
   foreach(t; T) {
 static if(!is(t : Base))
 static assert(0, t.stringof ~ " is not a child of " ~ 
Base.stringof);

   }
   return true;
}

template ClassList(Base, T...) if(checkClassList!(Base, T)) {
alias ClassList = T;
}


Usage:

alias list = ClassList!(A, AA, AB, AC); // good


add:

class B {}
alias list = ClassList!(A, AA, AB, AC, B);

and get error:

test50.d(12): Error: static assert  "B is not a child of A"
test50.d(19):instantiated from here: checkClassList!(A, 
AA, AB, AC, B)


Re: MSG_WAITALL for Sockets

2013-11-20 Thread Jonathan M Davis
On Wednesday, November 20, 2013 17:26:27 Jeroen Bollen wrote:
> On Tuesday, 19 November 2013 at 23:36:57 UTC, Rob T wrote:
> > On Tuesday, 19 November 2013 at 18:35:08 UTC, Jeroen Bollen
> > 
> > wrote:
> >> Is there a way I can call a receive method on a socket with
> >> MSG_WAITALL as a flag? There doesn't seem to be an enum for
> >> that.
> > 
> > module core.sys.posix.sys.socket;
> > 
> > enum : uint
> > {
> > 
> > MSG_CTRUNC = 0x08,
> > MSG_DONTROUTE = 0x04,
> > MSG_EOR = 0x80,
> > MSG_OOB = 0x01,
> > MSG_PEEK = 0x02,
> > MSG_TRUNC = 0x20,
> > MSG_WAITALL = 0x100
> > 
> > }
> > 
> > Use SocketFlags to set the flag.
> > 
> > If using Windows, you can set up your own enum, as I don't
> > think one is pre-defined.
> > 
> > --rt
> 
> Thanks! I don't really get how this is working though, isn't the
> point of using an enum as a type, preventing any values that's
> not listed in the enum definition?

SocketFlags in std.socket is used incorrectly. It's used as a parameter type 
for &ed values rather than just a list of the flags that you can & together, 
and unfortunately, the language does not currently prevent that. You can do 
stuff like.

enum Foo : string { a = "bar" }

auto b = Foo.a;
b ~= " stool";

with impunity. It's just that the compiler will prevent something like

Foo f = "hello";

So, the type protection on enums is currently quite poor. IMHO, the compiler 
should prevent an enum from ever having an invalid enum value when no casts 
are used, but that's just not the way that it is right now. Pretty much all it 
protects against are direct assignments. And I have no idea whether that will 
ever be fixed or not. Hopefully it will be though.

- Jonathan M Davis


Re: D game engine -- Any suggestions?

2013-11-20 Thread Paulo Pinto

On Wednesday, 20 November 2013 at 16:40:59 UTC, Mineko wrote:
On Wednesday, 20 November 2013 at 15:30:32 UTC, Geancarlo Rocha 
wrote:
You should fix your LICENSE following these instructions 
http://www.gnu.org/licenses/gpl-howto.html. I hope you 
understand the virality of GPL and why most people won't touch 
your code for real work.




Yeah I know, have any better ideas that is at least similar 
enough to the GPL?


I would suggest dual license.

GPL for open source projects and something else for commercial 
projects.


It all depends how you see companies using your code, without any 
kind of retribution or recognition. I see this happening all the 
time in the SaaS enterprise space I work on.


For many companies open source means free beer.

I wonder how much Sony was given back to the open source projects 
that make up the PS4 besides the license note, for example.


http://www.scei.co.jp/ps4-license/

Anyway it is your project, so it is up to you to decide what 
license to use.


--
Paulo



Re: D game engine -- Any suggestions?

2013-11-20 Thread Mineko

On Wednesday, 20 November 2013 at 19:38:09 UTC, Paulo Pinto wrote:


I would suggest dual license.

GPL for open source projects and something else for commercial 
projects.


It all depends how you see companies using your code, without 
any kind of retribution or recognition. I see this happening 
all the time in the SaaS enterprise space I work on.


For many companies open source means free beer.

I wonder how much Sony was given back to the open source 
projects that make up the PS4 besides the license note, for 
example.


http://www.scei.co.jp/ps4-license/

Anyway it is your project, so it is up to you to decide what 
license to use.


--
Paulo


Ahh ok, I was worried when you said that the GPL was viral, I was 
planning on a dual license, GPL for the actual engine, and maybe 
boost or something for the actual assets, of course that depends 
on who uses the code, as long as the engine itself is free and 
redistributed intact then everything is fine.


Re: D game engine -- Any suggestions?

2013-11-20 Thread Franz

On Wednesday, 20 November 2013 at 20:00:17 UTC, Mineko wrote:
On Wednesday, 20 November 2013 at 19:38:09 UTC, Paulo Pinto 
wrote:


as long as the engine itself is free and redistributed intact 
then everything is fine.


Then you are probably looking at a LGPL license. I'm not gonna
explain in deep the differences but keeping it short:
If a library is GPL, then the whole project must be redistributed
as GPL software. If someone uses your code and uses in a broader
project, the whole project would need to be GPL too.
If a library is LGPL, then the modified library must be
redistributed as LGPL library. If someone uses and/or modifies
your library in a broader project, only the library will need to
be redistributed as open.

EG: one takes your game engine and links it against some other
libraries to make a full game (eg: adding networking, scripting
engine, etc). If the license is LGPL, everything is fine. If
license is GPL, he will need to release everything as GPL.
Something this isn't even possible due to license
incompatibilities. However, if he modifies your library (like,
adds something to rendering routines), he has to release the
modified code, doesn't matter if it's GPL or LGPL.

Last but not least, the copyright holder (you) can relicense the
work at any time.


Re: D game engine -- Any suggestions?

2013-11-20 Thread Mineko

On Wednesday, 20 November 2013 at 20:57:11 UTC, Franz wrote:

On Wednesday, 20 November 2013 at 20:00:17 UTC, Mineko wrote:
On Wednesday, 20 November 2013 at 19:38:09 UTC, Paulo Pinto 
wrote:


as long as the engine itself is free and redistributed intact 
then everything is fine.


Then you are probably looking at a LGPL license. I'm not gonna
explain in deep the differences but keeping it short:
If a library is GPL, then the whole project must be 
redistributed

as GPL software. If someone uses your code and uses in a broader
project, the whole project would need to be GPL too.
If a library is LGPL, then the modified library must be
redistributed as LGPL library. If someone uses and/or modifies
your library in a broader project, only the library will need to
be redistributed as open.

EG: one takes your game engine and links it against some other
libraries to make a full game (eg: adding networking, scripting
engine, etc). If the license is LGPL, everything is fine. If
license is GPL, he will need to release everything as GPL.
Something this isn't even possible due to license
incompatibilities. However, if he modifies your library (like,
adds something to rendering routines), he has to release the
modified code, doesn't matter if it's GPL or LGPL.

Last but not least, the copyright holder (you) can relicense the
work at any time.


Finally.. I finally got a clear explanation of the LGPL, I was on 
the fence about it but ended up going with GPl, now that I know 
though I'll convert it to LGPL, much thanks.


Re: D game engine -- Any suggestions?

2013-11-20 Thread Paulo Pinto

On Wednesday, 20 November 2013 at 21:13:05 UTC, Mineko wrote:

On Wednesday, 20 November 2013 at 20:57:11 UTC, Franz wrote:

On Wednesday, 20 November 2013 at 20:00:17 UTC, Mineko wrote:
On Wednesday, 20 November 2013 at 19:38:09 UTC, Paulo Pinto 
wrote:


as long as the engine itself is free and redistributed intact 
then everything is fine.


Then you are probably looking at a LGPL license. I'm not gonna
explain in deep the differences but keeping it short:
If a library is GPL, then the whole project must be 
redistributed
as GPL software. If someone uses your code and uses in a 
broader

project, the whole project would need to be GPL too.
If a library is LGPL, then the modified library must be
redistributed as LGPL library. If someone uses and/or modifies
your library in a broader project, only the library will need 
to

be redistributed as open.

EG: one takes your game engine and links it against some other
libraries to make a full game (eg: adding networking, scripting
engine, etc). If the license is LGPL, everything is fine. If
license is GPL, he will need to release everything as GPL.
Something this isn't even possible due to license
incompatibilities. However, if he modifies your library (like,
adds something to rendering routines), he has to release the
modified code, doesn't matter if it's GPL or LGPL.

Last but not least, the copyright holder (you) can relicense 
the

work at any time.


Finally.. I finally got a clear explanation of the LGPL, I was 
on the fence about it but ended up going with GPl, now that I 
know though I'll convert it to LGPL, much thanks.


Take note that LGPL is only valid as long as you only use dynamic 
linking.


If you use static linking, it is under the same obligations as 
pure GPL.


--
Paulo


Re: D game engine -- Any suggestions?

2013-11-20 Thread Mineko
On Wednesday, 20 November 2013 at 09:15:41 UTC, Rene Zwanenburg 
wrote:


Hi,

A few things jumped out at me:

Camera.d:

- The use of x, y, z and rx, ry, rz. These should really be in 
some vector struct. Since you're using Dub, you can easily use 
gl3n [1][2]. While it's still pretty basic, should be more than 
enough to get you started.


- Use Quaternions to store your rotations instead of euler 
angles.


- You can use @property instead of trivial getters and setters

- You may want to store your camera matrices in the camera 
class, and pass them to OpenGL when rendering. These matrices 
can be useful, and you don't want to use glGet* functions ever 
if you care about performance ;). gl3n provides matrix structs 
and facilities to create projection matrices and the like.


Oops, I have to run.. Will take a look at the rest later.

[1] http://dav1dde.github.io/gl3n/index.html
[2] http://code.dlang.org/packages/gl3n


After a bit of careful study I figured out how @property works, I 
just implemented it wrong last time, very helpful, thanks.


Accessing mutable data that isn't

2013-11-20 Thread Spott

I've been screwing around with templates lately, and I'm
attempting to figure out why the following won't compile:

struct value
{
 int a;

 const auto
 opBinary(string op, T)(in T rhs) const pure {
 static if (op == "+")
 return intermediateValue!(value.plus,this,rhs)();
 }

 ref value opAssign(T)( in T t ) {
 a = t.a;
 return this;
 }

 static
 int plus(T1, T2)(in T1 x, in T2 y) pure {
 return x.a + y.a;
 }

}

struct intermediateValue(alias Op, alias A, alias B)
{

 auto opBinary(string op, T)(in T rhs) const pure {
 static if (op == "+")
 return intermediateValue!(value.plus,this,rhs)();
 }

 @property auto a() const pure {
 return Op(A, B);
 }

}

void main()
{
 value a = value(2);
 value b = value(3);
 value c;
 c = a + b;
}

The error is:
d_playground.d(34): Error: pure nested function 'a' cannot access
mutable data 'this'
d_playground.d(34): Error: pure nested function 'a' cannot access
mutable data 'this'
d_playground.d(10): Error: template instance
d_playground.value.opBinary!("+",
value).opBinary.intermediateValue!(plus, this, rhs) error
instantiating
d_playground.d(44):instantiated from here: opBinary!("+",
value)
d_playground.d(44): Error: template instance
d_playground.value.opBinary!("+", value) error instantiating

What is going on?  Why is 'a' not allowed to "access" mutable
data (even though it isn't modifying it)? How do I tell the
compiler to pass "this" in a const fashion?


Re: Class References

2013-11-20 Thread Jared Miller

On Monday, 28 October 2013 at 11:22:03 UTC, Jeroen Bollen wrote:

Is it possible in D to create an enum of class references?
Something around the lines of:

enum ClassReferences : Interface {
CLASS1 = &ClassOne,
CLASS2 = &ClassTwo
}


Here's my solution using an enum as you originally wanted. 
However, depending on what you're really trying to do, there 
could be a better way.


import std.stdio;
import std.traits : fullyQualifiedName;

interface Foo { void bar(); }

class Class1 : Foo {
void bar() { writeln("Class1"); }
}

class Class2 : Foo {
void bar() { writeln("Class2"); }
}

enum ClassNames : string {
CLASS1 = fullyQualifiedName!Class1,
CLASS2 = fullyQualifiedName!Class2
}

Foo getObj(ClassNames name) {
// without cast, it converts to the enum member name.
return cast(Foo)Object.factory(cast(string)name);
}

void main() {
auto c1 = getObj(ClassNames.CLASS1);
auto c2 = getObj(ClassNames.CLASS2);
assert(c1 && c2);
c1.bar();
c2.bar();
}


Re: Class References

2013-11-20 Thread Jared Miller
On Wednesday, 20 November 2013 at 23:06:37 UTC, Jared Miller 
wrote:



Foo getObj(ClassNames name) {
// without cast, it converts to the enum member name.
return cast(Foo)Object.factory(cast(string)name);
}


Oops, never mind - you don't need the "cast(string)" there.


Re: std.json

2013-11-20 Thread Craig Dillabaugh

On Wednesday, 20 November 2013 at 13:48:37 UTC, Orvid King wrote:
On 11/20/13, Craig Dillabaugh  
wrote:

On Wednesday, 20 November 2013 at 13:29:54 UTC, Dicebot wrote:

What I mean is that std.json does not seem to be written with
such usage mode in mind, it is more about direct DOM
manipulation/construction. So probably examples should 
probably

not highlight how bad it is at tasks it is really bad at :P


So I was basically wasting my time trying to figure out how to
drive a nail with a screwdriver :o)



But driving a nail with a screwdriver works very well! Or at 
least it

does if you have a large enough screwdriver :P

Regardless, if your looking to avoid the vibe.d dependency, my
serialization framework does support JSON, and still has the 
simple

API that vibe.d's module does.
https://github.com/Orvid/JSONSerialization


Thanks, I may have a look.

Craig


Re: Red-Black tree storing color without additional memory requirements

2013-11-20 Thread Ellery Newcomer

On 11/20/2013 06:50 AM, bearophile wrote:

safety0ff:


Since the GC supports interior pointers, I think you can justify using
the least significant bits as long as the size and alignment of the
pointed object guarantee that the pointer + tag will always lie inside
the memory block.


From:
http://dlang.org/garbage.html


Do not take advantage of alignment of pointers to store bit flags in
the low order bits:


Bye,
bearophile


ha. I did this with steve's rb tree. hasn't bit me yet.


Get array of elements the base type from Variant

2013-11-20 Thread RomulT
Hi, help please, how I get array of elements the base type from 
Variant?



http://dpaste.dzfl.pl/6dd70f9b


Re: Get array of elements the base type from Variant

2013-11-20 Thread evilrat

On Thursday, 21 November 2013 at 05:16:10 UTC, RomulT wrote:
Hi, help please, how I get array of elements the base type from 
Variant?



http://dpaste.dzfl.pl/6dd70f9b


may be there is a way to cast array directly but i doubt.

so you need either to do this

IXXX[] x = [new XXX(), new XXX()];
Variant v = x;
writeln(v.get!(IXXX[]));

or cast all members of original array to its base type

XXX[] x = [new XXX(), new XXX()];
Variant v = x;

foreach( ixx ; v.get!(XXX[]) )
  writeln(cast(IXXX)ixx.get());


Re: D game engine -- Any suggestions?

2013-11-20 Thread qznc

On Wednesday, 20 November 2013 at 16:40:59 UTC, Mineko wrote:
On Wednesday, 20 November 2013 at 15:30:32 UTC, Geancarlo Rocha 
wrote:
You should fix your LICENSE following these instructions 
http://www.gnu.org/licenses/gpl-howto.html. I hope you 
understand the virality of GPL and why most people won't touch 
your code for real work.




Yeah I know, have any better ideas that is at least similar 
enough to the GPL?


You could try my little wizard:

http://beza1e1.tuxen.de/licences/


Re: Get array of elements the base type from Variant

2013-11-20 Thread RomulT

On Thursday, 21 November 2013 at 05:44:53 UTC, evilrat wrote:

On Thursday, 21 November 2013 at 05:16:10 UTC, RomulT wrote:
Hi, help please, how I get array of elements the base type 
from Variant?



http://dpaste.dzfl.pl/6dd70f9b


may be there is a way to cast array directly but i doubt.

so you need either to do this

IXXX[] x = [new XXX(), new XXX()];
Variant v = x;
writeln(v.get!(IXXX[]));

or cast all members of original array to its base type

XXX[] x = [new XXX(), new XXX()];
Variant v = x;

foreach( ixx ; v.get!(XXX[]) )
  writeln(cast(IXXX)ixx.get());
Yes, it a work, thank you. The problem occurs when, in Variant 
already recorded XXX[] and it is necessary to extract the IXXX[], 
because in the place used nothing is known about type XXX.


Re: Accessing mutable data that isn't

2013-11-20 Thread Jesse Phillips

On Wednesday, 20 November 2013 at 22:49:42 UTC, Spott wrote:

I've been screwing around with templates lately, and I'm
attempting to figure out why the following won't compile:

struct value
{
 int a;

 const auto
 opBinary(string op, T)(in T rhs) const pure {
 static if (op == "+")
 return 
intermediateValue!(value.plus,this,rhs)();

 }


const here is redundant, probably wanted const(auto) which isn't 
valid syntax. The function being const may already be returning a 
const type.



What is going on?  Why is 'a' not allowed to "access" mutable
data (even though it isn't modifying it)? How do I tell the
compiler to pass "this" in a const fashion?


I'm not seeing an issue with the declarations. The function being 
declared as const is what make 'this' const. Probably should file 
as a bug if you don't get any confirmation soon. And reply with 
the bug entry.


Re: Accessing mutable data that isn't

2013-11-20 Thread qznc

On Wednesday, 20 November 2013 at 22:49:42 UTC, Spott wrote:

I've been screwing around with templates lately, and I'm
attempting to figure out why the following won't compile:

struct value
{
 int a;

 const auto
 opBinary(string op, T)(in T rhs) const pure {
 static if (op == "+")
 return 
intermediateValue!(value.plus,this,rhs)();

 }

 ref value opAssign(T)( in T t ) {
 a = t.a;
 return this;
 }

 static
 int plus(T1, T2)(in T1 x, in T2 y) pure {
 return x.a + y.a;
 }

}

struct intermediateValue(alias Op, alias A, alias B)
{

 auto opBinary(string op, T)(in T rhs) const pure {
 static if (op == "+")
 return intermediateValue!(value.plus,this,rhs)();
 }

 @property auto a() const pure {
 return Op(A, B);
 }

}

void main()
{
 value a = value(2);
 value b = value(3);
 value c;
 c = a + b;
}

The error is:
d_playground.d(34): Error: pure nested function 'a' cannot 
access

mutable data 'this'
d_playground.d(34): Error: pure nested function 'a' cannot 
access

mutable data 'this'
d_playground.d(10): Error: template instance
d_playground.value.opBinary!("+",
value).opBinary.intermediateValue!(plus, this, rhs) error
instantiating
d_playground.d(44):instantiated from here: 
opBinary!("+",

value)
d_playground.d(44): Error: template instance
d_playground.value.opBinary!("+", value) error instantiating

What is going on?  Why is 'a' not allowed to "access" mutable
data (even though it isn't modifying it)? How do I tell the
compiler to pass "this" in a const fashion?


No answer, but two notes.

First, use dpaste for such code snippets: 
http://dpaste.dzfl.pl/f2f39b32


Second, what are you trying to do? intermediateValue is a struct 
without members. I am not sure what 'this' means in such a case.


Re: Get array of elements the base type from Variant

2013-11-20 Thread evilrat

On Thursday, 21 November 2013 at 06:31:54 UTC, RomulT wrote:
Yes, it a work, thank you. The problem occurs when, in Variant 
already recorded XXX[] and it is necessary to extract the 
IXXX[], because in the place used nothing is known about type 
XXX.


so you need just to cast XXX[] to IXXX[] ? AFAIK arrays can't be 
casted to other types. but you can use std.conv.to to convert it.


writeln( std.conv.to!(IXXX[])(v.get!(XXX[])) );

but if you put another class derived from IXXX you can see they 
are still initial types, not IXXX as you may expect.


Re: Accessing mutable data that isn't

2013-11-20 Thread Jonathan M Davis
On Wednesday, November 20, 2013 23:49:42 Spott wrote:
> I've been screwing around with templates lately, and I'm
> attempting to figure out why the following won't compile:
> 
> struct value
> {
>   int a;
> 
>   const auto
>   opBinary(string op, T)(in T rhs) const pure {
>   static if (op == "+")
>   return intermediateValue!(value.plus,this,rhs)();
>   }
> 
>   ref value opAssign(T)( in T t ) {
>   a = t.a;
>   return this;
>   }
> 
>   static
>   int plus(T1, T2)(in T1 x, in T2 y) pure {
>   return x.a + y.a;
>   }
> 
> }
> 
> struct intermediateValue(alias Op, alias A, alias B)
> {
> 
>   auto opBinary(string op, T)(in T rhs) const pure {
>   static if (op == "+")
>   return intermediateValue!(value.plus,this,rhs)();
>   }
> 
>   @property auto a() const pure {
>   return Op(A, B);
>   }
> 
> }
> 
> void main()
> {
>   value a = value(2);
>   value b = value(3);
>   value c;
>   c = a + b;
> }
> 
> The error is:
> d_playground.d(34): Error: pure nested function 'a' cannot access
> mutable data 'this'
> d_playground.d(34): Error: pure nested function 'a' cannot access
> mutable data 'this'
> d_playground.d(10): Error: template instance
> d_playground.value.opBinary!("+",
> value).opBinary.intermediateValue!(plus, this, rhs) error
> instantiating
> d_playground.d(44):instantiated from here: opBinary!("+",
> value)
> d_playground.d(44): Error: template instance
> d_playground.value.opBinary!("+", value) error instantiating
> 
> What is going on?  Why is 'a' not allowed to "access" mutable
> data (even though it isn't modifying it)? How do I tell the
> compiler to pass "this" in a const fashion?


pure functions can only access their arguments and global/static constants. 
a's only argument is its invisible this pointer. Op, A, and B are aliases to 
stuff outside of a. I suppose that an argument could be made that because 
the're template arguments to the type that a is a part of that they should be 
considered to be arguments to a like the this pointer is, but you are 
essentially trying to have it access data which is not one of its arguments 
and that violates purity.

But all in all, I find your code quite bizarre and difficult to understand - 
particularly your use of aliases - so it's kind of hard for me to say how 
valid it is. I'm surprised that you can get away with feeding a purely runtime 
argument to a template as an alias (namely rhs). I wouldn't have thought that 
that would be valid. In most cases, all template alias parameters get used for 
is passing in predicates to functions (which are almost invariably delegates 
or lambdas). So, clearly my understanding of how alias template parameters 
work is too limited.

- Jonathan M Davis


bitwise operation and type

2013-11-20 Thread bioinfornatics

why this fail http://www.dpaste.dzfl.pl/a6d6acf4

I want to works with ubyte ->  
i do not want use int for manipulating these byte and consume 
more memory as need!


Re: Accessing mutable data that isn't

2013-11-20 Thread Jonathan M Davis
On Thursday, November 21, 2013 07:48:34 qznc wrote:
> First, use dpaste for such code snippets:
> http://dpaste.dzfl.pl/f2f39b32

Really? I find it annoying when people do that unless the code is quite long. 
It's much easier to have it just be in the message IMHO. Also, it has the 
benefit of not having to worry about the link not being valid in the future, 
potentially rendering the message impossible to understand. I have no idea how 
long dpaste links stick around; a while I expect, but there's no guarantee 
that they'll be around as long as the forum or its archives will be.

- Jonathan M Davis


Re: bitwise operation and type

2013-11-20 Thread Jonathan M Davis
On Thursday, November 21, 2013 08:21:37 bioinfornatics wrote:
> why this fail http://www.dpaste.dzfl.pl/a6d6acf4
> 
> I want to works with ubyte ->  
> i do not want use int for manipulating these byte and consume
> more memory as need!

All arithmetic operations on integer types (including bitwise manipulations) 
operate on the original type or (u)int (whichever is larger). So, if you want 
to manipulate a ubyte and then assign the result to a ubyte, you need to cast 
it. It's the same with C/C++ except that C/C++ just silently do the cast for 
you, whereas D requires an explicit cast for narrowing conversions.

- Jonathan M Davis


Re: bitwise operation and type

2013-11-20 Thread Ellery Newcomer

On 11/20/2013 11:21 PM, bioinfornatics wrote:

why this fail http://www.dpaste.dzfl.pl/a6d6acf4


as with c, most of the integer operators return int for integral types 
smaller than int. also, this is a case where


a += b

does something different than

a = a + b

i guess the former automatically inserts a cast or something.



I want to works with ubyte ->  
i do not want use int for manipulating these byte and consume more
memory as need!


tough. use a cast.