diff --git a/.fpccfg b/.fpccfg new file mode 100644 index 0000000..0857ebb --- /dev/null +++ b/.fpccfg @@ -0,0 +1,2 @@ +[wasm32-unknown-wasi] +sysroot = "/home/kotofyt/Downloads/wasi-sysroot-29.0/" diff --git a/.gitmodules b/.gitmodules index be52a84..d429b95 100644 --- a/.gitmodules +++ b/.gitmodules @@ -28,3 +28,6 @@ [submodule "external/xtool"] path = external/xtool url = https://github.com/xtool-org/xtool.git +[submodule "external/funnystdlib"] + path = external/funnystdlib + url = https://github.com/KoT3isGood/funnystdlib.git diff --git a/appleauth/auth.cpp b/appleauth/auth.cpp deleted file mode 100644 index e6d8f81..0000000 --- a/appleauth/auth.cpp +++ /dev/null @@ -1,640 +0,0 @@ -#include "appleauth/iauth.h" -#include "tier2/fileformats/plist.h" -#include "http/http.h" -#include "openssl/srp.h" -#include "openssl/evp.h" -#include "openssl/sha.h" -#include "tier0/rand.h" - -IHTTPClientManager *g_pHttpClientMgr = NULL; -static int base64_decode(const char *b64, unsigned char *pOut) { - int len = strlen(b64); - if (pOut == NULL) - return (len*3)/4; - int out_len = EVP_DecodeBlock(pOut, - (const unsigned char *)b64, - len); - if (out_len < 0) - return -1; - - while (len > 0 && b64[len - 1] == '=') { - out_len--; - len--; - } - - return out_len; -} - -// autogenerated -#define APPLE_LOCAL_USER "e2e70285da39596ef06153b9c4e1e5dc8d2f983bc5cd63f5b1e292207060d931" -#define APPLE_HTTP_HEADER \ -{ \ - {"X-Apple-I-Client-Time", "2026-1-9T12:00:00"}, \ - {"X-Apple-Locale", "en_US"}, \ - {"X-Apple-I-TimeZone", "Europe/Kyiv"}, \ - {"X-Mme-Client-Info", " "}, \ - {"User-Agent", "akd/1.0 CFNetwork/808.1.4"}, \ - {"X-Apple-I-MD-LU", APPLE_LOCAL_USER}, \ - {"X-Apple-I-MD-M", "0"}, \ - {"X-Apple-I-SRL-NO", "0"}, \ - {"X-Mme-Device-Id", "0"}, \ - {"Content-Type", "text/x-xml-plist"}, \ - {"Accept", "*/*"}, \ -}; - -#define N2048 "AC6BDB41324A9A9BF166DE5E1389582FAF72B6651987EE07FC3192943DB56050A37329CBB4A099ED8193E0757767A13DD52312AB4B03310DCD7F48A9DA04FD50E8083969EDB767B0CF6095179A163AB3661A05FBD5FAAAE82918A9962F0B93B855F97993EC975EEAA80D740ADBF4FF747359D041D5C33EA71D281E446B14773BCA97B43A23FB801676BD207A436C6481F1D2B9078717461A5B9D32E688F87748544523B524B0D57D5EA77A2775D2ECFA032CFBDBF52FB3786160279004E57AE6AF874E7303CE53299CCC041C7BC308D82A5698F3A8D0C38271AE35F8E9DBFBB694B5C803D89F7AE435DE236D525F54759B65E372FCD68EF20FA7111F9E4AFF73" -#define G2048 "2" -enum EPasswordType -{ - PASSWORD_TYPE_S2K, - PASSWORD_TYPE_S2K_FO, -}; - -class CAppleAuth: public IAppleAuth -{ -public: - virtual void Init() override; - virtual void Shutdown() override; - virtual void LaunchLoginDaemon() override; - virtual EAppleAuthDaemonStatus GetStatus() override; - virtual EAppleAuthStatus SubmitLoginData( const char *szEmail, const char *szPassword ) override; - virtual EAppleAuthStatus Submit2FA( const char *szCode ) override; - virtual CUtlString EncryptPassword( const char *szPassword, CUtlString szSalt, uint32_t uIters, EPasswordType eType ); - void ComputeM1( unsigned char M1[SHA256_DIGEST_LENGTH], const BIGNUM *N, const BIGNUM *g, const char *username, const char *password, const unsigned char *salt, size_t salt_len, const BIGNUM *A, const BIGNUM *B, const BIGNUM *a ); - - CUtlString FetchADIPB(); - void FetchHeaders( CUtlString szAdiPb ); - - IHTTPClient *m_pANIClient; - IHTTPClient *m_pGrandSlamClient; - - CUtlString m_szProvisionStart = "/grandslam/MidService/startMachineProvisioning"; - CUtlString m_szProvisionFinish = "/grandslam/MidService/finishMachineProvisioning"; - IJSONObject *pHeader; - - CUtlString m_szAppleIMD; - CUtlString m_szAppleIMDM; - CUtlString m_szAppleIMDRINFO; - -}; - -CUtlString CAppleAuth::FetchADIPB() -{ - - CUtlString szProvisionExpectedInputRaw = NULL; - IJSONObject *pObject = NULL; - IJSONObject *pPlistObject = NULL; - CUtlString szProvisionExpectedInput = NULL; - CUtlString szAdiPb = NULL; - - m_pANIClient = g_pHttpClientMgr->Connect("ani.sidestore.io", true, NULL); - - { - HTTPHeaderParam_t params[] = APPLE_HTTP_HEADER; - HTTPHeader_t header = { - sizeof(params)/sizeof(HTTPHeaderParam_t), - params, - }; - m_pGrandSlamClient->Get("/grandslam/GsService2/lookup", &header); - HTTPResponse_t r = m_pGrandSlamClient->GetResponse(); - if ( r.m_uCode != 200 ) - { - g_pHttpClientMgr->Disconnect(m_pANIClient); - return NULL; - } - } - - if ( !m_pANIClient->WebSocket_Connect("/v3/provisioning_session") ) - Plat_FatalErrorFunc("Failed to init AppleAuth websocket\n"); - - // Getting adipb - while ( ( szProvisionExpectedInputRaw = m_pANIClient->WebSocket_RecvText() ) != NULL ) - { - pObject = JSONManager()->ReadString(szProvisionExpectedInputRaw); - szProvisionExpectedInput = pObject->GetValue("result")->GetStringValue(); - V_printf("%s\n",szProvisionExpectedInput.GetString()); - if ( szProvisionExpectedInput == "GiveIdentifier" ) - { - m_pANIClient->WebSocket_SendText("{\"identifier\": \"" APPLE_LOCAL_USER "\"}"); - continue; - } - if ( szProvisionExpectedInput == "GiveStartProvisioningData" ) - { - const char *plist = - "\n" - "\n" - "\n" - "\n" - "\tHeader\n" - "\t\n" - "\tRequest\n" - "\t\n" - "\n" - "\n"; - - HTTPHeaderParam_t params[] = APPLE_HTTP_HEADER; - HTTPHeader_t header = { - sizeof(params)/sizeof(HTTPHeaderParam_t), - params, - }; - m_pGrandSlamClient->Post(m_szProvisionStart, &header, V_strlen(plist), plist); - HTTPResponse_t r = m_pGrandSlamClient->GetResponse(); - if ( r.m_uCode != 200 ) - { - g_pHttpClientMgr->Disconnect(m_pANIClient); - return NULL; - } - IJSONObject *pObject = PropertyListManager()->ReadString(r.m_message); - CUtlString spim = pObject->GetValue("Response")->GetObject()->GetValue("spim")->GetStringValue(); - m_pANIClient->WebSocket_SendText(CUtlString("{\"spim\": \"%s\"}", spim.GetString())); - - continue; - } - if ( szProvisionExpectedInput == "GiveEndProvisioningData" ) - { - CUtlString cpim = pObject->GetValue("cpim")->GetStringValue(); - - CUtlString plist = CUtlString( - "\n" - "\n" - "\n" - "\n" - "\tHeader\n" - "\t\n" - "\tRequest\n" - "\t\n" - "\tcpim\n" - "\t%s\n" - "\t\n" - "\n" - "\n", cpim.GetString()); - - HTTPHeaderParam_t params[] = APPLE_HTTP_HEADER; - HTTPHeader_t header = { - sizeof(params)/sizeof(HTTPHeaderParam_t), - params, - }; - m_pGrandSlamClient->Post(m_szProvisionFinish, &header, V_strlen(plist), plist); - HTTPResponse_t r = m_pGrandSlamClient->GetResponse(); - if ( r.m_uCode != 200 ) - { - g_pHttpClientMgr->Disconnect(m_pANIClient); - return NULL; - } - IJSONObject *pObject = PropertyListManager()->ReadString(r.m_message); - CUtlString tk = pObject->GetValue("Response")->GetObject()->GetValue("tk")->GetStringValue(); - CUtlString ptm = pObject->GetValue("Response")->GetObject()->GetValue("ptm")->GetStringValue(); - - V_printf("%s\n",CUtlString("{\"tk\": \"%s\", \"ptm\": \"%s\"}", tk.GetString(), ptm.GetString()).GetString()); - m_pANIClient->WebSocket_SendText(CUtlString("{\"tk\": \"%s\", \"ptm\": \"%s\"}", tk.GetString(), ptm.GetString())); - - continue; - } - if ( szProvisionExpectedInput == "ProvisioningSuccess" ) - { - szAdiPb = pObject->GetValue("adi_pb")->GetStringValue(); - g_pHttpClientMgr->Disconnect(m_pANIClient); - break; - } - if ( szProvisionExpectedInput == "Timeout" ) - { - break; - } - g_pHttpClientMgr->Disconnect(m_pANIClient); - return NULL; - } - g_pHttpClientMgr->Disconnect(m_pANIClient); - return szAdiPb; -} -void CAppleAuth::FetchHeaders( CUtlString szAdiPb ) -{ - // Get header - HTTPHeaderParam_t params[] = { - "Content-Type", "application/json", - }; - HTTPHeader_t header = { - sizeof(params)/sizeof(HTTPHeaderParam_t), - params, - }; - m_pANIClient = g_pHttpClientMgr->Connect("ani.sidestore.io", true, NULL); - CUtlString szPostData = CUtlString("{\"identifier\": \"" APPLE_LOCAL_USER "\", \"adi_pb\": \"%s\"}", szAdiPb.GetString()); - V_printf("%s\n",szPostData.GetString()); - m_pANIClient->Post("/v3/get_headers", &header, V_strlen(szPostData), szPostData); - HTTPResponse_t r = m_pANIClient->GetResponse(); - V_printf("%i\n",r.m_uCode); - if ( r.m_uCode == 200 ) - { - V_printf("%s\n",r.m_message.GetMemory()); - pHeader = JSONManager()->ReadString(r.m_message); - m_szAppleIMD = pHeader->GetValue("X-Apple-I-MD")->GetStringValue(); - m_szAppleIMDM = pHeader->GetValue("X-Apple-I-MD-M")->GetStringValue(); - m_szAppleIMDRINFO = pHeader->GetValue("X-Apple-I-MD-RINFO")->GetStringValue(); - JSONManager()->FreeObject(pHeader); - } - g_pHttpClientMgr->Disconnect(m_pANIClient); -} - -void CAppleAuth::Init() -{ - CreateInterfaceFn fnHttpFactory = Sys_GetFactory("funnyhttp"); - - g_pHttpClientMgr = (IHTTPClientManager*)fnHttpFactory(HTTP_CLIENT_INTERFACE_VERSION, NULL); - - m_pGrandSlamClient = g_pHttpClientMgr->Connect("gsa.apple.com", true, NULL); - - CUtlString szAdiPb = FetchADIPB(); - FetchHeaders(szAdiPb); - - - -} - -void CAppleAuth::Shutdown() -{ - -} - -void CAppleAuth::LaunchLoginDaemon() -{ - - -} - -EAppleAuthDaemonStatus CAppleAuth::GetStatus() -{ - return APPLE_AUTH_DAEMON_NOT_LOGGED_IN; -} - - -EAppleAuthStatus CAppleAuth::SubmitLoginData( const char *szEmail, const char *szPassword ) -{ - const char *pszUser = szEmail; - const char *pszPass = szPassword; - - BIGNUM* pN = BN_new(); - BIGNUM* pG = BN_new(); - BIGNUM* pa = BN_new(); - BIGNUM* pA = BN_new(); - BN_CTX *pbnCtx = BN_CTX_new(); - - SHA256_CTX pSha; - unsigned char pK[SHA256_DIGEST_LENGTH]; - BN_hex2bn(&pN, N2048); - BN_hex2bn(&pG, G2048); - CUtlBuffer bN; - CUtlBuffer bG; - bN = CUtlBuffer(BN_num_bytes(pN)); - bG = CUtlBuffer(BN_num_bytes(pG)); - BN_bn2bin(pN, bN.GetMemory()); - SHA256_Init(&pSha); - SHA256_Update(&pSha, bN.GetMemory(), bN.GetSize()); - SHA256_Update(&pSha, bG.GetMemory(), bG.GetSize()); - SHA256_Final(pK, &pSha); - - BN_rand(pa, 256, 0, 0); - BN_set_flags(pa, BN_FLG_CONSTTIME); - BN_mod_exp(pA, pG, pa, pN, pbnCtx); - - char *pszA = BN_bn2hex(pA); - - CUtlString plist = CUtlString( - "\n" - "\n" - "\n" - "\n" - "\tHeader\n" - "\t\n" - "\tVersion\n" - "\t1.0.1\n" - "\t\n" - - "\tRequest\n" - "\t\n" - - "\tA2k\n" - "\t%s\n" - - "\tps\n" - "\ts2ks2k_fo\n" - - "\tu\n" - "\t%s\n" - - "\to\n" - "\tinit\n" - - "\tcpd\n" - "\t\n" - - "\tX-Apple-I-Client-Time\n" - "\t2026-1-9T12:00:00Z\n" - "\tX-Apple-I-MD\n" - "\t%s\n" - "\tX-Apple-I-MD-LU\n" - "\t" APPLE_LOCAL_USER "\n" - "\tX-Apple-I-MD-M\n" - "\t%s\n" - "\tX-Apple-I-MD-RINFO\n" - "\t%s\n" - "\tX-Mme-Client-Info\n" - "\t<MacBookPro13,2> <macOS;13.1;22C65> <com.apple.AuthKit/1 (com.apple.dt.Xcode/3594.4.19)>\n" - "\tX-Apple-I-SRL-NO\n" - "\t0\n" - - - "\tbootstrap\n" - "\t\n" - - "\ticscrec\n" - "\t\n" - - - "\tpbe\n" - "\t\n" - - "\tprkgen\n" - "\t\n" - - "\tsvct\n" - "\tiCloud\n" - - "\tloc\n" - "\ten_US\n" - - "\t\n" - - "\t\n" - "\n" - "\n", pszA, szEmail, m_szAppleIMD.GetString(), m_szAppleIMDM.GetString(), m_szAppleIMDRINFO.GetString()); - HTTPHeaderParam_t params[] = { - {"Content-Type", "text/x-xml-plist"}, - {"Accept", "*/*"}, - {"User-Agent", "akd/1.0 CFNetwork/808.1.4"}, \ - {"X-Mme-Client-Info", " "}, \ - }; - HTTPHeader_t header = { - sizeof(params)/sizeof(HTTPHeaderParam_t), - params, - }; - V_printf("%s\n",plist.GetString()); - m_pGrandSlamClient->Post("/grandslam/GsService2", &header, plist.GetLenght(), plist); - HTTPResponse_t stResponse = m_pGrandSlamClient->GetResponse(); - V_printf("%i %i\n", stResponse.m_uCode, stResponse.m_bIsComplete); - if (stResponse.m_uCode != 200) - return APPLE_AUTH_FAILURE; - V_printf("%s\n",stResponse.m_message.GetMemory()); - IJSONObject *pObject = PropertyListManager()->ReadString(stResponse.m_message); - IJSONObject *pResponse = pObject->GetValue("Response")->GetObject(); - CUtlString szEncryptedPassword = EncryptPassword(szPassword, pResponse->GetValue("s")->GetStringValue(), pResponse->GetValue("i")->GetNumberValue(), PASSWORD_TYPE_S2K); - const char *szSalt = pResponse->GetValue("s")->GetStringValue(); - const char *szB = pResponse->GetValue("B")->GetStringValue(); - unsigned char salt[32]; - int iSaltLen = base64_decode(szSalt, salt); - - int iBLen = base64_decode(szB, NULL); - CUtlBuffer BBuffer = CUtlBuffer(iBLen); - iBLen = base64_decode(szB, BBuffer.GetMemory()); - BIGNUM *pB = BN_bin2bn(BBuffer.GetMemory(), BBuffer.GetSize(), NULL); - unsigned char M1[SHA256_DIGEST_LENGTH]; - ComputeM1(M1, pN, pG, szEmail, szPassword, salt, iSaltLen, pA, pB, pa); - - CUtlString szM1 = {}; - for ( int i = 0; i < SHA256_DIGEST_LENGTH; i++ ) - { - szM1.AppendTail(CUtlString("%02x", M1[i])); - } - - plist = CUtlString( - "\n" - "\n" - "\n" - "\n" - "\tHeader\n" - "\t\n" - "\tVersion\n" - "\t1.0.1\n" - "\t\n" - - "\tRequest\n" - "\t\n" - - "\tM1\n" - "\t%s\n" - - "\tc\n" - "\t%s\n" - - "\tps\n" - "\ts2ks2k_fo\n" - - "\tu\n" - "\t%s\n" - - "\to\n" - "\tcomplete\n" - - "\tcpd\n" - "\t\n" - - "\tX-Apple-I-Client-Time\n" - "\t2026-1-9T12:00:00Z\n" - "\tX-Apple-I-MD\n" - "\t%s\n" - "\tX-Apple-I-MD-LU\n" - "\t" APPLE_LOCAL_USER "\n" - "\tX-Apple-I-MD-M\n" - "\t%s\n" - "\tX-Apple-I-MD-RINFO\n" - "\t%s\n" - "\tX-Mme-Client-Info\n" - "\t<MacBookPro13,2> <macOS;13.1;22C65> <com.apple.AuthKit/1 (com.apple.dt.Xcode/3594.4.19)>\n" - "\tX-Apple-I-SRL-NO\n" - "\t0\n" - - - "\tbootstrap\n" - "\t\n" - - "\ticscrec\n" - "\t\n" - - - "\tpbe\n" - "\t\n" - - "\tprkgen\n" - "\t\n" - - "\tsvct\n" - "\tiCloud\n" - - "\tloc\n" - "\ten_US\n" - - "\t\n" - - "\t\n" - "\n" - "\n", szM1.GetString(), pResponse->GetValue("c")->GetStringValue(), szEmail, m_szAppleIMD.GetString(), m_szAppleIMDM.GetString(), m_szAppleIMDRINFO.GetString()); - V_printf("%s\n", plist.GetString()); - m_pGrandSlamClient->Post("/grandslam/GsService2", &header, plist.GetLenght(), plist); - stResponse = m_pGrandSlamClient->GetResponse(); - V_printf("%i %i\n", stResponse.m_uCode, stResponse.m_bIsComplete); - if (stResponse.m_uCode != 200) - return APPLE_AUTH_FAILURE; - V_printf("%s\n", stResponse.m_message.GetMemory()); - - g_pHttpClientMgr->Disconnect(m_pGrandSlamClient); - - - OPENSSL_free(pszA); - return APPLE_AUTH_SUCCESS; -} - -static void hash_bn_pad(unsigned char out[SHA256_DIGEST_LENGTH], const BIGNUM *bn) -{ - unsigned char buf[256]; - memset(buf, 0, sizeof(buf)); - - int len = BN_num_bytes(bn); - BN_bn2bin(bn, buf + (256 - len)); - - SHA256(buf, 256, out); -} - -void CAppleAuth::ComputeM1( - unsigned char M1[SHA256_DIGEST_LENGTH], - const BIGNUM *N, - const BIGNUM *g, - const char *username, - const char *password, - const unsigned char *salt, size_t salt_len, - const BIGNUM *A, - const BIGNUM *B, - const BIGNUM *a -) -{ - SHA256_CTX ctx; - unsigned char HN[SHA256_DIGEST_LENGTH], Hg[SHA256_DIGEST_LENGTH], HNxorg[SHA256_DIGEST_LENGTH]; - unsigned char HI[SHA256_DIGEST_LENGTH]; - - /* H(N) xor H(g) */ - hash_bn_pad(HN, N); - hash_bn_pad(Hg, g); - for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) - HNxorg[i] = HN[i] ^ Hg[i]; - - /* H(I) */ - SHA256((const unsigned char *)username, strlen(username), HI); - - /* x = H(s || H(I ":" P)) */ - unsigned char inner_hash[SHA256_DIGEST_LENGTH]; - SHA256_Init(&ctx); - SHA256_Update(&ctx, (const unsigned char *)username, strlen(username)); - SHA256_Update(&ctx, (const unsigned char *)":", 1); - SHA256_Update(&ctx, (const unsigned char *)password, strlen(password)); - SHA256_Final(inner_hash, &ctx); - - unsigned char x_hash[SHA256_DIGEST_LENGTH]; - SHA256_Init(&ctx); - SHA256_Update(&ctx, salt, salt_len); - SHA256_Update(&ctx, inner_hash, SHA256_DIGEST_LENGTH); - SHA256_Final(x_hash, &ctx); - - BIGNUM *x = BN_bin2bn(x_hash, SHA256_DIGEST_LENGTH, NULL); - - /* k = H(N || g) */ - unsigned char k_hash[SHA256_DIGEST_LENGTH]; - SHA256_Init(&ctx); - unsigned char bufN[256], bufg[256]; - memset(bufN, 0, 256); BN_bn2bin(N, bufN + (256 - BN_num_bytes(N))); - memset(bufg, 0, 256); BN_bn2bin(g, bufg + (256 - BN_num_bytes(g))); - SHA256_Update(&ctx, bufN, 256); - SHA256_Update(&ctx, bufg, 256); - SHA256_Final(k_hash, &ctx); - BIGNUM *k = BN_bin2bn(k_hash, SHA256_DIGEST_LENGTH, NULL); - - /* u = H(A || B) */ - unsigned char bufA[256], bufB[256], u_hash[SHA256_DIGEST_LENGTH]; - memset(bufA, 0, 256); BN_bn2bin(A, bufA + (256 - BN_num_bytes(A))); - memset(bufB, 0, 256); BN_bn2bin(B, bufB + (256 - BN_num_bytes(B))); - SHA256_Init(&ctx); - SHA256_Update(&ctx, bufA, 256); - SHA256_Update(&ctx, bufB, 256); - SHA256_Final(u_hash, &ctx); - BIGNUM *u = BN_bin2bn(u_hash, SHA256_DIGEST_LENGTH, NULL); - - /* S = (B - k * g^x)^(a + u * x) mod N */ - BN_CTX *bn_ctx = BN_CTX_new(); - BIGNUM *gx = BN_new(), *kgx = BN_new(), *B_sub = BN_new(); - BIGNUM *ux = BN_new(), *exp = BN_new(), *S = BN_new(); - - BN_mod_exp(gx, g, x, N, bn_ctx); /* g^x mod N */ - BN_mod_mul(kgx, k, gx, N, bn_ctx); /* k * g^x mod N */ - BN_mod_sub(B_sub, B, kgx, N, bn_ctx); /* B - k*g^x mod N */ - BN_mul(ux, u, x, bn_ctx); /* u*x */ - BN_add(exp, a, ux); /* a + u*x */ - BN_mod_exp(S, B_sub, exp, N, bn_ctx); /* S */ - - /* K = H(S) */ - unsigned char S_bytes[256]; - memset(S_bytes, 0, 256); - BN_bn2bin(S, S_bytes + (256 - BN_num_bytes(S))); - unsigned char K[SHA256_DIGEST_LENGTH]; - SHA256(S_bytes, 256, K); - - /* Compute M1 */ - SHA256_Init(&ctx); - SHA256_Update(&ctx, HNxorg, SHA256_DIGEST_LENGTH); - SHA256_Update(&ctx, HI, SHA256_DIGEST_LENGTH); - SHA256_Update(&ctx, salt, salt_len); - SHA256_Update(&ctx, bufA, 256); - SHA256_Update(&ctx, bufB, 256); - SHA256_Update(&ctx, K, SHA256_DIGEST_LENGTH); - SHA256_Final(M1, &ctx); - - /* Cleanup */ - BN_free(x); BN_free(k); BN_free(u); - BN_free(gx); BN_free(kgx); BN_free(B_sub); BN_free(ux); BN_free(exp); BN_free(S); - BN_CTX_free(bn_ctx); -} - -EAppleAuthStatus CAppleAuth::Submit2FA( const char *szCode ) -{ - -} -CUtlString CAppleAuth::EncryptPassword( const char *szPassword, CUtlString szSalt, uint32_t uIters, EPasswordType eType ) -{ - - unsigned char hashedPassword[SHA256_DIGEST_LENGTH]; - CUtlString szHashedPasswordHex = ""; - unsigned char encryptedPassword[32]; - CUtlString szEncryptedPasswordHex = ""; - unsigned char salt[32]; - int iSaltLen = base64_decode(szSalt, salt); - - if ( eType == PASSWORD_TYPE_S2K ) - { - for ( int i = 0; i < SHA256_DIGEST_LENGTH; i++ ) - { - szHashedPasswordHex.AppendTail(CUtlString("%02x", hashedPassword[i])); - } - PKCS5_PBKDF2_HMAC(szHashedPasswordHex, szHashedPasswordHex.GetLenght(), salt, iSaltLen, uIters, EVP_sha256(), 32, encryptedPassword); - }; - for ( int i = 0; i < SHA256_DIGEST_LENGTH; i++ ) - { - szEncryptedPasswordHex.AppendTail(CUtlString("%02x", encryptedPassword[i])); - } - V_printf("%s\n",szEncryptedPasswordHex.GetString()); - return szEncryptedPasswordHex; - -} - - -static CAppleAuth s_appleAuth; -EXPOSE_INTERFACE_GLOBALVAR(CAppleAuth, IAppleAuth, APPLE_AUTH_INTERFACE_VERSION, s_appleAuth); - diff --git a/appleauth/build.cpp b/appleauth/build.cpp deleted file mode 100644 index be90437..0000000 --- a/appleauth/build.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "helper.h" -#include "c.h" -#include "ld.h" -#include "tier1/utlstring.h" - -ADD_DEPENDENCY_BUILD_FILE(tier0, "../tier0/build.cpp") -ADD_DEPENDENCY_BUILD_FILE(tier1, "../tier1/build.cpp") -ADD_DEPENDENCY_BUILD_FILE(tier2, "../tier2/build.cpp") -ADD_DEPENDENCY_BUILD_FILE(http, "../http/build.cpp") - -DECLARE_BUILD_STAGE(appleauth) -{ - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - - compileProject.m_szName = "appleauth"; - compileProject.files = { - "auth.cpp" - }; - compileProject.includeDirectories = {"../public"}; - compileProject.bFPIC = true; - ldProject = ccompiler->Compile(&compileProject); - ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier1, "tier1")}); - ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier2, "tier2")}); - ldProject.libraries = { - "crypto", - }; - ldProject.linkType = ELINK_DYNAMIC_LIBRARY; - - CUtlString szOutputProject = linker->Link(&ldProject); - - ADD_OUTPUT_OBJECT("appleauth", szOutputProject) - - return 0; -}; - diff --git a/asmrigs/as/as.cpp b/asmrigs/as/as.cpp deleted file mode 100644 index 16ad5b2..0000000 --- a/asmrigs/as/as.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include "asmrigs/as.h" -#include "tier2/tokenizer.h" -#include "asmrigs/tokenparser.h" - -struct ObjectHeader_t -{ - uint8_t m_magic[4]; - uint32_t m_uSymbolCount; - uint32_t m_uDatasCount; -}; - -enum EDataFlags: uint32_t -{ - DATA_TYPE_DECLARE, - DATA_TYPE_USED, -}; - -struct Data_t -{ - uint64_t m_uDataSize; - uint64_t m_uDataOffsetSize; -}; - -struct Symbol_t -{ - uint32_t m_uName; - uint32_t m_uData; - EDataFlags m_eDataFlags; -}; - -enum EInstruction: uint8_t -{ - I_NOP = 0, - - I_PUSH = 3, - I_POP = 4, - - I_CMP = 5, - - I_JUMP = 6, - I_JZ = 7, - I_JNZ = 8, - I_JG = 9, - I_JGE = 10, - I_JLE = 11, - - I_LOAD = 12, - I_STORE = 13, - I_LOADPTR = 14, - I_STOREPTR = 15, - I_LOADLIT = 16, - - I_JSR = 20, - I_RET = 21, -}; - -CUtlBuffer Assemble( const char *szAssembly, AsOptions_t stOptions ) -{ - CUtlVector externalFunctions; - CUtlVector publicFunctions; - CUtlVector labels; - CUtlVector tokens = Tokenize(szAssembly); - Token_t *pTokens = tokens.GetData(); - for ( int i = 0; i < tokens.GetSize()-2; ) - { - if ( !tokens[i].m_bIsQuoted && tokens[i].m_szValue == "/" ) - if ( !tokens[i+1].m_bIsQuoted && tokens[i+1].m_szValue == "/" ) - if ( !tokens[i+2].m_bIsQuoted && tokens[i+2].m_szValue == "/" ) - { - tokens.RemoveAt(i, 3); - continue; - } - i++; - }; - CTokenParser parser; - parser.m_pTokens = tokens.GetData(); - parser.m_pTokensEnd = tokens.GetData()+tokens.GetSize(); - parser.m_pCurrentToken = tokens.GetData()-1; - parser.Continue(); - - CUtlVector commandStream; - - for (;;) - { - if (parser.IsEOF()) - break; - CUtlString szCommand = parser.PeekToken(); - parser.Continue(); - if ( szCommand == "extrn" ) - { - externalFunctions.AppendTail(parser.PeekToken()); - parser.Continue(); - continue; - } - if ( szCommand == "public" ) - { - publicFunctions.AppendTail(parser.PeekToken()); - parser.Continue(); - continue; - } - if ( szCommand == "store" ) - { - continue; - } - if ( szCommand == "load" ) - { - continue; - } - if ( szCommand == "jsr" ) - { - commandStream.AppendTail(I_JSR); - continue; - } - if ( szCommand == "ret" ) - { - commandStream.AppendTail(I_RET); - continue; - } - if (parser.IsEOF()) - break; - if (!V_strcmp(parser.PeekToken(), ":")) - { - parser.Continue(); - labels.AppendTail(""); - } - else - { - V_printf("%s is not a valid instuction or label\n", szCommand.GetString()); - } - } - return {}; -}; diff --git a/asmrigs/as/main.cpp b/asmrigs/as/main.cpp deleted file mode 100644 index 071aa1d..0000000 --- a/asmrigs/as/main.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "asmrigs/tokenparser.h" -#include "asmrigs/as.h" -#include "tier0/commandline.h" -#include "tier2/ifilesystem.h" -int main( int argc, char **argv ) -{ - CommandLine()->CreateCommandLine(argc, argv); - - CreateInterfaceFn filesystemFactory = Sys_GetFactory("filesystem_std"); - filesystem = (IFileSystem*)filesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL); - - IFileHandle *pFile = filesystem->Open(argv[1], FILEMODE_READ); - const char *szFileContents = filesystem->ReadString(pFile); - filesystem->Close(pFile); - - Assemble(szFileContents, {}); - return 0; -} diff --git a/asmrigs/brb/brb.h b/asmrigs/brb/brb.h deleted file mode 100644 index ee24086..0000000 --- a/asmrigs/brb/brb.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef BRB_H -#define BRB_H - -#include "tier2/tokenizer.h" -#include "tier3/lexer.h" - - -abstract_class IBGenerator -{ -public: - virtual void AddExternSymbol( const char *szName ) = 0; - virtual void DefineFunction( const char *szName ) = 0; - virtual void Load( uint8_t uRegister, int iValue ) = 0; - virtual void Return() = 0; - virtual CUtlString GetAssembly() = 0; -}; - -#define B_GENERATOR_INTERFACE_VERSION "BGenerator001" - -#endif diff --git a/asmrigs/brb/main.cpp b/asmrigs/brb/main.cpp deleted file mode 100644 index cdf6195..0000000 --- a/asmrigs/brb/main.cpp +++ /dev/null @@ -1,395 +0,0 @@ -#include "brb.h" -#include "asmrigs/tokenparser.h" -#include "tier0/commandline.h" -#include "tier2/ifilesystem.h" - -IBGenerator *g_pGenerator; - -class CBGenerator: public IBGenerator -{ -public: - virtual void AddExternSymbol( const char *szName ) override; - virtual void DefineFunction( const char *szName ) override; - virtual CUtlString GetAssembly() override; - CUtlVector m_externalSymbols; - CUtlString m_szAssembly; -}; -EXPOSE_INTERFACE(CBGenerator, IBGenerator, B_GENERATOR_INTERFACE_VERSION); - -void CBGenerator::AddExternSymbol( const char *szName ) -{ - m_externalSymbols.AppendTail(szName); -} - -void CBGenerator::DefineFunction( const char *szName ) -{ - m_szAssembly.AppendTail(CUtlString("public %s\n", szName)); - m_szAssembly.AppendTail(CUtlString("%s:\n", szName)); -} - -CUtlString CBGenerator::GetAssembly() -{ - return m_szAssembly; -} - -void CompileErrorExpectedToken( Token_t *pToken, const char *szToken ) -{ - if (pToken->m_bIsQuoted) - V_printf("%d:%d: expected %s but got string literal\n", pToken->m_iLine, pToken->m_iCharacter, szToken); - else - V_printf("%d:%d: expected %s but got %s\n", pToken->m_iLine, pToken->m_iCharacter, szToken, pToken->m_szValue.GetString()); - exit(1); -} - -void CompileErrorUnexpectedToken( Token_t *pToken ) -{ - if (pToken->m_bIsQuoted) - V_printf("%d:%d: unexpected string literal\n", pToken->m_iLine, pToken->m_iCharacter ); - else - V_printf("%d:%d: unexpected %s\n", pToken->m_iLine, pToken->m_iCharacter, pToken->m_szValue.GetString()); - exit(1); -} -void CompileErrorGotRValue( Token_t *pToken ) -{ - V_printf("%d:%d: got rvalue when expected lvalue\n", pToken->m_iLine, pToken->m_iCharacter ); - exit(1); -} - -enum EBValueType -{ - EBVALUE_TYPE_UNKNOWN, - EBVALUE_TYPE_INT_LITERAL, - EBVALUE_TYPE_VARIABLE, -}; - -struct BValue_t -{ - enum EBValueType m_eType; - int m_iLiteral; - const char *m_szVarName; -}; - -enum EBValueNodeOp -{ - EBVALUE_OP_NOTHING, - EBVALUE_OP_VALUE, - EBVALUE_OP_READ_PTR, - EBVALUE_OP_GET_PTR, - EBVALUE_OP_ADD, - EBVALUE_OP_SUB, - EBVALUE_OP_MUL, - EBVALUE_OP_DIV, - EBVALUE_OP_PARENTHESIS, - EBVALUE_OP_NEG, - EBVALUE_OP_NOT, -}; - -struct Node_t -{ - BValue_t m_value; - struct Node_t *m_pLeftValue; - struct Node_t *m_pRightValue; - EBValueNodeOp m_eOp; -}; - -struct ScopeVariable_t -{ - const char *szName; -}; - - -BValue_t ParseVar( CTokenParser *pParser ) -{ - const char *szToken = pParser->PeekToken(); - - if (V_isdigit(szToken[0])) - { - pParser->Continue(); - return {EBVALUE_TYPE_INT_LITERAL, atoi(szToken)}; - } - pParser->Continue(); - return {EBVALUE_TYPE_VARIABLE, 0, szToken}; -}; -Node_t *ParseExpr( CTokenParser *pParser ); -void ParseRValue( CTokenParser *pParser ); -Node_t *ParsePrimary( CTokenParser *pParser ) -{ - Node_t *pNode; - if (pParser->IsToken("(")) - { - pParser->Continue(); - pNode = ParseExpr(pParser); - if (!pParser->IsToken(")")) - CompileErrorExpectedToken(pParser->m_pCurrentToken, ")"); - pParser->Continue(); - goto lvalue; - } - pNode = new Node_t(); - pNode->m_eOp = EBVALUE_OP_VALUE; - pNode->m_value = ParseVar( pParser ); -lvalue: - if (pParser->IsToken("=")) - { - if (pNode->m_eOp == EBVALUE_OP_VALUE) - { - if ( pNode->m_value.m_eType == EBVALUE_TYPE_VARIABLE ) - goto confirmedlvalue; - }; - CompileErrorGotRValue(pParser->m_pCurrentToken); -confirmedlvalue: - pParser->Continue(); - ParseRValue(pParser); - }; - - return pNode; -} -Node_t *ParseUnary( CTokenParser *pParser ) -{ - return ParsePrimary(pParser); -} -Node_t *ParseTerm( CTokenParser *pParser ) -{ - Node_t *pNode; - Node_t *pNewNode; - - EBValueNodeOp eOp = EBVALUE_OP_NOTHING; - pNode = new Node_t(); - for (;;) - { - if (pParser->IsToken("*")) - { - pParser->Continue(); - eOp = EBVALUE_OP_MUL; - } - else if (pParser->IsToken("/")) - { - pParser->Continue(); - eOp = EBVALUE_OP_DIV; - } - else - { - pNode->m_eOp = eOp; - if (pNode->m_pLeftValue == NULL) - pNode->m_pLeftValue = ParseUnary(pParser); - else - { - if (eOp == EBVALUE_OP_NOTHING) - break; - eOp = EBVALUE_OP_NOTHING; - pNode->m_pRightValue = ParseUnary(pParser); - pNewNode = new Node_t(); - pNewNode->m_pLeftValue = pNode; - pNode = pNewNode; - } - } - } - if (pNode->m_pRightValue == NULL) - { - pNewNode = pNode->m_pLeftValue; - delete pNode; - return pNewNode; - } - return pNode; -} - -Node_t *ParseExpr( CTokenParser *pParser ) -{ - Node_t *pNode; - Node_t *pNewNode; - - EBValueNodeOp eOp = EBVALUE_OP_NOTHING; - pNode = new Node_t(); - for (;;) - { - if (pParser->IsToken("+")) - { - pParser->Continue(); - eOp = EBVALUE_OP_ADD; - } - else if (pParser->IsToken("-")) - { - pParser->Continue(); - eOp = EBVALUE_OP_SUB; - } - else - { - pNode->m_eOp = eOp; - if (pNode->m_pLeftValue == NULL) - pNode->m_pLeftValue = ParseTerm(pParser); - else - { - if (eOp == EBVALUE_OP_NOTHING) - break; - eOp = EBVALUE_OP_NOTHING; - pNode->m_pRightValue = ParseTerm(pParser); - pNewNode = new Node_t(); - pNewNode->m_pLeftValue = pNode; - pNode = pNewNode; - } - } - } - if (pNode->m_pRightValue == NULL) - { - pNewNode = pNode->m_pLeftValue; - delete pNode; - return pNewNode; - } - return pNode; -} - -void PrintExpr( Node_t *pNode ) -{ - if ( pNode->m_eOp == EBVALUE_OP_VALUE ) - { - switch ( pNode->m_value.m_eType ) - { - case EBVALUE_TYPE_INT_LITERAL: - V_printf("%i\n", pNode->m_value.m_iLiteral); - break; - case EBVALUE_TYPE_VARIABLE: - V_printf("%s\n", pNode->m_value.m_szVarName); - break; - - } - } else { - if (pNode->m_pLeftValue) - PrintExpr(pNode->m_pLeftValue); - if (pNode->m_pRightValue) - PrintExpr(pNode->m_pRightValue); - if (pNode->m_eOp == EBVALUE_OP_ADD) - V_printf("+\n"); - if (pNode->m_eOp == EBVALUE_OP_SUB) - V_printf("-\n"); - if (pNode->m_eOp == EBVALUE_OP_MUL) - V_printf("*\n"); - if (pNode->m_eOp == EBVALUE_OP_DIV) - V_printf("/\n"); - } -} - -void ParseRValue( CTokenParser *pParser ) -{ - PrintExpr(ParseExpr( pParser )); -} - -void ParseStatement( CTokenParser *pParser ) -{ - if (pParser->IsToken("return")) - { - pParser->Continue(); - ParseRValue( pParser ); - if (!pParser->IsToken(";")) - CompileErrorExpectedToken(pParser->m_pCurrentToken, ";"); - V_printf(" ret\n"); - pParser->Continue(); - } - else if (pParser->IsToken("extrn")) - { - pParser->Continue(); - for (;;) - { - const char *szName = pParser->PeekToken(); - pParser->Continue(); - if (pParser->IsToken(",")) - { - pParser->Continue(); - continue; - } - if (pParser->IsToken(";")) - { - pParser->Continue(); - break; - } - CompileErrorUnexpectedToken(pParser->m_pCurrentToken); - }; - } - else if (pParser->IsToken("auto")) - { - pParser->Continue(); - for (;;) - { - const char *szName = pParser->PeekToken(); - pParser->Continue(); - if (pParser->IsToken(",")) - { - pParser->Continue(); - continue; - } - if (pParser->IsToken(";")) - { - pParser->Continue(); - break; - } - CompileErrorUnexpectedToken(pParser->m_pCurrentToken); - }; - } - else - { - ParseRValue(pParser); - if (!pParser->IsToken(";")) - CompileErrorExpectedToken(pParser->m_pCurrentToken, ";"); - pParser->Continue(); - }; - -} - -void ParseGlobal( CTokenParser *pParser ) -{ - - for (;;) - { - if (pParser->IsEOF()) - break; - const char *szObjectName = pParser->PeekToken(); - pParser->Continue(); - - if (pParser->IsToken("(")) - { - pParser->Continue(); - if (!pParser->IsToken(")")) - CompileErrorExpectedToken(pParser->m_pCurrentToken, ")"); - pParser->Continue(); - g_pGenerator->DefineFunction(szObjectName); - - if (!pParser->IsToken("{")) - CompileErrorExpectedToken(pParser->m_pCurrentToken, "{"); - pParser->Continue(); - while (!pParser->IsToken("}")) - { - ParseStatement( pParser ); - } - pParser->Continue(); - } - else - { - CompileErrorExpectedToken(pParser->m_pCurrentToken, "("); - } - } - V_printf("%s\n", g_pGenerator->GetAssembly().GetString()); -}; - - -int main( int argc, char **argv ) -{ - CommandLine()->CreateCommandLine(argc, argv); - - CreateInterfaceFn filesystemFactory = Sys_GetFactory("filesystem_std"); - filesystem = (IFileSystem*)filesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL); - - IFileHandle *pFile = filesystem->Open(argv[1], FILEMODE_READ); - const char *szFileContents = filesystem->ReadString(pFile); - filesystem->Close(pFile); - - g_pGenerator = (IBGenerator*)CreateInterface(B_GENERATOR_INTERFACE_VERSION, NULL); - - - CUtlVector tokens = Tokenize(szFileContents); - CTokenParser parser; - parser.m_pTokens = tokens.GetData(); - parser.m_pTokensEnd = tokens.GetData()+tokens.GetSize(); - parser.m_pCurrentToken = tokens.GetData()-1; - parser.Continue(); - ParseGlobal(&parser); - - V_free((void*)szFileContents); -} diff --git a/asmrigs/build.cpp b/asmrigs/build.cpp deleted file mode 100644 index 6e30724..0000000 --- a/asmrigs/build.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "c.h" -#include "ld.h" -#include "helper.h" - -ADD_DEPENDENCY_BUILD_FILE(tier0, "../tier0/build.cpp") -ADD_DEPENDENCY_BUILD_FILE(tier1, "../tier1/build.cpp") -ADD_DEPENDENCY_BUILD_FILE(tier2, "../tier2/build.cpp") -ADD_DEPENDENCY_BUILD_FILE(fs, "../stdfilesystems/build.cpp") - - -DECLARE_BUILD_STAGE(libbras) -{ - CProject_t stProject = {}; - LinkProject_t stLink = {}; - CUtlString szBuiltFile = {}; - - stProject.m_szName = "bras"; - stProject.files = { - "as/as.cpp", - }; - stProject.includeDirectories = { - "../public" - }; - - stLink = ccompiler->Compile(&stProject); - stLink.linkType = ELINK_STATIC_LIBRARY; - stLink.libraryObjects = { - GET_PROJECT_LIBRARY(tier0, "tier0"), - GET_PROJECT_LIBRARY(tier1, "tier1"), - GET_PROJECT_LIBRARY(tier2, "tier2"), - }; - szBuiltFile = linker->Link(&stLink); - ADD_OUTPUT_OBJECT("bras", szBuiltFile); - - return 0; -}; - -DECLARE_BUILD_STAGE(bras) -{ - CProject_t stProject = {}; - LinkProject_t stLink = {}; - CUtlString szBuiltFile = {}; - - stProject.m_szName = "bras"; - stProject.files = { - "as/main.cpp", - }; - stProject.includeDirectories = { - "../public" - }; - - stLink = ccompiler->Compile(&stProject); - stLink.libraryObjects = { - GET_PROJECT_LIBRARY(libbras, "bras"), - GET_PROJECT_LIBRARY(tier0, "tier0"), - GET_PROJECT_LIBRARY(tier1, "tier1"), - GET_PROJECT_LIBRARY(tier2, "tier2"), - }; - szBuiltFile = linker->Link(&stLink); - ADD_OUTPUT_OBJECT("bras", szBuiltFile); - - return 0; -}; - -DECLARE_BUILD_STAGE(brb) -{ - CProject_t stProject = {}; - LinkProject_t stLink = {}; - CUtlString szBuiltFile = {}; - - stProject.m_szName = "bc"; - stProject.files = { - "brb/main.cpp", - }; - stProject.includeDirectories = { - "../public" - }; - - stLink = ccompiler->Compile(&stProject); - stLink.libraryObjects = { - GET_PROJECT_LIBRARY(libbras, "bras"), - GET_PROJECT_LIBRARY(tier0, "tier0"), - GET_PROJECT_LIBRARY(tier1, "tier1"), - GET_PROJECT_LIBRARY(tier2, "tier2"), - }; - szBuiltFile = linker->Link(&stLink); - ADD_OUTPUT_OBJECT("bc", szBuiltFile); - - return 0; -}; - -DECLARE_BUILD_STAGE(install) -{ - CUtlString szBuildOutput = CUtlString("build/%s", Target_t::DefaultTarget().GetTriplet().GetString()); - filesystem2->MakeDirectory(szBuildOutput); - filesystem2->CopyFile(szBuildOutput, GET_PROJECT_OBJECT(brb, "bc")); - filesystem2->CopyFile(szBuildOutput, GET_PROJECT_OBJECT(bras, "bras")); - filesystem2->CopyFile(szBuildOutput, GET_PROJECT_LIBRARY(tier0, "tier0")); - filesystem2->CopyFile(szBuildOutput, GET_PROJECT_LIBRARY(filesystem_std, "fs")); - return 0; -} diff --git a/asmrigs/libbr/Makefile b/asmrigs/libbr/Makefile deleted file mode 100644 index e69de29..0000000 diff --git a/asmrigs/libbr/math.s b/asmrigs/libbr/math.s deleted file mode 100644 index d61e6ce..0000000 --- a/asmrigs/libbr/math.s +++ /dev/null @@ -1,26 +0,0 @@ -public min -min: - pop b - pop c - min a, b, c - ret - -public max -max: - pop b - pop c - max a, b, c - ret - -public abs -abs: - pop b - abs a, b, c - ret - -public sign -sign: - pop b - sign a, b - ret - diff --git a/asmrigs/tests/001.b b/asmrigs/tests/001.b deleted file mode 100644 index 47fcd70..0000000 --- a/asmrigs/tests/001.b +++ /dev/null @@ -1,4 +0,0 @@ -_tick() -{ - -} diff --git a/asmrigs/tests/001.s b/asmrigs/tests/001.s deleted file mode 100644 index 564452e..0000000 --- a/asmrigs/tests/001.s +++ /dev/null @@ -1,3 +0,0 @@ -public _tick -_tick: - ret diff --git a/asmrigs/tests/002.b b/asmrigs/tests/002.b deleted file mode 100644 index 34bea15..0000000 --- a/asmrigs/tests/002.b +++ /dev/null @@ -1,5 +0,0 @@ -_tick() -{ - extrn a; - a = 30; -} diff --git a/asmrigs/tests/002.s b/asmrigs/tests/002.s deleted file mode 100644 index 564452e..0000000 --- a/asmrigs/tests/002.s +++ /dev/null @@ -1,3 +0,0 @@ -public _tick -_tick: - ret diff --git a/asmrigs/tests/003.b b/asmrigs/tests/003.b deleted file mode 100644 index 203337e..0000000 --- a/asmrigs/tests/003.b +++ /dev/null @@ -1,5 +0,0 @@ -_tick() -{ - extrn a; - a = 1 + 2 * 3 * ( 4 + 5 ); -} diff --git a/asmrigs/tests/004.b b/asmrigs/tests/004.b deleted file mode 100644 index 65dec45..0000000 --- a/asmrigs/tests/004.b +++ /dev/null @@ -1,8 +0,0 @@ -main() -{ - extrn something; - auto a, b; - a = 10; - b = a + 5; - return b; -} diff --git a/asmrigs/tests/005.b b/asmrigs/tests/005.b deleted file mode 100644 index d562b56..0000000 --- a/asmrigs/tests/005.b +++ /dev/null @@ -1,9 +0,0 @@ -add(a,b) -{ - return a + b; -} - -main() -{ - return add(2,3); -} diff --git a/brv/brv.h b/brv/brv.h deleted file mode 100644 index e69de29..0000000 diff --git a/brv/build.cpp b/brv/build.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/brv/cbrv.h b/brv/cbrv.h deleted file mode 100644 index e69de29..0000000 diff --git a/brv/modern.cpp b/brv/modern.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/build.cpp b/build.cpp index 09df40a..6bbfab3 100755 --- a/build.cpp +++ b/build.cpp @@ -2,88 +2,26 @@ #include "helper.h" #include "tier1/utlstring.h" - -CUtlVector all_IncludeDirectories = { - "public", - "external", - "external/Vulkan-Headers/include", - "external/Vulkan-Utility-Libraries/include", - "external/volk", - "external/cglm/include", - "external/stb", - "external/SDL/include", - "external/steamworks/public", - "external/GameNetworkingSockets/include", -}; - auto szTarget = Target_t::DefaultTarget().GetTriplet(); -auto szOutputDir = CUtlString("build/funnygame/%s/game",szTarget.GetString()); +auto szOutputDir = CUtlString("build/funnygame/%s/game", szTarget.GetString()); -bool bStaticBuild = false; -bool bSteam = false; -CUtlString steam_lib; +ADD_DEPENDENCY_BUILD_FILE(launcher, "launcher/build.cpp"); +ADD_DEPENDENCY_BUILD_FILE(engine, "engine/build.cpp"); +ADD_DEPENDENCY_BUILD_FILE(ms, "materialsystem/build.cpp"); +ADD_DEPENDENCY_BUILD_FILE(fs, "external/funnystdlib/stdfilesystems/build.cpp"); +ADD_DEPENDENCY_BUILD_FILE(tier0, "external/funnystdlib/tier0/build.cpp"); -extern "C" void Preinit() +DECLARE_BUILD_STAGE(install) { - if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_IOS || Target_t::DefaultTarget().kernel == TARGET_KERNEL_WINDOWS) + filesystem2->MakeDirectory(szOutputDir); + filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(launcher, "launcher")); + filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(engine, "engine")); + filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(MaterialSystem, "MaterialSystem")); + filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(RenderSystemVulkan, "RenderSystemVulkan")); + filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(tier0, "tier0")); + filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(filesystem_std, "fs")); + if (Target_t::DefaultTarget().kernel & TARGET_KERNEL_WINDOWS_DEVICES) { - bStaticBuild = true; } - - if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_IOS || Target_t::DefaultTarget().kernel == TARGET_KERNEL_DARWIN) - { - all_IncludeDirectories.AppendTail("external/metal-cpp"); - } else { - all_IncludeDirectories.AppendTail("external/Vulkan-Headers/include"); - all_IncludeDirectories.AppendTail("external/VulkanMemoryAllocator/include"); - } - switch ( Target_t::DefaultTarget().kernel ) - { - case TARGET_KERNEL_WINDOWS: - bSteam = true; - steam_lib = "external/steamworks/redistributable_bin/win64/steam_api64.dll"; - break; - case TARGET_KERNEL_LINUX: - bSteam = true; - steam_lib = "external/steamworks/redistributable_bin/linux64/libsteam_api.so"; - break; - case TARGET_KERNEL_DARWIN: - bSteam = true; - break; - default: - break; - } - if (bSteam) - { - if (bStaticBuild) - { - filesystem2->MakeDirectory(CUtlString("%s/bin", szOutputDir.GetString())); - filesystem2->CopyFile(CUtlString("%s/bin", szOutputDir.GetString()), steam_lib); - } else - { - filesystem2->MakeDirectory(CUtlString("%s/bin", szOutputDir.GetString())); - filesystem2->CopyFile(CUtlString("%s/bin", szOutputDir.GetString()), steam_lib); - } - } -}; - -CUtlString tier0_lib; -CUtlString engine_lib; -CUtlString server_lib; -CUtlString client_lib; - -#include "tier0/__build.cpp" -#include "tier1/__build.cpp" -#include "tier2/__build.cpp" - -#include "game/server/__build.cpp" -#include "game/client/__build.cpp" - -#include "materialsystem/__build.cpp" - -#include "rapier/__build.cpp" -#include "engine/__build.cpp" -#include "shadercompiler/__build.cpp" - -#include "launcher/__build.cpp" -#include "funnyassets/__build.cpp" + return 0; +} diff --git a/engine/__build.cpp b/engine/__build.cpp index 3c3eb22..14b95e8 100644 --- a/engine/__build.cpp +++ b/engine/__build.cpp @@ -2,7 +2,6 @@ #include "c.h" #include "ld.h" #include "tier1/utlstring.h" -#include "tier1/commandline.h" CUtlVector engine_CompiledFiles = { "engine/engine.cpp", @@ -27,10 +26,11 @@ DECLARE_BUILD_STAGE(engine) compileProject.m_szName = "engine"; compileProject.files = engine_CompiledFiles; - compileProject.includeDirectories = all_IncludeDirectories; + compileProject.includeDirectories = {"public"}; compileProject.bFPIC = true; ldProject = ccompiler->Compile(&compileProject); + /* if (bStaticBuild) ldProject.linkType = ELINK_STATIC_LIBRARY; else @@ -41,20 +41,25 @@ DECLARE_BUILD_STAGE(engine) ldProject.objects.AppendTail((Object_t){material_lib}); if (bSteam) ldProject.objects.AppendTail((Object_t){steam_lib}); - ldProject.linkType = ELINK_DYNAMIC_LIBRARY; } + */ + ldProject.linkType = ELINK_DYNAMIC_LIBRARY; ldProject.libraries = engine_Libraries; - CUtlString outputProject = linker->Link(&ldProject); + CUtlString szOutputDir = linker->Link(&ldProject); + /* if (!bStaticBuild) { + */ filesystem2->MakeDirectory(CUtlString("%s/bin",szOutputDir.GetString())); - filesystem2->CopyFile(CUtlString("%s/bin", szOutputDir.GetString()), outputProject); + filesystem2->CopyFile(CUtlString("%s/bin", szOutputDir.GetString()), szOutputDir); + /* } else { engine_lib = outputProject; } + */ return 0; }; diff --git a/engine/build.cpp b/engine/build.cpp index 686fe2b..52fe9d7 100644 --- a/engine/build.cpp +++ b/engine/build.cpp @@ -2,15 +2,20 @@ #include "c.h" #include "ld.h" #include "tier1/utlstring.h" -#include "tier1/commandline.h" -ADD_DEPENDENCY_BUILD_FILE(MaterialSystem, "../materialsystem/") -ADD_DEPENDENCY_BUILD_FILE(tier0, "../tier0/"); -ADD_DEPENDENCY_BUILD_FILE(tier1, "../tier1/"); -ADD_DEPENDENCY_BUILD_FILE(tier2, "../tier2/"); +#define FUNNYSTDLIB "../external/funnystdlib/" +ADD_DEPENDENCY_BUILD_FILE(MaterialSystem, "../materialsystem/build.cpp") +ADD_DEPENDENCY_BUILD_FILE(tier0, FUNNYSTDLIB"tier0/build.cpp"); +ADD_DEPENDENCY_BUILD_FILE(tier1, FUNNYSTDLIB"tier1/build.cpp"); +ADD_DEPENDENCY_BUILD_FILE(tier2, FUNNYSTDLIB"tier2/build.cpp"); DECLARE_BUILD_STAGE(engine) { + bool bUsesSDL = true; + if (Target_t::DefaultTarget().cpu == TARGET_CPU_WASM32) + { + bUsesSDL = false; + } CProject_t compileProject = {}; LinkProject_t ldProject = {}; @@ -19,14 +24,16 @@ DECLARE_BUILD_STAGE(engine) "engine.cpp", "cvar.cpp", - "gamewindow_sdl.cpp", - "sv_dll.cpp", "cl_dll.cpp", }; + if (bUsesSDL) + compileProject.files.AppendTail("gamewindow_sdl.cpp"); + compileProject.includeDirectories = { "../public", "../external/SDL/include", + FUNNYSTDLIB"public", }; compileProject.bFPIC = true; ldProject = ccompiler->Compile(&compileProject); @@ -34,12 +41,29 @@ DECLARE_BUILD_STAGE(engine) ldProject.linkType = ELINK_DYNAMIC_LIBRARY; ldProject.libraryObjects = { - GET_PROJECT_LIBRARY("tier1", "tier1"), - GET_PROJECT_LIBRARY("tier2", "tier2"), + GET_PROJECT_LIBRARY(tier0, "tier0"), }; - ldProject.libraries = { - "SDL3" + ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier1, "tier1")}); + ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier2, "tier2")}); + + if (bUsesSDL) + ldProject.libraries.AppendTail("SDL3"); + if (ldProject.m_target.kernel & TARGET_KERNEL_WINDOWS_DEVICES) + { + ldProject.libraryDirectories = {"../external/windows"}; + ldProject.libraries.AppendTail("winpthread-1"); + ldProject.libraries.AppendTail("winmm"); + ldProject.libraries.AppendTail("ole32"); + ldProject.libraries.AppendTail("gdi32"); + ldProject.libraries.AppendTail("oleaut32"); + ldProject.libraries.AppendTail("setupapi"); + ldProject.libraries.AppendTail("imm32"); + ldProject.libraries.AppendTail("version"); + ldProject.libraries.AppendTail("shell32"); + ldProject.libraries.AppendTail("uuid"); + }; + CUtlString outputProject = linker->Link(&ldProject); ADD_OUTPUT_OBJECT("engine", outputProject) diff --git a/engine/engine.cpp b/engine/engine.cpp index ec38140..8a5cfbb 100644 --- a/engine/engine.cpp +++ b/engine/engine.cpp @@ -3,22 +3,26 @@ #include "igamewindow.h" #include "materialsystem/imaterialsystem.h" #include "tier1/interface.h" -#include "tier1/commandline.h" +#include "tier0/commandline.h" #include "tier0/mem.h" #include "sv_dll.h" +IRenderContext *g_pRenderContext; +IFileSystem *filesystem; + extern "C" void FunnyMain( int argc, char **argv ) { CommandLine()->CreateCommandLine(argc, argv); - void *pFilesystem = Plat_LoadLibrary("libfilesystem.so"); - CreateInterfaceFn pFilesystemFactory = Sys_GetFactory(pFilesystem); + CreateInterfaceFn pFilesystemFactory = Sys_GetFactory("filesystem_std"); filesystem = (IFileSystem*)pFilesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL); filesystem->Init(); - gamewindow->Init(); - g_pMaterialSystem->Init(); + CreateInterfaceFn pMaterialSystemFactory = Sys_GetFactory("MaterialSystem"); + CreateInterfaceFn pRenderSystemFactory = Sys_GetFactory("RenderSystemVulkan"); + g_pRenderContext = (IRenderContext*)pRenderSystemFactory(RENDER_CONTEXT_INTERFACE_VERSION, NULL); + g_pRenderContext->Init(); ServerGameDLL()->Init(); @@ -43,26 +47,25 @@ extern "C" void FunnyMain( int argc, char **argv ) pCameraInfoBuffer = g_pRenderContext->CreateConstantBuffer(64); + /* pShader = g_pRenderContext->CreateShader("funnygame/core/shaders/flat.shader_c"); pMaterial = g_pRenderContext->CreateMaterial(pShader); pMaterial->PSSetConstantsBuffer(0, pCameraInfoBuffer); + */ pOutputImage = g_pRenderContext->CreateRenderTarget( - g_pRenderContext->GetNewOutputImageWidth(), - g_pRenderContext->GetNewOutputImageHeight(), + 1280, + 720, IMAGE_FORMAT_RGBA8_UNORM, MULTISAMPLE_TYPE_NONE); IRenderCommandList *pCommandList = g_pRenderContext->CreateCommandList(); pCommandList->StartRecording(); pCommandList->SetRenderTarget(0, pOutputImage); - pCommandList->SetMaterial(pMaterial); - pCommandList->SetVertexBuffer(0, pVertices); - pCommandList->DrawPrimitives(3, 0, 1, 0); + pCommandList->SetClearColor(0, 1,0,0,0); pCommandList->EndRecording(); for (;;) { - gamewindow->UpdateWindow(); /* if (g_pRenderContext->BIsOutputImageOutdated()) { @@ -77,11 +80,7 @@ extern "C" void FunnyMain( int argc, char **argv ) */ g_pRenderContext->SubmitCommandList(pCommandList); - - g_pRenderContext->SetOutputImage(pOutputImage); - - gamewindow->UpdateWindow(); - Materials()->Frame(0); + g_pRenderContext->Frame(0); }; }; diff --git a/engine/gamemgr.cpp b/engine/gamemgr.cpp index a0effa6..43e4ac6 100644 --- a/engine/gamemgr.cpp +++ b/engine/gamemgr.cpp @@ -36,9 +36,9 @@ void CGameManager::Init() CUtlString sz; pFile = filesystem->Open("game.ini", FILEMODE_READ); - szData = CUtlBuffer(pFile->Size()); - pFile->Read(szData.GetMemory(), szData.GetSize()); - pFile->Close(); + szData = CUtlBuffer(filesystem->Size(pFile)); + filesystem->Read(pFile, szData.GetMemory(), szData.GetSize()); + filesystem->Close(pFile); g_pGameParameters= INIManager()->ReadString(szData); pMainGame = g_pGameParameters->GetSection("MainGame"); diff --git a/engine/gamewindow_sdl.cpp b/engine/gamewindow_sdl.cpp index 5370e44..0d5154d 100644 --- a/engine/gamewindow_sdl.cpp +++ b/engine/gamewindow_sdl.cpp @@ -17,48 +17,22 @@ class CSDLGameWindow: public IGameWindow public: virtual void Init() override; virtual void Shutdown() override; - virtual void UpdateWindow() override; + virtual void Tick( float fDelta ) override; + virtual void Frame( float fDelta ) override; + virtual uint32_t GetRenderWidth() override; + virtual uint32_t GetRenderHeight() override; - // Rendering info - virtual void SetRenderImage( IImage *pImage ) override; - virtual bool BIsRenderResolutionUpdated() override; - virtual void GetRenderWidth() override; - virtual void GetRenderHeight() override; - - // Vulkan stuff - virtual int GetVulkanInstanceExtensionCount() override; - virtual const char **GetVulkanInstanceExtensions() override; - - virtual void CreateVulkanSurface( void *pInstance, void *pDevice ) override; - virtual void DestroyVulkanSurface( void *pInstance, void *pDevice ) override; - - virtual void *GetVulkanSurface() override; - virtual void *GetVulkanFence( int iFrame ) override; - virtual void *GetVulkanDrawSemaphore( int iFrame ) override; - virtual void *GetVulkanPresentSemaphore( int iFrame ) override; - virtual IImage *GetVulkanSwapchainImage( int iFrame ) override; + virtual void *CreateVulkanSurface( void *pInstance ) override; + virtual void DestroyVulkanSurface( void *pInstance ) override; private: + + VkSurfaceKHR m_hSurface; SDL_Window *m_pWindow; - EGraphicsAPI m_ePreferredGraphicsAPI; - - uint32_t m_uRenderWidth; - uint32_t m_uRenderHeight; - bool m_bIsRenderResolutionUpdated; - - void *m_pVulkanSurface; - CUtlVector m_vulkanImages; - void *m_pVulkanFences[VULKAN_FRAMES_IN_FLIGHT]; - void *m_pVulkanPresentSemaphores[VULKAN_FRAMES_IN_FLIGHT]; }; -CSDLGameWindow g_sdlGameWindow; -IGameWindow *gamewindow = &g_sdlGameWindow; - void CSDLGameWindow::Init() { - m_ePreferredGraphicsAPI = GRAPHICS_API_VULKAN; - if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_GAMEPAD)) Plat_FatalErrorFunc("SDL_Init: %s\n", SDL_GetError()); @@ -72,18 +46,14 @@ void CSDLGameWindow::Shutdown() } -void CSDLGameWindow::UpdateWindow() +void CSDLGameWindow::Frame( float fDelta ) { SDL_Event event; - m_bIsRenderResolutionUpdated = false; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED: - m_bIsRenderResolutionUpdated = true; - m_uRenderWidth = event.window.data1; - m_uRenderWidth = event.window.data2; break; case SDL_EVENT_QUIT: SDL_Quit(); @@ -94,46 +64,92 @@ void CSDLGameWindow::UpdateWindow() } } } -EGraphicsAPI CSDLGameWindow::GetGraphicsAPI() +void CSDLGameWindow::Tick( float fDelta ) { - return GRAPHICS_API_VULKAN; + +}; + +uint32_t CSDLGameWindow::GetRenderWidth() +{ + return 0; } -int CSDLGameWindow::GetVulkanInstanceExtensionCount() +uint32_t CSDLGameWindow::GetRenderHeight() { - if ( m_ePreferredGraphicsAPI != GRAPHICS_API_VULKAN ) - return -1; + return 0; +} + +void *CSDLGameWindow::CreateVulkanSurface( void *pInstance ) +{ + SDL_Vulkan_CreateSurface(m_pWindow, (VkInstance)pInstance, NULL, (VkSurfaceKHR*)&m_hSurface); + return (void*)m_hSurface; +} + +void CSDLGameWindow::DestroyVulkanSurface( void *pInstance ) +{ + SDL_Vulkan_DestroySurface((VkInstance)pInstance, (VkSurfaceKHR)m_hSurface, NULL); +} + +class CSDLGameWindowManager: public IGameWindowManager +{ + + virtual void Init() override; + virtual void Tick( float fDelta ) override; + virtual void Frame( float fDelta ) override; + virtual void Shutdown() override; + + virtual IGameWindow *CreateWindow() override; + virtual void DestroyWindow( IGameWindow* pWindow ) override; + + virtual int GetVulkanInstanceExtensionCount() override; + virtual const char **GetVulkanInstanceExtensions() override; +}; + +void CSDLGameWindowManager::Init() +{ + +} + +void CSDLGameWindowManager::Tick( float fDelta ) +{ + +} + +void CSDLGameWindowManager::Frame( float fDelta ) +{ + +} + +void CSDLGameWindowManager::Shutdown() +{ + +} + + +IGameWindow *CSDLGameWindowManager::CreateWindow() +{ + +} + +void CSDLGameWindowManager::DestroyWindow( IGameWindow* pWindow ) +{ + +} + + +int CSDLGameWindowManager::GetVulkanInstanceExtensionCount() +{ uint32_t nCount; SDL_Vulkan_GetInstanceExtensions(&nCount); return nCount; } -const char **CSDLGameWindow::GetVulkanInstanceExtensions() +const char **CSDLGameWindowManager::GetVulkanInstanceExtensions() { - if ( m_ePreferredGraphicsAPI != GRAPHICS_API_VULKAN ) - return 0; uint32_t nCount; return (const char **)SDL_Vulkan_GetInstanceExtensions(&nCount); } -void CSDLGameWindow::CreateVulkanSurface( void *pInstance ) -{ - if ( m_ePreferredGraphicsAPI != GRAPHICS_API_VULKAN ) - return; - - SDL_Vulkan_CreateSurface(m_pWindow, (VkInstance)pInstance, NULL, (VkSurfaceKHR*)&m_pVulkanSurface); -} - -void CSDLGameWindow::DestroyVulkanSurface( void *pInstance ) -{ - SDL_Vulkan_DestroySurface((VkInstance)pInstance, (VkSurfaceKHR)m_pVulkanSurface, NULL); -} - -void *CSDLGameWindow::GetVulkanSurface() -{ - return m_pVulkanSurface; -} - diff --git a/external/funnystdlib b/external/funnystdlib new file mode 160000 index 0000000..07089ff --- /dev/null +++ b/external/funnystdlib @@ -0,0 +1 @@ +Subproject commit 07089ffe1ca77ecfcd45dd498b9006498ca1836a diff --git a/fpc/.fpccfg b/fpc/.fpccfg deleted file mode 100644 index da89455..0000000 --- a/fpc/.fpccfg +++ /dev/null @@ -1 +0,0 @@ -[i386-unknown-linux] diff --git a/fpc/Makefile b/fpc/Makefile deleted file mode 100644 index be0d70b..0000000 --- a/fpc/Makefile +++ /dev/null @@ -1,79 +0,0 @@ -# We want to build just enough to use other stuff -TIER0_FILES := ../tier0/lib.cpp ../tier0/mem.cpp ../tier0/platform.cpp ../tier0/commandline.cpp ../tier0/rand.cpp -TIER1_FILES := ../tier1/utlbuffer.cpp ../tier1/interface.cpp ../tier1/utlstring.cpp ../tier1/utlvector.cpp ../tier1/utlmap.cpp -TIER2_FILES := ../tier2/filesystem.cpp ../tier2/fileformats/ini.cpp ../tier2/tokenizer.cpp ../tier2/fileformats/json.cpp -FILESYSTEM_FILES := ../stdfilesystems/filesystem_libc.cpp -TIER1_OBJS := $(TIER1_FILES:.cpp=.o) -TIER2_OBJS := $(TIER2_FILES:.cpp=.o) -FPC_FILES := library/helper.cpp library/target.cpp library/builder.cpp library/runner.cpp library/c.cpp library/ld.cpp library/clang/c.cpp library/clang/ld.cpp -CC = clang++ - -ifneq ($(FPC_ARCH),) -ifneq ($(FPC_OS),) -ifneq ($(FPC_ABI),) -REAL_TARGET := -target $(FPC_ARCH)-$(FPC_OS)-$(FPC_ABI) -DFPC_ARCH=\"$(FPC_ARCH)\" -DFPC_OS=\"$(FPC_OS)\" -DFPC_ABI=\"$(FPC_ABI)\" -else -REAL_TARGET := -target $(FPC_ARCH)-$(FPC_OS) -DFPC_ARCH=\"$(FPC_ARCH)\" -DFPC_OS=\"$(FPC_OS)\" -endif -endif -endif - -CCFLAGS = $(REAL_TARGET) -g -I../public -Ipublic - -UNAME_S := $(shell uname -s) -ifeq ($(UNAME_S),Darwin) -CCFLAGS += -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -std=c++11 -Wl,-export_dynamic -endif -ifeq ($(UNAME_S),Linux) -endif - -recompile: ../build/tools/fpc - build/fpc build - -install: ../build/tools/fpc build/libfpcbuild.a build/libfpc.so build/libtier0.so build/libtier1.a build/libtier2.a build/libfilesystem_std.so install_temp builddir - $(CC) -fPIC main.cpp library/helper.cpp library/target.cpp library/builder.cpp -lc -lstdc++ $(CCFLAGS) -o build/fpc -ltier0 -Lbuild build/libtier1.a build/libtier2.a -Wl,--disable-new-dtags -Wl,-rpath,'$$ORIGIN' - build/fpc build -fpcdebug - mv build/fpc_temp build/fpc - mv build/libfpc_temp.so build/libfpc.so - build/fpc build -fpcdebug - mv build/fpc_temp build/fpc - mv build/libfpc_temp.so build/libfpc.so - -build/libtier0.so: $(TIER0_FILES) builddir - $(CC) $(CCFLAGS) -fPIC -shared -o build/libtier0.so $(TIER0_FILES) - -%.o: %.cpp - $(CC) $(CCFLAGS) -fPIC -c $< -o $@ - -build/libtier1.a: $(TIER1_OBJS) builddir build/libtier0.so - ar rcs build/libtier1.a $(TIER1_OBJS) - -build/libtier2.a: $(TIER2_OBJS) builddir build/libtier1.a - ar rcs build/libtier2.a $(TIER2_OBJS) - -build/libfilesystem_std.so: $(FILESYSTEM_FILES) build/libtier1.a build/libtier0.so builddir - $(CC) $(CCFLAGS) -fPIC -shared -o build/libfilesystem_std.so $(FILESYSTEM_FILES) build/libtier1.a -ltier0 -Lbuild - -build/libfpcbuild.a: buildfile/interfaces.o builddir - ar rcs build/libfpcbuild.a buildfile/interfaces.o - -build/libfpc.so: $(FPC_FILES) builddir build/libfpcbuild.a build/libtier1.a build/libtier2.a - $(CC) $(CCFLAGS) $(FPC_FILES) library/libfpc.cpp -fPIC -shared -o build/libfpc.so build/libtier1.a build/libtier2.a - -builddir: - mkdir -p build - -../build/tools/fpc: - mkdir -p ../build/tools/fpc - -install_fpc: ../build/tools/fpc - cp -r build/* ../build/tools/fpc - -install_temp: builddir - cp -r public build - cp -r ../public/tier0 build/public - cp -r ../public/tier1 build/public - cp -r ../public/tier2 build/public - -auto: install install_fpc - diff --git a/fpc/README b/fpc/README deleted file mode 100644 index 9138fc4..0000000 --- a/fpc/README +++ /dev/null @@ -1,34 +0,0 @@ - funny project compiler - -fpc is a simple project manager written in C++ without usage of STL. -Instead it uses C++ files for building stuff with quite simple API. -It also generates compile_commands.json. - - basics cheat sheet - -With this toolset it should be sufficient enough to build any simple application. - -DECLARE_BUILD_STAGE( stage_name, function ) - Declares build stage - -CProject - compiler output base; -CShaderProject - shader compiler output base (NOT IMPLEMENTED) - -CCProject - C, C++, Objective-C, Objective-C++ compiler -CLDProject - linker - -IFileSystem2 - simple filesystem for creating, deleting and copying stuff - - usage parameters cheat sheet - --os - sets target kernel - windows - linux - macos - ios - android - --arch - sets target arch - x86_64 - aarch64 - --fpcdebug - shows shell command used to run the command diff --git a/fpc/apple/build.cpp b/fpc/apple/build.cpp deleted file mode 100644 index ccb51da..0000000 --- a/fpc/apple/build.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "c.h" -#include "swift.h" -#include "ld.h" -#include "helper.h" -#include "tier0/platform.h" -#include "tier1/interface.h" - -ADD_DEPENDENCY_BUILD_FILE(tier1, "../../tier1/build.cpp"); - -DECLARE_BUILD_STAGE(xtool) -{ - if (!linker->IsLibraryExists("swiftCore")) - { - V_printf("Swift is not installed\n"); - return 0; - } - - - CUtlString outputProject = CUtlString("fpcxtool/.build/%s/debug/libfpcxtool.so",Target_t::HostTarget().GetTriplet().GetString()); - V_printf("SWIFT %s\n", outputProject.GetString()); - - CUtlVector args = {"build"}; - runner->Run("swift","fpcxtool", args); - runner->Wait(); - - ADD_OUTPUT_OBJECT("xtool", outputProject); - - return 0; -}; - -DECLARE_BUILD_STAGE(xtool_cpp) -{ - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - CUtlString szOutputProject = ""; - - compileProject.m_szName = "xtool"; - compileProject.files = { - "fpcxtool/fpcxtool.cpp" - }; - compileProject.includeDirectories = {"../public","../../public"}; - compileProject.bFPIC = true; - ldProject = ccompiler->Compile(&compileProject); - - ldProject.linkType = ELINK_DYNAMIC_LIBRARY; - ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(xtool, "xtool")}); - ldProject.libraryObjects = { - GET_PROJECT_LIBRARY(tier1, "tier1"), - }; - - szOutputProject = linker->Link(&ldProject); - ADD_OUTPUT_OBJECT("xtool", szOutputProject); - return 0; -} diff --git a/fpc/build.cpp b/fpc/build.cpp deleted file mode 100644 index 32befd4..0000000 --- a/fpc/build.cpp +++ /dev/null @@ -1,160 +0,0 @@ -#include "c.h" -#include "ld.h" -#include "helper.h" -#include "tier0/platform.h" -#include "tier1/interface.h" - -ADD_DEPENDENCY_BUILD_FILE(tier0, "../tier0/build.cpp"); -ADD_DEPENDENCY_BUILD_FILE(tier1, "../tier1/build.cpp"); -ADD_DEPENDENCY_BUILD_FILE(tier2, "../tier2/build.cpp"); -ADD_DEPENDENCY_BUILD_FILE(appleauth, "../appleauth/build.cpp"); - - -CUtlVector g_fpcFiles = { - - "main.cpp", - "library/helper.cpp", - "library/target.cpp", - "library/builder.cpp", -}; - -CUtlVector g_libFpcFiles = { - "library/libfpc.cpp", - "library/helper.cpp", - "library/target.cpp", - "library/builder.cpp", - "library/runner.cpp", - "library/winerunner.cpp", - "library/deploy.cpp", - - "library/c.cpp", - "library/ld.cpp", - "library/swift.cpp", - - "library/android/apktool.cpp", - "library/apple/appletool.cpp", - - "library/clang/c.cpp", - "library/clang/ld.cpp", - - "library/windows/c.cpp", - "library/windows/ld.cpp", - - "library/apple/swift.cpp", - -}; - -CUtlVector g_IncludeDirectories = { - "public", - "../public", -}; - -DECLARE_BUILD_STAGE(libfpcbuild) -{ - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - - compileProject.m_szName = "fpcbuild"; - compileProject.files = g_libFpcFiles; - compileProject.includeDirectories = g_IncludeDirectories; - compileProject.bFPIC = true; - ldProject = ccompiler->Compile(&compileProject); - ldProject.linkType = ELINK_STATIC_LIBRARY; - - CUtlString outputProject = linker->Link(&ldProject); - - - ADD_OUTPUT_OBJECT("fpcbuild", outputProject) - - return 0; -} -DECLARE_BUILD_STAGE(libfpc) -{ - if (linker->IsLibraryExists("clang")) - g_libFpcFiles.AppendTail("library/clang/c_libclang.cpp"); - else - V_printf("Warning: to support included files libclang must be installed.\n"); - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - - compileProject.m_szName = "fpc"; - compileProject.files = g_libFpcFiles; - compileProject.includeDirectories = g_IncludeDirectories; - compileProject.bFPIC = true; - compileProject.macros = { - {"FPC_ARCH", CUtlString("\"%s\"",Target_t::StringFromCPU(compileProject.m_target.cpu))}, - {"FPC_OS", CUtlString("\"%s\"",Target_t::StringFromKernel(compileProject.m_target.kernel))}, - {"FPC_ABI", CUtlString("\"%s\"",Target_t::StringFromABI(compileProject.m_target.abi))}, - }; - ldProject = ccompiler->Compile(&compileProject); - ldProject.linkType = ELINK_DYNAMIC_LIBRARY; - ldProject.libraryObjects = { - GET_PROJECT_LIBRARY(tier0, "tier0"), - GET_PROJECT_LIBRARY(tier1, "tier1"), - GET_PROJECT_LIBRARY(tier2, "tier2"), - }; - - if (linker->IsLibraryExists("clang")) - ldProject.libraries.AppendTail("clang"); - - CUtlString outputProject = linker->Link(&ldProject); - - - ADD_OUTPUT_OBJECT("fpc", outputProject) - - return 0; -}; - -DECLARE_BUILD_STAGE(fpc) -{ - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - - compileProject.m_szName = "fpc"; - compileProject.files = g_fpcFiles; - compileProject.bFPIC = true; - compileProject.includeDirectories = g_IncludeDirectories; - compileProject.macros = { - {"FPC_ARCH", CUtlString("\"%s\"",Target_t::StringFromCPU(compileProject.m_target.cpu))}, - {"FPC_OS", CUtlString("\"%s\"",Target_t::StringFromKernel(compileProject.m_target.kernel))}, - {"FPC_ABI", CUtlString("\"%s\"",Target_t::StringFromABI(compileProject.m_target.abi))}, - }; - ldProject = ccompiler->Compile(&compileProject); - ldProject.libraryObjects = { - GET_PROJECT_LIBRARY(tier0, "tier0"), - GET_PROJECT_LIBRARY(tier1, "tier1"), - GET_PROJECT_LIBRARY(tier2, "tier2"), - }; - - CUtlString outputProject = linker->Link(&ldProject); - - - ADD_OUTPUT_OBJECT("fpc", outputProject); - - return 0; -}; - - -DECLARE_BUILD_STAGE(install) -{ - CUtlString szExe = GET_PROJECT_LIBRARY(fpc, "fpc"); - CUtlString szLibFpc = GET_PROJECT_LIBRARY(libfpc, "fpc"); - CUtlString szTier0 = GET_PROJECT_LIBRARY(tier0, "tier0"); - CUtlString szTier1 = GET_PROJECT_LIBRARY(tier1, "tier1"); - CUtlString szTier2 = GET_PROJECT_LIBRARY(tier2, "tier2"); - CUtlString szHttp = GET_PROJECT_LIBRARY(funnyhttp, "funnyhttp"); - CUtlString szAppleAuth = GET_PROJECT_LIBRARY(appleauth, "appleauth"); - - filesystem2->CopyFile("build/fpc_temp", szExe); - filesystem2->CopyFile("build/libfpc_temp.so", szLibFpc); - filesystem2->CopyFile("build", szHttp); - filesystem2->CopyFile("build", szAppleAuth); - - /* - filesystem2->CopyFile("build/libtier1.a", szTier1); - filesystem2->CopyFile("build/libtier2.a", szTier2); - filesystem2->CopyFile("build/libtier0_temp.so", szTier0); - */ - - return 0; -}; diff --git a/fpc/buildfile/interfaces.cpp b/fpc/buildfile/interfaces.cpp deleted file mode 100644 index fbf587d..0000000 --- a/fpc/buildfile/interfaces.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "tier1/interface.h" -#include "helper.h" - -static BuildFileInfo_t buildfileinfo = {}; -CBuildStage *g_pCurrentStage = NULL; -GetProjectObjectFn g_pfnGetProjectObject = NULL; - -BuildFileInfo_t *GetBuildFileInfo() -{ - return &buildfileinfo; -} - - -CBuildStage::CBuildStage( const char *psz, int(*pMainFn)() ) -{ - m_psz = psz; - m_pMainFn = pMainFn; - if (psz == 0 || pMainFn == 0) - Plat_FatalErrorFunc("Name and function pointer must be set\n"); - - GetBuildFileInfo()->m_stages.AppendTail(this); -}; - -CBuildDependentFile::CBuildDependentFile( const char *psz ) -{ - // TODO: This doesn't affect recursion, which is bad - - GetBuildFileInfo()->m_dependantFiles.AppendTail(psz); -} - -CUtlString FPC_GetProjectObject( const char *szName, const char *szObjectName ) -{ - CUtlString szOutputString; - szOutputString = g_pfnGetProjectObject(szName, szObjectName); - return szOutputString; -} - - -EXPOSE_INTERFACE_GLOBALVAR(BuildFileInfo_t, BuildFileInfo_t, BUILD_FILE_INFO_INTERFACE_VERSION, buildfileinfo); -EXPOSE_INTERFACE_GLOBALVAR(CBuildStage, CBuildStage, BUILD_CURRENT_STAGE_INTERFACE_VERSION, g_pCurrentStage); -EXPOSE_INTERFACE_GLOBALVAR(GetProjectObjectFn, GetProjectObjectFn, BUILD_GET_PROJECT_OBJECT_INTERFACE_VERSION, g_pfnGetProjectObject); diff --git a/fpc/external/build.cpp b/fpc/external/build.cpp deleted file mode 100644 index e95e5a8..0000000 --- a/fpc/external/build.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "c.h" -#include "ld.h" -#include "helper.h" -#include "tier0/platform.h" -#include "tier1/interface.h" -#include "tier2/ifilesystem.h" - -DECLARE_BUILD_STAGE(zsign) -{ - if (!filesystem) - { - void *pFilesystem = Plat_LoadLibrary("libfilesystem_std.so"); - CreateInterfaceFn pFilesystemFactory = Sys_GetFactory(pFilesystem); - - filesystem = (IFileSystem*)pFilesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL); - } - IDirectoryHandle *pDir = filesystem->OpenDir("zsign"); - if (!pDir) - return 0; - filesystem->CloseDir(pDir); - - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - CUtlString szOutputProject = ""; - - compileProject.m_szName = "zsign"; - compileProject.m_target = Target_t::HostTarget(); - compileProject.bFPIC = true; - compileProject.files = { - "zsign/src/common/archive.cpp", - "zsign/src/common/base64.cpp", - "zsign/src/common/fs.cpp", - "zsign/src/common/json.cpp", - "zsign/src/common/log.cpp", - "zsign/src/common/sha.cpp", - "zsign/src/common/timer.cpp", - "zsign/src/common/util.cpp", - "zsign/src/archo.cpp", - "zsign/src/bundle.cpp", - "zsign/src/macho.cpp", - "zsign/src/openssl.cpp", - "zsign/src/signing.cpp", - "zsign/src/zsign.cpp", - }; - compileProject.includeDirectories = { - "zsign/src/common", - "zsign/src", - }; - ldProject = ccompiler->Compile(&compileProject); - - ldProject.linkType = ELINK_DYNAMIC_LIBRARY; - szOutputProject = linker->Link(&ldProject); - - ADD_OUTPUT_OBJECT("zsign", szOutputProject); - - return 0; -} diff --git a/fpc/external/zsign b/fpc/external/zsign deleted file mode 160000 index cb49b1d..0000000 --- a/fpc/external/zsign +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cb49b1d34e8e0e02aac82f3579dbd7936232499b diff --git a/fpc/generators/make/make.cpp b/fpc/generators/make/make.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/fpc/library/android/apktool.cpp b/fpc/library/android/apktool.cpp deleted file mode 100644 index 63904b3..0000000 --- a/fpc/library/android/apktool.cpp +++ /dev/null @@ -1,207 +0,0 @@ -#include "apktool.h" -#include "helper.h" -#include "tier0/lib.h" -#include "tier0/platform.h" -#include "tier0/commandline.h" -#include "tier1/interface.h" -#include "runner.h" -#include "tier1/utlstring.h" -#include "tier1/utlvector.h" - -void AndroidManifest_t::SetPackageVersion( CUtlString szVersion ) -{ - m_szVersion = szVersion; -} - -void AndroidManifest_t::SetPackageBuild( uint64_t nBuild ) -{ - m_nBuild = nBuild; -} - -void AndroidManifest_t::SetPackageID( CUtlString szPackageID ) -{ - m_szPackageID = szPackageID; -} - -void AndroidManifest_t::SetPackageName( CUtlString szPackageName ) -{ - m_szPackageName = szPackageName; -} - -void AndroidManifest_t::SetTargetSDKVersion( uint64_t nTargetVersion ) -{ - m_nTargetVersion = nTargetVersion; -} - -void AndroidManifest_t::SetMinSDKVersion( uint64_t nMinVersion ) -{ - m_nMinVersion = nMinVersion; -} - -void AndroidManifest_t::AddUserFeature( CUtlString szName, bool bIsRequired, uint64_t nVersion ) -{ - -} - -void AndroidManifest_t::AddUserLibrary( CUtlString szPath ) -{ - -} - -CUtlString AndroidManifest_t::BuildManifest() -{ - CPUProject_t project = {}; - project.m_szName = m_szPackageName; - unsigned int hash = project.GenerateProjectHash(); - CUtlString szOutputDir = CUtlString("%s/android/%u_%s/",FPC_TEMPORAL_DIRNAME, hash, m_szPackageID.GetString()); - filesystem2->MakeDirectory(szOutputDir); - filesystem2->MakeDirectory(CUtlString("%s/res", szOutputDir.GetString())); - - CUtlString szAndroidManifestPath = CUtlString("%s/AndroidManifest.xml", szOutputDir.GetString()); - FILE *pAndroidManifest = V_fopen(szAndroidManifestPath, "wb"); - - V_fprintf(pAndroidManifest, "\n"); - V_fprintf(pAndroidManifest, "\n", m_szPackageID.GetString()); - V_fprintf(pAndroidManifest, "\n",m_nMinVersion, m_nTargetVersion); - V_fprintf(pAndroidManifest, "\n", m_szPackageName.GetString()); - V_fprintf(pAndroidManifest, "\n", m_szPackageName.GetString()); - V_fprintf(pAndroidManifest, "\n"); - V_fprintf(pAndroidManifest, "\n"); - V_fprintf(pAndroidManifest, "\n"); - V_fprintf(pAndroidManifest, "\n"); - V_fprintf(pAndroidManifest, "\n"); - V_fprintf(pAndroidManifest, "\n"); - V_fprintf(pAndroidManifest, "\n"); - V_fprintf(pAndroidManifest, "\n"); - - V_fclose(pAndroidManifest); - return szOutputDir; -}; - - - -class CAPKTool : public IAPKTool -{ -public: - virtual CUtlString BuildPackage( AndroidManifest_t manifest, CUtlString szManifestDir ) override; - virtual CUtlString SignPackage( const char *szApk, LegalInfo_t *pLegalInfo, const char *szAlias, const char *szStorePassword, const char *szKeyPassword ) override; -private: -}; - - - -CUtlString CAPKTool::BuildPackage( AndroidManifest_t manifest, CUtlString szManifestDir ) -{ - - V_printf(" APKTOOL %s\n", manifest.m_szPackageID.GetString()); - - IINISection *pSection = NULL; - const char *szBuildTools; - pSection = g_pConfig->GetSection("Android_Build_Tools"); - if (!pSection) - Plat_FatalErrorFunc("build_tools are required for this target"); - szBuildTools = pSection->GetStringValue("path"); - CUtlVector args = { - "package", - "-f", - "-M", - "AndroidManifest.xml", - "-S", - "res", - "-I", - CUtlString("%s/../../platforms/android-%lu/android.jar", szBuildTools, manifest.m_nTargetVersion), - "-F", - CUtlString("%s.unaligned.apk", manifest.m_szPackageID.GetString()), - }; - runner->Run(CUtlString("%s/aapt",szBuildTools),szManifestDir,args); - runner->Wait(); - - args = { - "-u", - CUtlString("%s.unaligned.apk", manifest.m_szPackageID.GetString()), - "lib/x86_64/libnative-app.so", - }; - runner->Run("zip",szManifestDir, args); - runner->Wait(); - - args = { - "-f", - "-v", - "4", - CUtlString("%s.unaligned.apk", manifest.m_szPackageID.GetString()), - CUtlString("%s.apk", manifest.m_szPackageID.GetString()), - }; - runner->Run(CUtlString("%s/zipalign",szBuildTools),szManifestDir,args); - runner->Wait(); - - return CUtlString("%s/%s.apk",szManifestDir.GetString(), manifest.m_szPackageID.GetString()); -} - -CUtlString CAPKTool::SignPackage( const char *szApk, LegalInfo_t *pLegalInfo, const char *szAlias, const char *szStorePassword, const char *szKeyPassword ) -{ - V_printf(" APKSIGN %s\n", szApk ); - CUtlString szOutput = CUtlString("%s.signed", szApk); - LegalInfo_t stLegalInfo = {}; - CUtlVector args = {}; - - CPUProject_t project = {}; - project.m_szName = szAlias; - unsigned int hash = project.GenerateProjectHash(); - CUtlString szOutputDir = CUtlString("%s/android/%u_%s/",FPC_TEMPORAL_DIRNAME, hash, szAlias); - filesystem2->MakeDirectory(szOutputDir); - CUtlString szKeystoreDir = CUtlString("%s/%s.jks",szOutputDir.GetString(),szAlias); - CUtlString szDname = ""; - - IINISection *pSection = NULL; - const char *szBuildTools; - pSection = g_pConfig->GetSection("Android_Build_Tools"); - if (!pSection) - Plat_FatalErrorFunc("build_tools are required for this target"); - szBuildTools = pSection->GetStringValue("path"); - - // We need to have a name at least - stLegalInfo.FirstName = "Gordon"; - stLegalInfo.LastName = "Freeman"; - - if (pLegalInfo != NULL) - stLegalInfo = *pLegalInfo; - - if (!stLegalInfo.FirstName) - Plat_FatalErrorFunc("First name wasn't provided\n"); - if (!stLegalInfo.LastName) - Plat_FatalErrorFunc("Last name wasn't provided\n"); - szDname.AppendTail(CUtlString("CN=%s %s", stLegalInfo.FirstName, stLegalInfo.LastName)); - - args = { - "-genkeypair", - "-keystore", szKeystoreDir, - "-alias", szAlias, - "-keyalg", "RSA", - "-keysize", "2048", - "-validity", "10000", - "-storepass", szStorePassword, - "-keypass", szKeyPassword, - "-dname", szDname, - }; - runner->Run("keytool", args); - runner->Wait(); - - args = { - "sign", - "--ks", szKeystoreDir, - "--ks-key-alias", szAlias, - "--ks-pass", CUtlString("pass:%s",szStorePassword), - "--key-pass", CUtlString("pass:%s",szKeyPassword), - szApk, - }; - runner->Run(CUtlString("%s/apksigner",szBuildTools), args); - runner->Wait(); - - return szApk; -}; - -IAPKTool *APKTool() -{ - static CAPKTool s_apktool = {}; - return &s_apktool; -} diff --git a/fpc/library/android/signtool.cpp b/fpc/library/android/signtool.cpp deleted file mode 100644 index 63704fa..0000000 --- a/fpc/library/android/signtool.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "signtool.h" -#include "tier0/platform.h" -#include "tier1/interface.h" - -class CAndroidSignTool : public ISignTool -{ -public: - virtual void SignFile( CUtlString szFile ) override; - virtual void SignDirectory( CUtlString szDirectory ) override; -}; - -EXPOSE_INTERFACE(CAndroidSignTool, ISignTool, ANDROID_SIGN_TOOL_INTERFACE_NAME); - -void CAndroidSignTool::SignFile( CUtlString szFile ) -{ - -} - -void CAndroidSignTool::SignDirectory( CUtlString szDirectory ) -{ - V_printf("Android doesn't support signing of directories\n"); -} - diff --git a/fpc/library/apple/appletool.cpp b/fpc/library/apple/appletool.cpp deleted file mode 100644 index ba16694..0000000 --- a/fpc/library/apple/appletool.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#include "appletool.h" -#include "helper.h" -#include "runner.h" -#include "appleauth/iauth.h" - -void AppleManifest_t::SetPackageID( CUtlString szPackageID ) -{ - m_szPackageID = szPackageID; -} - -void AppleManifest_t::SetPackageName( CUtlString szPackageName ) -{ - m_szPackageName = szPackageName; -} - -void AppleManifest_t::SetPackageExecutable( CUtlString szPackageExecutable ) -{ - m_szPackageExecutable = szPackageExecutable; -} - -CUtlString AppleManifest_t::BuildManifest() -{ - CPUProject_t project = {}; - project.m_szName = m_szPackageName; - unsigned int hash = project.GenerateProjectHash(); - CUtlString szOutputDir = CUtlString("%s/apple/%u_%s/app/",FPC_TEMPORAL_DIRNAME, hash, m_szPackageID.GetString()); - filesystem2->MakeDirectory(szOutputDir); - filesystem2->CopyFile(szOutputDir, m_szPackageExecutable); - CUtlString szInfoPlist = CUtlString("%s/Info.plist", szOutputDir.GetString()); - FILE *pInfoPlistFile = V_fopen(szInfoPlist, "wb"); - - V_fprintf(pInfoPlistFile, "\n"); - V_fprintf(pInfoPlistFile, "\n"); - V_fprintf(pInfoPlistFile, "\n"); - V_fprintf(pInfoPlistFile, "\n"); - V_fprintf(pInfoPlistFile, "CFBundleIdentifier\n"); - V_fprintf(pInfoPlistFile, "%s\n", m_szPackageID.GetString()); - V_fprintf(pInfoPlistFile, "CFBundleName\n"); - V_fprintf(pInfoPlistFile, "%s\n", m_szPackageName.GetString()); - V_fprintf(pInfoPlistFile, "CFBundleDisplayName\n"); - V_fprintf(pInfoPlistFile, "%s\n", m_szPackageName.GetString()); - V_fprintf(pInfoPlistFile, "CFBundleExecutable\n"); - V_fprintf(pInfoPlistFile, "%s\n", m_szPackageExecutable.GetFileName().GetString()); - V_fprintf(pInfoPlistFile, "CFBundlePackageType\n"); - V_fprintf(pInfoPlistFile, "APPL\n"); - V_fprintf(pInfoPlistFile, "CFBundleVersion\n"); - V_fprintf(pInfoPlistFile, "1.0\n"); - V_fprintf(pInfoPlistFile, "CFBundleShortVersionString\n"); - V_fprintf(pInfoPlistFile, "1.0\n"); - V_fprintf(pInfoPlistFile, "LSRequiresIPhoneOS\n"); - V_fprintf(pInfoPlistFile, "\n"); - V_fprintf(pInfoPlistFile, "UIDeviceFamily\n"); - V_fprintf(pInfoPlistFile, "\n"); - V_fprintf(pInfoPlistFile, "1\n"); - V_fprintf(pInfoPlistFile, "2\n"); - V_fprintf(pInfoPlistFile, "\n"); - V_fprintf(pInfoPlistFile, "\n"); - - V_fclose(pInfoPlistFile); - return szOutputDir; -} - - -class CAppleTool: public IAppleTool -{ -public: - virtual CUtlString BuildPackage( AppleManifest_t manifest, CUtlString szManifestDir ) override; - virtual CUtlString SignPackage( const char *szIpa, const char *szPassword ) override; -}; - -CUtlString CAppleTool::BuildPackage( AppleManifest_t manifest, CUtlString szManifestDir ) -{ - CUtlVector args = {}; - args = { - "-r", - CUtlString("../%s.ipa", manifest.m_szPackageName.GetString()), - CUtlString("."), - }; - runner->Run("zip",szManifestDir, args); - runner->Wait(); - return CUtlString("../%s.ipa", manifest.m_szPackageName.GetString()); -} - -static IAppleAuth *g_pAppleAuth; -CUtlString CAppleTool::SignPackage( const char *szIpa, const char *szPassword ) -{ - CreateInterfaceFn fnFactory = Sys_GetFactory("appleauth"); - if (fnFactory == NULL) - Plat_FatalErrorFunc("Couldn't get xtool\n"); - - g_pAppleAuth = (IAppleAuth*)fnFactory(APPLE_AUTH_INTERFACE_VERSION, NULL); - g_pAppleAuth->Init(); - char *szGSAEmail = CommandLine()->ParamValue("-apple-login"); - char *szGSAPassword = CommandLine()->ParamValue("-apple-password"); - if (szGSAEmail && szGSAPassword) - g_pAppleAuth->SubmitLoginData(szGSAEmail, szGSAPassword); - return szIpa; -} - - -IAppleTool *AppleTool() -{ - static CAppleTool s_tool; - return &s_tool; -} diff --git a/fpc/library/apple/swift.cpp b/fpc/library/apple/swift.cpp deleted file mode 100644 index 8d2ec89..0000000 --- a/fpc/library/apple/swift.cpp +++ /dev/null @@ -1,135 +0,0 @@ -#include "swift.h" - -class CSwiftCompiler: public ISwiftCompiler -{ -public: - - // Compiles all files into objects, returns linker project, - // which can be linked into executable or library. - //virtual LinkProject_t Compile( SwiftProject_t *pProject ); - - //virtual void GenerateLinterData() ; - -protected: - // Compiler internals - - virtual CUtlVector BuildCommandLine( SwiftProject_t *pProject, const char *szFileName, const char *szOutputFileName ) override; - - // Returns executable which should the OS run - virtual const char *GetCompilerExecutable( SwiftProject_t *pProject ) override; - - // returns object file format, eg .obj or .o - virtual const char *GetOutputObjectFormat() override; - - virtual void IncludeDirectory( CUtlVector &cmd, const char *szName ) override; - virtual void IncludeFile( CUtlVector &cmd, const char *szName ) override; - virtual void Macro( CUtlVector &cmd, const char *szName ) override; - virtual void Macro( CUtlVector &cmd, const char *szName, const char *szValue ) override; - - virtual void SetTarget( CUtlVector &cmd, SwiftProject_t *pProject ) override; - virtual void SetSysroot( CUtlVector &cmd, SwiftProject_t *pProject , const char *szSysroot ) override; - virtual void SetOutputFile( CUtlVector &cmd, const char *szName ) override; - - virtual void CompileFile( CUtlVector &cmd, const char *szName ) override; - - virtual void EnableDebugSymbols( CUtlVector &cmd ) override; - virtual void EnablePIE( CUtlVector &cmd ) override; - virtual void EnablePIC( CUtlVector &cmd ) override; -}; - -const char *CSwiftCompiler::GetOutputObjectFormat() -{ - return ".o"; -} - -CUtlVector CSwiftCompiler::BuildCommandLine( SwiftProject_t *pProject, const char *szFileName, const char *szOutputFileName ) -{ - CUtlVector cmd; - cmd = ISwiftCompiler::BuildCommandLine(pProject, szFileName, szOutputFileName); - cmd.AppendHead("-c"); - return cmd; -} - - -const char *CSwiftCompiler::GetCompilerExecutable( SwiftProject_t *pProject ) -{ - return "swiftc"; -} - - -void CSwiftCompiler::IncludeDirectory( CUtlVector &cmd, const char *szName ) -{ - cmd.AppendTail("-I"); - cmd.AppendTail(szName); -} - -void CSwiftCompiler::IncludeFile( CUtlVector &cmd, const char *szName ) -{ -} - -void CSwiftCompiler::Macro( CUtlVector &cmd, const char *szName ) -{ -} - -void CSwiftCompiler::Macro( CUtlVector &cmd, const char *szName, const char *szValue ) -{ - cmd.AppendTail("-D"); - cmd.AppendTail(CUtlString("%s=%s", (char*)szName, (char*)szValue)); -} - -void CSwiftCompiler::EnableDebugSymbols( CUtlVector &cmd ) -{ - cmd.AppendTail("-g"); -} - -void CSwiftCompiler::SetTarget( CUtlVector &cmd, SwiftProject_t *pProject ) -{ - cmd.AppendTail("-target"); - cmd.AppendTail(pProject->m_target.GetTriplet()); -} - -void CSwiftCompiler::CompileFile( CUtlVector &cmd, const char *szName ) -{ - cmd.AppendTail(szName); -} -void CSwiftCompiler::SetOutputFile( CUtlVector &cmd, const char *szName ) -{ - cmd.AppendTail("-o"); - cmd.AppendTail(szName); -} -void CSwiftCompiler::EnablePIE( CUtlVector &cmd ) -{ - cmd.AppendTail("-fPIE"); -} - -void CSwiftCompiler::EnablePIC( CUtlVector &cmd ) -{ - cmd.AppendTail("-fPIC"); -} -void CSwiftCompiler::SetSysroot( CUtlVector &cmd, SwiftProject_t *pProject, const char *szName ) -{ - if (szName != NULL) - { - cmd.AppendTail("--sysroot"); - cmd.AppendTail(szName); - return; - } - - if (!g_pConfig) - return; - - - IINISection *pSection = g_pConfig->GetSection(pProject->m_target.GetTriplet()); - if (!pSection) - return; - - const char *szSysroot = pSection->GetStringValue("sysroot"); - if (szSysroot) - { - cmd.AppendTail("--sysroot"); - cmd.AppendTail(szSysroot); - } -} - -EXPOSE_INTERFACE(CSwiftCompiler, ISwiftCompiler, SWIFT_COMPILER_INTERFACE_VERSION) - diff --git a/fpc/library/builder.cpp b/fpc/library/builder.cpp deleted file mode 100644 index ee40597..0000000 --- a/fpc/library/builder.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#include "builder.h" -#include "ld.h" -#include "c.h" - -CUtlVector buildFileInfos = {}; - - -class CProjectBuilder : public IProjectBuilder -{ -public: - virtual BuildFile_t *BuildProject( const char *szProjectName, const char *szPath ) override; - - BuildFile_t *m_pBuildFiles = NULL; -}; - - -static CProjectBuilder s_projectBuilder; - -EXPOSE_INTERFACE_GLOBALVAR(CProjectBuilder, IProjectBuilder, PROJECT_BUILDER_INTERFACE_NAME, s_projectBuilder) - -IProjectBuilder *ProjectBuilder() -{ - return &s_projectBuilder; -}; - -CUtlString FPC_GetProjectObject( const char *szName, const char *szObjectName ) -{ - for (auto b: buildFileInfos) - { - for (auto s: b.m_stages) - { - if (strcmp(s->m_psz, szName)) - continue; - for (auto o: s->m_outputs) - { - if (strcmp(o.m_szName, szObjectName)) - continue; - - return o.m_szPath; - } - } - } - return NULL; -} - -BuildFile_t *CProjectBuilder::BuildProject( const char *szProjectName, const char *szPath ) -{ - CProject_t stCompileProject = {}; - LinkProject_t stLinkProject = {}; - CUtlString szBuildLibrary; - void *pLibrary; - CreateInterfaceFn pBuildFactory; - BuildFileInfo_t *pBuildFileInfo; - BuildFileInfo_t stBuildFileInfo; - BuildFile_t *pBuildFile = NULL; - CBuildStage **ppExecutedBuildStage = NULL; - GetProjectObjectFn *pfnGetProjectObject = NULL; - CUtlString szWd = CUtlString(szPath).GetDirectory(); - - Plat_SetWorkingDir(szWd); - - - stCompileProject.m_szName = szProjectName; - stCompileProject.files = { - szPath, - }; - stCompileProject.includeDirectories = {CUtlString("%s/public",filesystem2->OwnDirectory())}; - stCompileProject.bFPIC = true; - stCompileProject.m_target = Target_t::HostTarget(); - - stLinkProject = ccompiler->Compile(&stCompileProject); - stLinkProject.linkType = ELINK_DYNAMIC_LIBRARY; - stLinkProject.m_target = Target_t::HostTarget(); - stLinkProject.objects.AppendHead({CUtlString("%s/libfpcbuild.a",filesystem2->OwnDirectory())}); - stLinkProject.libraryObjects.AppendHead({CUtlString("%s/libfpc.so",filesystem2->OwnDirectory())}); - stLinkProject.libraryObjects.AppendHead({CUtlString("%s/libtier2.a",filesystem2->OwnDirectory())}); - stLinkProject.libraryObjects.AppendHead({CUtlString("%s/libtier1.a",filesystem2->OwnDirectory())}); - szBuildLibrary = linker->Link(&stLinkProject); - - pLibrary = Plat_LoadLibrary(szBuildLibrary); - if ( !pLibrary ) - return NULL; - - pBuildFactory = Sys_GetFactory(pLibrary); - if (!pBuildFactory) - { - V_printf("Failed to find CreateInterface\n"); - Plat_UnloadLibrary(szBuildLibrary); - return NULL; - } - - pBuildFileInfo = (BuildFileInfo_t*)pBuildFactory(BUILD_FILE_INFO_INTERFACE_VERSION, NULL); - ppExecutedBuildStage = (CBuildStage**)pBuildFactory(BUILD_CURRENT_STAGE_INTERFACE_VERSION, NULL); - pfnGetProjectObject = (GetProjectObjectFn*)pBuildFactory(BUILD_GET_PROJECT_OBJECT_INTERFACE_VERSION, NULL); - if (!pBuildFileInfo || !ppExecutedBuildStage || !pfnGetProjectObject) - { - V_printf("Required interfaces are not present\n"); - Plat_UnloadLibrary(szBuildLibrary); - return NULL; - } - stBuildFileInfo = *pBuildFileInfo; - buildFileInfos.AppendTail(stBuildFileInfo); - *pfnGetProjectObject = FPC_GetProjectObject; - for (auto a: stBuildFileInfo.m_dependantFiles) - { - BuildProject("something", CUtlString("%s/%s",szWd.GetString(),a)); - } - - Plat_SetWorkingDir(szWd); - - - for (auto &build: stBuildFileInfo.m_stages) - { - *ppExecutedBuildStage = build; - build->m_pMainFn(); - for ( auto &o: build->m_outputs) - { - o.m_szPath.AppendHead("/"); - o.m_szPath.AppendHead(Plat_GetWorkingDir()); - }; - }; - - pBuildFile = new BuildFile_t; - pBuildFile->m_szOutputFile = szBuildLibrary; - pBuildFile->m_pLibrary = pLibrary; - pBuildFile->m_pNext = m_pBuildFiles; - m_pBuildFiles = pBuildFile; - - - return pBuildFile; -} diff --git a/fpc/library/c.cpp b/fpc/library/c.cpp deleted file mode 100644 index 54776e8..0000000 --- a/fpc/library/c.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "c.h" -#include "target.h" -#include - -ICCompiler *ccompiler; - -CUtlString ICCompiler::GetOutputObjectName( CProject_t *pProject, unsigned int hash, CUtlString szFileName ) -{ - CUtlString szTarget = pProject->m_target.GetTriplet(); - - return CUtlString( - "%s/%s/cc/%u_%s/%s/%s%s", - FPC_TEMPORAL_DIRNAME, - szTarget.GetString(), - hash, - pProject->m_szName.GetString(), - filesystem2->BuildDirectory(), - szFileName.GetString(), - GetOutputObjectFormat()); -}; - -CUtlVector ICCompiler::BuildCommandLine( CProject_t *pProject, const char *szFileName, const char *szOutputFileName ) -{ - - CUtlVector cmd; - - EnableDebugSymbols(cmd); - if (pProject->bFPIC) - EnablePIC(cmd); - if (pProject->bFPIE) - EnablePIE(cmd); - SetTarget(cmd, pProject); - SetOutputFile(cmd, szOutputFileName); - SetSysroot(cmd, pProject, NULL); - CompileFile(cmd, szFileName); - for (auto ¯o: pProject->macros) - Macro(cmd, macro.szName, macro.szValue.GetString()); - for (auto &dir: pProject->includeDirectories) - IncludeDirectory(cmd, dir); - - return cmd; -} - -LinkProject_t ICCompiler::Compile( CProject_t *pProject ) -{ - if (pProject->m_szName == 0) - { - Plat_FatalErrorFunc("m_szName must be present\n"); - } - - LinkProject_t proj = {}; - proj.m_szName = pProject->m_szName; - proj.m_target = pProject->m_target; - proj.m_androidmanifest = pProject->m_androidmanifest; - unsigned int hash = pProject->GenerateProjectHash(); - - - // Get output directories - for (auto &file: pProject->files) - { - CUtlString szOutputFile = GetOutputObjectName(pProject, hash, file); - CUtlString szOutputDir = szOutputFile; - szOutputDir = dirname(szOutputDir); - filesystem2->MakeDirectory(szOutputDir); - } - - // Run CC - for (auto &file: pProject->files) - { - CUtlString szOutputFile = GetOutputObjectName(pProject, hash, file); - CUtlVector args; - - args = BuildCommandLine(pProject, file, szOutputFile); - if (!filesystem2->ShouldRecompile(file, szOutputFile)) - goto skipcompile; - else - V_printf(" CC %s\n", file.GetString()); - runner->Run(GetCompilerExecutable(pProject), args); -skipcompile: - proj.objects.AppendTail((Object_t){szOutputFile}); - } - runner->Wait(); - return proj; -} diff --git a/fpc/library/clang/c.cpp b/fpc/library/clang/c.cpp deleted file mode 100644 index 6dc1ae9..0000000 --- a/fpc/library/clang/c.cpp +++ /dev/null @@ -1,284 +0,0 @@ -#include "c.h" -#include "c_libclang.h" -#include "helper.h" -#include "obj.h" -#include "target.h" -#include "tier0/lib.h" -#include "tier0/platform.h" -#include "tier0/commandline.h" -#include "tier1/interface.h" -#include "tier1/utlstring.h" -#include "tier1/utlvector.h" -#include "tier2/fileformats/json.h" -#include "libgen.h" -#include "ctype.h" - -struct ClangFile_t -{ - CUtlString m_szName; - CUtlVector m_szArguments; -}; - -class CClangCompiler : public ICCompiler -{ -public: - virtual LinkProject_t Compile( CProject_t *pProject ) override; - - virtual void GenerateLinterData() override; -protected: - - virtual CUtlVector BuildCommandLine( CProject_t *pProject, const char *szFileName, const char *szOutputFileName ) override; - - // Returns executable which should the OS run - virtual const char *GetCompilerExecutable( CProject_t *pProject ) override; - - // returns object file format, eg .obj or .o - virtual const char *GetOutputObjectFormat() override; - - virtual void IncludeDirectory( CUtlVector &cmd, const char *szName ) override; - virtual void IncludeFile( CUtlVector &cmd, const char *szName ) override; - virtual void Macro( CUtlVector &cmd, const char *szName ) override; - virtual void Macro( CUtlVector &cmd, const char *szName, const char *szValue ) override; - - virtual void SetTarget( CUtlVector &cmd, CProject_t *pProject ) override; - virtual void CompileFile( CUtlVector &cmd, const char *szName ) override; - virtual void SetOutputFile( CUtlVector &cmd, const char *szName ) override; - - virtual void EnableDebugSymbols( CUtlVector &cmd ) override; - virtual void EnablePIE( CUtlVector &cmd ) override; - virtual void EnablePIC( CUtlVector &cmd ) override; - - virtual void SetSysroot( CUtlVector &cmd, CProject_t *pProject, const char *szSysroot ) override; -}; - -const char *CClangCompiler::GetOutputObjectFormat() -{ - return ".o"; -} - -CUtlVector CClangCompiler::BuildCommandLine( CProject_t *pProject, const char *szFileName, const char *szOutputFileName ) -{ - CUtlVector cmd; - cmd = ICCompiler::BuildCommandLine(pProject, szFileName, szOutputFileName); - cmd.AppendHead("-c"); - return cmd; -} - - -const char *CClangCompiler::GetCompilerExecutable( CProject_t *pProject ) -{ - return "clang"; -} - - -void CClangCompiler::IncludeDirectory( CUtlVector &cmd, const char *szName ) -{ - cmd.AppendTail("-I"); - cmd.AppendTail(szName); -} - -void CClangCompiler::IncludeFile( CUtlVector &cmd, const char *szName ) -{ -} - -void CClangCompiler::Macro( CUtlVector &cmd, const char *szName ) -{ -} - -void CClangCompiler::Macro( CUtlVector &cmd, const char *szName, const char *szValue ) -{ - cmd.AppendTail("-D"); - cmd.AppendTail(CUtlString("%s=%s", (char*)szName, (char*)szValue)); -} - -void CClangCompiler::EnableDebugSymbols( CUtlVector &cmd ) -{ - cmd.AppendTail("-g"); -} - -void CClangCompiler::SetTarget( CUtlVector &cmd, CProject_t *pProject ) -{ - cmd.AppendTail("-target"); - cmd.AppendTail(pProject->m_target.GetTriplet()); -} - -void CClangCompiler::CompileFile( CUtlVector &cmd, const char *szName ) -{ - cmd.AppendTail(szName); -} -void CClangCompiler::SetOutputFile( CUtlVector &cmd, const char *szName ) -{ - cmd.AppendTail("-o"); - cmd.AppendTail(szName); -} -void CClangCompiler::EnablePIE( CUtlVector &cmd ) -{ - cmd.AppendTail("-fPIE"); -} - -void CClangCompiler::EnablePIC( CUtlVector &cmd ) -{ - cmd.AppendTail("-fPIC"); -} -void CClangCompiler::SetSysroot( CUtlVector &cmd, CProject_t *pProject, const char *szName ) -{ - if (szName != NULL) - { - cmd.AppendTail("--sysroot"); - cmd.AppendTail(szName); - return; - } - - if (!g_pConfig) - return; - - - IINISection *pSection = g_pConfig->GetSection(pProject->m_target.GetTriplet()); - if (!pSection) - return; - - const char *szSysroot = pSection->GetStringValue("sysroot"); - if (szSysroot) - { - cmd.AppendTail("--sysroot"); - cmd.AppendTail(szSysroot); - } -} - - - -EXPOSE_INTERFACE(CClangCompiler, ICCompiler, CLANG_C_COMPILER_INTERFACE_NAME); - -CUtlVector g_clangFiles; -IClangBackend *clangbackend = NULL; - -LinkProject_t CClangCompiler::Compile( CProject_t *pProject ) -{ - if (!clangbackend && CommandLine()->CheckParam("-experimental_header_include")) - clangbackend = (IClangBackend*)CreateInterface(CLANG_BACKEND_INTERFACE_NAME, NULL); - - if (pProject->m_szName == 0) - { - Plat_FatalErrorFunc("m_szName must be present\n"); - } - - LinkProject_t proj = {}; - proj.m_szName = pProject->m_szName; - proj.m_target = pProject->m_target; - proj.m_androidmanifest = pProject->m_androidmanifest; - unsigned int hash = pProject->GenerateProjectHash(); - - // Get output directories - for (auto &file: pProject->files) - { - CUtlString szOutputFile = GetOutputObjectName(pProject, hash, file); - CUtlString szOutputDir = szOutputFile; - szOutputDir = dirname(szOutputDir); - filesystem2->MakeDirectory(szOutputDir); - } - - // Run CC - for (auto &file: pProject->files) - { - - bool bAreDependenciesUpdated = false; - CUtlString szOutputFile = GetOutputObjectName(pProject, hash, file); - CUtlVector args; - /* - CUtlString szTarget = pProject->m_target.GetTriplet(); - CUtlString szCompiledTarget = szTarget; - if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID) - { - szCompiledTarget = CUtlString("%s%u", szTarget.GetString(), pProject->m_androidmanifest.m_nTargetVersion); - } - CUtlString szOutputFile = CUtlString("%s/%s/cc/%u_%s/%s/%s.o",FPC_TEMPORAL_DIRNAME, szTarget.GetString(), hash, pProject->m_szName.GetString(), filesystem2->BuildDirectory(), file.GetString()); - - args = { - "-target", - szCompiledTarget, - }; - */ - - /* - if (!strcmp(Plat_GetExtension(file),"cpp")) - args.AppendTail("-std=c++17"); - else if (!strcmp(Plat_GetExtension(file),"mm")) - ; - else - args.AppendTail("-std=c99"); - */ - - args = BuildCommandLine(pProject, file, szOutputFile); - - /* - if (pProject->m_target.kernel == TARGET_KERNEL_DARWIN) - { - args.AppendTail("-isysroot"); - args.AppendTail("/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"); - } else if (pProject->m_target.kernel == TARGET_KERNEL_IOS) - { - args.AppendTail("-isysroot"); - args.AppendTail("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"); - args.AppendTail("-miphoneos-version-min=18.0 "); - args.AppendTail("-fembed-bitcode"); - } - */ - - if (!filesystem2->ShouldRecompile(file, szOutputFile)) - goto skipcompile; - else - V_printf(" CC %s\n", file.GetString()); - - runner->Run(GetCompilerExecutable(pProject), args); -skipcompile: - proj.objects.AppendTail((Object_t){szOutputFile}); - - ClangFile_t cfile = {}; - cfile.m_szName = file; - cfile.m_szArguments = args; - cfile.m_szArguments.AppendHead(GetCompilerExecutable(pProject)); - - g_clangFiles.AppendTail(cfile); - } - runner->Wait(); - return proj; -} - -void CClangCompiler::GenerateLinterData() -{ - CUtlVector jsonValues = {}; - FILE* f = V_fopen("compile_commands.json", "wb"); - for ( auto &f: g_clangFiles ) - { - IJSONObject *pFileObject = JSONManager()->CreateObject(); - IJSONValue *pFileValue = JSONManager()->CreateValue(); - IJSONArray *pArgumentFiles = JSONManager()->CreateArray(); - IJSONValue *pArgumentsValue = JSONManager()->CreateValue(); - IJSONValue *pFileNameValue = JSONManager()->CreateValue(); - IJSONValue *pDirectoryValue = JSONManager()->CreateValue(); - CUtlVector values; - - for (auto &arg: f.m_szArguments) - { - IJSONValue *pFileValue = JSONManager()->CreateValue(); - pFileValue->SetStringValue(arg.GetString()); - values.AppendTail(pFileValue); - } - pArgumentFiles->SetArray(values.GetSize(), values.GetData()); - pArgumentsValue->SetArrayValue(pArgumentFiles); - pFileNameValue->SetStringValue(f.m_szName.GetString()); - pDirectoryValue->SetStringValue(filesystem2->BuildDirectory()); - pFileObject->SetValue("arguments", pArgumentsValue); - pFileObject->SetValue("file", pFileNameValue); - pFileObject->SetValue("directory", pDirectoryValue); - pFileValue->SetObjectValue(pFileObject); - jsonValues.AppendTail(pFileValue); - }; - IJSONArray *pArray = JSONManager()->CreateArray(); - pArray->SetArray(jsonValues.GetSize(), jsonValues.GetData()); - IJSONValue *pRoot = JSONManager()->CreateValue(); - pRoot->SetArrayValue(pArray); - CUtlString szCommands = JSONManager()->WriteString(pRoot); - V_fprintf(f, szCommands.GetString()); - V_fclose(f); -}; diff --git a/fpc/library/clang/c_clang_cl.cpp b/fpc/library/clang/c_clang_cl.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/fpc/library/clang/c_libclang.cpp b/fpc/library/clang/c_libclang.cpp deleted file mode 100644 index c3c5b6d..0000000 --- a/fpc/library/clang/c_libclang.cpp +++ /dev/null @@ -1,65 +0,0 @@ - -#include "c_libclang.h" -#include "helper.h" -#include "tier1/interface.h" - -#include "clang-c/Index.h" -#include -#include - -class CClangBackend: public IClangBackend -{ -public: - virtual bool AreFileDependenciesUpdated( CUtlString szFile, CUtlString szOutputFile, CUtlString szHashFile, CUtlVector arguments ) override; - - bool bAnyOutdated; - CUtlString szCurrentFile; - CUtlString szHashFile; - -private: - static void InclusionVisitor( CXFile included_file, CXSourceLocation *include_stack, unsigned include_len, CXClientData client_data ); -}; - -EXPOSE_INTERFACE(CClangBackend, IClangBackend, CLANG_BACKEND_INTERFACE_NAME); - -bool CClangBackend::AreFileDependenciesUpdated( CUtlString szFile, CUtlString szOutputFile, CUtlString szHashFile, CUtlVector arguments ) -{ - szCurrentFile = szOutputFile; - bAnyOutdated = false; - - CUtlVector cArguments = {}; - for (auto &arg: arguments) - cArguments.AppendTail(arg); - - CXIndex index = clang_createIndex(0, 0); - CXTranslationUnit tu; - CXErrorCode err = clang_parseTranslationUnit2(index, szFile.GetString(), cArguments.GetData(), cArguments.GetSize(), NULL, 0, 0, &tu); - - if (err != CXError_Success) { - printf("clang_parseTranslationUnit2 failed with error code %d\n", err); - return false; - } - - clang_getInclusions(tu, CClangBackend::InclusionVisitor, NULL); - - clang_disposeTranslationUnit(tu); - clang_disposeIndex(index); - return bAnyOutdated; -} - -void CClangBackend::InclusionVisitor( CXFile included_file, CXSourceLocation *include_stack, unsigned include_len, CXClientData client_data ) -{ - if (((CClangBackend*)clangbackend)->bAnyOutdated) - return; - CXString filename = clang_getFileName(included_file); - - bool bUpdate = - filesystem2->ShouldRecompile(clang_getCString(filename), ((CClangBackend*)clangbackend)->szCurrentFile); - if (bUpdate) - { - ((CClangBackend*)clangbackend)->bAnyOutdated = true; - } - - clang_disposeString(filename); -} - diff --git a/fpc/library/clang/c_libclang.h b/fpc/library/clang/c_libclang.h deleted file mode 100644 index e726cd6..0000000 --- a/fpc/library/clang/c_libclang.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef C_LIBCLANG_H -#define C_LIBCLANG_H - -#include "tier0/platform.h" -#include "tier1/utlstring.h" - -#define CLANG_BACKEND_INTERFACE_NAME "ClangBackend001" - -abstract_class IClangBackend -{ -public: - virtual bool AreFileDependenciesUpdated( CUtlString szFile, CUtlString szOutputFile, CUtlString szHashFile, CUtlVector arguments ) = 0; -}; - -extern IClangBackend *clangbackend; - -#endif diff --git a/fpc/library/clang/ld.cpp b/fpc/library/clang/ld.cpp deleted file mode 100644 index b2c1802..0000000 --- a/fpc/library/clang/ld.cpp +++ /dev/null @@ -1,413 +0,0 @@ -#include "ld.h" -#include "helper.h" -#include "libgen.h" -#include "target.h" -#include "tier0/platform.h" -#include "tier1/interface.h" -#include "tier1/utlstring.h" - -class CClangLinker : public ILinker -{ -public: - //virtual CUtlString Link( LinkProject_t *pProject ) override; - virtual bool IsLibraryExists( CUtlString szName ) override; -protected: - //virtual CUtlVector BuildLinkCommandLine( LinkProject_t *pProject, const char *szFileName, const char *szOutputFileName ); - //virtual CUtlVector BuildArchiveCommandLine( LinkProject_t *pProject, const char *szFileName, const char *szOutputFileName ); - - // Returns executable which should the OS run - virtual const char *GetCompilerExecutable( LinkProject_t *pProject ) override; - - virtual void SetTarget( CUtlVector &cmd, LinkProject_t *pProject ) override; - virtual void SetSysroot( CUtlVector &cmd, LinkProject_t *pProject , const char *szSysroot ) override; - virtual void SetOutputFile( CUtlVector &cmd, const char *szName ) override; - - - // sets rpath - // for windows should be ignored - virtual void SetDefaultLibraryPaths( CUtlVector &cmd, LinkProject_t *pProject ) override; - - virtual void UseStdLib( CUtlVector &cmd, bool bUse ) override; - - // windows doesn't use it as well - virtual void UseDynamicLookup( CUtlVector &cmd, bool bUse ) override; - - // includes whole file - virtual void UseFullFile( CUtlVector &cmd, LinkProject_t *pProject ) override; - - // includes used stuff in a file - virtual void UsePartialFile( CUtlVector &cmd, LinkProject_t *pProject ) override; - - virtual void LinkFile( CUtlVector &cmd, const char *szName ) override; - virtual void LinkLibraryObject( CUtlVector &cmd, const char *szName ) override; - virtual void LinkLibrary( CUtlVector &cmd, const char *szName ) override; - virtual void LinkLibraryPath( CUtlVector &cmd, const char *szName ) override; -}; - - - -const char *CClangLinker::GetCompilerExecutable( LinkProject_t *pProject ) -{ - IINISection *pSection = NULL; - const char *szLinker = "clang++"; - if (!g_pConfig) - return szLinker; - - - pSection = g_pConfig->GetSection(pProject->m_target.GetTriplet()); - if (!pSection) - return szLinker; - - - szLinker = pSection->GetStringValue("CLANG_LINKER_INTERFACE_NAME"); - if (szLinker == NULL) - return "clang++"; - return szLinker; -} - - - -void CClangLinker::SetTarget( CUtlVector &cmd, LinkProject_t *pProject ) -{ - if (pProject->linkType == ELINK_DYNAMIC_LIBRARY) - cmd.AppendTail("-shared"); - - if (pProject->m_target.kernel == TARGET_KERNEL_IOS) - cmd.AppendTail("-fuse-ld=lld"); - - cmd.AppendTail("-target"); - cmd.AppendTail(pProject->m_target.GetTriplet()); -} - -void CClangLinker::SetSysroot( CUtlVector &cmd, LinkProject_t *pProject , const char *szName ) -{ - if (szName != NULL) - { - cmd.AppendTail("--sysroot"); - cmd.AppendTail(szName); - return; - } - - if (!g_pConfig) - return; - - - IINISection *pSection = g_pConfig->GetSection(pProject->m_target.GetTriplet()); - if (!pSection) - return; - - const char *szSysroot = pSection->GetStringValue("sysroot"); - if (szSysroot) - { - cmd.AppendTail("--sysroot"); - cmd.AppendTail(szSysroot); - } -} - -void CClangLinker::SetOutputFile( CUtlVector &cmd, const char *szName ) -{ - cmd.AppendTail("-o"); - cmd.AppendTail(szName); -} - -void CClangLinker::SetDefaultLibraryPaths( CUtlVector &cmd, LinkProject_t *pProject ) -{ - if (pProject->m_target.kernel & TARGET_KERNEL_LINUX) - { - cmd.AppendTail("-Wl,--disable-new-dtags"); - cmd.AppendTail("-Wl,-rpath,$ORIGIN"); - } -} - - -void CClangLinker::UseStdLib( CUtlVector &cmd, bool bUse ) -{ - if (!bUse) - cmd.AppendTail("-nostdlib"); -} - - -void CClangLinker::UseDynamicLookup( CUtlVector &cmd, bool bUse ) -{ - -} - - -void CClangLinker::UseFullFile( CUtlVector &cmd, LinkProject_t *pProject ) -{ - if (pProject->m_target.kernel != TARGET_KERNEL_IOS) - cmd.AppendTail("-Wl,--whole-archive"); -} - - -void CClangLinker::UsePartialFile( CUtlVector &cmd, LinkProject_t *pProject ) -{ - if (pProject->m_target.kernel != TARGET_KERNEL_IOS) - cmd.AppendTail("-Wl,--no-whole-archive"); -} - - -void CClangLinker::LinkFile( CUtlVector &cmd, const char *szName ) -{ - cmd.AppendTail(szName); -} - -void CClangLinker::LinkLibraryObject( CUtlVector &cmd, const char *szName ) -{ - CUtlString szDir = CUtlString(szName).GetDirectory(); - CUtlString szFileName = CUtlString(szName).GetFileName(); - if (!V_strncmp(szFileName, "lib",3)) - szFileName.RemoveHead(3); - if (!V_strncmp(szFileName.GetFileExtension(), "so",2)) - szFileName.RemoveTail(3); - if (!V_strncmp(szFileName.GetFileExtension(), "a",1)) - szFileName.RemoveTail(2); - cmd.AppendTail("-L"); - cmd.AppendTail(szDir); - cmd.AppendTail("-l"); - cmd.AppendTail(szFileName); -} - -void CClangLinker::LinkLibrary( CUtlVector &cmd, const char *szName ) -{ - cmd.AppendTail("-l"); - cmd.AppendTail(szName); -} - -void CClangLinker::LinkLibraryPath( CUtlVector &cmd, const char *szName ) -{ - cmd.AppendTail("-L"); - cmd.AppendTail(szName); -} - -EXPOSE_INTERFACE(CClangLinker, ILinker, CLANG_LINKER_INTERFACE_NAME); -/* -CUtlString CClangLinker::Link( LinkProject_t *pProject ) -{ - if (pProject->m_szName == 0) - { - Plat_FatalErrorFunc("m_szName must be present\n"); - } - - // Find a name for the file - CUtlString szFileName; - unsigned int hash = pProject->GenerateProjectHash(); - switch(pProject->linkType) - { - case ELINK_EXECUTABLE: - if (pProject->m_target.kernel == TARGET_KERNEL_WINDOWS) - szFileName = CUtlString("%s.exe", pProject->m_szName.GetString()); - else if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID) - szFileName = CUtlString("lib%s.so", pProject->m_szName.GetString()); - else - szFileName = CUtlString("%s", pProject->m_szName.GetString()); - break; - case ELINK_STATIC_LIBRARY: - szFileName = CUtlString("lib%s.a", pProject->m_szName.GetString()); - break; - case ELINK_DYNAMIC_LIBRARY: - if (pProject->m_target.kernel == TARGET_KERNEL_DARWIN) - szFileName = CUtlString("lib%s.dylib", pProject->m_szName.GetString()); - if (pProject->m_target.kernel == TARGET_KERNEL_LINUX) - szFileName = CUtlString("lib%s.so", pProject->m_szName.GetString()); - break; - case ELINK_KERNEL_DRIVER: - Plat_FatalErrorFunc("TODO: not supported\n"); - break; - } - - CUtlString szTarget = pProject->m_target.GetTriplet(); - CUtlString szOutputFile = CUtlString("%s/%s/ld/%u_%s/%s",FPC_TEMPORAL_DIRNAME, szTarget.GetString(), hash, pProject->m_szName.GetString(), szFileName.GetString()); - CUtlString szOutputDir = szOutputFile; - szOutputDir = dirname(szOutputDir); - filesystem2->MakeDirectory(szOutputDir); - if (pProject->linkType == ELINK_STATIC_LIBRARY) - { - V_printf(" AR %s\n", pProject->m_szName.GetString()); - bool shouldRecompile = false; - CUtlVector args; - for (auto object: pProject->objects) - { - if (filesystem2->ShouldRecompile(object.m_szObjectFile,szOutputFile)) - { - shouldRecompile = true; - break; - } - } - if (!shouldRecompile) - goto compiled; - args = { - "rcs", - szOutputFile - }; - for (auto object: pProject->objects) - args.AppendTail(object.m_szObjectFile); - runner->Run("ar", args); - runner->Wait(); - - } else { - V_printf(" LINK %s\n", pProject->m_szName.GetString()); - bool shouldRecompile = false; - CUtlVector args; - - // Check if any of the files have changed - for (auto object: pProject->objects) - { - if (filesystem2->ShouldRecompile(object.m_szObjectFile,szOutputFile)) - { - shouldRecompile = true; - break; - } - } - if (!shouldRecompile) - goto compiled; - - - CUtlString szTarget = pProject->m_target.GetTriplet(); - CUtlString szCompiledTarget = szTarget; - if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID) - { - szCompiledTarget = CUtlString("%s%u", szTarget.GetString(), pProject->m_androidmanifest.m_nTargetVersion); - } - args = { - "-o", - szOutputFile, - "-target", - szCompiledTarget, - }; - - // Disable stdlib - if (pProject->bNoStdLib) - { - args.AppendTail("-nostdlib"); - } - - // Sysroots - if (pProject->m_target.kernel == TARGET_KERNEL_DARWIN) - { - args.AppendTail("-isysroot"); - args.AppendTail("/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"); - - // Shouldn't be here - args.AppendTail("-Wl,-export_dynamic"); - args.AppendTail("-undefined"); - args.AppendTail("dynamic_lookup"); - } - else if (pProject->m_target.kernel == TARGET_KERNEL_IOS) - { - args.AppendTail("-isysroot"); - args.AppendTail("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"); - // Shouldn't be here ? - args.AppendTail("-fembed-bitcode"); - args.AppendTail("-Wl,-rpath,@executable_path"); - args.AppendTail("-Wl,-all_load"); - args.AppendTail("-w"); - args.AppendTail("-miphoneos-version-min=18.0 "); - } - else if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID) - { - // args.AppendTail(CUtlString("--sysroot=%s/sysroot", pProject->m_target.szSysroot)); - - // Shouldn't be here ? - args.AppendTail("-static-libstdc++"); - } - else if (pProject->m_target.szSysroot) - { - // args.AppendTail(CUtlString("--sysroot=%s", pProject->m_target.szSysroot)); - } - - // Magic for the systems - if (pProject->m_target.kernel == TARGET_KERNEL_WINDOWS) - { - args.AppendTail("-fuse-ld=ld"); - } - if (pProject->m_target.kernel == TARGET_KERNEL_LINUX || pProject->m_target.kernel == TARGET_KERNEL_ANDROID) - { - args.AppendTail("-Wl,--disable-new-dtags"); - args.AppendTail("-Wl,-rpath,$ORIGIN"); - } - - // Dynamic libraries - // Android can't run executables - if (pProject->linkType == ELINK_DYNAMIC_LIBRARY || pProject->m_target.kernel == TARGET_KERNEL_ANDROID) - { - args.AppendTail("-shared"); - } - - // All the objects - if (pProject->m_target.kernel == TARGET_KERNEL_WINDOWS || pProject->m_target.kernel == TARGET_KERNEL_LINUX || pProject->m_target.kernel == TARGET_KERNEL_ANDROID) - args.AppendTail("-Wl,--whole-archive"); - for (auto object: pProject->objects) - args.AppendTail(object.m_szObjectFile); - if (pProject->m_target.kernel == TARGET_KERNEL_WINDOWS || pProject->m_target.kernel == TARGET_KERNEL_LINUX || pProject->m_target.kernel == TARGET_KERNEL_ANDROID) - args.AppendTail("-Wl,--no-whole-archive"); - for (auto object: pProject->libraryObjects) - args.AppendTail(object); - - // Libraries - for (auto lib: pProject->libraries) - { - args.AppendTail("-l"); - args.AppendTail(lib); - } - for (auto lib: pProject->libraryDirectories) - { - args.AppendTail("-L"); - args.AppendTail(lib); - } - - // Apple frameworks - for (auto &directory: pProject->frameworkDirectories) - { - args.AppendTail("-F"); - args.AppendTail(directory); - } - for (auto &framework: pProject->frameworks) - { - args.AppendTail("-framework"); - args.AppendTail(framework); - } - - IINISection *pSection = NULL; - const char *szLinker; - const char *szSysroot; - if (!g_pConfig) - goto use_default_linker; - - - pSection = g_pConfig->GetSection(pProject->m_target.GetTriplet()); - if (!pSection) - goto use_default_linker; - szSysroot = pSection->GetStringValue("sysroot"); - if (szSysroot) - { - args.AppendTail("--sysroot"); - args.AppendTail(szSysroot); - } - - szLinker = pSection->GetStringValue("CLANG_LINKER_INTERFACE_NAME"); - if (szLinker) - { - runner->Run(szLinker, args); - } - - runner->Wait(); - - goto compiled; -use_default_linker: - runner->Run("clang++", args); - runner->Wait(); - } -compiled: - return szOutputFile; -}; -*/ -bool CClangLinker::IsLibraryExists( CUtlString szName ) -{ - szName = CUtlString("lib%s.so", szName.GetString()); - void *pLib = Plat_LoadLibrary(szName.GetString()); - if (!pLib) - return false; - Plat_UnloadLibrary(pLib); - return true; -} diff --git a/fpc/library/deploy.cpp b/fpc/library/deploy.cpp deleted file mode 100644 index 0e1bb2b..0000000 --- a/fpc/library/deploy.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "deploy.h" - - -class CDeployDeviceManager: public IDeployDeviceManager -{ -public: - virtual void AddDevice( IDeployDevice *pDevice ) override; - virtual IDeployDevice *FindDeviceByName( const char *szDeviceName ) override; - virtual const CUtlVector &ListDevices() override; -private: - CUtlVector m_devices; -}; - -static CDeployDeviceManager s_deviceManager; - -void CDeployDeviceManager::AddDevice( IDeployDevice *pDevice ) -{ - m_devices.AppendTail(pDevice); -} - -IDeployDevice *CDeployDeviceManager::FindDeviceByName( const char *szDeviceName ) -{ - for ( auto device: m_devices ) - { - if ( !V_strcmp(device->GetName(), szDeviceName) ) - return device; - } - return NULL; -} - -const CUtlVector &CDeployDeviceManager::ListDevices() -{ - return m_devices; -} - - -IDeployDeviceManager *DeployDeviceManager() -{ - return &s_deviceManager; -} diff --git a/fpc/library/helper.cpp b/fpc/library/helper.cpp deleted file mode 100644 index 50efd67..0000000 --- a/fpc/library/helper.cpp +++ /dev/null @@ -1,139 +0,0 @@ -#include "helper.h" -#include "runner.h" -#include "tier0/platform.h" -#include "tier1/utlvector.h" -#include "tier1/utlstring.h" -#include "unistd.h" -#include "libgen.h" -#include "sys/stat.h" -#include "tier1/interface.h" -#ifdef __APPLE__ -#include -#endif - -unsigned int g_hashState = 102851263; -unsigned int BaseProject_t::GenerateProjectHash( void ) -{ - unsigned int hash = 5381+g_hashState; - int c; - char *szName = m_szName; - - while( (c = *szName++) ) - hash = (hash * 33) + c; - - g_hashState = g_hashState * 1664525 + 1013904223; - - return hash; -}; - -static char path[1024]; -#ifdef __linux__ -static ssize_t pathSize = readlink("/proc/self/exe", path, sizeof(path) - 1); -#endif -#ifdef __APPLE__ -static uint32_t pathSize = sizeof(path); -static int pathResult = _NSGetExecutablePath(path, &pathSize); -#endif -static char *szPathDir = dirname(path); -static char *s_szBuildDir = 0; -EXPOSE_INTERFACE_GLOBALVAR(szBuildDir, char*, FILE_SYSTEM_2_BUILD_DIRECTORY_INTERFACE_VERSION, s_szBuildDir); - -class CPOSIXFileSystem2: public IFileSystem2 -{ -public: - virtual char *OwnDirectory() override; - virtual char *BuildDirectory() override; - virtual void MakeDirectory( const char *psz ) override; - virtual void CopyFile( const char *szDestination, const char *szOrigin ) override; - virtual void CopyDirectory( const char *szDestination, const char *szOrigin ) override; - virtual bool ShouldRecompile( const char *szSource, const char *szOutput ) override; - virtual char *GetWindowsPath( const char *szPath ) override; - virtual char *GetPOSIXPath( const char *szPath ) override; -}; - -char *CPOSIXFileSystem2::GetWindowsPath( const char *szPath ) -{ - char *szNewPath = (char*)V_malloc(V_strlen(szPath)+1); - int i = 0; - V_strcpy(szNewPath, szPath); - while(szNewPath[i]) - { - if (szNewPath[i] == '/') - szNewPath[i] = '\\'; - i++; - } - return szNewPath; -} - -char *CPOSIXFileSystem2::GetPOSIXPath( const char *szPath ) -{ - char *szNewPath = (char*)V_malloc(V_strlen(szPath)+1); - int i = 0; - V_strcpy(szNewPath, szPath); - while(szNewPath[i]) - { - if (szNewPath[i] == '\\') - szNewPath[i] = '/'; - i++; - } - return szNewPath; -} - -EXPOSE_INTERFACE(CPOSIXFileSystem2, IFileSystem2, FILE_SYSTEM_2_INTERFACE_NAME); -IFileSystem2 *filesystem2; - -char *CPOSIXFileSystem2::OwnDirectory() -{ - return szPathDir; -}; -char *CPOSIXFileSystem2::BuildDirectory() -{ - return s_szBuildDir; -}; - -void CPOSIXFileSystem2::CopyFile( const char *szDestination, const char *szOrigin ) -{ - CUtlVector args = { - szOrigin, - szDestination, - }; - runner->Run(CUtlString("cp"), args); - runner->Wait(); -} -void CPOSIXFileSystem2::CopyDirectory( const char *szDestination, const char *szOrigin ) -{ - CUtlVector args = { - "-r", - szOrigin, - szDestination, - }; - runner->Run("cp", args); - runner->Wait(); -} - -void CPOSIXFileSystem2::MakeDirectory( const char *psz ) -{ - CUtlVector args = { - "-p", - CUtlString(psz), - }; - runner->Run("mkdir", args); - runner->Wait(); -}; - -bool CPOSIXFileSystem2::ShouldRecompile(const char *szSource, const char *szOutput) -{ - struct stat srcbuf; - struct stat outbuf; - if (stat(szSource, &srcbuf) != 0) { - return true; - } - if (stat(szOutput, &outbuf) != 0) { - return true; - } - return outbuf.st_mtime < srcbuf.st_mtime; -}; - - -IINIFile *g_pConfig; -EXPOSE_INTERFACE_GLOBALVAR(IINIFile, IINIFile, LIBFPC_CONFIG_INTERFACE_VERSION, g_pConfig); diff --git a/fpc/library/ld.cpp b/fpc/library/ld.cpp deleted file mode 100644 index dea45e9..0000000 --- a/fpc/library/ld.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include "ld.h" - -ILinker *linker; - -void LinkProject_t::AddObject( Object_t object ) -{ - objects.AppendTail(object); -}; -CUtlString ILinker::GetOutputObjectName( LinkProject_t *pProject, unsigned int hash, CUtlString szFileName ) -{ - CUtlString szTarget = pProject->m_target.GetTriplet(); - CUtlString szFileNameFormat; - switch (pProject->linkType) - { - case ELINK_EXECUTABLE: - szFileNameFormat = CUtlString(pProject->m_target.GetExecutableFileFormat(),pProject->m_szName.GetString()); - break; - case ELINK_DYNAMIC_LIBRARY: - szFileNameFormat = CUtlString(pProject->m_target.GetDynamicLibraryFileFormat(),pProject->m_szName.GetString()); - break; - case ELINK_STATIC_LIBRARY: - szFileNameFormat = CUtlString(pProject->m_target.GetStaticLibraryFileFormat(),pProject->m_szName.GetString()); - break; - default: - break; - } - - return CUtlString( - "%s/%s/ld/%u_%s/%s", - FPC_TEMPORAL_DIRNAME, - szTarget.GetString(), - hash, - pProject->m_szName.GetString(), - szFileNameFormat.GetString()); -} - -CUtlString ILinker::Link( LinkProject_t *pProject ) -{ - if (pProject->m_szName == 0) - { - Plat_FatalErrorFunc("m_szName must be present\n"); - } - LinkProject_t stLinkProject = *pProject; - if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID) - stLinkProject.linkType = ELINK_DYNAMIC_LIBRARY; - - unsigned int hash = pProject->GenerateProjectHash(); - CUtlString szOutputFile = GetOutputObjectName(&stLinkProject, hash, NULL); - filesystem2->MakeDirectory(szOutputFile.GetDirectory()); - - if (stLinkProject.linkType == ELINK_STATIC_LIBRARY) - { - CUtlVector args; - bool shouldRecompile = false; - for (auto object: pProject->objects) - { - if (filesystem2->ShouldRecompile(object.m_szObjectFile,szOutputFile)) - { - shouldRecompile = true; - break; - } - } - if (!shouldRecompile) - goto compiled; - - V_printf(" AR %s\n", pProject->m_szName.GetString()); - args = { - "rcs", - szOutputFile - }; - for (auto object: pProject->objects) - args.AppendTail(object.m_szObjectFile); - runner->Run("ar", args); - runner->Wait(); - } else { - bool shouldRecompile = false; - for (auto object: pProject->objects) - { - if (filesystem2->ShouldRecompile(object.m_szObjectFile,szOutputFile)) - { - shouldRecompile = true; - break; - } - } - for (auto object: pProject->libraryObjects) - { - if (filesystem2->ShouldRecompile(object,szOutputFile)) - { - shouldRecompile = true; - break; - } - } - if (!shouldRecompile) - goto compiled; - - V_printf(" LINK %s\n", pProject->m_szName.GetString()); - CUtlVector args; - args = BuildLinkCommandLine(pProject, szOutputFile); - runner->Run(GetCompilerExecutable(pProject), args); - runner->Wait(); - } -compiled: - return szOutputFile; -} - -CUtlVector ILinker::BuildLinkCommandLine( LinkProject_t *pProject, const char *szOutputFileName ) -{ - CUtlVector cmd; - SetTarget(cmd, pProject); - SetOutputFile(cmd, szOutputFileName); - SetSysroot(cmd, pProject, NULL); - SetDefaultLibraryPaths(cmd, pProject); - UseFullFile(cmd, pProject); - for (auto &o: pProject->objects) - { - LinkFile(cmd, o.m_szObjectFile); - } - UsePartialFile(cmd, pProject); - - for (auto &o: pProject->libraryObjects) - { - LinkLibraryObject(cmd, o); - }; - for (auto &o: pProject->libraries) - { - LinkLibrary(cmd, o); - }; - for (auto &o: pProject->libraryDirectories) - { - LinkLibraryPath(cmd, o); - }; - return cmd; - -} - -CUtlVector ILinker::BuildArchiveCommandLine( LinkProject_t *pProject, const char *szOutputFileName ) -{ - CUtlVector cmd; -} - diff --git a/fpc/library/libfpc.cpp b/fpc/library/libfpc.cpp deleted file mode 100644 index e7e481c..0000000 --- a/fpc/library/libfpc.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "helper.h" -#include "runner.h" -#include "c.h" -#include "ld.h" -#include "tier2/ifilesystem.h" - -IFileSystem *filesystem; - -void *LibFpcInit() -{ - filesystem2 = (IFileSystem2*)CreateInterface(FILE_SYSTEM_2_INTERFACE_NAME, NULL); - runner = (IRunner*)CreateInterface(RUNNER_INTERFACE_NAME, NULL); - ccompiler = (ICCompiler*)CreateInterface(CLANG_C_COMPILER_INTERFACE_NAME, NULL); - linker = (ILinker*)CreateInterface(CLANG_LINKER_INTERFACE_NAME, NULL); - - void *pFilesystem = Plat_LoadLibrary("libfilesystem_std.so"); - CreateInterfaceFn pFilesystemFactory = Sys_GetFactory(pFilesystem); - filesystem = (IFileSystem*)pFilesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL); - filesystem->Init(); - return NULL; -} - -EXPOSE_INTERFACE_FN(LibFpcInit, LibFpcInit, LIBFPC_INIT_INTERFACE_VERSION); diff --git a/fpc/library/runner.cpp b/fpc/library/runner.cpp deleted file mode 100644 index ef31573..0000000 --- a/fpc/library/runner.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#include "runner.h" -#include "tier0/platform.h" -#include "tier1/interface.h" -#include "tier1/utlstring.h" -#include "tier1/utlvector.h" -#include "unistd.h" -#include "sys/wait.h" -#include "tier0/commandline.h" - -#include "winerunner.h" - - -CUtlVector m_processes; -class CPOSIXRunner: public IRunner -{ -public: - virtual int Run( CUtlString szName, CUtlVector& args ) override; - virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector& args ) override; - virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector& args, CUtlVector& environment ) override; - virtual int Wait( void ) override; -}; - -EXPOSE_INTERFACE(CPOSIXRunner, IRunner, RUNNER_INTERFACE_NAME); -IRunner *runner; -IWineRunner *winerunner; - -int CPOSIXRunner::Run(CUtlString szName, CUtlVector& args) -{ - pid_t pid = fork(); - if (pid < 0) - Plat_FatalErrorFunc("Failed to fork"); - /* child */ - if (pid == 0) - { - CUtlVector execargs; - execargs.AppendTail(szName); - if (CommandLine()->CheckParam("-fpcdebug")) - V_printf("%s",szName.GetString()); - for (auto &arg: args) - { - execargs.AppendTail(arg); - if (CommandLine()->CheckParam("-fpcdebug")) - V_printf(" %s",arg.GetString()); - } - if (CommandLine()->CheckParam("-fpcdebug")) - V_printf("\n"); - execargs.AppendTail(0); - if ( execvp(szName, (char *const*)execargs.GetData()) == -1 ) - { - V_printf("Failed to launch %s\n",szName.GetString()); - _exit(0); - } - } - m_processes.AppendTail(pid); - return 0; -} - -int CPOSIXRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector& args) -{ - pid_t pid = fork(); - if (pid < 0) - Plat_FatalErrorFunc("Failed to fork"); - /* child */ - if (pid == 0) - { - CUtlVector execargs; - execargs.AppendTail(szName); - if (CommandLine()->CheckParam("-fpcdebug")) - V_printf("%s",szName.GetString()); - for (auto &arg: args) - { - execargs.AppendTail(arg); - if (CommandLine()->CheckParam("-fpcdebug")) - V_printf(" %s",arg.GetString()); - } - if (CommandLine()->CheckParam("-fpcdebug")) - V_printf("\n"); - execargs.AppendTail(0); - chdir(szDirectory.GetString()); - if ( execvp(szName, (char *const*)execargs.GetData()) == -1 ) - { - V_printf("Failed to launch %s\n",szName.GetString()); - _exit(0); - } - } - m_processes.AppendTail(pid); - /* parent */ - return 0; -} - -int CPOSIXRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector& args, CUtlVector& environment) -{ - -} - -int CPOSIXRunner::Wait( void ) -{ - for (int i = 0; im_target.GetTriplet(); - - return CUtlString( - "%s/%s/swift/%u_%s/%s/%s%s", - FPC_TEMPORAL_DIRNAME, - szTarget.GetString(), - hash, - pProject->m_szName.GetString(), - filesystem2->BuildDirectory(), - szFileName.GetString(), - GetOutputObjectFormat()); -}; - -CUtlVector ISwiftCompiler::BuildCommandLine( SwiftProject_t *pProject, const char *szFileName, const char *szOutputFileName ) -{ - - CUtlVector cmd; - - EnableDebugSymbols(cmd); - if (pProject->bFPIC) - EnablePIC(cmd); - if (pProject->bFPIE) - EnablePIE(cmd); - SetTarget(cmd, pProject); - SetOutputFile(cmd, szOutputFileName); - SetSysroot(cmd, pProject, NULL); - CompileFile(cmd, szFileName); - for (auto ¯o: pProject->macros) - Macro(cmd, macro.szName, macro.szValue.GetString()); - for (auto &dir: pProject->includeDirectories) - IncludeDirectory(cmd, dir); - - return cmd; -} - -LinkProject_t ISwiftCompiler::Compile( SwiftProject_t *pProject ) -{ - if (pProject->m_szName == 0) - { - Plat_FatalErrorFunc("m_szName must be present\n"); - } - - LinkProject_t proj = {}; - proj.m_szName = pProject->m_szName; - proj.m_target = pProject->m_target; - proj.m_androidmanifest = pProject->m_androidmanifest; - unsigned int hash = pProject->GenerateProjectHash(); - - - // Get output directories - for (auto &file: pProject->files) - { - CUtlString szOutputFile = GetOutputObjectName(pProject, hash, file); - CUtlString szOutputDir = szOutputFile.GetDirectory(); - filesystem2->MakeDirectory(szOutputDir); - } - - // Run CC - for (auto &file: pProject->files) - { - CUtlString szOutputFile = GetOutputObjectName(pProject, hash, file); - CUtlVector args; - - args = BuildCommandLine(pProject, file, szOutputFile); - if (!filesystem2->ShouldRecompile(file, szOutputFile)) - goto skipcompile; - else - V_printf(" SWIFT %s\n", file.GetString()); - runner->Run(GetCompilerExecutable(pProject), args); -skipcompile: - proj.objects.AppendTail((Object_t){szOutputFile}); - } - runner->Wait(); - return proj; -} - -ISwiftCompiler *swiftcompiler = NULL; diff --git a/fpc/library/target.cpp b/fpc/library/target.cpp deleted file mode 100644 index e85885d..0000000 --- a/fpc/library/target.cpp +++ /dev/null @@ -1,257 +0,0 @@ -#include "target.h" -#include "tier0/commandline.h" -#include "tier1/utlstring.h" -#include "sys/utsname.h" - -// see Target_t::HostTarget -#if defined(__i386__) && defined(POSIX) -static utsname s_uname; -static int s_iuNameRes = uname(&s_uname); -#endif - -//----------------------------------------------------------------------------- -// Generates triplet suitable for most compilers. -//----------------------------------------------------------------------------- -CUtlString Target_t::GetTriplet() -{ - CUtlString triplet = ""; - - triplet.AppendTail(StringFromCPU(cpu)); - triplet.AppendTail("-"); - triplet.AppendTail(StringFromKernel(kernel)); - - if ( abi != TARGET_ABI_UNDEFINED && abi != TARGET_ABI_DEFAULT ) - { - triplet.AppendTail("-"); - triplet.AppendTail(StringFromABI(abi)); - } - - - return triplet; -} - -const char *Target_t::GetExecutableFileFormat() -{ - if (kernel & TARGET_KERNEL_POSIX) - return "%s"; - - if (kernel & TARGET_KERNEL_WINDOWS_DEVICES) - { - return "%s.exe"; - } - return NULL; -} - -const char *Target_t::GetStaticLibraryFileFormat() -{ - if (kernel & TARGET_KERNEL_POSIX) - return "lib%s.a"; - - if (kernel & TARGET_KERNEL_WINDOWS_DEVICES) - { - switch(abi) - { - case TARGET_ABI_MSVC: - return "%s.lib"; - default: - return "lib%s.a"; - } - } - return NULL; -} -const char *Target_t::GetDynamicLibraryFileFormat() -{ - if (kernel & TARGET_KERNEL_LINUX_DEVICES) - return "lib%s.so"; - if (kernel & TARGET_KERNEL_APPLE_DEVICES) - return "lib%s.dylib"; - if (kernel & TARGET_KERNEL_WINDOWS_DEVICES) - return "lib%s.dylib"; - return NULL; -} -//---------------------------------------------------------------------------- -// Returns target on which fpc is being run -// -// For targets such as i386, i486, i586 -//---------------------------------------------------------------------------- -Target_t Target_t::HostTarget() -{ - ETargetKernel kernel = TARGET_KERNEL_UNDEFINED; -#if defined(__linux__) - kernel = TARGET_KERNEL_LINUX; -#elif defined(__APPLE__) - kernel TARGET_KERNEL_DARWIN; -#endif -ETargetCPU cpu = TARGET_CPU_UNDEFINED; -#if defined(__x86_64__) - cpu = TARGET_CPU_AMD64; -#endif -#if defined(__i386__) - cpu = TARGET_CPU_80386; -#endif -// POSIX doesn't know about these -// use uname to get them -#if defined(__i386__) && defined(POSIX) - if (!V_strcmp("i486", s_uname.machine)) - cpu = TARGET_CPU_80486; - if (!V_strcmp("i586", s_uname.machine)) - cpu = TARGET_CPU_80586; - if (!V_strcmp("i686", s_uname.machine)) - cpu = TARGET_CPU_80686; -#endif - ETargetABI abi = TARGET_ABI_GNU; - -#ifdef FPC_ARCH - cpu = CPUFromString(FPC_ARCH); -#endif -#ifdef FPC_OS - kernel = KernelFromString(FPC_OS); -#endif -#ifdef FPC_ABI - abi = ABIFromString(FPC_ABI); -#endif - - - return { - .kernel = kernel, - .cpu = cpu, - .abi = abi, - .optimization = TARGET_DEBUG, - }; -}; - -//----------------------------------------------------------------------------- -// Returns default target for build, by default it will be host target -//----------------------------------------------------------------------------- -Target_t Target_t::DefaultTarget() -{ - CUtlString szDevice = CommandLine()->ParamValue("-device"); - CUtlString szOS = CommandLine()->ParamValue("-os"); - CUtlString szArch = CommandLine()->ParamValue("-arch"); - CUtlString szAbi = CommandLine()->ParamValue("-abi"); - - ETargetKernel kernel = KernelFromString(szOS); - ETargetCPU cpu = CPUFromString(szArch); - ETargetABI abi = ABIFromString(szAbi); - if (cpu == TARGET_CPU_UNDEFINED) - cpu = HostTarget().cpu; - if (kernel == TARGET_KERNEL_UNDEFINED) - kernel = HostTarget().kernel; - if (abi == TARGET_ABI_UNDEFINED) - abi = HostTarget().abi; - - - return { - .kernel = kernel, - .cpu = cpu, - .abi = abi, - .optimization = TARGET_DEBUG, - }; -} -const char *Target_t::StringFromCPU( ETargetCPU cpu ) -{ - if ( cpu == TARGET_CPU_AMD64 ) - return "x86_64"; - if ( cpu == TARGET_CPU_80386 ) - return "i386"; - if ( cpu == TARGET_CPU_80486 ) - return "i486"; - if ( cpu == TARGET_CPU_80586 ) - return "i586"; - if ( cpu == TARGET_CPU_80686 ) - return "i686"; - if ( cpu == TARGET_CPU_AARCH64 ) - return "aarch64"; - if ( cpu == TARGET_CPU_WASM32 ) - return "wasm32"; - return NULL; -} - -const char *Target_t::StringFromKernel( ETargetKernel kernel ) -{ - if ( kernel == TARGET_KERNEL_UNKNOWN ) - return "unknown-unknown"; - if ( kernel == TARGET_KERNEL_UNKNOWN_LINUX ) - return "unknown-linux"; - if ( kernel == TARGET_KERNEL_PC_LINUX ) - return "pc-linux"; - if ( kernel == TARGET_KERNEL_ALPINE_LINUX ) - return "alpine-linux"; - if ( kernel == TARGET_KERNEL_WINDOWS ) - return "pc-windows"; - if ( kernel == TARGET_KERNEL_DARWIN ) - return "apple-darwin"; - if ( kernel == TARGET_KERNEL_IOS ) - return "apple-ios"; - if ( kernel == TARGET_KERNEL_ANDROID ) - return "linux-android"; - if ( kernel == TARGET_KERNEL_WASI ) - return "unknown-wasi"; - if ( kernel == TARGET_KERNEL_EMSCRIPTEN ) - return "unknown-emscripten"; - return NULL; -} - -const char *Target_t::StringFromABI( ETargetABI abi ) -{ - if ( abi == TARGET_ABI_GNU ) - return "gnu"; - if ( abi == TARGET_ABI_MUSL ) - return "musl"; - return NULL; -} - -ETargetCPU Target_t::CPUFromString( const char *szName ) -{ - CUtlString szUtlName = szName; - if ( szUtlName == "x86_64" ) - return TARGET_CPU_AMD64; - else if ( szUtlName == "i386" ) - return TARGET_CPU_80386; - else if ( szUtlName == "i486" ) - return TARGET_CPU_80486; - else if ( szUtlName == "i586" ) - return TARGET_CPU_80586; - else if ( szUtlName == "i686" ) - return TARGET_CPU_80686; - else if ( szUtlName == "aarch64" ) - return TARGET_CPU_AARCH64; - else if ( szUtlName == "wasm32" ) - return TARGET_CPU_WASM32; - return TARGET_CPU_UNDEFINED; -} - -ETargetKernel Target_t::KernelFromString( const char *szName ) -{ - CUtlString szUtlName = szName; - if ( szUtlName == "unknown" ) - return TARGET_KERNEL_UNKNOWN; - else if ( szUtlName == "windows" ) - return TARGET_KERNEL_WINDOWS; - else if ( szUtlName == "linux" ) - return TARGET_KERNEL_LINUX; - else if ( szUtlName == "unknown-linux" ) - return TARGET_KERNEL_UNKNOWN_LINUX; - else if ( szUtlName == "pc-linux" ) - return TARGET_KERNEL_PC_LINUX; - else if ( szUtlName == "alpine-linux" ) - return TARGET_KERNEL_ALPINE_LINUX; - else if ( szUtlName == "macos" ) - return TARGET_KERNEL_DARWIN; - else if ( szUtlName == "ios" ) - return TARGET_KERNEL_IOS; - else if ( szUtlName == "android" ) - return TARGET_KERNEL_ANDROID; - return TARGET_KERNEL_UNDEFINED; -} - -ETargetABI Target_t::ABIFromString( const char *szName ) -{ - CUtlString szUtlName = szName; - if ( szUtlName == "gnu" ) - return TARGET_ABI_GNU; - else if ( szUtlName == "musl" ) - return TARGET_ABI_MUSL; - return TARGET_ABI_UNDEFINED; -} - diff --git a/fpc/library/windows/c.cpp b/fpc/library/windows/c.cpp deleted file mode 100644 index 8e4395f..0000000 --- a/fpc/library/windows/c.cpp +++ /dev/null @@ -1,155 +0,0 @@ -#include "tier0/mem.h" -#include "winerunner.h" -#include "c.h" -#include "helper.h" -#include "obj.h" -#include "target.h" -#include "tier0/lib.h" -#include "tier0/mem.h" -#include "tier0/platform.h" -#include "tier0/commandline.h" -#include "tier1/interface.h" -#include "tier1/utlstring.h" -#include "tier1/utlvector.h" -#include "libgen.h" -#include "ctype.h" - -struct ClangFile_t -{ - CUtlString m_szName; - CUtlVector m_szArguments; -}; - -class CMSVCCompiler : public ICCompiler -{ -public: - - virtual void GenerateLinterData() override; -protected: - - virtual CUtlVector BuildCommandLine( CProject_t *pProject, const char *szFileName, const char *szOutputFileName ) override; - - // Returns executable which should the OS run - virtual const char *GetCompilerExecutable( CProject_t *pProject ) override; - - // returns object file format, eg .obj or .o - virtual const char *GetOutputObjectFormat() override; - - virtual void IncludeDirectory( CUtlVector &cmd, const char *szName ) override; - virtual void IncludeFile( CUtlVector &cmd, const char *szName ) override; - virtual void Macro( CUtlVector &cmd, const char *szName ) override; - virtual void Macro( CUtlVector &cmd, const char *szName, const char *szValue ) override; - - virtual void SetTarget( CUtlVector &cmd, CProject_t *pProject ) override; - virtual void SetSysroot( CUtlVector &cmd, CProject_t *pProject , const char *szSysroot ) override; - virtual void SetOutputFile( CUtlVector &cmd, const char *szName ) override; - virtual void CompileFile( CUtlVector &cmd, const char *szName ) override; - - virtual void EnableDebugSymbols( CUtlVector &cmd ) override; - virtual void EnablePIE( CUtlVector &cmd ) override; - virtual void EnablePIC( CUtlVector &cmd ) override; -}; - -const char *CMSVCCompiler::GetOutputObjectFormat() -{ - return ".o"; -} - -CUtlVector CMSVCCompiler::BuildCommandLine( CProject_t *pProject, const char *szFileName, const char *szOutputFileName ) -{ - CUtlVector cmd; - cmd = ICCompiler::BuildCommandLine(pProject, szFileName, szOutputFileName); - cmd.AppendHead("/c"); - return cmd; -} - - -const char *CMSVCCompiler::GetCompilerExecutable( CProject_t *pProject ) -{ - if (!g_pConfig) - Plat_FatalErrorFunc(".fpccfg was not found\n"); - static IINISection *pSection = g_pConfig->GetSection("MSVC_C_COMPILER_INTERFACE_NAME"); - if (!pSection) - Plat_FatalErrorFunc("MSVC_C_COMPILER_INTERFACE_NAME was not found in .fpccfg\n"); - static CUtlString szExePath = pSection->GetStringValue("exe"); - return szExePath; -} - - -void CMSVCCompiler::IncludeDirectory( CUtlVector &cmd, const char *szName ) -{ - cmd.AppendTail(CUtlString("/I%s",szName)); -} - -void CMSVCCompiler::IncludeFile( CUtlVector &cmd, const char *szName ) -{ -} - -void CMSVCCompiler::Macro( CUtlVector &cmd, const char *szName ) -{ -} - -void CMSVCCompiler::Macro( CUtlVector &cmd, const char *szName, const char *szValue ) -{ - cmd.AppendTail(CUtlString("/D%s=%s", (char*)szName, (char*)szValue)); -} - -void CMSVCCompiler::EnableDebugSymbols( CUtlVector &cmd ) -{ -} - -void CMSVCCompiler::SetTarget( CUtlVector &cmd, CProject_t *pProject ) -{ - -} - -void CMSVCCompiler::SetSysroot( CUtlVector &cmd, CProject_t *pProject , const char *szSysroot ) -{ - -} - -void CMSVCCompiler::CompileFile( CUtlVector &cmd, const char *szName ) -{ - cmd.AppendTail(szName); -} -void CMSVCCompiler::SetOutputFile( CUtlVector &cmd, const char *szName ) -{ - cmd.AppendTail("/Fo"); - cmd.AppendTail(szName); -} -void CMSVCCompiler::EnablePIE( CUtlVector &cmd ) -{ -} - -void CMSVCCompiler::EnablePIC( CUtlVector &cmd ) -{ -} - - -EXPOSE_INTERFACE(CMSVCCompiler, ICCompiler, MSVC_C_COMPILER_INTERFACE_NAME); - -void CMSVCCompiler::GenerateLinterData() -{ - /* - FILE* f = V_fopen("compile_commands.json", "wb"); - V_fprintf(f, "[\n"); - uint32_t i = 0; - for (auto &file: g_clangFiles) - { - V_fprintf(f, "\t{\n"); - V_fprintf(f, "\t\t\"arguments\": [\n"); - for (auto &arg: file.m_szArguments) - V_fprintf(f, "\t\t\t\"%s\",\n",arg.GetString()); - - V_fseek(f, -2, SEEK_CUR); - V_fprintf(f, "\n\t\t],\n"); - V_fprintf(f, "\t\t\"file\": \"%s\",\n", file.m_szName.GetString()); - V_fprintf(f, "\t\t\"directory\": \"%s\"\n", filesystem2->BuildDirectory()); - V_fprintf(f, "\t},\n"); - }; - V_fseek(f, -2, SEEK_CUR); - V_fprintf(f, "\n]\n"); - V_fclose(f); - */ -}; - diff --git a/fpc/library/windows/ld.cpp b/fpc/library/windows/ld.cpp deleted file mode 100644 index db4f9f3..0000000 --- a/fpc/library/windows/ld.cpp +++ /dev/null @@ -1,264 +0,0 @@ -#include "ld.h" -#include "helper.h" -#include "libgen.h" -#include "target.h" -#include "tier0/platform.h" -#include "tier1/interface.h" -#include "tier1/utlstring.h" -#include "tier2/fileformats/ini.h" -#include "winerunner.h" - -class CMSVCLinker : public ILinker -{ -public: - virtual CUtlString Link( LinkProject_t *pProject ) override; - virtual bool IsLibraryExists( CUtlString szName ) override; -protected: - // Returns executable which should the OS run - virtual const char *GetCompilerExecutable( LinkProject_t *pProject ) override; - - virtual void SetTarget( CUtlVector &cmd, LinkProject_t *pProject ) override; - virtual void SetSysroot( CUtlVector &cmd, LinkProject_t *pProject , const char *szSysroot ) override; - virtual void SetOutputFile( CUtlVector &cmd, const char *szOutput) override; - - - // sets rpath - // for windows should be ignored - virtual void SetDefaultLibraryPaths( CUtlVector &cmd, LinkProject_t *pProject ) override; - - virtual void UseStdLib( CUtlVector &cmd, bool bUse ) override; - - // windows doesn't use it as well - virtual void UseDynamicLookup( CUtlVector &cmd, bool bUse ) override; - - // includes whole file - virtual void UseFullFile( CUtlVector &cmd, LinkProject_t *pProject ) override; - - // includes used stuff in a file - virtual void UsePartialFile( CUtlVector &cmd, LinkProject_t *pProject ) override; - - virtual void LinkFile( CUtlVector &cmd, const char *szName ) override; - virtual void LinkLibraryObject( CUtlVector &cmd, const char *szName ) override; - virtual void LinkLibrary( CUtlVector &cmd, const char *szName ) override; - virtual void LinkLibraryPath( CUtlVector &cmd, const char *szName ) override; -}; - -const char *CMSVCLinker::GetCompilerExecutable( LinkProject_t *pProject ) -{ - -} - -void CMSVCLinker::SetTarget( CUtlVector &cmd, LinkProject_t *pProject ) -{ - -} - -void CMSVCLinker::SetSysroot( CUtlVector &cmd, LinkProject_t *pProject , const char *szSysroot ) -{ - -} - -void CMSVCLinker::SetOutputFile( CUtlVector &cmd, const char *szName ) -{ - -} - -void CMSVCLinker::SetDefaultLibraryPaths( CUtlVector &cmd, LinkProject_t *pProject ) -{ - -} - - -void CMSVCLinker::UseStdLib( CUtlVector &cmd, bool bUse ) -{ - -} - - -void CMSVCLinker::UseDynamicLookup( CUtlVector &cmd, bool bUse ) -{ - -} - - -void CMSVCLinker::UseFullFile( CUtlVector &cmd, LinkProject_t *pProject ) -{ - -} - - -void CMSVCLinker::UsePartialFile( CUtlVector &cmd, LinkProject_t *pProject ) -{ - -} - - -void CMSVCLinker::LinkFile( CUtlVector &cmd, const char *szName ) -{ - -} - -void CMSVCLinker::LinkLibraryObject( CUtlVector &cmd, const char *szName ) -{ - -} - -void CMSVCLinker::LinkLibrary( CUtlVector &cmd, const char *szName ) -{ - -} - -void CMSVCLinker::LinkLibraryPath( CUtlVector &cmd, const char *szName ) -{ - -} - -EXPOSE_INTERFACE(CMSVCLinker, ILinker, MSVC_LINKER_INTERFACE_NAME); - -CUtlString CMSVCLinker::Link( LinkProject_t *pProject ) -{ - if (pProject->m_szName == 0) - { - Plat_FatalErrorFunc("m_szName must be present\n"); - } - - if (pProject->m_target.kernel != TARGET_KERNEL_WINDOWS) - { - Plat_FatalErrorFunc("target must be TARGET_KERNEL_WINDOWS\n"); - } - - // Find a name for the file - CUtlString szFileName; - unsigned int hash = pProject->GenerateProjectHash(); - switch(pProject->linkType) - { - case ELINK_EXECUTABLE: - szFileName = CUtlString("%s.exe", pProject->m_szName.GetString()); - case ELINK_STATIC_LIBRARY: - szFileName = CUtlString("lib%s.a", pProject->m_szName.GetString()); - break; - case ELINK_DYNAMIC_LIBRARY: - szFileName = CUtlString("%s.dll", pProject->m_szName.GetString()); - break; - case ELINK_KERNEL_DRIVER: - szFileName = CUtlString("%s.sys", pProject->m_szName.GetString()); - break; - } - - CUtlString szTarget = pProject->m_target.GetTriplet(); - CUtlString szOutputFile = CUtlString("%s/%s/ld/%u_%s/%s",FPC_TEMPORAL_DIRNAME, szTarget.GetString(), hash, pProject->m_szName.GetString(), szFileName.GetString()); - CUtlString szOutputDir = szOutputFile; - szOutputDir = dirname(szOutputDir); - filesystem2->MakeDirectory(szOutputDir); - - if (!g_pConfig) - Plat_FatalErrorFunc(".fpccfg was not found\n"); - IINISection *pSection = g_pConfig->GetSection("MSVC_LINKER_INTERFACE_NAME"); - if (!pSection) - Plat_FatalErrorFunc("MSVC_LINKER_INTERFACE_NAME was not found in .fpccfg\n"); - CUtlString szExePath = pSection->GetStringValue("exe"); - if (!pSection) - Plat_FatalErrorFunc("exe was not found in MSVC_LINKER_INTERFACE_NAME\n"); - - if (pProject->linkType == ELINK_STATIC_LIBRARY) - { - V_printf(" AR %s\n", pProject->m_szName.GetString()); - bool shouldRecompile = false; - CUtlVector args; - for (auto object: pProject->objects) - { - if (filesystem2->ShouldRecompile(object.m_szObjectFile,szOutputFile)) - { - shouldRecompile = true; - break; - } - } - if (!shouldRecompile) - goto compiled; - args = { - "rcs", - szOutputFile - }; - for (auto object: pProject->objects) - args.AppendTail(object.m_szObjectFile); - runner->Run("ar", args); - runner->Wait(); - - } else { - V_printf(" LINK %s\n", pProject->m_szName.GetString()); - bool shouldRecompile = false; - CUtlVector args; - - // Check if any of the files have changed - for (auto object: pProject->objects) - { - if (filesystem2->ShouldRecompile(object.m_szObjectFile,szOutputFile)) - { - shouldRecompile = true; - break; - } - } - if (!shouldRecompile) - goto compiled; - - - CUtlString szTarget = pProject->m_target.GetTriplet(); - CUtlString szCompiledTarget = szTarget; - if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID) - { - szCompiledTarget = CUtlString("%s%u", szTarget.GetString(), pProject->m_androidmanifest.m_nTargetVersion); - } - - args = { - "/nologo" - }; - - const char *szWindowsPath = filesystem2->GetWindowsPath(szOutputFile); - args.AppendTail(CUtlString("/out:%s", szWindowsPath)); - V_free((void*)szWindowsPath); - - if (pProject->linkType == ELINK_KERNEL_DRIVER) - { - args.AppendTail("/driver"); - args.AppendTail(CUtlString("/entry:%s", pProject->szEntry)); - } - switch (pProject->m_eWindowsSubsystem) - { - case WINDOWS_SUBSYSTEM_NATIVE: - args.AppendTail("/subsystem:native"); - default: - break; - } - - // Disable stdlib - if (pProject->bNoStdLib) - { - } - - for (auto object: pProject->objects) - args.AppendTail(object.m_szObjectFile); - - for (auto lib: pProject->libraries) - { - /* - args.AppendTail("-l"); - args.AppendTail(lib); - */ - } - - winerunner->Run(szExePath, args); - winerunner->Wait(); - } -compiled: - return szOutputFile; -}; - -bool CMSVCLinker::IsLibraryExists( CUtlString szName ) -{ - szName = CUtlString("%s.dll", szName.GetString()); - void *pLib = Plat_LoadLibrary(szName.GetString()); - if (!pLib) - return false; - Plat_UnloadLibrary(pLib); - return true; -} diff --git a/fpc/library/windows/runner.cpp b/fpc/library/windows/runner.cpp deleted file mode 100644 index 3eeeb50..0000000 --- a/fpc/library/windows/runner.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "runner.h" -#include "tier0/platform.h" -#include "tier0/commandline.h" -#include "tier1/interface.h" -#include "tier1/utlstring.h" -#include "tier1/utlvector.h" -#include "windows.h" - - -class CWindowsRunner: public IRunner -{ -public: - virtual int Run( CUtlString szName, CUtlVector& args ) override; - virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector& args ) override; - virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector& args, CUtlVector& environment ) override; - virtual int Wait( void ) override; - CUtlVector s_processes = {}; -}; - -EXPOSE_INTERFACE(CWindowsRunner, IRunner, POSIX_RUNNER_INTERFACE_NAME); -IRunner *runner; - -int CWindowsRunner::Run(CUtlString szName, CUtlVector& args) -{ - pid_t pid = fork(); - if (pid < 0) - Plat_FatalErrorFunc("Failed to fork"); - /* child */ - if (pid == 0) - { - CUtlVector execargs; - execargs.AppendTail(szName); - if (CommandLine()->CheckParam("-fpcdebug")) - V_printf("%s",szName.GetString()); - for (auto &arg: args) - { - execargs.AppendTail(arg); - if (CommandLine()->CheckParam("-fpcdebug")) - V_printf(" %s",arg.GetString()); - } - if (CommandLine()->CheckParam("-fpcdebug")) - V_printf("\n"); - execargs.AppendTail(0); - if ( execvp(szName, (char *const*)execargs.GetData()) == -1 ) - { - V_printf("Failed to launch %s\n",szName.GetString()); - _exit(0); - } - } - s_processes.AppendTail(pid); - return 0; -} - -int CWindowsRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector& args) -{ - pid_t pid = fork(); - if (pid < 0) - Plat_FatalErrorFunc("Failed to fork"); - /* child */ - if (pid == 0) - { - CUtlVector execargs; - execargs.AppendTail(szName); - if (CommandLine()->CheckParam("-fpcdebug")) - V_printf("%s",szName.GetString()); - for (auto &arg: args) - { - execargs.AppendTail(arg); - if (CommandLine()->CheckParam("-fpcdebug")) - V_printf(" %s",arg.GetString()); - } - if (CommandLine()->CheckParam("-fpcdebug")) - V_printf("\n"); - execargs.AppendTail(0); - chdir(szDirectory.GetString()); - if ( execvp(szName, (char *const*)execargs.GetData()) == -1 ) - { - V_printf("Failed to launch %s\n",szName.GetString()); - _exit(0); - } - } - s_processes.AppendTail(pid); - /* parent */ - return 0; -} - -int CWindowsRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector& args, CUtlVector& environment) -{ - -} - -int CWindowsRunner::Wait( void ) -{ - for (auto &process: s_processes) - { - int status; - pid_t wpid = waitpid(process, &status, 0); - } - s_processes = {}; - return 0; -}; diff --git a/fpc/library/windows/windres.cpp b/fpc/library/windows/windres.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/fpc/library/winerunner.cpp b/fpc/library/winerunner.cpp deleted file mode 100644 index 7602f0a..0000000 --- a/fpc/library/winerunner.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "runner.h" -#include "winerunner.h" -#include "tier0/platform.h" -#include "tier1/interface.h" -#include "tier1/utlstring.h" -#include "tier1/utlvector.h" -#include "unistd.h" -#include "sys/wait.h" -#include "tier0/commandline.h" - -class CWineRunner: public IWineRunner -{ -public: - CWineRunner(); - ~CWineRunner(); - - virtual int Run( CUtlString szName, CUtlVector& args ) override; - virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector& args ) override; - virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector& args, CUtlVector& environment ) override; - virtual int Wait( void ) override; -private: - pid_t m_wineServerPID; -}; - -EXPOSE_INTERFACE(CWineRunner, IWineRunner, WINE_RUNNER_INTERFACE_NAME); - -CWineRunner::CWineRunner() -{ - -} -CWineRunner::~CWineRunner() -{ - -} - -int CWineRunner::Run(CUtlString szName, CUtlVector& args) -{ - return runner->Run(szName, args); -} - -int CWineRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector& args) -{ - CUtlVector args2 = args; - args2.AppendHead(szName); - return runner->Run("wine", szDirectory, args2); -} - -int CWineRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector& args, CUtlVector& environment) -{ - CUtlVector args2 = args; - args2.AppendHead(szName); - return runner->Run("wine", szDirectory, args2, environment); -} - -int CWineRunner::Wait( void ) -{ - return runner->Wait(); -}; diff --git a/fpc/main.cpp b/fpc/main.cpp deleted file mode 100644 index 7d9cb6c..0000000 --- a/fpc/main.cpp +++ /dev/null @@ -1,173 +0,0 @@ -#include "tier0/platform.h" -#include "tier0/rand.h" -#include "tier0/commandline.h" -#include "tier1/interface.h" -#include "tier1/utlvector.h" -#include "tier1/utlstring.h" -#include "tier2/ifilesystem.h" -#include "tier2/fileformats/ini.h" -#include "public/c.h" -#include "public/helper.h" -#include "public/ld.h" -#include "public/target.h" -#include "runner.h" -#include "winerunner.h" -#include "c.h" -#include "signal.h" -#include "libgen.h" -#include "builder.h" - -CUtlString owndir; -static char **pszBuildDir; - -void build_tier0() -{ - -}; - -int build() -{ - BuildFile_t *pBuildFile = ProjectBuilder()->BuildProject("main",CUtlString("%s/build.cpp",*pszBuildDir)); - - /* - - LinkProject_t linkScriptProject = ccompiler->Compile(&compileScriptProject); - linkScriptProject.linkType = ELINK_DYNAMIC_LIBRARY; - linkScriptProject.m_target = Target_t::HostTarget(); - - CUtlString script = linker->Link(&linkScriptProject); - - - void *scriptDLL = Plat_LoadLibrary(script); - pBuildFactory = Sys_GetFactory(scriptDLL); - - - pBuildFactory = NULL; - pBuildFileInfo = (BuildFileInfo_t*)pBuildFactory(BUILD_FILE_INFO_INTERFACE_NAME, NULL); - if (!pBuildFactory) - Plat_FatalErrorFunc("Failed to find build file info interface\n"); - - auto PreinitFn = (void(*)())Plat_GetProc(scriptDLL, "Preinit"); - if (PreinitFn) - PreinitFn(); - - for (auto &build: pBuildFileInfo->m_stages) - { - build->m_pMainFn(); - }; - */ - - ccompiler->GenerateLinterData(); - - return 0; -}; - - -void IEngine_Signal(int sig) -{ - switch (sig) - { - case SIGSEGV: - case SIGILL: - case SIGABRT: - Plat_Backtrace(); - Plat_FatalErrorFunc("Fault\n"); - break; - case SIGINT: - Plat_Exit(0); - break; - default: - break; - }; - Plat_Exit(0); -}; - -IRunner *runner; -IWineRunner *winerunner; -ICCompiler *ccompiler; -ILinker *linker; - - -int main(int c, char **v) -{ - - char path[1024]; - - CUtlString buildcppDir = Plat_GetWorkingDir(); - owndir = buildcppDir; - char *szBuildcppDir = buildcppDir.GetString(); - -findbuild: - FILE* file = V_fopen("build.cpp", "rb"); - if (!file) - { - buildcppDir = buildcppDir.GetDirectory(); - if (buildcppDir=="/") - { - V_printf("build.cpp not found\n"); - return 0; - } - Plat_SetWorkingDir(szBuildcppDir); - goto findbuild; - } else { - V_fclose(file); - } - - #ifdef __linux - signal(SIGHUP, IEngine_Signal); - signal(SIGINT, IEngine_Signal); - signal(SIGQUIT, IEngine_Signal); - signal(SIGILL, IEngine_Signal); - signal(SIGTRAP, IEngine_Signal); - signal(SIGIOT, IEngine_Signal); - signal(SIGBUS, IEngine_Signal); - signal(SIGFPE, IEngine_Signal); - signal(SIGSEGV, IEngine_Signal); - signal(SIGTERM, IEngine_Signal); - #endif - - - void *pLibFPC = Plat_LoadLibrary("libfpc.so"); - CreateInterfaceFn pLibFPCFactory = Sys_GetFactory(pLibFPC); - - filesystem2 = (IFileSystem2*)pLibFPCFactory(FILE_SYSTEM_2_INTERFACE_NAME, NULL); - pszBuildDir = (char**)pLibFPCFactory(FILE_SYSTEM_2_BUILD_DIRECTORY_INTERFACE_VERSION, NULL); - *pszBuildDir = szBuildcppDir; - runner = (IRunner*)pLibFPCFactory(RUNNER_INTERFACE_NAME, NULL); - winerunner = (IWineRunner*)pLibFPCFactory(WINE_RUNNER_INTERFACE_NAME, NULL); - ccompiler = (ICCompiler*)pLibFPCFactory(CLANG_C_COMPILER_INTERFACE_NAME, NULL); - linker = (ILinker*)pLibFPCFactory(CLANG_LINKER_INTERFACE_NAME, NULL); - - - - pLibFPCFactory(LIBFPC_INIT_INTERFACE_VERSION, NULL); - - - void *pFilesystem = Plat_LoadLibrary("libfilesystem_std.so"); - CreateInterfaceFn pFilesystemFactory = Sys_GetFactory(pFilesystem); - - filesystem = (IFileSystem*)pFilesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL); - filesystem->Init(); - - g_pConfig = INIManager()->ReadFile(".fpccfg"); - - IINIFile **ppConfig = (IINIFile**)pLibFPCFactory(LIBFPC_CONFIG_INTERFACE_VERSION, NULL); - *ppConfig = g_pConfig; - - CommandLine()->CreateCommandLine(c, v); - Plat_InitRandom(); - - if (CommandLine()->CheckParam("-v") || CommandLine()->CheckParam("--version")) - { - V_printf("fpc version v1\n"); - V_printf("built " __DATE__ " " __TIME__ "\n"); - V_printf("built for %s\n", Target_t::HostTarget().GetTriplet().GetString()); - return 0; - } - - if (CommandLine()->CheckParam("build")) - build(); - const char *szDeployDevice = CommandLine()->ParamValue("deploy"); - Plat_ShutdownRandom(); - return 0; -}; diff --git a/fpc/public/apktool.h b/fpc/public/apktool.h deleted file mode 100644 index 8a64624..0000000 --- a/fpc/public/apktool.h +++ /dev/null @@ -1,45 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Set Android metadata aboth the package. -//===========================================================================// - -#ifndef APK_TOOL_H -#define APK_TOOL_H - -#include "tier0/platform.h" -#include "tier1/utlstring.h" -#include "legal.h" - -struct AndroidManifest_t -{ -public: - void SetPackageVersion( CUtlString szVersion ); - void SetPackageBuild( uint64_t nBuild ); - void SetPackageID( CUtlString szPackageID ); - void SetPackageName( CUtlString szPackageName ); - - void SetTargetSDKVersion( uint64_t nTargetVersion ); - void SetMinSDKVersion( uint64_t nMinVersion ); - - void AddUserFeature( CUtlString szName, bool bIsRequired, uint64_t nVersion ); - void AddUserLibrary( CUtlString szPath ); - CUtlString BuildManifest(); - - CUtlString m_szPackageName; - CUtlString m_szPackageID; - uint64_t m_nBuild; - CUtlString m_szVersion; - - uint64_t m_nTargetVersion; - uint64_t m_nMinVersion; -}; - -abstract_class IAPKTool -{ -public: - virtual CUtlString BuildPackage( AndroidManifest_t manifest, CUtlString szManifestDir ) = 0; - virtual CUtlString SignPackage( const char *szApk, LegalInfo_t *pLegalInfo, const char *szAlias, const char *szStorePassword, const char *szKeyPassword ) = 0; -}; - -IAPKTool *APKTool(); - -#endif diff --git a/fpc/public/appletool.h b/fpc/public/appletool.h deleted file mode 100644 index 18f0040..0000000 --- a/fpc/public/appletool.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef Apple_TOOL_H -#define Apple_TOOL_H - -#include "tier0/platform.h" -#include "tier1/utlstring.h" -#include "legal.h" - -struct AppleManifest_t -{ -public: - void SetPackageID( CUtlString szPackageID ); - void SetPackageName( CUtlString szPackageName ); - void SetPackageExecutable( CUtlString szPackageExecutable ); - - CUtlString BuildManifest(); - - CUtlString m_szPackageName; - CUtlString m_szPackageID; - CUtlString m_szPackageExecutable; -}; - -abstract_class IAppleTool -{ -public: - virtual CUtlString BuildPackage( AppleManifest_t manifest, CUtlString szManifestDir ) = 0; - virtual CUtlString SignPackage( const char *szIpa, const char *szPassword ) = 0; -}; - - -IAppleTool *AppleTool(); - -#endif - diff --git a/fpc/public/builder.h b/fpc/public/builder.h deleted file mode 100644 index c9f75d7..0000000 --- a/fpc/public/builder.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef BUILDER_H -#define BUILDER_H - -#include "tier1/interface.h" -#include "tier1/utlvector.h" -#include "tier1/utlstring.h" - -struct BuildOutput_t -{ - const char *m_szName; -}; - -struct BuildOutputs_t -{ - const char *m_szBuildStageName; - CUtlVector m_buildOutputs; -}; - -struct BuildFile_t -{ - CUtlString m_szOutputFile; - void *m_pLibrary; - CUtlVector m_compiledProjects; - - struct BuildFile_t *m_pNext; -}; - -abstract_class IProjectBuilder -{ -public: - virtual BuildFile_t *BuildProject( const char *szProjectName, const char *szPath ) = 0; -}; - -IProjectBuilder *ProjectBuilder(); - -#define PROJECT_BUILDER_INTERFACE_NAME "ProjectBuilder001" - -#endif diff --git a/fpc/public/c.h b/fpc/public/c.h deleted file mode 100644 index ae996e3..0000000 --- a/fpc/public/c.h +++ /dev/null @@ -1,128 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: C, C++, Objective-C and Objective-C++ compiler interface. -//===========================================================================// - -#ifndef C_H -#define C_H - -#include "tier0/platform.h" -#include "tier1/utlstring.h" -#include "tier1/utlvector.h" -#include "runner.h" -#include "ld.h" -#include "target.h" -#include "helper.h" - -struct C_Macro_t -{ - CUtlString szName; - CUtlString szValue; -}; - - -// Target C version -enum ECVersion -{ - CVERSION_89, - CVERSION_99 = 0, - CVERSION_11, - CVERSION_17, - CVERSION_23, - CVERSION_2Y, -}; - -// Target C++ version -enum ECPPVersion -{ - CPPVERSION_98 = 0, - CPPVERSION_11 = 1, - CPPVERSION_14 = 2, - CPPVERSION_17 = 3, - CPPVERSION_20 = 4, - CPPVERSION_23 = 5, - CPPVERSION_2C = 6, -}; - -//---------------------------------------------------------------------------- -// C project settings used in compilation -// Example usage: -// CProject_t compileProject = {}; -// LinkProject_t ldProject = {}; -// -// compileProject.m_szName = "your project name"; -// compileProject.files = g_CompiledFiles; -// compileProject.includeDirectories = g_IncludeDirectories; -// ldProject = ccompiler->Compile(&compileProject); -//---------------------------------------------------------------------------- -struct CProject_t : public CPUProject_t -{ -public: - // Compiled files - CUtlVector files = {}; - - // Included directories - CUtlVector includeDirectories = {}; - - // Included files - // They are included on top of the file - CUtlVector includeFiles = {}; - - // Defined macros - CUtlVector macros = {}; - - // Target C version - ECVersion cVersion; - - // Target C++ version - ECPPVersion cppVersion; -}; - -// Basic interface name -#define C_COMPILER_INTERFACE_NAME "CCompiler001" -#define CLANG_C_COMPILER_INTERFACE_NAME "Clang" C_COMPILER_INTERFACE_NAME -#define GNU_C_COMPILER_INTERFACE_NAME "GNU" C_COMPILER_INTERFACE_NAME -#define MSVC_C_COMPILER_INTERFACE_NAME "MSVC" C_COMPILER_INTERFACE_NAME - -class ICCompiler -{ -public: - - // Compiles all files into objects, returns linker project, - // which can be linked into executable or library. - virtual LinkProject_t Compile( CProject_t *pProject ); - - virtual void GenerateLinterData() = 0; -protected: - // Compiler internals - - // Returns file name of the - CUtlString GetOutputObjectName( CProject_t *pProject, unsigned int hash, CUtlString szFileName ); - - virtual CUtlVector BuildCommandLine( CProject_t *pProject, const char *szFileName, const char *szOutputFileName ); - - // Returns executable which should the OS run - virtual const char *GetCompilerExecutable( CProject_t *pProject ) = 0; - - // returns object file format, eg .obj or .o - virtual const char *GetOutputObjectFormat() = 0; - - virtual void IncludeDirectory( CUtlVector &cmd, const char *szName ) = 0; - virtual void IncludeFile( CUtlVector &cmd, const char *szName ) = 0; - virtual void Macro( CUtlVector &cmd, const char *szName ) = 0; - virtual void Macro( CUtlVector &cmd, const char *szName, const char *szValue ) = 0; - - virtual void SetTarget( CUtlVector &cmd, CProject_t *pProject ) = 0; - virtual void SetSysroot( CUtlVector &cmd, CProject_t *pProject , const char *szSysroot ) = 0; - virtual void SetOutputFile( CUtlVector &cmd, const char *szName ) = 0; - - virtual void CompileFile( CUtlVector &cmd, const char *szName ) = 0; - - virtual void EnableDebugSymbols( CUtlVector &cmd ) = 0; - virtual void EnablePIE( CUtlVector &cmd ) = 0; - virtual void EnablePIC( CUtlVector &cmd ) = 0; - -}; - -extern ICCompiler *ccompiler; - -#endif diff --git a/fpc/public/deploy.h b/fpc/public/deploy.h deleted file mode 100644 index 9cb4f7e..0000000 --- a/fpc/public/deploy.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef DEPLOY_H -#define DEPLOY_H - -#include "tier0/platform.h" -#include "tier1/utlstring.h" - -abstract_class IDeployDevice -{ -public: - virtual const char *GetName() = 0; - virtual void *Install( const char *szPath ) = 0; -}; - -abstract_class IDeployDeviceManager -{ -public: - virtual void AddDevice( IDeployDevice *pDevice ) = 0; - virtual IDeployDevice *FindDeviceByName( const char *szDeviceName ) = 0; - virtual const CUtlVector &ListDevices() = 0; -}; - -IDeployDeviceManager *DeployDeviceManager(); - - -#endif diff --git a/fpc/public/generator.h b/fpc/public/generator.h deleted file mode 100644 index e69de29..0000000 diff --git a/fpc/public/helper.h b/fpc/public/helper.h deleted file mode 100644 index 6bce7f8..0000000 --- a/fpc/public/helper.h +++ /dev/null @@ -1,164 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Helper functions for compilers, filesystem2 and build stages. -//===========================================================================// - -#ifndef HELPER_H -#define HELPER_H - -#include "apktool.h" -#include "tier1/utlstring.h" -#include "target.h" -#include "tier2/fileformats/ini.h" -#include "tier1/interface.h" - -#define FPC_TEMPORAL_DIRNAME ".fpc" - -//----------------------------------------------------------------------------- -// A base for all projects -//----------------------------------------------------------------------------- -struct BaseProject_t -{ -public: - CUtlString m_szName; - // Creates a hash for the project - unsigned int GenerateProjectHash( void ); -}; - -//----------------------------------------------------------------------------- -// A base for cpu projects -//----------------------------------------------------------------------------- -struct CPUProject_t : public BaseProject_t -{ -public: - Target_t m_target = Target_t::DefaultTarget(); - - // Is compiled as position independent executable - bool bFPIE = false; - - // Is compiled as position independent code - // Use for shared libraries - bool bFPIC = false; - - // TODO: rework manifests - // Android manifest - AndroidManifest_t m_androidmanifest = {}; -}; - -//----------------------------------------------------------------------------- -// A base for shader projects -//----------------------------------------------------------------------------- -struct ShaderProject_t : public BaseProject_t -{ -public: - EShaderTarget m_eTarget; -}; - -//----------------------------------------------------------------------------- -// File system manager. -//----------------------------------------------------------------------------- -#define FILE_SYSTEM_2_INTERFACE_NAME "FileSystem2_001" -#define FILE_SYSTEM_2_BUILD_DIRECTORY_INTERFACE_VERSION "FileSystem2BuildDirectory_001" - -abstract_class IFileSystem2 -{ -public: - // Returns a directory of fpc executable - virtual char *OwnDirectory() = 0; - - // Returns directory of build.cpp - virtual char *BuildDirectory() = 0; - - // Creates new directory at path - virtual void MakeDirectory( const char *psz ) = 0; - - // UNIX-style file copy - virtual void CopyFile( const char *szDestination, const char *szOrigin ) = 0; - - // UNIX-style recursive directory copy - virtual void CopyDirectory( const char *szDestination, const char *szOrigin ) = 0; - - // Compares timestamps of 2 files - virtual bool ShouldRecompile( const char *szSource, const char *szOutput ) = 0; - - virtual char *GetWindowsPath( const char *szPath ) = 0; - virtual char *GetPOSIXPath( const char *szPath ) = 0; -}; - -extern IFileSystem2 *filesystem2; - -struct StageOutput_t -{ - const char *m_szName; - CUtlString m_szPath; -}; - -//----------------------------------------------------------------------------- -// Build stage. -//----------------------------------------------------------------------------- -class CBuildStage -{ -public: - CBuildStage( const char *psz, int(*pMainFn)() ); - const char *m_psz; - CUtlString m_szPath; - CUtlVector m_outputs; - int(*m_pMainFn)(); -}; - - -class CBuildDependentFile -{ -public: - CBuildDependentFile( const char *psz ); -}; - -//----------------------------------------------------------------------------- -// Declares new build stage. -// example: -// DECLARE_BUILD_STAGE(your_build_stage_name) -// { -// return 0; -// } -//----------------------------------------------------------------------------- -#define DECLARE_BUILD_STAGE(sz) \ -static int __build_stage_##sz(); \ -static CBuildStage __##sz##_build_stage(#sz, __build_stage_##sz); \ -static int __build_stage_##sz() - -#define ADD_DEPENDENCY_BUILD_FILE(name, path) \ -static CBuildDependentFile __##name##DependencyFile(path); - -#define ADD_OUTPUT_OBJECT(sz, path) \ - g_pCurrentStage->m_outputs.AppendTail((StageOutput_t){sz, path}); - -#define DEPEND_ON_PROJECT(sz) \ - -#define GET_PROJECT_LIBRARY(sz, szLib) \ - FPC_GetProjectObject(#sz, szLib) - - -struct BuildFileInfo_t -{ - CUtlVector m_dependantFiles; - CUtlVector m_stages; -}; - -BuildFileInfo_t *GetBuildFileInfo(); -extern CBuildStage *g_pCurrentStage; - -CUtlString FPC_GetProjectObject( const char *szName, const char *szObjectName ); - - -#define BUILD_FILE_INFO_INTERFACE_VERSION "BuildFileInfo001" -#define BUILD_CURRENT_STAGE_INTERFACE_VERSION "BuildCurrentStage001" - -typedef CUtlString(*GetProjectObjectFn)( const char *szName, const char *szObjectName ); -#define BUILD_GET_PROJECT_OBJECT_INTERFACE_VERSION "GetProjectObject001" - -#define LIBFPC_INIT_INTERFACE_VERSION "LibFPCInit001" - - -extern IINIFile *g_pConfig; -#define LIBFPC_CONFIG_INTERFACE_VERSION "LibFPCConfig001" - -#endif diff --git a/fpc/public/iostool.h b/fpc/public/iostool.h deleted file mode 100644 index d6004ea..0000000 --- a/fpc/public/iostool.h +++ /dev/null @@ -1,26 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Automatic signature generator for iOS, Android and other devices, -// which require signed executables, files etc. -//===========================================================================// - -#ifndef SIGN_TOOL_H -#define SIGN_TOOL_H - -#include "tier0/platform.h" -#include "tier1/utlstring.h" - -#define APPLE_SIGN_TOOL_INTERFACE_NAME "SignToolApple001" -#define ANDROID_SIGN_TOOL_INTERFACE_NAME "SignToolAndroid001" - -abstract_class ISignTool -{ -public: - virtual void SetSignPassword( CUtlString szPassword ) = 0; - virtual void SignFile( CUtlString szFile ) = 0; - virtual void SignDirectory( CUtlString szDirectory ) = 0; -}; - -extern ISignTool *signtool_android; -extern ISignTool *signtool_apple; - -#endif diff --git a/fpc/public/ld.h b/fpc/public/ld.h deleted file mode 100644 index f4d1de7..0000000 --- a/fpc/public/ld.h +++ /dev/null @@ -1,135 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Linker interface. -//===========================================================================// - -#ifndef LD_H -#define LD_H - - -#include "runner.h" -#include "helper.h" -#include "obj.h" -#include "tier0/platform.h" -#include "tier1/utlstring.h" - -enum ELinkType -{ - ELINK_EXECUTABLE, - ELINK_DYNAMIC_LIBRARY, - ELINK_STATIC_LIBRARY, - - // drivers - ELINK_KERNEL_DRIVER -}; - -enum EWindowsSubsystem -{ - WINDOWS_SUBSYSTEM_NATIVE, -}; - -//---------------------------------------------------------------------------- -// C project settings used in compilation -// Example usage: -// CProject_t compileProject = {}; -// LinkProject_t ldProject = {}; -// CUtlString szOutputFile; -// -// compileProject.m_szName = "your_project_name"; -// compileProject.files = g_CompiledFiles; -// compileProject.includeDirectories = g_IncludeDirectories; -// -// ldProject = ccompiler->Compile(&compileProject); -// ldProject.linkType = ELINK_EXECUTABLE -// szOutputFile = linker->Link(&ldProject); -// -//---------------------------------------------------------------------------- -struct LinkProject_t: public CPUProject_t -{ -public: - void AddObject( Object_t object ); - - // output file - ELinkType linkType; - - // objects, they could be libraries and compiled files - CUtlVector objects = {}; - - // system libraries - CUtlVector libraries ={}; - - // directories for libraries - CUtlVector libraryDirectories = {}; - - // not used - CUtlVector libraryObjects = {}; - - // Apple framework directories - CUtlVector frameworkDirectories = {}; - - const char *szEntry = ""; - - // Disables C standart library - bool bNoStdLib; - - // Apple frameworks - CUtlVector frameworks = {}; - - // Windows subsystem - EWindowsSubsystem m_eWindowsSubsystem; -}; - -// Basic interface name -#define LINKER_INTERFACE_NAME "Linker001" -#define CLANG_LINKER_INTERFACE_NAME "Clang" LINKER_INTERFACE_NAME -#define MSVC_LINKER_INTERFACE_NAME "MSVC" LINKER_INTERFACE_NAME - -abstract_class ILinker -{ -public: - - // Links project - virtual CUtlString Link( LinkProject_t *pProject ); - - virtual bool IsLibraryExists( CUtlString szName ) = 0; - -protected: - // Link - // Returns file name of the - CUtlString GetOutputObjectName( LinkProject_t *pProject, unsigned int hash, CUtlString szFileName ); - - virtual CUtlVector BuildLinkCommandLine( LinkProject_t *pProject, const char *szOutputFileName ); - virtual CUtlVector BuildArchiveCommandLine( LinkProject_t *pProject, const char *szOutputFileName ); - - // Returns executable which should the OS run - virtual const char *GetCompilerExecutable( LinkProject_t *pProject ) = 0; - - virtual void SetTarget( CUtlVector &cmd, LinkProject_t *pProject ) = 0; - virtual void SetSysroot( CUtlVector &cmd, LinkProject_t *pProject , const char *szSysroot ) = 0; - virtual void SetOutputFile( CUtlVector &cmd, const char *szName ) = 0; - - - // sets rpath - // for windows should be ignored - virtual void SetDefaultLibraryPaths( CUtlVector &cmd, LinkProject_t *pProject ) = 0; - - virtual void UseStdLib( CUtlVector &cmd, bool bUse ) = 0; - - // windows doesn't use it as well - virtual void UseDynamicLookup( CUtlVector &cmd, bool bUse ) = 0; - - // includes whole file - virtual void UseFullFile( CUtlVector &cmd, LinkProject_t *pProject ) = 0; - - // includes used stuff in a file - virtual void UsePartialFile( CUtlVector &cmd, LinkProject_t *pProject ) = 0; - - virtual void LinkFile( CUtlVector &cmd, const char *szName ) = 0; - virtual void LinkLibraryObject( CUtlVector &cmd, const char *szName ) = 0; - virtual void LinkLibrary( CUtlVector &cmd, const char *szName ) = 0; - virtual void LinkLibraryPath( CUtlVector &cmd, const char *szName ) = 0; - -}; - -extern ILinker *linker; - -#endif diff --git a/fpc/public/legal.h b/fpc/public/legal.h deleted file mode 100644 index 9097751..0000000 --- a/fpc/public/legal.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef LEGAL_H -#define LEGAL_H - -struct LegalInfo_t -{ - const char *FirstName; - const char *LastName; - const char *OrganizationalUnitName; - const char *OrganizationName; - const char *City; - const char *State; - const char *CountryCode; -}; - - -#endif diff --git a/fpc/public/lsp.h b/fpc/public/lsp.h deleted file mode 100644 index af98124..0000000 --- a/fpc/public/lsp.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef LSP_H -#define LSP_H - -#include "tier0/platform.h" - -abstract_class IBasicLSP -{ - virtual void GenerateConfig() = 0; -}; - -#endif diff --git a/fpc/public/obj.h b/fpc/public/obj.h deleted file mode 100644 index b4b32b3..0000000 --- a/fpc/public/obj.h +++ /dev/null @@ -1,17 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Object handler. -//===========================================================================// - -#ifndef OBJ_H -#define OBJ_H - -#include "tier1/utlstring.h" - -struct Object_t -{ -public: - CUtlString m_szObjectFile; - CUtlString m_szSourceFile; -}; - -#endif diff --git a/fpc/public/runner.h b/fpc/public/runner.h deleted file mode 100644 index ff079ed..0000000 --- a/fpc/public/runner.h +++ /dev/null @@ -1,27 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Executable runner. It is mainly used to run compilers and linkers, -// but can be used to run anything with given executable name -//===========================================================================// - -#ifndef RUNNER_H -#define RUNNER_H - -#include "tier0/platform.h" -#include "tier1/utlvector.h" -#include "tier1/utlstring.h" - -#define RUNNER_INTERFACE_NAME "Runner001" - -abstract_class IRunner -{ -public: - virtual int Run( CUtlString szName, CUtlVector& args ) = 0; - virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector& args ) = 0; - virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector& args, CUtlVector& environment ) = 0; - virtual int Wait( void ) = 0; -}; - - -extern IRunner *runner; - -#endif diff --git a/fpc/public/signer.h b/fpc/public/signer.h deleted file mode 100644 index d822e08..0000000 --- a/fpc/public/signer.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef SIGNER_H -#define SIGNER_H - -#include "c.h" -#include "ld.h" -#include "helper.h" -#include "tier0/platform.h" -#include "tier1/interface.h" -#include "tier0/platform.h" - -#endif diff --git a/fpc/public/slang.h b/fpc/public/slang.h deleted file mode 100644 index e69de29..0000000 diff --git a/fpc/public/swift.h b/fpc/public/swift.h deleted file mode 100644 index 41df23d..0000000 --- a/fpc/public/swift.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef SWIFT_H -#define SWIFT_H - -#include "tier0/platform.h" -#include "tier1/utlstring.h" -#include "tier1/utlvector.h" -#include "runner.h" -#include "ld.h" -#include "c.h" -#include "target.h" -#include "helper.h" - -struct SwiftProject_t : public CPUProject_t -{ -public: - // Compiled files - CUtlVector files = {}; - - // Included directories - CUtlVector includeDirectories = {}; - - // Included files - CUtlVector includeObjcFiles = {}; - - // Stuff for embedded objc - // Included files - // They are included on top of the file - CUtlVector includeFiles = {}; - - // Stuff for embedded objc - // Defined macros - CUtlVector macros = {}; - - // Stuff for embedded objc - // Target C version - ECVersion cVersion; - - // Stuff for embedded objc - // Target C++ version - ECPPVersion cppVersion; -}; - -#define SWIFT_COMPILER_INTERFACE_VERSION "SwiftCompiler001" - -class ISwiftCompiler -{ -public: - - // Compiles all files into objects, returns linker project, - // which can be linked into executable or library. - virtual LinkProject_t Compile( SwiftProject_t *pProject ); - - //virtual void GenerateLinterData() = 0; -protected: - // Compiler internals - - // Returns file name of the - CUtlString GetOutputObjectName( SwiftProject_t *pProject, unsigned int hash, CUtlString szFileName ); - - virtual CUtlVector BuildCommandLine( SwiftProject_t *pProject, const char *szFileName, const char *szOutputFileName ); - - // Returns executable which should the OS run - virtual const char *GetCompilerExecutable( SwiftProject_t *pProject ) = 0; - - // returns object file format, eg .obj or .o - virtual const char *GetOutputObjectFormat() = 0; - - virtual void IncludeDirectory( CUtlVector &cmd, const char *szName ) = 0; - virtual void IncludeFile( CUtlVector &cmd, const char *szName ) = 0; - virtual void Macro( CUtlVector &cmd, const char *szName ) = 0; - virtual void Macro( CUtlVector &cmd, const char *szName, const char *szValue ) = 0; - - virtual void SetTarget( CUtlVector &cmd, SwiftProject_t *pProject ) = 0; - virtual void SetSysroot( CUtlVector &cmd, SwiftProject_t *pProject , const char *szSysroot ) = 0; - virtual void SetOutputFile( CUtlVector &cmd, const char *szName ) = 0; - - virtual void CompileFile( CUtlVector &cmd, const char *szName ) = 0; - - virtual void EnableDebugSymbols( CUtlVector &cmd ) = 0; - virtual void EnablePIE( CUtlVector &cmd ) = 0; - virtual void EnablePIC( CUtlVector &cmd ) = 0; -}; - - -extern ISwiftCompiler *swiftcompiler; - -#endif diff --git a/fpc/public/sysrootfetch.h b/fpc/public/sysrootfetch.h deleted file mode 100644 index 50c55b1..0000000 --- a/fpc/public/sysrootfetch.h +++ /dev/null @@ -1,3 +0,0 @@ -#ifndef SYSROOT_FETCH_H -#define SYSROOT_FETCH_H -#endif diff --git a/fpc/public/target.h b/fpc/public/target.h deleted file mode 100644 index 0520c51..0000000 --- a/fpc/public/target.h +++ /dev/null @@ -1,94 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Target manager for compilers. -//===========================================================================// - -#ifndef TARGET_T -#define TARGET_T - -#include "tier0/commandline.h" -#include "tier1/utlstring.h" - -enum ETargetKernel -{ - TARGET_KERNEL_UNDEFINED, - TARGET_KERNEL_UNKNOWN = 1, - - TARGET_KERNEL_WINDOWS_DEVICES = 0x100, - TARGET_KERNEL_WINDOWS, - - TARGET_KERNEL_POSIX = 0x10000, - TARGET_KERNEL_LINUX_DEVICES = TARGET_KERNEL_POSIX | 0x1000, - TARGET_KERNEL_UNKNOWN_LINUX, - TARGET_KERNEL_LINUX = TARGET_KERNEL_UNKNOWN_LINUX, - TARGET_KERNEL_ALPINE_LINUX, - TARGET_KERNEL_PC_LINUX, - TARGET_KERNEL_ANDROID, - TARGET_KERNEL_APPLE_DEVICES = TARGET_KERNEL_POSIX | 0x2000, - TARGET_KERNEL_DARWIN, - TARGET_KERNEL_IOS, - - TARGET_KERNEL_WEB_DEVICES = 0x400, - TARGET_KERNEL_WASI, - TARGET_KERNEL_EMSCRIPTEN, -}; - -enum ETargetCPU -{ - TARGET_CPU_UNDEFINED, - TARGET_CPU_80386, - TARGET_CPU_80486, - TARGET_CPU_80586, - TARGET_CPU_80686, - TARGET_CPU_AMD64, - TARGET_CPU_AARCH64, - TARGET_CPU_WASM32, -}; -enum ETargetABI -{ - TARGET_ABI_UNDEFINED, - TARGET_ABI_DEFAULT, - TARGET_ABI_GNU, - TARGET_ABI_MUSL, - TARGET_ABI_MSVC, -}; - -enum ETargetOptimization -{ - TARGET_DEBUG, - TARGET_RELEASE_SPEED, - TARGET_RELEASE_SIZE -}; - -struct Target_t -{ - ETargetKernel kernel; - ETargetCPU cpu; - ETargetABI abi; - ETargetOptimization optimization; - const char *szSysroot = CommandLine()->ParamValue("-sysroot"); - - CUtlString GetTriplet(); - const char *GetExecutableFileFormat(); - const char *GetStaticLibraryFileFormat(); - const char *GetDynamicLibraryFileFormat(); - static Target_t HostTarget(); - static Target_t DefaultTarget(); - static const char *StringFromCPU( ETargetCPU eCPU ); - static const char *StringFromKernel( ETargetKernel eKernel ); - static const char *StringFromABI( ETargetABI eABI ); - static ETargetCPU CPUFromString( const char *szName ); - static ETargetKernel KernelFromString( const char *szName ); - static ETargetABI ABIFromString( const char *szName ); -}; - -enum EShaderTarget -{ - SHADER_TARGET_VULKAN_SPIRV, - SHADER_TARGET_OPENGL_SPIRV, - SHADER_TARGET_GLSL, - SHADER_TARGET_HLSL, - SHADER_TARGET_MSL, -}; - - -#endif diff --git a/fpc/public/temporalmgr.h b/fpc/public/temporalmgr.h deleted file mode 100644 index e69de29..0000000 diff --git a/fpc/public/watchmgr.h b/fpc/public/watchmgr.h deleted file mode 100644 index e69de29..0000000 diff --git a/fpc/public/windres.h b/fpc/public/windres.h deleted file mode 100644 index e69de29..0000000 diff --git a/fpc/public/winerunner.h b/fpc/public/winerunner.h deleted file mode 100644 index 3c54002..0000000 --- a/fpc/public/winerunner.h +++ /dev/null @@ -1,28 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Run Windows applications using Wine. On native system this will use -// CWindowsRunner. -//===========================================================================// - -#ifndef WINE_RUNNER_H -#define WINE_RUNNER_H - -#include "runner.h" -#include "tier0/platform.h" -#include "tier1/utlvector.h" -#include "tier1/utlstring.h" - -#define WINE_RUNNER_INTERFACE_NAME "WineRunner001" - -abstract_class IWineRunner: public IRunner -{ -public: - virtual int Run( CUtlString szName, CUtlVector& args ) = 0; - virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector& args ) = 0; - virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector& args, CUtlVector& environment ) = 0; - virtual int Wait( void ) = 0; -}; - - -extern IWineRunner *winerunner; - -#endif diff --git a/fpc/sysroots/ios.cpp b/fpc/sysroots/ios.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/fpc/sysroots/macos.cpp b/fpc/sysroots/macos.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/fpc/sysroots/wdk.cpp b/fpc/sysroots/wdk.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/fpc/sysroots/xcode.cpp b/fpc/sysroots/xcode.cpp deleted file mode 100644 index 58c428e..0000000 --- a/fpc/sysroots/xcode.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "c.h" -#include "ld.h" -#include "helper.h" -#include "sysroots.h" - -DECLARE_SYSROOT_INSTALL_STAGE(xcode_install) -{ - - return 0; -} diff --git a/fpc/tests/android_build/.fpccfg b/fpc/tests/android_build/.fpccfg deleted file mode 100644 index 6227ba8..0000000 --- a/fpc/tests/android_build/.fpccfg +++ /dev/null @@ -1,6 +0,0 @@ -[x86_64-linux-android] -sysroot = "/home/kotofyt/Android/Sdk/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/sysroot" -CLANG_LINKER_INTERFACE_NAME = "/home/kotofyt/Android/Sdk/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++" - -[Android_Build_Tools] -path = "/home/kotofyt/Android/Sdk/build-tools/36.0.0" diff --git a/fpc/tests/android_build/android_native_app_glue.c b/fpc/tests/android_build/android_native_app_glue.c deleted file mode 100644 index 433d4c0..0000000 --- a/fpc/tests/android_build/android_native_app_glue.c +++ /dev/null @@ -1,443 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include -#include -#include -#include -#include - -#include "android_native_app_glue.h" -#include - -#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "threaded_app", __VA_ARGS__)) -#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "threaded_app", __VA_ARGS__)) - -/* For debug builds, always enable the debug traces in this library */ -#ifndef NDEBUG -# define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, "threaded_app", __VA_ARGS__)) -#else -# define LOGV(...) ((void)0) -#endif - -static void free_saved_state(struct android_app* android_app) { - pthread_mutex_lock(&android_app->mutex); - if (android_app->savedState != NULL) { - free(android_app->savedState); - android_app->savedState = NULL; - android_app->savedStateSize = 0; - } - pthread_mutex_unlock(&android_app->mutex); -} - -int8_t android_app_read_cmd(struct android_app* android_app) { - int8_t cmd; - if (read(android_app->msgread, &cmd, sizeof(cmd)) == sizeof(cmd)) { - switch (cmd) { - case APP_CMD_SAVE_STATE: - free_saved_state(android_app); - break; - } - return cmd; - } else { - LOGE("No data on command pipe!"); - } - return -1; -} - -static void print_cur_config(struct android_app* android_app) { - char lang[2], country[2]; - AConfiguration_getLanguage(android_app->config, lang); - AConfiguration_getCountry(android_app->config, country); - - LOGV("Config: mcc=%d mnc=%d lang=%c%c cnt=%c%c orien=%d touch=%d dens=%d " - "keys=%d nav=%d keysHid=%d navHid=%d sdk=%d size=%d long=%d " - "modetype=%d modenight=%d", - AConfiguration_getMcc(android_app->config), - AConfiguration_getMnc(android_app->config), - lang[0], lang[1], country[0], country[1], - AConfiguration_getOrientation(android_app->config), - AConfiguration_getTouchscreen(android_app->config), - AConfiguration_getDensity(android_app->config), - AConfiguration_getKeyboard(android_app->config), - AConfiguration_getNavigation(android_app->config), - AConfiguration_getKeysHidden(android_app->config), - AConfiguration_getNavHidden(android_app->config), - AConfiguration_getSdkVersion(android_app->config), - AConfiguration_getScreenSize(android_app->config), - AConfiguration_getScreenLong(android_app->config), - AConfiguration_getUiModeType(android_app->config), - AConfiguration_getUiModeNight(android_app->config)); -} - -void android_app_pre_exec_cmd(struct android_app* android_app, int8_t cmd) { - switch (cmd) { - case APP_CMD_INPUT_CHANGED: - LOGV("APP_CMD_INPUT_CHANGED\n"); - pthread_mutex_lock(&android_app->mutex); - if (android_app->inputQueue != NULL) { - AInputQueue_detachLooper(android_app->inputQueue); - } - android_app->inputQueue = android_app->pendingInputQueue; - if (android_app->inputQueue != NULL) { - LOGV("Attaching input queue to looper"); - AInputQueue_attachLooper(android_app->inputQueue, - android_app->looper, LOOPER_ID_INPUT, NULL, - &android_app->inputPollSource); - } - pthread_cond_broadcast(&android_app->cond); - pthread_mutex_unlock(&android_app->mutex); - break; - - case APP_CMD_INIT_WINDOW: - LOGV("APP_CMD_INIT_WINDOW\n"); - pthread_mutex_lock(&android_app->mutex); - android_app->window = android_app->pendingWindow; - pthread_cond_broadcast(&android_app->cond); - pthread_mutex_unlock(&android_app->mutex); - break; - - case APP_CMD_TERM_WINDOW: - LOGV("APP_CMD_TERM_WINDOW\n"); - pthread_cond_broadcast(&android_app->cond); - break; - - case APP_CMD_RESUME: - case APP_CMD_START: - case APP_CMD_PAUSE: - case APP_CMD_STOP: - LOGV("activityState=%d\n", cmd); - pthread_mutex_lock(&android_app->mutex); - android_app->activityState = cmd; - pthread_cond_broadcast(&android_app->cond); - pthread_mutex_unlock(&android_app->mutex); - break; - - case APP_CMD_CONFIG_CHANGED: - LOGV("APP_CMD_CONFIG_CHANGED\n"); - AConfiguration_fromAssetManager(android_app->config, - android_app->activity->assetManager); - print_cur_config(android_app); - break; - - case APP_CMD_DESTROY: - LOGV("APP_CMD_DESTROY\n"); - android_app->destroyRequested = 1; - break; - } -} - -void android_app_post_exec_cmd(struct android_app* android_app, int8_t cmd) { - switch (cmd) { - case APP_CMD_TERM_WINDOW: - LOGV("APP_CMD_TERM_WINDOW\n"); - pthread_mutex_lock(&android_app->mutex); - android_app->window = NULL; - pthread_cond_broadcast(&android_app->cond); - pthread_mutex_unlock(&android_app->mutex); - break; - - case APP_CMD_SAVE_STATE: - LOGV("APP_CMD_SAVE_STATE\n"); - pthread_mutex_lock(&android_app->mutex); - android_app->stateSaved = 1; - pthread_cond_broadcast(&android_app->cond); - pthread_mutex_unlock(&android_app->mutex); - break; - - case APP_CMD_RESUME: - free_saved_state(android_app); - break; - } -} - -void app_dummy() { - -} - -static void android_app_destroy(struct android_app* android_app) { - LOGV("android_app_destroy!"); - free_saved_state(android_app); - pthread_mutex_lock(&android_app->mutex); - if (android_app->inputQueue != NULL) { - AInputQueue_detachLooper(android_app->inputQueue); - } - AConfiguration_delete(android_app->config); - android_app->destroyed = 1; - pthread_cond_broadcast(&android_app->cond); - pthread_mutex_unlock(&android_app->mutex); - // Can't touch android_app object after this. -} - -static void process_input(struct android_app* app, struct android_poll_source* source) { - AInputEvent* event = NULL; - if (AInputQueue_getEvent(app->inputQueue, &event) >= 0) { - LOGV("New input event: type=%d\n", AInputEvent_getType(event)); - if (AInputQueue_preDispatchEvent(app->inputQueue, event)) { - return; - } - int32_t handled = 0; - if (app->onInputEvent != NULL) handled = app->onInputEvent(app, event); - AInputQueue_finishEvent(app->inputQueue, event, handled); - } else { - LOGE("Failure reading next input event: %s\n", strerror(errno)); - } -} - -static void process_cmd(struct android_app* app, struct android_poll_source* source) { - int8_t cmd = android_app_read_cmd(app); - android_app_pre_exec_cmd(app, cmd); - if (app->onAppCmd != NULL) app->onAppCmd(app, cmd); - android_app_post_exec_cmd(app, cmd); -} - -static void* android_app_entry(void* param) { - struct android_app* android_app = (struct android_app*)param; - - android_app->config = AConfiguration_new(); - AConfiguration_fromAssetManager(android_app->config, android_app->activity->assetManager); - - print_cur_config(android_app); - - android_app->cmdPollSource.id = LOOPER_ID_MAIN; - android_app->cmdPollSource.app = android_app; - android_app->cmdPollSource.process = process_cmd; - android_app->inputPollSource.id = LOOPER_ID_INPUT; - android_app->inputPollSource.app = android_app; - android_app->inputPollSource.process = process_input; - - ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); - ALooper_addFd(looper, android_app->msgread, LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT, NULL, - &android_app->cmdPollSource); - android_app->looper = looper; - - pthread_mutex_lock(&android_app->mutex); - android_app->running = 1; - pthread_cond_broadcast(&android_app->cond); - pthread_mutex_unlock(&android_app->mutex); - - android_main(android_app); - - android_app_destroy(android_app); - return NULL; -} - -// -------------------------------------------------------------------- -// Native activity interaction (called from main thread) -// -------------------------------------------------------------------- - -static struct android_app* android_app_create(ANativeActivity* activity, - void* savedState, size_t savedStateSize) { - struct android_app* android_app = (struct android_app*)malloc(sizeof(struct android_app)); - memset(android_app, 0, sizeof(struct android_app)); - android_app->activity = activity; - - pthread_mutex_init(&android_app->mutex, NULL); - pthread_cond_init(&android_app->cond, NULL); - - if (savedState != NULL) { - android_app->savedState = malloc(savedStateSize); - android_app->savedStateSize = savedStateSize; - memcpy(android_app->savedState, savedState, savedStateSize); - } - - int msgpipe[2]; - if (pipe(msgpipe)) { - LOGE("could not create pipe: %s", strerror(errno)); - return NULL; - } - android_app->msgread = msgpipe[0]; - android_app->msgwrite = msgpipe[1]; - - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_create(&android_app->thread, &attr, android_app_entry, android_app); - - // Wait for thread to start. - pthread_mutex_lock(&android_app->mutex); - while (!android_app->running) { - pthread_cond_wait(&android_app->cond, &android_app->mutex); - } - pthread_mutex_unlock(&android_app->mutex); - - return android_app; -} - -static void android_app_write_cmd(struct android_app* android_app, int8_t cmd) { - if (write(android_app->msgwrite, &cmd, sizeof(cmd)) != sizeof(cmd)) { - LOGE("Failure writing android_app cmd: %s\n", strerror(errno)); - } -} - -static void android_app_set_input(struct android_app* android_app, AInputQueue* inputQueue) { - pthread_mutex_lock(&android_app->mutex); - android_app->pendingInputQueue = inputQueue; - android_app_write_cmd(android_app, APP_CMD_INPUT_CHANGED); - while (android_app->inputQueue != android_app->pendingInputQueue) { - pthread_cond_wait(&android_app->cond, &android_app->mutex); - } - pthread_mutex_unlock(&android_app->mutex); -} - -static void android_app_set_window(struct android_app* android_app, ANativeWindow* window) { - pthread_mutex_lock(&android_app->mutex); - if (android_app->pendingWindow != NULL) { - android_app_write_cmd(android_app, APP_CMD_TERM_WINDOW); - } - android_app->pendingWindow = window; - if (window != NULL) { - android_app_write_cmd(android_app, APP_CMD_INIT_WINDOW); - } - while (android_app->window != android_app->pendingWindow) { - pthread_cond_wait(&android_app->cond, &android_app->mutex); - } - pthread_mutex_unlock(&android_app->mutex); -} - -static void android_app_set_activity_state(struct android_app* android_app, int8_t cmd) { - pthread_mutex_lock(&android_app->mutex); - android_app_write_cmd(android_app, cmd); - while (android_app->activityState != cmd) { - pthread_cond_wait(&android_app->cond, &android_app->mutex); - } - pthread_mutex_unlock(&android_app->mutex); -} - -static void android_app_free(struct android_app* android_app) { - pthread_mutex_lock(&android_app->mutex); - android_app_write_cmd(android_app, APP_CMD_DESTROY); - while (!android_app->destroyed) { - pthread_cond_wait(&android_app->cond, &android_app->mutex); - } - pthread_mutex_unlock(&android_app->mutex); - - close(android_app->msgread); - close(android_app->msgwrite); - pthread_cond_destroy(&android_app->cond); - pthread_mutex_destroy(&android_app->mutex); - free(android_app); -} - -static void onDestroy(ANativeActivity* activity) { - LOGV("Destroy: %p\n", activity); - android_app_free((struct android_app*)activity->instance); -} - -static void onStart(ANativeActivity* activity) { - LOGV("Start: %p\n", activity); - android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_START); -} - -static void onResume(ANativeActivity* activity) { - LOGV("Resume: %p\n", activity); - android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_RESUME); -} - -static void* onSaveInstanceState(ANativeActivity* activity, size_t* outLen) { - struct android_app* android_app = (struct android_app*)activity->instance; - void* savedState = NULL; - - LOGV("SaveInstanceState: %p\n", activity); - pthread_mutex_lock(&android_app->mutex); - android_app->stateSaved = 0; - android_app_write_cmd(android_app, APP_CMD_SAVE_STATE); - while (!android_app->stateSaved) { - pthread_cond_wait(&android_app->cond, &android_app->mutex); - } - - if (android_app->savedState != NULL) { - savedState = android_app->savedState; - *outLen = android_app->savedStateSize; - android_app->savedState = NULL; - android_app->savedStateSize = 0; - } - - pthread_mutex_unlock(&android_app->mutex); - - return savedState; -} - -static void onPause(ANativeActivity* activity) { - LOGV("Pause: %p\n", activity); - android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_PAUSE); -} - -static void onStop(ANativeActivity* activity) { - LOGV("Stop: %p\n", activity); - android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_STOP); -} - -static void onConfigurationChanged(ANativeActivity* activity) { - struct android_app* android_app = (struct android_app*)activity->instance; - LOGV("ConfigurationChanged: %p\n", activity); - android_app_write_cmd(android_app, APP_CMD_CONFIG_CHANGED); -} - -static void onLowMemory(ANativeActivity* activity) { - struct android_app* android_app = (struct android_app*)activity->instance; - LOGV("LowMemory: %p\n", activity); - android_app_write_cmd(android_app, APP_CMD_LOW_MEMORY); -} - -static void onWindowFocusChanged(ANativeActivity* activity, int focused) { - LOGV("WindowFocusChanged: %p -- %d\n", activity, focused); - android_app_write_cmd((struct android_app*)activity->instance, - focused ? APP_CMD_GAINED_FOCUS : APP_CMD_LOST_FOCUS); -} - -static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* window) { - LOGV("NativeWindowCreated: %p -- %p\n", activity, window); - android_app_set_window((struct android_app*)activity->instance, window); -} - -static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* window) { - LOGV("NativeWindowDestroyed: %p -- %p\n", activity, window); - android_app_set_window((struct android_app*)activity->instance, NULL); -} - -static void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue) { - LOGV("InputQueueCreated: %p -- %p\n", activity, queue); - android_app_set_input((struct android_app*)activity->instance, queue); -} - -static void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue) { - LOGV("InputQueueDestroyed: %p -- %p\n", activity, queue); - android_app_set_input((struct android_app*)activity->instance, NULL); -} - -void ANativeActivity_onCreate(ANativeActivity* activity, - void* savedState, size_t savedStateSize) { - LOGV("Creating: %p\n", activity); - activity->callbacks->onDestroy = onDestroy; - activity->callbacks->onStart = onStart; - activity->callbacks->onResume = onResume; - activity->callbacks->onSaveInstanceState = onSaveInstanceState; - activity->callbacks->onPause = onPause; - activity->callbacks->onStop = onStop; - activity->callbacks->onConfigurationChanged = onConfigurationChanged; - activity->callbacks->onLowMemory = onLowMemory; - activity->callbacks->onWindowFocusChanged = onWindowFocusChanged; - activity->callbacks->onNativeWindowCreated = onNativeWindowCreated; - activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed; - activity->callbacks->onInputQueueCreated = onInputQueueCreated; - activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed; - - activity->instance = android_app_create(activity, savedState, savedStateSize); -} diff --git a/fpc/tests/android_build/android_native_app_glue.h b/fpc/tests/android_build/android_native_app_glue.h deleted file mode 100644 index 1b8c1f1..0000000 --- a/fpc/tests/android_build/android_native_app_glue.h +++ /dev/null @@ -1,349 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef _ANDROID_NATIVE_APP_GLUE_H -#define _ANDROID_NATIVE_APP_GLUE_H - -#include -#include -#include - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * The native activity interface provided by - * is based on a set of application-provided callbacks that will be called - * by the Activity's main thread when certain events occur. - * - * This means that each one of this callbacks _should_ _not_ block, or they - * risk having the system force-close the application. This programming - * model is direct, lightweight, but constraining. - * - * The 'threaded_native_app' static library is used to provide a different - * execution model where the application can implement its own main event - * loop in a different thread instead. Here's how it works: - * - * 1/ The application must provide a function named "android_main()" that - * will be called when the activity is created, in a new thread that is - * distinct from the activity's main thread. - * - * 2/ android_main() receives a pointer to a valid "android_app" structure - * that contains references to other important objects, e.g. the - * ANativeActivity obejct instance the application is running in. - * - * 3/ the "android_app" object holds an ALooper instance that already - * listens to two important things: - * - * - activity lifecycle events (e.g. "pause", "resume"). See APP_CMD_XXX - * declarations below. - * - * - input events coming from the AInputQueue attached to the activity. - * - * Each of these correspond to an ALooper identifier returned by - * ALooper_pollOnce with values of LOOPER_ID_MAIN and LOOPER_ID_INPUT, - * respectively. - * - * Your application can use the same ALooper to listen to additional - * file-descriptors. They can either be callback based, or with return - * identifiers starting with LOOPER_ID_USER. - * - * 4/ Whenever you receive a LOOPER_ID_MAIN or LOOPER_ID_INPUT event, - * the returned data will point to an android_poll_source structure. You - * can call the process() function on it, and fill in android_app->onAppCmd - * and android_app->onInputEvent to be called for your own processing - * of the event. - * - * Alternatively, you can call the low-level functions to read and process - * the data directly... look at the process_cmd() and process_input() - * implementations in the glue to see how to do this. - * - * See the sample named "native-activity" that comes with the NDK with a - * full usage example. Also look at the JavaDoc of NativeActivity. - */ - -struct android_app; - -/** - * Data associated with an ALooper fd that will be returned as the "outData" - * when that source has data ready. - */ -struct android_poll_source { - // The identifier of this source. May be LOOPER_ID_MAIN or - // LOOPER_ID_INPUT. - int32_t id; - - // The android_app this ident is associated with. - struct android_app* app; - - // Function to call to perform the standard processing of data from - // this source. - void (*process)(struct android_app* app, struct android_poll_source* source); -}; - -/** - * This is the interface for the standard glue code of a threaded - * application. In this model, the application's code is running - * in its own thread separate from the main thread of the process. - * It is not required that this thread be associated with the Java - * VM, although it will need to be in order to make JNI calls any - * Java objects. - */ -struct android_app { - // The application can place a pointer to its own state object - // here if it likes. - void* userData; - - // Fill this in with the function to process main app commands (APP_CMD_*) - void (*onAppCmd)(struct android_app* app, int32_t cmd); - - // Fill this in with the function to process input events. At this point - // the event has already been pre-dispatched, and it will be finished upon - // return. Return 1 if you have handled the event, 0 for any default - // dispatching. - int32_t (*onInputEvent)(struct android_app* app, AInputEvent* event); - - // The ANativeActivity object instance that this app is running in. - ANativeActivity* activity; - - // The current configuration the app is running in. - AConfiguration* config; - - // This is the last instance's saved state, as provided at creation time. - // It is NULL if there was no state. You can use this as you need; the - // memory will remain around until you call android_app_exec_cmd() for - // APP_CMD_RESUME, at which point it will be freed and savedState set to NULL. - // These variables should only be changed when processing a APP_CMD_SAVE_STATE, - // at which point they will be initialized to NULL and you can malloc your - // state and place the information here. In that case the memory will be - // freed for you later. - void* savedState; - size_t savedStateSize; - - // The ALooper associated with the app's thread. - ALooper* looper; - - // When non-NULL, this is the input queue from which the app will - // receive user input events. - AInputQueue* inputQueue; - - // When non-NULL, this is the window surface that the app can draw in. - ANativeWindow* window; - - // Current content rectangle of the window; this is the area where the - // window's content should be placed to be seen by the user. - ARect contentRect; - - // Current state of the app's activity. May be either APP_CMD_START, - // APP_CMD_RESUME, APP_CMD_PAUSE, or APP_CMD_STOP; see below. - int activityState; - - // This is non-zero when the application's NativeActivity is being - // destroyed and waiting for the app thread to complete. - int destroyRequested; - - // ------------------------------------------------- - // Below are "private" implementation of the glue code. - - pthread_mutex_t mutex; - pthread_cond_t cond; - - int msgread; - int msgwrite; - - pthread_t thread; - - struct android_poll_source cmdPollSource; - struct android_poll_source inputPollSource; - - int running; - int stateSaved; - int destroyed; - int redrawNeeded; - AInputQueue* pendingInputQueue; - ANativeWindow* pendingWindow; - ARect pendingContentRect; -}; - -enum { - /** - * Looper data ID of commands coming from the app's main thread, which - * is returned as an identifier from ALooper_pollOnce(). The data for this - * identifier is a pointer to an android_poll_source structure. - * These can be retrieved and processed with android_app_read_cmd() - * and android_app_exec_cmd(). - */ - LOOPER_ID_MAIN = 1, - - /** - * Looper data ID of events coming from the AInputQueue of the - * application's window, which is returned as an identifier from - * ALooper_pollOnce(). The data for this identifier is a pointer to an - * android_poll_source structure. These can be read via the inputQueue - * object of android_app. - */ - LOOPER_ID_INPUT = 2, - - /** - * Start of user-defined ALooper identifiers. - */ - LOOPER_ID_USER = 3, -}; - -enum { - /** - * Command from main thread: the AInputQueue has changed. Upon processing - * this command, android_app->inputQueue will be updated to the new queue - * (or NULL). - */ - APP_CMD_INPUT_CHANGED, - - /** - * Command from main thread: a new ANativeWindow is ready for use. Upon - * receiving this command, android_app->window will contain the new window - * surface. - */ - APP_CMD_INIT_WINDOW, - - /** - * Command from main thread: the existing ANativeWindow needs to be - * terminated. Upon receiving this command, android_app->window still - * contains the existing window; after calling android_app_exec_cmd - * it will be set to NULL. - */ - APP_CMD_TERM_WINDOW, - - /** - * Command from main thread: the current ANativeWindow has been resized. - * Please redraw with its new size. - */ - APP_CMD_WINDOW_RESIZED, - - /** - * Command from main thread: the system needs that the current ANativeWindow - * be redrawn. You should redraw the window before handing this to - * android_app_exec_cmd() in order to avoid transient drawing glitches. - */ - APP_CMD_WINDOW_REDRAW_NEEDED, - - /** - * Command from main thread: the content area of the window has changed, - * such as from the soft input window being shown or hidden. You can - * find the new content rect in android_app::contentRect. - */ - APP_CMD_CONTENT_RECT_CHANGED, - - /** - * Command from main thread: the app's activity window has gained - * input focus. - */ - APP_CMD_GAINED_FOCUS, - - /** - * Command from main thread: the app's activity window has lost - * input focus. - */ - APP_CMD_LOST_FOCUS, - - /** - * Command from main thread: the current device configuration has changed. - */ - APP_CMD_CONFIG_CHANGED, - - /** - * Command from main thread: the system is running low on memory. - * Try to reduce your memory use. - */ - APP_CMD_LOW_MEMORY, - - /** - * Command from main thread: the app's activity has been started. - */ - APP_CMD_START, - - /** - * Command from main thread: the app's activity has been resumed. - */ - APP_CMD_RESUME, - - /** - * Command from main thread: the app should generate a new saved state - * for itself, to restore from later if needed. If you have saved state, - * allocate it with malloc and place it in android_app.savedState with - * the size in android_app.savedStateSize. The will be freed for you - * later. - */ - APP_CMD_SAVE_STATE, - - /** - * Command from main thread: the app's activity has been paused. - */ - APP_CMD_PAUSE, - - /** - * Command from main thread: the app's activity has been stopped. - */ - APP_CMD_STOP, - - /** - * Command from main thread: the app's activity is being destroyed, - * and waiting for the app thread to clean up and exit before proceeding. - */ - APP_CMD_DESTROY, -}; - -/** - * Call when ALooper_pollAll() returns LOOPER_ID_MAIN, reading the next - * app command message. - */ -int8_t android_app_read_cmd(struct android_app* android_app); - -/** - * Call with the command returned by android_app_read_cmd() to do the - * initial pre-processing of the given command. You can perform your own - * actions for the command after calling this function. - */ -void android_app_pre_exec_cmd(struct android_app* android_app, int8_t cmd); - -/** - * Call with the command returned by android_app_read_cmd() to do the - * final post-processing of the given command. You must have done your own - * actions for the command before calling this function. - */ -void android_app_post_exec_cmd(struct android_app* android_app, int8_t cmd); - -/** - * Dummy function you can call to ensure glue code isn't stripped. - */ -void app_dummy(); - -/** - * This is the function that application code must implement, representing - * the main entry to the app. - */ -extern void android_main(struct android_app* app); - -#ifdef __cplusplus -} -#endif - -#endif /* _ANDROID_NATIVE_APP_GLUE_H */ diff --git a/fpc/tests/android_build/build.cpp b/fpc/tests/android_build/build.cpp deleted file mode 100644 index 5318a80..0000000 --- a/fpc/tests/android_build/build.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "helper.h" -#include "c.h" -#include "ld.h" -#include "tier1/utlstring.h" - -DECLARE_BUILD_STAGE(android_build) -{ - AndroidManifest_t manifest = {}; - manifest.SetMinSDKVersion(21); - manifest.SetTargetSDKVersion(35); - manifest.SetPackageName("FPC Testing facility"); - manifest.SetPackageID("com.example.testfpc"); - CUtlString szManifestDir = manifest.BuildManifest(); - - CProject_t compileProject = {}; - compileProject.m_szName = "android_app"; - compileProject.m_androidmanifest = manifest; - compileProject.bFPIC = true; - compileProject.m_target = Target_t::HostTarget(); - compileProject.m_target.kernel = TARGET_KERNEL_ANDROID; - compileProject.files = { - "main.c", - "android_native_app_glue.c", - }; - LinkProject_t ldProject = ccompiler->Compile(&compileProject); - ldProject.libraries = { - "android", - "log", - }; - CUtlString szOutputDir = linker->Link(&ldProject); - filesystem2->MakeDirectory(CUtlString("%s/lib/x86_64",szManifestDir.GetString())); - filesystem2->CopyFile(CUtlString("%s/lib/x86_64/libnative-app.so",szManifestDir.GetString()), szOutputDir); - - CUtlString szApk = APKTool()->BuildPackage(manifest, szManifestDir); - APKTool()->SignPackage(szApk, NULL, "mykey", "storepass", "storepass"); - - return 0; -} - diff --git a/fpc/tests/android_build/main.c b/fpc/tests/android_build/main.c deleted file mode 100644 index 1c77754..0000000 --- a/fpc/tests/android_build/main.c +++ /dev/null @@ -1,40 +0,0 @@ - -#include "android_native_app_glue.h" -#include - -#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "NativeApp", __VA_ARGS__)) - -// Handle lifecycle events -static void handle_cmd(struct android_app* app, int32_t cmd) { - switch (cmd) { - case APP_CMD_INIT_WINDOW: - LOGI("Window created"); - // You could init OpenGL/Vulkan here - break; - case APP_CMD_TERM_WINDOW: - LOGI("Window destroyed"); - break; - } -} - -void android_main(struct android_app* app) { - app->onAppCmd = handle_cmd; - - LOGI("Native app started"); - - int events; - struct android_poll_source* source; - - while (1) { - LOGI("what"); - int ident; - while ((ident = ALooper_pollOnce(0, NULL, &events, (void**)&source)) >= 0) { - if (source) source->process(app, source); - if (app->destroyRequested) { - LOGI("App destroy requested"); - return; - } - } - - } -} diff --git a/fpc/tests/android_build/my-release-key.jks b/fpc/tests/android_build/my-release-key.jks deleted file mode 100644 index 227d6f7..0000000 Binary files a/fpc/tests/android_build/my-release-key.jks and /dev/null differ diff --git a/fpc/tests/ios_build/.fpccfg b/fpc/tests/ios_build/.fpccfg deleted file mode 100644 index 0b63401..0000000 --- a/fpc/tests/ios_build/.fpccfg +++ /dev/null @@ -1,2 +0,0 @@ -[aarch64-apple-ios] -sysroot = "/home/kotofyt/clones/yay/xcode/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk" diff --git a/fpc/tests/ios_build/build.cpp b/fpc/tests/ios_build/build.cpp deleted file mode 100644 index a4d99fb..0000000 --- a/fpc/tests/ios_build/build.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "helper.h" -#include "c.h" -#include "ld.h" -#include "tier1/utlstring.h" -#include "appletool.h" - -DECLARE_BUILD_STAGE(ios_build) -{ - V_printf("Cool\n"); - CProject_t compileProject = {}; - compileProject.m_szName = "ios_app"; - compileProject.m_target = Target_t::HostTarget(); - compileProject.m_target.kernel = TARGET_KERNEL_IOS; - compileProject.m_target.cpu = TARGET_CPU_AARCH64; - compileProject.files = { - "main.c", - }; - LinkProject_t ldProject = ccompiler->Compile(&compileProject); - CUtlString szOutput = linker->Link(&ldProject); - - AppleManifest_t manifest = {}; - manifest.SetPackageName("FPC Testing facility"); - manifest.SetPackageID("com.example.testfpc"); - manifest.SetPackageExecutable(szOutput); - CUtlString szIpa = AppleTool()->BuildPackage( manifest, manifest.BuildManifest() ); - CUtlString szPackage = AppleTool()->SignPackage(szIpa, NULL); - - return 0; -} diff --git a/fpc/tests/ios_build/main.c b/fpc/tests/ios_build/main.c deleted file mode 100644 index 0734f35..0000000 --- a/fpc/tests/ios_build/main.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "stdio.h" -int main() -{ - printf("Hello, world!\n"); - return 0; -}; diff --git a/fpc/tests/windows_drivers_build/build.cpp b/fpc/tests/windows_drivers_build/build.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/fpc/tests/windows_drivers_build/main.c b/fpc/tests/windows_drivers_build/main.c deleted file mode 100644 index e69de29..0000000 diff --git a/game/client/__build.cpp b/game/client/__build.cpp index f3d182b..a84ddd8 100644 --- a/game/client/__build.cpp +++ b/game/client/__build.cpp @@ -24,6 +24,7 @@ DECLARE_BUILD_STAGE(client) CUtlString outputProject = linker->Link(&ldProject); + /* if (!bStaticBuild) { filesystem2->MakeDirectory(CUtlString("%s/funnygame/bin",szOutputDir.GetString())); @@ -31,6 +32,7 @@ DECLARE_BUILD_STAGE(client) } else { client_lib = outputProject; } + */ return 0; }; diff --git a/http/build.cpp b/http/build.cpp deleted file mode 100644 index 0613b0b..0000000 --- a/http/build.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "helper.h" -#include "c.h" -#include "ld.h" -#include "tier1/utlstring.h" -#include "tier0/commandline.h" - -ADD_DEPENDENCY_BUILD_FILE(tier0, "../tier0/build.cpp") -ADD_DEPENDENCY_BUILD_FILE(tier1, "../tier1/build.cpp") -ADD_DEPENDENCY_BUILD_FILE(tier2, "../tier2/build.cpp") - -DECLARE_BUILD_STAGE(funnyhttp) -{ - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - - compileProject.m_szName = "funnyhttp"; - compileProject.files = { - "client.cpp" - }; - compileProject.includeDirectories = {"../public"}; - compileProject.bFPIC = true; - ldProject = ccompiler->Compile(&compileProject); - ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier1, "tier1")}); - ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier2, "tier2")}); - ldProject.libraries = { - "ssl", - "crypto", - }; - ldProject.linkType = ELINK_DYNAMIC_LIBRARY; - - CUtlString szOutputDir = linker->Link(&ldProject); - - ADD_OUTPUT_OBJECT("funnyhttp", szOutputDir) - - return 0; -}; - diff --git a/http/client.cpp b/http/client.cpp deleted file mode 100644 index eaf286a..0000000 --- a/http/client.cpp +++ /dev/null @@ -1,563 +0,0 @@ - -#include "http/http.h" -#include "tier1/interface.h" -#include "tier1/utlstring.h" -#include "netdb.h" -#include "unistd.h" -#include "fcntl.h" -#include "openssl/ssl.h" -#include "openssl/err.h" -#include "arpa/inet.h" - -abstract_class CHTTPClient: public IHTTPClient -{ -public: - void ConnectToServer(); - void CloseConnection(); - - virtual void Post( const char *szResource, HTTPHeader_t *pHeader, uint32_t uDataSize, const void *data ) override; - virtual void Get( const char *szResource, HTTPHeader_t *pHeader ) override; - virtual HTTPResponse_t GetResponse() override; - - virtual bool WebSocket_Connect( const char *szResource ) override; - virtual void WebSocket_Close( void ) override; - virtual void WebSocket_SendText( const char *szData ) override; - virtual CUtlString WebSocket_RecvText() override; - virtual void WebSocket_SendBinary( size_t uSize, const void *pData ) override; - virtual WebSocketPacket_t WebSocket_RecvBinary() override; - - ssize_t Write( void *pData, ssize_t uSize ); - ssize_t Read( void *pData, ssize_t uSize ); - - HTTPResponse_t ParseResponse( const char *szMessage, uint32_t uDataSize ); - const char *GetVersion(); - HTTPHeaderParam_t ParseHeaderParams( const char *szHeaderLine ); - - const char *m_szHostName; - uint16_t m_uPort; - bool m_bIsSecure; - SSL *m_pSSL; - SSL_CTX *m_pSSLCtx; - - int m_iFileDescriptor; -}; - -void CHTTPClient::Post( const char *szResource, HTTPHeader_t *pHeader, uint32_t uDataSize, const void *data ) -{ - if (pHeader == NULL) - return; - - ConnectToServer(); - - CUtlString szMessage = CUtlString( - "POST %s HTTP/%s\r\n", - szResource, GetVersion()); - CUtlString szHeader = CUtlString( - "Host: %s\r\n" - "Content-Length: %u\r\n", - m_szHostName, - uDataSize - ); - - CUtlString szCombined; - int i = 0; - - for ( i = 0; i < pHeader->m_nParamCount; i++ ) - { - szHeader.AppendTail(CUtlString("%s: %s\r\n", pHeader->m_params[i].m_szParamName.GetString(), pHeader->m_params[i].m_szValue.GetString())); - } - - szCombined = szMessage; - szCombined.AppendTail(szHeader); - szCombined.AppendTail("\r\n"); - V_printf("%s\n",szCombined.GetString()); - - Write(szCombined.GetString(), szCombined.GetLenght()); - Write((void*)data, uDataSize); -} - -void CHTTPClient::Get( const char *szResource, HTTPHeader_t *pHeader ) -{ - if (pHeader == NULL) - return; - - ConnectToServer(); - - CUtlString szMessage = CUtlString( - "GET %s HTTP/%s\r\n", - szResource, GetVersion()); - CUtlString szHeader = CUtlString( - "Host: %s\r\n", - m_szHostName - ); - - CUtlString szCombined; - int i = 0; - - for ( i = 0; i < pHeader->m_nParamCount; i++ ) - { - szHeader.AppendTail(CUtlString("%s: %s\r\n", pHeader->m_params[i].m_szParamName.GetString(), pHeader->m_params[i].m_szValue.GetString())); - } - - szCombined = szMessage; - szCombined.AppendTail(szHeader); - szCombined.AppendTail("\r\n"); - - Write(szCombined.GetString(), szCombined.GetLenght()); -} - -HTTPResponse_t CHTTPClient::GetResponse() -{ - CUtlResizableBuffer szCharBuffer(0); - char response[4096] = {}; - int n; - int nPreviousSize = 0; - -readSocket: - - n = Read(response, sizeof(response)); - V_printf("%s\n",response); - if (n == -1) - goto responseDone; - - - szCharBuffer.Resize(nPreviousSize+n); - V_memcpy((char*)szCharBuffer.GetMemory()+nPreviousSize, response, n); - nPreviousSize += n; - - // HTTP 1.0 reacts either to socket being closed or Content-Lenght - // HTTP 1.1 has Transfer-Encoding: chunked, which we need to respect - // Still some response codes may not include a body - if ( n > 0 ) - { - HTTPResponse_t r = ParseResponse(szCharBuffer, szCharBuffer.GetSize()); - if (r.m_bIsComplete) - goto responseDone; - - // these do not provide body - } - // there is some data so go and read back again - goto readSocket; -responseDone: - - return ParseResponse(szCharBuffer, szCharBuffer.GetSize()); -} - -HTTPResponse_t CHTTPClient::ParseResponse( const char *szMessage, uint32_t uDataSize ) -{ - char cPreviousCharacter = 0; - char cCurrentCharacter = 0; - const char *pcCurrentCharacter = szMessage; - CUtlString szBuffer = ""; - bool bIsMessage = true; - HTTPResponse_t response = {}; - CUtlVector headers = {}; - CUtlBuffer data = {}; - - if (!szMessage) - return {}; - // Parse header - while (*pcCurrentCharacter) - { - cCurrentCharacter = *pcCurrentCharacter; - if ( cPreviousCharacter == '\r') - { - if ( cCurrentCharacter == '\n') - { - if (bIsMessage) - { - uint32_t uResult = 0; - while (szBuffer[0] != ' ') - szBuffer.RemoveHead(1); - while (szBuffer[0] == ' ') - szBuffer.RemoveHead(1); - V_sscanf(szBuffer, "%i", &uResult); - response.m_uCode = uResult; - } - if (szBuffer == "") - break; - if (!bIsMessage) - headers.AppendTail(ParseHeaderParams(szBuffer)); - bIsMessage = false; - szBuffer = ""; - cPreviousCharacter = 0; - cCurrentCharacter = *pcCurrentCharacter++; - continue; - } - } - if (cPreviousCharacter != 0) - szBuffer.AppendTail(cPreviousCharacter); - pcCurrentCharacter++; - - cPreviousCharacter = cCurrentCharacter; - }; - switch (response.m_uCode) - { - case 100: - case 101: - case 204: - case 205: - case 304: - response.m_bIsComplete = true; - return response; - default: - break; - } - - bool bParseInChunks = false; - uint64_t uBodySize = 0; - // check content lenght - for ( int i = 0; i < headers.GetSize(); i++ ) - { - if ( !V_stricmp( headers[i].m_szParamName, "Content-Length" ) ) - { - uBodySize = atoll(headers[i].m_szValue); - bParseInChunks = false; - }; - - - if ( !V_stricmp( headers[i].m_szParamName, "Transfer-Encoding" ) ) - { - if ( !V_stricmp( headers[i].m_szValue, "Chunked" ) ) - { - bParseInChunks = true; - }; - }; - } - pcCurrentCharacter++; - if ( !bParseInChunks ) - { - uint32_t nDataLen = uDataSize-(pcCurrentCharacter-szMessage); - if (nDataLen < uBodySize) - { - response.m_bIsComplete = false; - return response; - } - data = CUtlBuffer(nDataLen+1); - V_memcpy(data.GetMemory(), pcCurrentCharacter, nDataLen); - data[nDataLen] = 0; - response.m_params = CUtlBuffer(headers.GetSize()); - for (int i = 0; i < headers.GetSize(); i++ ) - { - response.m_params.operator[](i) = headers.operator[](i); - } - response.m_message = data; - response.m_bIsComplete = true; - - } else { - szBuffer = ""; - while (*pcCurrentCharacter) - { - - cCurrentCharacter = *pcCurrentCharacter; - if ( cPreviousCharacter == '\r') - { - if ( cCurrentCharacter == '\n') - { - uint32_t uChunkSize; - uChunkSize = strtol(szBuffer, NULL, 0); - } - } - if (cPreviousCharacter != 0) - szBuffer.AppendTail(cPreviousCharacter); - pcCurrentCharacter++; - - cPreviousCharacter = cCurrentCharacter; - } - } - - return response; -} - -const char *CHTTPClient::GetVersion() -{ - - return "1.1"; -} -HTTPHeaderParam_t CHTTPClient::ParseHeaderParams( const char *szHeaderLine ) -{ - const char *psz = szHeaderLine; - CUtlString szName; - CUtlString szValue; - - int stage = 0; - while (*psz) - { - if (stage == 0) - { - if (*psz == ':') - stage = 1; - else - szName.AppendTail(*psz); - } else if (stage == 1) - { - if (*psz != ' ') - break; - } - psz++; - } - szValue = psz; - return {szName, szValue}; -} -void CHTTPClient::ConnectToServer() -{ - struct hostent *pServerHostName = NULL; - struct sockaddr_in serverAddress; - int err; - SSL_CTX *ctx; - SSL *ssl; - - if (V_strcmp(m_szHostName, "localhost")) - { - pServerHostName = gethostbyname(m_szHostName); - if (!pServerHostName) - return; - } - - - V_memset(&serverAddress, 0, sizeof(serverAddress)); - serverAddress.sin_family = AF_INET; - if (!V_strcmp(m_szHostName, "localhost")) - inet_pton(AF_INET, "127.0.0.1", &serverAddress.sin_addr); - else - V_memcpy(&serverAddress.sin_addr.s_addr, pServerHostName->h_addr, pServerHostName->h_length); - - // https - serverAddress.sin_port = htons(m_uPort); - - err = connect(m_iFileDescriptor, (struct sockaddr *)&serverAddress, sizeof(serverAddress)); - if (err < 0) - return; - - if (m_bIsSecure) - { - ctx = SSL_CTX_new(TLS_client_method()); - if (!ctx) - return; - ssl =SSL_new(ctx); - if (!ssl) - return; - - SSL_set_fd(ssl, m_iFileDescriptor); - SSL_set_tlsext_host_name(ssl, m_szHostName); - - int r = SSL_connect(ssl); - if (r <= 0) - { - ERR_print_errors_fp(stdout); - SSL_free(ssl); - SSL_CTX_free(ctx); - return; - } - }; - - if (m_bIsSecure) - { - m_pSSL = ssl; - m_pSSLCtx = ctx; - } - - -} - -void CHTTPClient::CloseConnection() -{ - -} -bool CHTTPClient::WebSocket_Connect( const char *szResource ) -{ - HTTPResponse_t stResponse; - HTTPHeaderParam_t params[] = { - {"Upgrade", "websocket"}, - {"Connection", "Upgrade"}, - {"Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="}, - {"Sec-WebSocket-Protocol", "chat, superchat"}, - {"Sec-WebSocket-Version", "13"}, - }; - HTTPHeader_t stHeader = { - sizeof(params)/sizeof(params[0]), - params - }; - Get(szResource, &stHeader); - stResponse = GetResponse(); - // According to spec 101 is a good sign - if (stResponse.m_uCode == 101) - return true; - return false; -} - - -void CHTTPClient::WebSocket_Close( void ) -{ - -} - -enum EWebSocketOp -{ - WEBSOCKET_CONTINUE = 0, - WEBSOCKET_TEXT = 1, - WEBSOCKET_BINARY = 2, - WEBSOCKET_CLOSE = 8, - WEBSOCKET_PING = 9, - WEBSOCKET_PONG = 10, -}; - -struct WebSocketFrame_t -{ - EWebSocketOp nOpCode: 4; - uint8_t nReserved: 3; - uint8_t bFin: 1; - uint8_t nPayloadLenght: 7; - uint8_t bMasked: 1; -}; - -void CHTTPClient::WebSocket_SendText( const char *szData ) -{ - size_t uLen; - WebSocketFrame_t stFrame; - uLen = V_strlen(szData); - stFrame = (WebSocketFrame_t){ - .nOpCode = WEBSOCKET_TEXT, - .bFin = 1, - .bMasked = 1, - }; - // im too lazy to mask it - int iMask = 0; - - if ( uLen <= 125 ) - { - stFrame.nPayloadLenght = uLen; - Write(&stFrame, 2); - Write(&iMask, 4); - } - else if ( uLen <= 65535 ) - { - stFrame.nPayloadLenght = 126; - Write(&stFrame, 2); - uint16_t uLenN = htons(uLen); - Write(&uLenN, 2); - Write(&iMask, 4); - } - else - { - stFrame.nPayloadLenght = 127; - Write(&stFrame, 2); - Write(&iMask, 4); - Write(&uLen, 8); - } - Write((void*)szData, uLen); - -} - -CUtlString CHTTPClient::WebSocket_RecvText() -{ - WebSocketFrame_t stFrame; - size_t uLen = 0; - CUtlBuffer szText; - Read(&stFrame, 2); - if (stFrame.nPayloadLenght == 126) - { - Read(&uLen, 2); - } else if (stFrame.nPayloadLenght == 127) - { - Read(&uLen, 8); - } else { - uLen = stFrame.nPayloadLenght; - } - szText = CUtlBuffer(uLen+1); - Read(szText, uLen); - szText[uLen] = 0; - return szText.GetMemory(); -} - -void CHTTPClient::WebSocket_SendBinary( size_t uSize, const void *pData ) -{ - -} - -WebSocketPacket_t CHTTPClient::WebSocket_RecvBinary() -{ - -} - - -ssize_t CHTTPClient::Write( void *pData, ssize_t uSize ) -{ - if (m_bIsSecure) - return SSL_write(m_pSSL, pData, uSize); - else - return write(m_iFileDescriptor, pData, uSize); -} - -ssize_t CHTTPClient::Read( void *pData, ssize_t uSize ) -{ - ssize_t n; - if ( m_bIsSecure ) - { - n = SSL_read(m_pSSL, pData, uSize); - if (n == 0) - return -1; - } - else - { - n = read(m_iFileDescriptor, pData, uSize); - if (n == -1) - return -1; - } - return n; -} - - - -abstract_class CHTTPClientManager: public IHTTPClientManager -{ -public: - CHTTPClientManager(); - virtual IHTTPClient *Connect( const char *szUrl, bool bSecure, uint16_t *pPort ) override; - virtual void Disconnect( IHTTPClient *szConnection ) override; -}; - -IHTTPClient *CHTTPClientManager::Connect( const char *szUrl, bool bSecure, uint16_t *pPort ) -{ - CHTTPClient *pClient; - int fd = 0; - - pClient = new CHTTPClient(); - if (pPort) - pClient->m_uPort = *pPort; - else - { - if (bSecure) - pClient->m_uPort = 443; - else - pClient->m_uPort = 80; - } - - fd = socket(AF_INET, SOCK_STREAM, 0); - if ( fd < 0 ) - return NULL; - - pClient->m_iFileDescriptor = fd; - - pClient->m_szHostName = szUrl; - pClient->m_bIsSecure = bSecure; - return pClient; -} - -void CHTTPClientManager::Disconnect( IHTTPClient *pClient ) -{ - CHTTPClient *pC = (CHTTPClient*)pClient; - close(pC->m_iFileDescriptor); -} - -CHTTPClientManager::CHTTPClientManager() -{ - SSL_library_init(); - SSL_load_error_strings(); - OpenSSL_add_all_algorithms(); -} - - -CHTTPClientManager s_HttpClientManager; -EXPOSE_INTERFACE_GLOBALVAR(IHTTPClientManager, CHTTPClientManager, HTTP_CLIENT_INTERFACE_VERSION, s_HttpClientManager); - diff --git a/http/test.cpp b/http/test.cpp deleted file mode 100644 index dc2294d..0000000 --- a/http/test.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "http/http.h" -#include "tier1/interface.h" - -IHTTPClientManager *g_pHttpClientMgr; -int main() -{ - Sys_GetFactory("tier0"); - CreateInterfaceFn pHttpFactory = Sys_GetFactory("funnyhttp"); - g_pHttpClientMgr = (IHTTPClientManager*)pHttpFactory(HTTP_CLIENT_INTERFACE_VERSION, NULL); - if ( !g_pHttpClientMgr ) - return 0; - IHTTPClient *pClient = g_pHttpClientMgr->Connect("www.example.com", true, NULL); - printf("%p\n",pClient); - if ( pClient == NULL ) - return 0; - HTTPHeaderParam_t params[] = { - {"User-Agent", "Funny"}, - {"Accept", "application/json"}, - }; - - HTTPHeader_t stHeader = { - sizeof(params)/sizeof(params[0]), - params - }; - pClient->Get("/", &stHeader); - - HTTPResponse_t stResponse = pClient->GetResponse(); - if (stResponse.m_uCode == 200) - { - V_printf("%s\n", stResponse.m_message.GetMemory()); - } - - g_pHttpClientMgr->Disconnect(pClient); - - return 0; -} diff --git a/ios_deploy/funnygame/Frameworks/.framework/Headers/SDL_gamepad.h b/ios_deploy/funnygame/Frameworks/.framework/Headers/SDL_gamepad.h deleted file mode 100644 index 460ae98..0000000 --- a/ios_deploy/funnygame/Frameworks/.framework/Headers/SDL_gamepad.h +++ /dev/null @@ -1,1513 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2025 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -/** - * # CategoryGamepad - * - * SDL provides a low-level joystick API, which just treats joysticks as an - * arbitrary pile of buttons, axes, and hat switches. If you're planning to - * write your own control configuration screen, this can give you a lot of - * flexibility, but that's a lot of work, and most things that we consider - * "joysticks" now are actually console-style gamepads. So SDL provides the - * gamepad API on top of the lower-level joystick functionality. - * - * The difference between a joystick and a gamepad is that a gamepad tells you - * _where_ a button or axis is on the device. You don't speak to gamepads in - * terms of arbitrary numbers like "button 3" or "axis 2" but in standard - * locations: the d-pad, the shoulder buttons, triggers, A/B/X/Y (or - * X/O/Square/Triangle, if you will). - * - * One turns a joystick into a gamepad by providing a magic configuration - * string, which tells SDL the details of a specific device: when you see this - * specific hardware, if button 2 gets pressed, this is actually D-Pad Up, - * etc. - * - * SDL has many popular controllers configured out of the box, and users can - * add their own controller details through an environment variable if it's - * otherwise unknown to SDL. - * - * In order to use these functions, SDL_Init() must have been called with the - * SDL_INIT_GAMEPAD flag. This causes SDL to scan the system for gamepads, and - * load appropriate drivers. - * - * If you would like to receive gamepad updates while the application is in - * the background, you should set the following hint before calling - * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS - * - * Gamepads support various optional features such as rumble, color LEDs, - * touchpad, gyro, etc. The support for these features varies depending on the - * controller and OS support available. You can check for LED and rumble - * capabilities at runtime by calling SDL_GetGamepadProperties() and checking - * the various capability properties. You can check for touchpad by calling - * SDL_GetNumGamepadTouchpads() and check for gyro and accelerometer by - * calling SDL_GamepadHasSensor(). - * - * By default SDL will try to use the most capable driver available, but you - * can tune which OS drivers to use with the various joystick hints in - * SDL_hints.h. - * - * Your application should always support gamepad hotplugging. On some - * platforms like Xbox, Steam Deck, etc., this is a requirement for - * certification. On other platforms, like macOS and Windows when using - * Windows.Gaming.Input, controllers may not be available at startup and will - * come in at some point after you've started processing events. - */ - -#ifndef SDL_gamepad_h_ -#define SDL_gamepad_h_ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -/** - * The structure used to identify an SDL gamepad - * - * \since This struct is available since SDL 3.2.0. - */ -typedef struct SDL_Gamepad SDL_Gamepad; - -/** - * Standard gamepad types. - * - * This type does not necessarily map to first-party controllers from - * Microsoft/Sony/Nintendo; in many cases, third-party controllers can report - * as these, either because they were designed for a specific console, or they - * simply most closely match that console's controllers (does it have A/B/X/Y - * buttons or X/O/Square/Triangle? Does it have a touchpad? etc). - */ -typedef enum SDL_GamepadType -{ - SDL_GAMEPAD_TYPE_UNKNOWN = 0, - SDL_GAMEPAD_TYPE_STANDARD, - SDL_GAMEPAD_TYPE_XBOX360, - SDL_GAMEPAD_TYPE_XBOXONE, - SDL_GAMEPAD_TYPE_PS3, - SDL_GAMEPAD_TYPE_PS4, - SDL_GAMEPAD_TYPE_PS5, - SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO, - SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT, - SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT, - SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR, - SDL_GAMEPAD_TYPE_GAMECUBE, - SDL_GAMEPAD_TYPE_COUNT -} SDL_GamepadType; - -/** - * The list of buttons available on a gamepad - * - * For controllers that use a diamond pattern for the face buttons, the - * south/east/west/north buttons below correspond to the locations in the - * diamond pattern. For Xbox controllers, this would be A/B/X/Y, for Nintendo - * Switch controllers, this would be B/A/Y/X, for GameCube controllers this - * would be A/X/B/Y, for PlayStation controllers this would be - * Cross/Circle/Square/Triangle. - * - * For controllers that don't use a diamond pattern for the face buttons, the - * south/east/west/north buttons indicate the buttons labeled A, B, C, D, or - * 1, 2, 3, 4, or for controllers that aren't labeled, they are the primary, - * secondary, etc. buttons. - * - * The activate action is often the south button and the cancel action is - * often the east button, but in some regions this is reversed, so your game - * should allow remapping actions based on user preferences. - * - * You can query the labels for the face buttons using - * SDL_GetGamepadButtonLabel() - * - * \since This enum is available since SDL 3.2.0. - */ -typedef enum SDL_GamepadButton -{ - SDL_GAMEPAD_BUTTON_INVALID = -1, - SDL_GAMEPAD_BUTTON_SOUTH, /**< Bottom face button (e.g. Xbox A button) */ - SDL_GAMEPAD_BUTTON_EAST, /**< Right face button (e.g. Xbox B button) */ - SDL_GAMEPAD_BUTTON_WEST, /**< Left face button (e.g. Xbox X button) */ - SDL_GAMEPAD_BUTTON_NORTH, /**< Top face button (e.g. Xbox Y button) */ - SDL_GAMEPAD_BUTTON_BACK, - SDL_GAMEPAD_BUTTON_GUIDE, - SDL_GAMEPAD_BUTTON_START, - SDL_GAMEPAD_BUTTON_LEFT_STICK, - SDL_GAMEPAD_BUTTON_RIGHT_STICK, - SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, - SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, - SDL_GAMEPAD_BUTTON_DPAD_UP, - SDL_GAMEPAD_BUTTON_DPAD_DOWN, - SDL_GAMEPAD_BUTTON_DPAD_LEFT, - SDL_GAMEPAD_BUTTON_DPAD_RIGHT, - SDL_GAMEPAD_BUTTON_MISC1, /**< Additional button (e.g. Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button, Google Stadia capture button) */ - SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1, /**< Upper or primary paddle, under your right hand (e.g. Xbox Elite paddle P1) */ - SDL_GAMEPAD_BUTTON_LEFT_PADDLE1, /**< Upper or primary paddle, under your left hand (e.g. Xbox Elite paddle P3) */ - SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2, /**< Lower or secondary paddle, under your right hand (e.g. Xbox Elite paddle P2) */ - SDL_GAMEPAD_BUTTON_LEFT_PADDLE2, /**< Lower or secondary paddle, under your left hand (e.g. Xbox Elite paddle P4) */ - SDL_GAMEPAD_BUTTON_TOUCHPAD, /**< PS4/PS5 touchpad button */ - SDL_GAMEPAD_BUTTON_MISC2, /**< Additional button */ - SDL_GAMEPAD_BUTTON_MISC3, /**< Additional button */ - SDL_GAMEPAD_BUTTON_MISC4, /**< Additional button */ - SDL_GAMEPAD_BUTTON_MISC5, /**< Additional button */ - SDL_GAMEPAD_BUTTON_MISC6, /**< Additional button */ - SDL_GAMEPAD_BUTTON_COUNT -} SDL_GamepadButton; - -/** - * The set of gamepad button labels - * - * This isn't a complete set, just the face buttons to make it easy to show - * button prompts. - * - * For a complete set, you should look at the button and gamepad type and have - * a set of symbols that work well with your art style. - * - * \since This enum is available since SDL 3.2.0. - */ -typedef enum SDL_GamepadButtonLabel -{ - SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN, - SDL_GAMEPAD_BUTTON_LABEL_A, - SDL_GAMEPAD_BUTTON_LABEL_B, - SDL_GAMEPAD_BUTTON_LABEL_X, - SDL_GAMEPAD_BUTTON_LABEL_Y, - SDL_GAMEPAD_BUTTON_LABEL_CROSS, - SDL_GAMEPAD_BUTTON_LABEL_CIRCLE, - SDL_GAMEPAD_BUTTON_LABEL_SQUARE, - SDL_GAMEPAD_BUTTON_LABEL_TRIANGLE -} SDL_GamepadButtonLabel; - -/** - * The list of axes available on a gamepad - * - * Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to - * SDL_JOYSTICK_AXIS_MAX, and are centered within ~8000 of zero, though - * advanced UI will allow users to set or autodetect the dead zone, which - * varies between gamepads. - * - * Trigger axis values range from 0 (released) to SDL_JOYSTICK_AXIS_MAX (fully - * pressed) when reported by SDL_GetGamepadAxis(). Note that this is not the - * same range that will be reported by the lower-level SDL_GetJoystickAxis(). - * - * \since This enum is available since SDL 3.2.0. - */ -typedef enum SDL_GamepadAxis -{ - SDL_GAMEPAD_AXIS_INVALID = -1, - SDL_GAMEPAD_AXIS_LEFTX, - SDL_GAMEPAD_AXIS_LEFTY, - SDL_GAMEPAD_AXIS_RIGHTX, - SDL_GAMEPAD_AXIS_RIGHTY, - SDL_GAMEPAD_AXIS_LEFT_TRIGGER, - SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, - SDL_GAMEPAD_AXIS_COUNT -} SDL_GamepadAxis; - -/** - * Types of gamepad control bindings. - * - * A gamepad is a collection of bindings that map arbitrary joystick buttons, - * axes and hat switches to specific positions on a generic console-style - * gamepad. This enum is used as part of SDL_GamepadBinding to specify those - * mappings. - * - * \since This enum is available since SDL 3.2.0. - */ -typedef enum SDL_GamepadBindingType -{ - SDL_GAMEPAD_BINDTYPE_NONE = 0, - SDL_GAMEPAD_BINDTYPE_BUTTON, - SDL_GAMEPAD_BINDTYPE_AXIS, - SDL_GAMEPAD_BINDTYPE_HAT -} SDL_GamepadBindingType; - -/** - * A mapping between one joystick input to a gamepad control. - * - * A gamepad has a collection of several bindings, to say, for example, when - * joystick button number 5 is pressed, that should be treated like the - * gamepad's "start" button. - * - * SDL has these bindings built-in for many popular controllers, and can add - * more with a simple text string. Those strings are parsed into a collection - * of these structs to make it easier to operate on the data. - * - * \since This struct is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadBindings - */ -typedef struct SDL_GamepadBinding -{ - SDL_GamepadBindingType input_type; - union - { - int button; - - struct - { - int axis; - int axis_min; - int axis_max; - } axis; - - struct - { - int hat; - int hat_mask; - } hat; - - } input; - - SDL_GamepadBindingType output_type; - union - { - SDL_GamepadButton button; - - struct - { - SDL_GamepadAxis axis; - int axis_min; - int axis_max; - } axis; - - } output; -} SDL_GamepadBinding; - - -/** - * Add support for gamepads that SDL is unaware of or change the binding of an - * existing gamepad. - * - * The mapping string has the format "GUID,name,mapping", where GUID is the - * string value from SDL_GUIDToString(), name is the human readable string for - * the device and mappings are gamepad mappings to joystick ones. Under - * Windows there is a reserved GUID of "xinput" that covers all XInput - * devices. The mapping format for joystick is: - * - * - `bX`: a joystick button, index X - * - `hX.Y`: hat X with value Y - * - `aX`: axis X of the joystick - * - * Buttons can be used as a gamepad axes and vice versa. - * - * If a device with this GUID is already plugged in, SDL will generate an - * SDL_EVENT_GAMEPAD_ADDED event. - * - * This string shows an example of a valid mapping for a gamepad: - * - * ```c - * "341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7" - * ``` - * - * \param mapping the mapping string. - * \returns 1 if a new mapping is added, 0 if an existing mapping is updated, - * -1 on failure; call SDL_GetError() for more information. - * - * \threadsafety It is safe to call this function from any thread. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_AddGamepadMappingsFromFile - * \sa SDL_AddGamepadMappingsFromIO - * \sa SDL_GetGamepadMapping - * \sa SDL_GetGamepadMappingForGUID - * \sa SDL_HINT_GAMECONTROLLERCONFIG - * \sa SDL_HINT_GAMECONTROLLERCONFIG_FILE - * \sa SDL_EVENT_GAMEPAD_ADDED - */ -extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMapping(const char *mapping); - -/** - * Load a set of gamepad mappings from an SDL_IOStream. - * - * You can call this function several times, if needed, to load different - * database files. - * - * If a new mapping is loaded for an already known gamepad GUID, the later - * version will overwrite the one currently loaded. - * - * Any new mappings for already plugged in controllers will generate - * SDL_EVENT_GAMEPAD_ADDED events. - * - * Mappings not belonging to the current platform or with no platform field - * specified will be ignored (i.e. mappings for Linux will be ignored in - * Windows, etc). - * - * This function will load the text database entirely in memory before - * processing it, so take this into consideration if you are in a memory - * constrained environment. - * - * \param src the data stream for the mappings to be added. - * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even - * in the case of an error. - * \returns the number of mappings added or -1 on failure; call SDL_GetError() - * for more information. - * - * \threadsafety It is safe to call this function from any thread. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_AddGamepadMapping - * \sa SDL_AddGamepadMappingsFromFile - * \sa SDL_GetGamepadMapping - * \sa SDL_GetGamepadMappingForGUID - * \sa SDL_HINT_GAMECONTROLLERCONFIG - * \sa SDL_HINT_GAMECONTROLLERCONFIG_FILE - * \sa SDL_EVENT_GAMEPAD_ADDED - */ -extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, bool closeio); - -/** - * Load a set of gamepad mappings from a file. - * - * You can call this function several times, if needed, to load different - * database files. - * - * If a new mapping is loaded for an already known gamepad GUID, the later - * version will overwrite the one currently loaded. - * - * Any new mappings for already plugged in controllers will generate - * SDL_EVENT_GAMEPAD_ADDED events. - * - * Mappings not belonging to the current platform or with no platform field - * specified will be ignored (i.e. mappings for Linux will be ignored in - * Windows, etc). - * - * \param file the mappings file to load. - * \returns the number of mappings added or -1 on failure; call SDL_GetError() - * for more information. - * - * \threadsafety It is safe to call this function from any thread. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_AddGamepadMapping - * \sa SDL_AddGamepadMappingsFromIO - * \sa SDL_GetGamepadMapping - * \sa SDL_GetGamepadMappingForGUID - * \sa SDL_HINT_GAMECONTROLLERCONFIG - * \sa SDL_HINT_GAMECONTROLLERCONFIG_FILE - * \sa SDL_EVENT_GAMEPAD_ADDED - */ -extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromFile(const char *file); - -/** - * Reinitialize the SDL mapping database to its initial state. - * - * This will generate gamepad events as needed if device mappings change. - * - * \returns true on success or false on failure; call SDL_GetError() for more - * information. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC bool SDLCALL SDL_ReloadGamepadMappings(void); - -/** - * Get the current gamepad mappings. - * - * \param count a pointer filled in with the number of mappings returned, can - * be NULL. - * \returns an array of the mapping strings, NULL-terminated, or NULL on - * failure; call SDL_GetError() for more information. This is a - * single allocation that should be freed with SDL_free() when it is - * no longer needed. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC char ** SDLCALL SDL_GetGamepadMappings(int *count); - -/** - * Get the gamepad mapping string for a given GUID. - * - * \param guid a structure containing the GUID for which a mapping is desired. - * \returns a mapping string or NULL on failure; call SDL_GetError() for more - * information. This should be freed with SDL_free() when it is no - * longer needed. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetJoystickGUIDForID - * \sa SDL_GetJoystickGUID - */ -extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_GUID guid); - -/** - * Get the current mapping of a gamepad. - * - * Details about mappings are discussed with SDL_AddGamepadMapping(). - * - * \param gamepad the gamepad you want to get the current mapping for. - * \returns a string that has the gamepad's mapping or NULL if no mapping is - * available; call SDL_GetError() for more information. This should - * be freed with SDL_free() when it is no longer needed. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_AddGamepadMapping - * \sa SDL_GetGamepadMappingForID - * \sa SDL_GetGamepadMappingForGUID - * \sa SDL_SetGamepadMapping - */ -extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad); - -/** - * Set the current mapping of a joystick or gamepad. - * - * Details about mappings are discussed with SDL_AddGamepadMapping(). - * - * \param instance_id the joystick instance ID. - * \param mapping the mapping to use for this device, or NULL to clear the - * mapping. - * \returns true on success or false on failure; call SDL_GetError() for more - * information. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_AddGamepadMapping - * \sa SDL_GetGamepadMapping - */ -extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping); - -/** - * Return whether a gamepad is currently connected. - * - * \returns true if a gamepad is connected, false otherwise. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepads - */ -extern SDL_DECLSPEC bool SDLCALL SDL_HasGamepad(void); - -/** - * Get a list of currently connected gamepads. - * - * \param count a pointer filled in with the number of gamepads returned, may - * be NULL. - * \returns a 0 terminated array of joystick instance IDs or NULL on failure; - * call SDL_GetError() for more information. This should be freed - * with SDL_free() when it is no longer needed. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_HasGamepad - * \sa SDL_OpenGamepad - */ -extern SDL_DECLSPEC SDL_JoystickID * SDLCALL SDL_GetGamepads(int *count); - -/** - * Check if the given joystick is supported by the gamepad interface. - * - * \param instance_id the joystick instance ID. - * \returns true if the given joystick is supported by the gamepad interface, - * false if it isn't or it's an invalid index. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetJoysticks - * \sa SDL_OpenGamepad - */ -extern SDL_DECLSPEC bool SDLCALL SDL_IsGamepad(SDL_JoystickID instance_id); - -/** - * Get the implementation dependent name of a gamepad. - * - * This can be called before any gamepads are opened. - * - * \param instance_id the joystick instance ID. - * \returns the name of the selected gamepad. If no name can be found, this - * function returns NULL; call SDL_GetError() for more information. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadName - * \sa SDL_GetGamepads - */ -extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadNameForID(SDL_JoystickID instance_id); - -/** - * Get the implementation dependent path of a gamepad. - * - * This can be called before any gamepads are opened. - * - * \param instance_id the joystick instance ID. - * \returns the path of the selected gamepad. If no path can be found, this - * function returns NULL; call SDL_GetError() for more information. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadPath - * \sa SDL_GetGamepads - */ -extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadPathForID(SDL_JoystickID instance_id); - -/** - * Get the player index of a gamepad. - * - * This can be called before any gamepads are opened. - * - * \param instance_id the joystick instance ID. - * \returns the player index of a gamepad, or -1 if it's not available. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadPlayerIndex - * \sa SDL_GetGamepads - */ -extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndexForID(SDL_JoystickID instance_id); - -/** - * Get the implementation-dependent GUID of a gamepad. - * - * This can be called before any gamepads are opened. - * - * \param instance_id the joystick instance ID. - * \returns the GUID of the selected gamepad. If called on an invalid index, - * this function returns a zero GUID. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GUIDToString - * \sa SDL_GetGamepads - */ -extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetGamepadGUIDForID(SDL_JoystickID instance_id); - -/** - * Get the USB vendor ID of a gamepad, if available. - * - * This can be called before any gamepads are opened. If the vendor ID isn't - * available this function returns 0. - * - * \param instance_id the joystick instance ID. - * \returns the USB vendor ID of the selected gamepad. If called on an invalid - * index, this function returns zero. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadVendor - * \sa SDL_GetGamepads - */ -extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendorForID(SDL_JoystickID instance_id); - -/** - * Get the USB product ID of a gamepad, if available. - * - * This can be called before any gamepads are opened. If the product ID isn't - * available this function returns 0. - * - * \param instance_id the joystick instance ID. - * \returns the USB product ID of the selected gamepad. If called on an - * invalid index, this function returns zero. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadProduct - * \sa SDL_GetGamepads - */ -extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductForID(SDL_JoystickID instance_id); - -/** - * Get the product version of a gamepad, if available. - * - * This can be called before any gamepads are opened. If the product version - * isn't available this function returns 0. - * - * \param instance_id the joystick instance ID. - * \returns the product version of the selected gamepad. If called on an - * invalid index, this function returns zero. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadProductVersion - * \sa SDL_GetGamepads - */ -extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersionForID(SDL_JoystickID instance_id); - -/** - * Get the type of a gamepad. - * - * This can be called before any gamepads are opened. - * - * \param instance_id the joystick instance ID. - * \returns the gamepad type. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadType - * \sa SDL_GetGamepads - * \sa SDL_GetRealGamepadTypeForID - */ -extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeForID(SDL_JoystickID instance_id); - -/** - * Get the type of a gamepad, ignoring any mapping override. - * - * This can be called before any gamepads are opened. - * - * \param instance_id the joystick instance ID. - * \returns the gamepad type. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadTypeForID - * \sa SDL_GetGamepads - * \sa SDL_GetRealGamepadType - */ -extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadTypeForID(SDL_JoystickID instance_id); - -/** - * Get the mapping of a gamepad. - * - * This can be called before any gamepads are opened. - * - * \param instance_id the joystick instance ID. - * \returns the mapping string. Returns NULL if no mapping is available. This - * should be freed with SDL_free() when it is no longer needed. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepads - * \sa SDL_GetGamepadMapping - */ -extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMappingForID(SDL_JoystickID instance_id); - -/** - * Open a gamepad for use. - * - * \param instance_id the joystick instance ID. - * \returns a gamepad identifier or NULL if an error occurred; call - * SDL_GetError() for more information. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_CloseGamepad - * \sa SDL_IsGamepad - */ -extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_OpenGamepad(SDL_JoystickID instance_id); - -/** - * Get the SDL_Gamepad associated with a joystick instance ID, if it has been - * opened. - * - * \param instance_id the joystick instance ID of the gamepad. - * \returns an SDL_Gamepad on success or NULL on failure or if it hasn't been - * opened yet; call SDL_GetError() for more information. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_GetGamepadFromID(SDL_JoystickID instance_id); - -/** - * Get the SDL_Gamepad associated with a player index. - * - * \param player_index the player index, which different from the instance ID. - * \returns the SDL_Gamepad associated with a player index. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadPlayerIndex - * \sa SDL_SetGamepadPlayerIndex - */ -extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_GetGamepadFromPlayerIndex(int player_index); - -/** - * Get the properties associated with an opened gamepad. - * - * These properties are shared with the underlying joystick object. - * - * The following read-only properties are provided by SDL: - * - * - `SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN`: true if this gamepad has an LED - * that has adjustable brightness - * - `SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN`: true if this gamepad has an LED - * that has adjustable color - * - `SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN`: true if this gamepad has a - * player LED - * - `SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN`: true if this gamepad has - * left/right rumble - * - `SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN`: true if this gamepad has - * simple trigger rumble - * - * \param gamepad a gamepad identifier previously returned by - * SDL_OpenGamepad(). - * \returns a valid property ID on success or 0 on failure; call - * SDL_GetError() for more information. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGamepadProperties(SDL_Gamepad *gamepad); - -#define SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN -#define SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN -#define SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN -#define SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN -#define SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN - -/** - * Get the instance ID of an opened gamepad. - * - * \param gamepad a gamepad identifier previously returned by - * SDL_OpenGamepad(). - * \returns the instance ID of the specified gamepad on success or 0 on - * failure; call SDL_GetError() for more information. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetGamepadID(SDL_Gamepad *gamepad); - -/** - * Get the implementation-dependent name for an opened gamepad. - * - * \param gamepad a gamepad identifier previously returned by - * SDL_OpenGamepad(). - * \returns the implementation dependent name for the gamepad, or NULL if - * there is no name or the identifier passed is invalid. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadNameForID - */ -extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadName(SDL_Gamepad *gamepad); - -/** - * Get the implementation-dependent path for an opened gamepad. - * - * \param gamepad a gamepad identifier previously returned by - * SDL_OpenGamepad(). - * \returns the implementation dependent path for the gamepad, or NULL if - * there is no path or the identifier passed is invalid. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadPathForID - */ -extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadPath(SDL_Gamepad *gamepad); - -/** - * Get the type of an opened gamepad. - * - * \param gamepad the gamepad object to query. - * \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not - * available. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadTypeForID - */ -extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadType(SDL_Gamepad *gamepad); - -/** - * Get the type of an opened gamepad, ignoring any mapping override. - * - * \param gamepad the gamepad object to query. - * \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not - * available. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetRealGamepadTypeForID - */ -extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadType(SDL_Gamepad *gamepad); - -/** - * Get the player index of an opened gamepad. - * - * For XInput gamepads this returns the XInput user index. - * - * \param gamepad the gamepad object to query. - * \returns the player index for gamepad, or -1 if it's not available. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_SetGamepadPlayerIndex - */ -extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad); - -/** - * Set the player index of an opened gamepad. - * - * \param gamepad the gamepad object to adjust. - * \param player_index player index to assign to this gamepad, or -1 to clear - * the player index and turn off player LEDs. - * \returns true on success or false on failure; call SDL_GetError() for more - * information. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadPlayerIndex - */ -extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index); - -/** - * Get the USB vendor ID of an opened gamepad, if available. - * - * If the vendor ID isn't available this function returns 0. - * - * \param gamepad the gamepad object to query. - * \returns the USB vendor ID, or zero if unavailable. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadVendorForID - */ -extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendor(SDL_Gamepad *gamepad); - -/** - * Get the USB product ID of an opened gamepad, if available. - * - * If the product ID isn't available this function returns 0. - * - * \param gamepad the gamepad object to query. - * \returns the USB product ID, or zero if unavailable. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadProductForID - */ -extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProduct(SDL_Gamepad *gamepad); - -/** - * Get the product version of an opened gamepad, if available. - * - * If the product version isn't available this function returns 0. - * - * \param gamepad the gamepad object to query. - * \returns the USB product version, or zero if unavailable. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadProductVersionForID - */ -extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersion(SDL_Gamepad *gamepad); - -/** - * Get the firmware version of an opened gamepad, if available. - * - * If the firmware version isn't available this function returns 0. - * - * \param gamepad the gamepad object to query. - * \returns the gamepad firmware version, or zero if unavailable. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepad); - -/** - * Get the serial number of an opened gamepad, if available. - * - * Returns the serial number of the gamepad, or NULL if it is not available. - * - * \param gamepad the gamepad object to query. - * \returns the serial number, or NULL if unavailable. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad); - -/** - * Get the Steam Input handle of an opened gamepad, if available. - * - * Returns an InputHandle_t for the gamepad that can be used with Steam Input - * API: https://partner.steamgames.com/doc/api/ISteamInput - * - * \param gamepad the gamepad object to query. - * \returns the gamepad handle, or 0 if unavailable. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetGamepadSteamHandle(SDL_Gamepad *gamepad); - -/** - * Get the connection state of a gamepad. - * - * \param gamepad the gamepad object to query. - * \returns the connection state on success or - * `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError() - * for more information. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetGamepadConnectionState(SDL_Gamepad *gamepad); - -/** - * Get the battery state of a gamepad. - * - * You should never take a battery status as absolute truth. Batteries - * (especially failing batteries) are delicate hardware, and the values - * reported here are best estimates based on what that hardware reports. It's - * not uncommon for older batteries to lose stored power much faster than it - * reports, or completely drain when reporting it has 20 percent left, etc. - * - * \param gamepad the gamepad object to query. - * \param percent a pointer filled in with the percentage of battery life - * left, between 0 and 100, or NULL to ignore. This will be - * filled in with -1 we can't determine a value or there is no - * battery. - * \returns the current battery state. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetGamepadPowerInfo(SDL_Gamepad *gamepad, int *percent); - -/** - * Check if a gamepad has been opened and is currently connected. - * - * \param gamepad a gamepad identifier previously returned by - * SDL_OpenGamepad(). - * \returns true if the gamepad has been opened and is currently connected, or - * false if not. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC bool SDLCALL SDL_GamepadConnected(SDL_Gamepad *gamepad); - -/** - * Get the underlying joystick from a gamepad. - * - * This function will give you a SDL_Joystick object, which allows you to use - * the SDL_Joystick functions with a SDL_Gamepad object. This would be useful - * for getting a joystick's position at any given time, even if it hasn't - * moved (moving it would produce an event, which would have the axis' value). - * - * The pointer returned is owned by the SDL_Gamepad. You should not call - * SDL_CloseJoystick() on it, for example, since doing so will likely cause - * SDL to crash. - * - * \param gamepad the gamepad object that you want to get a joystick from. - * \returns an SDL_Joystick object, or NULL on failure; call SDL_GetError() - * for more information. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetGamepadJoystick(SDL_Gamepad *gamepad); - -/** - * Set the state of gamepad event processing. - * - * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself - * and check the state of the gamepad when you want gamepad information. - * - * \param enabled whether to process gamepad events or not. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GamepadEventsEnabled - * \sa SDL_UpdateGamepads - */ -extern SDL_DECLSPEC void SDLCALL SDL_SetGamepadEventsEnabled(bool enabled); - -/** - * Query the state of gamepad event processing. - * - * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself - * and check the state of the gamepad when you want gamepad information. - * - * \returns true if gamepad events are being processed, false otherwise. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_SetGamepadEventsEnabled - */ -extern SDL_DECLSPEC bool SDLCALL SDL_GamepadEventsEnabled(void); - -/** - * Get the SDL joystick layer bindings for a gamepad. - * - * \param gamepad a gamepad. - * \param count a pointer filled in with the number of bindings returned. - * \returns a NULL terminated array of pointers to bindings or NULL on - * failure; call SDL_GetError() for more information. This is a - * single allocation that should be freed with SDL_free() when it is - * no longer needed. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC SDL_GamepadBinding ** SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count); - -/** - * Manually pump gamepad updates if not using the loop. - * - * This function is called automatically by the event loop if events are - * enabled. Under such circumstances, it will not be necessary to call this - * function. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC void SDLCALL SDL_UpdateGamepads(void); - -/** - * Convert a string into SDL_GamepadType enum. - * - * This function is called internally to translate SDL_Gamepad mapping strings - * for the underlying joystick device into the consistent SDL_Gamepad mapping. - * You do not normally need to call this function unless you are parsing - * SDL_Gamepad mappings in your own code. - * - * \param str string representing a SDL_GamepadType type. - * \returns the SDL_GamepadType enum corresponding to the input string, or - * `SDL_GAMEPAD_TYPE_UNKNOWN` if no match was found. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadStringForType - */ -extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeFromString(const char *str); - -/** - * Convert from an SDL_GamepadType enum to a string. - * - * \param type an enum value for a given SDL_GamepadType. - * \returns a string for the given type, or NULL if an invalid type is - * specified. The string returned is of the format used by - * SDL_Gamepad mapping strings. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadTypeFromString - */ -extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForType(SDL_GamepadType type); - -/** - * Convert a string into SDL_GamepadAxis enum. - * - * This function is called internally to translate SDL_Gamepad mapping strings - * for the underlying joystick device into the consistent SDL_Gamepad mapping. - * You do not normally need to call this function unless you are parsing - * SDL_Gamepad mappings in your own code. - * - * Note specially that "righttrigger" and "lefttrigger" map to - * `SDL_GAMEPAD_AXIS_RIGHT_TRIGGER` and `SDL_GAMEPAD_AXIS_LEFT_TRIGGER`, - * respectively. - * - * \param str string representing a SDL_Gamepad axis. - * \returns the SDL_GamepadAxis enum corresponding to the input string, or - * `SDL_GAMEPAD_AXIS_INVALID` if no match was found. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadStringForAxis - */ -extern SDL_DECLSPEC SDL_GamepadAxis SDLCALL SDL_GetGamepadAxisFromString(const char *str); - -/** - * Convert from an SDL_GamepadAxis enum to a string. - * - * \param axis an enum value for a given SDL_GamepadAxis. - * \returns a string for the given axis, or NULL if an invalid axis is - * specified. The string returned is of the format used by - * SDL_Gamepad mapping strings. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadAxisFromString - */ -extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis); - -/** - * Query whether a gamepad has a given axis. - * - * This merely reports whether the gamepad's mapping defined this axis, as - * that is all the information SDL has about the physical device. - * - * \param gamepad a gamepad. - * \param axis an axis enum value (an SDL_GamepadAxis value). - * \returns true if the gamepad has this axis, false otherwise. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GamepadHasButton - * \sa SDL_GetGamepadAxis - */ -extern SDL_DECLSPEC bool SDLCALL SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis); - -/** - * Get the current state of an axis control on a gamepad. - * - * The axis indices start at index 0. - * - * For thumbsticks, the state is a value ranging from -32768 (up/left) to - * 32767 (down/right). - * - * Triggers range from 0 when released to 32767 when fully pressed, and never - * return a negative value. Note that this differs from the value reported by - * the lower-level SDL_GetJoystickAxis(), which normally uses the full range. - * - * Note that for invalid gamepads or axes, this will return 0. Zero is also a - * valid value in normal operation; usually it means a centered axis. - * - * \param gamepad a gamepad. - * \param axis an axis index (one of the SDL_GamepadAxis values). - * \returns axis state. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GamepadHasAxis - * \sa SDL_GetGamepadButton - */ -extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis); - -/** - * Convert a string into an SDL_GamepadButton enum. - * - * This function is called internally to translate SDL_Gamepad mapping strings - * for the underlying joystick device into the consistent SDL_Gamepad mapping. - * You do not normally need to call this function unless you are parsing - * SDL_Gamepad mappings in your own code. - * - * \param str string representing a SDL_Gamepad axis. - * \returns the SDL_GamepadButton enum corresponding to the input string, or - * `SDL_GAMEPAD_BUTTON_INVALID` if no match was found. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadStringForButton - */ -extern SDL_DECLSPEC SDL_GamepadButton SDLCALL SDL_GetGamepadButtonFromString(const char *str); - -/** - * Convert from an SDL_GamepadButton enum to a string. - * - * \param button an enum value for a given SDL_GamepadButton. - * \returns a string for the given button, or NULL if an invalid button is - * specified. The string returned is of the format used by - * SDL_Gamepad mapping strings. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadButtonFromString - */ -extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForButton(SDL_GamepadButton button); - -/** - * Query whether a gamepad has a given button. - * - * This merely reports whether the gamepad's mapping defined this button, as - * that is all the information SDL has about the physical device. - * - * \param gamepad a gamepad. - * \param button a button enum value (an SDL_GamepadButton value). - * \returns true if the gamepad has this button, false otherwise. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GamepadHasAxis - */ -extern SDL_DECLSPEC bool SDLCALL SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button); - -/** - * Get the current state of a button on a gamepad. - * - * \param gamepad a gamepad. - * \param button a button index (one of the SDL_GamepadButton values). - * \returns true if the button is pressed, false otherwise. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GamepadHasButton - * \sa SDL_GetGamepadAxis - */ -extern SDL_DECLSPEC bool SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button); - -/** - * Get the label of a button on a gamepad. - * - * \param type the type of gamepad to check. - * \param button a button index (one of the SDL_GamepadButton values). - * \returns the SDL_GamepadButtonLabel enum corresponding to the button label. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadButtonLabel - */ -extern SDL_DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabelForType(SDL_GamepadType type, SDL_GamepadButton button); - -/** - * Get the label of a button on a gamepad. - * - * \param gamepad a gamepad. - * \param button a button index (one of the SDL_GamepadButton values). - * \returns the SDL_GamepadButtonLabel enum corresponding to the button label. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadButtonLabelForType - */ -extern SDL_DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabel(SDL_Gamepad *gamepad, SDL_GamepadButton button); - -/** - * Get the number of touchpads on a gamepad. - * - * \param gamepad a gamepad. - * \returns number of touchpads. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetNumGamepadTouchpadFingers - */ -extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpads(SDL_Gamepad *gamepad); - -/** - * Get the number of supported simultaneous fingers on a touchpad on a game - * gamepad. - * - * \param gamepad a gamepad. - * \param touchpad a touchpad. - * \returns number of supported simultaneous fingers. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadTouchpadFinger - * \sa SDL_GetNumGamepadTouchpads - */ -extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *gamepad, int touchpad); - -/** - * Get the current state of a finger on a touchpad on a gamepad. - * - * \param gamepad a gamepad. - * \param touchpad a touchpad. - * \param finger a finger. - * \param down a pointer filled with true if the finger is down, false - * otherwise, may be NULL. - * \param x a pointer filled with the x position, normalized 0 to 1, with the - * origin in the upper left, may be NULL. - * \param y a pointer filled with the y position, normalized 0 to 1, with the - * origin in the upper left, may be NULL. - * \param pressure a pointer filled with pressure value, may be NULL. - * \returns true on success or false on failure; call SDL_GetError() for more - * information. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetNumGamepadTouchpadFingers - */ -extern SDL_DECLSPEC bool SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, bool *down, float *x, float *y, float *pressure); - -/** - * Return whether a gamepad has a particular sensor. - * - * \param gamepad the gamepad to query. - * \param type the type of sensor to query. - * \returns true if the sensor exists, false otherwise. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadSensorData - * \sa SDL_GetGamepadSensorDataRate - * \sa SDL_SetGamepadSensorEnabled - */ -extern SDL_DECLSPEC bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type); - -/** - * Set whether data reporting for a gamepad sensor is enabled. - * - * \param gamepad the gamepad to update. - * \param type the type of sensor to enable/disable. - * \param enabled whether data reporting should be enabled. - * \returns true on success or false on failure; call SDL_GetError() for more - * information. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GamepadHasSensor - * \sa SDL_GamepadSensorEnabled - */ -extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, bool enabled); - -/** - * Query whether sensor data reporting is enabled for a gamepad. - * - * \param gamepad the gamepad to query. - * \param type the type of sensor to query. - * \returns true if the sensor is enabled, false otherwise. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_SetGamepadSensorEnabled - */ -extern SDL_DECLSPEC bool SDLCALL SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type); - -/** - * Get the data rate (number of events per second) of a gamepad sensor. - * - * \param gamepad the gamepad to query. - * \param type the type of sensor to query. - * \returns the data rate, or 0.0f if the data rate is not available. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type); - -/** - * Get the current state of a gamepad sensor. - * - * The number of values and interpretation of the data is sensor dependent. - * See SDL_sensor.h for the details for each type of sensor. - * - * \param gamepad the gamepad to query. - * \param type the type of sensor to query. - * \param data a pointer filled with the current sensor state. - * \param num_values the number of values to write to data. - * \returns true on success or false on failure; call SDL_GetError() for more - * information. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC bool SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values); - -/** - * Start a rumble effect on a gamepad. - * - * Each call to this function cancels any previous rumble effect, and calling - * it with 0 intensity stops any rumbling. - * - * This function requires you to process SDL events or call - * SDL_UpdateJoysticks() to update rumble state. - * - * \param gamepad the gamepad to vibrate. - * \param low_frequency_rumble the intensity of the low frequency (left) - * rumble motor, from 0 to 0xFFFF. - * \param high_frequency_rumble the intensity of the high frequency (right) - * rumble motor, from 0 to 0xFFFF. - * \param duration_ms the duration of the rumble effect, in milliseconds. - * \returns true on success or false on failure; call SDL_GetError() for more - * information. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC bool SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms); - -/** - * Start a rumble effect in the gamepad's triggers. - * - * Each call to this function cancels any previous trigger rumble effect, and - * calling it with 0 intensity stops any rumbling. - * - * Note that this is rumbling of the _triggers_ and not the gamepad as a - * whole. This is currently only supported on Xbox One gamepads. If you want - * the (more common) whole-gamepad rumble, use SDL_RumbleGamepad() instead. - * - * This function requires you to process SDL events or call - * SDL_UpdateJoysticks() to update rumble state. - * - * \param gamepad the gamepad to vibrate. - * \param left_rumble the intensity of the left trigger rumble motor, from 0 - * to 0xFFFF. - * \param right_rumble the intensity of the right trigger rumble motor, from 0 - * to 0xFFFF. - * \param duration_ms the duration of the rumble effect, in milliseconds. - * \returns true on success or false on failure; call SDL_GetError() for more - * information. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_RumbleGamepad - */ -extern SDL_DECLSPEC bool SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms); - -/** - * Update a gamepad's LED color. - * - * An example of a joystick LED is the light on the back of a PlayStation 4's - * DualShock 4 controller. - * - * For gamepads with a single color LED, the maximum of the RGB values will be - * used as the LED brightness. - * - * \param gamepad the gamepad to update. - * \param red the intensity of the red LED. - * \param green the intensity of the green LED. - * \param blue the intensity of the blue LED. - * \returns true on success or false on failure; call SDL_GetError() for more - * information. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue); - -/** - * Send a gamepad specific effect packet. - * - * \param gamepad the gamepad to affect. - * \param data the data to send to the gamepad. - * \param size the size of the data to send to the gamepad. - * \returns true on success or false on failure; call SDL_GetError() for more - * information. - * - * \since This function is available since SDL 3.2.0. - */ -extern SDL_DECLSPEC bool SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size); - -/** - * Close a gamepad previously opened with SDL_OpenGamepad(). - * - * \param gamepad a gamepad identifier previously returned by - * SDL_OpenGamepad(). - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_OpenGamepad - */ -extern SDL_DECLSPEC void SDLCALL SDL_CloseGamepad(SDL_Gamepad *gamepad); - -/** - * Return the sfSymbolsName for a given button on a gamepad on Apple - * platforms. - * - * \param gamepad the gamepad to query. - * \param button a button on the gamepad. - * \returns the sfSymbolsName or NULL if the name can't be found. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadAppleSFSymbolsNameForAxis - */ -extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button); - -/** - * Return the sfSymbolsName for a given axis on a gamepad on Apple platforms. - * - * \param gamepad the gamepad to query. - * \param axis an axis on the gamepad. - * \returns the sfSymbolsName or NULL if the name can't be found. - * - * \since This function is available since SDL 3.2.0. - * - * \sa SDL_GetGamepadAppleSFSymbolsNameForButton - */ -extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis); - - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif -#include - -#endif /* SDL_gamepad_h_ */ diff --git a/ios_deploy/funnygame/funnygame.xcodeproj/project.pbxproj b/ios_deploy/funnygame/funnygame.xcodeproj/project.pbxproj deleted file mode 100644 index b51055a..0000000 --- a/ios_deploy/funnygame/funnygame.xcodeproj/project.pbxproj +++ /dev/null @@ -1,380 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 77; - objects = { - -/* Begin PBXBuildFile section */ - 24417C492E15D4C9002CF759 /* default.cfg in Resources */ = {isa = PBXBuildFile; fileRef = 24417C482E15D4C9002CF759 /* default.cfg */; }; - 2444C86E2E13363000CC1EFA /* metal.pak in Resources */ = {isa = PBXBuildFile; fileRef = 2444C86D2E13363000CC1EFA /* metal.pak */; }; - 249345AB2E109B8A00369580 /* funnygame in Resources */ = {isa = PBXBuildFile; fileRef = 249345A92E109B8A00369580 /* funnygame */; }; - 249345AC2E109B8A00369580 /* rtt.pak in Resources */ = {isa = PBXBuildFile; fileRef = 249345AA2E109B8A00369580 /* rtt.pak */; }; - 2493BB3F2E19384900828D56 /* SDL3.framework in Resources */ = {isa = PBXBuildFile; fileRef = 2493BB3E2E19384900828D56 /* SDL3.framework */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 24417C482E15D4C9002CF759 /* default.cfg */ = {isa = PBXFileReference; lastKnownFileType = text; name = default.cfg; path = "../../build/funnygame/aarch64-apple-ios/game/bin/default.cfg"; sourceTree = ""; }; - 2444C86D2E13363000CC1EFA /* metal.pak */ = {isa = PBXFileReference; lastKnownFileType = file; name = metal.pak; path = "../../build/funnygame/aarch64-apple-ios/game/bin/metal.pak"; sourceTree = ""; }; - 249345A72E10997500369580 /* funnygame */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; name = funnygame; path = "../../build/funnygame/aarch64-apple-ios/game/bin/funnygame"; sourceTree = ""; }; - 249345A92E109B8A00369580 /* funnygame */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; name = funnygame; path = "../../build/funnygame/aarch64-apple-ios/game/bin/funnygame"; sourceTree = ""; }; - 249345AA2E109B8A00369580 /* rtt.pak */ = {isa = PBXFileReference; lastKnownFileType = file; name = rtt.pak; path = "../../build/funnygame/aarch64-apple-ios/game/bin/rtt.pak"; sourceTree = ""; }; - 2493BB3E2E19384900828D56 /* SDL3.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL3.framework; path = "../../build/funnygame/aarch64-apple-ios/game/bin/SDL3.framework"; sourceTree = ""; }; - 24CCF9852E1065A100A06964 /* funnygame.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = funnygame.app; sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXFileReference section */ - -/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */ - 2493459C2E108A3500369580 /* Exceptions for "funnygame" folder in "funnygame" target */ = { - isa = PBXFileSystemSynchronizedBuildFileExceptionSet; - membershipExceptions = ( - Info.plist, - ); - target = 24CCF9842E1065A100A06964 /* funnygame */; - }; -/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */ - -/* Begin PBXFileSystemSynchronizedRootGroup section */ - 24CCF9872E1065A100A06964 /* funnygame */ = { - isa = PBXFileSystemSynchronizedRootGroup; - exceptions = ( - 2493459C2E108A3500369580 /* Exceptions for "funnygame" folder in "funnygame" target */, - ); - path = funnygame; - sourceTree = ""; - }; -/* End PBXFileSystemSynchronizedRootGroup section */ - -/* Begin PBXGroup section */ - 24CCF97C2E1065A100A06964 = { - isa = PBXGroup; - children = ( - 2493BB3E2E19384900828D56 /* SDL3.framework */, - 24417C482E15D4C9002CF759 /* default.cfg */, - 2444C86D2E13363000CC1EFA /* metal.pak */, - 249345A72E10997500369580 /* funnygame */, - 249345A92E109B8A00369580 /* funnygame */, - 249345AA2E109B8A00369580 /* rtt.pak */, - 24CCF9872E1065A100A06964 /* funnygame */, - 24CCF9862E1065A100A06964 /* Products */, - ); - sourceTree = ""; - }; - 24CCF9862E1065A100A06964 /* Products */ = { - isa = PBXGroup; - children = ( - 24CCF9852E1065A100A06964 /* funnygame.app */, - ); - name = Products; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 24CCF9842E1065A100A06964 /* funnygame */ = { - isa = PBXNativeTarget; - buildConfigurationList = 24CCF99D2E1065A300A06964 /* Build configuration list for PBXNativeTarget "funnygame" */; - buildPhases = ( - 24CCF9A22E1065F500A06964 /* Run Script */, - 249345342E10872F00369580 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - fileSystemSynchronizedGroups = ( - 24CCF9872E1065A100A06964 /* funnygame */, - ); - name = funnygame; - packageProductDependencies = ( - ); - productName = funnygame; - productReference = 24CCF9852E1065A100A06964 /* funnygame.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 24CCF97D2E1065A100A06964 /* Project object */ = { - isa = PBXProject; - attributes = { - BuildIndependentTargetsInParallel = 1; - LastUpgradeCheck = 1640; - TargetAttributes = { - 24CCF9842E1065A100A06964 = { - CreatedOnToolsVersion = 16.2; - }; - }; - }; - buildConfigurationList = 24CCF9802E1065A100A06964 /* Build configuration list for PBXProject "funnygame" */; - developmentRegion = en; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = 24CCF97C2E1065A100A06964; - minimizedProjectReferenceProxies = 1; - preferredProjectObjectVersion = 77; - productRefGroup = 24CCF9862E1065A100A06964 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 24CCF9842E1065A100A06964 /* funnygame */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 249345342E10872F00369580 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 2493BB3F2E19384900828D56 /* SDL3.framework in Resources */, - 24417C492E15D4C9002CF759 /* default.cfg in Resources */, - 2444C86E2E13363000CC1EFA /* metal.pak in Resources */, - 249345AB2E109B8A00369580 /* funnygame in Resources */, - 249345AC2E109B8A00369580 /* rtt.pak in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXShellScriptBuildPhase section */ - 24CCF9A22E1065F500A06964 /* Run Script */ = { - isa = PBXShellScriptBuildPhase; - alwaysOutOfDate = 1; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - ); - name = "Run Script"; - outputFileListPaths = ( - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "export CODE_SIGN_IDENTITY=$(security find-identity -v -p codesigning | grep \"Apple Development\" | grep -o '\".*\"' | tr -d '\"')\ncd ../../\nbuild/tools/fpc build -os ios -arch aarch64\ncodesign -s \"$CODE_SIGN_IDENTITY\" --timestamp=none --force build/funnygame/aarch64-apple-ios/game/bin/funnygame\ncodesign -s \"$CODE_SIGN_IDENTITY\" --timestamp=none --force build/funnygame/aarch64-apple-ios/game/bin/SDL3.framework\n"; - }; -/* End PBXShellScriptBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 24CCF99E2E1065A300A06964 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; - CODE_SIGN_ENTITLEMENTS = funnygame/funnygame.entitlements; - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = QU3M3RV4XD; - GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_FILE = funnygame/Info.plist; - INFOPLIST_KEY_GCSupportsControllerUserInteraction = YES; - INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.games"; - INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; - INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; - INFOPLIST_KEY_UIRequiresFullScreen = YES; - INFOPLIST_KEY_UIStatusBarStyle = ""; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - IPHONEOS_DEPLOYMENT_TARGET = 18.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); - MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = kotofyt.funnygame; - PRODUCT_NAME = "$(TARGET_NAME)"; - SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; - SUPPORTS_MACCATALYST = NO; - SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; - SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; - SWIFT_EMIT_LOC_STRINGS = YES; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - 24CCF99F2E1065A300A06964 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; - CODE_SIGN_ENTITLEMENTS = funnygame/funnygame.entitlements; - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = QU3M3RV4XD; - GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_FILE = funnygame/Info.plist; - INFOPLIST_KEY_GCSupportsControllerUserInteraction = YES; - INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.games"; - INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; - INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; - INFOPLIST_KEY_UIRequiresFullScreen = YES; - INFOPLIST_KEY_UIStatusBarStyle = ""; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - IPHONEOS_DEPLOYMENT_TARGET = 18.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); - MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = kotofyt.funnygame; - PRODUCT_NAME = "$(TARGET_NAME)"; - SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; - SUPPORTS_MACCATALYST = NO; - SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; - SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; - SWIFT_EMIT_LOC_STRINGS = YES; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; - 24CCF9A02E1065A300A06964 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - DEVELOPMENT_TEAM = QU3M3RV4XD; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - ENABLE_USER_SCRIPT_SANDBOXING = YES; - GCC_C_LANGUAGE_STANDARD = gnu17; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 18.2; - LOCALIZATION_PREFERS_STRING_CATALOGS = YES; - MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; - MTL_FAST_MATH = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - }; - name = Debug; - }; - 24CCF9A12E1065A300A06964 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DEVELOPMENT_TEAM = QU3M3RV4XD; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_USER_SCRIPT_SANDBOXING = YES; - GCC_C_LANGUAGE_STANDARD = gnu17; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 18.2; - LOCALIZATION_PREFERS_STRING_CATALOGS = YES; - MTL_ENABLE_DEBUG_INFO = NO; - MTL_FAST_MATH = YES; - SDKROOT = iphoneos; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 24CCF9802E1065A100A06964 /* Build configuration list for PBXProject "funnygame" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 24CCF9A02E1065A300A06964 /* Debug */, - 24CCF9A12E1065A300A06964 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 24CCF99D2E1065A300A06964 /* Build configuration list for PBXNativeTarget "funnygame" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 24CCF99E2E1065A300A06964 /* Debug */, - 24CCF99F2E1065A300A06964 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 24CCF97D2E1065A100A06964 /* Project object */; -} diff --git a/ios_deploy/funnygame/funnygame.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ios_deploy/funnygame/funnygame.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 919434a..0000000 --- a/ios_deploy/funnygame/funnygame.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/ios_deploy/funnygame/funnygame.xcodeproj/project.xcworkspace/xcuserdata/kotofyt.xcuserdatad/UserInterfaceState.xcuserstate b/ios_deploy/funnygame/funnygame.xcodeproj/project.xcworkspace/xcuserdata/kotofyt.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100644 index de7aee8..0000000 Binary files a/ios_deploy/funnygame/funnygame.xcodeproj/project.xcworkspace/xcuserdata/kotofyt.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ diff --git a/ios_deploy/funnygame/funnygame.xcodeproj/xcshareddata/xcschemes/funnygame.xcscheme b/ios_deploy/funnygame/funnygame.xcodeproj/xcshareddata/xcschemes/funnygame.xcscheme deleted file mode 100644 index 040203a..0000000 --- a/ios_deploy/funnygame/funnygame.xcodeproj/xcshareddata/xcschemes/funnygame.xcscheme +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ios_deploy/funnygame/funnygame.xcodeproj/xcuserdata/kotofyt.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ios_deploy/funnygame/funnygame.xcodeproj/xcuserdata/kotofyt.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist deleted file mode 100644 index 011b72b..0000000 --- a/ios_deploy/funnygame/funnygame.xcodeproj/xcuserdata/kotofyt.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - diff --git a/ios_deploy/funnygame/funnygame.xcodeproj/xcuserdata/kotofyt.xcuserdatad/xcschemes/xcschememanagement.plist b/ios_deploy/funnygame/funnygame.xcodeproj/xcuserdata/kotofyt.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index 16cbd2d..0000000 --- a/ios_deploy/funnygame/funnygame.xcodeproj/xcuserdata/kotofyt.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - SchemeUserState - - funnygame.xcscheme_^#shared#^_ - - orderHint - 0 - - - SuppressBuildableAutocreation - - 24CCF9842E1065A100A06964 - - primary - - - - - diff --git a/ios_deploy/funnygame/funnygame/Assets.xcassets/AccentColor.colorset/Contents.json b/ios_deploy/funnygame/funnygame/Assets.xcassets/AccentColor.colorset/Contents.json deleted file mode 100644 index eb87897..0000000 --- a/ios_deploy/funnygame/funnygame/Assets.xcassets/AccentColor.colorset/Contents.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "colors" : [ - { - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/ios_deploy/funnygame/funnygame/Assets.xcassets/AppIcon.appiconset/Contents.json b/ios_deploy/funnygame/funnygame/Assets.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index 2305880..0000000 --- a/ios_deploy/funnygame/funnygame/Assets.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "images" : [ - { - "idiom" : "universal", - "platform" : "ios", - "size" : "1024x1024" - }, - { - "appearances" : [ - { - "appearance" : "luminosity", - "value" : "dark" - } - ], - "idiom" : "universal", - "platform" : "ios", - "size" : "1024x1024" - }, - { - "appearances" : [ - { - "appearance" : "luminosity", - "value" : "tinted" - } - ], - "idiom" : "universal", - "platform" : "ios", - "size" : "1024x1024" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/ios_deploy/funnygame/funnygame/Assets.xcassets/Contents.json b/ios_deploy/funnygame/funnygame/Assets.xcassets/Contents.json deleted file mode 100644 index 73c0059..0000000 --- a/ios_deploy/funnygame/funnygame/Assets.xcassets/Contents.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/ios_deploy/funnygame/funnygame/Info.plist b/ios_deploy/funnygame/funnygame/Info.plist deleted file mode 100644 index b866798..0000000 --- a/ios_deploy/funnygame/funnygame/Info.plist +++ /dev/null @@ -1,18 +0,0 @@ - - - - - CFBundleDocumentTypes - - - LSHandlerRank - Default - - - NSAppTransportSecurity - - NSExceptionDomains - - - - diff --git a/ios_deploy/funnygame/funnygame/funnygame.entitlements b/ios_deploy/funnygame/funnygame/funnygame.entitlements deleted file mode 100644 index c74150d..0000000 --- a/ios_deploy/funnygame/funnygame/funnygame.entitlements +++ /dev/null @@ -1,8 +0,0 @@ - - - - - com.apple.developer.game-center - - - diff --git a/launcher/__build.cpp b/launcher/__build.cpp deleted file mode 100644 index 31d8f16..0000000 --- a/launcher/__build.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "helper.h" -#include "c.h" -#include "ld.h" -#include "tier1/utlstring.h" - -CUtlVector launcher_CompiledFiles = { - "launcher/launcher.cpp", -}; - -DECLARE_BUILD_STAGE(launcher) -{ - filesystem2->MakeDirectory(CUtlString("%s/bin",szOutputDir.GetString())); - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - - compileProject.m_szName = "launcher"; - compileProject.files = launcher_CompiledFiles; - compileProject.includeDirectories = all_IncludeDirectories; - compileProject.bFPIC = true; - if (bStaticBuild) - { - compileProject.macros.AppendTail((C_Macro_t){"STATIC_BUILD","1"}); - } - ldProject = ccompiler->Compile(&compileProject); - ldProject.linkType = ELINK_EXECUTABLE; - CUtlString szBinaryOutput = CUtlString("%s/bin/funnygame", szOutputDir.GetString()); - - if (bStaticBuild) - { - ldProject.objects.AppendTail((Object_t){tier0_lib}); - ldProject.objects.AppendTail((Object_t){tier1_lib}); - ldProject.objects.AppendTail((Object_t){rapier_lib}); - ldProject.objects.AppendTail((Object_t){engine_lib}); - ldProject.objects.AppendTail((Object_t){server_lib}); - ldProject.objects.AppendTail((Object_t){client_lib}); - if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_IOS) - { - ldProject.frameworks.AppendTail("SDL3"); - ldProject.frameworks.AppendTail("CoreFoundation"); - ldProject.frameworks.AppendTail("CoreGraphics"); - ldProject.frameworks.AppendTail("IOSurface"); - ldProject.frameworks.AppendTail("Metal"); - ldProject.frameworks.AppendTail("Foundation"); - ldProject.frameworks.AppendTail("QuartzCore"); - ldProject.frameworks.AppendTail("UIKit"); - ldProject.frameworkDirectories.AppendTail("external/ios"); - filesystem2->CopyDirectory(CUtlString("%s/bin", szOutputDir.GetString()), "external/ios/SDL3.framework"); - }; - if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_WINDOWS) - { - ldProject.objects.AppendTail((Object_t){"external/windows/vulkan-1.dll"}); - ldProject.objects.AppendTail((Object_t){"external/windows/libSDL3.a"}); - ldProject.objects.AppendTail((Object_t){"external/windows/libpthread.a"}); - ldProject.objects.AppendTail((Object_t){"external/windows/libstdc++.a"}); - if (bSteam) - ldProject.objects.AppendTail((Object_t){"external/steamworks/redistributable_bin/win64/steam_api64.dll"}); - ldProject.libraries.AppendTail("ws2_32"); - ldProject.libraries.AppendTail("ntdll"); - ldProject.libraries.AppendTail("userenv"); - ldProject.libraries.AppendTail("winmm"); - ldProject.libraries.AppendTail("ole32"); - ldProject.libraries.AppendTail("setupapi"); - ldProject.libraries.AppendTail("gdi32"); - ldProject.libraries.AppendTail("cfgmgr32"); - ldProject.libraries.AppendTail("uuid"); - ldProject.libraries.AppendTail("imm32"); - ldProject.libraries.AppendTail("version"); - ldProject.libraries.AppendTail("oleaut32"); - filesystem2->CopyFile(CUtlString("%s/bin", szOutputDir.GetString()), "external/windows/libgcc_s_seh-1.dll"); - filesystem2->CopyFile(CUtlString("%s/bin", szOutputDir.GetString()), "external/windows/libwinpthread-1.dll"); - szBinaryOutput = CUtlString("%s/bin/funnygame.exe", szOutputDir.GetString()); - } - }; - - CUtlString outputProject = linker->Link(&ldProject); - filesystem2->CopyFile(szBinaryOutput, outputProject); - - return 0; -}; diff --git a/launcher/build.cpp b/launcher/build.cpp new file mode 100644 index 0000000..46fdef9 --- /dev/null +++ b/launcher/build.cpp @@ -0,0 +1,20 @@ +#include "target.h" +#include "helper.h" +#include "c.h" +#include "ld.h" +#include "tier1/utlstring.h" + +DECLARE_BUILD_STAGE(launcher) +{ + CProject_t compileProject = {}; + LinkProject_t ldProject = {}; + + compileProject.m_szName = "launcher"; + compileProject.files = {"launcher.cpp"}; + ldProject = ccompiler->Compile(&compileProject); + ldProject.linkType = ELINK_EXECUTABLE; + + CUtlString outputProject = linker->Link(&ldProject); + ADD_OUTPUT_OBJECT("launcher", outputProject); + return 0; +}; diff --git a/launcher/launcher.cpp b/launcher/launcher.cpp index 1af1425..ca80b08 100644 --- a/launcher/launcher.cpp +++ b/launcher/launcher.cpp @@ -1,6 +1,5 @@ #include "string.h" #include "stdio.h" -#include "tier0/platform.h" #include "unistd.h" #include "libgen.h" @@ -9,9 +8,7 @@ #endif #ifdef __WIN32__ #include "windows.h" -#endif - -#ifdef __linux__ +#else #include "dlfcn.h" #endif @@ -41,10 +38,9 @@ void *pTier0Lib = NULL; typedef void (*EngineMainFn)(int argc, char** argv); EngineMainFn pEngineMain; -extern "C" void FunnyMain( int argc, char **argv ); +//extern "C" void FunnyMain( int argc, char **argv ); int main( int argc, char **argv ) { -#ifndef STATIC_BUILD #ifdef __linux__ readlink("/proc/self/exe",szLauncherPath, MAX_PATH); dirname(szLauncherPath); @@ -62,6 +58,7 @@ int main( int argc, char **argv ) { snprintf(szEnginePath, MAX_PATH, "%s/libengine.dylib", szLauncherPath2); snprintf(szTier0Path, MAX_PATH, "%s/libtier0.dylib", szLauncherPath2); #endif +#ifndef __WIN32__ if ( !dlopen(szSteamPath, RTLD_NOW )) printf("Failed to open steam\n"); pTier0Lib = dlopen(szTier0Path, RTLD_LAZY | RTLD_GLOBAL); @@ -69,7 +66,7 @@ int main( int argc, char **argv ) { printf("Failed to open libtier0\n"); printf("\t%s\n",dlerror()); } - pEngineLib = dlopen(szEnginePath, RTLD_LAZY | RTLD_GLOBAL); + pEngineLib = dlopen(szEnginePath, RTLD_NOW ); if ( !pEngineLib ) { printf("Failed to open libengine\n"); printf("\t%s\n",dlerror()); @@ -86,12 +83,22 @@ int main( int argc, char **argv ) { pEngineMain(argc, argv); dlclose(pEngineLib); -#else +#endif #ifdef __WIN32__ GetModuleFileNameA(NULL, szLauncherPath, MAX_PATH); dirname(szLauncherPath); + + snprintf(szEnginePath, MAX_PATH, "%s/engine.dll", szLauncherPath); + snprintf(szTier0Path, MAX_PATH, "%s/tier0.dll", szLauncherPath); + printf("%s\n", szEnginePath); + pEngineLib = LoadLibraryA(szEnginePath); + pEngineMain = (EngineMainFn)GetProcAddress((HMODULE)pEngineLib, "FunnyMain"); + if ( !pEngineMain ) { + printf("Symbol not found: FunnyMain\n"); + } + dirname(szLauncherPath); SetCurrentDirectoryA(szLauncherPath); + pEngineMain(argc, argv); #endif - FunnyMain(argc, argv); -#endif + //FunnyMain(argc, argv); }; diff --git a/materialsystem/__build.cpp b/materialsystem/__build.cpp deleted file mode 100644 index 04acb4b..0000000 --- a/materialsystem/__build.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "helper.h" -#include "c.h" -#include "ld.h" -#include "tier1/utlstring.h" -#include "tier1/commandline.h" - -CUtlVector MaterialSystem_CompiledFiles = { - "materialsystem/materialsystem.cpp", - "materialsystem/compiledshader.cpp", -}; -CUtlVector RenderContextVulkan_CompiledFiles = { - "materialsystem/vulkan/shaderparser.cpp", - "materialsystem/vulkan/rendercontext.cpp", - "materialsystem/vulkan/commandbuffer.cpp", - "materialsystem/vulkan/rendercommandlist.cpp", - "materialsystem/vulkan/material.cpp", - "materialsystem/vulkan/shader.cpp", - "materialsystem/vulkan/utils.cpp", - "materialsystem/vulkan/vma.cpp", - "materialsystem/vulkan/commands/draw.cpp", - "materialsystem/vulkan/commands/transfer.cpp", - "materialsystem/vulkan/commands/base.cpp", - "materialsystem/vulkan/libraries/raster.cpp", - "external/volk/volk.c", -}; -CUtlString material_lib; - -DECLARE_BUILD_STAGE(MaterialSystem) -{ - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - - compileProject.m_szName = "MaterialSystem"; - compileProject.files = MaterialSystem_CompiledFiles; - compileProject.includeDirectories = all_IncludeDirectories; - compileProject.bFPIC = true; - ldProject = ccompiler->Compile(&compileProject); - ldProject.linkType = ELINK_STATIC_LIBRARY; - ldProject.libraries = { "vulkan" }; - - CUtlString outputProject = linker->Link(&ldProject); - material_lib = outputProject; - - return 0; -} diff --git a/materialsystem/build.cpp b/materialsystem/build.cpp index b54150a..7571ac1 100644 --- a/materialsystem/build.cpp +++ b/materialsystem/build.cpp @@ -2,13 +2,18 @@ #include "c.h" #include "ld.h" #include "tier1/utlstring.h" -#include "tier1/commandline.h" + +#define FUNNYSTDLIB "../external/funnystdlib/" +ADD_DEPENDENCY_BUILD_FILE(tier0, FUNNYSTDLIB"tier0/build.cpp"); +ADD_DEPENDENCY_BUILD_FILE(tier1, FUNNYSTDLIB"tier1/build.cpp"); +ADD_DEPENDENCY_BUILD_FILE(tier2, FUNNYSTDLIB"tier2/build.cpp"); CUtlVector MaterialSystem_CompiledFiles = { "materialsystem.cpp", "compiledshader.cpp", }; CUtlVector RenderContextVulkan_CompiledFiles = { + "compiledshader.cpp", "vulkan/shaderparser.cpp", "vulkan/rendercontext.cpp", "vulkan/commandbuffer.cpp", @@ -23,7 +28,6 @@ CUtlVector RenderContextVulkan_CompiledFiles = { "vulkan/libraries/raster.cpp", "../external/volk/volk.c", }; -CUtlString material_lib; DECLARE_BUILD_STAGE(MaterialSystem) { @@ -32,19 +36,33 @@ DECLARE_BUILD_STAGE(MaterialSystem) compileProject.m_szName = "MaterialSystem"; compileProject.files = MaterialSystem_CompiledFiles; - compileProject.includeDirectories = { "../public" }; + compileProject.includeDirectories = { + "../public", + FUNNYSTDLIB"public", + }; compileProject.bFPIC = true; ldProject = ccompiler->Compile(&compileProject); ldProject.linkType = ELINK_DYNAMIC_LIBRARY; + ldProject.libraryObjects = { + GET_PROJECT_LIBRARY(tier0, "tier0"), + }; + ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier1, "tier1")}); + + if (ldProject.m_target.kernel & TARGET_KERNEL_WINDOWS_DEVICES) + { + ldProject.libraries.AppendTail("pthread"); + }; CUtlString outputProject = linker->Link(&ldProject); - material_lib = outputProject; + ADD_OUTPUT_OBJECT("MaterialSystem", outputProject); return 0; } DECLARE_BUILD_STAGE(RenderSystemVulkan) { + if (Target_t::DefaultTarget().cpu == TARGET_CPU_WASM32) + return 0; CProject_t compileProject = {}; LinkProject_t ldProject = {}; @@ -52,6 +70,7 @@ DECLARE_BUILD_STAGE(RenderSystemVulkan) compileProject.files = RenderContextVulkan_CompiledFiles; compileProject.includeDirectories = { "../public", + FUNNYSTDLIB"public", "../external/Vulkan-Headers/include", "../external/Vulkan-Utility-Libraries/include", "../external/VulkanMemoryAllocator/include", @@ -60,10 +79,17 @@ DECLARE_BUILD_STAGE(RenderSystemVulkan) compileProject.bFPIC = true; ldProject = ccompiler->Compile(&compileProject); ldProject.linkType = ELINK_DYNAMIC_LIBRARY; - ldProject.libraries = { "vulkan" }; + ldProject.libraryObjects = { + GET_PROJECT_LIBRARY(tier0, "tier0"), + }; + ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier1, "tier1")}); + if (ldProject.m_target.kernel & TARGET_KERNEL_WINDOWS_DEVICES) + { + ldProject.libraries.AppendTail("pthread"); + }; CUtlString outputProject = linker->Link(&ldProject); - material_lib = outputProject; + ADD_OUTPUT_OBJECT("RenderSystemVulkan", outputProject); return 0; } diff --git a/materialsystem/compiledshader.cpp b/materialsystem/compiledshader.cpp index 8765ba9..2736ce4 100644 --- a/materialsystem/compiledshader.cpp +++ b/materialsystem/compiledshader.cpp @@ -55,6 +55,7 @@ public: virtual void ReadFromFile( CCompiledShader *pShader, const char *szFile ) override; }; +IFileSystem *filesystem = NULL; void CCompiledShaderManager::WriteToFile( CCompiledShader *pShader, const char *szFile ) { IFileHandle *pFile; @@ -68,8 +69,14 @@ void CCompiledShaderManager::WriteToFile( CCompiledShader *pShader, const char * stHeader.m_nNumLumps = pShader->m_lumps.GetSize(); stHeader.m_nNumShaders = pShader->m_objects.GetSize(); + if ( filesystem == NULL ) + { + CreateInterfaceFn pFilesystemFactory = Sys_GetFactory("filesystem_std"); + filesystem = (IFileSystem*)pFilesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL); + + } pFile = filesystem->Open(szFile, FILEMODE_WRITE); - pFile->Write(&stHeader, sizeof(ShaderHeader_t)); + filesystem->Write(pFile, &stHeader, sizeof(ShaderHeader_t)); // We want to get offset for the lump data nTotalSize += sizeof(ShaderLump_t) * pShader->m_lumps.GetSize(); @@ -82,7 +89,7 @@ void CCompiledShaderManager::WriteToFile( CCompiledShader *pShader, const char * ShaderLump_t stLump = {}; stLump.m_nOffset = nTotalSize; stLump.m_nSize = l.m_nSize; - pFile->Write(&stLump, sizeof(ShaderLump_t)); + filesystem->Write(pFile, &stLump, sizeof(ShaderLump_t)); nTotalSize += l.m_nSize; } @@ -97,11 +104,11 @@ void CCompiledShaderManager::WriteToFile( CCompiledShader *pShader, const char * // Lump Data for ( auto l: pShader->m_lumps ) { - pFile->Write(l.m_pAddress, l.m_nSize); + filesystem->Write(pFile, l.m_pAddress, l.m_nSize); } - pFile->Close(); + filesystem->Close(pFile); } void CCompiledShaderManager::ReadFromFile( CCompiledShader *pShader, const char *szFile ) @@ -114,27 +121,27 @@ void CCompiledShaderManager::ReadFromFile( CCompiledShader *pShader, const char CUtlVector lumpsData = {}; pFile = filesystem->Open(szFile, FILEMODE_READ); - pFile->Read(&stHeader, sizeof(ShaderHeader_t)); + filesystem->Read(pFile, &stHeader, sizeof(ShaderHeader_t)); objects.Resize(stHeader.m_nNumShaders); lumps.Resize(stHeader.m_nNumLumps); lumpsData.Resize(stHeader.m_nNumLumps); - pFile->Read(lumps.GetData(), stHeader.m_nNumLumps * sizeof(ShaderLump_t)); - pFile->Read(objects.GetData(), stHeader.m_nNumShaders * sizeof(ShaderObject_t)); + filesystem->Read(pFile, lumps.GetData(), stHeader.m_nNumLumps * sizeof(ShaderLump_t)); + filesystem->Read(pFile, objects.GetData(), stHeader.m_nNumShaders * sizeof(ShaderObject_t)); for ( i = 0; i < stHeader.m_nNumLumps; i++ ) { lumpsData[i].m_pAddress = V_malloc(lumps[i].m_nSize); - pFile->Seek(SEEKMODE_RELATIVE_START, lumps[i].m_nOffset); - pFile->Read(lumpsData[i].m_pAddress, lumps[i].m_nSize); + filesystem->Seek(pFile, SEEKMODE_RELATIVE_START, lumps[i].m_nOffset); + filesystem->Read(pFile, lumpsData[i].m_pAddress, lumps[i].m_nSize); lumpsData[i].m_nSize = lumps[i].m_nSize; }; pShader->m_objects = objects; pShader->m_lumps = lumpsData; - pFile->Close(); + filesystem->Close(pFile); } diff --git a/materialsystem/materialsystem.cpp b/materialsystem/materialsystem.cpp index 6f700de..461d99a 100644 --- a/materialsystem/materialsystem.cpp +++ b/materialsystem/materialsystem.cpp @@ -11,30 +11,20 @@ public: virtual void RenderGameWindow( IGameWindow *pWindow ) override; }; -EXPOSE_INTERFACE(CMaterialSystem, IMaterialSystem, MATERIAL_SYSTEM_INTERFACE_NAME) - -extern IRenderContext *g_pVkRenderContext; -IRenderContext *g_pRenderContext; +EXPOSE_INTERFACE(CMaterialSystem, IMaterialSystem, MATERIAL_SYSTEM_INTERFACE_VERSION) void CMaterialSystem::Init() { - g_pRenderContext = (IRenderContext*)CreateInterface(RENDER_CONTEXT_INTERFACE_NAME, NULL); - g_pRenderContext->Init(); } void CMaterialSystem::Frame( float fTime ) { - g_pRenderContext->Frame(fTime); } void CMaterialSystem::RenderGameWindow( IGameWindow *pWindow ) { - g_pRenderContext->RenderGameWindow( pWindow ); } void CMaterialSystem::Shutdown() { - g_pRenderContext->Shutdown(); } - -IMaterialSystem *g_pMaterialSystem; diff --git a/materialsystem/vulkan/rendercontext.cpp b/materialsystem/vulkan/rendercontext.cpp index 30508ec..11e6d9a 100644 --- a/materialsystem/vulkan/rendercontext.cpp +++ b/materialsystem/vulkan/rendercontext.cpp @@ -1,4 +1,3 @@ -#include "SDL3/SDL_vulkan.h" #include "commands.h" #include "materialsystem/imaterialsystem.h" #include "tier0/lib.h" @@ -250,14 +249,7 @@ public: virtual void Init() override; virtual void Frame( float fDeltaTime ) override; virtual void Shutdown() override; - - virtual void SetOutputImage( IImage *pImage ) override; - virtual bool BIsOutputImageOutdated() override; - virtual uint32_t GetNewOutputImageWidth() override; - virtual uint32_t GetNewOutputImageHeight() override; - virtual EImageFormat GetNewOutputImageFormat() override; - virtual IVertexBuffer *CreateVertexBuffer( uint32_t nSize ) override; virtual IIndexBuffer *CreateIndexBuffer( uint32_t nSize ) override; virtual IBuffer *CreateConstantBuffer( uint32_t nSize ) override; @@ -280,45 +272,24 @@ public: virtual IRenderCommandList *CreateCommandList() override; virtual void DestroyCommandList( IRenderCommandList *pCommandList ) override; virtual void SubmitCommandList(IRenderCommandList *pList) override; + + virtual void SetMainWindowManager( IGameWindowManager *pWindowManager ) override; + + virtual void RenderGameWindow( IGameWindow *pWindow ) override; + virtual void RegisterGameWindow( IGameWindow *pWindow ) override; + virtual void UnregisterGameWindow( IGameWindow *pWindow ) override; private: VkPhysicalDevice SelectPhysicalDevice( CUtlVector physicalDevices ); CUtlVector GetDeviceExtensions(); VkCommandBuffer GetCommandBuffer(); - void CreateSwapchain(); - void DestroySwapchain(); + void CreateSwapchain( IGameWindow *pWindow ); + void DestroySwapchain( IGameWindow *pWindow ); - IImage *m_pOutputImage = NULL; - bool m_bOutputImageOutdated = true; + IGameWindowManager *m_pWindowManager; }; -EXPOSE_INTERFACE(CVkRenderContext, IRenderContext, RENDER_CONTEXT_VULKAN_INTERFACE_NAME); - -void CVkRenderContext::SetOutputImage( IImage *pImage ) -{ - m_pOutputImage = pImage; -} - - -bool CVkRenderContext::BIsOutputImageOutdated( ) -{ - return m_bOutputImageOutdated; -} - -uint32_t CVkRenderContext::GetNewOutputImageWidth() -{ - return 1280; -} - -uint32_t CVkRenderContext::GetNewOutputImageHeight() -{ - return 720; -} - -EImageFormat CVkRenderContext::GetNewOutputImageFormat() -{ - -} +EXPOSE_INTERFACE(CVkRenderContext, IRenderContext, RENDER_CONTEXT_INTERFACE_VERSION); //----------------------------------------------------------------------------- @@ -424,7 +395,6 @@ IShader *CVkRenderContext::CreateShader( const char *szName ) pShader->AddShaderLibrary(&vertexTransform); pShader->AddShaderLibrary(&pixelShader); pShader->AddShaderLibrary(&pixelOutput); - printf("--- general pipeline ---\n"); pShader->Build(); return pShader; } @@ -459,6 +429,26 @@ void CVkRenderContext::SubmitCommandList(IRenderCommandList *pList) CVkRenderCommandList *pVkList = (CVkRenderCommandList*)pList; pVkList->Submit(); } +void CVkRenderContext::RenderGameWindow( IGameWindow *pWindow ) +{ + +} + +void CVkRenderContext::SetMainWindowManager( IGameWindowManager *pWindowManager ) +{ + m_pWindowManager = pWindowManager; +} + +void CVkRenderContext::RegisterGameWindow( IGameWindow *pWindow ) +{ + +} + +void CVkRenderContext::UnregisterGameWindow( IGameWindow *pWindow ) +{ + +} + VkPipelineLayout g_pLibraryEmptyLayout; static IVkCommandBuffer *s_pPresentCommandBuffer; @@ -488,10 +478,17 @@ void CVkRenderContext::Init() r = volkInitialize(); VULKAN_RESULT_PRINT(r, volkInitialize); - // Get extensions required by game window - nExtensionCount = gamewindow->GetVulkanInstanceExtensionCount(); - enabledInstanceExtensions.Resize(nExtensionCount); - V_memcpy(enabledInstanceExtensions.GetData(), gamewindow->GetVulkanInstanceExtensions(), enabledInstanceExtensions.GetSize()*sizeof(const char*)); + if (m_pWindowManager) + { + nExtensionCount = m_pWindowManager->GetVulkanInstanceExtensionCount(); + enabledInstanceExtensions.Resize(nExtensionCount); + V_memcpy( + enabledInstanceExtensions.GetData(), + m_pWindowManager->GetVulkanInstanceExtensions(), + nExtensionCount*sizeof(const char*) + ); + + } // Create instance stApplicationInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; @@ -596,8 +593,6 @@ void CVkRenderContext::Init() stPipelineLayout.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; stPipelineLayout.flags = VK_PIPELINE_LAYOUT_CREATE_INDEPENDENT_SETS_BIT_EXT; vkCreatePipelineLayout(g_vkDevice, &stPipelineLayout, NULL, &g_pLibraryEmptyLayout); - - CreateSwapchain(); g_vkCommandPools.Resize(g_vkSwapchainImages.GetSize()); @@ -619,6 +614,7 @@ void CVkRenderContext::Init() void CVkRenderContext::Frame( float fDeltaTime ) { + /* CVkBlitCommand *pBlitCommand = NULL; if (m_pOutputImage) { @@ -643,7 +639,6 @@ void CVkRenderContext::Frame( float fDeltaTime ) s_pPresentCommandBuffer->Render(); vkDeviceWaitIdle(g_vkDevice); - m_bOutputImageOutdated = false; static uint32_t s_nImageIndex = 0; uint32_t nImageIndex = 0; @@ -684,9 +679,10 @@ void CVkRenderContext::Frame( float fDeltaTime ) s_nImageIndex = (s_nImageIndex + 1) % g_vkSwapchainImages.GetSize(); g_vkCommandBuffers = {}; + */ } -void CVkRenderContext::CreateSwapchain() +void CVkRenderContext::CreateSwapchain( IGameWindow *pWindow ) { uint32_t numSurfaceFormats = 0; CUtlVector surfaceFormats; @@ -708,16 +704,17 @@ void CVkRenderContext::CreateSwapchain() uint32_t nSwapchainImages; CUtlVector swapchainImages; + VkSurfaceKHR hSurface; - gamewindow->CreateVulkanSurface(g_vkInstance); + hSurface = (VkSurfaceKHR)pWindow->CreateVulkanSurface(g_vkInstance); - vkGetPhysicalDeviceSurfaceCapabilitiesKHR(g_vkPhysicalDevice, (VkSurfaceKHR)gamewindow->GetVulkanSurface(), &surfaceCapatibilities); + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(g_vkPhysicalDevice, (VkSurfaceKHR)hSurface, &surfaceCapatibilities); - vkGetPhysicalDeviceSurfaceFormatsKHR(g_vkPhysicalDevice, (VkSurfaceKHR)gamewindow->GetVulkanSurface(), &numSurfaceFormats, NULL); + vkGetPhysicalDeviceSurfaceFormatsKHR(g_vkPhysicalDevice, (VkSurfaceKHR)hSurface, &numSurfaceFormats, NULL); surfaceFormats.Resize(numSurfaceFormats); - vkGetPhysicalDeviceSurfaceFormatsKHR(g_vkPhysicalDevice, (VkSurfaceKHR)gamewindow->GetVulkanSurface(), &numSurfaceFormats, surfaceFormats.GetData()); + vkGetPhysicalDeviceSurfaceFormatsKHR(g_vkPhysicalDevice, (VkSurfaceKHR)hSurface, &numSurfaceFormats, surfaceFormats.GetData()); stSelectedFormat = surfaceFormats[0]; @@ -734,12 +731,12 @@ void CVkRenderContext::CreateSwapchain() } formatPicked: - vkGetPhysicalDeviceSurfacePresentModesKHR(g_vkPhysicalDevice, (VkSurfaceKHR)gamewindow->GetVulkanSurface(), &nSurfacePresentModes, NULL); + vkGetPhysicalDeviceSurfacePresentModesKHR(g_vkPhysicalDevice, hSurface, &nSurfacePresentModes, NULL); surfacePresentModes.Resize(nSurfacePresentModes); - vkGetPhysicalDeviceSurfacePresentModesKHR(g_vkPhysicalDevice, (VkSurfaceKHR)gamewindow->GetVulkanSurface(), &nSurfacePresentModes, surfacePresentModes.GetData()); + vkGetPhysicalDeviceSurfacePresentModesKHR(g_vkPhysicalDevice, hSurface, &nSurfacePresentModes, surfacePresentModes.GetData()); stSwapchainCreateInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; - stSwapchainCreateInfo.surface = (VkSurfaceKHR)gamewindow->GetVulkanSurface(); + stSwapchainCreateInfo.surface = hSurface; stSwapchainCreateInfo.imageFormat = stSelectedFormat.format; stSwapchainCreateInfo.imageColorSpace = stSelectedFormat.colorSpace; stSwapchainCreateInfo.presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR; @@ -786,10 +783,10 @@ formatPicked: } -void CVkRenderContext::DestroySwapchain() +void CVkRenderContext::DestroySwapchain( IGameWindow *pWindow ) { vkDestroySwapchainKHR(g_vkDevice, g_vkSwapchain, NULL); - gamewindow->DestroyVulkanSurface(g_vkInstance); + pWindow->DestroyVulkanSurface(g_vkInstance); } //----------------------------------------------------------------------------- diff --git a/materialsystem/vulkan/shader.cpp b/materialsystem/vulkan/shader.cpp index eb264af..b8710d2 100644 --- a/materialsystem/vulkan/shader.cpp +++ b/materialsystem/vulkan/shader.cpp @@ -1,4 +1,8 @@ #include "vulkan_state.h" +CVkShader::~CVkShader() +{ + +} void CVkShader::AddShaderLibrary( CVkPipelineLibrary *pLibrary ) { m_libraries.AppendTail(pLibrary); diff --git a/materialsystem/vulkan/vulkan_state.h b/materialsystem/vulkan/vulkan_state.h index 6858a65..04db708 100644 --- a/materialsystem/vulkan/vulkan_state.h +++ b/materialsystem/vulkan/vulkan_state.h @@ -256,6 +256,7 @@ void CVk##name##PipelineLibrary::Build() \ class CVkShader : public IShader { public: + ~CVkShader(); void AddShaderLibrary( CVkPipelineLibrary *pLibrary ); void Build(); virtual uint32_t PSGetResourceByName( const char *szName ) override; diff --git a/public/appleauth/iauth.h b/public/appleauth/iauth.h deleted file mode 100644 index d12c9e5..0000000 --- a/public/appleauth/iauth.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef APPLE_AUTH_H -#define APPLE_AUTH_H - -#include "tier0/platform.h" -#include "tier2/iappsystem.h" - -enum EAppleAuthDaemonStatus -{ - APPLE_AUTH_DAEMON_NOT_LOGGED_IN, - APPLE_AUTH_DAEMON_LOGGED_IN, -}; - -enum EAppleAuthStatus -{ - APPLE_AUTH_FAILURE, - APPLE_AUTH_SUCCESS, - APPLE_AUTH_NEED_2FA, - APPLE_AUTH_NEED_SMS_2FA, -}; - -abstract_class IAppleAuth: public IAppSystem -{ -public: - virtual void LaunchLoginDaemon() = 0; - virtual EAppleAuthDaemonStatus GetStatus() = 0; - virtual EAppleAuthStatus SubmitLoginData( const char *szEmail, const char *szPassword ) = 0; - virtual EAppleAuthStatus Submit2FA( const char *szCode ) = 0; -}; - -#define APPLE_AUTH_INTERFACE_VERSION "AppleAuth001" - -#endif diff --git a/public/asmrigs/as.h b/public/asmrigs/as.h deleted file mode 100644 index ad20bd2..0000000 --- a/public/asmrigs/as.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef ASMRIGS_AS_H -#define ASMRIGS_AS_H - -#include "tier0/platform.h" -#include "tier1/utlbuffer.h" - -struct AsOptions_t -{ - -}; - -CUtlBuffer Assemble( const char *szAssembly, AsOptions_t stOptions ); - -#endif diff --git a/public/asmrigs/ld.h b/public/asmrigs/ld.h deleted file mode 100644 index 2c8be2e..0000000 --- a/public/asmrigs/ld.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef ASMRIGS_LD_H -#define ASMRIGS_LD_H - -#include "tier0/interface.h" - -#endif diff --git a/public/asmrigs/tokenparser.h b/public/asmrigs/tokenparser.h deleted file mode 100644 index 313b309..0000000 --- a/public/asmrigs/tokenparser.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef ASMRIGS_TOKEN_PARSER -#define ASMRIGS_TOKEN_PARSER - -#include "tier2/tokenizer.h" - -class CTokenParser -{ -public: - bool IsEOF(); - const char *PeekToken(); - bool IsToken( const char *szString ); - const char *PeekStringLiteral(); - bool Continue(); - - Token_t *m_pTokens; - Token_t *m_pTokensEnd; - Token_t *m_pCurrentToken; -}; - -inline const char *CTokenParser::PeekToken() -{ - if ( m_pCurrentToken->m_bIsQuoted ) - return NULL; - return m_pCurrentToken->m_szValue; -} -inline bool CTokenParser::IsEOF() -{ - if (m_pCurrentToken == m_pTokensEnd) - return true; - return false; -}; - -inline bool CTokenParser::IsToken( const char *szString ) -{ - if ( !V_strcmp(szString, m_pCurrentToken->m_szValue)) - return true; - return false; -}; - -inline const char *CTokenParser::PeekStringLiteral() -{ - if ( !m_pCurrentToken->m_bIsQuoted ) - return NULL; - return m_pCurrentToken->m_szValue; -} - -inline bool CTokenParser::Continue() -{ - m_pCurrentToken++; - if ( m_pCurrentToken == m_pTokensEnd ) - return false; - return true; -} - -#endif diff --git a/public/http/http.h b/public/http/http.h deleted file mode 100644 index 812fbe9..0000000 --- a/public/http/http.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef HTTP_H -#define HTTP_H - -#include "tier0/platform.h" -#include "tier1/utlvector.h" -#include "tier1/utlstring.h" - -struct HTTPHeaderParam_t -{ - CUtlString m_szParamName; - CUtlString m_szValue; -}; - -struct HTTPHeader_t -{ - uint32_t m_nParamCount; - HTTPHeaderParam_t *m_params; -}; - -struct HTTPResponse_t -{ - CUtlBuffer m_params; - CUtlBuffer m_message; - uint32_t m_uCode; - bool m_bIsComplete; -}; - -struct WebSocketPacket_t -{ - size_t m_uSize; - void *m_pData; -}; - -abstract_class IHTTPClient -{ -public: - virtual void Post( const char *szResource, HTTPHeader_t *pHeader, uint32_t uDataSize, const void *data ) = 0; - virtual void Get( const char *szResource, HTTPHeader_t *pHeader ) = 0; - - virtual bool WebSocket_Connect( const char *szResource ) = 0; - virtual void WebSocket_Close( void ) = 0; - virtual void WebSocket_SendText( const char *szData ) = 0; - virtual CUtlString WebSocket_RecvText() = 0; - virtual void WebSocket_SendBinary( size_t uSize, const void *pData ) = 0; - virtual WebSocketPacket_t WebSocket_RecvBinary() = 0; - - virtual HTTPResponse_t GetResponse() = 0; -}; - -abstract_class IHTTPClientManager -{ -public: - virtual IHTTPClient *Connect( const char *szUrl, bool bSecure, uint16_t *pPort ) = 0; - virtual void Disconnect( IHTTPClient *pClient ) = 0; -}; - -#define HTTP_CLIENT_INTERFACE_VERSION "FHTTPClientMgr001" -extern IHTTPClientManager *g_pHttpClientMgr; - - -#endif diff --git a/public/igamewindow.h b/public/igamewindow.h index 7117eed..ce24c3a 100644 --- a/public/igamewindow.h +++ b/public/igamewindow.h @@ -1,43 +1,28 @@ #ifndef GAME_WINDOW_H #define GAME_WINDOW_H -#include "tier2/iappsystem.h" +#include "gamesystem.h" #include "tier0/platform.h" #include "materialsystem/imaterialsystem.h" -enum EGraphicsAPI -{ - GRAPHICS_API_METAL, - GRAPHICS_API_VULKAN, -}; - -abstract_class IGameWindow: public IAppSystem +abstract_class IGameWindow: public IGameSystem { public: - virtual void UpdateWindow() = 0; + virtual uint32_t GetRenderWidth() = 0; + virtual uint32_t GetRenderHeight() = 0; - - // Rendering info - virtual void SetRenderImage( IImage *pImage ) = 0; - virtual bool BIsRenderResolutionUpdated() = 0; - virtual void GetRenderWidth() = 0; - virtual void GetRenderHeight() = 0; - virtual EGraphicsAPI GetGraphicsAPI() = 0; - - // Vulkan stuff - virtual int GetVulkanInstanceExtensionCount() = 0; - virtual const char **GetVulkanInstanceExtensions() = 0; - - virtual void CreateVulkanSurface( void *pInstance, void *pDevice ) = 0; - virtual void DestroyVulkanSurface( void *pInstance, void *pDevice ) = 0; - - virtual void *GetVulkanSurface() = 0; - virtual void *GetVulkanFence( int iFrame ) = 0; - virtual void *GetVulkanDrawSemaphore( int iFrame ) = 0; - virtual void *GetVulkanPresentSemaphore( int iFrame ) = 0; - virtual IImage *GetVulkanSwapchainImage( int iFrame ) = 0; + virtual void *CreateVulkanSurface( void *pInstance ) = 0; + virtual void DestroyVulkanSurface( void *pInstance ) = 0; }; -extern IGameWindow *gamewindow; +abstract_class IGameWindowManager: public IGameSystem +{ +public: + virtual IGameWindow *CreateWindow() = 0; + virtual void DestroyWindow( IGameWindow* pWindow ) = 0; + + virtual int GetVulkanInstanceExtensionCount() = 0; + virtual const char **GetVulkanInstanceExtensions() = 0; +}; #endif diff --git a/public/materialsystem/imaterialsystem.h b/public/materialsystem/imaterialsystem.h index 00ef1ea..35f7d55 100644 --- a/public/materialsystem/imaterialsystem.h +++ b/public/materialsystem/imaterialsystem.h @@ -4,6 +4,7 @@ #include "tier0/platform.h" #include "tier2/iappsystem.h" class IGameWindow; +class IGameWindowManager; #define VULKAN_FRAMES_IN_FLIGHT 2 @@ -87,7 +88,7 @@ enum ETopologyMode abstract_class IRenderingObject { public: - virtual ~IRenderingObject() = 0; + virtual ~IRenderingObject() = default; virtual void SetDebugName( const char *szName ) = 0; }; @@ -97,6 +98,7 @@ public: abstract_class IBuffer : public IRenderingObject { public: + virtual ~IBuffer() = default; virtual void Lock() = 0; virtual void Unlock() = 0; virtual void *Map() = 0; @@ -126,7 +128,7 @@ public: abstract_class IShader { public: - virtual ~IShader() = 0; + virtual ~IShader() = default; virtual uint32_t PSGetResourceByName( const char *szName ) = 0; virtual uint32_t VSGetResourceByName( const char *szName ) = 0; }; @@ -141,7 +143,7 @@ public: abstract_class IMaterial { public: - virtual ~IMaterial() = 0; + virtual ~IMaterial() = default; virtual void VSSetShaderResource( uint32_t uRegister, IRenderingObject *pResource ) = 0; virtual void PSSetShaderResource( uint32_t uRegister, IRenderingObject *pResource ) = 0; virtual void VSSetConstantsBuffer( uint32_t uRegister, IBuffer *pImage ) = 0; @@ -185,13 +187,6 @@ abstract_class IRenderContext: public IAppSystem { public: virtual void Frame( float fTime ) = 0; - - virtual void SetOutputImage( IImage *pImage ) = 0; - - virtual bool BIsOutputImageOutdated() = 0; - virtual uint32_t GetNewOutputImageWidth() = 0; - virtual uint32_t GetNewOutputImageHeight() = 0; - virtual EImageFormat GetNewOutputImageFormat() = 0; virtual IVertexBuffer *CreateVertexBuffer( uint32_t nSize ) = 0; virtual IIndexBuffer *CreateIndexBuffer( uint32_t nSize ) = 0; @@ -212,12 +207,16 @@ public: virtual IRenderCommandList *CreateCommandList() = 0; virtual void DestroyCommandList( IRenderCommandList *pCommandList ) = 0; virtual void SubmitCommandList(IRenderCommandList *pList) = 0; + + virtual void SetMainWindowManager( IGameWindowManager *pWindowManager ) = 0; virtual void RenderGameWindow( IGameWindow *pWindow ) = 0; + virtual void RegisterGameWindow( IGameWindow *pWindow ) = 0; + virtual void UnregisterGameWindow( IGameWindow *pWindow ) = 0; }; -#define RENDER_CONTEXT_INTERFACE_NAME "RenderContext001" -#define MATERIAL_SYSTEM_INTERFACE_NAME "MaterialSystem001" +#define RENDER_CONTEXT_INTERFACE_VERSION "RenderContext001" +#define MATERIAL_SYSTEM_INTERFACE_VERSION "MaterialSystem001" abstract_class IMaterialSystem: public IAppSystem { @@ -226,7 +225,5 @@ public: virtual void RenderGameWindow( IGameWindow *pWindow ) = 0; }; -extern IRenderContext *g_pRenderContext; -extern IMaterialSystem *g_pMaterialSystem; #endif diff --git a/public/tier0/commandline.h b/public/tier0/commandline.h deleted file mode 100644 index c41dbbe..0000000 --- a/public/tier0/commandline.h +++ /dev/null @@ -1,30 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Command line handler for argc and argv. It also allows to find -// parameters and push your own. -//===========================================================================// - -#ifndef TIER0_COMMANDLINE_H -#define TIER0_COMMANDLINE_H - - -#include "tier0/platform.h" - -abstract_class ICommandLine -{ -public: - virtual void CreateCommandLine( int argc, char **argv ) = 0; - - virtual bool CheckParam( const char *psz ) = 0; - virtual char *ParamValue( const char* psz, const char *szDefaultValue = 0 ) = 0; - - virtual void AddParam( char *psz ) = 0; - virtual void RemoveParam( char *psz ) = 0; - - virtual int ParamCount() = 0; - virtual int FindParam( const char *psz ) = 0; - virtual const char *GetParam(int nIndex) = 0; -}; - -ICommandLine *CommandLine(); - -#endif diff --git a/public/tier0/lib.h b/public/tier0/lib.h deleted file mode 100644 index c6c7b65..0000000 --- a/public/tier0/lib.h +++ /dev/null @@ -1,130 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: A header which implements or redefines libc implementation. -// It is defined with V_ prefix to differentiate own implementation from -// given libc by the OS. -//===========================================================================// - -#ifndef TIER0_STDLIB_H -#define TIER0_STDLIB_H - -#include "tier0/minmax_on.h" - -#include "stdint.h" -#include "string.h" -#include "stdio.h" -#include "stdlib.h" -#include "ctype.h" - -//----------------------------------------------------------------------------- -// string.h -//----------------------------------------------------------------------------- -#define V_memcpy memcpy -#define V_memmove memmove -#define V_memchr memchr -#define V_memcmp memcmp -#define V_memset memset - -#define V_strcat strcat -#define V_strncat strncat -#define V_strchr strchr -#define V_strrchr strrchr -#define V_strcmp strcmp -#define V_strncmp strncmp -#define V_strcoll strcoll -#define V_strcpy strcpy -#define V_strncpy strncpy -#define V_strlen strlen -#define V_strnlen strnlen -#define V_strspn strspn -#define V_strcspn strcspn -#define V_strpbrk strpbrk -#define V_strstr strstr -#define V_strtok strtok -#define V_strxfrm strxfrm - -#ifdef __WIN32__ -#define V_stricmp stricmp -#else -#define V_stricmp strcasecmp -#endif - -//----------------------------------------------------------------------------- -// stdio.h -//----------------------------------------------------------------------------- -#define V_fclose fclose -#define V_fopen fopen -#define V_freopen freopen -#define V_fdopen fdopen -#define V_remove remove -#define V_rename rename -#define V_rewind rewind -#define V_tmpfile tmpfile - -#define V_feof feof -#define V_ferror ferror -#define V_fflush fflush -#define V_fgetpos fgetpos -#define V_fgetc getc -#define V_fgets gets -#define V_fputc putc -#define V_fputs puts -#define V_ftell ftell -#define V_fseek fseek -#define V_fsetpos fsetpos -#define V_fread fread -#define V_fwrite fwrite -#define V_getc getc -#define V_getchar getchar -#define V_gets gets -#define V_printf printf -#define V_vprintf vprintf -#define V_fprintf fprintf -#define V_vfprintf vfprintf -#define V_sprintf sprintf -#define V_snprintf snprintf -#define V_vsprintf vsprintf -#define V_vsnprintf vsnprintf -#define V_perror perror -#define V_putc putc -#define V_putchar putchar -#define V_fputchar fputchar -#define V_scanf scanf -#define V_sscanf sscanf -#define V_vscanf vscanf -#define V_fscanf fscanf -#define V_vfscanf vfscanf -#define V_vsscanf vsscanf -#define V_setbuf setbuf -#define V_setvbuf setvbuf -#define V_tmpnam tmpnam -#define V_ungetc ungetc -#define V_puts puts - - -//----------------------------------------------------------------------------- -// stdlib.h -//----------------------------------------------------------------------------- -#define V_atoi atoi -#define V_atof atof - -//----------------------------------------------------------------------------- -// ctype.h -//----------------------------------------------------------------------------- - -#define V_isalnum isalnum -#define V_isalpha isalpha -#define V_isblank isblank -#define V_iscntrl iscntrl -#define V_isdigit isdigit -#define V_isgraph isgraph -#define V_islower islower -#define V_isprint isprint -#define V_ispunct ispunct -#define V_isspace isspace -#define V_isupper isupper -#define V_isxdigit isxdigit -#define V_tolower tolower -#define V_toupper toupper - - -#endif diff --git a/public/tier0/mem.h b/public/tier0/mem.h deleted file mode 100644 index 94f35e4..0000000 --- a/public/tier0/mem.h +++ /dev/null @@ -1,20 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: A memory allocator for C and C++. -// For now it uses libc but it is possible to use own allocators -//===========================================================================// - -#ifndef TIER0_MEM_H -#define TIER0_MEM_H - -#include "platform.h" -#include "lib.h" - -PLATFORM_INTERFACE void *V_malloc( int nSize ); -PLATFORM_INTERFACE void V_free( void *pMem ); -PLATFORM_INTERFACE void *V_realloc( void *pMem, int nSize ); - -void *operator new( size_t nCount ); -void *operator new ( size_t nCount, void *pPtr ); -void operator delete( void *pMem ) noexcept; - -#endif diff --git a/public/tier0/minmax_off.h b/public/tier0/minmax_off.h deleted file mode 100644 index 5c1ab93..0000000 --- a/public/tier0/minmax_off.h +++ /dev/null @@ -1,9 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Disables min and max. Used for C++ interoperability -//===========================================================================// - - -#ifdef min -#undef min -#undef max -#endif diff --git a/public/tier0/minmax_on.h b/public/tier0/minmax_on.h deleted file mode 100644 index 1969732..0000000 --- a/public/tier0/minmax_on.h +++ /dev/null @@ -1,8 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Enables min and max. Used for C++ interoperability -//===========================================================================// - -#include "minmax_off.h" - -#define max(x, y) (((x) > (y)) ? (x) : (y)) -#define min(x, y) (((x) < (y)) ? (x) : (y)) diff --git a/public/tier0/network.h b/public/tier0/network.h deleted file mode 100644 index 3283572..0000000 --- a/public/tier0/network.h +++ /dev/null @@ -1,21 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: -//===========================================================================// - -#ifndef TIER0_NETWORK_H -#define TIER0_NETWORK_H - -#include "platform.h" -#ifdef __linux__ -#include "arpa/inet.h" -#endif -#ifdef __WIN32__ -#include "winsock2.h" -#include "ws2tcpip.h" -#endif - - -PLATFORM_INTERFACE void Net_Init(); -PLATFORM_INTERFACE void Net_Deinit(); - -#endif diff --git a/public/tier0/platform.h b/public/tier0/platform.h deleted file mode 100644 index 4d1c140..0000000 --- a/public/tier0/platform.h +++ /dev/null @@ -1,114 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Multi-platform implementation of some of the functions which -// are provided by each OS differently. -//===========================================================================// - -#ifndef TIER0_PLATFORM_H -#define TIER0_PLATFORM_H - -#include "stdint.h" -#include "stddef.h" - -#ifdef __WIN32__ -#define DLL_EXPORT extern "C" -#define DLL_IMPORT extern "C" - -#define DLL_CLASS_EXPORT -#define DLL_CLASS_IMPORT - -#define DLL_GLOBAL_EXPORT extern -#define DLL_GLOBAL_IMPORT extern -#else -#define DLL_EXPORT extern "C" __attribute__ ((visibility("default"))) -#define DLL_IMPORT extern "C" - -#define DLL_CLASS_EXPORT __attribute__ ((visibility("default"))) -#define DLL_CLASS_IMPORT - -#define DLL_GLOBAL_EXPORT __attribute ((visibility("default"))) -#define DLL_GLOBAL_IMPORT extern - -#endif - -#ifdef TIER0_STATIC - -#define GLOBAL_USED __attribute__((used)) - -#else - -#define GLOBAL_USED __attribute__((used)) - -#ifdef TIER0_IMPLEMENTATION -#define PLATFORM_INTERFACE DLL_EXPORT -#define PLATFORM_OVERLOAD DLL_GLOBAL_EXPORT -#define PLATFORM_CLASS DLL_CLASS_EXPORT -#else -#define PLATFORM_INTERFACE DLL_IMPORT -#define PLATFORM_OVERLOAD DLL_GLOBAL_IMPORT -#define PLATFORM_CLASS DLL_CLASS_IMPORT -#endif - -#endif - -#if defined(__linux__) -#define POSIX -#endif - -#define SWAP16(x) (uint16_t)((((x) >> 8) & 0x00FF) | \ - (((x) << 8) & 0xFF00)) - -#define SWAP32(x) (uint32_t)((((x) >> 24) & 0x000000FF) | \ - (((x) >> 8) & 0x0000FF00) | \ - (((x) << 8) & 0x00FF0000) | \ - (((x) << 24) & 0xFF000000)) - -#define SWAP64(x) ((uint64_t)( \ - (((x) >> 56) & 0x00000000000000FFULL) | \ - (((x) >> 40) & 0x000000000000FF00ULL) | \ - (((x) >> 24) & 0x0000000000FF0000ULL) | \ - (((x) >> 8) & 0x00000000FF000000ULL) | \ - (((x) << 8) & 0x000000FF00000000ULL) | \ - (((x) << 24) & 0x0000FF0000000000ULL) | \ - (((x) << 40) & 0x00FF000000000000ULL) | \ - (((x) << 56) & 0xFF00000000000000ULL) )) - -#define abstract_class class - -PLATFORM_INTERFACE void Plat_FatalErrorFunc( const char *szFormat, ... ); - -typedef void( *ListDirCallbackFn )( const char *szPath ); -PLATFORM_INTERFACE void Plat_ListDirRecursive( const char *szPath, ListDirCallbackFn file, ListDirCallbackFn dir ); -PLATFORM_INTERFACE void Plat_ListDir( const char *szPath, ListDirCallbackFn file, ListDirCallbackFn dir ); -PLATFORM_INTERFACE char *Plat_GetExtension( const char *szPath ); - -PLATFORM_INTERFACE void Plat_MakeDir( const char *szPath, int iPermissions ); - -PLATFORM_INTERFACE void Plat_TrapSignals( void (*pfn)() ); -PLATFORM_INTERFACE void Plat_Backtrace( void ); - -PLATFORM_INTERFACE void *Plat_LoadLibrary( const char *psz ); -PLATFORM_INTERFACE void *Plat_GetProc( void *lib, const char *psz ); -PLATFORM_INTERFACE void Plat_UnloadLibrary( void *psz ); - -PLATFORM_INTERFACE void Plat_SetEnv( const char *szVar, const char *psz ); -PLATFORM_INTERFACE const char *Plat_GetEnv( const char *szVar ); - -PLATFORM_INTERFACE void Plat_SetWorkingDir( const char *psz ); -PLATFORM_INTERFACE const char *Plat_GetWorkingDir( void ); - -PLATFORM_INTERFACE const char *Plat_GetExecutablePath( void ); -PLATFORM_INTERFACE const char *Plat_GetParentDir( const char *psz ); - -PLATFORM_INTERFACE const char *Plat_GetUNIXExecutable( const char *psz ); -PLATFORM_INTERFACE const char *Plat_GetWindowsExecutable( const char *psz ); -PLATFORM_INTERFACE const char *Plat_GetPlatformExecutable( const char *psz ); - -PLATFORM_INTERFACE const char *Plat_GetDarwinSharedLib( const char *psz ); -PLATFORM_INTERFACE const char *Plat_GetUNIXSharedLib( const char *psz ); -PLATFORM_INTERFACE const char *Plat_GetWindowsSharedLib( const char *psz ); -PLATFORM_INTERFACE const char *Plat_GetPlatformSharedLib( const char *psz ); - -PLATFORM_INTERFACE double Plat_GetTime( void ); -PLATFORM_INTERFACE void Plat_Exit( int status ); - -#endif diff --git a/public/tier0/rand.h b/public/tier0/rand.h deleted file mode 100644 index a2eec79..0000000 --- a/public/tier0/rand.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef TIER0_RAND_H -#define TIER0_RAND_H - -#include "tier0/platform.h" - -PLATFORM_INTERFACE void Plat_InitRandom(); -PLATFORM_INTERFACE void Plat_ShutdownRandom(); -PLATFORM_INTERFACE void Plat_URandom( size_t uBufferSize, uint8_t *szBuffer ); - -#endif diff --git a/public/tier1/appinit.h b/public/tier1/appinit.h deleted file mode 100644 index 244ca1e..0000000 --- a/public/tier1/appinit.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef APPINIT_H -#define APPINIT_H - - -void AppInitializePath(); - -#endif diff --git a/public/tier1/ban_std.h b/public/tier1/ban_std.h deleted file mode 100644 index 0f7eec3..0000000 --- a/public/tier1/ban_std.h +++ /dev/null @@ -1,5 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: BAN STL. I hate it. -//===========================================================================// - -#define std no_you_do_not_use_std diff --git a/public/tier1/interface.h b/public/tier1/interface.h deleted file mode 100644 index e609cff..0000000 --- a/public/tier1/interface.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef INTERFACE_H -#define INTERFACE_H - -#include "tier0/platform.h" - -typedef void *( *CreateInterfaceFn )( const char *szName, int *pReturnCode ); -typedef void *( *InstantiateInterfaceFn )( void ); - -class CInterfaceRegistry -{ -public: - CInterfaceRegistry( InstantiateInterfaceFn fn, const char *szName ); - - InstantiateInterfaceFn m_CreateFn; - const char *m_szName; - - CInterfaceRegistry *m_pNext; -}; - - -#define EXPOSE_INTERFACE( className, interfaceName, versionName ) \ - static void *__Create##className##_interface() { return ( interfaceName* )( new className ); }; \ - static CInterfaceRegistry __Create##className##_registry( __Create##className##_interface, versionName ); - -#define EXPOSE_INTERFACE_FN( functionName, interfaceName, versionName ) \ - static CInterfaceRegistry __Create##interfaceName##_registry( functionName, versionName ); - -#define EXPOSE_INTERFACE_GLOBALVAR( className, interfaceName, versionName, globalVarName ) \ - static void *__Create##className##_interface() { return ( interfaceName* )( &globalVarName ); }; \ - static CInterfaceRegistry __Create##className##_registry( __Create##className##_interface, versionName ); - - -DLL_EXPORT void *CreateInterface( const char *szName, int *pReturnCode ); - -CreateInterfaceFn Sys_GetFactory( void *pLibrary ); -CreateInterfaceFn Sys_GetFactory( const char *szLibrary ); - -#endif diff --git a/public/tier1/unban_std.h b/public/tier1/unban_std.h deleted file mode 100644 index 30d44b7..0000000 --- a/public/tier1/unban_std.h +++ /dev/null @@ -1,5 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Unban STL because C++ doesn't like using something different. -//===========================================================================// - -#undef std diff --git a/public/tier1/utlbuffer.h b/public/tier1/utlbuffer.h deleted file mode 100644 index e0ee920..0000000 --- a/public/tier1/utlbuffer.h +++ /dev/null @@ -1,370 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Memory buffers for C++. They store data on heap as you have C -// arrays for stack. -//===========================================================================// - -#ifndef TIER1_UTL_BUFFER_H -#define TIER1_UTL_BUFFER_H - - -#include "tier0/mem.h" -#include "tier0/platform.h" -#include "tier0/lib.h" - -template -class CUtlBuffer; -template -class CUtlResizableBuffer; - -//----------------------------------------------------------------------------- -// This buffer contains static data allocated on heap. -//----------------------------------------------------------------------------- -template -class CUtlBuffer -{ -public: - CUtlBuffer( void ); - CUtlBuffer( size_t nSize ); - CUtlBuffer( const CUtlBuffer& buffer ); - CUtlBuffer( const CUtlResizableBuffer& buffer ); - ~CUtlBuffer( void ); - - size_t GetSize( void ) const; - T* GetMemory(void) const; - - operator T*( void ) const; - T& operator []( const size_t nIndex ); - T operator []( const size_t nIndex ) const; - CUtlBuffer& operator=(const CUtlBuffer& other); -private: - T* m_pData = NULL; - size_t m_nSize = 0; -}; - -//----------------------------------------------------------------------------- -// Constructor. -//----------------------------------------------------------------------------- -template -CUtlBuffer::CUtlBuffer() : m_nSize(0) -{ - m_pData = 0; -} - -//----------------------------------------------------------------------------- -// Constructor. -//----------------------------------------------------------------------------- -template -CUtlBuffer::CUtlBuffer( size_t nSize ) : m_nSize(nSize) -{ - if ( nSize == 0 ) - nSize = 1; - m_pData = (T*)V_malloc(sizeof(T)*nSize); - V_memset(m_pData, 0, sizeof(T)*nSize); -} - -//----------------------------------------------------------------------------- -// Constructor. -//----------------------------------------------------------------------------- -template -CUtlBuffer::CUtlBuffer( const CUtlBuffer& buffer ) : m_nSize(buffer.m_nSize) -{ - m_pData = (T*)V_malloc(sizeof(T)*buffer.m_nSize); - V_memcpy(m_pData,buffer.m_pData,sizeof(T)*buffer.m_nSize); -} - -//----------------------------------------------------------------------------- -// Constructor. -//----------------------------------------------------------------------------- -template -CUtlBuffer::CUtlBuffer( const CUtlResizableBuffer& buffer ) : m_nSize(buffer.GetSize()) -{ - m_pData = (T*)V_malloc(sizeof(T)*buffer.GetSize()); - V_memcpy(m_pData,buffer.GetMemory(),sizeof(T)*buffer.GetSize()); -} - -template -CUtlBuffer::~CUtlBuffer() -{ - if ( m_pData != 0) - V_free(m_pData); -} -//----------------------------------------------------------------------------- -// Gets memory size. -//----------------------------------------------------------------------------- -template -size_t CUtlBuffer::GetSize( void ) const -{ - return m_nSize; -} - -//----------------------------------------------------------------------------- -// Gets memory address. -//----------------------------------------------------------------------------- -template -T* CUtlBuffer::GetMemory( void ) const -{ - return m_pData; -} - -//----------------------------------------------------------------------------- -// Gets memory address using casting. -//----------------------------------------------------------------------------- -template -CUtlBuffer::operator T*( void ) const -{ - return m_pData; -} - -//----------------------------------------------------------------------------- -// Indexes buffer for writing. -//----------------------------------------------------------------------------- -template -T& CUtlBuffer::operator []( const size_t nIndex ) -{ - if ( m_pData == 0) - Plat_FatalErrorFunc("Buffer was not initialized\n"); - - if ( nIndex >= m_nSize ) - Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu\n", m_nSize/sizeof(T), nIndex); - - return m_pData[nIndex]; -} - -//----------------------------------------------------------------------------- -// Indexes buffer for reading. -//----------------------------------------------------------------------------- -template -T CUtlBuffer::operator []( const size_t nIndex ) const -{ - if ( nIndex >= m_nSize ) - Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu\n",m_nSize, nIndex); - return m_pData[nIndex]; -} - -//----------------------------------------------------------------------------- -// Assigns buffer. -//----------------------------------------------------------------------------- -template -CUtlBuffer& CUtlBuffer::operator=(const CUtlBuffer& other) -{ - if ( this != &other ) - { - if ( m_pData != 0) - V_free(m_pData); - m_pData = (T*)V_malloc(sizeof(T)*other.m_nSize); - m_nSize = other.m_nSize; - V_memcpy(m_pData, other.m_pData, sizeof(T)*other.m_nSize); - } - return *this; -} - -//----------------------------------------------------------------------------- -// This buffer contains static data allocated on heap which can be resized. -//----------------------------------------------------------------------------- -template -class CUtlResizableBuffer -{ -public: - CUtlResizableBuffer( void ); - CUtlResizableBuffer( size_t nSize ); - CUtlResizableBuffer( const CUtlBuffer& buffer ); - CUtlResizableBuffer( const CUtlResizableBuffer& buffer ); - ~CUtlResizableBuffer(); - - size_t GetSize() const; - size_t GetRealSize() const; - void Resize( size_t nSize, size_t nDataOffset = 0 ); - void* GetMemory(void) const; - - operator T*( void ) const; - T& operator []( const size_t nIndex ); - T operator []( const size_t nIndex ) const; - CUtlResizableBuffer& operator=(const CUtlResizableBuffer& other); -private: - size_t CalculateMemorySize(size_t nSize); - T* m_pData = NULL; - size_t m_nSize = 0; - size_t m_nAllocatedSize = 0; -}; - - - -//----------------------------------------------------------------------------- -// Constructor. -//----------------------------------------------------------------------------- -template -CUtlResizableBuffer::CUtlResizableBuffer() -{ - m_pData = NULL; - m_nSize = 0; - m_nAllocatedSize = 0; -} - -//----------------------------------------------------------------------------- -// Constructor. -//----------------------------------------------------------------------------- -template -CUtlResizableBuffer::CUtlResizableBuffer( size_t nSize ) -{ - Resize(nSize); -} - -//----------------------------------------------------------------------------- -// Constructor. -//----------------------------------------------------------------------------- -template -CUtlResizableBuffer::CUtlResizableBuffer( const CUtlBuffer& buffer ) : m_nSize(buffer.nSize) -{ -} - -//----------------------------------------------------------------------------- -// Constructor. -//----------------------------------------------------------------------------- -template -CUtlResizableBuffer::CUtlResizableBuffer( const CUtlResizableBuffer& buffer ) : m_nSize(buffer.m_nSize) -{ - *this = buffer; -} - -template -CUtlResizableBuffer::~CUtlResizableBuffer() -{ - for ( size_t i = 0; i < m_nSize; i++) - m_pData[i].~T(); - if (m_pData) - V_free(m_pData); - m_pData = 0; - m_nSize = 0; - m_nAllocatedSize = 0; -}; - -//----------------------------------------------------------------------------- -// Gets memory size. -//----------------------------------------------------------------------------- -template -size_t CUtlResizableBuffer::GetSize( void ) const -{ - return m_nSize; -} - -//----------------------------------------------------------------------------- -// Gets memory size. -//----------------------------------------------------------------------------- -template -size_t CUtlResizableBuffer::GetRealSize( void ) const -{ - return m_nAllocatedSize; -} - -//----------------------------------------------------------------------------- -// Resizes memory. -//----------------------------------------------------------------------------- -template -void CUtlResizableBuffer::Resize( size_t nSize, size_t nDataOffset ) -{ - if (nSize > m_nAllocatedSize) - { - size_t nAllocationSize = CalculateMemorySize(nSize); - T *pData = (T*)V_malloc(nAllocationSize*sizeof(T)); - for (size_t i = 0; i < m_nSize; i++) - { - new (&pData[i+nDataOffset]) T(m_pData[i]); - m_pData[i].~T(); - } - V_free(m_pData); - m_pData = pData; - m_nAllocatedSize = nAllocationSize; - } - for ( size_t i = m_nSize+nDataOffset; i < nSize; ++i ) - new (&m_pData[i]) T(); - m_nSize = nSize; -} - -//----------------------------------------------------------------------------- -// Gets memory address. -//----------------------------------------------------------------------------- -template -void* CUtlResizableBuffer::GetMemory( void ) const -{ - return m_pData; -} - -//----------------------------------------------------------------------------- -// Gets memory address using casting. -//----------------------------------------------------------------------------- -template -CUtlResizableBuffer::operator T*( void ) const -{ - return m_pData; -} - -//----------------------------------------------------------------------------- -// Indexes buffer for writing. -//----------------------------------------------------------------------------- -template -T& CUtlResizableBuffer::operator []( const size_t nIndex ) -{ - if ( m_pData == 0) - Plat_FatalErrorFunc("Buffer was not initialized\n"); - - if ( nIndex >= m_nSize ) - Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu\n",m_nSize, nIndex); - - return m_pData[nIndex]; -} - -//----------------------------------------------------------------------------- -// Indexes buffer for reading. -//----------------------------------------------------------------------------- -template -T CUtlResizableBuffer::operator []( const size_t nIndex ) const -{ - if ( nIndex >= m_nSize ) - Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu\n",m_nSize, nIndex); - return m_pData[nIndex]; -} - -//----------------------------------------------------------------------------- -// Assigns buffer. -//----------------------------------------------------------------------------- -template -CUtlResizableBuffer& CUtlResizableBuffer::operator=(const CUtlResizableBuffer& other) -{ - if ( this != &other ) - { - if (m_pData) - { - for (size_t i = 0; i < m_nSize; i++) - m_pData[i].~T(); - V_free(m_pData); - } - m_pData = (T*)V_malloc(other.m_nAllocatedSize*sizeof(T)); - m_nAllocatedSize = other.m_nAllocatedSize; - m_nSize = other.m_nSize; - for ( size_t i = 0; i < other.m_nSize; i++) - new (&m_pData[i]) T(other.m_pData[i]); - } - return *this; -} - -//----------------------------------------------------------------------------- -// Calculates memory size that is -//----------------------------------------------------------------------------- -template -size_t CUtlResizableBuffer::CalculateMemorySize(size_t nSize) -{ - size_t x = nSize; - if (x == 0) return 1; - x--; - x |= x >> 1; - x |= x >> 2; - x |= x >> 4; - x |= x >> 8; - x |= x >> 16; -#if SIZE_MAX > UINT32_MAX - x |= x >> 32; -#endif - return x + 1; -} - -#endif diff --git a/public/tier1/utlinitlist.h b/public/tier1/utlinitlist.h deleted file mode 100644 index eb08468..0000000 --- a/public/tier1/utlinitlist.h +++ /dev/null @@ -1,64 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// C++ only supports std::initializer_list, so we need to get around compiler. -// -// fuck C++ once -// fuck C++ twice -// fuck C++ thrice -//===========================================================================// - -#ifndef TIER1_UTL_INITIALIZER_LIST_H -#define TIER1_UTL_INITIALIZER_LIST_H - -#include "stddef.h" - -// from GCC -namespace std -{ - template - class initializer_list - { - public: - typedef _E value_type; - typedef const _E& reference; - typedef const _E& const_reference; - typedef size_t size_type; - typedef const _E* iterator; - typedef const _E* const_iterator; - - private: - iterator _M_array; - size_type _M_len; - - constexpr initializer_list(const_iterator __a, size_type __l) - : _M_array(__a), _M_len(__l) { } - - public: - constexpr initializer_list() noexcept - : _M_array(0), _M_len(0) { } - - constexpr size_type - size() const noexcept { return _M_len; } - - constexpr const_iterator - begin() const noexcept { return _M_array; } - - constexpr const_iterator - end() const noexcept { return begin() + size(); } - }; - - template - constexpr const _Tp* - begin(initializer_list<_Tp> __ils) noexcept - { return __ils.begin(); } - - template - constexpr const _Tp* - end(initializer_list<_Tp> __ils) noexcept - { return __ils.end(); } -} - -template -using CUtlInitializerList = std::initializer_list; - - -#endif diff --git a/public/tier1/utlmap.h b/public/tier1/utlmap.h deleted file mode 100644 index 6b89f0f..0000000 --- a/public/tier1/utlmap.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TIER1_UTL_STRING_H -#define TIER1_UTL_STRING_H - -#include "tier1/utlvector.h" - -#endif \ No newline at end of file diff --git a/public/tier1/utlmutex.h b/public/tier1/utlmutex.h deleted file mode 100644 index 7176442..0000000 --- a/public/tier1/utlmutex.h +++ /dev/null @@ -1,25 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Mutexes for C++ -//===========================================================================// - -#ifndef TIER1_UTL_MUTEX_H -#define TIER1_UTL_MUTEX_H - -#include "pthread.h" - -class CUtlLock -{ -public: - CUtlLock(); - ~CUtlLock(); - - CUtlLock(const CUtlLock&) = delete; - CUtlLock& operator=(const CUtlLock&) = delete; - - void Lock(); - void Unlock(); -private: - pthread_mutex_t m_lock; -}; - -#endif diff --git a/public/tier1/utlstring.h b/public/tier1/utlstring.h deleted file mode 100644 index fd07e94..0000000 --- a/public/tier1/utlstring.h +++ /dev/null @@ -1,275 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Own implementation of string. -//===========================================================================// - -#ifndef TIER1_UTL_STRING_H -#define TIER1_UTL_STRING_H - -#include "tier1/utlvector.h" -#include "tier0/lib.h" -#include "stdarg.h" - -class CUtlString { -public: - CUtlString( void ); - CUtlString( const char *psz, ... ); - CUtlString( const CUtlString &sz ); - - void AppendTail( const char *psz ); - void AppendTail( char ch ); - void AppendHead( const char *psz ); - void AppendHead( char ch ); - void AppendAt( size_t nPosition, const char *psz ); - - void RemoveTail( size_t nCount ); - void RemoveHead( size_t nCount ); - void RemoveAt( size_t nPosition, size_t nCount ); - - CUtlString GetFileName(); - CUtlString GetFileExtension(); - CUtlString GetDirectory(); - CUtlString RemoveHeadFile(); - - char *GetString( void ); - size_t GetLenght( void ); - operator char*( void ); - operator CUtlVector&( void ); - CUtlString& operator=(const CUtlString &sz); - bool operator==(const char* psz); - bool operator!=(const char* psz); - bool operator==(CUtlString& string); - bool operator!=(CUtlString& string); -private: - CUtlVector m_data = 0; -}; -inline CUtlString::CUtlString( void ) -{ - m_data.Reserve(1); - m_data[0]=0; -} - -inline CUtlString::CUtlString( const char *szFormat, ... ) -{ - if (szFormat == 0) - { - m_data.Reserve(1); - m_data[0]=0; - return; - } - va_list vlArgs; - va_start(vlArgs, szFormat); - va_list vlArgs2; - va_copy(vlArgs2, vlArgs); - size_t nSize = V_vsnprintf(NULL, 0, szFormat, vlArgs2); - m_data.Reserve(nSize + 1); - va_end(vlArgs2); - V_vsnprintf(m_data.GetData(), nSize + 1, szFormat, vlArgs); - m_data.Resize(nSize + 1); - va_end(vlArgs); -} - -inline CUtlString::CUtlString( const CUtlString &sz ) -{ - m_data = sz.m_data; -}; - -inline void CUtlString::AppendTail( const char *psz ) -{ - m_data.Resize(V_strlen(m_data.GetData())); - m_data.AppendTail(psz,V_strlen(psz)); - m_data.Reserve(m_data.GetSize()+1); - m_data[m_data.GetSize()] = 0; -} - -inline void CUtlString::AppendHead( const char *psz ) -{ - m_data.AppendHead(psz,V_strlen(psz)); -} - -inline void CUtlString::AppendTail( char ch ) -{ - m_data.Resize(V_strlen(m_data.GetData())); - m_data.AppendTail(ch); - m_data.Reserve(m_data.GetSize()+1); - m_data[m_data.GetSize()] = 0; -} - -inline void CUtlString::AppendHead( char ch ) -{ - m_data.AppendHead(ch); -} -inline void CUtlString::AppendAt( size_t nPosition, const char *psz ) -{ - -} - -inline void CUtlString::RemoveTail( size_t nCount ) -{ - m_data.RemoveTail(nCount); - m_data[m_data.GetSize()-1] = 0; -} - -inline void CUtlString::RemoveHead( size_t nCount ) -{ - m_data.RemoveHead(nCount); -} - -inline void CUtlString::RemoveAt( size_t nPosition, size_t nCount ) -{ - -} - -inline CUtlString CUtlString::GetFileName() -{ - CUtlString szFileName = GetString(); - if (GetLenght() == 0) - return ""; - - char *pLast = &m_data[GetLenght()-1]; - while (pLast != m_data.GetData()) - { - if (*pLast=='/') - { - pLast++; - break; - } - pLast--; - } - - return pLast; -} - -inline CUtlString CUtlString::GetFileExtension() -{ - CUtlString szFileName = GetString(); - - char *pLast = &m_data[GetLenght()-1]; - while (pLast != m_data.GetData()) - { - if (*pLast=='.') - break; - if (*pLast=='/') - return NULL; - pLast--; - } - - return pLast+1; -} - - - -inline CUtlString CUtlString::GetDirectory() -{ - if (GetLenght() == 0) - return NULL; - size_t iNumDeleted = 0; - char *pLast = &m_data[GetLenght()-1]; - CUtlString szDirectory = GetString(); - while (pLast != m_data.GetData()) - { - if (*pLast=='/') - { - iNumDeleted++; - break; - } - pLast--; - iNumDeleted++; - } - - szDirectory.RemoveTail(iNumDeleted); - - return szDirectory; -} - -inline CUtlString CUtlString::RemoveHeadFile() -{ - size_t iLenght = GetLenght(); - size_t iNumDeleted = 0; - char *pc = GetString(); - CUtlString szDirectory = pc; - - if (GetLenght() == 0) - return NULL; - while ( iNumDeleted < iLenght ) - { - if (*pc == '/') - goto remove_slashes; - pc++; - iNumDeleted++; - } - return NULL; -remove_slashes: - while ( iNumDeleted < iLenght ) - { - if (*pc != '/') - { - szDirectory.RemoveHead(iNumDeleted); - return szDirectory; - } - pc++; - iNumDeleted++; - } - return NULL; -} - -inline char *CUtlString::GetString( void ) -{ - return m_data.GetData(); -} - -inline size_t CUtlString::GetLenght( void ) -{ - return V_strlen(GetString()); -} - -inline CUtlString::operator char*( void ) -{ - return GetString(); -} - -inline CUtlString::operator CUtlVector&( void ) -{ - return m_data; -} - -inline CUtlString &CUtlString::operator=(const CUtlString &sz) -{ - if (this != &sz) - { - m_data = sz.m_data; - } - return *this; -} - -inline bool CUtlString::operator==(const char *psz) -{ - if (psz==0) - psz = ""; - if (!V_strcmp(GetString(), psz)) - return true; - return false; -} - -inline bool CUtlString::operator!=(const char *psz) -{ - if (psz==0) - psz = ""; - if (!V_strcmp(GetString(), psz)) - return false; - return true; -} - -inline bool CUtlString::operator==(CUtlString &string) -{ - if (!V_strcmp(GetString(), string.GetString())) - return true; - return false; -} - -inline bool CUtlString::operator!=(CUtlString &string) -{ - if (!V_strcmp(GetString(), string.GetString())) - return false; - return true; -} -#endif diff --git a/public/tier1/utlvector.h b/public/tier1/utlvector.h deleted file mode 100644 index 0c24440..0000000 --- a/public/tier1/utlvector.h +++ /dev/null @@ -1,447 +0,0 @@ -//================= Copyright kotofyt, All rights reserved ==================// -// Purpose: Own implementation of vectors, it is better to use them in local -// namespaces for own . -//===========================================================================// - -#ifndef TIER1_UTL_VECTOR_H -#define TIER1_UTL_VECTOR_H - -#include "tier0/lib.h" -#include "tier1/utlbuffer.h" -#include "tier1/utlinitlist.h" - -//----------------------------------------------------------------------------- -// Basic vector implementation. There isn't much in them but they work. -//----------------------------------------------------------------------------- -template -class CUtlVector -{ -public: - CUtlVector( void ); - CUtlVector( size_t nSize ); - CUtlVector( CUtlInitializerList initalizerList ); - CUtlVector( const CUtlVector &vector ); - ~CUtlVector(); - - void AppendHead( const T &data ); - void AppendHead( const T *pData, size_t n ); - void AppendTail( const T &data ); - void AppendTail( const T *data, size_t n ); - void AppendAt( size_t nIndex, const T &data ); - void AppendAt( size_t nIndex, const T *data, size_t n ); - - void RemoveHead(); - void RemoveHead( size_t n ); - void RemoveTail(); - void RemoveTail( size_t n ); - void RemoveAt( size_t nIndex ); - void RemoveAt( size_t nIndex, size_t n ); - - T *GetData( void ); - size_t GetSize( void ); - void Resize( size_t nSize, size_t nDataOffset = 0 ); - void Reserve( size_t nSize, size_t nDataOffset = 0 ); - - T &operator[]( size_t nIndex ); - T &operator[]( size_t nIndex ) const; - CUtlVector &operator=(const CUtlVector &vec); - - // Iterator stuff - // Do we really need it? - struct Iterator { - T *m_pCurrent; - Iterator( T *pCurrent ) : m_pCurrent(pCurrent) {} - T& operator*( void ) const { return *m_pCurrent;} - Iterator& operator++( void ) { - ++m_pCurrent; - return *this; - } - bool operator!=( const Iterator& other ) const - { - return m_pCurrent != other.m_pCurrent; - } - }; - - - Iterator begin( void ) const - { - return Iterator((T*)m_data.GetMemory()); - } - Iterator end( void ) const - { - return Iterator((T*)m_data.GetMemory()+m_nSize); - } - -private: - size_t m_nSize = 0; - CUtlResizableBuffer m_data; -}; - -//---------------------------------------------------------------------------- -// Constructor -//---------------------------------------------------------------------------- -template -CUtlVector::CUtlVector( void ) -{ - -}; - -//---------------------------------------------------------------------------- -// Constructor -//---------------------------------------------------------------------------- -template -CUtlVector::CUtlVector( size_t nSize ) -{ - m_data.Resize(nSize); - V_memset(m_data.GetMemory(),0,m_data.GetSize()*sizeof(T)); - m_nSize = nSize; -}; - -//---------------------------------------------------------------------------- -// Fancy constructor -//---------------------------------------------------------------------------- -template -CUtlVector::CUtlVector( CUtlInitializerList initalizerList ) -{ - m_data.Resize(initalizerList.size()); - V_memset(m_data.GetMemory(),0,m_data.GetSize()*sizeof(T)); - m_nSize = m_data.GetSize(); - for (size_t i = 0; i -CUtlVector::CUtlVector( const CUtlVector& vector ) -{ - *this = vector; -} -template -CUtlVector::~CUtlVector() -{ -} - -template -void CUtlVector::AppendHead( const T &data ) -{ - AppendHead(&data,1); -} - -template -void CUtlVector::AppendHead( const T *pData, size_t n ) -{ - size_t nOldSize = m_nSize; - m_data.Resize(m_nSize+n); - for (size_t i = nOldSize; i > 0; --i) - { - new (&m_data[i + n - 1]) T(m_data[i - 1]); - m_data[i - 1].~T(); - } - for (size_t i = 0; i < n; ++i) - { - new (&m_data[i]) T(pData[i]); - } - m_nSize+=n; -} - -template -void CUtlVector::AppendTail( const T &data ) -{ - AppendTail(&data,1); -} - -template -void CUtlVector::AppendTail( const T *pData, size_t n ) -{ - m_data.Resize(m_data.GetSize()+n); - for ( size_t i = 0; i < n; i++ ) - new (&m_data[i+m_nSize]) T(pData[i]); - m_nSize+=n; -} - -template -void CUtlVector::AppendAt( size_t nIndex, const T &data ) -{ - AppendAt(nIndex, &data, 1); -} - -template -void CUtlVector::AppendAt( size_t nIndex, const T *pData, size_t n ) -{ - size_t nOldSize = m_nSize; - m_data.Resize(m_nSize+n); - for (size_t i = nOldSize; i > nIndex; --i) - { - new (&m_data[i + n - 1]) T(m_data[i - 1]); - m_data[i - 1].~T(); - } - for (size_t i = 0; i < n; ++i) - { - new (&m_data[nIndex + i]) T(pData[i]); - } - m_nSize+=n; -} - -template -void CUtlVector::RemoveHead() -{ - RemoveHead( 1 ); -} -template -void CUtlVector::RemoveHead( size_t n ) -{ - RemoveAt(0, n); -} -template -void CUtlVector::RemoveTail() -{ - RemoveTail( 1 ); -} -template -void CUtlVector::RemoveTail( size_t n ) -{ - if (n > m_nSize) - n = m_nSize; - m_data.Resize(m_nSize-n); - m_nSize -= n; -} -template -void CUtlVector::RemoveAt( size_t nIndex ) -{ - RemoveAt( nIndex, 1 ); -} -template -void CUtlVector::RemoveAt( size_t nIndex, size_t n ) -{ - if ( nIndex >= m_nSize ) - { - return; - } - if ( nIndex + n > m_nSize ) - { - n = m_nSize - nIndex; - } - for ( size_t i = nIndex; i < nIndex + n; i++ ) - { - m_data[i].~T(); - } - - size_t nElementsToMove = m_nSize - (nIndex + n); - for ( size_t i = 0; i < nElementsToMove; i++ ) - { - new (&m_data[nIndex + i]) T(m_data[nIndex + n + i]); - m_data[nIndex + n + i].~T(); - } - m_nSize -= n; -} - -template -T *CUtlVector::GetData( void ) -{ - return (T*)m_data.GetMemory(); -} - -template -size_t CUtlVector::GetSize( void ) -{ - return m_nSize; -} - -template -void CUtlVector::Resize( size_t nSize, size_t nDataOffset ) -{ - m_data.Resize(nSize, nDataOffset); - m_nSize = nSize; -} -template -void CUtlVector::Reserve( size_t nSize, size_t nDataOffset ) -{ - m_data.Resize(nSize, nDataOffset); -} -template -CUtlVector &CUtlVector::operator=(const CUtlVector &vec) -{ - if (this != &vec) - { - m_nSize = vec.m_nSize; - m_data = vec.m_data; - } - return *this; -} - -template -T &CUtlVector::operator[]( size_t nIndex ) -{ - return m_data[nIndex]; -} - -template -T &CUtlVector::operator[]( size_t nIndex ) const -{ - return m_data[nIndex]; -} - - -//----------------------------------------------------------------------------- -// Self referencing arrays are quite cool. -// They allow to append stuff in head and tail of the array and use less memory -// copying. Downside is their indexing is O(n/2) -// -// Implements the same stuff as CUtlVector does. -//----------------------------------------------------------------------------- -template -class CUtlSelfReferencingVector -{ -private: - template - struct SelfData_t; -public: - CUtlSelfReferencingVector(); - ~CUtlSelfReferencingVector(); - - void AppendHead( const T& data ); - void AppendTail( const T& data ); - void AppendAt( size_t nIndex, const T& data ); - - void RemoveHead( void ); - void RemoveTail( void ); - void RemoveAt( size_t nIndex ); - - T &GetFirst(); - T &GetLast(); - - size_t GetSize(); - - T operator[]( size_t nIndex ); - T& operator[]( size_t nIndex ) const; - - - // Iterator stuff - struct Iterator { - SelfData_t *m_pCurrent; - Iterator( SelfData_t *pCurrent ) : m_pCurrent(pCurrent) {} - T& operator*( void ) const { return m_pCurrent->data;} - Iterator& operator++( void ) { - if (m_pCurrent) m_pCurrent = m_pCurrent->pNext; - return *this; - } - bool operator!=( const Iterator& other ) const - { - return m_pCurrent != other.m_pCurrent; - } - }; - - Iterator begin( void ) const - { - return Iterator(m_pHead); - } - Iterator end( void ) const - { - return Iterator(NULL); - } - -private: - size_t m_nSize = 0; - - template - struct SelfData_t - { - SelfData_t *pNext = NULL; - SelfData_t *pPrev = NULL; - A data; - }; - SelfData_t *m_pTail = NULL; - SelfData_t *m_pHead = NULL; -}; - - -//---------------------------------------------------------------------------- -// Constructor -//---------------------------------------------------------------------------- -template -CUtlSelfReferencingVector::CUtlSelfReferencingVector() -{ - -}; - -//---------------------------------------------------------------------------- -// Destructor -//---------------------------------------------------------------------------- -template -CUtlSelfReferencingVector::~CUtlSelfReferencingVector() -{ - SelfData_t *pNext = NULL; - for (SelfData_t *pCurrent = m_pHead; pCurrent; pCurrent=pNext) - { - pNext = pCurrent->pNext; - delete pCurrent; - } -}; - -//---------------------------------------------------------------------------- -// Inserts new element in the start of the vector. -//---------------------------------------------------------------------------- -template -void CUtlSelfReferencingVector::AppendHead( const T& data ) -{ - SelfData_t* pData = new SelfData_t; - pData->data = data; - pData->pNext = m_pHead; - if (m_pHead) - m_pHead->pPrev = pData; - pData->pPrev = 0; - m_pHead = pData; - if (m_pTail == 0) - m_pTail = m_pHead; - m_nSize++; -}; - -//---------------------------------------------------------------------------- -// Inserts new element in the end of the vector. -//---------------------------------------------------------------------------- -template -void CUtlSelfReferencingVector::AppendTail( const T& data ) -{ - SelfData_t* pData = new SelfData_t; - pData->data = data; - if (m_pTail) - m_pTail->pNext = pData; - pData->pPrev = m_pTail; - m_pTail = pData; - if (m_pHead == 0) - m_pHead = m_pTail; - - m_nSize++; -}; - -//---------------------------------------------------------------------------- -// Removes element in the start of the vector. -//---------------------------------------------------------------------------- -template -void CUtlSelfReferencingVector::RemoveHead( void ) -{ - if (m_pHead == m_pTail) - m_pHead = 0; -}; -//---------------------------------------------------------------------------- -// Removes element in the end of the vector. -//---------------------------------------------------------------------------- -template -void CUtlSelfReferencingVector::RemoveTail( void ) -{ - -} - -template -T &CUtlSelfReferencingVector::GetFirst() -{ - return m_pHead->data; -} - -template -T &CUtlSelfReferencingVector::GetLast() -{ - return m_pTail->data; -} - - -#endif diff --git a/public/tier2/fileformats/ini.h b/public/tier2/fileformats/ini.h deleted file mode 100644 index 6508e87..0000000 --- a/public/tier2/fileformats/ini.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef TIER2_INI_H -#define TIER2_INI_H - -#include "tier0/platform.h" -#include "tier1/utlstring.h" -#include "tier1/utlvector.h" - -abstract_class IINISection -{ -public: - virtual bool GetBoolValue( const char *szKeyName ) = 0; - virtual int GetIntValue( const char *szKeyName ) = 0; - virtual const char *GetStringValue( const char *szKeyName ) = 0; - virtual CUtlString GetUTLStringValue( const char *szKeyName ) = 0; -}; - -abstract_class IINIFile -{ -public: - virtual IINISection *GetSection( const char *szSectionName ) = 0; -}; - -abstract_class IINIManager -{ -public: - virtual IINIFile *ReadFile( const char *psz ) = 0; - virtual IINIFile *ReadString( const char *psz ) = 0; - virtual void ReleaseFile( IINIFile *pFile ) = 0; -}; - -IINIManager *INIManager(); - -#endif diff --git a/public/tier2/fileformats/json.h b/public/tier2/fileformats/json.h deleted file mode 100644 index d27a629..0000000 --- a/public/tier2/fileformats/json.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef TIER2_JSON_H -#define TIER2_JSON_H - -#include "tier0/platform.h" -#include "tier1/utlstring.h" - -class IJSONObject; -class IJSONArray; -class IJSONValue; - -enum EJSONParameterType -{ - JSON_PARAMETER_NULL, - JSON_PARAMETER_STRING, - JSON_PARAMETER_NUMBER, - JSON_PARAMETER_BOOLEAN, - JSON_PARAMETER_ARRAY, - JSON_PARAMETER_OBJECT, -}; - -enum EJSONParameterNotes -{ - JSON_PARAMETER_NOTE_NONE = 0, - JSON_PARAMETER_NOTE_BINARY, -}; - -abstract_class IJSONArray -{ -public: - virtual uint32_t GetCount() = 0; - virtual IJSONValue *GetParameter( uint32_t i ) = 0; - - virtual void SetArray( uint32_t uCount, IJSONValue **ppValues ) = 0; - - virtual void CopyTo( IJSONArray *pObject ) = 0; - virtual void Free() = 0; -}; - -abstract_class IJSONValue -{ -public: - virtual EJSONParameterType GetType( void ) = 0; - virtual - virtual const char *GetStringValue() = 0; - virtual float GetNumberValue() = 0; - virtual bool GetBooleanValue() = 0; - virtual IJSONArray *GetArray() = 0; - virtual IJSONObject *GetObject() = 0; - - virtual void MakeNULL() = 0; - virtual void SetStringValue( const char *szString ) = 0; - virtual void SetNumberValue( float fValue ) = 0; - virtual void SetBooleanValue( bool bValue ) = 0; - virtual void SetArrayValue( IJSONArray *pValue ) = 0; - virtual void SetObjectValue( IJSONObject *pValue ) = 0; - - virtual void CopyTo( IJSONValue *pObject ) = 0; - virtual void Free() = 0; -}; - -abstract_class IJSONObject -{ -public: - virtual IJSONValue *GetValue( const char *szName ) = 0; - virtual void SetValue( const char *szName, IJSONValue *pValue ) = 0; - - virtual void CopyTo( IJSONObject *pObject ) = 0; - virtual void Free() = 0; -}; - -abstract_class IJSONManager -{ -public: - virtual IJSONObject *CreateObject( ) = 0; - virtual void FreeObject( IJSONObject *pObject ) = 0; - virtual IJSONArray *CreateArray( ) = 0; - virtual void FreeArray( IJSONArray *pArray ) = 0; - virtual IJSONValue *CreateValue( ) = 0; - virtual void FreeValue( IJSONValue *pValue ) = 0; - - virtual IJSONValue *ReadString( const char *szString ) = 0; - virtual CUtlString WriteString( IJSONValue *pValue ) = 0; -}; - -IJSONManager *JSONManager(); - -#endif diff --git a/public/tier2/fileformats/plist.h b/public/tier2/fileformats/plist.h deleted file mode 100644 index e115466..0000000 --- a/public/tier2/fileformats/plist.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef TIER2_PLIST_H -#define TIER2_PLIST_H - -#include "tier2/fileformats/json.h" - -abstract_class IPropertyListManager -{ -public: - virtual IJSONObject *ReadString( const char *psz ) = 0; -}; - -IPropertyListManager *PropertyListManager(); -#endif diff --git a/public/tier2/fileformats/xml.h b/public/tier2/fileformats/xml.h deleted file mode 100644 index fc062d3..0000000 --- a/public/tier2/fileformats/xml.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef TIER2_XML_H -#define TIER2_XML_H - -#include "tier0/platform.h" -#include "tier1/utlstring.h" - -struct XMLParam_t -{ - CUtlString m_szName; - CUtlString m_szValue; -}; - -enum EXMLObjectType -{ - XML_OBJECT_ELEMENT, - XML_OBJECT_TEXT, - XML_OBJECT_COMMENT, - XML_OBJECT_CDATA, - XML_OBJECT_PROCESSING_INSTRUCTION, - XML_OBJECT_DOCUMENT_TYPE, -}; - -abstract_class IXMLObject -{ -public: - virtual EXMLObjectType GetType() = 0; - virtual const char *GetValue() = 0; - virtual void SetType( EXMLObjectType eType ) = 0; - virtual void SetValue( const char *psz ) = 0; - - virtual CUtlVector &GetParams() = 0; - - virtual CUtlVector &GetChildren() = 0; - - virtual void Free() = 0; - - inline IXMLObject *FindFirstTag( const char *szName ) - { - for ( auto &c: GetChildren() ) - { - if ( c->GetType() != XML_OBJECT_ELEMENT ) continue; - if ( V_strcmp(c->GetValue(), szName) ) continue; - return c; - } - return NULL; - }; -}; - -struct XMLFile_t -{ - IXMLObject *m_pRoot; - CUtlString m_szRootObjectName; - CUtlString m_szFPI; - CUtlString m_szURI; -}; - -abstract_class IXMLManager -{ -public: - virtual XMLFile_t ReadString( const char *szData ) = 0; - virtual CUtlString WriteString( IXMLObject *pObject ) = 0; - - virtual IXMLObject *CreateObject() = 0; - virtual void FreeObject( IXMLObject *pObject ) = 0; -}; - -IXMLManager *XMLManager(); - -#endif diff --git a/public/tier2/iappsystem.h b/public/tier2/iappsystem.h deleted file mode 100644 index fb4ad2c..0000000 --- a/public/tier2/iappsystem.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef APP_SYSTEM_H -#define APP_SYSTEM_H - -#include "tier1/interface.h" - -//---------------------------------------------------------------------------- -// App system is a module which has different applications based on the user's system. -// For example rendering could use either Vulkan or Metal based on the system. -//---------------------------------------------------------------------------- -abstract_class IAppSystem -{ -public: - virtual void Init() = 0; - virtual void Shutdown() = 0; -}; - -#endif diff --git a/public/tier2/ifilesystem.h b/public/tier2/ifilesystem.h deleted file mode 100644 index 75f1721..0000000 --- a/public/tier2/ifilesystem.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef FILESYSTEM_H -#define FILESYSTEM_H - -#include "iappsystem.h" -#include "tier0/platform.h" -#include "tier1/utlbuffer.h" - -enum EFileMode -{ - FILEMODE_READ = 0x01, - FILEMODE_WRITE = 0x02, - FILEMODE_APPEND = 0x04, -}; - -enum ESeekMode -{ - SEEKMODE_RELATIVE_CURRENT, - SEEKMODE_RELATIVE_START, - SEEKMODE_RELATIVE_END, -}; - -abstract_class IFileSystem; - -class IFileHandle -{ -public: - IFileSystem *m_pFileSystem; -}; - -abstract_class IDirectoryHandle -{ -}; - -//---------------------------------------------------------------------------- -// IFileSystem is an app system which manages files, could have different -// file systems etc. Because of that there is base file system which manages -// others. PAK files are opened first, then mounted stuff comes second and -// host's system last. -//---------------------------------------------------------------------------- -abstract_class IFileSystem: public IAppSystem -{ -public: - virtual IFileHandle *Open( const char *szFileName, int eOpCode ) = 0; - virtual size_t Write( IFileHandle *pFile, const void *pData, size_t nDataSize ) = 0; - virtual size_t Read( IFileHandle *pFile, void *pData, size_t nDataSize ) = 0; - - virtual size_t Seek( IFileHandle *pFile, ESeekMode eSeekMode, size_t nOffset ) = 0; - virtual size_t Tell( IFileHandle *pFile ) = 0; - virtual size_t Size( IFileHandle *pFile ) = 0; - - virtual void Close( IFileHandle *pFile ) = 0; - - // Some cool stuff - virtual CUtlBuffer Read( IFileHandle *pFile ) = 0; - - // Leaks memory - // Should be cleaned by the user - virtual const char *ReadString( IFileHandle *pFile ) = 0; - - // Directory stuff - virtual IDirectoryHandle *OpenDir( const char *szDirName ) = 0; - virtual void CloseDir( IDirectoryHandle *pDir ) = 0; - - IFileSystem *m_pNext; - - void RegisterFileSystem(); -}; - -#define FILESYSTEM_INTERFACE_VERSION "FileSystem001" - -extern IFileSystem *filesystem; - -#endif diff --git a/public/tier2/tokenizer.h b/public/tier2/tokenizer.h deleted file mode 100644 index 2da7ca3..0000000 --- a/public/tier2/tokenizer.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef TIER2_TOKENIZER_H -#define TIER2_TOKENIZER_H -#include "tier0/platform.h" -#include "tier1/utlstring.h" -#include "tier1/utlvector.h" - -struct Token_t -{ - CUtlString m_szValue; - bool m_bIsQuoted; - - uint32_t m_iLine; - uint32_t m_iCharacter; -}; - -typedef bool( *IsAlphabetSymbolFn )( char c ); - -struct TokenizeProperties_t -{ - IsAlphabetSymbolFn m_pfnIsAlphabetSymbol; - IsAlphabetSymbolFn m_pfnIsFirstAlphabetSymbol; - bool m_bAllowSlashToContinueString; -}; - -CUtlVector Tokenize( const char *szString ); -CUtlVector Tokenize( const char *szString, IsAlphabetSymbolFn pfnIsAlphabetSymbol ); - - -#endif diff --git a/public/tier2/uuid.h b/public/tier2/uuid.h deleted file mode 100644 index e69de29..0000000 diff --git a/public/tier3/lexer.h b/public/tier3/lexer.h deleted file mode 100644 index 264cff1..0000000 --- a/public/tier3/lexer.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef BRB_LEXER_H -#define BRB_LEXER_H - -#include "tier0/platform.h" - -abstract_class ILexerWord -{ -public: - virtual int GetType() = 0; -}; - -abstract_class ILexer -{ -public: - virtual ILexerWord *ParseTokens( CUtlVector tokens ) = 0; -}; - -#endif diff --git a/shadercompiler/__build.cpp b/shadercompiler/build.cpp similarity index 83% rename from shadercompiler/__build.cpp rename to shadercompiler/build.cpp index 0ad2a72..3edaefd 100644 --- a/shadercompiler/__build.cpp +++ b/shadercompiler/build.cpp @@ -3,33 +3,31 @@ #include "ld.h" #include "target.h" -CUtlString shadercompiler_lib; -CUtlString shadercompiler_exe; DECLARE_BUILD_STAGE(libshadercompiler) { CProject_t stProject; LinkProject_t stLinkProject; CUtlString szOutput; - stProject.m_szName = "shadercompiler"; - stProject.m_target = Target_t::HostTarget(); + stProject.m_szName = "ShaderCompiler"; stProject.bFPIC = true; stProject.includeDirectories = { - "public", - "external/slang/include", - "external/Vulkan-Headers/include", + "../public", + "../external/slang/include", + "../external/Vulkan-Headers/include", }; stProject.files = { - "shadercompiler/slang/vulkan_spirv.cpp", - "materialsystem/compiledshader.cpp", + "slang/vulkan_spirv.cpp", + "../materialsystem/compiledshader.cpp", }; stLinkProject = ccompiler->Compile(&stProject); stLinkProject.linkType = ELINK_STATIC_LIBRARY; szOutput = linker->Link(&stLinkProject); - shadercompiler_lib = szOutput; - return 1; + ADD_OUTPUT_OBJECT("lib", szOutput); + + return 0; } DECLARE_BUILD_STAGE(shadercompiler) { @@ -41,7 +39,7 @@ DECLARE_BUILD_STAGE(shadercompiler) stProject.m_target = Target_t::HostTarget(); stProject.includeDirectories = {"public"}; stProject.files = { - "shadercompiler/main.cpp", + "main.cpp", }; stLinkProject = ccompiler->Compile(&stProject); @@ -53,15 +51,18 @@ DECLARE_BUILD_STAGE(shadercompiler) stLinkProject.libraries = {"slang-compiler","slang-glslang-2025.24.2"}; stLinkProject.libraryDirectories = {"external/linux"}; szOutput = linker->Link(&stLinkProject); + /* filesystem2->MakeDirectory(CUtlString("%s/bin/tools", szOutputDir.GetString())); filesystem2->CopyFile(CUtlString("%s/bin/tools", szOutputDir.GetString()), szOutput); filesystem2->CopyFile(CUtlString("%s/bin/tools", szOutputDir.GetString()), "external/linux/libslang-compiler.so.0.2025.24.2"); filesystem2->CopyFile(CUtlString("%s/bin/tools", szOutputDir.GetString()), "external/linux/libslang-glslang-2025.24.2.so"); shadercompiler_exe = CUtlString("%s/bin/tools/fsc", szOutputDir.GetString()); + */ return 1; } +/* DECLARE_BUILD_STAGE(compileshaders) { if (CommandLine()->CheckParam("-nofsc")) @@ -73,3 +74,4 @@ DECLARE_BUILD_STAGE(compileshaders) runner->Wait(); return 0; }; +*/ diff --git a/stdfilesystems/build.cpp b/stdfilesystems/build.cpp deleted file mode 100644 index 36f365d..0000000 --- a/stdfilesystems/build.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "helper.h" -#include "c.h" -#include "ld.h" -#include "tier1/utlstring.h" - -ADD_DEPENDENCY_BUILD_FILE(tier0, "../tier0/build.cpp") -ADD_DEPENDENCY_BUILD_FILE(tier1, "../tier1/build.cpp") - -CUtlVector fs_CompiledFiles = { - "filesystem_libc.cpp", -}; - -DECLARE_BUILD_STAGE(filesystem_std) -{ - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - CUtlString szOutputProject = ""; - - compileProject.m_szName = "filesystem_std"; - compileProject.files = fs_CompiledFiles; - compileProject.includeDirectories = {"../public"}; - compileProject.bFPIC = true; - ldProject = ccompiler->Compile(&compileProject); - - ldProject.linkType = ELINK_DYNAMIC_LIBRARY; - ldProject.libraryObjects = { - GET_PROJECT_LIBRARY(tier0, "tier0"), - GET_PROJECT_LIBRARY(tier1, "tier1"), - }; - szOutputProject = linker->Link(&ldProject); - - ADD_OUTPUT_OBJECT("fs", szOutputProject); - - return 0; -}; diff --git a/stdfilesystems/filesystem_libc.cpp b/stdfilesystems/filesystem_libc.cpp deleted file mode 100644 index eed1215..0000000 --- a/stdfilesystems/filesystem_libc.cpp +++ /dev/null @@ -1,165 +0,0 @@ -#include "tier2/ifilesystem.h" -#include "tier1/interface.h" -#include "tier0/lib.h" -#include "errno.h" -#include "dirent.h" - -class CLIBCFileHandle : public IFileHandle -{ -public: - FILE *m_pFile; - size_t m_nSize; - -}; - -class CLIBCDirectoryHandle: public IDirectoryHandle -{ -public: - DIR *m_pDir; -}; - -class CLIBCFileSystem : public IFileSystem -{ -public: - virtual void Init() override { - - }; - virtual void Shutdown() override {}; - - virtual IFileHandle *Open( const char *szFileName, int eOpCode ) override - { - const char *szOperation; - FILE *pFile; - CLIBCFileHandle *pHandle = NULL; - - switch (eOpCode) - { - case FILEMODE_READ: - szOperation = "rb"; - break; - case FILEMODE_WRITE: - szOperation = "wb"; - break; - default: - V_printf("Operation is not supported\n"); - break; - } - - pFile = V_fopen(szFileName, szOperation); - if (!pFile) - { - return NULL; - } - - pHandle = new CLIBCFileHandle; - pHandle->m_pFileSystem = this; - pHandle->m_pFile = pFile; - Seek(pHandle,SEEKMODE_RELATIVE_END, 0); - pHandle->m_nSize = Tell(pHandle); - Seek(pHandle, SEEKMODE_RELATIVE_START, 0); - return pHandle; - } - virtual size_t Write( IFileHandle *pFile, const void *pData, size_t nDataSize ) override - { - CLIBCFileHandle *pHandle = (CLIBCFileHandle*)pFile; - if (!pHandle) - return 0; - return V_fwrite( pData, 1, nDataSize, pHandle->m_pFile); - } - virtual size_t Read( IFileHandle *pFile, void *pData, size_t nDataSize ) override - { - CLIBCFileHandle *pHandle = (CLIBCFileHandle*)pFile; - if (!pHandle) - return 0; - return V_fread( pData, 1, nDataSize, pHandle->m_pFile ); - } - - virtual size_t Seek( IFileHandle *pFile, ESeekMode eSeekMode, size_t nOffset ) override - { - CLIBCFileHandle *pHandle = (CLIBCFileHandle*)pFile; - int eLibcSeekMode = 0; - - if (!pHandle) - return 0; - - switch (eSeekMode) { - case SEEKMODE_RELATIVE_CURRENT: - eLibcSeekMode = SEEK_CUR; - break; - case SEEKMODE_RELATIVE_END: - eLibcSeekMode = SEEK_END; - break; - case SEEKMODE_RELATIVE_START: - eLibcSeekMode = SEEK_SET; - break; - } - - return V_fseek( pHandle->m_pFile, nOffset, eLibcSeekMode ); - } - - virtual size_t Tell( IFileHandle *pFile ) override - { - CLIBCFileHandle *pHandle = (CLIBCFileHandle*)pFile; - if (!pHandle) - return 0; - return V_ftell(pHandle->m_pFile); - } - - virtual size_t Size( IFileHandle *pFile ) override - { - CLIBCFileHandle *pHandle = (CLIBCFileHandle*)pFile; - if (!pHandle) - return 0; - return pHandle->m_nSize; - } - - - - virtual void Close( IFileHandle *pFile ) override - { - CLIBCFileHandle *pHandle = (CLIBCFileHandle*)pFile; - if (!pHandle) - return; - V_fclose(pHandle->m_pFile); - delete pHandle; - } - - virtual CUtlBuffer Read( IFileHandle *pFile ) override { return {}; }; - virtual const char *ReadString( IFileHandle *pFile ) override { - char *szData = NULL; - size_t uSize = Size(pFile); - - szData = (char*)V_malloc(uSize+1); - Read(pFile, szData,uSize); - szData[uSize] = 0; - - - return szData; - }; - - virtual IDirectoryHandle *OpenDir( const char *szDirName ) override - { - CLIBCDirectoryHandle *pHandle = NULL; - DIR *pDir = opendir(szDirName); - if (pDir == NULL) - return NULL; - - pHandle = new CLIBCDirectoryHandle; - pHandle->m_pDir = pDir; - return pHandle; - - }; - - virtual void CloseDir( IDirectoryHandle *pDir ) override - { - if (!pDir) - return; - CLIBCDirectoryHandle *pCDir = (CLIBCDirectoryHandle*)pDir; - - closedir(pCDir->m_pDir); - - delete (CLIBCDirectoryHandle*)pDir; - }; -}; - -EXPOSE_INTERFACE(CLIBCFileSystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION) diff --git a/tests/ini/build.cpp b/tests/ini/build.cpp deleted file mode 100644 index 2ef1f20..0000000 --- a/tests/ini/build.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "c.h" -#include "target.h" -#include "helper.h" - -DECLARE_BUILD_STAGE(ini_test) -{ - CProject_t p = { - .files = { - "../../tier0/lib.cpp", - "../../tier0/mem.cpp", - "../../tier0/platform.cpp", - "../../tier1/interface.cpp", - "../../tier1/utlbuffer.cpp", - "../../tier1/utlstring.cpp", - "../../tier1/utlvector.cpp", - "../../tier1/utlmap.cpp", - "../../tier1/commandline.cpp", - "../../tier2/fileformats/ini.cpp", - "../../tier2/filesystem.cpp", - "../../tier2/filesystem_libc.cpp", - "main.cpp", - }, - .includeDirectories = - { - "../../public" - }, - }; - p.m_szName = "initest"; - LinkProject_t l = ccompiler->Compile(&p); - CUtlString szPath = linker->Link(&l); - filesystem2->CopyFile("./", szPath); - - - return 0; -} diff --git a/tests/ini/initest b/tests/ini/initest deleted file mode 100644 index 8726a99..0000000 Binary files a/tests/ini/initest and /dev/null differ diff --git a/tests/ini/main.cpp b/tests/ini/main.cpp deleted file mode 100644 index 4dbf0fe..0000000 --- a/tests/ini/main.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "tier0/lib.h" -#include "tier0/mem.h" -#include "tier1/utlbuffer.h" -#include "tier2/fileformats/ini.h" -#include "tier2/ifilesystem.h" - -int main( int argc, char **argv ) -{ - - const char *szFileName; - IFileHandle *pHandle = NULL; - size_t nSize = 0; - CUtlBuffer szData; - - CommandLine()->CreateCommandLine(argc, argv); - filesystem->Init(); - - // Get file - szFileName = CommandLine()->ParamValue("-f"); - if (!szFileName) - return 0; - - // Load it - pHandle = filesystem->Open(szFileName, FILEMODE_READ); - if (!pHandle) - return 0; - - // Get size - pHandle->Seek(SEEKMODE_RELATIVE_END, 0); - nSize = pHandle->Tell(); - pHandle->Seek(SEEKMODE_RELATIVE_START, 0); - - // Read it - szData = CUtlBuffer(nSize+1); - pHandle->Read(szData, nSize); - pHandle->Close(); - - szData[nSize] = 0; - - IINIFile *pIniFile = INIManager()->ReadString(szData); - if (!pIniFile) - return 0; - IINISection *pTestValues = pIniFile->GetSection("Test_Values"); - if (!pTestValues) - return 0; - V_printf("%s\n",pTestValues->GetStringValue("abc3d")); - return 0; -}; diff --git a/tests/ini/test1.ini b/tests/ini/test1.ini deleted file mode 100644 index cf31c5e..0000000 --- a/tests/ini/test1.ini +++ /dev/null @@ -1,13 +0,0 @@ - -[Test_Values] -a = "Hello world!\n" -b = true -c = false -c = 3.1415926 -d = 123456 -e = -2.71828 -f = -890 -g = .34 -abc3d = "Hello world from the funny engine, you can use \" to add quotes" - - diff --git a/tests/ini/test2.ini b/tests/ini/test2.ini deleted file mode 100644 index 558ed37..0000000 --- a/tests/ini/test2.ini +++ /dev/null @@ -1 +0,0 @@ -[ diff --git a/tests/ini/test3.ini b/tests/ini/test3.ini deleted file mode 100644 index 95ef80c..0000000 --- a/tests/ini/test3.ini +++ /dev/null @@ -1 +0,0 @@ -[Hello diff --git a/tests/ini/test4.ini b/tests/ini/test4.ini deleted file mode 100644 index e849c76..0000000 --- a/tests/ini/test4.ini +++ /dev/null @@ -1 +0,0 @@ -[Test Hello] diff --git a/tests/ini/test5.ini b/tests/ini/test5.ini deleted file mode 100644 index 5ef5672..0000000 --- a/tests/ini/test5.ini +++ /dev/null @@ -1,2 +0,0 @@ -["Hello world"] -Test diff --git a/tests/ini/test6.ini b/tests/ini/test6.ini deleted file mode 100644 index 53973bf..0000000 --- a/tests/ini/test6.ini +++ /dev/null @@ -1,2 +0,0 @@ -[Test] -a b diff --git a/tests/ini/test7.ini b/tests/ini/test7.ini deleted file mode 100644 index 4df87f3..0000000 --- a/tests/ini/test7.ini +++ /dev/null @@ -1,2 +0,0 @@ -[Test] -a = diff --git a/tests/ini/test8.ini b/tests/ini/test8.ini deleted file mode 100644 index f6da3f4..0000000 --- a/tests/ini/test8.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Test] -a = b -c = d - -d = test diff --git a/tier0/__build.cpp b/tier0/__build.cpp deleted file mode 100644 index 954cbdb..0000000 --- a/tier0/__build.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "helper.h" -#include "c.h" -#include "ld.h" -#include "tier1/utlstring.h" -#include "tier1/commandline.h" - -CUtlVector tier0_CompiledFiles = { - "tier0/lib.cpp", - "tier0/mem.cpp", - "tier0/platform.cpp", - "tier0/network.cpp", -}; - -DECLARE_BUILD_STAGE(tier0) -{ - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - CUtlString szOutputProject = ""; - - compileProject.m_szName = "tier0"; - compileProject.files = tier0_CompiledFiles; - compileProject.includeDirectories = all_IncludeDirectories; - compileProject.bFPIC = true; - ldProject = ccompiler->Compile(&compileProject); - if (bStaticBuild) - { - ldProject.linkType = ELINK_STATIC_LIBRARY; - szOutputProject = linker->Link(&ldProject); - tier0_lib = szOutputProject; - } - else - { - ldProject.linkType = ELINK_DYNAMIC_LIBRARY; - szOutputProject = linker->Link(&ldProject); - filesystem2->MakeDirectory(CUtlString("%s/bin",szOutputDir.GetString())); - filesystem2->CopyFile(CUtlString("%s/bin", szOutputDir.GetString()), szOutputProject); - - ldProject.linkType = ELINK_STATIC_LIBRARY; - szOutputProject = linker->Link(&ldProject); - tier0_lib = szOutputProject; - } - - return 0; -}; diff --git a/tier0/build.cpp b/tier0/build.cpp deleted file mode 100644 index 5c7ea99..0000000 --- a/tier0/build.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "helper.h" -#include "c.h" -#include "ld.h" -#include "tier1/utlstring.h" - -CUtlVector tier0_CompiledFiles = { - "lib.cpp", - "mem.cpp", - "platform.cpp", - "network.cpp", - "commandline.cpp", - "rand.cpp", -}; - -DECLARE_BUILD_STAGE(tier0) -{ - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - CUtlString szOutputProject = ""; - - compileProject.m_szName = "tier0"; - compileProject.files = tier0_CompiledFiles; - compileProject.includeDirectories = {"../public"}; - compileProject.bFPIC = true; - ldProject = ccompiler->Compile(&compileProject); - - ldProject.linkType = ELINK_DYNAMIC_LIBRARY; - szOutputProject = linker->Link(&ldProject); - - ADD_OUTPUT_OBJECT("tier0", szOutputProject); - - return 0; -}; diff --git a/tier0/commandline.cpp b/tier0/commandline.cpp deleted file mode 100644 index 8190f81..0000000 --- a/tier0/commandline.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "tier0/commandline.h" -#include "tier1/utlvector.h" - - -class CCommandLine : public ICommandLine -{ -public: - virtual void CreateCommandLine( int argc, char **argv ) override; - - virtual bool CheckParam( const char *psz ) override; - virtual char *ParamValue( const char* psz, const char *szDefaultValue = 0 ) override; - - virtual void AddParam( char *psz ) override; - virtual void RemoveParam( char *psz ) override; - - virtual int ParamCount() override; - virtual int FindParam( const char *psz ) override; - virtual const char *GetParam(int nIndex) override; -private: - CUtlVector m_params; -}; - - -void CCommandLine::CreateCommandLine( int argc, char **argv ) -{ - m_params.AppendTail(argv,argc); -} - -bool CCommandLine::CheckParam( const char *psz ) -{ - for (auto szParam: m_params) { - if (!V_strcmp(szParam, psz)) - { - return true; - } - } - return false; -} - -char *CCommandLine::ParamValue( const char *psz, const char *szDefaultValue ) -{ - int i = 0; - for (auto szParam: m_params) { - i++; - if (i>=m_params.GetSize()) - break; - if (!V_strcmp(szParam, psz)) - return m_params[i]; - } - return (char*)szDefaultValue; -} - -void CCommandLine::AddParam( char *psz ) -{ - m_params.AppendTail(psz); -} - -void CCommandLine::RemoveParam( char *psz ) -{ - -} -int CCommandLine::ParamCount() -{ - return m_params.GetSize(); -} -int CCommandLine::FindParam( const char *psz ) -{ - int i = 0; - for (auto szParam: m_params) { - if (!V_strcmp(szParam, psz)) - return i; - i++; - } - return 0; -} -const char *CCommandLine::GetParam(int nIndex) -{ - return m_params[nIndex]; -} - -ICommandLine *CommandLine() -{ - static CCommandLine s_CommandLine; - return &s_CommandLine; -} diff --git a/tier0/lib.cpp b/tier0/lib.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/tier0/mem.cpp b/tier0/mem.cpp deleted file mode 100644 index 10e445f..0000000 --- a/tier0/mem.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "tier0/mem.h" -#include "stdlib.h" -#include "tier0/platform.h" - -//----------------------------------------------------------------------------- -// These functions copy over libc memory functions -//----------------------------------------------------------------------------- - -void* V_malloc(int nSize) -{ - void *pMemory = malloc(nSize); - if (!pMemory) - Plat_FatalErrorFunc("Failed to allocate memory"); - return pMemory; -} - -void V_free(void *pMem) -{ - return free(pMem); -} - -void* V_realloc(void *pMem, int nSize) -{ - return realloc(pMem, nSize); -} - -void *operator new( size_t nCount ) -{ - return V_malloc(nCount); -} - -void *operator new ( size_t nCount, void *pPtr ) -{ - return pPtr; -} - -void operator delete( void *pMem ) noexcept -{ - return V_free(pMem); -} diff --git a/tier0/network.cpp b/tier0/network.cpp deleted file mode 100644 index cc32de6..0000000 --- a/tier0/network.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "tier0/network.h" - -void Net_Init() -{ -} - -void Net_Deinit() -{ - -} - diff --git a/tier0/platform.cpp b/tier0/platform.cpp deleted file mode 100644 index 41bf345..0000000 --- a/tier0/platform.cpp +++ /dev/null @@ -1,310 +0,0 @@ -#include "tier0/platform.h" -#include "tier0/lib.h" -#include "stdarg.h" -#include "unistd.h" -#include "sys/stat.h" -#include "dirent.h" -#include "time.h" -#include "signal.h" - -#ifdef __linux__ -#include "dlfcn.h" -#ifdef __GLIBC__ -#include "execinfo.h" -#endif -#endif -#ifdef __APPLE__ -#include "dlfcn.h" -#endif -#ifdef __WIN32__ -#include "windows.h" -#include "direct.h" -#endif - -PLATFORM_INTERFACE void Plat_FatalErrorFunc(const char* szFormat, ...) -{ - va_list list; - va_start(list, szFormat); - V_vprintf(szFormat, list); - va_end(list); - fflush(stdout); -#if defined(__WIN32__) - __debugbreak(); -#elif defined(__wasm32__) -#else - raise(SIGTRAP); -#endif - Plat_Exit(1); -} - -PLATFORM_INTERFACE void Plat_ListDirRecursive(const char* szPath, ListDirCallbackFn file, ListDirCallbackFn dir) -{ - struct dirent *entry; - DIR *dp = opendir(szPath); - - if (!dp) { - return; - } - - while ((entry = readdir(dp)) != NULL) { - char full_path[1024]; - if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) - continue; - - snprintf(full_path, sizeof(full_path), "%s/%s", szPath, entry->d_name); - - struct stat statbuf; - if (stat(full_path, &statbuf) == -1) { - continue; - } - - if (S_ISDIR(statbuf.st_mode)) { - if (dir) - dir(full_path); - Plat_ListDirRecursive(full_path, file, dir); - } else { - if (file) - file(full_path); - } - } - - closedir(dp); -} -PLATFORM_INTERFACE void Plat_ListDir(const char* szPath, ListDirCallbackFn file, ListDirCallbackFn dir) -{ - struct dirent *entry; - DIR *dp = opendir(szPath); - - if (!dp) { - return; - } - - while ((entry = readdir(dp)) != NULL) { - char full_path[1024]; - if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) - continue; - - snprintf(full_path, sizeof(full_path), "%s/%s", szPath, entry->d_name); - - struct stat statbuf; - if (stat(full_path, &statbuf) == -1) { - continue; - } - - if (S_ISDIR(statbuf.st_mode)) { - if (dir) - dir(full_path); - } else { - if (file) - file(full_path); - } - } - - closedir(dp); -} - -PLATFORM_INTERFACE char *Plat_GetExtension( const char *szPath ) -{ - char *last = (char*)szPath + V_strlen(szPath) - 1; - while (last != szPath) - { - if (*last=='.') - { - break; - }; - if (*last=='/') - { - return 0; - } - last--; - } - return last+1; -} -PLATFORM_INTERFACE void Plat_MakeDir( const char *szPath, int iPermissions ) -{ -#ifdef __WIN32__ - _mkdir(szPath); -#endif -#ifdef POSIX -#ifndef ACCESSPERMS -#define ACCESSPERMS 0777 -#endif - mkdir(szPath, ACCESSPERMS); -#endif -} - -PLATFORM_INTERFACE void Plat_Backtrace( void ) -{ -#ifdef __linux__ -#ifdef __GLIBC__ - void *buffer[64]; - int nptrs = backtrace(buffer, 64); - char **symbols = backtrace_symbols(buffer, nptrs); - - if (symbols == NULL) { - V_printf("Backtrace failed\n"); - exit(EXIT_FAILURE); - } - - for (int i = 0; i < nptrs; i++) { - V_printf(" [%d] %s\n", i, symbols[i]); - } - - free(symbols); -#endif -#endif -#ifdef __WIN32__ - /* - void* buffer[64]; - USHORT nptrs = CaptureStackBackTrace(0, 64, buffer, NULL); - - HANDLE process = GetCurrentProcess(); - SymInitialize(process, NULL, TRUE); - - SYMBOL_INFO* symbol = (SYMBOL_INFO*)calloc(sizeof(SYMBOL_INFO) + 256, 1); - symbol->MaxNameLen = 255; - symbol->SizeOfStruct = sizeof(SYMBOL_INFO); - - if (!symbol) { - V_printf("Backtrace failed\n"); - return; - } - - for (USHORT i = 0; i < nptrs; i++) { - if (SymFromAddr(process, (DWORD64)(buffer[i]), 0, symbol)) { - V_printf(" [%d] %s - 0x%0llX\n", i, symbol->Name, symbol->Address); - } else { - V_printf(" [%d] ??? - 0x%0llX\n", i, (DWORD64)(buffer[i])); - } - } - - free(symbol); - */ -#endif -}; - -PLATFORM_INTERFACE void *Plat_LoadLibrary( const char *psz ) -{ -#ifdef __linux__ - void *lib = dlopen(psz, RTLD_NOW); - if (!lib) - V_printf("Failed to open %s\n\t%s\n", psz, dlerror()); - return lib; -#endif -#ifdef __APPLE__ - void *lib = dlopen(psz, RTLD_GLOBAL | RTLD_NOW); - if (!lib) - V_printf("Failed to open %s\n\t%s\n", psz, dlerror()); - return lib; -#endif -#ifdef __WIN32__ - return LoadLibraryA(psz); -#endif -} -PLATFORM_INTERFACE void *Plat_GetProc( void *lib, const char *psz ) -{ -#ifdef __linux__ - return dlsym(lib, psz); -#endif -#ifdef __APPLE__ - return dlsym(lib, psz); -#endif -#ifdef __WIN32__ - return (void*)GetProcAddress((HMODULE)lib, psz); -#endif -} - -PLATFORM_INTERFACE void Plat_SetEnv( const char *szVar, const char *psz ) -{ -#ifdef POSIX - setenv(szVar, psz, true); -#endif -#ifdef __WIN32__ - SetEnvironmentVariable(szVar, psz); -#endif -} - -PLATFORM_INTERFACE const char *Plat_GetEnv( const char *szVar ) -{ - return getenv(szVar); -} - - -PLATFORM_INTERFACE void Plat_SetWorkingDir( const char *psz ) -{ - chdir(psz); -} -#ifndef MAX_PATH -#define MAX_PATH 4096 -#endif - -PLATFORM_INTERFACE const char *Plat_GetWorkingDir( void ) -{ - static char szCwd[MAX_PATH]; - getcwd(szCwd, MAX_PATH); - return szCwd; -} - - -static char s_szExecutablePath[MAX_PATH]; -#ifdef __linux__ -static ssize_t s_iExecutablePathSize = readlink("/proc/self/exe", s_szExecutablePath, MAX_PATH); -#endif - -PLATFORM_INTERFACE const char *Plat_GetExecutablePath( void ) -{ - return s_szExecutablePath; -} -PLATFORM_INTERFACE const char *Plat_GetParentDir( const char *psz ) -{ -} - -PLATFORM_INTERFACE void Plat_UnloadLibrary( void *lib ) -{ -#ifdef __linux__ - dlclose(lib); -#endif -#ifdef __WIN32__ - FreeLibrary((HMODULE)lib); -#endif -}; - -PLATFORM_INTERFACE double Plat_GetTime( void ) -{ -#ifndef __WIN32__ - struct timespec tp; - clock_gettime(CLOCK_MONOTONIC, &tp); - static time_t s_starttime = tp.tv_sec; - - return (tp.tv_sec-s_starttime)+tp.tv_nsec/1e9; -#else - static LARGE_INTEGER s_startcount; - static LARGE_INTEGER s_frequency; - static int s_initialized = 0; - - LARGE_INTEGER tp; - - if (!s_initialized) { - QueryPerformanceFrequency(&s_frequency); - QueryPerformanceCounter(&s_startcount); - s_initialized = 1; - } - - QueryPerformanceCounter(&tp); - - return (double)(tp.QuadPart - s_startcount.QuadPart) / s_frequency.QuadPart; -#endif -} - -PLATFORM_INTERFACE void Plat_Exit( int status ) -{ -#ifdef __linux__ - _exit(status); -#endif -#ifdef __APPLE__ - _exit(status); -#endif -#ifdef __WIN32__ - _exit(status); -#endif -}; diff --git a/tier0/rand.cpp b/tier0/rand.cpp deleted file mode 100644 index 764d1b1..0000000 --- a/tier0/rand.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "tier0/rand.h" -#include "tier0/lib.h" - -static bool b_sIsRandInit = false; -static FILE *s_pURandom = NULL; - -PLATFORM_INTERFACE void Plat_InitRandom() -{ - if (b_sIsRandInit) - return; - s_pURandom = V_fopen("/dev/urandom","rb"); - if (!s_pURandom) - Plat_FatalErrorFunc("/dev/urandom wasn't found somehow\n"); - b_sIsRandInit = true; -} - -PLATFORM_INTERFACE void Plat_ShutdownRandom() -{ - b_sIsRandInit = false; -} - -PLATFORM_INTERFACE void Plat_URandom( size_t uBufferSize, uint8_t *szBuffer ) -{ - if (!b_sIsRandInit) - Plat_InitRandom(); - - V_fread(szBuffer, 1, uBufferSize, s_pURandom); -} - diff --git a/tier1/__build.cpp b/tier1/__build.cpp deleted file mode 100644 index 14422e5..0000000 --- a/tier1/__build.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "helper.h" -#include "c.h" -#include "ld.h" -#include "tier1/utlstring.h" -#include "tier1/commandline.h" - -CUtlVector tier1_CompiledFiles = { - "tier1/interface.cpp", - "tier1/appinit.cpp", - "tier1/commandline.cpp", - "tier1/utlbuffer.cpp", - "tier1/utlmap.cpp", - "tier1/utlstring.cpp", - "tier1/utlvector.cpp", -}; -CUtlString tier1_lib; - -DECLARE_BUILD_STAGE(tier1) -{ - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - - compileProject.m_szName = "tier1"; - compileProject.files = tier1_CompiledFiles; - compileProject.includeDirectories = all_IncludeDirectories; - compileProject.bFPIC = true; - ldProject = ccompiler->Compile(&compileProject); - ldProject.linkType = ELINK_STATIC_LIBRARY; - - CUtlString outputProject = linker->Link(&ldProject); - tier1_lib = outputProject; - - return 0; -}; diff --git a/tier1/appinit.cpp b/tier1/appinit.cpp deleted file mode 100644 index 805aa0a..0000000 --- a/tier1/appinit.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "tier1/appinit.h" -#include "tier1/utlstring.h" -#include "tier0/platform.h" - -void AppInitializePath() -{ - const char *szPath = Plat_GetExecutablePath(); - CUtlString szEnv = Plat_GetEnv("PATH"); - printf("%s\n",szEnv.GetString()); - szEnv.AppendTail(":"); - szEnv.AppendTail(szPath); - Plat_SetEnv("PATH", szEnv); -} diff --git a/tier1/build.cpp b/tier1/build.cpp deleted file mode 100644 index 7287323..0000000 --- a/tier1/build.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "helper.h" -#include "c.h" -#include "ld.h" -#include "tier1/utlstring.h" - -CUtlVector tier1_CompiledFiles = { - "interface.cpp", - "appinit.cpp", - "utlbuffer.cpp", - "utlmap.cpp", - "utlstring.cpp", - "utlvector.cpp", -}; - -DECLARE_BUILD_STAGE(tier1) -{ - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - - compileProject.m_szName = "tier1"; - compileProject.files = tier1_CompiledFiles; - compileProject.includeDirectories = {"../public"}; - compileProject.bFPIC = true; - ldProject = ccompiler->Compile(&compileProject); - ldProject.linkType = ELINK_STATIC_LIBRARY; - - CUtlString szOutputDir = linker->Link(&ldProject); - - ADD_OUTPUT_OBJECT("tier1", szOutputDir) - - return 0; -}; diff --git a/tier1/interface.cpp b/tier1/interface.cpp deleted file mode 100644 index 286e737..0000000 --- a/tier1/interface.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "tier1/interface.h" -#include "tier1/utlvector.h" -#include "tier1/utlstring.h" -#include "dlfcn.h" - -static CInterfaceRegistry *s_pInterfaceRegistries; - -CInterfaceRegistry::CInterfaceRegistry( InstantiateInterfaceFn fn, const char *szName ) - : m_szName(szName) -{ - m_CreateFn = fn; - m_pNext = s_pInterfaceRegistries; - s_pInterfaceRegistries = this; - Dl_info info = {}; - dladdr((void *)&s_pInterfaceRegistries, &info); - //printf("%p: %s in %s\n",&s_pInterfaceRegistries, m_szName, info.dli_fname); -}; - -DLL_EXPORT void *CreateInterface( const char *szName, int *pReturnCode ) -{ - CInterfaceRegistry *pRegistry = s_pInterfaceRegistries; - while (pRegistry) - { - if (!V_strcmp(szName, pRegistry->m_szName)) - { - if (pReturnCode) - *pReturnCode = 0; - return pRegistry->m_CreateFn(); - } - pRegistry = pRegistry->m_pNext; - } - if (pReturnCode) - *pReturnCode = 1; - return 0; -} - -CreateInterfaceFn Sys_GetFactory( void *lib ) -{ - return (CreateInterfaceFn)Plat_GetProc(lib, "CreateInterface"); -} -CreateInterfaceFn Sys_GetFactory( const char *szLibrary ) -{ - void *pLib = NULL; - CUtlString szLib = szLibrary; -#if defined(__linux) - szLib = CUtlString("lib%s.so", szLib.GetFileName().GetString()); - pLib = Plat_LoadLibrary(szLib); -#endif - if ( !pLib ) - return NULL; - return Sys_GetFactory(pLib); -} diff --git a/tier1/utlbuffer.cpp b/tier1/utlbuffer.cpp deleted file mode 100644 index 4c24633..0000000 --- a/tier1/utlbuffer.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "tier1/utlbuffer.h" \ No newline at end of file diff --git a/tier1/utlmap.cpp b/tier1/utlmap.cpp deleted file mode 100644 index 64d632c..0000000 --- a/tier1/utlmap.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "tier1/utlmap.h" \ No newline at end of file diff --git a/tier1/utlmutex.cpp b/tier1/utlmutex.cpp deleted file mode 100644 index 8844e28..0000000 --- a/tier1/utlmutex.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "tier1/utlmutex.h" -#include "pthread.h" - -CUtlLock::CUtlLock() -{ - pthread_mutex_init(&m_lock); -}; - -CUtlLock::~CUtlLock() -{ - -}; - -void CUtlLock::Lock() -{ - -}; - -void CUtlLock::Unlock() -{ - -}; diff --git a/tier1/utlstring.cpp b/tier1/utlstring.cpp deleted file mode 100644 index 18a3f95..0000000 --- a/tier1/utlstring.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "tier1/utlstring.h" - diff --git a/tier1/utlvector.cpp b/tier1/utlvector.cpp deleted file mode 100644 index 5af842f..0000000 --- a/tier1/utlvector.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "tier1/utlvector.h" \ No newline at end of file diff --git a/tier2/__build.cpp b/tier2/__build.cpp deleted file mode 100644 index bbb42ee..0000000 --- a/tier2/__build.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "helper.h" -#include "c.h" -#include "ld.h" -#include "tier1/utlstring.h" -#include "tier1/commandline.h" - -CUtlVector tier2_CompiledFiles = { - "fileformats/ini.cpp", - "fileformats/json.cpp", - "filesystem.cpp", - "filesystem_libc.cpp", -}; -CUtlString tier2_lib; - -DECLARE_BUILD_STAGE(tier2) -{ - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - - compileProject.m_szName = "tier2"; - compileProject.files = tier2_CompiledFiles; - compileProject.includeDirectories = all_IncludeDirectories; - compileProject.bFPIC = true; - ldProject = ccompiler->Compile(&compileProject); - ldProject.linkType = ELINK_STATIC_LIBRARY; - - CUtlString outputProject = linker->Link(&ldProject); - tier2_lib = outputProject; - - return 0; -}; diff --git a/tier2/build.cpp b/tier2/build.cpp deleted file mode 100644 index 3cd95df..0000000 --- a/tier2/build.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "helper.h" -#include "c.h" -#include "ld.h" -#include "tier1/utlstring.h" - -CUtlVector tier2_CompiledFiles = { - "fileformats/ini.cpp", - "fileformats/json.cpp", - "fileformats/xml.cpp", - "fileformats/plist.cpp", - "tokenizer.cpp", - "filesystem.cpp", -}; - - -DECLARE_BUILD_STAGE(tier2) -{ - CProject_t compileProject = {}; - LinkProject_t ldProject = {}; - - compileProject.m_szName = "tier2"; - compileProject.files = tier2_CompiledFiles; - compileProject.includeDirectories = {"../public"}; - compileProject.bFPIC = true; - ldProject = ccompiler->Compile(&compileProject); - ldProject.linkType = ELINK_STATIC_LIBRARY; - - CUtlString szOutputProject = linker->Link(&ldProject); - - ADD_OUTPUT_OBJECT("tier2", szOutputProject) - - return 0; -}; diff --git a/tier2/fileformats/ini.cpp b/tier2/fileformats/ini.cpp deleted file mode 100644 index 33c83cb..0000000 --- a/tier2/fileformats/ini.cpp +++ /dev/null @@ -1,335 +0,0 @@ - -#include "tier2/fileformats/ini.h" -#include "tier0/platform.h" -#include "tier1/utlstring.h" -#include "tier1/utlvector.h" -#include "tier0/lib.h" -#include "tier2/ifilesystem.h" - -enum ESectionType -{ - SECTIONTYPE_STRING, - SECTIONTYPE_BOOLEAN, - SECTIONTYPE_FLOAT, -}; - - -struct SectionData_t -{ - ESectionType m_eSectionType; - CUtlString m_szKey; - - bool m_bData; - float m_fData; - CUtlString m_szData; -}; - -abstract_class CINISection: public IINISection -{ -public: - virtual bool GetBoolValue( const char *szKeyName ) override; - virtual int GetIntValue( const char *szKeyName ) override; - virtual const char *GetStringValue( const char *szKeyName ) override; - virtual CUtlString GetUTLStringValue( const char *szKeyName ) override; - - CUtlVector m_values; - CUtlString m_szSectionName; -}; - -bool CINISection::GetBoolValue( const char *szKeyName ) -{ - -} - -int CINISection::GetIntValue( const char *szKeyName ) -{ - -} - -const char *CINISection::GetStringValue( const char *szKeyName ) -{ - for (auto &value: m_values) - { - if (value->m_szKey == szKeyName) - return value->m_szData; - } - return 0; -} - -CUtlString CINISection::GetUTLStringValue( const char *szKeyName ) -{ - for (auto &value: m_values) - { - if (value->m_szKey == szKeyName) - return value->m_szData; - } - return 0; -} - -class CINIFile: public IINIFile -{ -public: - virtual IINISection *GetSection( const char *szSectionName ) override; - - CUtlVector m_sections; -}; - -IINISection *CINIFile::GetSection( const char *szSectionName ) -{ - for ( auto §ion: m_sections ) - { - if ( section->m_szSectionName == szSectionName ) - return (IINISection*)section; - } - return 0; -} - - -class CINIManager: public IINIManager -{ -public: - virtual IINIFile *ReadFile( const char *psz ) override; - virtual IINIFile *ReadString( const char *psz ) override; - virtual void ReleaseFile( IINIFile *pFile ) override; - bool IsWordSymbol( char c ); - CUtlVector TokenizeString(); -}; -IINIFile *CINIManager::ReadFile( const char *psz ) -{ - IFileHandle *pFile; - const char *szData; - - pFile = filesystem->Open(psz, FILEMODE_READ); - if (!pFile) - return NULL; - szData = filesystem->ReadString(pFile); - filesystem->Close(pFile); - - return ReadString(szData); -} - -IINIFile *CINIManager::ReadString( const char *psz ) -{ - CINIFile *pFile = new CINIFile; - *pFile = {}; - bool bIsQuoted = false; - bool bIsSlash = false; - - bool bIsVarName; - bool bIsVarValue; - bool bIsSectionName; - - CINISection *pCurrentSection = 0; - SectionData_t *pCurrentSectionData = 0; - size_t i = 0; - - char c; - - CUtlString szStringValue; - - CUtlVector tokens; - uint32_t nCurrentLine = 0; - - while (true) - { - c = psz[i]; - i++; - if (c == '\0') - break; - if (c == '\n') - nCurrentLine++; - - - if (bIsQuoted) - { - // text within "" - if (bIsSlash) - { - // reading \n \t etc. - bIsSlash = false; - switch (c) - { - case '\\': - szStringValue.AppendTail('\\'); - continue; - case '"': - szStringValue.AppendTail('"'); - continue; - case 'n': - szStringValue.AppendTail('\n'); - continue; - case 't': - szStringValue.AppendTail('\t'); - continue; - // allow for strings to go to next line with by ending with backward slash - case '\n': - szStringValue.AppendTail('\n'); - continue; - default: - szStringValue.AppendTail(c); - continue; - } - } else { - // react to special symbols witin a string - switch (c) - { - - // enables reading \n \t etc. - case '\\': - bIsSlash = true; - continue; - - case '\n': - // newline - // we do want to end it to prevent parsing errors - // and there is no standart - V_printf("line %i: new line was found but the string wasn't finished, did you forget to place \" in the end of the line?\n", nCurrentLine); - case '"': - // end string - bIsQuoted = false; - if (szStringValue == 0) - continue; - tokens.AppendTail(szStringValue); - szStringValue = 0; - continue; - default: - szStringValue.AppendTail(c); - continue; - } - } - - } else { - // " makes it use a string - if (c == '"') - { - bIsQuoted = true; - } - - if (IsWordSymbol(c)) - { - szStringValue.AppendTail(c); - continue; - } else { - if (szStringValue != 0) - tokens.AppendTail(szStringValue); - szStringValue = 0; - if (V_isgraph(c) && c != '"') - tokens.AppendTail(CUtlString("%c", c)); - } - } - }; - - - // tokenize - // shitty tokenize - // must be reworked - for ( int i = 0; i < tokens.GetSize(); i++ ) - { - if (tokens[i] == "]") - { - V_printf("Error: unexpected ]\n"); - return pFile; - } - if (tokens[i] == "[") - { - i++; - if (i>=tokens.GetSize()) - { - V_printf("Error: Trailing section start\n"); - return pFile; - } - - pCurrentSection = (CINISection*)pFile->GetSection(tokens[i]); - if (!pCurrentSection) - { - pCurrentSection = new CINISection; - *pCurrentSection = {}; - pFile->m_sections.AppendTail(pCurrentSection); - } - pCurrentSection->m_szSectionName = tokens[i]; - - i++; - if (i>=tokens.GetSize()) - { - V_printf("Error: Trailing section name\n"); - return pFile; - } - if (tokens[i] != "]") - { - V_printf("Error: expected ]\n"); - return pFile; - } - continue; - } - if (!pCurrentSection) - { - V_printf("Error: section wasn't specified\n"); - return pFile; - } - if (tokens[i] == "=") - { - V_printf("Error: expected key\n"); - return pFile; - } - - pCurrentSectionData = new SectionData_t; - pCurrentSectionData->m_eSectionType = SECTIONTYPE_STRING; - pCurrentSectionData->m_szKey = tokens[i]; - - i++; - if (i>=tokens.GetSize()) - { - V_printf("Error: trailing key\n"); - delete pCurrentSectionData; - return pFile; - } - if (tokens[i] != "=") - { - V_printf("Error: expected =\n"); - delete pCurrentSectionData; - return pFile; - } - - i++; - - if (i>=tokens.GetSize()) - { - V_printf("Error: expected value\n"); - delete pCurrentSectionData; - return pFile; - } - pCurrentSectionData->m_szData = tokens[i]; - - pCurrentSection->m_values.AppendTail(pCurrentSectionData); - } - return (IINIFile*)pFile; -} - -void CINIManager::ReleaseFile( IINIFile *pFile ) -{ - delete (CINIFile*)pFile; -} - -bool CINIManager::IsWordSymbol( char c ) -{ - if (V_isalnum(c)) - return true; - switch (c) - { - case '-': - case '_': - case '.': - return true; - default: - return false; - } -} - -CUtlVector TokenizeString(); - -IINIManager *INIManager() -{ - static CINIManager manager; - return &manager; -} - diff --git a/tier2/fileformats/json.cpp b/tier2/fileformats/json.cpp deleted file mode 100644 index f183c4d..0000000 --- a/tier2/fileformats/json.cpp +++ /dev/null @@ -1,559 +0,0 @@ -#include "tier2/fileformats/json.h" -#include "tier2/tokenizer.h" - -abstract_class CJSONArray: public IJSONArray -{ -public: - virtual uint32_t GetCount() override; - virtual IJSONValue *GetParameter( uint32_t i ) override; - - virtual void SetArray( uint32_t uCount, IJSONValue **ppValues ) override; - - virtual void CopyTo( IJSONArray *pObject ) override; - virtual void Free() override; - - CUtlVector m_values; -}; - -uint32_t CJSONArray::GetCount() -{ - return m_values.GetSize(); -} - -IJSONValue *CJSONArray::GetParameter( uint32_t i ) -{ - return m_values[i]; -} - - -void CJSONArray::SetArray( uint32_t uCount, IJSONValue **ppValues ) -{ - m_values.Resize(uCount); - for ( uint32_t u = 0; u < uCount; u++) - m_values[u] = ppValues[u]; -} - -void CJSONArray::CopyTo( IJSONArray *pObject ) -{ - -} - -void CJSONArray::Free() -{ - for ( auto &value: m_values) - JSONManager()->FreeValue(value); - m_values = {}; -} - -abstract_class CJSONValue: public IJSONValue -{ -public: - virtual EJSONParameterType GetType( void ) override; - virtual const char *GetStringValue() override; - virtual float GetNumberValue() override; - virtual bool GetBooleanValue() override; - virtual IJSONArray *GetArray() override; - virtual IJSONObject *GetObject() override; - - virtual void MakeNULL() override; - virtual void SetStringValue( const char *szString ) override; - virtual void SetNumberValue( float fValue ) override; - virtual void SetBooleanValue( bool bValue ) override; - virtual void SetArrayValue( IJSONArray *pValue ) override; - virtual void SetObjectValue( IJSONObject *pValue ) override; - - virtual void CopyTo( IJSONValue *pObject ) override; - virtual void Free() override; - - EJSONParameterType m_eType; - CUtlString m_szString; - float m_fValue; - bool m_bValue; - IJSONArray *m_pArray; - IJSONObject *m_pObject; -}; - -EJSONParameterType CJSONValue::GetType( void ) -{ - return m_eType; -} - -const char * CJSONValue::GetStringValue() -{ - return m_szString; -} - -float CJSONValue::GetNumberValue() -{ - return m_fValue; -} - -bool CJSONValue::GetBooleanValue() -{ - return m_fValue; -} - -IJSONArray *CJSONValue::GetArray() -{ - return m_pArray; -} - -IJSONObject *CJSONValue::GetObject() -{ - return m_pObject; -} - - -void CJSONValue::MakeNULL() -{ - if ( GetType() == JSON_PARAMETER_OBJECT ) - { - JSONManager()->FreeObject(m_pObject); - m_pObject = NULL; - } - if ( GetType() == JSON_PARAMETER_ARRAY ) - { - - JSONManager()->FreeArray(m_pArray); - m_pArray = NULL; - } - if ( GetType() == JSON_PARAMETER_STRING ) - m_szString = NULL; -} - -void CJSONValue::SetStringValue( const char *szString ) -{ - MakeNULL(); - m_eType = JSON_PARAMETER_STRING; - m_szString = szString; -} - -void CJSONValue::SetNumberValue( float fValue ) -{ - MakeNULL(); - m_eType = JSON_PARAMETER_NUMBER; - m_fValue = fValue; -} - -void CJSONValue::SetBooleanValue( bool bValue ) -{ - MakeNULL(); - m_eType = JSON_PARAMETER_BOOLEAN; -} - -void CJSONValue::SetArrayValue( IJSONArray *pValue ) -{ - MakeNULL(); - m_eType = JSON_PARAMETER_ARRAY; - m_pArray = pValue; -} - -void CJSONValue::SetObjectValue( IJSONObject *pValue ) -{ - MakeNULL(); - m_eType = JSON_PARAMETER_OBJECT; - m_pObject = pValue; -} - - -void CJSONValue::CopyTo( IJSONValue *pObject ) -{ - MakeNULL(); -} - -void CJSONValue::Free() -{ - MakeNULL(); -} - - -abstract_class CJSONObject: public IJSONObject -{ -public: - virtual IJSONValue *GetValue( const char *szName ) override; - virtual void SetValue( const char *szName, IJSONValue *pValue ) override; - - virtual void CopyTo( IJSONObject *pObject ) override; - virtual void Free() override; - - struct JSONObjectParam_t - { - CUtlString m_szName; - IJSONValue *m_pValue; - }; - CUtlVector m_params; -}; - -IJSONValue *CJSONObject::GetValue( const char *szName ) -{ - int i; - JSONObjectParam_t *pParam; - for ( i = 0; i < m_params.GetSize(); i++ ) - { - if ( m_params[i].m_szName != szName ) - continue; - return m_params[i].m_pValue; - } - return NULL; - -} - -void CJSONObject::SetValue( const char *szName, IJSONValue *pValue ) -{ - int i; - JSONObjectParam_t *pParam; - for ( i = 0; i < m_params.GetSize(); i++ ) - { - if ( m_params[i].m_szName != szName ) - continue; - - - // Scary - if ( pValue == NULL ) - m_params.RemoveAt(i); - else - m_params[i].m_pValue = pValue; - return; - } - if ( pValue == NULL ) - return; - m_params.AppendTail({szName, pValue}); -} - - -void CJSONObject::CopyTo( IJSONObject *pObject ) -{ - -} - -void CJSONObject::Free() -{ - for ( auto ¶m: m_params ) - { - JSONManager()->FreeValue(param.m_pValue); - } -} - -abstract_class CJSONManager: public IJSONManager -{ -public: - virtual IJSONObject *CreateObject( ) override; - virtual void FreeObject( IJSONObject *pObject ) override; - virtual IJSONArray *CreateArray( ) override; - virtual void FreeArray( IJSONArray *pArray ) override; - virtual IJSONValue *CreateValue( ) override; - virtual void FreeValue( IJSONValue *pValue ) override; - - virtual IJSONValue *ReadString( const char *szString ) override; - virtual CUtlString WriteString( IJSONValue *pValue ) override; - -private: - CUtlString RealWriteString( IJSONValue *pValue, uint32_t uOffest ); - CUtlString GetAsJsonString( CUtlString szString ); - - static bool ExpectedToken( Token_t &token, const char *szValue ); - static CUtlString GetQuotedToken( Token_t &token ); - IJSONObject *ParseObject( Token_t *&pToken, const Token_t *pEnding ); - IJSONArray *ParseArray( Token_t *&pToken, const Token_t *pEnding ); - IJSONValue *ParseValue( Token_t *&pToken, const Token_t *pEnding ); -}; - -IJSONObject *CJSONManager::CreateObject( ) -{ - return new CJSONObject; -} - -void CJSONManager::FreeObject( IJSONObject *pObject ) -{ - pObject->Free(); - delete (CJSONObject*)pObject; -} - -IJSONArray *CJSONManager::CreateArray( ) -{ - return new CJSONArray; -} - -void CJSONManager::FreeArray( IJSONArray *pArray ) -{ - pArray->Free(); - delete (CJSONObject*)pArray; -} - -IJSONValue *CJSONManager::CreateValue( ) -{ - return new CJSONValue; -} - -void CJSONManager::FreeValue( IJSONValue *pValue ) -{ - pValue->Free(); - delete (CJSONValue*)pValue; -} - -#define NEXT_TOKEN() \ -pToken++; \ -if (pToken == pEnding) \ - goto eof \ - -bool CJSONManager::ExpectedToken( Token_t &token, const char *szValue ) -{ - if ( token.m_szValue == szValue && !token.m_bIsQuoted ) - return true; - return false; -} -CUtlString CJSONManager::GetQuotedToken( Token_t &token ) -{ - if ( token.m_bIsQuoted ) - return token.m_szValue; - return NULL; -} - -IJSONObject *CJSONManager::ParseObject( Token_t *&pToken, const Token_t *pEnding ) -{ - IJSONObject *pObject; - CUtlString szParamName; - IJSONValue *pValue; - - if ( !ExpectedToken(*(pToken), "{") ) - return NULL; - NEXT_TOKEN(); - pObject = CreateObject(); - - // object might be empty - if ( ExpectedToken(*pToken, "}") ) - { - NEXT_TOKEN(); - return pObject; - } - - while(true) - { - szParamName = NULL; - pValue = NULL; - if ( GetQuotedToken(*pToken) == NULL ) - goto not_quoted; - - szParamName = pToken->m_szValue; - NEXT_TOKEN(); - - if ( !ExpectedToken(*pToken, ":") ) - goto not_colon; - NEXT_TOKEN(); - - pValue = ParseValue(pToken, pEnding); - pObject->SetValue(szParamName, pValue); - - if ( !ExpectedToken(*pToken, ",") ) - { - if ( !ExpectedToken(*pToken, "}") ) - { - goto not_comma; - } - return pObject; - } - NEXT_TOKEN(); - } - return pObject; -not_comma: - V_printf("%i: comma (,) or } was expected but got %s\n", pToken->m_iLine, pToken->m_szValue.GetString()); - return NULL; -not_colon: - V_printf("%i: colon (:) was expected but got %s\n", pToken->m_iLine, pToken->m_szValue.GetString()); - return NULL; - -not_quoted: - V_printf("%s was not quoted\n", szParamName.GetString()); - return NULL; - -eof: - V_printf("EOF\n"); - return NULL; -} - -IJSONArray *CJSONManager::ParseArray( Token_t *&pToken, const Token_t *pEnding ) -{ - IJSONArray *pObject; - CUtlString szParamName; - IJSONValue *pValue; - CUtlVector values; - - if ( !ExpectedToken(*(pToken), "[") ) - return NULL; - NEXT_TOKEN(); - pObject = CreateArray(); - - // object might be empty - if ( ExpectedToken(*pToken, "]") ) - { - NEXT_TOKEN(); - return pObject; - } - - while(true) - { - pValue = ParseValue(pToken, pEnding); - values.AppendTail(pValue); - - if ( !ExpectedToken(*pToken, ",") ) - { - if ( !ExpectedToken(*pToken, "]") ) - { - goto not_comma; - } - - pObject->SetArray(values.GetSize(), values.GetData()); - return pObject; - } - NEXT_TOKEN(); - } - return pObject; -not_comma: - V_printf("%i: comma (,) or } was expected but got %s\n", pToken->m_iLine, pToken->m_szValue.GetString()); - return NULL; - -eof: - V_printf("EOF\n"); - pObject->SetArray(values.GetSize(), values.GetData()); - return pObject; -} - -IJSONValue *CJSONManager::ParseValue( Token_t *&pToken, const Token_t *pEnding ) -{ - IJSONObject *pObject = ParseObject(pToken, pEnding); - IJSONArray *pArray = ParseArray(pToken, pEnding); - IJSONValue *pValue = CreateValue(); - if (pObject) - { - pValue->SetObjectValue(pObject); - return pValue; - } - if (pArray) - { - pValue->SetArrayValue(pArray); - return pValue; - } - if ( GetQuotedToken(*pToken) != NULL ) - { - pValue->SetStringValue(pToken->m_szValue); - NEXT_TOKEN(); - return pValue; - } - return NULL; -eof: - V_printf("EOF\n"); - return NULL; -} - - -IJSONValue *CJSONManager::ReadString( const char *psz ) -{ - CUtlVector tokens; - CUtlVector stack; - IJSONValue *pGlobalObject = NULL; - - tokens = Tokenize(psz); - Token_t *pCurrentToken = tokens.GetData(); - pGlobalObject = ParseValue(pCurrentToken, tokens.end().m_pCurrent); - - return pGlobalObject; -}; - -CUtlString CJSONManager::WriteString( IJSONValue *pValue ) -{ - return RealWriteString(pValue, 0); -} -CUtlString CJSONManager::GetAsJsonString( CUtlString szString ) -{ - CUtlString szOut = "\""; - for ( int i = 0; i < szString.GetLenght(); i++ ) - { - char c = szString[i]; - switch (c) - { - case '\"': - szOut.AppendTail("\\\""); - break; - case '\n': - szOut.AppendTail("\\n"); - break; - case '\r': - szOut.AppendTail("\\r"); - break; - case '\t': - szOut.AppendTail("\\t"); - break; - case '\\': - szOut.AppendTail("\\\\"); - break; - default: - szOut.AppendTail(c); - break; - } - }; - szOut.AppendTail("\""); - return szOut; -} - -CUtlString CJSONManager::RealWriteString( IJSONValue *pValue, uint32_t uOffset ) -{ - IJSONArray *pArray; - CJSONObject *pObject; - CUtlString szString = ""; - if (pValue) - switch (pValue->GetType()) - { - case JSON_PARAMETER_NULL: - return CUtlString("null", pValue->GetNumberValue()); - case JSON_PARAMETER_BOOLEAN: - if (pValue->GetBooleanValue()) - return "true"; - return "false"; - case JSON_PARAMETER_NUMBER: - return CUtlString("%f", pValue->GetNumberValue()); - case JSON_PARAMETER_STRING: - return GetAsJsonString(pValue->GetStringValue()); - case JSON_PARAMETER_ARRAY: - pArray = pValue->GetArray(); - szString.AppendTail("[\n"); - for ( uint32_t i = 0; i < pArray->GetCount(); i++ ) - { - for ( uint32_t j = 0; j <= uOffset; j++) - szString.AppendTail("\t"); - szString.AppendTail(RealWriteString( pArray->GetParameter(i), uOffset+1 )); - if ( i != pArray->GetCount() - 1 ) - szString.AppendTail(","); - szString.AppendTail("\n"); - } - for ( uint32_t j = 0; j < uOffset; j++) - szString.AppendTail("\t"); - szString.AppendTail("]"); - return szString; - case JSON_PARAMETER_OBJECT: - pObject = (CJSONObject*)pValue->GetObject(); - szString.AppendTail("{\n"); - for ( uint32_t i = 0; i < pObject->m_params.GetSize(); i++ ) - { - for ( uint32_t j = 0; j <= uOffset; j++) - szString.AppendTail("\t"); - - szString.AppendTail(GetAsJsonString(pObject->m_params[i].m_szName)); - szString.AppendTail(": "); - - szString.AppendTail(RealWriteString( pObject->m_params[i].m_pValue, uOffset+1 )); - if ( i != pObject->m_params.GetSize() - 1 ) - szString.AppendTail(","); - szString.AppendTail("\n"); - } - for ( uint32_t j = 0; j < uOffset; j++) - szString.AppendTail("\t"); - szString.AppendTail("}"); - return szString; - } -} - -IJSONManager *JSONManager() -{ - static CJSONManager mgr; - return &mgr; -} diff --git a/tier2/fileformats/plist.cpp b/tier2/fileformats/plist.cpp deleted file mode 100644 index 039a823..0000000 --- a/tier2/fileformats/plist.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "tier2/fileformats/xml.h" -#include "tier2/fileformats/plist.h" - -class CPropertyListManager: public IPropertyListManager -{ -public: - IJSONObject *ReadDict( IXMLObject *pDict ); - virtual IJSONObject *ReadString( const char *psz ) override; -}; - -IJSONObject *CPropertyListManager::ReadString( const char *psz ) -{ - XMLFile_t file = XMLManager()->ReadString(psz); - IJSONObject *pObject; - - IXMLObject *pList = file.m_pRoot->FindFirstTag(file.m_szRootObjectName); - if (pList == NULL) - return NULL; - - IXMLObject *pDict = pList->FindFirstTag("dict"); - if (pDict == NULL) - return NULL; - - - pObject = ReadDict(pDict); - return pObject; -} -IJSONObject *CPropertyListManager::ReadDict( IXMLObject *pDict ) -{ - CUtlString szKeyToCreate = NULL; - IJSONObject *pObject = JSONManager()->CreateObject(); - for ( auto &c: pDict->GetChildren() ) - { - if (c->GetType() != XML_OBJECT_ELEMENT) - continue; - if ( !V_strcmp(c->GetValue(), "key")) - { - szKeyToCreate = c->GetChildren()[0]->GetValue(); - } - if ( !V_strcmp(c->GetValue(), "string") || !V_strcmp(c->GetValue(), "data") ) - { - if ( szKeyToCreate == NULL ) - continue; - IJSONValue *pVal = JSONManager()->CreateValue(); - if (c->GetChildren().GetSize()>0) - pVal->SetStringValue(c->GetChildren()[0]->GetValue()); - else - pVal->SetStringValue(""); - pObject->SetValue(szKeyToCreate, pVal); - szKeyToCreate = NULL; - } - if ( !V_strcmp(c->GetValue(), "integer") ) - { - if ( szKeyToCreate == NULL ) - continue; - IJSONValue *pVal = JSONManager()->CreateValue(); - if (c->GetChildren().GetSize()>0) - pVal->SetNumberValue(atol(c->GetChildren()[0]->GetValue())); - else - pVal->SetNumberValue(0); - pObject->SetValue(szKeyToCreate, pVal); - szKeyToCreate = NULL; - } - if ( !V_strcmp(c->GetValue(), "dict")) - { - if ( szKeyToCreate == NULL ) - continue; - IJSONValue *pVal = JSONManager()->CreateValue(); - pVal->SetObjectValue(ReadDict(c)); - pObject->SetValue(szKeyToCreate, pVal); - szKeyToCreate = NULL; - } - } - return pObject; -} - -IPropertyListManager *PropertyListManager() -{ - static CPropertyListManager mgr = {}; - return &mgr; -} diff --git a/tier2/fileformats/xml.cpp b/tier2/fileformats/xml.cpp deleted file mode 100644 index d3cc753..0000000 --- a/tier2/fileformats/xml.cpp +++ /dev/null @@ -1,420 +0,0 @@ -#include "tier2/fileformats/xml.h" -#include "tier2/tokenizer.h" - -class CXMLObject: public IXMLObject -{ -public: - virtual EXMLObjectType GetType() override; - virtual const char *GetValue() override; - virtual void SetType( EXMLObjectType eType ) override; - virtual void SetValue( const char *psz ) override; - virtual CUtlVector &GetChildren() override; - virtual CUtlVector &GetParams() override; - virtual void Free() override; - - EXMLObjectType m_eType; - CUtlString m_szValue; - CUtlVector m_children; - CUtlVector m_params; -}; - -EXMLObjectType CXMLObject::GetType() -{ - return m_eType; -} - -const char *CXMLObject::GetValue() -{ - return m_szValue.GetString(); -} - -void CXMLObject::SetType( EXMLObjectType eType ) -{ - m_eType = eType; -} - -void CXMLObject::SetValue( const char *psz ) -{ - m_szValue = psz; -} - - -CUtlVector &CXMLObject::GetChildren() -{ - return m_children; -} - -CUtlVector &CXMLObject::GetParams() -{ - return m_params; -} - -void CXMLObject::Free() -{ - -} - - -class CXMLManager: public IXMLManager -{ -public: - virtual XMLFile_t ReadString( const char *szData ) override; - virtual CUtlString WriteString( IXMLObject *pObject ) override; - - virtual IXMLObject *CreateObject() override; - virtual void FreeObject( IXMLObject *pObject ) override; - - IXMLObject *ReadTagParams( CUtlString szTag ); - XMLFile_t ReadDoctype( const char *szData ); - - bool BIsValidAtStart( char c ); - bool BIsValidAtMid( char c ); - void SkipWhiteSpaces( const char *&psz ); -}; - -static char XML_TAG[] = "<"; -static char XML_TAG_END[] = ">"; -static char XML_SELF_CLOSE_END[] = "/>"; -static char XML_CLOSE_TAG[] = ""; - -XMLFile_t CXMLManager::ReadString( const char *szString ) -{ - CUtlString szTagStack = {}; - CUtlString szRootObjectName; - IXMLObject *pRootObject = CreateObject(); - IXMLObject *pLastObject = pRootObject; - CUtlVector stack = {pRootObject}; - - enum EXMLParsingMode - { - XML_PARSING_MODE_TEXT, - XML_PARSING_MODE_PREPROCESS_TAG, - XML_PARSING_MODE_TAG, - XML_PARSING_MODE_CLOSE_TAG, - XML_PARSING_MODE_DOCTYPE, - XML_PARSING_MODE_COMMENT, - } eMode = XML_PARSING_MODE_TEXT; - - const char *psz = szString; - CUtlString szTag = ""; - CUtlString szText = ""; - XMLFile_t stFile = {}; - while (*psz) - { - switch (eMode) - { - case XML_PARSING_MODE_TEXT: - if (!V_strncmp(XML_DOCTYPE, psz, sizeof(XML_DOCTYPE)-1)) - { - psz+=sizeof(XML_DOCTYPE)-1; - szTag = NULL; - - eMode = XML_PARSING_MODE_DOCTYPE; - if (szText != NULL) - { - IXMLObject *pText = CreateObject(); - pText->SetType(XML_OBJECT_TEXT); - pText->SetValue(szText); - pLastObject->GetChildren().AppendTail(pText); - szText = NULL; - } - - break; - } - if (!V_strncmp(XML_PREPROCESSOR_BEGIN, psz, sizeof(XML_PREPROCESSOR_BEGIN)-1)) - { - psz+=sizeof(XML_PREPROCESSOR_BEGIN)-1; - szTag = NULL; - - eMode = XML_PARSING_MODE_PREPROCESS_TAG; - if (szText != NULL) - { - IXMLObject *pText = CreateObject(); - pText->SetType(XML_OBJECT_TEXT); - pText->SetValue(szText); - pLastObject->GetChildren().AppendTail(pText); - szText = NULL; - } - break; - } - if (!V_strncmp(XML_CLOSE_TAG, psz, sizeof(XML_CLOSE_TAG)-1)) - { - psz+=sizeof(XML_CLOSE_TAG)-1; - szTag = NULL; - - eMode = XML_PARSING_MODE_CLOSE_TAG; - if (szText != NULL) - { - IXMLObject *pText = CreateObject(); - pText->SetType(XML_OBJECT_TEXT); - pText->SetValue(szText); - pLastObject->GetChildren().AppendTail(pText); - szText = NULL; - } - break; - } - if (!V_strncmp(XML_TAG, psz, sizeof(XML_TAG)-1)) - { - psz+=sizeof(XML_TAG)-1; - szTag = NULL; - - eMode = XML_PARSING_MODE_TAG; - if (szText != NULL) - { - IXMLObject *pText = CreateObject(); - pText->SetType(XML_OBJECT_TEXT); - pText->SetValue(szText); - pLastObject->GetChildren().AppendTail(pText); - szText = NULL; - } - break; - } - szText.AppendTail(*psz); - psz++; - break; - case XML_PARSING_MODE_PREPROCESS_TAG: - if (!V_strncmp(XML_PREPROCESSOR_END, psz, sizeof(XML_PREPROCESSOR_END)-1)) - { - psz+=sizeof(XML_PREPROCESSOR_END)-1; - eMode = XML_PARSING_MODE_TEXT; - V_printf("preprocess: %s\n", szTag.GetString()); - break; - } - szTag.AppendTail(*psz); - psz++; - break; - case XML_PARSING_MODE_TAG: - if (!V_strncmp(XML_SELF_CLOSE_END, psz, sizeof(XML_SELF_CLOSE_END)-1)) - { - psz+=sizeof(XML_SELF_CLOSE_END)-1; - eMode = XML_PARSING_MODE_TEXT; - IXMLObject *pObject = ReadTagParams(szTag); - pLastObject->GetChildren().AppendTail(pObject); - - break; - } - - if (!V_strncmp(XML_TAG_END, psz, sizeof(XML_TAG_END)-1)) - { - psz+=sizeof(XML_TAG_END)-1; - eMode = XML_PARSING_MODE_TEXT; - IXMLObject *pObject = ReadTagParams(szTag); - stack.AppendTail(pObject); - pLastObject->GetChildren().AppendTail(pObject); - pLastObject = pObject; - break; - } - - szTag.AppendTail(*psz); - psz++; - break; - case XML_PARSING_MODE_CLOSE_TAG: - if (!V_strncmp(XML_TAG_END, psz, sizeof(XML_TAG_END)-1)) - { - psz+=sizeof(XML_TAG_END)-1; - eMode = XML_PARSING_MODE_TEXT; - - - if (!V_strcmp(pLastObject->GetValue(), szTag)) - { - stack.RemoveTail(); - pLastObject = stack[stack.GetSize()-1]; - } - else - V_printf("\"%s\" != \"%s\"\n",pLastObject->GetValue(), szTag.GetString()); - break; - } - szTag.AppendTail(*psz); - psz++; - break; - case XML_PARSING_MODE_DOCTYPE: - if (!V_strncmp(XML_TAG_END, psz, sizeof(XML_TAG_END)-1)) - { - psz+=sizeof(XML_TAG_END)-1; - eMode = XML_PARSING_MODE_TEXT; - - stFile = ReadDoctype(szTag); - break; - } - szTag.AppendTail(*psz); - psz++; - break; - case XML_PARSING_MODE_COMMENT: - break; - }; - }; - stFile.m_pRoot = pRootObject; - return stFile; -} -CUtlString CXMLManager::WriteString( IXMLObject *pObject ) -{ -}; - -IXMLObject *CXMLManager::ReadTagParams( CUtlString szTag ) -{ - const char *psz = szTag; - CUtlVector params; - CUtlString szTagName = NULL; - CUtlString szParamName = NULL; - IXMLObject *pObject = CreateObject(); - // Read tag name - if (!BIsValidAtStart(*psz)) - { - V_printf("tag must start with letter or _"); - FreeObject(pObject); - return NULL; - } - - szTagName.AppendTail(*psz++); - while (BIsValidAtMid(*psz)) - { - szTagName.AppendTail(*psz); - psz++; - } - pObject->SetType(XML_OBJECT_ELEMENT); - pObject->SetValue(szTagName); - - while (*psz) - { - while (V_isspace(*psz)) - { - psz++; - continue; - } - if (*psz && (!V_isalpha(*psz) || *psz == '_')) - { - V_printf("parameter must start with letter or _\n"); - return {}; - } - while (*psz && (*psz != ' ' || *psz != '=')) - { - psz++; - continue; - } - while (V_isspace(*psz)) - { - psz++; - continue; - } - szParamName.AppendTail(*psz); - }; - return pObject; -}; - -static bool XMLGetWordSymbol( char c ) -{ - if (V_isalnum(c)) - return true; - switch(c) - { - case ':': - return true; - case '.': - return true; - case '_': - return true; - case '-': - return true; - default: - break; - } - return false; -}; - -XMLFile_t CXMLManager::ReadDoctype( const char *szData ) -{ - const char *psz = szData; - XMLFile_t stFile = {}; - CUtlString dtdType = NULL; - CUtlVector tokens; - int i = 0; - - if (!V_isspace(*psz)) - return stFile; - - SkipWhiteSpaces(psz); - - tokens = Tokenize(psz, XMLGetWordSymbol); - if ( tokens.GetSize() < i + 1 ) - return stFile; - if ( tokens[i].m_bIsQuoted ) - return stFile; - - stFile.m_szRootObjectName = tokens[i++].m_szValue; - - // parse ddt - if ( tokens.GetSize() < i + 1 ) - return stFile; - - if ( tokens[i].m_szValue == "PUBLIC" && !tokens[i].m_bIsQuoted ) - { - i++; - if ( tokens.GetSize() < i + 2 ) - return stFile; - if (!tokens[i].m_bIsQuoted || !tokens[i+1].m_bIsQuoted) - return stFile; - stFile.m_szFPI = tokens[i++].m_szValue; - stFile.m_szURI = tokens[i++].m_szValue; - } else if ( tokens[i].m_szValue == "SYSTEM" && !tokens[i].m_bIsQuoted ) - { - } else - { - - } - - - - // read root element - return stFile; -} - -bool CXMLManager::BIsValidAtStart( char c ) -{ - if (V_isalpha(c)) - return true; - if (c == '_') - return true; - return false; -} - -bool CXMLManager::BIsValidAtMid( char c ) -{ - if (V_isalnum(c)) - return true; - if (c == '_') - return true; - if (c == '-') - return true; - if (c == '.') - return true; - return false; -} -void CXMLManager::SkipWhiteSpaces( const char *&psz ) -{ - while (V_isspace(*psz)) - { - psz++; - continue; - } -} - -IXMLObject *CXMLManager::CreateObject() -{ - return new CXMLObject; -} - -void CXMLManager::FreeObject( IXMLObject *pObject ) -{ - pObject->Free(); - delete (CXMLObject*)pObject; -} - - -IXMLManager *XMLManager() -{ - static CXMLManager mgr; - return &mgr; -}; diff --git a/tier2/filesystem.cpp b/tier2/filesystem.cpp deleted file mode 100644 index 64c0e18..0000000 --- a/tier2/filesystem.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include "tier2/ifilesystem.h" - -IFileSystem *filesystem; - diff --git a/tier2/tokenizer.cpp b/tier2/tokenizer.cpp deleted file mode 100644 index 07ddd91..0000000 --- a/tier2/tokenizer.cpp +++ /dev/null @@ -1,130 +0,0 @@ -#include "tier2/tokenizer.h" - -static bool IsWordSymbol( char c ) -{ - if (V_isalnum(c)) - return true; - switch (c) - { - case '_': - return true; - default: - return false; - } -} - -CUtlVector Tokenize( const char *psz ) -{ - return Tokenize(psz, IsWordSymbol); -} - -CUtlVector Tokenize( const char *psz, IsAlphabetSymbolFn fnIsAlphabetSymbol ) -{ - CUtlVector tokens = {}; - size_t i = 0; - char c; - uint32_t nCurrentLine = 1; - uint32_t nCurrentCharacter = 0; - uint32_t nStartingCharacter = 0; - bool bIsQuoted = false; - bool bIsSlash = false; - CUtlString szStringValue; - - while (true) - { - c = psz[i]; - if (c == '\0') - break; - if (c == '\n') - { - nCurrentCharacter = 0; - nStartingCharacter = 0; - nCurrentLine++; - } - else - nCurrentCharacter++; - i++; - - - if (bIsQuoted) - { - // text within "" - if (bIsSlash) - { - // reading \n \t etc. - bIsSlash = false; - switch (c) - { - case '\\': - szStringValue.AppendTail('\\'); - continue; - case '"': - szStringValue.AppendTail('"'); - continue; - case 'n': - szStringValue.AppendTail('\n'); - continue; - case 't': - szStringValue.AppendTail('\t'); - continue; - // allow for strings to go to next line with by ending with backward slash - case '\n': - szStringValue.AppendTail('\n'); - continue; - default: - szStringValue.AppendTail(c); - continue; - } - } else { - // react to special symbols witin a string - switch (c) - { - - // enables reading \n \t etc. - case '\\': - bIsSlash = true; - continue; - - case '\n': - // newline - // we do want to end it to prevent parsing errors - // and there is no standart - V_printf("line %i: new line was found but the string wasn't finished, did you forget to place \" in the end of the line?\n", nCurrentLine); - case '"': - // end string - bIsQuoted = false; - if (szStringValue == 0) - continue; - tokens.AppendTail({szStringValue, true, nCurrentLine, nStartingCharacter}); - szStringValue = 0; - continue; - default: - szStringValue.AppendTail(c); - continue; - } - } - - } else { - // " makes it use a string - if (c == '"') - { - bIsQuoted = true; - } - - if (fnIsAlphabetSymbol(c)) - { - szStringValue.AppendTail(c); - continue; - } else { - if (szStringValue != 0) - tokens.AppendTail({szStringValue, false, nCurrentLine, nStartingCharacter}); - - nStartingCharacter = nCurrentCharacter; - szStringValue = 0; - if (V_isgraph(c) && c != '"') - tokens.AppendTail({CUtlString("%c", c), false, nCurrentLine, nStartingCharacter}); - } - } - }; - return tokens; -}; diff --git a/tier2/uuid.cpp b/tier2/uuid.cpp deleted file mode 100644 index e69de29..0000000