Skip to content

Commit ebf5c0b

Browse files
author
Roderick Kennedy
committed
Linux support fixes.
1 parent 751d09b commit ebf5c0b

7 files changed

Lines changed: 81 additions & 29 deletions

File tree

Applications/Sfx/Environ.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static void SetEnv(const std::string &name_utf8, const std::string &value_utf8)
5151
static std::string ProcessEnvironmentVariables(const std::string &str)
5252
{
5353
std::string ret=str;
54-
std::regex re("\\$([A-Z|a-z|0-9|_]+)");
54+
std::regex re("[\\$%\\!]([A-Z|a-z|0-9|_]+)");
5555
std::sregex_iterator next(str.begin(), str.end(), re);
5656
std::sregex_iterator end;
5757
while (next != end)
@@ -60,11 +60,12 @@ static std::string ProcessEnvironmentVariables(const std::string &str)
6060
{
6161
std::smatch match = *next;
6262
std::string m=match[1].str();
63-
std::regex re(std::string("\\$")+m);
63+
std::regex re(std::string("[\\$%\\!]")+m);
6464
ret=std::regex_replace(ret,re,GetEnv(m));
6565
next++;
66-
} catch (std::regex_error& )
66+
} catch (std::regex_error& err)
6767
{
68+
std::cerr << "Regex error: " << err.what() << std::endl;
6869
// Syntax error in the regular expression
6970
}
7071
}

Applications/Sfx/Main.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ int main(int argc, char** argv)
115115
std::vector<std::string> platformFilenames;
116116
std::string optimization;
117117
std::vector<std::string> genericPathStrings;
118-
std::string outputFile=templateOutputFile;
119118
std::string intermediateDirectory;
120119
if(argc>1)
121120
{
@@ -125,6 +124,7 @@ int main(int argc, char** argv)
125124
int a=0;
126125
for(int i=1;i<argc;i++)
127126
{
127+
std::cout << "argv[" << i << "] " << argv[i] << std::endl;
128128
while(argv[i][0]==' ')
129129
argv[i]++;
130130
if(strlen(argv[i])>=2&&(argv[i][0]=='-'))
@@ -159,7 +159,9 @@ int main(int argc, char** argv)
159159
platformFilenames.push_back(std::filesystem::weakly_canonical(StripQuotes(arg)).generic_string());
160160
}
161161
else if (argtype == 'o' || argtype == 'O')
162+
{
162163
templateOutputFile = StripQuotes(arg);
164+
}
163165
else if (argtype == 'd' || argtype == 'D')
164166
{
165167
sfxOptions.debugInfo = true;
@@ -193,6 +195,7 @@ int main(int argc, char** argv)
193195
paths[n]=0;
194196
args[a]=0;
195197
}
198+
std::string outputFile=templateOutputFile;
196199
for (auto e : environment)
197200
{
198201
SetEnv(e.first, e.second);
@@ -239,7 +242,6 @@ int main(int argc, char** argv)
239242
break;
240243
}
241244
}
242-
std::cout << std::setw(4)<< "info: building "<<sourceName<<" for "<<platformName<<"."<< std::endl;
243245
SetEnv("PLATFORM_DIR",platform_dir.c_str());
244246
std::cout<<"\n"<<GetEnv("BUILD_DIR")<<std::endl;
245247
auto pathStrings=genericPathStrings;
@@ -320,7 +322,6 @@ int main(int argc, char** argv)
320322
pathStrings.push_back(ProcessPath(ProcessEnvironmentVariables(b)));
321323
}
322324
}
323-
outputFile=templateOutputFile;
324325
if(outputFile.length()==0)
325326
{
326327
if(j.count("outputPath")>0)
@@ -329,15 +330,15 @@ int main(int argc, char** argv)
329330
}
330331
else
331332
{
332-
outputFile ="$BUILD_DIR/Shaders/"+platformName+"/shaderbin"s;
333+
outputFile = "$BUILD_DIR/Shaders/" + platformName + "/shaderbin"s;
333334
}
334335
}
335-
outputFile=ProcessEnvironmentVariables(outputFile);
336-
if(intermediateDirectory.length()==0)
336+
outputFile = ProcessEnvironmentVariables(outputFile);
337+
if (intermediateDirectory.length() == 0)
337338
{
338-
if(j.count("intermediateDirectory")>0)
339+
if (j.count("intermediateDirectory") > 0)
339340
{
340-
sfxOptions.intermediateDirectory =ProcessEnvironmentVariables(j["intermediateDirectory"]);
341+
sfxOptions.intermediateDirectory = ProcessEnvironmentVariables(j["intermediateDirectory"]);
341342
}
342343
else
343344
{
@@ -597,9 +598,8 @@ int main(int argc, char** argv)
597598
}
598599
// write a summary output file, so we have a single output with the build time on it.
599600
SetEnv("PLATFORM_NAME","");
600-
templateOutputFile=ProcessEnvironmentVariables(templateOutputFile);
601601
sourceName = sourceName.replace(sourceName.rfind("."), sourceName.length(), "");
602-
std::string summaryFilename=templateOutputFile+"/"s+sourceName+".sfx_summary";
602+
std::string summaryFilename=ProcessEnvironmentVariables(templateOutputFile)+"/"s+sourceName+".sfx_summary";
603603
if(ret==0)
604604
{
605605
std::ofstream summary(summaryFilename);

CMake/Include.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ function(LibraryDefaults targname)
297297
target_compile_definitions(${targname} PRIVATE PLATFORM_NO_OPTIMIZATION )
298298
elseif(PLATFORM_LINUX)
299299
target_compile_definitions(${targname} PRIVATE "PLATFORM_NO_OPTIMIZATION=__attribute__((optnone))" )
300-
target_compile_options(${targname} PRIVATE -pedantic -Wno-nullability-completeness -Wno-keyword-macro -Wno-ignored-qualifiers -Wno-unused-function -Wno-sign-compare -Wno-gnu-anonymous-struct -Wno-gnu-redeclared-enum -Wno-nested-anon-types -Wno-gnu-zero-variadic-macro-arguments -Wno-unused-parameter -Wno-unused-variable -Wno-unused-value -Wno-missing-braces -Wno-keyword-macro -Wno-language-extension-token -Wno-missing-field-initializers)
300+
target_compile_options(${targname} PRIVATE -pedantic -Wno-nullability-extension -Wno-nullability-completeness -Wno-keyword-macro -Wno-ignored-qualifiers -Wno-unused-function -Wno-sign-compare -Wno-gnu-anonymous-struct -Wno-gnu-redeclared-enum -Wno-nested-anon-types -Wno-gnu-zero-variadic-macro-arguments -Wno-unused-parameter -Wno-unused-variable -Wno-unused-value -Wno-missing-braces -Wno-keyword-macro -Wno-language-extension-token -Wno-missing-field-initializers)
301301
target_compile_options(${targname} PUBLIC -pedantic -Wno-nullability-completeness -Wno-keyword-macro -Wno-ignored-qualifiers -Wno-unused-function -Wno-sign-compare -Wno-gnu-anonymous-struct -Wno-gnu-redeclared-enum -Wno-nested-anon-types -Wno-gnu-zero-variadic-macro-arguments -Wno-unused-parameter -Wno-unused-variable -Wno-unused-value -Wno-missing-braces -Wno-inconsistent-missing-override -Wno-deprecated-declarations)
302302
elseif(PLATFORM_EMSCRIPTEN)
303303
target_compile_definitions(${targname} PRIVATE "PLATFORM_NO_OPTIMIZATION=__attribute__((optnone))" )

CMake/Shader.cmake

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ function ( add_multiplatform_sfx_shader_project targetName )
106106
set(SET_DEFINES -E\"SCE_ORBIS_SDK_DIR=${SCE_ORBIS_SDK_DIR}\" )
107107
string(REPLACE "_MT" "" targetName "${targetName}")
108108
endif()
109-
foreach(opt_d ${sfx_DEFINES})
110-
set(SET_DEFINES "${SET_DEFINES} -E\"${opt_d}\"" )
111-
endforeach()
109+
list(JOIN sfx_DEFINES "\" -E\"" SET_DEFINES)
110+
set(SET_DEFINES "-E\"${SET_DEFINES}\"" )
112111
set(SET_CONFIGS)
113112
if("${sfx_CONFIG_FILES}" STREQUAL "")
114113
foreach(GRAPHICS_API ${PLATFORM_GRAPHICS_APIS})
@@ -123,15 +122,17 @@ function ( add_multiplatform_sfx_shader_project targetName )
123122
foreach(opt_in ${sfx_OPTIONS})
124123
set(EXTRA_OPTS "${EXTRA_OPTS} ${opt_in}" )
125124
endforeach()
125+
126126
set(INCLUDE_OPTS)
127127
foreach(incl_path ${sfx_INCLUDES})
128-
set(INCLUDE_OPTS ${INCLUDE_OPTS} -I"${incl_path}" )
128+
list(APPEND INCLUDE_OPTS "-I${incl_path}")
129129
endforeach()
130+
message(INCLUDE_OPTS ${INCLUDE_OPTS})
130131
if(NOT "${EXTRA_OPTS}" STREQUAL "")
131132
string(REPLACE "\"" "" EXTRA_OPTS ${EXTRA_OPTS})
132133
endif()
133134
set(EXTRA_OPTS "${EXTRA_OPTS} ${SET_DEFINES}")
134-
separate_arguments(EXTRA_OPTS_S WINDOWS_COMMAND "${EXTRA_OPTS}")
135+
separate_arguments(EXTRA_OPTS_S NATIVE_COMMAND "${EXTRA_OPTS}")
135136
if(SIMUL_DEBUG_SHADERS)
136137
set(EXTRA_OPTS_S ${EXTRA_OPTS_S} -v -d)
137138
endif()
@@ -159,13 +160,15 @@ function ( add_multiplatform_sfx_shader_project targetName )
159160
string(REPLACE ".sfx" ".sfxo" out_f ${name})
160161
set(out_f "${out_folder}/${out_f}")
161162
string(REPLACE ".sfxo" ".sfx_summary" main_output_file ${out_f})
162-
#message("add_custom_command sfx_OUTPUT ${sfx_OUTPUT}")
163+
list(JOIN EXTRA_OPTS_S " " EXTRA_OPTS)
164+
# Escape $ for the command line, otherwise CMake will try to expand it as a variable.
165+
string(REPLACE "$" "%" sfx_OUTPUT ${sfx_OUTPUT})
163166
add_custom_command(OUTPUT ${main_output_file}
164-
COMMAND "${this_exe}" ${in_f} ${INCLUDE_OPTS} -O"${sfx_OUTPUT}" ${SET_CONFIGS} ${EXTRA_OPTS_S}
167+
COMMAND ${this_exe} ${in_f} ${INCLUDE_OPTS} -O${sfx_OUTPUT} ${SET_CONFIGS} ${EXTRA_OPTS}
165168
MAIN_DEPENDENCY ${in_f}
166169
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
167170
DEPENDS ${PLATFORM_SFX_EXECUTABLE}
168-
COMMENT "\"${this_exe}\" ${in_f} ${INCLUDE_OPTS} -O\"${sfx_OUTPUT}\" ${SET_CONFIGS} ${EXTRA_OPTS_S}"
171+
COMMENT "\"${this_exe}\" ${in_f} ${INCLUDE_OPTS} -O\"${sfx_OUTPUT}\" ${SET_CONFIGS} ${EXTRA_OPTS}"
169172
#VERBATIM
170173
COMMAND_EXPAND_LISTS
171174
)

Core/BaseMouseHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace platform
2323
Button4 = 8,
2424
Button5 = 16,
2525
};
26-
MouseButtons operator|(MouseButtons a,MouseButtons b)
26+
inline MouseButtons operator|(MouseButtons a,MouseButtons b)
2727
{
2828
return (MouseButtons)((int)a|(int)b);
2929
}

CrossPlatform/RenderPlatform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ RenderPlatform::~RenderPlatform()
102102
while (!(effectCompileThread.joinable() && recompileThreadFinished))
103103
{
104104
}
105-
effectCompileThread.join();
105+
if(effectCompileThread.joinable())
106+
effectCompileThread.join();
106107

107108
allocator.Shutdown();
108109
InvalidateDeviceObjects();

Vulkan/DisplaySurface.cpp

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
#include <linux/input.h>
1010
#endif
1111
#include <vulkan/vulkan.hpp>
12+
13+
// Forward declare GLFW functions for Linux
14+
#ifndef _MSC_VER
15+
extern "C" {
16+
void glfwGetWindowSize(GLFWwindow* window, int* width, int* height);
17+
void glfwGetWindowPos(GLFWwindow* window, int* xpos, int* ypos);
18+
}
19+
#endif
1220
// Careless implementation by Vulkan requires this:
1321
#undef NOMINMAX
1422
// #include <vulkan/vk_sdk_platform.h>
@@ -854,7 +862,6 @@ void DisplaySurface::EndFrame()
854862

855863
void DisplaySurface::Resize()
856864
{
857-
#ifdef _MSC_VER
858865
auto *vulkanDevice = ((vulkan::RenderPlatform *)renderPlatform)->AsVulkanDevice();
859866
auto const fence_ci = vk::FenceCreateInfo().setFlags(vk::FenceCreateFlagBits::eSignaled);
860867
for (uint32_t i = 0; i < swapchain_image_resources.size(); i++)
@@ -863,10 +870,14 @@ void DisplaySurface::Resize()
863870
SIMUL_ASSERT(result == vk::Result::eSuccess);
864871
}
865872

873+
bool regen = false;
874+
uint32_t W = 0;
875+
uint32_t H = 0;
876+
877+
#ifdef _MSC_VER
866878
RECT rect = {};
867879
if (!GetClientRect((HWND)mHwnd, &rect))
868880
return;
869-
bool regen = false;
870881
RECT wrect = {};
871882
if (GetWindowRect((HWND)mHwnd, &wrect))
872883
{
@@ -877,8 +888,45 @@ void DisplaySurface::Resize()
877888
lastWindow.z = wrect.right - wrect.left;
878889
lastWindow.w = wrect.bottom - wrect.top;
879890
}
880-
UINT W = abs(rect.right - rect.left);
881-
UINT H = abs(rect.bottom - rect.top);
891+
W = abs(rect.right - rect.left);
892+
H = abs(rect.bottom - rect.top);
893+
#else
894+
// Linux/GLFW: Get window size from GLFW or use surface capabilities
895+
if (mHwnd)
896+
{
897+
GLFWwindow* glfwWindow = (GLFWwindow*)mHwnd;
898+
int width = 0, height = 0;
899+
glfwGetWindowSize(glfwWindow, &width, &height);
900+
W = (uint32_t)width;
901+
H = (uint32_t)height;
902+
903+
// Check if window position changed
904+
int x = 0, y = 0;
905+
glfwGetWindowPos(glfwWindow, &x, &y);
906+
if (x != lastWindow.x || y != lastWindow.y)
907+
regen = true;
908+
lastWindow.x = x;
909+
lastWindow.y = y;
910+
lastWindow.z = width;
911+
lastWindow.w = height;
912+
}
913+
else
914+
{
915+
// Fallback: use surface capabilities
916+
vk::SurfaceCapabilitiesKHR surfCapabilities;
917+
vk::PhysicalDevice *gpu = GetGPU();
918+
if (gpu && mSurface)
919+
{
920+
auto result = gpu->getSurfaceCapabilitiesKHR(mSurface, &surfCapabilities);
921+
if (result == vk::Result::eSuccess)
922+
{
923+
W = surfCapabilities.currentExtent.width;
924+
H = surfCapabilities.currentExtent.height;
925+
}
926+
}
927+
}
928+
#endif
929+
882930
if (viewport.w != W || viewport.h != H)
883931
regen = true;
884932
if (!regen)
@@ -892,5 +940,4 @@ void DisplaySurface::Resize()
892940
viewport.y = 0;
893941
if (renderer)
894942
renderer->ResizeView(mViewId, W, H);
895-
#endif
896943
}

0 commit comments

Comments
 (0)