Jump to content


Photo

Ds_bin Dll


  • Please log in to reply
29 replies to this topic

#1 Maarten Baert

Maarten Baert

    GMC Member

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

Posted 10 May 2009 - 07:14 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:36 AM.

  • 1

#2 IamCalle

IamCalle

    GMC Member

  • GMC Member
  • 444 posts

Posted 21 May 2009 - 03:03 AM

Thank you. =D
  • 0

#3 kake_fisk

kake_fisk

    GMC Member

  • New Member
  • 2391 posts
  • Version:GM7

Posted 24 May 2009 - 08:51 PM

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

#4 score_under

score_under

    Least kawaii

  • GMC Member
  • 1319 posts

Posted 24 May 2009 - 11:27 PM

My avg said your screenie was infected, but idk.

It's a .PNG file.
  • 0

#5 Maarten Baert

Maarten Baert

    GMC Member

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

Posted 25 May 2009 - 08:14 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

#6 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 10 April 2010 - 08:36 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 - 10:50 AM.

  • 0

#7 Maarten Baert

Maarten Baert

    GMC Member

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

Posted 18 April 2010 - 03:55 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

#8 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 25 April 2010 - 06:43 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 - 06:46 AM.

  • 0

#9 Maarten Baert

Maarten Baert

    GMC Member

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

Posted 29 April 2010 - 09:57 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

#10 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 02 May 2010 - 05:49 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

#11 57E

57E

    GMC Member

  • GMC Member
  • 44 posts

Posted 13 July 2010 - 10:09 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:10 AM.

  • 0

#12 safwat1995

safwat1995

    GMC Member

  • New Member
  • 394 posts

Posted 12 February 2011 - 04:23 AM

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

#13 57E

57E

    GMC Member

  • GMC Member
  • 44 posts

Posted 17 March 2011 - 06:32 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

Posted 18 March 2011 - 04:15 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

Posted 19 March 2011 - 05:46 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
  • 44 posts

Posted 19 March 2011 - 04:46 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
  • 44 posts

Posted 30 May 2011 - 08:46 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 - 08:59 PM.

  • 0

#18 Maarten Baert

Maarten Baert

    GMC Member

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

Posted 31 May 2011 - 10:24 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

#19 57E

57E

    GMC Member

  • GMC Member
  • 44 posts

Posted 31 May 2011 - 06:54 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
  • 715 posts
  • Version:GM8.1

Posted 31 May 2011 - 08:58 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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users