Jump to content


Photo

Ds_bin Dll


  • Please log in to reply
31 replies to this topic

#1 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 10 May 2009 - 07:28 PM

This DLL adds a new data structure to Game Maker. A ds_bin looks a bit like a grid, but there are some differences:
- A ds_bin can use up to 3 dimensions.
- A ds_bin contains only unsigned integers.
- You can choose the number of bits for each entry. Because of this a ds_bin uses almost no memory, this means you can use huge grids (for example 1000x1000) without running out of memory. You can use it as an alternative for surfaces, for example. For comparison: a ds_grid uses 10 bytes per cell!

There are functions for almost everything. For example, you can:
- add/subtract/multiply/divide two ds_bins
- change values of ds_bin A if the corresponding value of ds_bin B is equal/not equal/smaller/larger/... than the corresponding value of ds_bin C
- use a 'weighted' random function to select random cells (cells with a higher value will be selected more often, cells with a value of zero will never be selected)
- ...
The DLL contains 129 functions. I just added anything I could think of. If you need more functions, PM me.

Download: DS_bin - ZIP (190kb) (the compressed DLL is only 16kb, most of the file size is used by the examples)

The zip file contains the dll, a script file, an extension, and a few examples (gmk):
- Langton's Ant simulation, using both ds_bin and surfaces for comparison
- Conway's game of life
- Maze generator

Posted Image
A screenshot of the Langton's Ant simulation

Good luck!

Edited by Maarten Baert, 29 October 2012 - 12:50 AM.

  • 2
Posted Image

#2 IamCalle

IamCalle

    GMC Member

  • GMC Member
  • 444 posts

Posted 21 May 2009 - 03:17 AM

Thank you. =D
  • 0

#3 kake_fisk

kake_fisk

    GMC Member

  • GMC Member
  • 2392 posts
  • Version:GM7

Posted 24 May 2009 - 09:05 PM

My avg said your screenie was infected, but idk.
  • 0

#4 score_under

score_under

    Least kawaii

  • GMC Member
  • 1321 posts

Posted 24 May 2009 - 11:41 PM

My avg said your screenie was infected, but idk.

It's a .PNG file.
  • 0

Anti-Decompiler for GM6.1 to GM8.1.91! :GM8_new: [Main skin by Sindarin]
Discontinued.

decimal2.png
^ Signature image because it's been sorta empty since the old host died

If you need to contact me, I still get notification emails from PMs.


#5 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 25 May 2009 - 08:28 PM

I have uploaded the same image but this time I saved it with another program. Is AVG still showing that warning now? (refresh this page to clear cache)
  • 0
Posted Image

#6 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 10 April 2010 - 08:50 AM

My programs values are not actually being stored, it does not seem very logical what's wrong:
test = ds_bin_create(32, 5, 5, 0);
ds_bin_set_cell(2, 2, 0, 100);
show_message(string(ds_bin_get_cell(2, 2, 0)));
Displays -1. =\

Oh it's a bug, cannot have a 32-bit integer for some reason..

Edited by Krisando, 10 April 2010 - 11:04 AM.

  • 0

Posted Image


#7 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 18 April 2010 - 04:09 PM

My programs values are not actually being stored, it does not seem very logical what's wrong:

test = ds_bin_create(32, 5, 5, 0);
ds_bin_set_cell(2, 2, 0, 100);
show_message(string(ds_bin_get_cell(2, 2, 0)));
Displays -1. =\

Oh it's a bug, cannot have a 32-bit integer for some reason..

You forgot to use ds_bin_select. I've fixed the 32-bit bug now.
  • 0
Posted Image

#8 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 25 April 2010 - 06:57 AM

For some reason "ds_bin_find_region_continue()" isn't working so well for me. It will not seek the next value then give a null end type of value, stating it has reached the end of seeking range.

Correct me if i'm wrong.

Kris.

Edited by Krisando, 25 April 2010 - 07:00 AM.

  • 0

Posted Image


#9 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 29 April 2010 - 10:11 AM

You're right, there was still a bug. I've fixed it now.

I tested it with this code:
var a;

a = ds_bin_create(4,10,10,1);
ds_bin_clear(a,0);
ds_bin_select(a);

ds_bin_set_cell(2,3,0,12); // will be found
ds_bin_set_cell(4,3,0,12); // will be found
ds_bin_set_cell(1,4,0,12); // will be found
ds_bin_set_cell(8,7,0,12); // not inside the region

if ds_bin_find_region(1,1,0,7,7,1,12) {
do {
show_message("Found: ("+string(ds_bin_get_x())+","+string(ds_bin_get_y())+","+string(ds_bin_get_z())+")");
} until !ds_bin_find_region_continue(1,1,0,7,7,1,12);
}

ds_bin_destroy(a);

  • 0
Posted Image

#10 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 02 May 2010 - 06:03 AM

You're right, there was still a bug. I've fixed it now.

Thankyou for your prompt responses. I feel like this is an expensive commercial product, with exceptional customer service. ;D
  • 0

Posted Image


#11 57E

57E

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM:Studio

Posted 13 July 2010 - 10:23 AM

With any of the region funcitons, if you accidentally use an area too large to fit inside the bin it will cause an "Unexpected error" - message and crash.

You might want to put your own error message in there. I thought the crash was caused by something complitely else, and only recently noticed that one of the ds_bin_set_region() -calls could sometimes try to use region wich was 1 unit outside the bin borders.

But thats only a minor error.

Your dll has greatly helped me in my project :)

Edited by 57E, 13 July 2010 - 10:24 AM.

  • 0

#12 safwat1995

safwat1995

    GMC Member

  • New Member
  • 394 posts
  • Version:Unknown

Posted 12 February 2011 - 04:37 AM

The download link is broken :(
I desperately need this for my A* algorithms
  • 0

#13 57E

57E

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM:Studio

Posted 17 March 2011 - 06:46 PM

The download link is broken :(
I desperately need this for my A* algorithms

ds_bin.zip
  • 1

#14 safwat1995

safwat1995

    GMC Member

  • New Member
  • 394 posts
  • Version:Unknown

Posted 18 March 2011 - 04:29 PM

The download link is broken :(
I desperately need this for my A* algorithms

ds_bin.zip


Thanks a thousand times!
I truly appreciate this.
  • 0

#15 safwat1995

safwat1995

    GMC Member

  • New Member
  • 394 posts
  • Version:Unknown

Posted 19 March 2011 - 06:00 AM

that would be 60% less memory usage at WORST (if we use 32 bits for EVERY grid) and 95% less memory at the best case (if we use 4 bits for every grid)

Love this DLL!!
  • 0

#16 57E

57E

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM:Studio

Posted 19 March 2011 - 05:00 PM

@ safwat1995
As do I. ;)

@ Maarten Baert
Thanks for adding ds_bin_serialize and ds_bin_unserialize functions.
  • 0

#17 57E

57E

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM:Studio

Posted 30 May 2011 - 09:00 PM

ds_bin_serialize does nothing if the bin given is large enough. 64x64x64 for example seems to be too much, number of bits doesn't seem to matter.
Maybe the string would be too long for gm? :huh:



And another thing I noticed when serializing bins:

If I have a simple 2x2x1 bin with values

1|2
3|4


If the bin has 16 bits.
When serialized it looks like this: 0100020003000400

If the bin has 8 bits.
When serialized it looks like this: 01020304

And if the bin has 4 bits.
When serialized it looks like, well it looks like this: 21430000

Writing 4 bit bin to a string takes as much space as egual sized bin with 8 bits.
Why so many zeroes?

It's very possible that Im missing something important here, but shouldn't my simple example array fit in a string with a length of just four characters if its only 4 bits?

Edited by 57E, 30 May 2011 - 09:13 PM.

  • 0

#18 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 31 May 2011 - 10:38 AM

It will always return at least 8 characters because I use an array of 32-bit integers internally to store the data. So even if you use only 16 bits, the DLL will still create an array of one 32-bit integer. And for simplicity the serialize and unserialize functions just return the entire array, even though the end is not used.

I have no idea why it doesn't work for large ds_bins. I've used very large hex strings (more than a million characters) before, it should work.
  • 0
Posted Image

#19 57E

57E

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM:Studio

Posted 31 May 2011 - 07:08 PM

I have no idea why it doesn't work for large ds_bins. I've used very large hex strings (more than a million characters) before, it should work.


I'll see if I could come up with some exact bin sizes where it stops working.
Now I can only say that my bins are in sizes of 128x128x128, 64x64x64 and 32x32x32 with 8 bits. And only the 32x32x32 is only one that works properly. For larger bins it instantly returns an empty string.
  • 0

#20 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 31 May 2011 - 09:12 PM

Are you sure the id's are correct? ds_bin_serialize only returns an empty string in two situations:
- if the id doesn't exist
- if there is not enough free memory
But even a 128x128x128 ds_bin uses just 2MB, or 4MB when serialized. That shouldn't be a problem.

Maybe GM is limiting the length of strings. Can you send me a GMK that displays this problem?
  • 0
Posted Image

#21 57E

57E

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM:Studio

Posted 01 June 2011 - 12:37 PM

I made new example from a scratch and got the serializing working as it should.

So I'll have to take my level editor apart and see whats wrong with it.

- if there is not enough free memory

This desktop only has 1024mb of ram. And Im not sure at all how much models and their textures take space as models are genrated on the run.

Ok. Serializing the bins and writing them to file immediately at the game start, before the level model generating stuff starts, works perfectly and is suprisingly fast too.

Sorry for wasting your time.
  • 0

#22 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 01 June 2011 - 11:17 PM

No problem :). I'm glad you've fixed it .

If you run out of physical memory Windows will start using your hard drive instead. This is extremely slow, but it will still work. Every (32-bit) process can use up to 2GB (or 3GB if you change some setting), from that point allocations will fail anyway because the memory space is full. So even with 1GB of RAM memory shouldn't be the problem.
  • 0
Posted Image

#23 57E

57E

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM:Studio

Posted 26 June 2011 - 05:15 PM

Spoiler

Run this code first without any changes to see what it's supposed to do, and then change the variable "size = 32" to either 64 or 128 (for example) and see if it causes an unexpected error for you too.

Edited by 57E, 26 June 2011 - 05:21 PM.

  • 0

#24 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 27 June 2011 - 09:07 PM

It runs just fine in GM8, but it crashes in GM8.1. I attached the debugger and I get an access violation inside my DLL. It's a bit hard to find out what's happening because I only have the disassembly (the DLL was compiled with GCC, I'm using VC++ for debugging), but this ...
69B016D5  mov         eax,dword ptr [ebp+10h]  
69B016D8  mov         dword ptr [esp],eax  
69B016DB  call        69B137F8  <<< crashes inside this function
69B016E0  mov         ecx,dword ptr [esi+1Ch]  
69B016E3  lea         edx,[ecx+ecx]  
69B016E6  cmp         eax,edx  
69B016E8  je          69B016F8  
69B016EA  fld         dword ptr ds:[69B15014h]  
69B016F0  add         esp,2Ch  
69B016F3  pop         ebx  
69B016F4  pop         esi  
69B016F5  pop         edi  
69B016F6  pop         ebp  
69B016F7  ret  
... looks very similar to this ...
if(strlen(data)!=bin->size*2) return -1;
So apparently strlen() is crashing, which means the string is not NULL-terminated like it should be. Sounds like a GM8.1 bug. I will submit a bug report, but since YYG hasn't responded to any bug report for more than a month I don't think you should wait for them to fix it. Do you still have GM8.0?

Edited by Maarten Baert, 27 June 2011 - 09:09 PM.

  • 0
Posted Image

#25 57E

57E

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM:Studio

Posted 28 June 2011 - 09:12 AM

Yes I still have GM8.0
I'll try to convert my gm81 files pack to gmk and see if it works.

BTW
I read your bug report, funny it seems that all my recent gm problems are caused by this same bug. :D
Filepaths being screwed up in kbzip and several older file packing dlls I tried to get working all this month.
Hopefuly the next GM8.1 patch won't take all year.

Edited by 57E, 28 June 2011 - 09:17 AM.

  • 0

#26 57E

57E

    GMC Member

  • GMC Member
  • 64 posts
  • Version:GM:Studio

Posted 04 June 2012 - 03:35 PM

I don't know if you are still intrested for working on this, but here goes:

I would need functions to rotate an region of a bin around regions X, Y and Z axels, clockwise or counterclockwise.

In example this:

1|2|3
4|5|6
7|8|9

Rotated clockwise on Z axel:

7|4|1
8|5|2
9|6|3

Edited by 57E, 04 June 2012 - 03:38 PM.

  • 0

#27 Zesterer

Zesterer

    Professor of Articul

  • GMC Member
  • 1044 posts
  • Version:GM8

Posted 14 August 2012 - 12:24 PM

Sorry for bumping such an old topic but:

I tried this, then I realised that ds_bin_get(x,y,z,val) does not have an argument for choosing the ds bin. Does this mean it can only support one data structure at once? :S I hope not, I need it to support several hundred smaller 3D ones!

Zesterer

EDIT: Solved two minutes after I posted, i missed the ds_bin_select() function. Thanks for creating this amazing DLL!

EDIT 2: Anyway, this topic deserves to be bumped!

Edited by Zesterer, 15 August 2012 - 08:47 AM.

  • 0

Fortified - The sword thrusting, castle busting, catapult adjusting new Tower Defense game!

More projects and work coming soon... If you need help on voxels, mesh rendering, physics, perlin noise generation, 3D, mathematics or more just contact me and I'll be happy to help!

Skype: zesterer                Email: barry.of.smith@gmail.com <---- Actually, don't use this address, I never check it.


#28 brod

brod

    Brian RODriguez

  • GMC Member
  • 2050 posts
  • Version:GM8

Posted 19 March 2013 - 07:46 PM

Hi so I think I'm having trouble understanding how this works...

 

I'm trying to make a 5 bit bin that should store values from 0 - 31, but when I store ints it doesn't seem to work until I use at least 8 bits. Do you not store the least significant bits of an int or am I just using this wrong? Thanks for any help


  • 0

#29 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 25 March 2013 - 11:50 PM

That's because 5 bit is not supported. Only 1, 2, 4, 8, 16 or 32 :).


  • 0
Posted Image

#30 brod

brod

    Brian RODriguez

  • GMC Member
  • 2050 posts
  • Version:GM8

Posted 26 March 2013 - 02:40 AM

Aw ok, thanks for letting me know!

 

Another question, ds_bin_copy_part seems to be pretty buggy... Does anyone else have this issue? To the creator, may I suggest you implement it like GML scripts does their script, ds_grid_set_grid_region, that way I don't have to worry about creating a copy of the bin on my end of the coding side. If it is, then I'm sorry, I must just be implementing it wrong :(

 

Maybe it's because my code sometimes require that the area be copied to a negative position? I'm basically shifting the bin around as my player moves around, and I need it to do that so that I can reduce how many times I need to load cells. So sometimes it shifts by -1, or +3, etc. etc.

 

This code, for example, does exactly what I want:

 var copy,i,j,k,val;
    copy = ds_bin_create(8, worldVectorGrid_s, worldVectorGrid_s, 4);
    ds_bin_copy_direct(copy, worldVectorGrid);
    
    for (k = 0; k < 4; k+= 1)
    for (j = 0; j < worldVectorGrid_s; j+=1)
    for (i = 0; i < worldVectorGrid_s; i+=1)
    {
        ds_bin_select(copy);
        val = ds_bin_get_cell(i, j, k);
        ds_bin_select(worldVectorGrid);
        ds_bin_set_cell(i + argument0, j + argument1, k, val);
    }
    
    ds_bin_destroy(copy);

 

I figured that all of that code should do exactly what this should:

 

ds_bin_copy_part(worldVectorGrid, worldVectorGrid, argument0, argument1, 0, 0, 0, 0, worldVectorGrid_s, worldVectorGrid_s, 4);

Edited by brod, 27 March 2013 - 05:25 PM.

  • 0

#31 Elevory

Elevory

    GMC Member

  • GMC Member
  • 22 posts

Posted 30 September 2013 - 10:54 AM

Does this work in GameMaker: Studio?

 

Using the GEX extension, the following test returns 0:

test = ds_bin_create(8, 10, 10, 3);
ds_bin_select(test);
ds_bin_set_cell(1, 1, 1, "hello");
show_message(ds_bin_get_cell(1,1,1));

 

Using the DLL, I get a stack overflow error caused by ds_bin_create.


  • 0

#32 GamerXP

GamerXP

    GMC Member?

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 13 February 2014 - 02:01 PM

Maarten Baert, that's really useful DLL (not only because of memory usage, but also because it have 3 dimenstions). But I think it misses few important functions: how do I return the dimensions of ds_bin? I want to manually loop through all values, but I can't find a way to return width and height of a ds_bin;

 

 

Does this work in GameMaker: Studio?

 

Using the GEX extension, the following test returns 0:

test = ds_bin_create(8, 10, 10, 3);
ds_bin_select(test);
ds_bin_set_cell(1, 1, 1, "hello");
show_message(ds_bin_get_cell(1,1,1));

Using the DLL, I get a stack overflow error caused by ds_bin_create.

 

Use GML version. I don't know how it worked before, but there are no return() in scripts. So it always returns 0. You need to add return() to scripts for them to start working. Like:

/// ds_bin_create(bits,size_x,size_y,size_z)
return(external_call(global.define_ds_bin_create,argument0,argument1,argument2,argument3))

  • 0