Compare commits

..

No commits in common. "05ef5a0297278a0596a2981b44db95273b4bc9d4" and "d3b8a305dc0bc1a1e13139e33b934aff4333f47e" have entirely different histories.

4 changed files with 125 additions and 116 deletions

1
.gitignore vendored
View File

@ -4,4 +4,3 @@ out/
./cmake-build*/ ./cmake-build*/
./build/ ./build/
./out/ ./out/
.idea/

9
.idea/vcs.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/lib/blt-with-graphics" vcs="Git" />
<mapping directory="$PROJECT_DIR$/lib/blt-with-graphics/libraries/BLT" vcs="Git" />
<mapping directory="$PROJECT_DIR$/lib/blt-with-graphics/libraries/BLT/libraries/parallel-hashmap" vcs="Git" />
</component>
</project>

View File

@ -49,7 +49,7 @@ macro(blt_add_project name source type)
project(4p78-final-project) project(4p78-final-project)
endmacro() endmacro()
project(4p78-final-project VERSION 0.0.5) project(4p78-final-project VERSION 0.0.3)
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)

View File

@ -27,6 +27,7 @@
#include <emscripten/fetch.h> #include <emscripten/fetch.h>
#endif #endif
blt::gfx::matrix_state_manager global_matrices; blt::gfx::matrix_state_manager global_matrices;
blt::gfx::resource_manager resources; blt::gfx::resource_manager resources;
blt::gfx::batch_renderer_2d renderer_2d(resources, global_matrices); blt::gfx::batch_renderer_2d renderer_2d(resources, global_matrices);
@ -37,142 +38,142 @@ size_t last_time_ran = 0;
struct parker_json_t struct parker_json_t
{ {
float motorTargetAngle; float motorTargetAngle;
float position; float position;
struct anglePID_t
struct anglePID_t {
{ float setpoint;
float setpoint; float input;
float input; float output;
float output; } anglePID;
} anglePID; struct ypr_t
{
struct ypr_t float yaw;
{ float pitch;
float yaw; float roll;
float pitch; } ypr;
float roll; struct euler_t
} ypr; {
float psi;
struct euler_t float theta;
{ float phi;
float psi; } euler;
float theta; struct gravity_t
float phi; {
} euler; float x;
float y;
struct gravity_t float z;
{ } gravity;
float x; struct q_t
float y; {
float z; float x;
} gravity; float y;
float z;
struct q_t float w;
{ } q;
float x; struct aa_t
float y; {
float z; float x;
float w; float y;
} q; float z;
} aa;
struct aa_t struct gy_t
{ {
float x; float x;
float y; float y;
float z; float z;
} aa; } gy;
struct aaReal_t
struct gy_t {
{ float x;
float x; float y;
float y; float z;
float z; } aaReal;
} gy; struct aaWorld_t
{
struct aaReal_t float x;
{ float y;
float x; float z;
float y; } aaWorld;
float z;
} aaReal;
struct aaWorld_t
{
float x;
float y;
float z;
} aaWorld;
}; };
std::string send_get_request(const std::string& url)
{
#ifdef __EMSCRIPTEN__
auto* str = static_cast<char*>(EM_ASM_PTR(
{ const v = await fetch('$0', { 'credentials': 'omit', 'headers': { 'User-Agent':
'Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0', 'Accept': '/', 'Accept-Language': 'en-US,en;q=0.5', 'Priority':
'u=4' }, 'method': 'GET', 'mode': 'cors' }); if (!v.ok) { throw v.status; } return stringToNewUTF8(await response.text()); },
url.c_str()));
std::string str_obj{str};
free(str);
return str_obj;
#else
#endif
}
void check_for_request() void check_for_request()
{ {
const auto cur_time = blt::system::getCurrentTimeMilliseconds(); const auto cur_time = blt::system::getCurrentTimeMilliseconds();
if (cur_time - last_time_ran > 250) if (cur_time - last_time_ran > 250)
{ {
last_time_ran = cur_time; last_time_ran = cur_time;
const std::string_view fuck_you{buffer.data()}; const std::string_view fuck_you{buffer.data()};
std::string parker_hates_this{fuck_you}; std::string parker_hates_this{fuck_you};
auto cstr = parker_hates_this.c_str(); auto cstr = parker_hates_this.c_str();
parker_json_t data{}; parker_json_t data{};
} EM_ASM(
{
const v = await fetch('http://$0/get_stuff', {
'credentials': 'omit',
'headers': {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0',
'Accept': '/',
'Accept-Language': 'en-US,en;q=0.5',
'Priority': 'u=4'
},
'method': 'GET',
'mode': 'cors'
});
if (!v.ok) {
return v.status;
}
const j = await v.json();
const floatArray = j.values;
Module.HEAPF32.set(floatArray, $1 >> 2);
},
cstr,
reinterpret_cast<float*>(&data)
);
}
} }
void init(const blt::gfx::window_data&) void init(const blt::gfx::window_data&)
{ {
using namespace blt::gfx; using namespace blt::gfx;
global_matrices.create_internals();
resources.load_resources(); global_matrices.create_internals();
renderer_2d.create(); resources.load_resources();
renderer_2d.create();
} }
void update(const blt::gfx::window_data& data) void update(const blt::gfx::window_data& data)
{ {
global_matrices.update_perspectives(data.width, data.height, 90, 0.1, 2000); global_matrices.update_perspectives(data.width, data.height, 90, 0.1, 2000);
camera.update(); camera.update();
camera.update_view(global_matrices); camera.update_view(global_matrices);
global_matrices.update(); global_matrices.update();
check_for_request(); check_for_request();
ImGui::SetNextWindowSize(ImVec2(300, static_cast<float>(data.height))); ImGui::SetNextWindowSize(ImVec2(300, static_cast<float>(data.height)));
ImGui::SetNextWindowPos(ImVec2(0, 0)); ImGui::SetNextWindowPos(ImVec2(0, 0));
if (ImGui::Begin("Settings", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize)) if (ImGui::Begin("Settings", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize))
{ {
ImGui::InputText("IP Address", buffer.data(), buffer.size()); ImGui::InputText("IP Address", buffer.data(), buffer.size());
} }
ImGui::End(); ImGui::End();
renderer_2d.render(data.width, data.height); renderer_2d.render(data.width, data.height);
} }
void destroy(const blt::gfx::window_data&) void destroy(const blt::gfx::window_data&)
{ {
global_matrices.cleanup(); global_matrices.cleanup();
resources.cleanup(); resources.cleanup();
renderer_2d.cleanup(); renderer_2d.cleanup();
blt::gfx::cleanup(); blt::gfx::cleanup();
} }
int main() int main()
{ {
blt::gfx::init(blt::gfx::window_data{"Draw Window", init, update, destroy}.setSyncInterval(1)); blt::gfx::init(blt::gfx::window_data{"Draw Window", init, update, destroy}.setSyncInterval(1));
} }