summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--App.cpp2
-rw-r--r--App.h2
-rw-r--r--CMakeLists.txt1
-rw-r--r--Globals.h6
-rw-r--r--Icons.cpp93
-rw-r--r--Icons.h17
-rw-r--r--Label.h1
-rw-r--r--View.cpp16
-rw-r--r--View.h1
-rw-r--r--main.cpp1
10 files changed, 133 insertions, 7 deletions
diff --git a/App.cpp b/App.cpp
index f897ebb..99ac62f 100644
--- a/App.cpp
+++ b/App.cpp
@@ -9,6 +9,7 @@
App::App() :
+ icons {},
m_view {}
{
InitWindow(800, 600, "Derelict");
@@ -19,6 +20,7 @@ App::App() :
App::~App()
{
+ icons.reset();
m_view.reset();
CloseWindow();
}
diff --git a/App.h b/App.h
index 0ace948..af0fc38 100644
--- a/App.h
+++ b/App.h
@@ -2,6 +2,7 @@
#include <memory>
+#include "Icons.h"
#include "View.h"
@@ -12,6 +13,7 @@ public:
~App();
void assign(std::unique_ptr<View> view);
void loop();
+ Icons icons;
private:
std::unique_ptr<View> m_view;
};
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8945b6c..c641a61 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,6 +9,7 @@ add_executable(
${PROJECT_NAME}
App.cpp
DumpSource.cpp
+ Icons.cpp
main.cpp
Reader.cpp
Timeline.cpp
diff --git a/Globals.h b/Globals.h
new file mode 100644
index 0000000..8257130
--- /dev/null
+++ b/Globals.h
@@ -0,0 +1,6 @@
+#pragma once
+
+#include "App.h"
+
+
+extern App app;
diff --git a/Icons.cpp b/Icons.cpp
new file mode 100644
index 0000000..7b90ae0
--- /dev/null
+++ b/Icons.cpp
@@ -0,0 +1,93 @@
+#include "Icons.h"
+
+#include <string>
+#include <unordered_map>
+
+#include <raylib.h>
+
+
+static const std::unordered_map<long int, std::string> FILENAMES {
+ {11176, "resources/frigate_16.png"},
+ {11198, "resources/frigate_16.png"},
+ {11202, "resources/frigate_16.png"},
+ {11393, "resources/frigate_16.png"},
+ {11400, "resources/frigate_16.png"},
+ {11963, "resources/cruiser_16.png"},
+ {11965, "resources/cruiser_16.png"},
+ {11969, "resources/cruiser_16.png"},
+ {11971, "resources/cruiser_16.png"},
+ {11987, "resources/cruiser_16.png"},
+ {11989, "resources/cruiser_16.png"},
+ {11993, "resources/cruiser_16.png"},
+ {12017, "resources/cruiser_16.png"},
+ {12034, "resources/frigate_16.png"},
+ {17920, "resources/battleship_16.png"},
+ {19720, "resources/dreadnought_16.png"},
+ {19722, "resources/dreadnought_16.png"},
+ {2161, "resources/frigate_16.png"},
+ {22442, "resources/battleCruiser_16.png"},
+ {22456, "resources/destroyer_16.png"},
+ {22460, "resources/destroyer_16.png"},
+ {22464, "resources/destroyer_16.png"},
+ {32876, "resources/destroyer_16.png"},
+ {33468, "resources/frigate_16.png"},
+ {33474, "resources/mobileStorage.png"},
+ {33476, "resources/mobileCynosuralInhibitor.png"},
+ {34828, "resources/destroyer_16.png"},
+ {35683, "resources/destroyer_16.png"},
+ {37480, "resources/destroyer_16.png"},
+ {37482, "resources/destroyer_16.png"},
+ {37604, "resources/forceAuxiliary_16.png"},
+ {3766, "resources/frigate_16.png"},
+ {45534, "resources/cruiser_16.png"},
+ {583, "resources/frigate_16.png"},
+ {585, "resources/frigate_16.png"},
+ {606, "resources/rookie_16.png"},
+ {634, "resources/cruiser_16.png"},
+ {640, "resources/battleship_16.png"},
+ {644, "resources/battleship_16.png"},
+ {651, "resources/industrial_16.png"},
+ {670, "resources/frozenCorpse.png"},
+ {672, "resources/shuttle_16.png"},
+};
+
+
+Icons::Icons() :
+ m_cache {}
+{
+}
+
+
+Icons::~Icons()
+{
+ reset();
+}
+
+
+void
+Icons::reset()
+{
+ for (const auto& [_, texture] : m_cache)
+ UnloadTexture(texture);
+ m_cache.clear();
+}
+
+
+Texture2D
+Icons::find(const long int type)
+{
+ const auto existing = m_cache.find(type);
+ if (existing != m_cache.end()) {
+ return existing->second;
+ }
+ else {
+ Texture2D texture;
+ const auto filename = FILENAMES.find(type);
+ if (filename != FILENAMES.end())
+ texture = LoadTexture(filename->second.data());
+ else
+ texture = LoadTexture("resources/wreck.png");
+ m_cache[type] = texture;
+ return texture;
+ }
+}
diff --git a/Icons.h b/Icons.h
new file mode 100644
index 0000000..367d9aa
--- /dev/null
+++ b/Icons.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include <unordered_map>
+
+#include <raylib.h>
+
+
+class Icons
+{
+public:
+ Icons();
+ ~Icons();
+ void reset();
+ Texture2D find(long int type);
+private:
+ std::unordered_map<long int, Texture2D> m_cache;
+};
diff --git a/Label.h b/Label.h
index cfd5fc7..d33b069 100644
--- a/Label.h
+++ b/Label.h
@@ -15,4 +15,5 @@ struct Label
float length;
bool hover;
std::reference_wrapper<const Wreck> wreck;
+ Texture2D texture;
};
diff --git a/View.cpp b/View.cpp
index 50e5549..3360808 100644
--- a/View.cpp
+++ b/View.cpp
@@ -7,18 +7,22 @@
#include <raylib.h>
+#include "Globals.h"
#include "Grid.h"
#include "Label.h"
#include "Timeline.h"
#include "Utils.h"
+const Color BACKGROUND {8, 8, 50, 255};
+const Color LINE {240, 240, 240, 160};
+
+
View::View(std::vector<Grid> grids, Timeline timeline) :
m_camera {},
m_grids {grids},
m_labels {},
m_grid {0},
- m_texture {LoadTexture("resources/wreck.png")},
m_active {nullptr},
m_timeline {timeline}
{
@@ -33,7 +37,6 @@ View::View(std::vector<Grid> grids, Timeline timeline) :
View::~View()
{
- UnloadTexture(m_texture);
}
@@ -62,7 +65,8 @@ View::update(const float dt)
const auto depth = dist(m_camera.position, wreck.position);
const auto length = dist(pos, base);
const bool hover = 8.0f > dist(mouse, pos);
- m_labels.push_back(Label{pos, base, depth, length, hover, std::ref(wreck)});
+ m_labels.push_back(
+ Label{pos, base, depth, length, hover, std::ref(wreck), app.icons.find(wreck.killmail.ship)});
}
std::sort(m_labels.begin(), m_labels.end(), [](auto& a, auto& b){ return a.depth > b.depth; });
m_active = nullptr;
@@ -81,12 +85,12 @@ void
View::draw() const
{
BeginDrawing();
- ClearBackground(RAYWHITE);
+ ClearBackground(BACKGROUND);
BeginMode3D(m_camera);
DrawGrid(12, 1.0f);
EndMode3D();
for (const auto& point : m_labels) {
- Color line = point.hover ? ORANGE : GRAY;
+ Color line = point.hover ? ORANGE : LINE;
Color icon = point.hover ? ORANGE : WHITE;
if (!point.hover && point.wreck.get().time > m_timeline.current()) {
line.a = 20;
@@ -94,7 +98,7 @@ View::draw() const
}
if (point.length > 8)
DrawLine(point.base.x, point.base.y, point.pos.x, point.pos.y, line);
- DrawTexture(m_texture, point.pos.x - 8, point.pos.y - 8, icon);
+ DrawTexture(point.texture, point.pos.x - 8, point.pos.y - 8, icon);
}
DrawFPS(5, 5);
DrawText(TextFormat("%d", m_labels.size()), 5, 25, 20, DARKGRAY);
diff --git a/View.h b/View.h
index 48c5491..e98502a 100644
--- a/View.h
+++ b/View.h
@@ -22,7 +22,6 @@ private:
std::vector<Label> m_labels;
unsigned int m_grid;
float m_timer;
- Texture2D m_texture;
Label* m_active;
Timeline m_timeline;
};
diff --git a/main.cpp b/main.cpp
index a0c4285..41d5ef2 100644
--- a/main.cpp
+++ b/main.cpp
@@ -5,6 +5,7 @@
#include "App.h"
#include "DumpSource.h"
+#include "Globals.h"
#include "Reader.h"
#include "View.h"