Re: How to specify an exact template?

2021-01-16 Thread solidstate1991 via Digitalmars-d-learn
Well, it's quite complicated to do. I have to manually unwrap 
each and all function template, then pray for the compile-time 
optimization gods that they'll be inlined.


This is so annoying, that I might issue a DIP...


Re: How to specify an exact template?

2021-01-16 Thread solidstate1991 via Digitalmars-d-learn

On Saturday, 16 January 2021 at 14:18:55 UTC, Tove wrote:
probably you can use 
https://dlang.org/spec/traits.html#getOverloads


I don't know how to use it with functions outside of 
structs/classes.


Re: How to specify an exact template?

2021-01-16 Thread solidstate1991 via Digitalmars-d-learn
On Saturday, 16 January 2021 at 14:13:29 UTC, solidstate1991 
wrote:

Here's the following line, among many others:

return !(ubyte);

This generates an error, as this function template matches two 
instances, but currently I don't know how to choose the one I 
need, other than write a local function, that looks a bit ugly.


Forgot to link the code example: 
https://github.com/ZILtoid1991/pixelperfectengine/blob/master/pixeperfectengine/src/PixelPerfectEngine/graphics/layers/base.d#L143


How to specify an exact template?

2021-01-16 Thread solidstate1991 via Digitalmars-d-learn

Here's the following line, among many others:

return !(ubyte);

This generates an error, as this function template matches two 
instances, but currently I don't know how to choose the one I 
need, other than write a local function, that looks a bit ugly.


Re: opApply and attributes

2020-07-16 Thread solidstate1991 via Digitalmars-d-learn

On Tuesday, 14 July 2020 at 00:17:14 UTC, solidstate1991 wrote:

Something like that, but with @safe, pure, etc. attributes.


I've tried to "bruteforce" it by generating functions with 
combinations of attributes, and it kinda works, but is a very 
janky solution.


I'll brainstorm some DIP to fix this issue.


Re: opApply and attributes

2020-07-13 Thread solidstate1991 via Digitalmars-d-learn

On Tuesday, 7 July 2020 at 20:53:05 UTC, Ali Çehreli wrote:
I am not sure whether I understand it correctly but there has 
been a request for opApply() to gain the attributes of the 
delegate (or the range?). In other words, "transfer the 
attributes to opApply". This is needed because I want opApply() 
to work with any foreach body, attributes of which opApply() 
cannot know.


I am sure I created an issue on Dlang bug tracker for Weka on 
this topic but I can't find it now. (Aside: The search boxes on 
the bug tracker are inferior to the automatic search feature 
that works when creating a bug.) Anyway, this one seems related:


  https://issues.dlang.org/show_bug.cgi?id=7543

Ali


Something like that, but with @safe, pure, etc. attributes.


Re: opApply and attributes

2020-07-07 Thread solidstate1991 via Digitalmars-d-learn

On Tuesday, 7 July 2020 at 13:33:41 UTC, Paul Backus wrote:


You can make opApply a template:

int opApply(Dg)(Dg dg)
if (is(Dg : scope int delegate(ref E)))
{
// etc.
}

Because `scope int delegate(ref E) @safe` implicitly converts 
to `scope int delegate(ref E)`, this version will accept both 
@safe and non-@safe delegates. (And likewise for the other 
function attributes.)


Unfortunately this doesn't really work, even with explicitly 
defined foreach arguments.


opApply and attributes

2020-07-06 Thread solidstate1991 via Digitalmars-d-learn
See implementation of data structure here: 
https://github.com/ZILtoid1991/collections-d/blob/master/source/collections/treemap.d#L565


If I try to compile this code, it'll fail, limiting it's usecase:

@safe pure unittest {
alias IntMap = TreeMap!(int, int, false);
IntMap test;
test[5] = 5;
test[7] = 7;
test[3] = 3;
foreach(elem, key; test) {
assert(elem == key);
}
}

I know that implementing foreach with other means do exist, and I 
used them in my other data structures, but it's much more 
difficult (and potentially slower) to implement that within a 
binary search tree.


Should I change the `opApply` into the `popfront` - `front` - 
`empty` trinity, or write a template that overrides all the 
potential attribute combinations?


Maybe D needs a template for attributes somehow, or something 
like that.


Re: A custom name for variables

2020-05-29 Thread solidstate1991 via Digitalmars-d-learn

On Thursday, 28 May 2020 at 20:26:55 UTC, Quantium wrote:

I need to create a variable with custom name, like this
import std;
void main()
{
string name;
readf(" %s", );
// some code that generates a variable of type integer and 
value 0

}
Could you help me with that?


This might be possible in certain scripting languages, but not in 
D.


Static fields are generated during compile time, and while 
something like that is possible using template mixins in the code 
(famous use in D is Phobos's bitfields, which generates 
properties for a struct or a class), it's impossible during 
runtime, and - in extension - by reading a value from console.


Re: Linker error under Ubuntu

2020-05-15 Thread solidstate1991 via Digitalmars-d-learn

On Friday, 15 May 2020 at 03:46:57 UTC, evilrat wrote:


Um, pardon the stupid question, but did you just forgot to link 
it? I can't see a mention of it anywhere in both the old json 
and dub.sdl, and I don't see subpackages either. (does it links 
implicitly by the compiler?)


Also if it's digged up somewhere, another possibility is the 
link order issue(you need to put libs in order that adds linker 
symbols for previous libs to consume, for circular dependencies 
you can specify libs multiple times). The MS linker and LLVM 
linkers(not sure about GNU gold) does some work for you so you 
don't have to reorder libs most of the time.


Dub should do the linking by itself.


Linker error under Ubuntu

2020-05-14 Thread solidstate1991 via Digitalmars-d-learn
When I try to compile my own project under Ubuntu with dub, I get 
the following linker error:


/usr/bin/ld: .dub/obj/pixelperfectengine_pixelperfecteditor.o: 
undefined reference to symbol 'inflateEnd'
//lib/x86_64-linux-gnu/libz.so.1: error adding symbols: DSO 
missing from command line

collect2: error: ld returned 1 exit status
Error: /usr/bin/gcc failed with status: 1
/usr/bin/ldc2 failed with exit code 1.

I've checked for zlib and it was already preinstalled. I tried to 
install LLD, but that didn't help.


The latest version of my project found here: 
https://github.com/ZILtoid1991/pixelperfectengine


Re: Fixing race issues the right way

2020-04-20 Thread solidstate1991 via Digitalmars-d-learn

On Sunday, 5 April 2020 at 22:33:50 UTC, Stefan Koch wrote:


Look at your program in a debugger and see if it does spawn 
threads.

If it does find out where and why they are spawned.


Thanks for the answer, but it seems the issue was the lack of the 
ability of unittesting such a large package. So I broke out 
collections-d similarly to other projects.


Fixing race issues the right way

2020-04-05 Thread solidstate1991 via Digitalmars-d-learn
My game engine is currently broken due to some race issue I don't 
really know how to resolve.


It seems that the compiler tries to skip instructions that are 
not locked with a `writeln()` or something similar. Usually I can 
safely remove the writeln after compiling it once with that way. 
However I've once ran into an issue when a previously working 
code just started to emit random junk data depending on CPU 
usage, and in that case the aforementioned workaround only 
partially worked (delaying crashes, etc).


I've heard something about Mutex, however I lack the experience 
with multithreading.


Re: How to debug in vscode Windows?

2020-01-01 Thread solidstate1991 via Digitalmars-d-learn

On Wednesday, 1 January 2020 at 14:46:01 UTC, NaN wrote:
You can use visual studio (works in 2019, havent tried earlier 
versions) to debug any exe you want. You do this...


Go to File menu, then Open, then Project/Solution

Make sure "all project files" is selected, then find the exe 
you want to debug, click Open.


Now you can debug that exe inside Visual Studio (as long as its 
been compiled with debug info) You can also save the solution 
so next time you just open the solution and you're ready to 
debug.


You can drop source files into visual studio and set 
breakpoints, but it will also automatically pull up the source 
when it hits an exception. Although you might need adjust VS 
settings so it breaks on all exceptions IIRC... explains how on 
this page...


https://docs.microsoft.com/en-us/visualstudio/debugger/managing-exceptions-with-the-debugger?view=vs-2019

Its pretty much all working, except you cant see dynamic array 
contents and occasionally it steps a line out of sync.


I never managed to get any debugger working in VSCode. But this 
way you get the Visual Studio debugger which as good as it 
gets, and its just a couple of clicks away.


Oh I'm using LDC to compile so I'm not sure how well it works 
with DMD, haven't tried, but should work the same I imagine.


I usually just make an empty project and set up the exe file to 
the one that dub creates instead.


LLD-link doesn't work, how do I change linkers?

2020-01-01 Thread solidstate1991 via Digitalmars-d-learn
I cannot do any work, since LLD-link is broken and doesn't want 
to link for anything. It just gives me a bunch of errors for 
missing symbols, that supposed to be in the core libraries.


How can I set up the Microsoft linker instead?


"Mixin is not defined" error when trying to use template mixins

2019-10-27 Thread solidstate1991 via Digitalmars-d-learn
There's a template mixin in my dimage project's new version in 
base.d, and when I try to access it from another file I get two 
errors:


undefined identifier `ChunkyAccess4bit`, did you mean template 
`ChunkyAccess4Bit()`?


and

mixin `dimage.tga.TGA.ChunkyAccess4bit!()` is not defined

Should I put the template into the base class of TGA (Image) 
instead of keeping it outside of that?


Any easy way to check if an object have inherited an interface?

2019-07-22 Thread solidstate1991 via Digitalmars-d-learn
It seems that I've to write my own function that searches in the 
given object's classinfo.interfaces since I couldn't find 
anything related in Phobos.


Re: std.zlib odd behavior

2019-05-20 Thread solidstate1991 via Digitalmars-d-learn

On Wednesday, 6 March 2019 at 01:50:16 UTC, solidstate1991 wrote:
Thanks, it seems I'll have to write my own solution for this, 
and I really dislike the way streaming compression works in C. 
I've spotted some other bugs regarding my PNG implementation, 
but those were unrelated and didn't improve the compression 
issues.
I was finally able to tame the beast, now I can load and save PNG 
files. Now I probably have issues with standardization, which 
will require me to read up on the topic, since my output isn't 
liked by IrfanView, and many other applications.




Re: std.zlib odd behavior

2019-03-05 Thread solidstate1991 via Digitalmars-d-learn

On Tuesday, 5 March 2019 at 02:19:26 UTC, Adam D. Ruppe wrote:
I haven't found the bug in your code yet, but one thing I 
suspect from my experience is you might be reusing a buffer. 
std.zlib actually stores pointers internally across function 
calls, so if you are trying to compress a stream, you are 
liable to get corruption.


(std.zlib is very bad code, frankly.)

I don't know for sure though, my brain is in the compiler 
tonight...


Thanks, it seems I'll have to write my own solution for this, and 
I really dislike the way streaming compression works in C. I've 
spotted some other bugs regarding my PNG implementation, but 
those were unrelated and didn't improve the compression issues.


std.zlib odd behavior

2019-03-04 Thread solidstate1991 via Digitalmars-d-learn

https://github.com/ZILtoid1991/dimage/blob/master/source/dimage/png.d

It seems that after a certain point, it doesn't add more data to 
the compression stream, flushing doesn't help.


Re: Odd behavior of darray.dup

2019-02-23 Thread solidstate1991 via Digitalmars-d-learn
On Saturday, 23 February 2019 at 19:21:10 UTC, Bastiaan Veelo 
wrote:


It works for me:
https://run.dlang.io/gist/473b0021487275751accaebeb00be05c

-- Bastiaan


Still no luck, not even with memcpy.

There's even more mystery as I printed out the original static 
immutable array's content, which is different from the 
non-immutable one. Instead of the 32bit hex value of the given 
color in the format of "0x", I get 
"immutable(Color)(#{overlap raw, colors})". This might be a bug.


Odd behavior of darray.dup

2019-02-22 Thread solidstate1991 via Digitalmars-d-learn
If I want to copy an array of structs with .dup (cannot post the 
link in question here at the moment due to non-working clipboard, 
it's Color from pixelperfectengine.graphics.common) I get all 
zeroes instead of the values from the original array. I haven't 
disabled post-blit to my knowledge.


Is it some kind of a bug, or the .dup function has some behavior 
that's not currently documented on the site (such as needing a 
copy constructor)?


Where to start with SafeD?

2019-02-13 Thread solidstate1991 via Digitalmars-d-learn
When I tried to apply to a position at Symmetry, I've got a 
criticism from Atila Neves that some of my code relied too much 
on memcpy, thus making it unsafe. After digging into std.array, I 
found some function that could possibly replace it to emulate 
writing in the middle of a file, but at least for VFile, I need 
some type agnostic solution. I don't think it would be an easy 
task to make CPUBLiT safe, unless I write a high-level wrapper 
for it that works with either array slices and/or on a per-image 
basis, but I don't have a need for such thing at the moment.


Should this library binding work?

2018-12-26 Thread solidstate1991 via Digitalmars-d-learn

https://github.com/ZILtoid1991/bindbc-zstandard

After looking for alternatives to my megaproject of porting LZHAM 
to D (since it had several issues, I'll salvaging my tar 
implementation as well as another archive format meant for 
application data storage), I found out that zstandard not only 
has better ratios than DEFLATE, but also faster (LZHAM was a bit 
below DEFLATE decompression-wise with poor compression rate, 
probably due to poor implementation). So I thought I'll make a 
new binding for zstandard instead as the old one is abandoned 
pretty much at this point.


Currently it compiles, I'll write a testcase for it to see if it 
can load a DLL file tomorrow. I don't really have any real way to 
test it on OSX, might try to test it under Linux since I have a 
second machine with it.


Template matches more than one template declaration error when trying to pass function's pointer

2018-11-30 Thread solidstate1991 via Digitalmars-d-learn
After some refactoring, there are four functions sharing the same 
name (technically four, but LDC didn't complain about them):


@nogc void blitter(T)(T* src, T* dest, size_t length){...}

and

@nogc void blitter(T)(T* src, T* dest, size_t length, T* 
mask){...}


I need the first one, but at compilation time I get the following 
error:


pixelperfectengine\src\PixelPerfectEngine\graphics\layers.d(61,30): Error: 
template CPUblit.composing.blitter matches more than one template declaration:
..\..\..\AppData\Local\dub\packages\cpublit-0.2.3\cpublit\src\CPUblit\composing.d(2006,19):
 blitter(T)(T* src, T* dest, size_t length)
and
..\..\..\AppData\Local\dub\packages\cpublit-0.2.3\cpublit\src\CPUblit\composing.d(2274,19):
 blitter(T)(T* src, T* dest, size_t length, T* mask)


Can opApply be made @nogc?

2018-10-19 Thread solidstate1991 via Digitalmars-d-learn
Since it's a bit difficult to make tree traversal through range 
(especially if someone wants to make it @nogc), I thought I'll 
make it through opApply override, however the delegate passed by 
it doesn't have the @nogc attribute, which would automatically 
make it incapable to be used in a @nogc context.


I also don't know if it would work with structs instead of 
classes, since they're easier to handle in a @nogc situation.


Interfacing D with C++ functions that take reference values

2018-10-03 Thread solidstate1991 via Digitalmars-d-learn
I need some C++ stuff, but some of the functions take reference 
values (Stuff&), and I don't know if this feature is emulated on 
D side with extern(C++) functions. While I don't have to worry 
about it with functions that are defined in the header, other 
ones and classes are a different matter.


Using fibers

2018-08-03 Thread solidstate1991 via Digitalmars-d-learn
I'm porting LZHAM to D, and the original used some very unusual 
approach for coroutines:
 - the whole thing is running inside of a single switch-case 
block created by C++ macros

 - the function saves some local values
 - a macro sets the state variable to the current line number, 
returns the status (eg. if compression error happened or the 
decompressor needs more data), then the function can be continued 
from a new case block labelled by __LINE__


I started to switch out error codes with exceptions, at least 
they also provide more information besides what happened, but 
don't know what should the fate of the other status codes be. I 
probably making them derived from the Throwable class to 
distinguish them from the error codes, or put delegates in place 
of them. I hope the Fiber class will eliminate the ugliness of 
the macro-generated switch-case block, and make the code easier 
to read and debug.


Casting a pointer and length value as a dynamic array

2018-07-30 Thread solidstate1991 via Digitalmars-d-learn
I need this to port a C++ code to D (a compression algorithm 
known as LZHAM), and the easiest way to deal with it would be 
that. The ADLER32 and CRC32 algorithms had to be ditched, and 
while I could rewrite the former to make sense (used some form of 
"vectorization") I would like to use the standard library's 
implementation for the latter.


Re: Using an external Assembler with D

2018-04-25 Thread solidstate1991 via Digitalmars-d-learn

On Wednesday, 25 April 2018 at 15:25:42 UTC, Stefan Koch wrote:

Pass stuff on the stack ;)
and use extern (C) functions.


Thanks! What about extern (D)? Is there a big chaos in the D ABI 
under x86?


Using an external Assembler with D

2018-04-24 Thread solidstate1991 via Digitalmars-d-learn
In order to make one of my own code more readable (and hopefully 
to avoid a lot of compiling errors under LDC, which don't happen 
in DMD for some reason), I'm planning to put my assembly 
functions into separate files for each system that needs them, 
mainly due to the lack of proper SIMD support, mainly due to 
these functions are relatively easy to implement. Here's a few 
questions of mine:


- Can I return vectors in XMM registers and accept arguments as 
vectors in them?
- How much is the D ABI differs on DMD and LDC for x86? I'm 
planning to support both (with mainly using DMD as a debug 
compiler for its speed), and want the most universal solution 
possible.


Better multithreading with D

2018-04-20 Thread solidstate1991 via Digitalmars-d-learn
In order to call a function multiple time at parallel (rendering 
function, very well parallelizable), but in order to push the CPU 
to it's limits I have to get some form of parallelization. 
Currently I'm using parallel foreach, which isn't very nice, and 
since it uses GC allocation that creates some performance impact 
from time to time.


Re: Game and GC

2018-04-08 Thread solidstate1991 via Digitalmars-d-learn

On Monday, 9 April 2018 at 01:01:18 UTC, Chris Katko wrote:
Why... associative arrays? Wouldn't that become expensive when 
you hit 1,000s, or 10,000's of objects, for something as tiny 
as a coordinate (two or three floats) lookup?
Well, that's the other reason why I was looking for a different 
solution. Currently it's quite fast, maybe because it uses 
integers for the most part (only transformation effects use 
floats due to easier workarounds with vectorization), might 
replace the multiple associative arrays with a single 
auto-sorting one.


Checking if a function pointer is set or null

2018-04-08 Thread solidstate1991 via Digitalmars-d-learn
Would the if(!(myFunctionPointer is null)){} work is I 
intended?


Re: Game and GC

2018-04-08 Thread solidstate1991 via Digitalmars-d-learn
On Saturday, 24 February 2018 at 07:12:21 UTC, Guillaume Piolat 
wrote:

From my experience a combination of the following is necessary:
- not having the audio thread registered
- using pools aggressively for game entities


Also you can save a lot of clockcycles if you put @nogc 
everywhere you don't allocate on the heap, the stack will be 
automatically cleaned up.


I'm currently thinking on restructuring the way my engine handles 
display lists on sprites (dynamic array contains the priority, 
multiple associative arrays for Coordinates, sprites, 
attributes), however if enabling exception handling in @nogc 
parts will enable associative array indexing, I'll just skip the 
whole procedure, otherwise probably moving the whole thing to 
rbtree.


Re: Issues using the in-line assembler

2018-04-05 Thread solidstate1991 via Digitalmars-d-learn

Seems I found a better solution hidden in the docs:

@nogc protected int[2] transformFunc(int[2] xy){
version(X86){
asm @nogc{
naked;
mov EBX, this;
movdXMM1, sX[EBX];
pslldq  XMM1, 4;
movss   XMM1, sY[EBX];
movqXMM0, xy;
paddd   XMM0, XMM1; // [x,y] + [sX,sY]
movqXMM3, xy0[EBX];
psubd   XMM0, XMM3; // ([x,y] + [sX,sY] - [x_0,y_0])
movqXMM1, ac[EBX];
movqXMM2, bd[EBX];
pmuludq XMM1, XMM0; // [A,0,C,0] * ([x,y] + [sX,sY] - 
[x_0,y_0])
	psrlq		XMM1, 16;	// ([A,0,C,0] * ([x,y] + [sX,sY] - 
[x_0,y_0]))>>16

movups  XMM4, XMM0;
psrldq  XMM4, 4;
pslldq  XMM0, 4;
por XMM4, XMM0;
pmuludq XMM2, XMM4; // [0,B,0,D] * ([x,y] + [sX,sY] - [x_0,y_0])
	psrlq		XMM2, 16;	// ([0,B,0,D] * ([x,y] + [sX,sY] - 
[x_0,y_0]))>>16
	paddq		XMM1, XMM2; // ([A,B,C,D] * ([x,y] + [sX,sY] - 
[x_0,y_0]))>>16

punpckldq   XMM3, XMM7;
	paddq		XMM1, XMM3;	// ([A,B,C,D] * ([x,y] + [sX,sY] - 
[x_0,y_0]))>>16 + [x_0,y_0]

movups  XMM0, XMM1; // Convert 64 bit vectors into 32 bit 
ones
psrldq  XMM0, 4;
por XMM0, XMM1; 
ret ;
}
}(...)
}


Re: Issues using the in-line assembler

2018-04-05 Thread solidstate1991 via Digitalmars-d-learn

On Thursday, 5 April 2018 at 04:48:02 UTC, Basile B. wrote:
The "this" seems to be in R11, so you have to apply the asm 
syntax for accessing the members using 
.offsetof.[R11], example:


```
class Foo
{
double a = 123456;
extern(D) double foo()
{
asm
{
naked;
movqXMM0, Foo.a.offsetof[R11];
ret;
}
}
}

void main()
{
import std.stdio;
(new Foo).foo(0,0).writeln;
}
```

However i cant find any specification saying that R11 is "this".
With a free function just pass the instance as param and 
replace R11 by the register where the instance is passed.


It seems that the compiler lets it through if I change it like 
this:


asm @nogc{
naked;
movdXMM1, dword ptr sX[EBP];
pslldq  XMM1, 4;
movss   XMM1, dword ptr sY[EBP];
movqXMM0, xy;
paddd   XMM0, XMM1; // [x,y] + [sX,sY]
movqXMM3, qword ptr xy0[EBP];
psubd   XMM0, XMM3; // ([x,y] + [sX,sY] - [x_0,y_0])
movqXMM1, qword ptr ac[EBP];
movqXMM2, qword ptr bd[EBP];
pmuludq XMM1, XMM0; // [A,0,C,0] * ([x,y] + [sX,sY] - 
[x_0,y_0])
	psrlq		XMM1, 16;	// ([A,0,C,0] * ([x,y] + [sX,sY] - 
[x_0,y_0]))>>16

movups  XMM4, XMM0;
psrldq  XMM4, 4;
pslldq  XMM0, 4;
por XMM4, XMM0;
pmuludq XMM2, XMM4; // [0,B,0,D] * ([x,y] + [sX,sY] - [x_0,y_0])
	psrlq		XMM2, 16;	// ([0,B,0,D] * ([x,y] + [sX,sY] - 
[x_0,y_0]))>>16
	paddq		XMM1, XMM2; // ([A,B,C,D] * ([x,y] + [sX,sY] - 
[x_0,y_0]))>>16

punpckldq   XMM3, XMM7;
	paddq		XMM1, XMM3;	// ([A,B,C,D] * ([x,y] + [sX,sY] - 
[x_0,y_0]))>>16 + [x_0,y_0]

movups  XMM0, XMM1; // Convert 64 bit vectors into 32 bit 
ones
psrldq  XMM0, 4;
por XMM0, XMM1; 
ret ;
}
I wonder if I can return an int[2] in XMM0. I can do some 
modifications to either move the result to the stack first, or 
add an import to core.simd (which needs to be refactored 
completely) and instead make the return type int4 on SIMD enabled 
CPUs.


Re: Issues using the in-line assembler

2018-04-04 Thread solidstate1991 via Digitalmars-d-learn

I forgot to tell, that xy0 ac, and bd are local to the class.


Issues using the in-line assembler

2018-04-04 Thread solidstate1991 via Digitalmars-d-learn

I have this code:
asm @nogc{
movqXMM0, xy;
paddd   XMM0, sXY;  // xy + sXY
movqXMM3, xy0;
psubd   XMM0, XMM3; // xy + sXY - x0y0
movqXMM1, ac;
movqXMM2, bd;
pmuludq XMM1, XMM0; // (ac * (xy + sXY - x0y0))
psrlq   XMM1, 16;   // (ac * (xy + sXY - x0y0))>>16
pmuludq XMM2, XMM0; // (bd * (xy + sXY - x0y0))
psrlq   XMM2, 16;   // (bd * (xy + sXY - x0y0))>>16
	paddq		XMM1, XMM2; // (bd * (xy + sXY - x0y0))>>16 * (ac * (xy + 
sXY - x0y0))>>16

punpckldq   XMM3, XMM7;
	paddq		XMM1, XMM3;	// (bd * (xy + sXY - x0y0))>>16 * (ac * (xy + 
sXY - x0y0))>>16 + x0y0

movups  XMM2, XMM1; // Convert 64 bit vectors into 32 bit 
ones
psrldq  XMM2, 4;
por XMM2, XMM1; 
movqresult, XMM2;
}
I'm getting "bad type/size of operand 'movq'" error on xy0, ac, 
and bd when I try to compile it. All of the values are the type 
of int[2], xy is function parameter, sXY is created locally. How 
can I fix it?


Re: Alias on an array element

2017-10-12 Thread solidstate1991 via Digitalmars-d-learn

On Friday, 13 October 2017 at 01:09:56 UTC, solidstate1991 wrote:
I'm making a struct for easy color handling Here's a code 
sample:


ublic struct Color{
union{
		uint raw;	///Raw representation in integer form, also forces 
the system to align in INT32.
		ubyte[4] colors;	///Normal representation, aliases are used 
for color naming.

ubyte alpha, red, green, blue;
}
version(LittleEndian){
alias alpha = colors[0];
alias red = colors[1];
alias green = colors[2];
alias blue = colors[3];
}else{
alias alpha = colors[3];
alias red = colors[2];
alias green = colors[1];
alias blue = colors[0];
}
}

All the aliases are fail to compile, have not found anything 
about it in any of the documentations I checked.


Edit: ubyte alpha, red, green, blue; was added so I can continue 
debugging after the refactoring until I find a solution.


Alias on an array element

2017-10-12 Thread solidstate1991 via Digitalmars-d-learn

I'm making a struct for easy color handling Here's a code sample:

ublic struct Color{
union{
		uint raw;	///Raw representation in integer form, also forces 
the system to align in INT32.
		ubyte[4] colors;	///Normal representation, aliases are used for 
color naming.

ubyte alpha, red, green, blue;
}
version(LittleEndian){
alias alpha = colors[0];
alias red = colors[1];
alias green = colors[2];
alias blue = colors[3];
}else{
alias alpha = colors[3];
alias red = colors[2];
alias green = colors[1];
alias blue = colors[0];
}
}

All the aliases are fail to compile, have not found anything 
about it in any of the documentations I checked.


How to use encode and decode of std.utf

2017-09-09 Thread solidstate1991 via Digitalmars-d-learn
There's not much deep documentation about the functions, and I'm 
interested if it can decode into UTF16 from UTF8.


Re: D is Multiplatform[DUVIDA]

2017-09-09 Thread solidstate1991 via Digitalmars-d-learn

On Friday, 8 September 2017 at 05:13:18 UTC, dark777 wrote:
On Friday, 8 September 2017 at 03:56:25 UTC, rikki cattermole 
wrote:

On 08/09/2017 3:08 AM, dark777 wrote:
On Friday, 8 September 2017 at 00:09:08 UTC, solidstate1991 
wrote:

On Thursday, 7 September 2017 at 23:58:05 UTC, dark777 wrote:
Good night, did you want to know this? Is the DE language 
cross-platform or cross-compile like C ++?


GDC and LDC has multi-platform support, I'm currently 
working on an ARM backend for DMD.


so does it mean that if I develop a program using the D 
language in BSD creating generic resources for example and 
compiling on windows, linux and darwin it would work fine?


Each platform has its own unique behavior and related code.
Gotta try it to know for certain.

But that is unrelated to D in the most part :)


but in any case then the D language can be considered 
multiplatform?


Yes, and it even has language features related to multiplatform 
ddevelopment, eg. conditional compiling.


Re: D is Multiplatform[DUVIDA]

2017-09-07 Thread solidstate1991 via Digitalmars-d-learn

On Thursday, 7 September 2017 at 23:58:05 UTC, dark777 wrote:
Good night, did you want to know this? Is the DE language 
cross-platform or cross-compile like C ++?


GDC and LDC has multi-platform support, I'm currently working on 
an ARM backend for DMD.


Re: 24-bit int

2017-09-02 Thread solidstate1991 via Digitalmars-d-learn
On Friday, 1 September 2017 at 19:39:14 UTC, EntangledQuanta 
wrote:
Is there a way to create a 24-bit int? One that for all 
practical purposes acts as such? This is for 24-bit stuff like 
audio. It would respect endianness, allow for arrays int24[] 
that work properly, etc.


If you need to perform math on integer audio, I strongly suggest 
to use int32 for this purpose to avoid performance degradation, 
then convert back to int24 when you're finished. Probably going 
to add such feature into my PCM library.


Re: How can I serialize a struct into a file in the style of C?

2017-07-22 Thread solidstate1991 via Digitalmars-d-learn

On Saturday, 22 July 2017 at 02:22:53 UTC, Mike Parker wrote:


I should add, though, that you're better off using either 
std.stdio.File or std.file. Use the former if you need to make 
multiple reads/writes to a file, the latter if you can pull it 
in or push it out all in one go. They take arrays as arguments, 
so if you have something like Data[], you can pass it directly 
to the appropriate functions. To write a single instance, 
you'll have to take the pointer and slice it. Either way, it's 
less code, less error prone, and more idiomatic than using the 
C API.


Well, it seems the toStringz() function adds a few garbage 
characters to the end of the filename, I might look into a way to 
read the data with Phobos instead of the C API.


How can I serialize a struct into a file in the style of C?

2017-07-21 Thread solidstate1991 via Digitalmars-d-learn
Due to it's convenience, I was thinking on reading and writing 
file headers by creating structs mirroring the layouts of actual 
headers I would need. I've seen many examples of this in C, 
however I' struggling using the same methods through the use of 
code.stdc.stdio, especially as I can't really trace bugs from 
fread.


Re: iOS Apps in D

2017-05-31 Thread solidstate1991 via Digitalmars-d-learn

On Wednesday, 31 May 2017 at 12:49:38 UTC, Oleksii wrote:

Hi everybody,

Perhaps this topic has been raised many times before, but I'm 
going to go back to it anyways :-P


Are there any good reference materials and/or tutorials on 
programming for iOS and Android in D? I wonder if anybody could 
share their story of success with D on mobile?


Thanks,
--
Oleksii


There's some success on developing for Android under D via LDC, 
the compiler for iOS is even more experimental due to the 
closedness of the system (although not as bad as Windows Phone). 
x86 Android isn't that much tested at this time.


Re: How to setup DLL and EXE projects in one VS solution

2017-05-17 Thread solidstate1991 via Digitalmars-d-learn

On Wednesday, 17 May 2017 at 16:56:13 UTC, Igor wrote:

At the moment I have:

EXEProject:
  app.d - it does loadlibrary of dllproj and uses data 
structures defined in dllproj.d (it imports dllproj). On the 
file system this file is under /platform/win32/ 
and is defined as module win32.app;


DLLProject
  dllproj.d - exports functions and contains data structures 
those function use. On file system this file is under 
/source and is defined as module dllproj;


EXEProject depends on DLLProject. DLL project compiles and 
builds DLL fine but, of course EXE project breaks with an error:


module dllproj is in file dllproj.d which cannot be read.

I could just copy all the structs from dllproj.d to app.d and 
remove the import and I guess it would all work but there has 
to be a better way to structure code so structs are only 
written in one place?


I think you should make a binding for your DLL file. On the other 
hand I successfully set up a static library and an application in 
the same solution (now it has 2 apps, one is my map editor and 
file converter, the other is a window layout editor, going to add 
a third one for testing other functions later on) by adding the 
engine's sources and library files to the app.


Re: ordered Associative array

2017-04-13 Thread solidstate1991 via Digitalmars-d-learn

On Friday, 14 April 2017 at 00:29:34 UTC, Jethro wrote:
Is there a way to retain the ordering of an associative array? 
When the elements are added then looped over using a foreach, 
the order is different.


Use a separate array to store the keys, order them all time when 
you add a new one, etc. This was the only workaround I could come 
up with for my engine (see it here: 
https://github.com/ZILtoid1991/pixelperfectengine/blob/master/source/PixelPerfectEngine/graphics/layers.d at Classes SpriteLayer and SpriteLayer32Bit), maybe in the future I'll come up with a better solution. I call this technique as "prioritized hash table" as the keys give them a certain priority, so there's no issue which sprite where supposed to show up.


Re: Use of "T"

2017-04-12 Thread solidstate1991 via Digitalmars-d-learn

On Wednesday, 12 April 2017 at 16:05:23 UTC, XavierAP wrote:
On Wednesday, 12 April 2017 at 14:46:20 UTC, solidstate1991 
wrote:




T is just the common name of a (type) parameter, mostly 
whenever the template is more generic that you can't think of a 
more informative (template) parameter name. Just like you could 
use "str" for a string or "i" for an int name. But in you case 
you could use a more informative name such as "keyType" since 
you are describing keyType -> valueType dictionaries, also 
called associative arrays.


Moreover these dictionaries are built-in basic types in D:
https://dlang.org/spec/hash-map.html





So according to the spec linked above, those examples would be 
declared:


string[int] dict1;
string[string] dict2;
int[string] dict3;


I know the existence of those and I'm frequently using them, 
however I need a two-way one. (Might be using two hash-tables 
instead if I can't find a better solution)


Re: Use of "T"

2017-04-12 Thread solidstate1991 via Digitalmars-d-learn

On Wednesday, 12 April 2017 at 13:54:11 UTC, qznc wrote:
On Wednesday, 12 April 2017 at 13:17:42 UTC, solidstate1991 
wrote:
How can I make use of T? I've seen it being used many times 
for this application.


What "T"? This letter is often used as a generic template 
parameter. Are you talking about templates?


Maybe you can give some examples of the "many times" you have 
seen it used?


Yes, templates. I've looked this up a bit, and I found it. I want 
to use it to use the dictionaries for different things than 
string<->int conversion. This should be the Dictionary(int), 
string<->string conversion should be done with 
Dictionary(string). Int<->string should be done as 
Dictionary(string,int) if possible.


Use of "T"

2017-04-12 Thread solidstate1991 via Digitalmars-d-learn
Some utilities of my game engine needs a two-way "dictionary", 
mainly for increasing the readability of configuration files, but 
I was thinking on letting the end-user to use it for certain 
things and I don't want to recreate the encode/decode/load from 
SDLang file functions every time I have to use a similar thing. 
Currently I need to use it for int<->string conversion only (key 
names, button names, axis names, etc.), in the future I might use 
it for even more purpose (language files are planned to use XML 
due to the possibility of using UTF16, as the engine's native 
character handling is using it, not to mention the easier 
formatting via markup).


How can I make use of T? I've seen it being used many times for 
this application.


Re: Problems with setting up dub for publication

2017-03-04 Thread solidstate1991 via Digitalmars-d-learn
Replaced all the ~> with ==, now I'm getting error from dub 
wanting to use the alpha versions of the derelict libraries, 
which have minor compatibility issues with my project.


Problems with setting up dub for publication

2017-03-04 Thread solidstate1991 via Digitalmars-d-learn

My graphics engine contains two subpackages currently:

-PixelPerfectEngine (the engine itself)

-PixelPerfectEditor (the editor/converter, uses the engine itself 
to display screen data)


However, after I wrote the dub.json and try to compile it as a 
test, I get this output:


Building package pixelperfectengine in 
G:\Developing\PixelPerfectEngine\

Performing "debug" build using dmd for x86.
pixelperfectengine ~master: building configuration "library"...
source\PixelPerfectEditor\app.d(15,8): Error: module sdl is in 
file 'derelict\sdl2\sdl.d' which cannot be read

import path[0] = source
import path[1] = C:\D\dmd2\windows\bin\..\..\src\phobos
import path[2] = C:\D\dmd2\windows\bin\..\..\src\druntime\import
dmd failed with exit code 1.

Here's the json file:

{

"name": "pixelperfectengine",

"authors": [
"Laszlo Szeremi"
],

"description": "A 2D game engine for retro styled games",

	"copyright": "Copyright 2015-2017 by Laszlo Szeremi under Boost 
license",


"license": "Boost",
"subPackages": [
{
"name": "pixelperfectengine",
"sourcePath": "source/pixelperfectengine",
"importPath": "source",
"targetpath": "lib",
"dependencies":
{

"derelict-sdl2": "~>2.1.0",

"derelict-util": "~>2.1.0"

},

},
{
"name": "pixelperfecteditor",
"sourcePath": "source/pixelperfecteditor",
"importPath": "source",
"targetpath": "bin/pixelperfecteditor",
"dependencies":
{
"pixelperfectengine:pixelperfectengine": "*",
"derelict-sdl2": "~>2.1.0",

"derelict-util": "~>2.1.0"
,
"derelict-fi": "~>3.0.0-alpha.1"
},
}
],
}

The dependencies compile by themselves (as I don't like to use 
dub because of things like this), I don't know what's the problem.


Reading image files

2016-11-25 Thread solidstate1991 via Digitalmars-d-learn
After I couldn't figure out how to convert Imageformats' own 
format to my own (consequential read from IFImage resulted in a 
glitchy image after rendering the result) and I have no idea how 
DerelictFI works at all, I'm currently out of options. At least I 
need PNG and TGA (the latter is important as my rendering engine 
relies on transparencies), the best could be is to be able to 
read paletted bitmaps directly, which is a missing feature in 
Imageformats.


Multi-threading how-to

2016-08-31 Thread solidstate1991 via Digitalmars-d-learn
I decided to write a shared library for OSC in D despite the lack 
of popularity.


I decided to add a functionality that if multiple programs use 
the same instance of the library on the same computer, the 
messages will be passed directly instead of via networking.


Unfortunately we barely touched multi-threading in college. Some 
suggestions?


Is this a bug or I made some mistake?

2016-08-29 Thread solidstate1991 via Digitalmars-d-learn
Since I have some screenshots: 
https://twitter.com/EvilReptoid/status/770303804550021121


I needed a bitarray, that had some more capability than the one 
in std.bitmanip for collision detection. I could test a whole 
line with it at once if my predictions are right. However I 
couldn't do the array slicing effectively if that code doesn't 
work. Some idea?


Using external libraries the correct way

2016-07-17 Thread solidstate1991 via Digitalmars-d-learn
Up to this day, I have to use them by dragging the source into my 
project. When I tried to import imageformats, the compiler looks 
up for the file imageformats.d and fails to finish the program.


I'm not using command line for compiling, I use Xamarin with 
mono-D instead.


Creating a JSON file

2015-02-03 Thread solidstate1991 via Digitalmars-d-learn
I wrote my graphics engine with CodeBlocks, and I only used dub 
when I complied the derelict SDL2 libs.


https://github.com/ZILtoid1991/VDP-engine

You can find the sources here.