Compare commits

..

No commits in common. "1767643da1d987c90b4fbbab8968761d27e5148e" and "84043e31e7da7fe037b5351c65dcee93f0d4a651" have entirely different histories.

6 changed files with 57 additions and 65 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 34 KiB

41
assets/WorldRPG.world Normal file
View file

@ -0,0 +1,41 @@
{
"maps": [
{
"fileName": "level0.tmx",
"height": 192,
"width": 384,
"x": 0,
"y": 0
},
{
"fileName": "level1.tmx",
"height": 192,
"width": 384,
"x": 384,
"y": 0
},
{
"fileName": "level2.tmx",
"height": 192,
"width": 384,
"x": 0,
"y": 192
},
{
"fileName": "level3.tmx",
"height": 192,
"width": 384,
"x": 384,
"y": 192
},
{
"fileName": "level4.tmx",
"height": 192,
"width": 384,
"x": 384,
"y": 384
}
],
"onlyShowAdjacentMaps": false,
"type": "world"
}

View file

@ -269,8 +269,8 @@ void game_get_inputs(Game *game) {
if(mynpc) {
mynpc->curx = (player->x << PRECISION) / PXSIZE;
mynpc->cury = (player->y << PRECISION) / PXSIZE;
mynpc->x = 0;
mynpc->y = 0;
mynpc->x = player->x;
mynpc->y = player->x;
mynpc->hasPath = 0;
mynpc->owns_path = false;
mynpc->face = 0;

View file

@ -74,7 +74,7 @@ int npc_clear_path(NPC *npc) {
return 0;
}
int npc_append_path(int16_t x, int16_t y, NPC *npc) {
int npc_append_path(uint16_t x, uint16_t y, NPC *npc) {
npc->xpath = realloc(npc->xpath, npc->path_length * 2 + 2);
npc->ypath = realloc(npc->ypath, npc->path_length * 2 + 2);
if(npc->xpath == NULL || npc->ypath == NULL)
@ -91,50 +91,6 @@ void as_clean(uint8_t *visited, uint8_t *gscore, uint8_t *fscore) {
free(fscore);
}
int npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *npc){
uint8_t *map = full_map->walkable;
uint32_t w = full_map->w;
uint32_t h = full_map->h;
uint32_t sx = npc_from_curxy(npc->curx);
uint32_t sy = npc_from_curxy(npc->cury);
dest_x /= PXSIZE;
dest_y /= PXSIZE;
if(dest_x < 0 || dest_y < 0 || dest_x >= w*T_WIDTH || dest_y >= h*T_HEIGHT)
return 2;
/*if(map[dest_y*w + dest_x])
return 2;
if(map[sy*w + sx])
return 2;*/
if(!npc->owns_path || npc->path_length > 64)
npc_clear_path(npc);
/*int bx;
int by;
int bscore = 0x7FFFFFFF;
for(int i = sx-1; i < sx+2; i++){
for(int j = sy-1; j < sy+2; j++){
int tscore = (dest_x-sx)*(dest_x-sx) + (dest_y-sy)*(dest_y-sy);
if(tscore < bscore){
bscore = tscore;
bx = i;
by = j;
}
}
}
if(bscore == 0x7FFFFFFF) return 3;*/
if(npc_append_path(dest_x,dest_y, npc))
return 1;
npc->hasPath = true;
return 0;
}
int as_reconstruct_path(int16_t *came_from, int w, int h, int16_t start,
int16_t dest, bool is_alloc, NPC *npc) {
if(npc_clear_path(npc))
@ -176,8 +132,8 @@ int as_reconstruct_path(int16_t *came_from, int w, int h, int16_t start,
npc->ypath[npc->path_length - i - 1] = ty;
}*/
/*if(is_alloc)
free(came_from);*/
if(is_alloc)
free(came_from);
npc->hasPath = true;
@ -185,8 +141,8 @@ int as_reconstruct_path(int16_t *came_from, int w, int h, int16_t start,
as_recons_fail:
/*if(is_alloc)
free(came_from);*/
if(is_alloc)
free(came_from);
return 1;
}
@ -194,8 +150,8 @@ as_recons_fail:
uint32_t xyram = 0xe500e000 + 32;
/* Custom a* implemetation
* Borked, use npc_pathfind instead*/
int __npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *npc) {
* Unoptimized, may become an issue */
int npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *npc) {
int32_t i, j;
int32_t w = full_map->w/T_WIDTH/PXSIZE;
@ -224,7 +180,7 @@ int __npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *npc) {
bool is_alloc;
if(isSH3() || w * h * 5 > 1024 * 15) {
if(1 || isSH3() || w * h * 5 > 1024 * 15) {
is_alloc = true;
visited = malloc(w * h);
@ -286,9 +242,9 @@ int __npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *npc) {
bscore = fscore[i];
}
if(bx == dest_x && by == dest_y) {
if(is_alloc) as_clean(visited, gscore, fscore);
as_clean(visited, gscore, fscore);
return 0; /*as_reconstruct_path(came_from, w, h, spos,
dest_y * w + dest_x, is_alloc npc)*/
dest_y * w + dest_x, npc)*/
}
visited[by * w + bx] = 1;
@ -318,10 +274,9 @@ int __npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *npc) {
}
}
if(is_alloc){
as_clean(visited, gscore, fscore);
free(came_from);
}
as_clean(visited, gscore, fscore);
free(came_from);
return 3;
}

View file

@ -10,10 +10,6 @@
/*Maximum iterations before the pathfinding considers the target unreacheable*/
#define PATHFIND_MAX_ITER 64
#define npc_from_curxy(a) (((a)>>PRECISION)/PXSIZE)
#define npc_to_curxy(a) (((a)*PXSIZE)<<PRECISION)
enum {
NPC_NONE = 0,
@ -45,7 +41,7 @@ int npc_clear_path(NPC *npc);
/* Adds point x,y to the path of npc
* Won't work on static NPCs, use npc_clear_path before or make them on the
* heap */
int npc_append_path(int16_t x, int16_t y, NPC *npc);
int npc_append_path(uint16_t x, uint16_t y, NPC *npc);
/* Clears the NPCs path and creates a new one going to dest,
* avoiding non-walkable tiles