Pages: 1
  Print  
Author Topic: Error with bitmask operations  (Read 2554 times)
Offline (Unknown gender) ojars
Posted on: May 29, 2019, 11:56:03 PM
Member
Joined: May 2019
Posts: 16

View Profile
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?
« Last Edit: May 30, 2019, 01:37:46 AM by ojars » Logged
Offline (Male) Goombert
Reply #1 Posted on: May 30, 2019, 06:27:56 AM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3151

View Profile
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:
y = ((unsigned int)y&$ffffffe0)+32;
« Last Edit: May 30, 2019, 06:29:46 AM by Goombert » Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) ojars
Reply #2 Posted on: May 30, 2019, 07:43:13 AM
Member
Joined: May 2019
Posts: 16

View Profile
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.
« Last Edit: May 30, 2019, 07:46:46 AM by ojars » Logged
Offline (Male) Goombert
Reply #3 Posted on: May 30, 2019, 06:56:08 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3151

View Profile
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!
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Pages: 1
  Print