From: hgn Date: Mon, 8 Aug 2022 20:55:11 +0000 (+0100) Subject: new build method X-Git-Url: https://harrygodden.com/git/?p=vg.git;a=commitdiff_plain;h=290b48a4215fa0a0906b0d75075a1c8b90a34cc4 new build method --- diff --git a/src/tools.sh b/src/tools.sh new file mode 100644 index 0000000..e5a428a --- /dev/null +++ b/src/tools.sh @@ -0,0 +1,32 @@ +mkdir $_folder/tools -p + +_link="-lm" + +tool_shader(){ + _src="vg/src/shader.c" + _dst="tools/shader" + compile_x +} + +tool_fontcomp(){ + _src="vg/src/fontcomp.c" + _dst="tools/fontcomp" + compile_x +} + +tool_qoiconv(){ + _src="vg/src/qoiconv.c" + _dst="tools/qoiconv" + compile_x +} + +tool_texsheet(){ + _src="vg/src/texsheet.c" + _dst="tools/texsheet" + compile_x +} + +tool_shader +tool_fontcomp +tool_qoiconv +tool_texsheet diff --git a/src/vg/vg_m.h b/src/vg/vg_m.h index 7e827a5..a97101e 100644 --- a/src/vg/vg_m.h +++ b/src/vg/vg_m.h @@ -902,29 +902,29 @@ static inline void m4x3_lookat( m4x3f m, v3f pos, v3f target, v3f up ) { 0.0f, 0.0f, 0.0f, 0.0f }} static void m4x4_projection( m4x4f m, float angle, - float ratio, float near, float far ) + float ratio, float fnear, float ffar ) { - float scale = tanf( angle * 0.5f * VG_PIf / 180.0f ) * near, + float scale = tanf( angle * 0.5f * VG_PIf / 180.0f ) * fnear, r = ratio * scale, l = -r, t = scale, b = -t; - m[0][0] = 2.0f * near / (r - l); + m[0][0] = 2.0f * fnear / (r - l); m[0][1] = 0.0f; m[0][2] = 0.0f; m[0][3] = 0.0f; m[1][0] = 0.0f; - m[1][1] = 2.0f * near / (t - b); + m[1][1] = 2.0f * fnear / (t - b); m[1][2] = 0.0f; m[1][3] = 0.0f; m[2][0] = (r + l) / (r - l); m[2][1] = (t + b) / (t - b); - m[2][2] = -(far + near) / (far - near); + m[2][2] = -(ffar + fnear) / (ffar - fnear); m[2][3] = -1.0f; m[3][0] = 0.0f; m[3][1] = 0.0f; - m[3][2] = -2.0f * far * near / (far - near); + m[3][2] = -2.0f * ffar * fnear / (ffar - fnear); m[3][3] = 0.0f; } diff --git a/src/vg/vg_steam.h b/src/vg/vg_steam.h index b503d0b..604dcdf 100644 --- a/src/vg/vg_steam.h +++ b/src/vg/vg_steam.h @@ -27,6 +27,14 @@ typedef int E_iCallBack_t; typedef u64 u64_steamid; typedef u64 SteamAPICall_t; +typedef u32 AppId_t; +const AppId_t k_uAppIdInvalid = 0x0; + +typedef u32 DepotId_t; +const DepotId_t k_uDepotIdInvalid = 0x0; + +typedef u32 RTime32; + enum { k_iSteamUserCallbacks = 100 }; enum { k_iSteamGameServerCallbacks = 200 }; enum { k_iSteamFriendsCallbacks = 300 }; @@ -576,4 +584,15 @@ static void steamworks_event_loop( HSteamPipe pipe, } } +/* + * This is required to run the server outside of steamcmd environment. + * It can be any appid but idealy the one that is actually your game + */ +static void steamworks_ensure_txt( const char *appid_str ) +{ + FILE *txt = fopen("steam_appid.txt", "w"); + fputs( appid_str, txt ); + fclose( txt ); +} + #endif /* VG_STEAM_H */ diff --git a/src/vg/vg_steam_auth.h b/src/vg/vg_steam_auth.h index dec590a..9d06c9c 100644 --- a/src/vg/vg_steam_auth.h +++ b/src/vg/vg_steam_auth.h @@ -1,6 +1,9 @@ #ifndef VG_STEAM_AUTH_H #define VG_STEAM_AUTH_H +typedef u32 HAuthTicket; +enum{ k_HAuthTicketInvalid = 0 }; + #include "vg_steam.h" #if defined( VALVE_CALLBACK_PACK_SMALL ) #pragma pack( push, 4 ) @@ -8,19 +11,134 @@ #pragma pack( push, 8 ) #endif +typedef struct EncryptedAppTicketResponse_t EncryptedAppTicketResponse_t; +struct EncryptedAppTicketResponse_t +{ + EResult m_eResult; +}; +enum{ k_iEncryptedAppTicketResponse = k_iSteamUserCallbacks + 54 }; + +typedef struct GetAuthSessionTicketResponse_t GetAuthSessionTicketResponse_t; +struct GetAuthSessionTicketResponse_t +{ + HAuthTicket m_hAuthTicket; + EResult m_eResult; +}; +enum{ k_iGetAuthSessionTicketResponse = k_iSteamUserCallbacks + 63 }; + #pragma pack(pop) -typedef u32 HAuthTicket; -enum{ k_HAuthTicketInvalid = 0 }; +/* + * Regular authentication + */ -void *SteamAPI_SteamUser_v021(void); -void *SteamAPI_SteamUser(void) +typedef void ISteamUser; +ISteamUser *SteamAPI_SteamUser_v021(void); +ISteamUser *SteamAPI_SteamUser(void) { return SteamAPI_SteamUser_v021(); } HAuthTicket SteamAPI_ISteamUser_GetAuthSessionTicket( - void *self, void *pTicket, + ISteamUser *self, void *pTicket, int cbMaxTicket, u32 *pcbTicket ); +/* + * Application symetric-key ticket (Client) + */ + +SteamAPICall_t SteamAPI_ISteamUser_RequestEncryptedAppTicket( + ISteamUser *self, void *pDataToInclude, int cbDataToInclude ); + +int SteamAPI_ISteamUser_GetEncryptedAppTicket( + ISteamUser *self, void *pTicket, + int cbMaxTicket, u32 *pcbTicket ); + + +/* + * Application symetric-key ticket method (Server) + */ + +enum { k_nSteamEncryptedAppTicketSymmetricKeyLen = 32 }; + +int SteamEncryptedAppTicket_BDecryptTicket( u8 *rgubTicketEncrypted, + u32 cubTicketEncrypted, u8 *rgubTicketDecrypted, + u32 *pcubTicketDecrypted, + u8 rgubKey[k_nSteamEncryptedAppTicketSymmetricKeyLen], + int cubKey ); + +int SteamEncryptedAppTicket_BIsTicketForApp( u8 *rgubTicketDecrypted, + u32 cubTicketDecrypted, AppId_t nAppID ); + +RTime32 SteamEncryptedAppTicket_GetTicketIssueTime( u8 *rgubTicketDecrypted, + u32 cubTicketDecrypted ); + +void SteamEncryptedAppTicket_GetTicketSteamID( + u8 *rgubTicketDecrypted, u32 cubTicketDecrypted, CSteamID *psteamID ); + +AppId_t SteamEncryptedAppTicket_GetTicketAppID( u8 *rgubTicketDecrypted, + u32 cubTicketDecrypted ); + +int SteamEncryptedAppTicket_BUserOwnsAppInTicket( u8 *rgubTicketDecrypted, + u32 cubTicketDecrypted, AppId_t nAppID ); + +int SteamEncryptedAppTicket_BUserIsVacBanned( u8 *rgubTicketDecrypted, + u32 cubTicketDecrypted ); + +int SteamEncryptedAppTicket_BGetAppDefinedValue( u8 *rgubTicketDecrypted, + u32 cubTicketDecrypted, u32 *pValue ); + +u8 *SteamEncryptedAppTicket_GetUserVariableData( u8 *rgubTicketDecrypted, + u32 cubTicketDecrypted, u32 *pcubUserData ); + +int SteamEncryptedAppTicket_BIsTicketSigned( u8 *rgubTicketDecrypted, + u32 cubTicketDecrypted, u8 *pubRSAKey, u32 cubRSAKey ); + +int SteamEncryptedAppTicket_BIsLicenseBorrowed( u8 *rgubTicketDecrypted, + u32 cubTicketDecrypted ); + +int SteamEncryptedAppTicket_BIsLicenseTemporary( u8 *rgubTicketDecrypted, + u32 cubTicketDecrypted ); + +static u8 vg_char_base16( char c ) +{ + if( c >= '0' && c <= '9' ) + return c-'0'; + if( c >= 'a' && c <= 'f' ) + return (c-'a') + 10; + + return 0; +} + +static int vg_load_steam_symetric_key( const char *path, u8 *buf ) +{ + i64 len; + char *text_src = vg_textasset_read_s( path, &len ); + + if( text_src ) + { + if( len < k_nSteamEncryptedAppTicketSymmetricKeyLen ) + { + vg_error( "Application key was invalid size\n" ); + free( text_src ); + return 0; + } + + for( int i=0; im_pData ); + */ + void (*m_pfnFreeData)( SteamNetworkingMessage_t *pMsg ); + + /* + * Function to used to decrement the internal reference count and, if + * it's zero, release the message. You should not set this function pointer, + * or need to access this directly! Use the Release() function instead! + */ + void (*m_pfnRelease)( SteamNetworkingMessage_t *pMsg ); + + /* + * When using ISteamNetworkingMessages, the channel number the message was + * received on (Not used for messages sent or received on "connections") + */ + int m_nChannel; + + /* + * Bitmask of k_nSteamNetworkingSend_xxx flags. + * For received messages, only the k_nSteamNetworkingSend_Reliable bit is + * valid. + * For outbound messages, all bits are relevant + */ + int m_nFlags; + + /* + * Arbitrary user data that you can use when sending messages using + * ISteamNetworkingUtils::AllocateMessage and + * ISteamNetworkingSockets::SendMessage. + * (The callback you set in m_pfnFreeData might use this field.) + * + * Not used for received messages. + */ + i64 m_nUserData; + + /* + * For outbound messages, which lane to use? See + * ISteamNetworkingSockets::ConfigureConnectionLanes. + * For inbound messages, what lane was the message received on? + */ + u16 m_idxLane; + u16 _pad1__; +}; + +void SteamAPI_SteamNetworkingMessage_t_Release(SteamNetworkingMessage_t* self); + + + + +/* + * Utility + */ + +static const char *string_ESteamNetworkingConnectionState( + ESteamNetworkingConnectionState s ) +{ + switch(s) + { + case k_ESteamNetworkingConnectionState_None: return "None"; break; + case k_ESteamNetworkingConnectionState_Connecting: + return "Connecting"; + break; + case k_ESteamNetworkingConnectionState_FindingRoute: + return "Finding route"; + break; + case k_ESteamNetworkingConnectionState_Connected: + return "Connected"; + break; + case k_ESteamNetworkingConnectionState_ClosedByPeer: + return "Closed By Peer"; + break; + case k_ESteamNetworkingConnectionState_ProblemDetectedLocally: + return "Problem detected locally"; + break; + case k_ESteamNetworkingConnectionState_FinWait: + return "Finwait"; + break; + case k_ESteamNetworkingConnectionState_Linger: + return "Linger"; + break; + case k_ESteamNetworkingConnectionState_Dead: + return "Dead"; + break; + case k_ESteamNetworkingConnectionState__Force32Bit: + return "Force 32 Bit"; + break; + } + + return "Error"; +} + +static const char *string_ESteamNetworkingAvailability( + ESteamNetworkingAvailability s ) +{ + switch(s) + { + case k_ESteamNetworkingAvailability_CannotTry: + return "Cannot Try"; + break; + case k_ESteamNetworkingAvailability_Failed: + return "Failed"; + break; + case k_ESteamNetworkingAvailability_Previously: + return "Previously"; + break; + case k_ESteamNetworkingAvailability_Retrying: + return "Retrying"; + break; + case k_ESteamNetworkingAvailability_NeverTried: + return "Never tried"; + break; + case k_ESteamNetworkingAvailability_Waiting: + return "Waiting"; + break; + case k_ESteamNetworkingAvailability_Attempting: + return "Attempting"; + break; + case k_ESteamNetworkingAvailability_Current: + return "Current"; + break; + case k_ESteamNetworkingAvailability_Unknown: + return "Unknown"; + break; + default: + return "Error"; + break; + } +} + #endif /* VG_STEAM_NETWORKING_H */ diff --git a/src/vg/vg_ui.h b/src/vg/vg_ui.h index 5b97133..917b5e6 100644 --- a/src/vg/vg_ui.h +++ b/src/vg/vg_ui.h @@ -123,6 +123,8 @@ struct ui_ctx } *verts; #pragma pack(pop) + + u32 control_id; u32 num_verts; u16 *indices; @@ -133,8 +135,7 @@ struct ui_ctx u32 stack_count; u32 capture_mouse_id; int capture_lock; - u32 id_base; - int glyph_base; + /* User input */ ui_px mouse[2]; @@ -463,21 +464,14 @@ static void ui_clamp_rect( ui_rect parent, ui_rect dest ) dest[1] = vg_max( parent[1], dest[1] ); } -static u32 ui_group_id( ui_ctx *ctx, u32 lesser_unique ) -{ - return ctx->id_base | lesser_unique; -} - static void ui_capture_mouse( ui_ctx *ctx, u32 id ) { - u32 group_uid = ui_group_id(ctx,id); - struct ui_qnode *node = &ctx->stack[ ctx->stack_count-1 ]; - node->capture_id = group_uid; + node->capture_id = id; if( !ctx->capture_lock && node->mouse_over ) { - ctx->capture_mouse_id = group_uid; + ctx->capture_mouse_id = id; } } @@ -728,11 +722,13 @@ enum button_state k_button_hold }; -static int ui_button( ui_ctx *ctx, u32 id ) +static int ui_button( ui_ctx *ctx ) { + u32 uid = ctx->control_id ++; + ui_new_node( ctx ); { - ui_capture_mouse( ctx, id ); + ui_capture_mouse( ctx, uid ); if( ui_hasmouse(ctx) ) { @@ -757,8 +753,6 @@ static int ui_button( ui_ctx *ctx, u32 id ) static int ui_window( ui_ctx *ctx, struct ui_window *window, u32 control_group ) { - ctx->id_base = control_group << 16; - if( window->drag ) { window->transform[0] = ctx->mouse[0]+window->drag_offset[0]; @@ -776,13 +770,13 @@ static int ui_window( ui_ctx *ctx, struct ui_window *window, u32 control_group ) ui_new_node( ctx ); { - ui_capture_mouse( ctx, __COUNTER__ ); + ui_capture_mouse( ctx, ctx->control_id ++ ); /* Drag bar */ ctx->cursor[3] = 25; ui_new_node( ctx ); { - ui_capture_mouse( ctx, __COUNTER__ ); + ui_capture_mouse( ctx, ctx->control_id ++ ); struct ui_vert *drag_bar = ui_fill_rect( ctx, ctx->cursor, 0xff555555 ); @@ -798,7 +792,7 @@ static int ui_window( ui_ctx *ctx, struct ui_window *window, u32 control_group ) ui_align_top( ctx ); ui_rect_pad( ctx->cursor, 4 ); - if( ui_button( ctx, __COUNTER__ ) ) + if( ui_button( ctx ) ) { vg_info( "Click clacked\n" ); } @@ -870,12 +864,9 @@ static void ui_slider( ui_ctx *ctx, struct ui_slider *slider ) ctx->cursor[2] = fwidth; ctx->cursor[0] = slider_start + fpos * fmove; - /* TODO.. */ - u32 uid = (u32)(u64)slider->data; - int status = ui_button( ctx, uid ); - - if( ctx->capture_lock && - (ctx->capture_mouse_id == ui_group_id( ctx, uid ))) + u32 uid = ctx->control_id ++; + int status = ui_button( ctx ); + if( ctx->capture_lock && (ctx->capture_mouse_id == uid)) { float ui_new = ctx->mouse[0], local = ui_new - (slider_start + fstart), @@ -891,7 +882,6 @@ static void ui_slider( ui_ctx *ctx, struct ui_slider *slider ) snprintf( buf, 12, "%.2f", *slider->data ); ui_text( ctx, ctx->cursor, buf, 1, 0 ); ui_end_down( ctx ); - ui_end_down( ctx ); } @@ -908,8 +898,7 @@ static void ui_slider_vector( ui_ctx *ctx, struct ui_slider_vector *slider ) static void ui_checkbox( ui_ctx *ctx, struct ui_checkbox *cb ) { - u32 uid = (u32)(u64)cb->data; - if( ui_button(ctx,uid) == k_button_click ) + if( ui_button(ctx) == k_button_click ) *cb->data ^= 0x1; ui_new_node(ctx); @@ -938,7 +927,6 @@ static void ui_checkbox( ui_ctx *ctx, struct ui_checkbox *cb ) #define gui_align_top() ui_align_top( &ui_global_ctx ) #define gui_align_left() ui_align_left( &ui_global_ctx ) #define gui_clamp_rect(...) ui_clamp_rect( &ui_global_ctx, __VA_ARGS__) -#define gui_group_id(...) ui_group_id( &ui_global_ctx, __VA_ARGS__) #define gui_capture_mouse(...) ui_capture_mouse( &ui_global_ctx, __VA_ARGS__) #define gui_set_clip(...) ui_set_clip( &ui_global_ctx, __VA_ARGS__) #define gui_release_clip() ui_release_clip( &ui_global_ctx ) diff --git a/vg_build.sh b/vg_build.sh new file mode 100644 index 0000000..9ea7867 --- /dev/null +++ b/vg_build.sh @@ -0,0 +1,85 @@ +#!/bin/bash +# Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved + +# Util +# ============================================================================== +error(){ + echo -e "\033[1;31mError:\e[0m $@" + exit 1 +} + +warning(){ + echo -e "\033[1;33mWarning:\e[0m $@" +} + +success(){ + echo -e "\033[1;32mSuccess:\e[0m $@" +} + +logit(){ + echo -e "\033[0;37m$@\e[0m" +} + +titleit(){ + echo "" + echo -e "\033[1;35m$@\e[0m" + echo "================================================================" + echo "" +} + +titleit " vg_build.sh ver: 2.0\n" + +# Compile shit +# ============================================================================== + +compiler_cache="ccache" + +# Autodetect ccache unavailible +if ! [ -x "$( command -v $compiler_cache )" ]; then + compiler_cache="" +fi + +compile_x(){ + mkdir $_folder -p + + cmd="$compiler_cache $_compiler + $_options + $_warnings + $_include + $_library + $_src + -o $_folder/$_dst$_ext + $_link + $_epilogue" + + logit " $cmd\n" + $cmd + + if [ $? -ne 0 ]; then + error "compiler failed" + fi + + success "Compiled item\n" +} + +# Tools scripts +# ============================================================================== +enable_tools=false + +vg_compile_tools() { + if [ $enable_tools = true ]; then source vg/src/tools.sh; fi +} + +tools() { + enable_tools=true +} + +$1 +$2 +$3 +$4 +$5 +$6 +$7 +$8 +$9