21 #include "framework/application.hpp" 23 #include "framework/common.hpp" 24 #include "platform/os.hpp" 25 #include "platform/platform.hpp" 36 LinuxAssetManager::LinuxAssetManager()
41 static const char *exts[] = {
"exe",
"file",
"path/a.out" };
44 string linkPath =
"/proc/";
45 linkPath += to_string(pid);
49 ssize_t ret = readlink(linkPath.c_str(), buf,
sizeof(buf) - 1);
55 auto pos = basePath.find_last_of(
'/');
56 if (pos == string::npos)
59 basePath = basePath.substr(0, pos);
61 LOGI(
"Found application base directory: \"%s\".\n", basePath.c_str());
66 LOGE(
"Could not find application path based on /proc/$pid interface. Will " 67 "use working directory instead.\n");
71 Result LinuxAssetManager::readBinaryFile(
const char *pPath,
void **ppData,
size_t *pSize)
73 auto fullpath = basePath +
"/assets/" + pPath;
74 return AssetManager::readBinaryFile(fullpath.c_str(), ppData, pSize);
83 double OS::getCurrentTime()
86 if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
88 LOGE(
"clock_gettime() failed.\n");
92 return ts.tv_sec + ts.tv_nsec * 1e-9;
95 unsigned OS::getNumberOfCpuThreads()
97 long cpus = sysconf(_SC_NPROCESSORS_ONLN);
100 LOGI(
"Detected %ld CPUs.\n", cpus);
101 return unsigned(cpus);
105 LOGE(
"Failed to detect number of CPUs, assuming 1.\n");
113 int main(
int argc,
char **argv)
115 Platform &platform = Platform::get();
118 LOGE(
"Failed to initialize platform.\n");
125 LOGE(
"Failed to create platform window.\n");
132 LOGE(
"Failed to create application.\n");
138 LOGE(
"Failed to initialize application.\n");
142 vector<VkImage> images;
146 unsigned frameCount = 0;
147 double startTime = OS::getCurrentTime();
149 unsigned maxFrameCount = 0;
150 bool useMaxFrameCount =
false;
153 maxFrameCount = strtoul(argv[1],
nullptr, 0);
154 useMaxFrameCount =
true;
161 while (res == RESULT_ERROR_OUTDATED_SWAPCHAIN)
170 LOGE(
"Unrecoverable swapchain error.\n");
174 app->
render(index, 0.0166f);
178 if (FAILED(res) && res != RESULT_ERROR_OUTDATED_SWAPCHAIN)
182 if (frameCount == 100)
184 double endTime = OS::getCurrentTime();
185 LOGI(
"FPS: %.3f\n", frameCount / (endTime - startTime));
190 if (useMaxFrameCount && (--maxFrameCount == 0))
The Linux asset manager. It is based on regular fopen(), with the exception that all paths passed to ...
The asset manager reads data from a platform specific location. This class is used internally to load...
virtual void terminate()=0
Destructor for the class.
virtual void render(unsigned swapchainIndex, float deltaTime)=0
Render a frame.
virtual void updateSwapchain(const std::vector< VkImage > &backbuffers, const Platform::SwapchainDimensions &dimensions)=0
Called when the swapchain has been initialized.
VulkanApplication is inherited by all samples. The common platform code will run the main loop and ta...
virtual bool initialize(Context *pContext)=0
This function is called when the context is brought up and is the constructor of this class...