Skip to content

Commit ffb9988

Browse files
committed
Renamed the library to Easy Spatial Navigation.
1 parent e48e104 commit ffb9988

File tree

10 files changed

+56
-55
lines changed

10 files changed

+56
-55
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ allegro.log
1414
*.aps
1515
game_data/test/*
1616
user_data/*
17-
spat_nav_tests
17+
easy_spat_nav_tests
1818
/pikifen
1919
/pikifen_shortcut
2020
/pikifen*.exe

source/source/content/other/gui.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ bool GuiManager::draw() {
862862
);
863863
}
864864

865-
#ifdef SPAT_NAV_DEBUG
865+
#ifdef EASY_SPAT_NAV_DEBUG
866866
for(const auto& i : sNInterface.lastNavInfo) {
867867
al_draw_filled_circle(
868868
i.second.focusX, i.second.focusY, 3, al_map_rgb(0, 0, 255)
@@ -1322,16 +1322,16 @@ void GuiManager::handleSpatialNavigationAction(const Inpution::Action& action) {
13221322
//Fill in the data for the spatial navigation algorithm.
13231323
sNInterface.clearItems();
13241324
bool hasItems = false;
1325-
SpatNav::DIRECTION direction = SpatNav::DIRECTION_RIGHT;
1325+
EasySpatNav::DIRECTION direction = EasySpatNav::DIRECTION_RIGHT;
13261326
switch(action.actionTypeId) {
13271327
case PLAYER_ACTION_TYPE_MENU_UP: {
1328-
direction = SpatNav::DIRECTION_UP;
1328+
direction = EasySpatNav::DIRECTION_UP;
13291329
break;
13301330
} case PLAYER_ACTION_TYPE_MENU_LEFT: {
1331-
direction = SpatNav::DIRECTION_LEFT;
1331+
direction = EasySpatNav::DIRECTION_LEFT;
13321332
break;
13331333
} case PLAYER_ACTION_TYPE_MENU_DOWN: {
1334-
direction = SpatNav::DIRECTION_DOWN;
1334+
direction = EasySpatNav::DIRECTION_DOWN;
13351335
break;
13361336
}
13371337
}

source/source/content/other/gui.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "../../core/controls_mediator.h"
2323
#include "../../core/misc_structs.h"
2424
#include "../../lib/data_file/data_file.h"
25-
#include "../../lib/spatial_navigation/spatial_navigation.h"
25+
#include "../../lib/easy_spat_nav/easy_spat_nav.h"
2626
#include "../../util/drawing_utils.h"
2727
#include "../../util/general_utils.h"
2828
#include "../../util/geometry_utils.h"
@@ -797,7 +797,7 @@ class GuiManager {
797797
bool visible = true;
798798

799799
//Spatial navigation algorithm interface.
800-
SpatNav::Interface sNInterface;
800+
EasySpatNav::Interface sNInterface;
801801

802802
//Focus cursor.
803803
struct FocusCursor {

source/source/lib/spatial_navigation/spatial_navigation.cpp renamed to source/source/lib/easy_spat_nav/easy_spat_nav.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) Andre 'Espyo' Silva 2013.
33
*
44
* === FILE DESCRIPTION ===
5-
* Source code for the spatial navigation library.
5+
* Source code for the Easy Spatial Navigation library.
66
* Please read the included readme file.
77
*/
88

@@ -11,10 +11,10 @@
1111
#include <float.h>
1212
#include <limits.h>
1313

14-
#include "spatial_navigation.h"
14+
#include "easy_spat_nav.h"
1515

1616

17-
namespace SpatNav {
17+
namespace EasySpatNav {
1818

1919

2020
/**
@@ -124,7 +124,7 @@ void* Interface::doNavigation(
124124
) {
125125
//Setup.
126126

127-
#ifdef SPAT_NAV_DEBUG
127+
#ifdef EASY_SPAT_NAV_DEBUG
128128
lastNavInfo.clear();
129129
#endif
130130

@@ -289,7 +289,7 @@ void Interface::getBestItem(
289289
*bestItemId = i.first;
290290
}
291291

292-
#ifdef SPAT_NAV_DEBUG
292+
#ifdef EASY_SPAT_NAV_DEBUG
293293
lastNavInfo[i.first].score = score;
294294
lastNavInfo[i.first].accepted = true;
295295
lastNavInfo[i.first].looped = loopedItems;
@@ -371,7 +371,7 @@ void Interface::getItemDiffs(
371371
*outDiffX = itemX - workingX;
372372
*outDiffY = itemY - workingY;
373373

374-
#ifdef SPAT_NAV_DEBUG
374+
#ifdef EASY_SPAT_NAV_DEBUG
375375
lastNavInfo[iPtr->id].focusX = workingX;
376376
lastNavInfo[iPtr->id].focusY = workingY;
377377
lastNavInfo[iPtr->id].itemX = itemX;
@@ -453,7 +453,7 @@ void Interface::getItemRelativeUnits(
453453
if(heuristics.centerOnly) {
454454
diffX = iPtr->flatX - focusX;
455455
diffY = iPtr->flatY - focusY;
456-
#ifdef SPAT_NAV_DEBUG
456+
#ifdef EASY_SPAT_NAV_DEBUG
457457
lastNavInfo[iPtr->id].focusX = focusX;
458458
lastNavInfo[iPtr->id].focusY = focusY;
459459
lastNavInfo[iPtr->id].itemX = iPtr->flatX;

source/source/lib/spatial_navigation/spatial_navigation.h renamed to source/source/lib/easy_spat_nav/easy_spat_nav.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) Andre 'Espyo' Silva 2025.
33
*
44
* === FILE DESCRIPTION ===
5-
* Header for the spatial navigation library.
5+
* Header for the Easy Spatial Navigation library.
66
* Please read the included readme file.
77
*/
88

@@ -14,10 +14,10 @@
1414
#include <vector>
1515

1616

17-
//#define SPAT_NAV_DEBUG
17+
//#define EASY_SPAT_NAV_DEBUG
1818

1919

20-
namespace SpatNav {
20+
namespace EasySpatNav {
2121

2222
//Full circle, in radians.
2323
constexpr const float TAU = (float) M_PI * 2.0f;
@@ -118,7 +118,7 @@ class Interface {
118118
} heuristics;
119119

120120

121-
#ifdef SPAT_NAV_DEBUG
121+
#ifdef EASY_SPAT_NAV_DEBUG
122122

123123
/**
124124
* @brief Represents an item when it was checked for the latest navigation.

source/source/lib/spatial_navigation/readme.md renamed to source/source/lib/easy_spat_nav/readme.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Spatial Navigation
1+
# Easy Spatial Navigation
22

3-
Espyo's GUI spatial navigation algorithm.
3+
Espyo's Easy Spatial Navigation algorithm for GUIs.
44

55
> * [Overview](#overview)
66
> * [Quick example](#quick-example)
@@ -24,29 +24,30 @@ Spatial navigation is surprisingly tricky. Guessing which GUI item the user want
2424
## Quick example
2525

2626
```cpp
27-
#include "spatial_navigation.h"
27+
#include "easy_spat_nav.h"
2828
#include "my_program_stuff.h"
2929

3030
// (...)
3131

32-
void myProgram::doSpatialNavigation(SpatNav::DIRECTION direction) {
33-
SpatNav::Interface spatNavManager;
32+
void myProgram::doSpatialNavigation(EGSpatNav::DIRECTION direction) {
33+
EasySpatNav::Interface esnInterface;
3434

3535
for(const auto& item : myProgram.currentGUI.items) {
3636
if(!item.canBeFocused()) continue;
37-
spatNavManager.addItem((void*) item, item.center.x, item.center.y, item.size.x, item.size.y);
37+
esnInterface.addItem((void*) item, item.center.x, item.center.y, item.size.x, item.size.y);
3838
}
3939

40-
GuiItem* targetItemPtr = (MyProgram::GuiItem*) spatNavManager.navigate(direction, (void*) myProgram.currentGui.focusedItem);
40+
MyProgram::GuiItem* targetItemPtr =
41+
(MyProgram::GuiItem*) esnInterface.navigate(direction, (void*) myProgram.currentGui.focusedItem);
4142
}
4243
```
4344
4445
## Features
4546
46-
* Support for looping around the edges of the GUI (see `Manager::settings`).
47-
* Support for parent items that have children items that can overflow inside (see `Manager::setParentItem`).
48-
* Customizable heuristics (see `Manager::heuristics`).
49-
* Basic debugging logic (see `SPAT_NAV_DEBUG`).
47+
* Support for looping around the edges of the GUI (see `Interface::settings`).
48+
* Support for parent items that have children items that can overflow inside (see `Interface::setParentItem`).
49+
* Customizable heuristics (see `Interface::heuristics`).
50+
* Basic debugging logic (see `EASY_SPAT_NAV_DEBUG`).
5051
* Fairly light, and fairly simple.
5152
* Very agnostic, and with no external dependencies.
5253
* Simple unit test coverage for the library itself.
@@ -67,9 +68,9 @@ void myProgram::doSpatialNavigation(SpatNav::DIRECTION direction) {
6768
* When looping through an edge of the GUI, it's skipping over an item.
6869
* Make sure there's at least a small gap between the items and the edges of the GUI. If it doesn't, you can manually grow the limits by 0.01 without any real drawback.
6970
* The algorithm is picking the wrong item and I can't understand why.
70-
* Try defining `SPAT_NAV_DEBUG` (or uncomment its line near the top of the header file). Then on every frame draw onto the window the contents provided by `Manager::lastNavInfo` in whatever way you want. This should help you understand what the algorithm is doing and what you can customize to make it do what you want.
71+
* Try defining `EASY_SPAT_NAV_DEBUG` (or uncomment its line near the top of the header file). Then on every frame draw onto the window the contents provided by `Interface::lastNavInfo` in whatever way you want. This should help you understand what the algorithm is doing and what you can customize to make it do what you want.
7172
* There's an item a bit out of the way, but I can't seem to reach it.
72-
* Try `Manager::heuristics::singleLoopPass`.
73+
* Try `Interface::heuristics::singleLoopPass`.
7374
7475
7576
## Inner workings notes

source/source/lib/spatial_navigation/tests/makefile renamed to source/source/lib/easy_spat_nav/tests/makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Makefile for the spatial navigation library's test framework. This should be run in the tests folder.
1+
# Makefile for the Easy Spatial Navigation library's test framework. This should be run in the tests folder.
22

33

44
# Basics.
5-
PROG := spat_nav_tests
5+
PROG := easy_spat_nav_tests
66
CXX := g++
77
SRCS := $(shell find .. -name '*.cpp')
88
OBJS := $(SRCS:.cpp=.o)

source/source/lib/spatial_navigation/tests/tests_main.cpp renamed to source/source/lib/easy_spat_nav/tests/tests_main.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
* Copyright (c) Andre 'Espyo' Silva 2025.
33
*
44
* === FILE DESCRIPTION ===
5-
* Unit tests for the spatial navigation library.
5+
* Unit tests for the Easy Spatial Navigation library.
66
* Please read the included readme file.
77
*/
88

99
#include <vector>
1010
#include <string>
1111

12-
#include "../spatial_navigation.h"
12+
#include "../easy_spat_nav.h"
1313

1414

1515
constexpr const char* COLOR_BOLD = "\033[1m";
@@ -186,15 +186,15 @@ void SpatNavTestInterface::fromString(const std::string& s) {
186186

187187

188188
/**
189-
* @brief Recursively adds children interfaces to the SpatNav manager.
189+
* @brief Recursively adds children interfaces to the EasySpatNav manager.
190190
*
191191
* @param manager The manager.
192192
* @param interface Interface whose children to add.
193193
* @param itemNr Current item number.
194194
* @param interfaceFirstItemNr Item number of the first item in the interface.
195195
*/
196196
void addChildren(
197-
SpatNav::Interface& manager, SpatNavTestInterface* interface,
197+
EasySpatNav::Interface& manager, SpatNavTestInterface* interface,
198198
size_t& itemNr, size_t interfaceFirstItemNr
199199
) {
200200
for(size_t ci = 0; ci < interface->children.size(); ci++) {
@@ -273,12 +273,12 @@ void test(
273273
*/
274274
void testNav(
275275
const std::string& testDescription,
276-
SpatNavTestInterface& interface, SpatNav::DIRECTION direction,
276+
SpatNavTestInterface& interface, EasySpatNav::DIRECTION direction,
277277
size_t focusedItemNr, size_t expectedItemNr,
278-
const SpatNav::Interface::Heuristics& heuristics = {},
279-
const SpatNav::Interface::Settings& settings = {}
278+
const EasySpatNav::Interface::Heuristics& heuristics = {},
279+
const EasySpatNav::Interface::Settings& settings = {}
280280
) {
281-
SpatNav::Interface spatNavManager;
281+
EasySpatNav::Interface spatNavManager;
282282
spatNavManager.heuristics = heuristics;
283283
spatNavManager.settings = settings;
284284

@@ -309,10 +309,10 @@ void testNav(
309309
}
310310

311311

312-
using SpatNav::DIRECTION_RIGHT;
313-
using SpatNav::DIRECTION_DOWN;
314-
using SpatNav::DIRECTION_LEFT;
315-
using SpatNav::DIRECTION_UP;
312+
using EasySpatNav::DIRECTION_RIGHT;
313+
using EasySpatNav::DIRECTION_DOWN;
314+
using EasySpatNav::DIRECTION_LEFT;
315+
using EasySpatNav::DIRECTION_UP;
316316

317317

318318
/**
@@ -506,17 +506,17 @@ int main(int argc, char** argv) {
506506
testNav(
507507
"Test that Euclidean distance checks pick the best option.",
508508
ifDistances, DIRECTION_UP, 3, 2,
509-
{ .distCalcMethod = SpatNav::DIST_CALC_METHOD_EUCLIDEAN }
509+
{ .distCalcMethod = EasySpatNav::DIST_CALC_METHOD_EUCLIDEAN }
510510
);
511511
testNav(
512512
"Test that taxicab distance checks pick the best option.",
513513
ifDistances, DIRECTION_UP, 3, 1,
514-
{ .distCalcMethod = SpatNav::DIST_CALC_METHOD_TAXICAB }
514+
{ .distCalcMethod = EasySpatNav::DIST_CALC_METHOD_TAXICAB }
515515
);
516516
testNav(
517517
"Test that taxicab 2 distance checks pick the best option.",
518518
ifDistances2, DIRECTION_UP, 3, 1,
519-
{ .distCalcMethod = SpatNav::DIST_CALC_METHOD_TAXICAB_2 }
519+
{ .distCalcMethod = EasySpatNav::DIST_CALC_METHOD_TAXICAB_2 }
520520
);
521521

522522
//Single loop pass.

source/vs_code/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
"preLaunchTask": "Build Pikifen - Debug"
2626
},
2727
{
28-
"name": "Debug SpatNav's unit tests with GDB",
28+
"name": "Debug EasySpatNav's unit tests with GDB",
2929
"type": "cppdbg",
3030
"request": "launch",
31-
"program": "${workspaceFolder}/source/source/lib/spatial_navigation/tests/spat_nav_tests",
31+
"program": "${workspaceFolder}/source/source/lib/easy_spat_nav/tests/easy_spat_nav_tests",
3232
"args": [],
3333
"stopAtEntry": false,
3434
"cwd": "${workspaceFolder}",
@@ -42,7 +42,7 @@
4242
"ignoreFailures": true
4343
}
4444
],
45-
"preLaunchTask": "Build SpatNav's unit tests - Debug"
45+
"preLaunchTask": "Build EasySpatNav's unit tests - Debug"
4646
}
4747
]
4848
}

source/vs_code/tasks.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@
106106
},
107107
{
108108
"type": "shell",
109-
"label": "Build SpatNav's unit tests - Debug",
109+
"label": "Build EasySpatNav's unit tests - Debug",
110110
"command": "make",
111111
"args": [
112112
"debug",
113113
],
114114
"options": {
115-
"cwd": "${workspaceFolder}/source/source/lib/spatial_navigation/tests"
115+
"cwd": "${workspaceFolder}/source/source/lib/easy_spat_nav/tests"
116116
},
117117
"problemMatcher": [
118118
"$gcc"
@@ -124,7 +124,7 @@
124124
"reveal": "always",
125125
"echo": true
126126
},
127-
"detail": "Use make to compile the spatial navigation library's unit tests."
127+
"detail": "Use make to compile the Easy Spatial Navigation library's unit tests."
128128
},
129129
]
130130
}

0 commit comments

Comments
 (0)