actually find the parser bug (not handling lines that end in \r\n). formatting changes. comment out functions b/c clang can't be bothered to generate generic function defs if the function that uses it isn't actually part of the main program

This commit is contained in:
2025-08-19 08:50:10 -05:00
parent cad3849f28
commit d4d4a236e9
8 changed files with 79 additions and 70 deletions

View File

@@ -67,7 +67,7 @@ bool load_body(body* out_body, const char* obj_filepath) {
start = i + 1;
}
}
if (source[i] == '\n') {
if (source[i] == '\n' || source[i] == '\r') {
state = ParserState::PREFIX;
continue;
}

View File

@@ -8,11 +8,12 @@
#include "util.hpp"
#include "shaders.hpp"
#include "body.hpp"
#include "tcp_server.hpp"
static GLFWwindow* window;
static float width, height;
void framebuffer_size_callback(GLFWwindow* window, int w, int h) {
void framebuffer_size_callback(GLFWwindow* window, int w, int h) {
width = w;
height = h;
glViewport(0, 0, width, height);
@@ -21,7 +22,6 @@ void framebuffer_size_callback(GLFWwindow* window, int w, int h) {
void process_input() {
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
}
static bool mouse_pressed = false;
@@ -50,7 +50,7 @@ static void cursor_position_callback(GLFWwindow* window, double xpos, double ypo
}
if (scroll_pressed) {
focal_point += strafe_x * (dx/300) + strafe_y * (dy/300);
focal_point += strafe_x * (dx / 300) + strafe_y * (dy / 300);
}
double len = glm::length(camera_loc);
@@ -75,12 +75,11 @@ void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
glfwGetCursorPos(window, &prev_cursor_x, &prev_cursor_y);
}
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset) {
glm::vec4 k = camera_t[2];
float d = yoffset;
camera_loc += k * (d/10 * glm::max(glm::length(camera_loc), 1.0f));
camera_loc += k * (d / 10 * max(glm::length(camera_loc), 1.0f));
camera_t = glm::lookAt(camera_loc, focal_point, up);
}
@@ -107,8 +106,12 @@ bool glfw_setup() {
return true;
}
int main() {
//tcpserver server;
//if (!create_server(&server, "127.0.0.1", 5000, 1)) {
// //return -1;
//}
if (!glfw_setup())
return -1;
@@ -126,7 +129,7 @@ int main() {
if (!load_shader(&shader, vertex_filepath, fragment_filepath))
return -1;
//glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
// glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT); // Write to back buffer
@@ -147,9 +150,9 @@ int main() {
b2.pose = glm::translate(b.pose, glm::vec3(2, 0, 0));
b2.color = glm::vec4(0, 0.5, 0, 1);
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
//set_uniform(shader, "color", glm::vec4 { sin(time), sin(time + glm::radians(45.0f)), sin(time + glm::radians(90.0f)), 1.0 } / 2.0f);
//time = glfwGetTime();
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// set_uniform(shader, "color", glm::vec4 { sin(time), sin(time + glm::radians(45.0f)), sin(time +
// glm::radians(90.0f)), 1.0 } / 2.0f); time = glfwGetTime();
glDisable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);

View File

@@ -1,6 +1,7 @@
#include <WS2tcpip.h>
#include <cstring>
#pragma comment(lib, "pthreadVC3d.lib")
#pragma comment(lib, "WS2_32.Lib")
// I hate windows. I hate windows. I hate windows.
@@ -26,20 +27,21 @@ bool create_server(tcpserver* server_out, const char* hostname, int port, int ma
winsock_initialized = true;
return false;
}
SOCKET sock;
// ********** Addr Info Creation **********
addrinfo *result, *ptr, hints;
addrinfo *result, hints;
char port_str[16];
_itoa_s(port, port_str, 10);
// TODO: Ensure hostname is null-terminated
int status = getaddrinfo(hostname, port_str, &hints, result);
int status = getaddrinfo(hostname, port_str, &hints, &result);
if (status != 0) {
printf("Error at getaddrinfo(): %d\n", status);
goto fail_cleanup;
}
// *********** Socket Creation ************
SOCKET sock = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
sock = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
if (sock == INVALID_SOCKET) {
printf("Error at socket(): %d\n", WSAGetLastError());
freeaddrinfo(result);
@@ -65,35 +67,36 @@ fail_cleanup:
void start_server(tcpserver& s) { }
void stop_server(tcpserver& s) { }
void send_data(tcpserver& s, SOCKET client, array<char> data) { }
void register_cb(tcpserver& s, data_received_cb_t cb) { append(s.cbs, cb); }
//void register_recv_cb(tcpserver& s, data_received_cb_t cb) { append(s.cbs, cb); }
void _server_loop(void* args) {
tcpserver* s = static_cast<tcpserver*>(args);
int num_connections = 0;
int slots[s->max_connections];
array<int> open_slots
= { .data = slots, .len = (size_t)s->max_connections, .cap = (size_t)s->max_connections };
for (int i = 0; i < open_slots.len; i++) {
open_slots[i] = open_slots.len - (i + 1);
}
SOCKET clients[s->max_connections];
memset(clients, INVALID_SOCKET, sizeof(SOCKET));
while (true) {
while (num_connections < s->max_connections) {
int slot = pop(open_slots);
clients[slot] = accept(s->sock, NULL, NULL);
// TODO: More robust handling of bad client sockets
if (clients[slot] == INVALID_SOCKET) {
printf("Error at accept(): %d\n", WSAGetLastError());
stop_server(*s);
return;
}
_start_conn_loop(clients[slot]);
}
}
}
//void _server_loop(void* args) {
// tcpserver* s = static_cast<tcpserver*>(args);
//
// int num_connections = 0;
// int mc = s->max_connections;
// array<int> open_slots = {
// .data = (int*)malloc(sizeof(int)*mc), .len = (size_t)mc, .cap = (size_t)mc
// };
// for (int i = 0; i < open_slots.len; i++) {
// open_slots[i] = open_slots.len - (i + 1);
// }
//
// array<SOCKET> clients = { (SOCKET*)malloc(sizeof(SOCKET) * mc), (size_t)mc, (size_t)mc };
// memset(clients.data, INVALID_SOCKET, sizeof(SOCKET)*mc);
// while (true) {
// while (num_connections < s->max_connections) {
// int slot = pop(open_slots);
// clients[slot] = accept(s->sock, NULL, NULL);
// // TODO: More robust handling of bad client sockets
// if (clients[slot] == INVALID_SOCKET) {
// printf("Error at accept(): %d\n", WSAGetLastError());
// stop_server(*s);
// return;
// }
// _start_conn_loop(clients[slot]);
// }
// }
//}
void _start_conn_loop(SOCKET client_s) {