better logging + fix re-login bug + fix some modal bugs
This commit is contained in:
+20
-6
@@ -465,6 +465,9 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
|
|||||||
state->ship_tab_states = ShipTabStateMain;
|
state->ship_tab_states = ShipTabStateMain;
|
||||||
} break;
|
} break;
|
||||||
case MessageTurnTick: {
|
case MessageTurnTick: {
|
||||||
|
MemoryZero(sbuf, SBUFLEN);
|
||||||
|
sprintf(sbuf,"got TurnTick message from server %lld", loop_count);
|
||||||
|
addSystemMessage((u8*)sbuf);
|
||||||
state->screen = ScreenTurnTick;
|
state->screen = ScreenTurnTick;
|
||||||
state->turn_tick_started_on = loop_count;
|
state->turn_tick_started_on = loop_count;
|
||||||
} break;
|
} break;
|
||||||
@@ -473,6 +476,9 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
|
|||||||
MemoryCopyStruct(&state->tx_result, &msg.tx_result);
|
MemoryCopyStruct(&state->tx_result, &msg.tx_result);
|
||||||
} break;
|
} break;
|
||||||
case MessagePlayerDetails: {
|
case MessagePlayerDetails: {
|
||||||
|
MemoryZero(sbuf, SBUFLEN);
|
||||||
|
sprintf(sbuf,"got player details for: %lld (%s us)", msg.ship.id, msg.ship.id == state->me.id ? "it's" : "not");
|
||||||
|
addSystemMessage((u8*)sbuf);
|
||||||
if (msg.ship.id == state->me.id) {
|
if (msg.ship.id == state->me.id) {
|
||||||
state->me.type = msg.ship.type;
|
state->me.type = msg.ship.type;
|
||||||
state->me.system_idx = msg.ship.system_idx;
|
state->me.system_idx = msg.ship.system_idx;
|
||||||
@@ -495,6 +501,9 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case MessageStarPositions: {
|
case MessageStarPositions: {
|
||||||
|
MemoryZero(sbuf, SBUFLEN);
|
||||||
|
sprintf(sbuf,"got StarPositions message from server");
|
||||||
|
addSystemMessage((u8*)sbuf);
|
||||||
for (u32 i = 0; i < STAR_SYSTEM_COUNT; i++) {
|
for (u32 i = 0; i < STAR_SYSTEM_COUNT; i++) {
|
||||||
state->map[i].name = STAR_NAMES[i];
|
state->map[i].name = STAR_NAMES[i];
|
||||||
state->map[i].x = msg.positions[i].x;
|
state->map[i].x = msg.positions[i].x;
|
||||||
@@ -521,11 +530,12 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
|
|||||||
} break;
|
} break;
|
||||||
case MessageCharacterId: {
|
case MessageCharacterId: {
|
||||||
state->me.id = msg.id;
|
state->me.id = msg.id;
|
||||||
char bytes[256] = {0};
|
MemoryZero(sbuf, SBUFLEN);
|
||||||
sprintf(bytes,"got character id: %lld", msg.id);
|
sprintf(sbuf,"got character id: %lld", msg.id);
|
||||||
addSystemMessage((u8*)bytes);
|
addSystemMessage((u8*)sbuf);
|
||||||
state->screen = ScreenMainGame;
|
state->screen = ScreenMainGame;
|
||||||
state->menu.selected_index = 0;
|
state->menu.selected_index = TabMap;
|
||||||
|
state->menu.len = Tab_Count;
|
||||||
state->row.selected_index = 0;
|
state->row.selected_index = 0;
|
||||||
} break;
|
} break;
|
||||||
case Message_Count:
|
case Message_Count:
|
||||||
@@ -572,7 +582,7 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
|
|||||||
//// SIMULATION
|
//// SIMULATION
|
||||||
if (state->me.id != 0) {
|
if (state->me.id != 0) {
|
||||||
state->screen = ScreenMainGame;
|
state->screen = ScreenMainGame;
|
||||||
state->menu.selected_index = 0;
|
state->menu.selected_index = TabMap;
|
||||||
state->menu.len = Tab_Count;
|
state->menu.len = Tab_Count;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -846,11 +856,12 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case TabShip: {
|
case TabShip: {
|
||||||
|
if (state->ship_tab_states == ShipTabStateMain) {
|
||||||
if (input_buffer[0] == 'q' || user_pressed_esc) {
|
if (input_buffer[0] == 'q' || user_pressed_esc) {
|
||||||
should_quit = true;
|
should_quit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
moveRowUpDown(user_pressed_up, user_pressed_down);
|
moveRowUpDown(user_pressed_up, user_pressed_down);
|
||||||
|
}
|
||||||
|
|
||||||
u32 yoff = box.y+1;
|
u32 yoff = box.y+1;
|
||||||
MemoryZero(sbuf, SBUFLEN);
|
MemoryZero(sbuf, SBUFLEN);
|
||||||
@@ -933,6 +944,9 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
|
|||||||
};
|
};
|
||||||
u32 y_off = modal_outline.y+2;
|
u32 y_off = modal_outline.y+2;
|
||||||
if (state->ship_tab_states == ShipTabStatePayoffModal) {
|
if (state->ship_tab_states == ShipTabStatePayoffModal) {
|
||||||
|
if (input_buffer[0] == 'q' || user_pressed_esc) {
|
||||||
|
state->ship_tab_states = ShipTabStateMain;
|
||||||
|
}
|
||||||
if (user_pressed_a_number) {
|
if (user_pressed_a_number) {
|
||||||
String next_char = { 1, 2, (char*)input_buffer };
|
String next_char = { 1, 2, (char*)input_buffer };
|
||||||
stringChunkListAppend(&state->string_arena, &state->message_input, next_char);
|
stringChunkListAppend(&state->string_arena, &state->message_input, next_char);
|
||||||
|
|||||||
+3
-3
@@ -129,12 +129,12 @@ fn void copyStr(u8* bytes, str cstring) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn void clearBox(TuiState* tui, Box box) {
|
fn void clearBox(TuiState* tui, Box box) {
|
||||||
for (u32 i = 0; i < box.height; i++) {
|
for (u32 i = 0; i <= box.height; i++) {
|
||||||
for (u32 ii = 0; ii < box.width; ii++) {
|
for (u32 ii = 0; ii <= box.width; ii++) {
|
||||||
u32 pos = XYToPos(box.x+ii, box.y+i, tui->screen_dimensions.width);
|
u32 pos = XYToPos(box.x+ii, box.y+i, tui->screen_dimensions.width);
|
||||||
tui->frame_buffer[pos].background = 0;
|
tui->frame_buffer[pos].background = 0;
|
||||||
tui->frame_buffer[pos].foreground = 0;
|
tui->frame_buffer[pos].foreground = 0;
|
||||||
tui->frame_buffer[pos].bytes[0] = 0;
|
tui->frame_buffer[pos].bytes[0] = ' ';
|
||||||
tui->frame_buffer[pos].bytes[1] = 0;
|
tui->frame_buffer[pos].bytes[1] = 0;
|
||||||
tui->frame_buffer[pos].bytes[2] = 0;
|
tui->frame_buffer[pos].bytes[2] = 0;
|
||||||
tui->frame_buffer[pos].bytes[3] = 0;
|
tui->frame_buffer[pos].bytes[3] = 0;
|
||||||
|
|||||||
+21
-14
@@ -300,6 +300,24 @@ fn void sendMessagePayoffResult(SocketAddress addr) {
|
|||||||
printf("%s sent\n", MESSAGE_STRINGS[outgoing_message.bytes[0]]);
|
printf("%s sent\n", MESSAGE_STRINGS[outgoing_message.bytes[0]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn void sendMessageStarPositions(SocketAddress addr) {
|
||||||
|
UDPMessage outgoing_message = {0};
|
||||||
|
outgoing_message.address = addr;
|
||||||
|
// tell the client about the map
|
||||||
|
u32 star_msg_size = 2+MAX_PLANETS;
|
||||||
|
outgoing_message.bytes_len = 1+(star_msg_size*STAR_SYSTEM_COUNT);
|
||||||
|
outgoing_message.bytes[0] = (u8)MessageStarPositions;
|
||||||
|
for (u32 i = 0; i < STAR_SYSTEM_COUNT; i++) {
|
||||||
|
outgoing_message.bytes[1+(i*star_msg_size)] = (u8)state.map[i].x;
|
||||||
|
outgoing_message.bytes[2+(i*star_msg_size)] = (u8)state.map[i].y;
|
||||||
|
for (u32 ii = 0; ii < MAX_PLANETS; ii++) {
|
||||||
|
outgoing_message.bytes[3+ii+(i*star_msg_size)] = state.map[i].planets[ii].type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outgoingMessageQueuePush(state.network_send_queue, &outgoing_message);
|
||||||
|
printf("%s sent\n", MESSAGE_STRINGS[outgoing_message.bytes[0]]);
|
||||||
|
}
|
||||||
|
|
||||||
fn void sendMessagePlayerDetails(PlayerShip ship, SocketAddress addr) {
|
fn void sendMessagePlayerDetails(PlayerShip ship, SocketAddress addr) {
|
||||||
UDPMessage outgoing_message = makeMessagePlayerDetails(ship);
|
UDPMessage outgoing_message = makeMessagePlayerDetails(ship);
|
||||||
outgoing_message.address = addr;
|
outgoing_message.address = addr;
|
||||||
@@ -643,6 +661,8 @@ fn void* gameLoop(void* params) {
|
|||||||
arenaDealloc(&permanent_arena, name.capacity);
|
arenaDealloc(&permanent_arena, name.capacity);
|
||||||
if (pw_matches) {
|
if (pw_matches) {
|
||||||
printf(" pw matched\n");
|
printf(" pw matched\n");
|
||||||
|
existing_account->changed = true;
|
||||||
|
sendMessageStarPositions(sender);
|
||||||
} else {
|
} else {
|
||||||
// tell the client they did a bad pw
|
// tell the client they did a bad pw
|
||||||
outgoing_message.bytes[0] = (u8)MessageBadPw;
|
outgoing_message.bytes[0] = (u8)MessageBadPw;
|
||||||
@@ -723,20 +743,7 @@ fn void* gameLoop(void* params) {
|
|||||||
|
|
||||||
sendMessagePlayerDetails(account->ship, sender);
|
sendMessagePlayerDetails(account->ship, sender);
|
||||||
|
|
||||||
// tell the client about the map
|
sendMessageStarPositions(sender);
|
||||||
u32 star_msg_size = 2+MAX_PLANETS;
|
|
||||||
outgoing_message.address = sender;
|
|
||||||
outgoing_message.bytes_len = 1+(star_msg_size*STAR_SYSTEM_COUNT);
|
|
||||||
outgoing_message.bytes[0] = (u8)MessageStarPositions;
|
|
||||||
for (u32 i = 0; i < STAR_SYSTEM_COUNT; i++) {
|
|
||||||
outgoing_message.bytes[1+(i*star_msg_size)] = (u8)state.map[i].x;
|
|
||||||
outgoing_message.bytes[2+(i*star_msg_size)] = (u8)state.map[i].y;
|
|
||||||
for (u32 ii = 0; ii < MAX_PLANETS; ii++) {
|
|
||||||
outgoing_message.bytes[3+ii+(i*star_msg_size)] = state.map[i].planets[ii].type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
outgoingMessageQueuePush(state.network_send_queue, &outgoing_message);
|
|
||||||
printf("%s sent\n", MESSAGE_STRINGS[outgoing_message.bytes[0]]);
|
|
||||||
|
|
||||||
outgoing_message = makeMessageSystemCommodities(&starting_system);
|
outgoing_message = makeMessageSystemCommodities(&starting_system);
|
||||||
outgoing_message.address = sender;
|
outgoing_message.address = sender;
|
||||||
|
|||||||
Reference in New Issue
Block a user