Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flowfield & collision avoidance #3078

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,10 @@ win32/CodeAnalyst
/.ci/flatpak/net.wz2100.wz2100.yaml
/.ci/flatpak/Toolchain-cross-arch.cmake
/.ci/flatpak/meson-cross-file.txt

#
tags
*.log
*.txt

comments*
1 change: 1 addition & 0 deletions lib/framework/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ static const char *code_part_names[] =
"research",
"savegame",
"repairs",
"flowfield",
"last"
};

Expand Down
1 change: 1 addition & 0 deletions lib/framework/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ enum code_part
LOG_RESEARCH,
LOG_SAVEGAME,
LOG_REPAIRS,
LOG_FLOWFIELD,
LOG_LAST /**< _must_ be last! */
};

Expand Down
3 changes: 2 additions & 1 deletion lib/framework/fixedpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ static inline WZ_DECL_CONST float UNDEG(uint16_t angle)
return angle * (360.f / 65536.0f) * (3.141592f / 180.0f);
}

// Should be a macro (or two separate functions), since we can't do function overloading for float and int, and we don't want to use the float version for anything game-state related.
// Should be a macro (or two separate functions), since we can't do function overloading for float and int,
// and we don't want to use the float version for anything game-state related.
// 65536 / 360 = 8192 / 45, with a bit less overflow risk.
#define DEG(degrees) ((degrees) * 8192 / 45)

Expand Down
20 changes: 20 additions & 0 deletions lib/ivis_opengl/pieblitfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,26 @@ void iV_Lines(const std::vector<glm::ivec4> &lines, PIELIGHT colour)
gfx_api::LinePSO::get().unbind_vertex_buffers(pie_internal::rectBuffer);
}

void iV_PolyLine(const std::vector<Vector3i> &points, const glm::mat4 &mvp, PIELIGHT colour)
{
std::vector<glm::ivec4> lines;
Vector2i result;
Vector2i lastPoint;

for(auto i = 0; i < points.size(); i++){
Vector3i source = points[i];
pie_RotateProjectWithPerspective(&source, mvp, &result);

if(i > 0){
lines.push_back({ lastPoint.x, lastPoint.y, result.x, result.y });
}

lastPoint = result;
}

iV_Lines(lines, colour);
}

/**
* Assumes render mode set up externally, draws filled rectangle.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/ivis_opengl/pieblitfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ glm::mat4 defaultProjectionMatrix();
void iV_ShadowBox(int x0, int y0, int x1, int y1, int pad, PIELIGHT first, PIELIGHT second, PIELIGHT fill);
void iV_Line(int x0, int y0, int x1, int y1, PIELIGHT colour);
void iV_Lines(const std::vector<glm::ivec4> &lines, PIELIGHT colour);
// world coordinates
void iV_PolyLine(const std::vector<Vector3i> &points, const glm::mat4 &mvp, PIELIGHT colour);
void iV_Box2(int x0, int y0, int x1, int y1, PIELIGHT first, PIELIGHT second);
static inline void iV_Box(int x0, int y0, int x1, int y1, PIELIGHT first)
{
Expand Down
1 change: 1 addition & 0 deletions src/cheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static CHEAT_ENTRY cheatCodes[] =
{"autogame off", kf_AutoGame},
{"shakey", kf_ToggleShakeStatus}, //shakey
{"list droids", kf_ListDroids},
{"toggleff", kf_ToggleFlowField} // switch between Flow field and regular pathfinding / movement logic

};

Expand Down
9 changes: 7 additions & 2 deletions src/clparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "clparse.h"
#include "display3d.h"
#include "frontend.h"
#include "flowfield.h"
#include "keybind.h"
#include "loadsave.h"
#include "main.h"
Expand Down Expand Up @@ -337,6 +338,7 @@ typedef enum
CLI_CONTINUE,
CLI_AUTOHOST,
CLI_AUTORATING,
CLI_FLOWFIELD,
CLI_AUTOHEADLESS,
#if defined(WZ_OS_WIN)
CLI_WIN_ENABLE_CONSOLE,
Expand Down Expand Up @@ -416,6 +418,8 @@ static const struct poptOption *getOptionsTable()
{ "skirmish", POPT_ARG_STRING, CLI_SKIRMISH, N_("Start skirmish game with given settings file"), N_("test") },
{ "continue", POPT_ARG_NONE, CLI_CONTINUE, N_("Continue the last saved game"), nullptr },
{ "autohost", POPT_ARG_STRING, CLI_AUTOHOST, N_("Start host game with given settings file"), N_("autohost") },
{ "autorating", POPT_ARG_STRING, CLI_AUTORATING, N_("Query ratings from given server url (containing \"{HASH}\"), when hosting"), N_("autorating") },
{ "flowfield", POPT_ARG_NONE, CLI_FLOWFIELD, N_("Use advanced Flow fields method for path finding (experimental)"), nullptr },
{ "autorating", POPT_ARG_STRING, CLI_AUTORATING, N_("Query ratings from given server url, when hosting"), N_("autorating") },
#if defined(WZ_OS_WIN)
{ "enableconsole", POPT_ARG_NONE, CLI_WIN_ENABLE_CONSOLE, N_("Attach or create a console window and display console output (Windows only)"), nullptr },
Expand Down Expand Up @@ -959,7 +963,9 @@ bool ParseCommandLine(int argc, const char * const *argv)
wz_autoratingUrl = token;
debug(LOG_INFO, "Using \"%s\" for ratings.", wz_autoratingUrl.c_str());
break;

case CLI_FLOWFIELD:
flowfieldEnable();
break;
case CLI_AUTOHEADLESS:
wz_cli_headless = true;
setHeadlessGameMode(true);
Expand Down Expand Up @@ -1032,7 +1038,6 @@ bool ParseCommandLine(int argc, const char * const *argv)
}
debug(LOG_INFO, "Games will automatically start with [%d] players (when ready)", wz_min_autostart_players);
break;

};
}

Expand Down
3 changes: 3 additions & 0 deletions src/display3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include "warzoneconfig.h"
#include "multistat.h"
#include "animation.h"
#include "flowfield.h"
#include "faction.h"

/******************** Prototypes ********************/
Expand Down Expand Up @@ -1239,6 +1240,8 @@ static void drawTiles(iView *player)
gfx_api::context::get().debugStringMarker("Draw 3D scene - blueprints");
displayBlueprints(viewMatrix, perspectiveViewMatrix);

debugDrawFlowfields(perspectiveViewMatrix * glm::translate(glm::vec3(-player->p.x, 0, player->p.z)));

pie_RemainingPasses(currentGameFrame); // draws shadows and transparent shapes

if (!gamePaused())
Expand Down
10 changes: 9 additions & 1 deletion src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include "combat.h"
#include "template.h"
#include "qtscript.h"
#include "flowfield.h"

#define DEFAULT_RECOIL_TIME (GAME_TICKS_PER_SEC/4)
#define DROID_DAMAGE_SPREAD (16 - rand()%32)
Expand Down Expand Up @@ -728,7 +729,14 @@ void droidUpdate(DROID *psDroid)
syncDebugDroid(psDroid, 'M');

// update the move system
moveUpdateDroid(psDroid);
if (isFlowfieldEnabled())
{
moveUpdateDroid(psDroid);
}
else
{
moveUpdateDroid_original(psDroid);
}

/* Only add smoke if they're visible */
if (psDroid->visibleForLocalDisplay() && psDroid->droidType != DROID_PERSON)
Expand Down
3 changes: 2 additions & 1 deletion src/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "combat.h"
#include "multiplay.h"
#include "qtscript.h"
#include "flowfield.h"

#include "mapgrid.h"
#include "display3d.h"
Expand Down Expand Up @@ -528,7 +529,7 @@ bool destroyFeature(FEATURE *psDel, unsigned impactTime)
}
}
}

markTileAsDefaultCost(map_coord(psDel->pos.x), map_coord(psDel->pos.y), PROPULSION_TYPE_WHEELED);
removeFeature(psDel);
psDel->died = impactTime;
return true;
Expand Down
Loading