summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-05-03 16:12:52 +0200
committerAki <please@ignore.pl>2022-05-03 16:12:52 +0200
commitc610c4b94eda867a3f0b083038502dccb8116170 (patch)
treedda7499b3ac3c9f29bf70ecf927c1031758f53c1
parent8e85b084e6ec73cd99899ad276891eb40944b909 (diff)
downloadderelict-c610c4b94eda867a3f0b083038502dccb8116170.zip
derelict-c610c4b94eda867a3f0b083038502dccb8116170.tar.gz
derelict-c610c4b94eda867a3f0b083038502dccb8116170.tar.bz2
Added source and related stubs
-rw-r--r--CMakeLists.txt1
-rw-r--r--ExampleSource.cpp47
-rw-r--r--ExampleSource.h13
-rw-r--r--Killmail.h16
-rw-r--r--Location.h9
-rw-r--r--Owner.h10
-rw-r--r--Ship.h8
-rw-r--r--Source.h12
-rw-r--r--main.cpp27
9 files changed, 129 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b99e075..b0e7a6b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,6 +6,7 @@ set(CMAKE_CXX_EXTENSIONS No)
find_package(raylib 3 REQUIRED)
add_executable(
${PROJECT_NAME}
+ ExampleSource.cpp
main.cpp
)
target_link_libraries(${PROJECT_NAME} raylib)
diff --git a/ExampleSource.cpp b/ExampleSource.cpp
new file mode 100644
index 0000000..e79e7ad
--- /dev/null
+++ b/ExampleSource.cpp
@@ -0,0 +1,47 @@
+#include "ExampleSource.h"
+
+#include <utility>
+#include <vector>
+
+#include <raylib.h>
+
+#include "Killmail.h"
+
+
+constexpr int AMOUNT {1000};
+constexpr float MAX {4.0f};
+constexpr float MIN {-4.0f};
+constexpr float STEP {0.1f};
+
+
+static float random_position();
+
+
+ExampleSource::ExampleSource()
+{
+}
+
+
+std::vector<Killmail>
+ExampleSource::all() const
+{
+ std::vector<Killmail> killmails;
+ killmails.reserve(AMOUNT);
+ for (int i = 0; i < AMOUNT; ++i) {
+ Killmail km;
+ km.position = {
+ random_position(),
+ random_position(),
+ random_position(),
+ };
+ killmails.push_back(std::move(km));
+ }
+ return killmails;
+}
+
+
+float
+random_position()
+{
+ return GetRandomValue(MIN / STEP, MAX / STEP) * STEP;
+}
diff --git a/ExampleSource.h b/ExampleSource.h
new file mode 100644
index 0000000..2f45332
--- /dev/null
+++ b/ExampleSource.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <vector>
+
+#include "Killmail.h"
+#include "Source.h"
+
+
+struct ExampleSource : public Source
+{
+ ExampleSource();
+ std::vector<Killmail> all() const override;
+};
diff --git a/Killmail.h b/Killmail.h
new file mode 100644
index 0000000..64cf972
--- /dev/null
+++ b/Killmail.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <raylib.h>
+
+#include "Location.h"
+#include "Owner.h"
+#include "Ship.h"
+
+
+struct Killmail
+{
+ Location location;
+ Owner owner;
+ Ship ship;
+ Vector3 position;
+};
diff --git a/Location.h b/Location.h
new file mode 100644
index 0000000..dbbb27b
--- /dev/null
+++ b/Location.h
@@ -0,0 +1,9 @@
+#pragma once
+
+
+struct Location
+{
+ const char* system;
+ const char* constellation;
+ const char* region;
+};
diff --git a/Owner.h b/Owner.h
new file mode 100644
index 0000000..b311f80
--- /dev/null
+++ b/Owner.h
@@ -0,0 +1,10 @@
+#pragma once
+
+
+struct Owner
+{
+ const char* character;
+ const char* corporation;
+ const char* alliance;
+ const char* faction;
+};
diff --git a/Ship.h b/Ship.h
new file mode 100644
index 0000000..2ca6883
--- /dev/null
+++ b/Ship.h
@@ -0,0 +1,8 @@
+#pragma once
+
+
+struct Ship
+{
+ const char* name;
+ const char* icon;
+};
diff --git a/Source.h b/Source.h
new file mode 100644
index 0000000..295a65b
--- /dev/null
+++ b/Source.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include <vector>
+
+#include "Killmail.h"
+
+
+struct Source
+{
+ virtual ~Source() = default;
+ virtual std::vector<Killmail> all() const = 0;
+};
diff --git a/main.cpp b/main.cpp
index dfe0990..58c7347 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,9 +1,13 @@
#include <algorithm>
#include <cmath>
+#include <memory>
#include <vector>
#include <raylib.h>
+#include "ExampleSource.h"
+#include "Source.h"
+
constexpr int AMOUNT {2000};
@@ -29,32 +33,27 @@ main(int argc, char* argv[])
camera.fovy = 45;
camera.projection = CAMERA_PERSPECTIVE;
SetCameraMode(camera, CAMERA_ORBITAL);
- std::vector<Vector3> points;
- points.reserve(AMOUNT);
- for (int i = 0; i < AMOUNT; ++i)
- points.push_back({
- GetRandomValue(-100, 100) * 0.05f,
- GetRandomValue(-100, 100) * 0.05f,
- GetRandomValue(-100, 100) * 0.05f});
+ std::unique_ptr<Source> source = std::make_unique<ExampleSource>();
+ auto killmails = source->all();
std::vector<Entry> projected;
while (!WindowShouldClose())
{
UpdateCamera(&camera);
projected.clear();
- projected.reserve(points.size());
+ projected.reserve(killmails.size());
const int height = GetScreenHeight();
const int width = GetScreenWidth();
- for (const auto& point : points) {
- const auto vec2 = GetWorldToScreen(point, camera);
+ for (const auto& km : killmails) {
+ const auto vec2 = GetWorldToScreen(km.position, camera);
const float d =
std::sqrt(
- std::pow(camera.position.x - point.x, 2) +
- std::pow(camera.position.y - point.y, 2) +
- std::pow(camera.position.z - point.z, 2));
+ std::pow(camera.position.x - km.position.x, 2) +
+ std::pow(camera.position.y - km.position.y, 2) +
+ std::pow(camera.position.z - km.position.z, 2));
if (0 > vec2.x || width < vec2.x || 0 > vec2.y || height < vec2.y)
continue;
projected.push_back(Entry{
- vec2, GetWorldToScreen({point.x, 0, point.z}, camera), d
+ vec2, GetWorldToScreen({km.position.x, 0, km.position.z}, camera), d
});
}
std::sort(projected.begin(), projected.end(), [](Entry& a, Entry& b){ return a.depth > b.depth; });