ENIGMA Forums

Outsourcing saves money => Programming Help => Topic started by: ojars on May 29, 2019, 11:56:03 pm

Title: Error with bitmask operations
Post by: ojars on May 29, 2019, 11:56:03 pm
Hi!
In platformers for a collision checking with obstacles I don't use objects, instead, I create a collision map and use bitmask operations, for example:
if (get_block(x, y + 1) &  (BLOCK | LADDER_TOP))) 
   y = (y&$ffffffe0)+32;
where BLOCK and LADDER_TOP are constants (macros) and get_block() is a script.
In GM this works nice, but in ENIGMA I got an error: C:/Users/User/AppData/Local/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:367:13: error: invalid operands of types 'cs_scalar' {aka 'double'} and 'unsigned int' to binary 'operator&'
  367 |       y =(y & 0xffffffe0)+ 32;
      |           ~ ^ ~~~~~~~~~~
      |           |   |
      |           |   unsigned int
      |           cs_scalar {aka double} 

What is the right way to write such expressions?
Title: Re: Error with bitmask operations
Post by: Goombert on May 30, 2019, 06:27:56 am
That's interesting. I would actually consider this a bug sort of. We are clearly storing x/y as collision system scalar which is just a double. There's no such thing as bitwise operations on floating point numbers. ENIGMA would only be able to get around this by changing the x/y of every object to var (eh, that'll slow it down a bit) or making a new type of double that allows binary operators.

Here's a temporary workaround:
[snip]y = ((unsigned int)y&$ffffffe0)+32;[/snip]
Title: Re: Error with bitmask operations
Post by: ojars on May 30, 2019, 07:43:13 am
Thanks, with casting to uint code works. But there is another problem.  I have code
Code: [Select]
///create_collision_map(col_map, w, h)
/*
constants: blocks
    EMPTY      = 0
    BLOCK      = 1
    LADDER     = 2
    LADDER_TOP = 4
    LADDER_WAT = 8
    WATER      = 16
    ACID       = 32
    GATE       = 64
    LAMP       = 128   
*/

var map = argument0;
var w = argument1;
var h = argument2;

for (var j = 0; j < h; j++) {
    for (var i = w - 1; i > -1; i--) {
      map[@ j, i] = 0;//error
    }
}

var xpos, ypos, t, xx, yy, left, xpos;//, top, ypos, ind;
var bgw = background_get_width(col_tiles) >> 6;
//store all tiles in the array
for (ypos = 0; ypos < room_height; ypos += BL_SIZE) {
    for (xpos = 0; xpos < room_width; xpos += BL_SIZE) {       
        t = tile_layer_find(0, xpos, ypos);       
        if (t > 0) {
            left = tile_get_left(t) >> 6;
            switch(left) {
                case 1: map[@ ypos >> 6, xpos >> 6] = BLOCK;      break;
                case 2: map[@ ypos >> 6, xpos >> 6] = LADDER;     break;
                case 3: map[@ ypos >> 6, xpos >> 6] = LADDER_TOP; break;
                case 4: map[@ ypos >> 6, xpos >> 6] = LADDER_WAT; break;
                case 5: map[@ ypos >> 6, xpos >> 6] = WATER;      break;
                case 6: map[@ ypos >> 6, xpos >> 6] = ACID;       break;
                case 7: {
                    var lamp = array_create(5);
                    lamp[L.x] = xpos;
                    lamp[L.y] = ypos;
                    lamp[L.spr] = get_lamp_sprite();
                    lamp[L.frm] = 0;
                    lamp[L.spd] = random_range(0.05, 0.2);
                    ds_list_add(g.lamplist, lamp);
                }
                    break;
            }
        }//if t
    }//for xpos
}//for ypos

tile_layer_delete(0);

}

And there is an error:
Syntax error in script 'create_collision_map'
Line 19, position 13(absolute 386): Unexpected symbol '@': unknown to compiler

If I understand right, ENIGMA does not allow GML acessors for arrays, lists and so on.
Title: Re: Error with bitmask operations
Post by: Goombert on May 30, 2019, 06:56:08 pm
That's good. Your next problem is not solvable yet, and is a feature request in ENIGMA. We do not yet support data structure accessors or the associated operators. Our plan is to add normal accessors and the GML variant will be purely syntactic sugar. We just haven't had time to get to it yet. Please be patient, thanks!