Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Added support for nested block comments in INI. ([Issue #248](https://github.com/cortex-command-community/Cortex-Command-Community-Project-Source/issues/248))
The reader will track block comment open tags and crash if a file ends while a block is open, reporting the line it was opened on.

- Added thickness option to Line primitives. ([Issue #403](https://github.com/cortex-command-community/Cortex-Command-Community-Project-Source/issues/403))
New bindings with argument for thickness are:
`PrimitiveMan:DrawLinePrimitive(startPos, endPos, color, thickness)`
`PrimitiveMan:DrawLinePrimitive(player, startPos, endPos, color, thickness)`
Original bindings with no thickness argument are untouched and can be called as they were.

</details>

Expand Down
2 changes: 2 additions & 0 deletions Lua/LuaBindingsManagers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ namespace RTE {
return luabind::class_<PrimitiveMan>("PrimitiveManager")

.def("DrawLinePrimitive", (void (PrimitiveMan::*)(const Vector &start, const Vector &end, unsigned char color))&PrimitiveMan::DrawLinePrimitive)
.def("DrawLinePrimitive", (void (PrimitiveMan::*)(const Vector &start, const Vector &end, unsigned char color, int thickness))&PrimitiveMan::DrawLinePrimitive)
.def("DrawLinePrimitive", (void (PrimitiveMan::*)(int player, const Vector &start, const Vector &end, unsigned char color))&PrimitiveMan::DrawLinePrimitive)
.def("DrawLinePrimitive", (void (PrimitiveMan::*)(int player, const Vector &start, const Vector &end, unsigned char color, int thickness))&PrimitiveMan::DrawLinePrimitive)
.def("DrawArcPrimitive", (void (PrimitiveMan::*)(const Vector &pos, float startAngle, float endAngle, int radius, unsigned char color))&PrimitiveMan::DrawArcPrimitive)
.def("DrawArcPrimitive", (void (PrimitiveMan::*)(const Vector &pos, float startAngle, float endAngle, int radius, unsigned char color, int thickness))&PrimitiveMan::DrawArcPrimitive)
.def("DrawArcPrimitive", (void (PrimitiveMan::*)(int player, const Vector &pos, float startAngle, float endAngle, int radius, unsigned char color))&PrimitiveMan::DrawArcPrimitive)
Expand Down
17 changes: 17 additions & 0 deletions Managers/PrimitiveMan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@

namespace RTE {

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void PrimitiveMan::DrawLinePrimitive(int player, const Vector &startPos, const Vector &endPos, unsigned char color, int thickness) {
if (thickness > 1) {
Vector dirVector = g_SceneMan.ShortestDistance(startPos, endPos, g_SceneMan.SceneWrapsX()).SetMagnitude(static_cast<float>(thickness - 1) / 2.0F).Perpendicularize();
Vector pointA = startPos + dirVector;
Vector pointB = startPos - dirVector;
Vector pointC = endPos + dirVector;
Vector pointD = endPos - dirVector;

DrawTriangleFillPrimitive(player, pointA, pointB, pointC, color);
DrawTriangleFillPrimitive(player, pointC, pointD, pointB, color);
} else {
m_ScheduledPrimitives.emplace_back(std::make_unique<LinePrimitive>(player, startPos, endPos, color));
}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void PrimitiveMan::DrawBitmapPrimitive(int player, const Vector &centerPos, Entity *entity, float rotAngle, int frame, bool hFlipped, bool vFlipped) {
Expand Down
23 changes: 21 additions & 2 deletions Managers/PrimitiveMan.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ namespace RTE {
/// <param name="startPos">Start position of primitive in scene coordinates.</param>
/// <param name="endPos">End position of primitive in scene coordinates.</param>
/// <param name="color">Color to draw primitive with.</param>
void DrawLinePrimitive(const Vector &startPos, const Vector &endPos, unsigned char color) { m_ScheduledPrimitives.push_back(std::make_unique<LinePrimitive>(-1, startPos, endPos, color)); }
void DrawLinePrimitive(const Vector &startPos, const Vector &endPos, unsigned char color) { DrawLinePrimitive(-1, startPos, endPos, color, 1); }

/// <summary>
/// Schedule to draw a line primitive with the option to change thickness.
/// </summary>
/// <param name="startPos">Start position of primitive in scene coordinates.</param>
/// <param name="endPos">End position of primitive in scene coordinates.</param>
/// <param name="color">Color to draw primitive with.</param>
/// <param name="thickness">Thickness of the line in pixels.</param>
void DrawLinePrimitive(const Vector &startPos, const Vector &endPos, unsigned char color, int thickness) { DrawLinePrimitive(-1, startPos, endPos, color, thickness); }

/// <summary>
/// Schedule to draw a line primitive visible only to a specified player.
Expand All @@ -55,7 +64,17 @@ namespace RTE {
/// <param name="startPos">Start position of primitive in scene coordinates.</param>
/// <param name="endPos">End position of primitive in scene coordinates.</param>
/// <param name="color">Color to draw primitive with.</param>
void DrawLinePrimitive(int player, const Vector &startPos, const Vector &endPos, unsigned char color) { m_ScheduledPrimitives.push_back(std::make_unique<LinePrimitive>(player, startPos, endPos, color)); }
void DrawLinePrimitive(int player, const Vector &startPos, const Vector &endPos, unsigned char color) { DrawLinePrimitive(player, startPos, endPos, color, 1); }

/// <summary>
/// Schedule to draw a line primitive visible only to a specified player with the option to change thickness.
/// </summary>
/// <param name="player">Player screen to draw primitive on.</param>
/// <param name="startPos">Start position of primitive in scene coordinates.</param>
/// <param name="endPos">End position of primitive in scene coordinates.</param>
/// <param name="color">Color to draw primitive with.</param>
/// <param name="thickness">Thickness of the line in pixels.</param>
void DrawLinePrimitive(int player, const Vector &startPos, const Vector &endPos, unsigned char color, int thickness);

/// <summary>
/// Schedule to draw an arc primitive.
Expand Down