Skip to content

Commit a3a3905

Browse files
authored
Merge pull request #9 from simul/teleport
Teleport, Linux improvements.
2 parents bda19e4 + ba5aebf commit a3a3905

63 files changed

Lines changed: 2234 additions & 1716 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/Build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ jobs:
1515

1616
steps:
1717
- name: Clone Platform
18-
uses: actions/checkout@v4
18+
uses: actions/checkout@v6
1919

2020
- name: Update Submodules
2121
run: git submodule update --init --force
2222

2323
- name: Install Vulkan SDK
24-
uses: humbletim/install-vulkan-sdk@v1.1.1
24+
uses: humbletim/install-vulkan-sdk@v1.2
2525
with:
2626
version: 1.3.296.0
2727
cache: true

Applications/Sfx/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,4 @@ if(PLATFORM_WINDOWS OR PLATFORM_LINUX)
5555
VS_DEBUGGER_COMMAND_ARGUMENTS "${SFX_TEST_FILE} -I\"${CMAKE_SOURCE_DIR}/..\" -I\"${SIMUL_PLATFORM_DIR}/CrossPlatform/Shaders\" -o\"${CMAKE_BINARY_DIR}/Platform/shaderbin/$PLATFORM_NAME\" ${TEST_CONFIGS} -l -v ${SFX_TEST_DEFINES}"
5656
)
5757
endif()
58-
if(PLATFORM_LINUX)
59-
target_link_libraries(Sfx c++)
60-
endif()
6158
endif()

Applications/Sfx/Compiler.cpp

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ void ReplaceRegexes(string &src, const std::map<string,string> &replace)
440440
}
441441
static std::map<std::string,std::string> useCompilerPath;
442442

443+
static bool checkedCompilerPath=false;
444+
443445
extern void CalcCompilerPathToUse(const SfxConfig &sfxConfig,const SfxOptions &sfxOptions)
444446
{
445447
std::string usePath="";
@@ -657,7 +659,7 @@ bool RewriteOutput(const SfxConfig &sfxConfig
657659
(*log)<< str.c_str();
658660
return has_errors;
659661
}
660-
662+
#pragma optimize("",off)
661663
bool IsShaderUnchanged(std::string sourceFilename,std::string outputFilename,const std::string &src)
662664
{
663665
if(!std::filesystem::exists(outputFilename))
@@ -676,7 +678,6 @@ bool IsShaderUnchanged(std::string sourceFilename,std::string outputFilename,con
676678
return true;
677679
}
678680

679-
680681
int Compile(std::shared_ptr<ShaderInstance> shaderInstance
681682
,const string &sourceFile
682683
,string targetFile
@@ -869,7 +870,7 @@ int Compile(std::shared_ptr<ShaderInstance> shaderInstance
869870
string src = preamble;
870871
src += sharedSource;
871872
src+=shaderInstance->m_augmentedSource;
872-
ReplaceRegexes(src, sfxConfig.replace);
873+
873874
const char *strSrc=src.c_str();
874875

875876
wstring targetDir=StringToWString(GetDirectoryFromFilename(targetFile));
@@ -893,8 +894,8 @@ int Compile(std::shared_ptr<ShaderInstance> shaderInstance
893894
#else
894895
ofstream ofs(WStringToUtf8(generatedSourceFilename).c_str());
895896
#endif
896-
ofs.write(strSrc, strlen(strSrc));
897-
ofs.close();
897+
ofs.write(strSrc, strlen(strSrc));
898+
ofs.close();
898899
}
899900
#ifdef _MSC_VER
900901
// Now delete the corresponding sdb's
@@ -933,52 +934,52 @@ int Compile(std::shared_ptr<ShaderInstance> shaderInstance
933934
if(!unchanged)
934935
{
935936
compile_command=BuildCompileCommand
936-
(
937-
shaderInstance,
938-
sfxConfig,
939-
sfxOptions,
940-
targetDir,
941-
outputFile,
937+
(
938+
shaderInstance,
939+
sfxConfig,
940+
sfxOptions,
941+
targetDir,
942+
outputFile,
942943
generatedSourceFilename,
943-
t,
944-
pixelOutputFormat
945-
);
946-
// If no compiler provided, we can return now (perhaps we are only interested in
947-
// the shader source)
948-
if (compile_command.empty())
949-
{
950-
if(sfxOptions.verbose)
944+
t,
945+
pixelOutputFormat
946+
);
947+
// If no compiler provided, we can return now (perhaps we are only interested in
948+
// the shader source)
949+
if (compile_command.empty())
950+
{
951+
if(sfxOptions.verbose)
951952
std::cout<<WStringToUtf8(generatedSourceFilename).c_str()<<"\n";
952-
// But let's in that case, wrap up the GENERATED SOURCE in sfxb:
953-
if (sfxOptions.wrapOutput)
954-
{
955-
//concatenate
956-
#ifdef _MSC_VER
953+
// But let's in that case, wrap up the GENERATED SOURCE in sfxb:
954+
if (sfxOptions.wrapOutput)
955+
{
956+
//concatenate
957+
#ifdef _MSC_VER
957958
std::ifstream if_c(generatedSourceFilename.c_str(), std::ios_base::binary);
958-
#else
959+
#else
959960
std::ifstream if_c(WStringToUtf8(generatedSourceFilename).c_str(), std::ios_base::binary);
960-
#endif
961-
if(!if_c.good())
962-
{
963-
SFX_BREAK("Failed to load generated shader source");
964-
exit(1002);
965-
}
966-
std::streampos startp = combinedBinary.tellp();
967-
combinedBinary << if_c.rdbuf();
968-
std::streampos endp = combinedBinary.tellp();
969-
size_t sz=endp - startp;
970-
if(!sz)
971-
{
972-
SFX_BREAK("Empty output shader ");
961+
#endif
962+
if(!if_c.good())
963+
{
964+
SFX_BREAK("Failed to load generated shader source");
965+
exit(1002);
966+
}
967+
std::streampos startp = combinedBinary.tellp();
968+
combinedBinary << if_c.rdbuf();
969+
std::streampos endp = combinedBinary.tellp();
970+
size_t sz=endp - startp;
971+
if(!sz)
972+
{
973+
SFX_BREAK("Empty output shader ");
973974
std::cerr<<"Empty output shader "<<WStringToUtf8(generatedSourceFilename)<<"\n";
974-
exit(1001);
975-
}
976-
binaryMap[sbf] = std::make_tuple(startp, sz);
975+
exit(1001);
977976
}
978-
return true;
977+
binaryMap[sbf] = std::make_tuple(startp, sz);
979978
}
980-
if(sfxOptions.verbose)
981-
std::cout<<WStringToUtf8(compile_command).c_str()<<std::endl;
979+
return true;
980+
}
981+
if(sfxOptions.verbose)
982+
std::cout<<WStringToUtf8(compile_command).c_str()<<std::endl;
982983
}
983984

984985
// Run the provided .exe!
@@ -1036,7 +1037,7 @@ int Compile(std::shared_ptr<ShaderInstance> shaderInstance
10361037
{
10371038
if (terminate_command)
10381039
exit(2000);
1039-
Sleep(10);
1040+
sleep(10);
10401041
}
10411042
if(!if_c.good())
10421043
{

Applications/Sfx/Compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#pragma once
22
#include <string>
33
#include <map>
4+
#include <memory>
45
#include "SfxClasses.h"
56
#include "SfxEffect.h"
67
#include "ShaderInstance.h"
78

9+
extern void ReplaceRegexes(std::string &src, const std::map<std::string,std::string> &replace);
810
extern int Compile(std::shared_ptr<sfx::ShaderInstance> shader, const std::string &sourceFile, std::string targetFile
911
, sfx::ShaderType t
1012
, sfx::PixelOutputFormat pixelOutputFormat

Applications/Sfx/Environ.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ static void SetEnv(const std::string &name_utf8, const std::string &value_utf8)
4242
errno_t err = _wputenv_s(
4343
wname.c_str(),wval.c_str());
4444
#else
45-
char txt[1000];
46-
sprintf(txt,"%s=%s",name_utf8.c_str(),value_utf8.c_str());
47-
putenv(txt);
45+
setenv(name_utf8.c_str(),value_utf8.c_str(),1);
4846
#endif
4947
}
5048

@@ -53,7 +51,6 @@ static void SetEnv(const std::string &name_utf8, const std::string &value_utf8)
5351
static std::string ProcessEnvironmentVariables(const std::string &str)
5452
{
5553
std::string ret=str;
56-
#if defined(WIN32)|| defined(WIN64)
5754
std::regex re("\\$([A-Z|a-z|0-9|_]+)");
5855
std::sregex_iterator next(str.begin(), str.end(), re);
5956
std::sregex_iterator end;
@@ -71,6 +68,5 @@ static std::string ProcessEnvironmentVariables(const std::string &str)
7168
// Syntax error in the regular expression
7269
}
7370
}
74-
#endif
7571
return ret;
7672
}

Applications/Sfx/FileLoader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ void FileLoader::AcquireFileContents(void*& pointer, unsigned int& bytes, const
197197
fclose(fp);
198198
}
199199

200-
uint64_t FileLoader::GetFileDate(const char *filename_utf8)
200+
uint64_t FileLoader::GetFileDateUnixTimeMs(const char *filename_utf8)
201201
{
202202
std::wstring filenamew=StringToWString(filename_utf8);
203203
#ifdef _MSC_VER
@@ -208,7 +208,7 @@ uint64_t FileLoader::GetFileDate(const char *filename_utf8)
208208
stat(filename_utf8, &buf);
209209
#endif
210210
buf.st_mtime;
211-
time_t t = buf.st_mtime;
211+
time_t t = buf.st_mtime*1000;
212212
return static_cast<uint64_t>(t);
213213
}
214214

Applications/Sfx/FileLoader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22
#include <vector>
33
#include <string>
4+
#include <stdint.h>
45
#ifndef _MAX_PATH
56
#define _MAX_PATH 260
67
#endif
@@ -16,7 +17,7 @@ class FileLoader
1617
bool FileExists(const char *filename_utf8) const;
1718
const char *FindFileInPathStack(const char *filename_utf8,const std::vector<std::string> &path_stack_utf8) const;
1819
void AcquireFileContents(void*& pointer, unsigned int& bytes, const char* filename_utf8,bool open_as_text);
19-
static uint64_t GetFileDate(const char* filename_utf8);
20+
static uint64_t GetFileDateUnixTimeMs(const char* filename_utf8);
2021
void ReleaseFileContents(void* pointer);
2122
void Save(void* pointer, unsigned int bytes, const char* filename_utf8,bool save_as_text);
2223
};

Applications/Sfx/Main.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
2-
/* Parts of this program are Copyright (c) 2011, Max Aizenshtein <max.sniffer@gmail.com>
3-
*/
4-
51
#include <stdio.h>
62
#include <vector>
73
#include <iomanip> // for setw
@@ -50,6 +46,7 @@ const SfxOptions &GetSfxOptions()
5046
return sfxOptions;
5147
}
5248
extern bool terminate_command;
49+
#ifdef _MSC_VER
5350
// A ctrl message handler to detect "close" events.
5451
BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
5552
{
@@ -86,13 +83,14 @@ BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
8683
return FALSE;
8784
}
8885
}
86+
#endif
8987
std::string templateOutputFile;
9088
int main(int argc, char** argv)
9189
{
90+
#ifdef _MSC_VER
9291
if (SetConsoleCtrlHandler(CtrlHandler, TRUE))
9392
{
9493
}
95-
#ifdef _MSC_VER
9694
SetErrorMode(SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX | SEM_NOALIGNMENTFAULTEXCEPT);
9795
_set_abort_behavior(0, _WRITE_ABORT_MSG);
9896
#endif
@@ -127,6 +125,8 @@ int main(int argc, char** argv)
127125
int a=0;
128126
for(int i=1;i<argc;i++)
129127
{
128+
while(argv[i][0]==' ')
129+
argv[i]++;
130130
if(strlen(argv[i])>=2&&(argv[i][0]=='-'))
131131
{
132132
const char *arg=argv[i]+2;
@@ -241,6 +241,7 @@ int main(int argc, char** argv)
241241
}
242242
std::cout << std::setw(4)<< "info: building "<<sourceName<<" for "<<platformName<<"."<< std::endl;
243243
SetEnv("PLATFORM_DIR",platform_dir.c_str());
244+
std::cout<<"\n"<<GetEnv("BUILD_DIR")<<std::endl;
244245
auto pathStrings=genericPathStrings;
245246
pathStrings.push_back(json_path);
246247
pathStrings.push_back(platform_dir+"/Shaders/SL"s);

Applications/Sfx/Preprocessor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <vector>
55
#include <string>
66
#include <map>
7+
#include <stdint.h>
78
enum Test
89
{
910
IS_DEFINED,NOT_DEFINED,ZERO,NONZERO,EQUALS,NOTEQUAL,GREATER,LESS,GREATER_EQUAL,LESS_EQUAL

Applications/Sfx/Sfx.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ typedef int errno_t;
5959
#include "SfxClasses.h"
6060
#include "Sfx.h"
6161
#include "SfxEffect.h"
62+
#include "Compiler.h"
6263

6364
#ifdef _MSC_VER
6465
#define YY_NO_UNISTD_H
@@ -106,7 +107,7 @@ FILE* OpenFile(const char *filename_utf8,std::string &fullPathNameUtf8,uint64_t
106107
if(last_slash>0)
107108
path=path.substr(0,last_slash);
108109
shaderPathsUtf8.push_back(path);
109-
datetime=FileLoader::GetFileDate(fullPathNameUtf8.c_str());
110+
datetime=FileLoader::GetFileDateUnixTimeMs(fullPathNameUtf8.c_str());
110111
return f;
111112
}
112113

@@ -513,6 +514,13 @@ std::string GetExecutableDirectory()
513514
}
514515
else
515516
str=L"";
517+
#else
518+
char pBuf[512];
519+
size_t len = sizeof(pBuf);
520+
int bytes = std::min((int)readlink("/proc/self/exe", pBuf, len), (int)len - 1);
521+
if(bytes >= 0)
522+
pBuf[bytes] = '\0';
523+
return std::string(pBuf);
516524
#endif
517525
return WStringToUtf8(str);
518526
}
@@ -602,13 +610,13 @@ bool sfxParseEffectFromFile(int effect, const char *file, const std::vector<std:
602610
readlink("/proc/self/exe",exeNameUtf8,_MAX_PATH);
603611
#endif
604612
// start with the date that this exe was made, so new exe's rebuild the shaders.
605-
uint64_t exe_datetime=FileLoader::GetFileDate(exeNameUtf8);
606-
uint64_t platformfile_datetime=FileLoader::GetFileDate(config->platformFilename.c_str());
613+
uint64_t exe_datetime=FileLoader::GetFileDateUnixTimeMs(exeNameUtf8);
614+
uint64_t platformfile_datetime=FileLoader::GetFileDateUnixTimeMs(config->platformFilename.c_str());
607615
latest_datetime= std::max(exe_datetime,platformfile_datetime);
608616
latest_file=file;
609617
if (!preprocess(file, config->define, sfxOptions->disableLineWrites))
610618
return false;
611-
uint64_t output_filedatetime = FileLoader::GetFileDate(sfxoFilename.c_str());
619+
uint64_t output_filedatetime = FileLoader::GetFileDateUnixTimeMs(sfxoFilename.c_str());
612620
bool recompile=false;
613621
if(sfxOptions->force)
614622
{
@@ -646,9 +654,6 @@ bool sfxParseEffectFromFile(int effect, const char *file, const std::vector<std:
646654
if(sfxOptions->verbose)
647655
{
648656
char buffer[_MAX_PATH];
649-
string wd="";
650-
if(_getcwd(buffer,_MAX_PATH))
651-
wd=string(buffer)+"/";
652657
mkpath(sfxOptions->intermediateDirectory);
653658
ppfile=((string(sfxOptions->intermediateDirectory)+"/")+GetFilenameOnly(file))+"_pp";
654659
ofstream pps(ppfile);

0 commit comments

Comments
 (0)