fix: missing leading coordinate bytes
This commit is contained in:
parent
d09f3cf642
commit
a13f2271da
31
lib/db.c
31
lib/db.c
|
@ -162,11 +162,12 @@ int y16t_db_lookup(
|
|||
typedef struct {
|
||||
y16t_db_t db;
|
||||
const uint8_t *xy;
|
||||
uint8_t oth;
|
||||
int (*callback)(const uint8_t*, const uint8_t*, void*);
|
||||
void *context;
|
||||
} y16t_db_fectx_t;
|
||||
|
||||
static int y16t_db_foreach_x3(uint32_t offset, void *context_)
|
||||
static int y16t_db_foreach_x3(uint8_t x1, uint32_t offset, void *context_)
|
||||
{
|
||||
if(!offset) return 0;
|
||||
const y16t_db_fectx_t *context = context_;
|
||||
|
@ -184,14 +185,18 @@ static int y16t_db_foreach_x3(uint32_t offset, void *context_)
|
|||
if(memcmp(&buf[i], zeros, 44) == 0)
|
||||
break;
|
||||
if(memcmp(&buf[i + 14], xyrest, 14) == 0) {
|
||||
const int tmp2 = context->callback(&buf[i], &buf[i + 28], context->context);
|
||||
uint8_t x[16] = {0};
|
||||
x[0] = context->oth;
|
||||
x[1] = x1;
|
||||
memcpy(&x[2], &buf[i], 14);
|
||||
const int tmp2 = context->callback(x, &buf[i + 28], context->context);
|
||||
if(tmp2) return tmp2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int y16t_db_foreach_y3(uint32_t offset, void *context_)
|
||||
static int y16t_db_foreach_y3(uint8_t y1, uint32_t offset, void *context_)
|
||||
{
|
||||
if(!offset) return 0;
|
||||
const y16t_db_fectx_t *context = context_;
|
||||
|
@ -209,24 +214,30 @@ static int y16t_db_foreach_y3(uint32_t offset, void *context_)
|
|||
if(memcmp(&buf[i], zeros, 44) == 0)
|
||||
break;
|
||||
if(memcmp(&buf[i], xyrest, 14) == 0) {
|
||||
const int tmp2 = context->callback(&buf[i + 14], &buf[i + 28], context->context);
|
||||
uint8_t y[16] = {0};
|
||||
y[0] = context->oth;
|
||||
y[1] = y1;
|
||||
memcpy(&y[2], &buf[i + 14], 14);
|
||||
const int tmp2 = context->callback(y, &buf[i + 28], context->context);
|
||||
if(tmp2) return tmp2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int y16t_db_foreach_x2(uint32_t offset, void *context_) {
|
||||
const y16t_db_fectx_t *context = context_;
|
||||
static int y16t_db_foreach_x2(uint8_t x0, uint32_t offset, void *context_) {
|
||||
y16t_db_fectx_t *context = context_;
|
||||
if(!offset) return 0;
|
||||
context->oth = x0;
|
||||
const y16t_idx_t idx = { context->db, offset };
|
||||
return y16t_idx_foreach_x(idx, context->xy[1],
|
||||
y16t_db_foreach_x3, context_);
|
||||
}
|
||||
|
||||
static int y16t_db_foreach_y2(uint32_t offset, void *context_) {
|
||||
const y16t_db_fectx_t *context = context_;
|
||||
static int y16t_db_foreach_y2(uint8_t y0, uint32_t offset, void *context_) {
|
||||
y16t_db_fectx_t *context = context_;
|
||||
if(!offset) return 0;
|
||||
context->oth = y0;
|
||||
const y16t_idx_t idx = { context->db, offset };
|
||||
return y16t_idx_foreach_y(idx, context->xy[1],
|
||||
y16t_db_foreach_y3, context_);
|
||||
|
@ -237,7 +248,7 @@ int y16t_db_foreach_x(
|
|||
int (*callback)(const uint8_t*, const uint8_t*, void*),
|
||||
void *context
|
||||
) {
|
||||
y16t_db_fectx_t fectx = { db, y, callback, context };
|
||||
y16t_db_fectx_t fectx = { db, y, 0, callback, context };
|
||||
const y16t_idx_t idx = { db, 0 };
|
||||
return y16t_idx_foreach_x(idx, y[0], y16t_db_foreach_x2, (void*) &fectx);
|
||||
}
|
||||
|
@ -247,7 +258,7 @@ int y16t_db_foreach_y(
|
|||
int (*callback)(const uint8_t*, const uint8_t*, void*),
|
||||
void *context
|
||||
) {
|
||||
y16t_db_fectx_t fectx = { db, x, callback, context };
|
||||
y16t_db_fectx_t fectx = { db, x, 0, callback, context };
|
||||
const y16t_idx_t idx = { db, 0 };
|
||||
return y16t_idx_foreach_y(idx, x[0], y16t_db_foreach_y2, (void*) &fectx);
|
||||
}
|
||||
|
|
15
lib/idx.c
15
lib/idx.c
|
@ -78,23 +78,24 @@ static int y16t_idx_foreach_inner(
|
|||
y16t_idx_t idx,
|
||||
uint8_t x,
|
||||
uint8_t y,
|
||||
int (*callback)(uint32_t, void*),
|
||||
uint8_t oth,
|
||||
int (*callback)(uint8_t, uint32_t, void*),
|
||||
void *context
|
||||
) {
|
||||
uint32_t value = 0;
|
||||
int tmp = y16t_idx_lookup(idx, x, y, &value);
|
||||
const int tmp = y16t_idx_lookup(idx, x, y, &value);
|
||||
if(tmp < 0) return tmp;
|
||||
return callback(ntohl(value), context);
|
||||
return callback(oth, ntohl(value), context);
|
||||
}
|
||||
|
||||
int y16t_idx_foreach_x(
|
||||
y16t_idx_t idx,
|
||||
uint8_t y,
|
||||
int (*callback)(uint32_t, void*),
|
||||
int (*callback)(uint8_t, uint32_t, void*),
|
||||
void *context
|
||||
) {
|
||||
for (uint16_t x = 0; x < 0xff; ++x) {
|
||||
const int tmp = y16t_idx_foreach_inner(idx, x, y, callback, context);
|
||||
const int tmp = y16t_idx_foreach_inner(idx, x, y, x, callback, context);
|
||||
if(tmp) return tmp;
|
||||
}
|
||||
|
||||
|
@ -104,11 +105,11 @@ int y16t_idx_foreach_x(
|
|||
int y16t_idx_foreach_y(
|
||||
y16t_idx_t idx,
|
||||
uint8_t x,
|
||||
int (*callback)(uint32_t, void*),
|
||||
int (*callback)(uint8_t, uint32_t, void*),
|
||||
void *context
|
||||
) {
|
||||
for (uint16_t y = 0; y < 0xff; ++y) {
|
||||
const int tmp = y16t_idx_foreach_inner(idx, x, y, callback, context);
|
||||
const int tmp = y16t_idx_foreach_inner(idx, x, y, y, callback, context);
|
||||
if(tmp) return tmp;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,13 +43,13 @@ int y16t_idx_get_or_insert(
|
|||
int y16t_idx_foreach_x(
|
||||
y16t_idx_t idx,
|
||||
uint8_t y,
|
||||
int (*callback)(uint32_t, void*),
|
||||
int (*callback)(uint8_t, uint32_t, void*),
|
||||
void *context
|
||||
);
|
||||
|
||||
int y16t_idx_foreach_y(
|
||||
y16t_idx_t idx,
|
||||
uint8_t χ,
|
||||
int (*callback)(uint32_t, void*),
|
||||
int (*callback)(uint8_t, uint32_t, void*),
|
||||
void *context
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue