File confec.cpp changed (mode: 100644) (index 37a1e17..44006b9) |
... |
... |
std::string character_selected = "", character_next_screen = "", |
495 |
495 |
fworld::Entity *trading_entity; |
fworld::Entity *trading_entity; |
496 |
496 |
|
|
497 |
497 |
fgl::Texture tex_circle_grey, tex_circle_orange, tex_cursor, |
fgl::Texture tex_circle_grey, tex_circle_orange, tex_cursor, |
498 |
|
tex_net_notification, tex_notification, tex_recipe_overlay, |
|
|
498 |
|
tex_notification_net, tex_notification, tex_recipe_overlay, |
499 |
499 |
tex_boxes, tex_box_select, tex_character_select; |
tex_boxes, tex_box_select, tex_character_select; |
500 |
500 |
|
|
501 |
501 |
fgl::Framebuffer framebuffer; |
fgl::Framebuffer framebuffer; |
|
... |
... |
int portraitScreenHeight3D = 549; // Supposed to look good at 960p. |
516 |
516 |
int simScreenHeight2D = landscapeScreenHeight2D; |
int simScreenHeight2D = landscapeScreenHeight2D; |
517 |
517 |
int simScreenHeight3D = landscapeScreenHeight3D; |
int simScreenHeight3D = landscapeScreenHeight3D; |
518 |
518 |
|
|
|
519 |
|
// Camera zoom factor. |
|
520 |
|
// This is actually the inverse camera distance factor, as in dolly moves. |
|
521 |
|
double zoom_factor = 1.0; |
|
522 |
|
|
519 |
523 |
fgl::Color ambient_colors[] = { |
fgl::Color ambient_colors[] = { |
520 |
524 |
{ 0.4f, 0.5f, 0.8f, 1.0f }, // Night. |
{ 0.4f, 0.5f, 0.8f, 1.0f }, // Night. |
521 |
525 |
{ 0.6f, 0.5f, 0.8f, 1.0f }, // Morning twilight. |
{ 0.6f, 0.5f, 0.8f, 1.0f }, // Morning twilight. |
|
... |
... |
int main( int argc, char* argv[] ){ |
1446 |
1450 |
tex_circle_grey = loadImage( data_path + "/circle-grey.png", false, false ); |
tex_circle_grey = loadImage( data_path + "/circle-grey.png", false, false ); |
1447 |
1451 |
tex_circle_orange = loadImage( data_path + "/circle-orange.png", false, false ); |
tex_circle_orange = loadImage( data_path + "/circle-orange.png", false, false ); |
1448 |
1452 |
tex_cursor = loadImage( data_path + "/ui/cursor.bmp", false, false ); |
tex_cursor = loadImage( data_path + "/ui/cursor.bmp", false, false ); |
1449 |
|
tex_net_notification = loadImage( data_path + "/ui/net_notification.png", true, false ); |
|
|
1453 |
|
tex_notification_net = loadImage( data_path + "/ui/notification_net.png", true, false ); |
1450 |
1454 |
tex_notification = loadImage( data_path + "/ui/notification.png", true, false ); |
tex_notification = loadImage( data_path + "/ui/notification.png", true, false ); |
1451 |
1455 |
tex_recipe_overlay = loadImage( data_path + "/ui/recipe_overlay.png", false, false ); |
tex_recipe_overlay = loadImage( data_path + "/ui/recipe_overlay.png", false, false ); |
1452 |
1456 |
tex_boxes = loadImage( data_path + "/ui/boxes.png", false, false ); |
tex_boxes = loadImage( data_path + "/ui/boxes.png", false, false ); |
|
... |
... |
FILE *FileOpen( const char* filename, const char* modes ){ |
1506 |
1510 |
void wsConnect( const std::string &uri, void (*f)(std::string) ){ |
void wsConnect( const std::string &uri, void (*f)(std::string) ){ |
1507 |
1511 |
if( !emscripten_websocket_is_supported() ){ |
if( !emscripten_websocket_is_supported() ){ |
1508 |
1512 |
Notify( |
Notify( |
1509 |
|
&tex_net_notification, |
|
|
1513 |
|
&tex_notification_net, |
1510 |
1514 |
"Network Error", |
"Network Error", |
1511 |
1515 |
"WebSocket unsupported" |
"WebSocket unsupported" |
1512 |
1516 |
); |
); |
|
... |
... |
void wsConnect( const std::string &uri, void (*f)(std::string) ){ |
1523 |
1527 |
ws_socket = emscripten_websocket_new( &attr ); |
ws_socket = emscripten_websocket_new( &attr ); |
1524 |
1528 |
if( ws_socket <= 0 ){ |
if( ws_socket <= 0 ){ |
1525 |
1529 |
Notify( |
Notify( |
1526 |
|
&tex_net_notification, |
|
|
1530 |
|
&tex_notification_net, |
1527 |
1531 |
"Network Error", |
"Network Error", |
1528 |
1532 |
"WebSocket creation failed" |
"WebSocket creation failed" |
1529 |
1533 |
); |
); |
|
... |
... |
EM_BOOL wsOnError( int eventType, const EmscriptenWebSocketErrorEvent *e, void * |
1559 |
1563 |
(void)e; |
(void)e; |
1560 |
1564 |
(void)userData; |
(void)userData; |
1561 |
1565 |
Notify( |
Notify( |
1562 |
|
&tex_net_notification, |
|
|
1566 |
|
&tex_notification_net, |
1563 |
1567 |
"Network Error", |
"Network Error", |
1564 |
1568 |
"Event type: " + std::to_string( eventType ) |
"Event type: " + std::to_string( eventType ) |
1565 |
1569 |
); |
); |
|
... |
... |
void wsConnect( const std::string &uri, void (*f)(std::string) ){ |
1610 |
1614 |
// Parse the URI. |
// Parse the URI. |
1611 |
1615 |
auto uri_parts = wsParseAddress( uri ); |
auto uri_parts = wsParseAddress( uri ); |
1612 |
1616 |
if( uri_parts.size() < 6 ){ |
if( uri_parts.size() < 6 ){ |
1613 |
|
Notify( &tex_net_notification, "Network Error", "Invalid URI" ); |
|
|
1617 |
|
Notify( &tex_notification_net, "Network Error", "Invalid URI" ); |
1614 |
1618 |
// Return to the main menu. |
// Return to the main menu. |
1615 |
1619 |
settings_display = false; |
settings_display = false; |
1616 |
1620 |
inputTarget = nullptr; |
inputTarget = nullptr; |
|
... |
... |
void wsConnect( const std::string &uri, void (*f)(std::string) ){ |
1681 |
1685 |
return; |
return; |
1682 |
1686 |
} |
} |
1683 |
1687 |
ws_socket_active = true; |
ws_socket_active = true; |
1684 |
|
// TODO: Notify( &tex_net_notification, "Connected to", uri ); |
|
|
1688 |
|
// TODO: Notify( &tex_notification_net, "Connected to", uri ); |
1685 |
1689 |
ws_callback = f; |
ws_callback = f; |
1686 |
1690 |
// Spawn the WebSocket thread if it does not already exist. |
// Spawn the WebSocket thread if it does not already exist. |
1687 |
1691 |
if( ws_thread.get_id() != std::thread::id() ) return; |
if( ws_thread.get_id() != std::thread::id() ) return; |
|
... |
... |
std::smatch wsParseAddress( const std::string &uri ){ |
1756 |
1760 |
// Poco WebSocket exception handler. |
// Poco WebSocket exception handler. |
1757 |
1761 |
void wsHandleException( Poco::Exception &e ){ |
void wsHandleException( Poco::Exception &e ){ |
1758 |
1762 |
Notify( |
Notify( |
1759 |
|
&tex_net_notification, |
|
|
1763 |
|
&tex_notification_net, |
1760 |
1764 |
"Network Error", |
"Network Error", |
1761 |
1765 |
e.displayText() |
e.displayText() |
1762 |
1766 |
); |
); |
|
... |
... |
void wsConnect( const std::string &uri, void (*f)(std::string) ){ |
1864 |
1868 |
ws_mutex.lock(); |
ws_mutex.lock(); |
1865 |
1869 |
if( uri_parts.size() < 6 || !ws_ready ){ |
if( uri_parts.size() < 6 || !ws_ready ){ |
1866 |
1870 |
Notify( |
Notify( |
1867 |
|
&tex_net_notification, |
|
|
1871 |
|
&tex_notification_net, |
1868 |
1872 |
"Network Error", |
"Network Error", |
1869 |
1873 |
ws_ready ? "Invalid URI" : "Hung socket" |
ws_ready ? "Invalid URI" : "Hung socket" |
1870 |
1874 |
); |
); |
|
... |
... |
void wsConnect( const std::string &uri, void (*f)(std::string) ){ |
1916 |
1920 |
#endif |
#endif |
1917 |
1921 |
}catch( std::exception const &e ){ |
}catch( std::exception const &e ){ |
1918 |
1922 |
Notify( |
Notify( |
1919 |
|
&tex_net_notification, |
|
|
1923 |
|
&tex_notification_net, |
1920 |
1924 |
"Network Error", |
"Network Error", |
1921 |
1925 |
e.what() |
e.what() |
1922 |
1926 |
); |
); |
|
... |
... |
void wsConnect( const std::string &uri, void (*f)(std::string) ){ |
2008 |
2012 |
ws_tcp_sock->set_option( ws_net::ip::tcp::no_delay( true ) ); |
ws_tcp_sock->set_option( ws_net::ip::tcp::no_delay( true ) ); |
2009 |
2013 |
}catch( std::exception const &e ){ |
}catch( std::exception const &e ){ |
2010 |
2014 |
Notify( |
Notify( |
2011 |
|
&tex_net_notification, |
|
|
2015 |
|
&tex_notification_net, |
2012 |
2016 |
"Network Error", |
"Network Error", |
2013 |
2017 |
e.what() |
e.what() |
2014 |
2018 |
); |
); |
|
... |
... |
void wsConnect( const std::string &uri, void (*f)(std::string) ){ |
2019 |
2023 |
return; |
return; |
2020 |
2024 |
} |
} |
2021 |
2025 |
ws_socket_active = true; |
ws_socket_active = true; |
2022 |
|
// TODO: Notify( &tex_net_notification, "Connected to", uri ); |
|
|
2026 |
|
// TODO: Notify( &tex_notification_net, "Connected to", uri ); |
2023 |
2027 |
ws_callback = f; |
ws_callback = f; |
2024 |
2028 |
|
|
2025 |
2029 |
// Asynchronous code. |
// Asynchronous code. |
|
... |
... |
void Tick(){ |
4026 |
4030 |
if( timeout_timer > 5.0 ){ |
if( timeout_timer > 5.0 ){ |
4027 |
4031 |
timeout_timer = 0.0; |
timeout_timer = 0.0; |
4028 |
4032 |
Notify( |
Notify( |
4029 |
|
&tex_net_notification, |
|
|
4033 |
|
&tex_notification_net, |
4030 |
4034 |
"Network Error", |
"Network Error", |
4031 |
4035 |
"Connection lost" |
"Connection lost" |
4032 |
4036 |
); |
); |
|
... |
... |
void Render(){ |
4353 |
4357 |
// Use an inverse square curve to zoom in and a square curve to zoom |
// Use an inverse square curve to zoom in and a square curve to zoom |
4354 |
4358 |
// out. This has the effect of kicking off in either direction while |
// out. This has the effect of kicking off in either direction while |
4355 |
4359 |
// being framerate-independent. |
// being framerate-independent. |
4356 |
|
double zoom_factor = ease( |
|
|
4360 |
|
zoom_factor = ease( |
4357 |
4361 |
1.0, |
1.0, |
4358 |
4362 |
1.1, |
1.1, |
4359 |
4363 |
zoom ? ( 1.0 - ( 1.0 - f ) * ( 1.0 - f ) ) : ( f * f ) |
zoom ? ( 1.0 - ( 1.0 - f ) * ( 1.0 - f ) ) : ( f * f ) |
|
... |
... |
void DrawFloorParticles(){ |
5105 |
5109 |
); |
); |
5106 |
5110 |
} |
} |
5107 |
5111 |
auto viewMat = world.viewMat; |
auto viewMat = world.viewMat; |
|
5112 |
|
// Apply zoom factor to view matrix. |
|
5113 |
|
viewMat[3].xyz() *= 1.0 - ( zoom_factor - 1.0 ) * 6.2; |
|
5114 |
|
// Apply map position to view matrix. |
5108 |
5115 |
viewMat[3][0] += world.cameraX; |
viewMat[3][0] += world.cameraX; |
5109 |
5116 |
viewMat[3][1] -= world.cameraY; |
viewMat[3][1] -= world.cameraY; |
5110 |
5117 |
auto projMat = linalg::perspective_matrix( 68.5 * 0.01745, (double)world.screenWidth / (double)world.screenHeight, 0.1, 44.0 ); |
auto projMat = linalg::perspective_matrix( 68.5 * 0.01745, (double)world.screenWidth / (double)world.screenHeight, 0.1, 44.0 ); |
|
... |
... |
void DrawParticles(){ |
5150 |
5157 |
); |
); |
5151 |
5158 |
} |
} |
5152 |
5159 |
auto viewMat = world.viewMat; |
auto viewMat = world.viewMat; |
|
5160 |
|
// Apply zoom factor to view matrix. |
|
5161 |
|
viewMat[3].xyz() *= 1.0 - ( zoom_factor - 1.0 ) * 6.2; |
|
5162 |
|
// Apply map position to view matrix. |
5153 |
5163 |
viewMat[3][0] += world.cameraX; |
viewMat[3][0] += world.cameraX; |
5154 |
5164 |
viewMat[3][1] -= world.cameraY; |
viewMat[3][1] -= world.cameraY; |
5155 |
5165 |
auto projMat = linalg::perspective_matrix( 68.5 * 0.01745, (double)world.screenWidth / (double)world.screenHeight, 0.1, 44.0 ); |
auto projMat = linalg::perspective_matrix( 68.5 * 0.01745, (double)world.screenWidth / (double)world.screenHeight, 0.1, 44.0 ); |