main
Brett 2025-04-11 14:44:52 -04:00
parent ec2884bece
commit d7f23958c1
2 changed files with 115 additions and 116 deletions

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.3) project(4p78-final-project VERSION 0.0.4)
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,7 +27,6 @@
#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);
@ -40,30 +39,35 @@ 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 yaw;
float pitch; float pitch;
float roll; float roll;
} ypr; } ypr;
struct euler_t struct euler_t
{ {
float psi; float psi;
float theta; float theta;
float phi; float phi;
} euler; } euler;
struct gravity_t struct gravity_t
{ {
float x; float x;
float y; float y;
float z; float z;
} gravity; } gravity;
struct q_t struct q_t
{ {
float x; float x;
@ -71,24 +75,28 @@ struct parker_json_t
float z; float z;
float w; float w;
} q; } q;
struct aa_t struct aa_t
{ {
float x; float x;
float y; float y;
float z; float z;
} aa; } aa;
struct gy_t struct gy_t
{ {
float x; float x;
float y; float y;
float z; float z;
} gy; } gy;
struct aaReal_t struct aaReal_t
{ {
float x; float x;
float y; float y;
float z; float z;
} aaReal; } aaReal;
struct aaWorld_t struct aaWorld_t
{ {
float x; float x;
@ -97,6 +105,22 @@ struct parker_json_t
} aaWorld; } 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();
@ -107,30 +131,6 @@ void check_for_request()
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)
);
} }
} }
@ -138,7 +138,6 @@ void init(const blt::gfx::window_data&)
{ {
using namespace blt::gfx; using namespace blt::gfx;
global_matrices.create_internals(); global_matrices.create_internals();
resources.load_resources(); resources.load_resources();
renderer_2d.create(); renderer_2d.create();