|
|
@ -253,7 +253,6 @@ static enum BoxType currently_building()
|
|
|
|
return toolbar[cur_toolbar_slot];
|
|
|
|
return toolbar[cur_toolbar_slot];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct BoxInfo boxinfo(enum BoxType type)
|
|
|
|
struct BoxInfo boxinfo(enum BoxType type)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int i = 0; i < ARRLEN(boxes); i++)
|
|
|
|
for (int i = 0; i < ARRLEN(boxes); i++)
|
|
|
@ -519,29 +518,30 @@ static void init(void)
|
|
|
|
result = ma_device_init(NULL, µphone_config, µphone_device);
|
|
|
|
result = ma_device_init(NULL, µphone_config, µphone_device);
|
|
|
|
if (result != MA_SUCCESS)
|
|
|
|
if (result != MA_SUCCESS)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Log("Failed to initialize capture device.\n");
|
|
|
|
quit_with_popup("Failed to initialize microphone\n", "Failed to initialize audio");
|
|
|
|
exit(-1);
|
|
|
|
Log("Cap device fail\n");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result = ma_device_init(NULL, &speaker_config, &speaker_device);
|
|
|
|
result = ma_device_init(NULL, &speaker_config, &speaker_device);
|
|
|
|
if (result != MA_SUCCESS)
|
|
|
|
if (result != MA_SUCCESS)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ma_device_uninit(µphone_device);
|
|
|
|
ma_device_uninit(µphone_device);
|
|
|
|
|
|
|
|
quit_with_popup("Failed to initialize speaker/headphones\n", "Failed to initialize audio");
|
|
|
|
Log("Failed to init speaker\n");
|
|
|
|
Log("Failed to init speaker\n");
|
|
|
|
exit(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ma_mutex_init(&send_packets_mutex) != MA_SUCCESS)
|
|
|
|
flight_assert(ma_mutex_init(&send_packets_mutex) == MA_SUCCESS);
|
|
|
|
Log("Failed to init send mutex\n");
|
|
|
|
flight_assert(ma_mutex_init(&play_packets_mutex) == MA_SUCCESS);
|
|
|
|
if (ma_mutex_init(&play_packets_mutex) != MA_SUCCESS)
|
|
|
|
|
|
|
|
Log("Failed to init play mutex\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = ma_device_start(µphone_device);
|
|
|
|
result = ma_device_start(µphone_device);
|
|
|
|
if (result != MA_SUCCESS)
|
|
|
|
if (result != MA_SUCCESS)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ma_device_uninit(µphone_device);
|
|
|
|
ma_device_uninit(µphone_device);
|
|
|
|
Log("Failed to start device.\n");
|
|
|
|
Log("Failed to start mic.\n");
|
|
|
|
exit(-1);
|
|
|
|
quit_with_popup("Failed to start microphone device\n", "Failed to start audio");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result = ma_device_start(&speaker_device);
|
|
|
|
result = ma_device_start(&speaker_device);
|
|
|
@ -550,7 +550,8 @@ static void init(void)
|
|
|
|
ma_device_uninit(µphone_device);
|
|
|
|
ma_device_uninit(µphone_device);
|
|
|
|
ma_device_uninit(&speaker_device);
|
|
|
|
ma_device_uninit(&speaker_device);
|
|
|
|
Log("Failed to start speaker\n");
|
|
|
|
Log("Failed to start speaker\n");
|
|
|
|
exit(-1);
|
|
|
|
quit_with_popup("Failed to start speaker device\n", "Failed to start audio");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Log("Initialized audio\n");
|
|
|
|
Log("Initialized audio\n");
|
|
|
@ -580,118 +581,114 @@ static void init(void)
|
|
|
|
exit(-1);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// shaders
|
|
|
|
// initialize shaders
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// initialize shader
|
|
|
|
sgp_pipeline_desc pip_desc = {
|
|
|
|
|
|
|
|
.shader = *hueshift_program_shader_desc(sg_query_backend()),
|
|
|
|
|
|
|
|
.blend_mode = SGP_BLENDMODE_BLEND,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
hueshift_pipeline = sgp_make_pipeline(&pip_desc);
|
|
|
|
|
|
|
|
if (sg_query_pipeline_state(hueshift_pipeline) != SG_RESOURCESTATE_VALID)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fprintf(stderr, "failed to make hueshift pipeline\n");
|
|
|
|
sgp_pipeline_desc pip_desc = {
|
|
|
|
exit(-1);
|
|
|
|
.shader = *hueshift_program_shader_desc(sg_query_backend()),
|
|
|
|
}
|
|
|
|
.blend_mode = SGP_BLENDMODE_BLEND,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
hueshift_pipeline = sgp_make_pipeline(&pip_desc);
|
|
|
|
|
|
|
|
if (sg_query_pipeline_state(hueshift_pipeline) != SG_RESOURCESTATE_VALID)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(stderr, "failed to make hueshift pipeline\n");
|
|
|
|
|
|
|
|
exit(-1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sgp_pipeline_desc pip_desc = {
|
|
|
|
|
|
|
|
.shader = *goodpixel_program_shader_desc(sg_query_backend()),
|
|
|
|
|
|
|
|
.blend_mode = SGP_BLENDMODE_BLEND,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
goodpixel_pipeline = sgp_make_pipeline(&pip_desc);
|
|
|
|
{
|
|
|
|
if (sg_query_pipeline_state(goodpixel_pipeline) != SG_RESOURCESTATE_VALID)
|
|
|
|
sgp_pipeline_desc pip_desc = {
|
|
|
|
{
|
|
|
|
.shader = *goodpixel_program_shader_desc(sg_query_backend()),
|
|
|
|
fprintf(stderr, "failed to make goodpixel pipeline\n");
|
|
|
|
.blend_mode = SGP_BLENDMODE_BLEND,
|
|
|
|
exit(-1);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// images loading
|
|
|
|
goodpixel_pipeline = sgp_make_pipeline(&pip_desc);
|
|
|
|
|
|
|
|
if (sg_query_pipeline_state(goodpixel_pipeline) != SG_RESOURCESTATE_VALID)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int i = 0; i < ARRLEN(boxes); i++)
|
|
|
|
fprintf(stderr, "failed to make goodpixel pipeline\n");
|
|
|
|
{
|
|
|
|
exit(-1);
|
|
|
|
boxes[i].image = load_image(boxes[i].image_path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
image_thrusterburn = load_image("loaded/thrusterburn.png");
|
|
|
|
|
|
|
|
image_itemframe = load_image("loaded/itemframe.png");
|
|
|
|
|
|
|
|
image_itemframe_selected = load_image("loaded/itemframe_selected.png");
|
|
|
|
|
|
|
|
image_player = load_image("loaded/player.png");
|
|
|
|
|
|
|
|
image_cockpit_used = load_image("loaded/cockpit_used.png");
|
|
|
|
|
|
|
|
image_stars = load_image("loaded/stars.png");
|
|
|
|
|
|
|
|
image_stars2 = load_image("loaded/stars2.png");
|
|
|
|
|
|
|
|
image_sun = load_image("loaded/sun.png");
|
|
|
|
|
|
|
|
image_medbay_used = load_image("loaded/medbay_used.png");
|
|
|
|
|
|
|
|
image_mystery = load_image("loaded/mystery.png");
|
|
|
|
|
|
|
|
image_explosion = load_image("loaded/explosion.png");
|
|
|
|
|
|
|
|
image_low_health = load_image("loaded/low_health.png");
|
|
|
|
|
|
|
|
image_mic_muted = load_image("loaded/mic_muted.png");
|
|
|
|
|
|
|
|
image_mic_unmuted = load_image("loaded/mic_unmuted.png");
|
|
|
|
|
|
|
|
image_flag_available = load_image("loaded/flag_available.png");
|
|
|
|
|
|
|
|
image_flag_taken = load_image("loaded/flag_ripped.png");
|
|
|
|
|
|
|
|
image_squad_invite = load_image("loaded/squad_invite.png");
|
|
|
|
|
|
|
|
image_check = load_image("loaded/check.png");
|
|
|
|
|
|
|
|
image_no = load_image("loaded/no.png");
|
|
|
|
|
|
|
|
image_solarpanel_charging = load_image("loaded/solarpanel_charging.png");
|
|
|
|
|
|
|
|
image_scanner_head = load_image("loaded/scanner_head.png");
|
|
|
|
|
|
|
|
image_itemswitch = load_image("loaded/itemswitch.png");
|
|
|
|
|
|
|
|
image_cloaking_panel = load_image("loaded/cloaking_panel.png");
|
|
|
|
|
|
|
|
image_missile_burning = load_image("loaded/missile_burning.png");
|
|
|
|
|
|
|
|
image_missile = load_image("loaded/missile.png");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// socket initialization
|
|
|
|
// images loading
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (enet_initialize() != 0)
|
|
|
|
for (int i = 0; i < ARRLEN(boxes); i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fprintf(stderr, "An error occurred while initializing ENet.\n");
|
|
|
|
boxes[i].image = load_image(boxes[i].image_path);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
image_thrusterburn = load_image("loaded/thrusterburn.png");
|
|
|
|
client = enet_host_create(NULL /* create a client host */,
|
|
|
|
image_itemframe = load_image("loaded/itemframe.png");
|
|
|
|
1 /* only allow 1 outgoing connection */,
|
|
|
|
image_itemframe_selected = load_image("loaded/itemframe_selected.png");
|
|
|
|
2 /* allow up 2 channels to be used, 0 and 1 */,
|
|
|
|
image_player = load_image("loaded/player.png");
|
|
|
|
0 /* assume any amount of incoming bandwidth */,
|
|
|
|
image_cockpit_used = load_image("loaded/cockpit_used.png");
|
|
|
|
0 /* assume any amount of outgoing bandwidth */);
|
|
|
|
image_stars = load_image("loaded/stars.png");
|
|
|
|
if (client == NULL)
|
|
|
|
image_stars2 = load_image("loaded/stars2.png");
|
|
|
|
{
|
|
|
|
image_sun = load_image("loaded/sun.png");
|
|
|
|
fprintf(
|
|
|
|
image_medbay_used = load_image("loaded/medbay_used.png");
|
|
|
|
stderr,
|
|
|
|
image_mystery = load_image("loaded/mystery.png");
|
|
|
|
"An error occurred while trying to create an ENet client host.\n");
|
|
|
|
image_explosion = load_image("loaded/explosion.png");
|
|
|
|
exit(-1);
|
|
|
|
image_low_health = load_image("loaded/low_health.png");
|
|
|
|
}
|
|
|
|
image_mic_muted = load_image("loaded/mic_muted.png");
|
|
|
|
ENetAddress address;
|
|
|
|
image_mic_unmuted = load_image("loaded/mic_unmuted.png");
|
|
|
|
ENetEvent event;
|
|
|
|
image_flag_available = load_image("loaded/flag_available.png");
|
|
|
|
|
|
|
|
image_flag_taken = load_image("loaded/flag_ripped.png");
|
|
|
|
enet_address_set_host(&address, SERVER_ADDRESS);
|
|
|
|
image_squad_invite = load_image("loaded/squad_invite.png");
|
|
|
|
Log("Connecting to %s:%d\n", SERVER_ADDRESS, SERVER_PORT);
|
|
|
|
image_check = load_image("loaded/check.png");
|
|
|
|
address.port = SERVER_PORT;
|
|
|
|
image_no = load_image("loaded/no.png");
|
|
|
|
peer = enet_host_connect(client, &address, 2, 0);
|
|
|
|
image_solarpanel_charging = load_image("loaded/solarpanel_charging.png");
|
|
|
|
if (peer == NULL)
|
|
|
|
image_scanner_head = load_image("loaded/scanner_head.png");
|
|
|
|
{
|
|
|
|
image_itemswitch = load_image("loaded/itemswitch.png");
|
|
|
|
fprintf(stderr,
|
|
|
|
image_cloaking_panel = load_image("loaded/cloaking_panel.png");
|
|
|
|
"No available peers for initiating an ENet connection.\n");
|
|
|
|
image_missile_burning = load_image("loaded/missile_burning.png");
|
|
|
|
exit(-1);
|
|
|
|
image_missile = load_image("loaded/missile.png");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// the timeout is the third parameter here
|
|
|
|
|
|
|
|
if (enet_host_service(client, &event, 5000) > 0 &&
|
|
|
|
// socket initialization
|
|
|
|
event.type == ENET_EVENT_TYPE_CONNECT)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (enet_initialize() != 0)
|
|
|
|
Log("Connected\n");
|
|
|
|
{
|
|
|
|
}
|
|
|
|
fprintf(stderr, "An error occurred while initializing ENet.\n");
|
|
|
|
else
|
|
|
|
exit(-1);
|
|
|
|
{
|
|
|
|
}
|
|
|
|
/* Either the 5 seconds are up or a disconnect event was */
|
|
|
|
client = enet_host_create(NULL /* create a client host */,
|
|
|
|
/* received. Reset the peer in the event the 5 seconds */
|
|
|
|
1 /* only allow 1 outgoing connection */,
|
|
|
|
/* had run out without any significant event. */
|
|
|
|
2 /* allow up 2 channels to be used, 0 and 1 */,
|
|
|
|
enet_peer_reset(peer);
|
|
|
|
0 /* assume any amount of incoming bandwidth */,
|
|
|
|
fprintf(stderr, "Connection to server failed.");
|
|
|
|
0 /* assume any amount of outgoing bandwidth */);
|
|
|
|
exit(-1);
|
|
|
|
if (client == NULL)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
fprintf(
|
|
|
|
|
|
|
|
stderr,
|
|
|
|
|
|
|
|
"An error occurred while trying to create an ENet client host.\n");
|
|
|
|
|
|
|
|
exit(-1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ENetAddress address;
|
|
|
|
|
|
|
|
ENetEvent event;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enet_address_set_host(&address, SERVER_ADDRESS);
|
|
|
|
|
|
|
|
Log("Connecting to %s:%d\n", SERVER_ADDRESS, SERVER_PORT);
|
|
|
|
|
|
|
|
address.port = SERVER_PORT;
|
|
|
|
|
|
|
|
peer = enet_host_connect(client, &address, 2, 0);
|
|
|
|
|
|
|
|
if (peer == NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
|
|
|
"No available peers for initiating an ENet connection.\n");
|
|
|
|
|
|
|
|
exit(-1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// the timeout is the third parameter here
|
|
|
|
|
|
|
|
if (enet_host_service(client, &event, 5000) > 0 &&
|
|
|
|
|
|
|
|
event.type == ENET_EVENT_TYPE_CONNECT)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Log("Connected\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Either the 5 seconds are up or a disconnect event was */
|
|
|
|
|
|
|
|
/* received. Reset the peer in the event the 5 seconds */
|
|
|
|
|
|
|
|
/* had run out without any significant event. */
|
|
|
|
|
|
|
|
enet_peer_reset(peer);
|
|
|
|
|
|
|
|
Log("Failed to connecvt to server\n");
|
|
|
|
|
|
|
|
quit_with_popup("Failed to connect to server. Is your wifi down? It took too long.", "Connection Failure");
|
|
|
|
|
|
|
|
Log("Connection to server failed.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|