#define VG_3D
#define VG_FRAMEBUFFER_RESIZE 1
#include "vg/vg.h"
+#include "anyascii/anyascii.h"
typedef struct ray_hit ray_hit;
struct ray_hit
static int network_scores_updated = 0;
+static u32 utf8_byte0_byte_count( u8 char0 )
+{
+ for( u32 k=2; k<4; k++ )
+ {
+ if( !(char0 & (0x80 >> k)) )
+ return k;
+ }
+
+ return 0;
+}
+
+static void str_utf8_collapse( const char *str, char *buf, u32 length )
+{
+ if( length == 0 )
+ {
+ strncpy( buf, "User", length );
+ return;
+ }
+
+ u8 *ustr = (u8 *)str;
+ u32 utf32_code = 0x00000000;
+ u32 i=0, j=0, utf32_byte_ct=0;
+
+ for(;i < length-1;)
+ {
+ if( ustr[i] == 0x00 )
+ break;
+
+ if( ustr[i] & 0x80 )
+ {
+ if( utf32_byte_ct )
+ {
+ utf32_byte_ct --;
+ utf32_code |= (ustr[i] & 0x3F) << (utf32_byte_ct*6);
+
+ if( !utf32_byte_ct )
+ {
+ const char *match;
+ size_t chars = anyascii( utf32_code, &match );
+
+ for( u32 k=0; k<VG_MIN(chars, length-1-j); k++ )
+ {
+ buf[ j++ ] = (u8)match[k];
+ }
+ }
+ }
+ else
+ {
+ utf32_byte_ct = utf8_byte0_byte_count( ustr[i] )-1;
+ utf32_code = ustr[i] & (0x3F >> utf32_byte_ct);
+ utf32_code <<= utf32_byte_ct*6;
+ }
+ }
+ else
+ {
+ utf32_byte_ct = 0x00;
+ buf[j ++] = str[i];
+ }
+
+ i++;
+ }
+
+ buf[j] = 0x00;
+}
+
#endif /* COMMON_H */
#include "audio.h"
#include "world.h"
#include "player.h"
+#include "network.h"
-static int cl_ui = 1;
+static int cl_ui = 1,
+ cl_menu = 0;
int main( int argc, char *argv[] )
-{
+{
vg_enter( argc, argv, "Voyager Game Engine" );
}
player_update_pre();
world_update( player.phys.rb.co );
}
+
+ if( vg_get_button_down( "menu" ) )
+ {
+ cl_menu = !cl_menu;
+ }
}
static void vg_update_fixed( int loaded )
void vg_ui(void)
{
+ if( cl_menu )
+ {
+ ui_rect menu =
+ {
+ vg.window_x / 2 - 150,
+ vg.window_y / 2 - 50,
+ 300,
+ 130
+ };
+
+ ui_fill_rect( &ui_global_ctx, menu, 0xa0000000 );
+
+ ui_text( &ui_global_ctx, (ui_rect){ menu[0]+menu[2]/2,menu[1]+6, 0, 0 },
+ steam_username_at_startup,
+ 1, k_text_align_center );
+ menu[1] += 24;
+ menu[3] -= 30;
+
+ ui_rect_pad( menu, 8 );
+ ui_fill_rect( &ui_global_ctx, menu, 0x90ffffff );
+ ui_rect_pad( menu, 2 );
+ ui_fill_rect( &ui_global_ctx, menu, 0xa0000000 );
+
+ menu[1] += 32;
+ ui_text( &ui_global_ctx, (ui_rect){ menu[0]+menu[2]/2,menu[1], 0, 0 },
+ "Exit", 2, k_text_align_center );
+
+ if( vg_get_button_down( "jump" ) )
+ {
+ glfwSetWindowShouldClose( vg.window, 1 );
+ }
+ }
+
#if 0
if( lightedit )
{
/*
* Interface
*/
-#define SR_USE_LOCALHOST
+//#define SR_USE_LOCALHOST
/* Call it at start; Connects us to the gameserver */
static void network_init(void);
nick.inetmsg_id = k_inetmsg_set_nickname;
memset( nick.nickname, 0, 10 );
- strcpy( nick.nickname, "Harry" );
+ strncpy( nick.nickname, steam_username_at_startup, 9 );
SteamAPI_ISteamNetworkingSockets_SendMessageToConnection(
hSteamNetworkingSockets, cremote, &nick, sizeof(netmsg_set_nickname),
#include "vg/vg_steam_networking.h"
#include "vg/vg_steam_auth.h"
#include "vg/vg_steam_http.h"
+#include "vg/vg_steam_friends.h"
/*
* We only want to use steamworks if building for the networked version,
* nothing.
*/
+static char steam_username_at_startup[128];
+
static void recv_steam_warning( int severity, const char *msg )
{
if( severity == 0 )
static int steam_init(void)
{
+ const char *username = NULL;
+
#ifdef SR_NETWORKED
vg_info( "Initializing steamworks\n" );
printf("\n");
vg_success( "\nSteamworks API running\n" );
+
+ ISteamFriends *hSteamFriends = SteamAPI_SteamFriends();
+ username = SteamAPI_ISteamFriends_GetPersonaName( hSteamFriends );
#endif
+ /* TODO: On username update callback */
+ str_utf8_collapse( username, steam_username_at_startup,
+ vg_list_size(steam_username_at_startup) );
+
return 1;
}
{ .name = "down", .bind = GLFW_KEY_F },
{ .name = "yawl", .bind = GLFW_KEY_Q },
{ .name = "yawr", .bind = GLFW_KEY_E },
- { .name = "push", .bind = GLFW_KEY_T }
+ { .name = "push", .bind = GLFW_KEY_T },
+ { .name = "menu", .bind = GLFW_KEY_ESCAPE }
};
static struct button_binding vg_controller_binds[] =
{ "jump", GLFW_GAMEPAD_BUTTON_A },
{ "break", GLFW_GAMEPAD_BUTTON_B },
{ "switchmode", GLFW_GAMEPAD_BUTTON_Y },
- { "reset", GLFW_GAMEPAD_BUTTON_LEFT_BUMPER }
+ { "reset", GLFW_GAMEPAD_BUTTON_LEFT_BUMPER },
+ { "menu", GLFW_GAMEPAD_BUTTON_BACK }
};
static struct axis_binding vg_axis_binds[] =