Free Hero Mesh

Diff
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.

Differences From Artifact [bffe9b84f5]:

To Artifact [bd128e8f11]:


2033
2034
2035
2036
2037
2038
2039

























































2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058

2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
  v=send_message(n2,n1,MSG_COLLIDING,NVALUE(objects[n2]->x),NVALUE(objects[n2]->y),NVALUE(r2));
  if(v.t) Throw("Type mismatch");
  h|=v.u;
  if((h&0x0002) && try_sharp(n1,n2)) h|=0x0004;
  if((h&0x00020000) && try_sharp(n2,n1)) h|=0x00040000;
  return h;
}


























































static Uint32 deferred_colliding(Uint32 obj,int x,int y) {
  Object*o=objects[obj];
  Object*oE;
  Uint32 h=0xFFFFFFFF;
  Uint32 objE=playfield[x+y*64-65];
  Uint8 d;
  int xx,yy;
  while(objE!=VOIDLINK) {
    oE=objects[objE];
    if(!(oE->oflags&(OF_DESTROYED|OF_VISUALONLY))) {
      if(oE->oflags&OF_MOVING) {
        // At this point, it is necessary to check for a loop, which may be like the diagram below:
        //     >>>>>>>v
        //        ^<<<<
        // The loop may also have a different shape.
        // If a loop is found, call the handle_colliding function to determine what to do next.
        // If there is no loop, allow the move to be retried later, trying objE's location next.
        

      }
      if(oE->height>o->climb || (classes[o->class]->collisionLayers&classes[oE->class]->collisionLayers)) {
        h&=handle_colliding(obj,objE,1,0);
        
      }
    }
    objE=oE->up;
  }
  
  // Find other objects trying to move to the same place
  if(h&8) for(d=0;d<8;d++) {
    xx=x-x_delta[d];
    yy=y-y_delta[d];
    if(xx<1 || xx>pfwidth || yy<1 || yy>pfheight) continue;
    objE=playfield[xx+yy*64-65];
    while(objE!=VOIDLINK) {
      oE=objects[objE];
      if(obj!=objE && (oE->oflags&OF_MOVING) && oE->dir==d && !(oE->oflags&OF_DESTROYED)) {
        if(o->height>oE->climb || oE->height>o->climb || (classes[o->class]->collisionLayers&classes[oE->class]->collisionLayers)) {
          h&=handle_colliding(obj,objE,2,2);
          
        }
      }
      objE=oE->up;
    }
    
  }
  
  return ~h;
}

static void do_deferred_moves(void) {
  Object*o;
  Object*p;
  Uint32 h,n;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>











|
|
<
<
<
|
<
|
>
|
|

<




<











<




|
<
<







2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109



2110

2111
2112
2113
2114
2115

2116
2117
2118
2119

2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130

2131
2132
2133
2134
2135


2136
2137
2138
2139
2140
2141
2142
  v=send_message(n2,n1,MSG_COLLIDING,NVALUE(objects[n2]->x),NVALUE(objects[n2]->y),NVALUE(r2));
  if(v.t) Throw("Type mismatch");
  h|=v.u;
  if((h&0x0002) && try_sharp(n1,n2)) h|=0x0004;
  if((h&0x00020000) && try_sharp(n2,n1)) h|=0x00040000;
  return h;
}

static inline Uint8 find_deferred_movement_loop(Uint32 obj,Uint8 xx,Uint8 yy) {
  // At this point, it is necessary to check for a loop, which may be like the diagram below:
  //     >>>>>>>v
  //        ^<<<<
  // The loop may also have a different shape.
  // If a loop is found, call the handle_colliding function to determine what to do next.
  // If there is no loop, allow the move to be retried later, trying objE's location next.
  // Since there may be multiple objects in a location, which move in different directions,
  // a variable "ch" mentions the next object to try, if it is VOIDLINK. If not, then once
  // it reaches the end without finding a loop, it can try the next one, resetting ch to
  // VOIDLINK. This will find not only loops, but also if there is a branch that is later
  // merged; due to what this program needs to do, and how they will be dealt with after
  // the potential loop is found, that isn't a problem.
  static sqlite3_uint64 board[64]; // bit board for locations with possible collisions
  Object*o=objects[obj];
  Uint32 ch=VOIDLINK; // first object found in same place as other where it must be checked
  Uint8 x=o->x;
  Uint8 y=o->y;
  Uint32 n,nn;
  memset(board,0,sizeof(board));
  begin:
  if(x==xx && y==yy) return 1;
  if(x<1 || x>pfwidth || y<1 || y>pfheight) goto notfound;
  if(board[y-1]&(1ULL<<(x-1))) return 0;
  board[y-1]|=1ULL<<(x-1);
  n=playfield[x+y*64-65];
  nn=VOIDLINK;
  while(n!=VOIDLINK) {
    o=objects[n];
    if((o->oflags&(OF_MOVING|OF_VISUALONLY|OF_DESTROYED))==OF_MOVING && o->height>0) {
      if(nn==VOIDLINK) {
        nn=n;
        if(ch!=VOIDLINK) goto found;
      } else if(ch==VOIDLINK) {
        ch=n;
        goto found;
      }
    }
    up:
    n=o->up;
  }
  if(nn==VOIDLINK) {
    notfound:
    if(ch==VOIDLINK) return 0;
    o=objects[n=ch];
    x=o->x;
    y=o->y;
    ch=VOIDLINK;
    goto up;
  }
  found:
  o=objects[nn];
  x+=x_delta[o->dir];
  y+=y_delta[o->dir];
  goto begin;
}

static Uint32 deferred_colliding(Uint32 obj,int x,int y) {
  Object*o=objects[obj];
  Object*oE;
  Uint32 h=0xFFFFFFFF;
  Uint32 objE=playfield[x+y*64-65];
  Uint8 d;
  int xx,yy;
  while(objE!=VOIDLINK) {
    oE=objects[objE];
    if(!(oE->oflags&(OF_DESTROYED|OF_VISUALONLY))) {
      if((oE->oflags&OF_MOVING) && oE->height>0) {
        if(find_deferred_movement_loop(objE,objects[obj]->x,objects[obj]->y)) {



          h&=handle_colliding(obj,objE,3,3);

        } else {
          return h&4;
        }
      } else if(oE->height>o->climb || (classes[o->class]->collisionLayers&classes[oE->class]->collisionLayers)) {
        h&=handle_colliding(obj,objE,1,0);

      }
    }
    objE=oE->up;
  }

  // Find other objects trying to move to the same place
  if(h&8) for(d=0;d<8;d++) {
    xx=x-x_delta[d];
    yy=y-y_delta[d];
    if(xx<1 || xx>pfwidth || yy<1 || yy>pfheight) continue;
    objE=playfield[xx+yy*64-65];
    while(objE!=VOIDLINK) {
      oE=objects[objE];
      if(obj!=objE && (oE->oflags&OF_MOVING) && oE->dir==d && !(oE->oflags&OF_DESTROYED)) {
        if(o->height>oE->climb || oE->height>o->climb || (classes[o->class]->collisionLayers&classes[oE->class]->collisionLayers)) {
          h&=handle_colliding(obj,objE,2,2);

        }
      }
      objE=oE->up;
    }
  }


  return ~h;
}

static void do_deferred_moves(void) {
  Object*o;
  Object*p;
  Uint32 h,n;
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
          re=1;
          o->oflags=(o->oflags|OF_MOVED)&~OF_MOVING;
          i-=65;
          if(i<0) i=0;
          goto retry;
        }
        stop:
        if(!(h&4)) o->oflags&=~OF_MOVING;
      }
      skip:
      n=o->up;
    }
  }
  if(re) goto restart;
}







|







2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
          re=1;
          o->oflags=(o->oflags|OF_MOVED)&~OF_MOVING;
          i-=65;
          if(i<0) i=0;
          goto retry;
        }
        stop:
        if((h&5)!=4) o->oflags&=~OF_MOVING;
      }
      skip:
      n=o->up;
    }
  }
  if(re) goto restart;
}