Parcourir la source

Move os.h to core

Daniele Bartolini il y a 11 ans
Parent
commit
6a38ea7500

+ 1 - 5
engine/compilers/bundle_compiler.cpp

@@ -66,12 +66,8 @@ bool BundleCompiler::compile(const char* bundle_dir, const char* source_dir, con
 	{
 		BundleCompiler::scan(source_dir, "", files);
 
-		// Create bundle dir if does not exist
 		DiskFilesystem temp;
-		if (!temp.is_directory(bundle_dir) || !temp.is_file(bundle_dir))
-		{
-			temp.create_directory(bundle_dir);
-		}
+		temp.create_directory(bundle_dir);
 
 		// Copy crown.config to bundle dir
 		DiskFilesystem src_fs(source_dir);

+ 15 - 3
engine/core/filesystem/disk_filesystem.cpp

@@ -36,14 +36,13 @@ namespace crown
 //-----------------------------------------------------------------------------
 DiskFilesystem::DiskFilesystem()
 {
-	string::strncpy(m_root_path, os::get_cwd(), MAX_PATH_LENGTH);
+	os::getcwd(m_root_path, MAX_PATH_LENGTH);
 }
 
 //-----------------------------------------------------------------------------
 DiskFilesystem::DiskFilesystem(const char* root_path)
 {
 	CE_ASSERT_NOT_NULL(root_path);
-
 	string::strncpy(m_root_path, root_path, MAX_PATH_LENGTH);
 }
 
@@ -67,6 +66,18 @@ void DiskFilesystem::close(File* file)
 	CE_DELETE(default_allocator(), file);
 }
 
+//-----------------------------------------------------------------------------
+bool DiskFilesystem::exists(const char* path)
+{
+	CE_ASSERT_NOT_NULL(path);
+
+	TempAllocator256 alloc;
+	DynamicString abs_path(alloc);
+	get_absolute_path(path, abs_path);
+
+	return os::exists(abs_path.c_str());
+}
+
 //-----------------------------------------------------------------------------
 bool DiskFilesystem::is_directory(const char* path)
 {
@@ -100,7 +111,8 @@ void DiskFilesystem::create_directory(const char* path)
 	DynamicString abs_path(alloc);
 	get_absolute_path(path, abs_path);
 
-	os::create_directory(abs_path.c_str());
+	if (!os::exists(abs_path.c_str()))
+		os::create_directory(abs_path.c_str());
 }
 
 //-----------------------------------------------------------------------------

+ 3 - 0
engine/core/filesystem/disk_filesystem.h

@@ -59,6 +59,9 @@ public:
 	/// Closes the given @a file.
 	void close(File* file);
 
+	/// Returns whether @a path exists.
+	bool exists(const char* path);
+
 	/// Returns true if @a path is a directory.
 	bool is_directory(const char* path);
 

+ 3 - 0
engine/core/filesystem/filesystem.h

@@ -95,6 +95,9 @@ public:
 	/// Closes the given @a file.
 	virtual void close(File* file) = 0;
 
+	/// Returns whether @a path exists.
+	virtual bool exists(const char* path) = 0;
+
 	/// Returns true if @a path is a directory.
 	virtual bool is_directory(const char* path) = 0;
 

+ 6 - 0
engine/core/filesystem/network_filesystem.cpp

@@ -60,6 +60,12 @@ void NetworkFilesystem::close(File* file)
 	CE_DELETE(default_allocator(), file);
 }
 
+//-----------------------------------------------------------------------------
+bool NetworkFilesystem::exists(const char* path)
+{
+	return false;
+}
+
 //-----------------------------------------------------------------------------
 bool NetworkFilesystem::is_directory(const char* path)
 {

+ 3 - 0
engine/core/filesystem/network_filesystem.h

@@ -83,6 +83,9 @@ public:
 	/// Closes the given @a file.
 	void close(File* file);
 
+	/// Returns whether @a path exists.
+	bool exists(const char* path);
+
 	/// Returns true if @a path is a directory.
 	bool is_directory(const char* path);
 

+ 463 - 0
engine/core/os.h

@@ -0,0 +1,463 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#pragma once
+
+#include "config.h"
+#include "types.h"
+#include "vector.h"
+#include "dynamic_string.h"
+#include "string_utils.h"
+#include "temp_allocator.h"
+
+#if CROWN_PLATFORM_POSIX
+	#include "assert.h"
+	#include <cstdarg>
+	#include <cstdio>
+	#include <cstdlib>
+	#include <dirent.h>
+	#include <dlfcn.h>
+	#include <sys/stat.h>
+	#include <sys/time.h>
+	#include <sys/types.h>
+	#include <sys/wait.h>
+	#include <errno.h>
+	#include <time.h>
+	#include <unistd.h>
+#elif CROWN_PLATFORM_WINDOWS
+	#include <win_headers.h>
+#endif
+
+#if CROWN_PLATFORM_ANDROID
+	#include <android/log.h>
+#endif
+
+namespace crown
+{
+
+#if CROWN_PLATFORM_LINUX
+	const size_t	MAX_PATH_LENGTH = 1024;
+	const char		PATH_SEPARATOR = '/';
+#elif CROWN_PLATFORM_WINDOWS
+	const size_t	MAX_PATH_LENGTH = 1024;
+	const char		PATH_SEPARATOR = '\\';
+	#define snprintf _snprintf
+#elif CROWN_PLATFORM_ANDROID
+	const size_t	MAX_PATH_LENGTH = 1024;
+	const char		PATH_SEPARATOR = '/';
+#endif
+
+namespace os
+{
+
+//-----------------------------------------------------------------------------
+inline void log_debug(const char* string, va_list arg)
+{
+#if CROWN_PLATFORM_ANDROID
+	__android_log_vprint(ANDROID_LOG_DEBUG, "crown", string, arg);
+#else
+	vprintf(string, arg);
+	printf("\n");
+#endif
+}
+
+//-----------------------------------------------------------------------------
+inline void log_error(const char* string, va_list arg)
+{
+#if CROWN_PLATFORM_ANDROID
+	__android_log_vprint(ANDROID_LOG_ERROR, "crown", string, arg);
+#else
+	vprintf(string, arg);
+	printf("\n");
+#endif
+}
+
+//-----------------------------------------------------------------------------
+inline void log_warning(const char* string, va_list arg)
+{
+#if CROWN_PLATFORM_ANDROID
+	__android_log_vprint(ANDROID_LOG_WARN, "crown", string, arg);
+#else
+	vprintf(string, arg);
+	printf("\n");
+#endif
+}
+
+//-----------------------------------------------------------------------------
+inline void log_info(const char* string, va_list arg)
+{
+#if CROWN_PLATFORM_ANDROID
+	__android_log_vprint(ANDROID_LOG_INFO, "crown", string, arg);
+#else
+	vprintf(string, arg);
+	printf("\n");
+#endif
+}
+
+//-----------------------------------------------------------------------------
+inline bool is_root_path(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	return (path != NULL && string::strlen(path) == 1 && path[0] == PATH_SEPARATOR);
+#elif CROWN_PLATFORM_WINDOWS
+	return (path != NULL && string::strlen(path) == 3 && string::is_alpha(path[0]) &&
+		path[1] == ':' && path[2] == PATH_SEPARATOR;
+#endif
+}
+
+//-----------------------------------------------------------------------------
+inline bool is_absolute_path(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	return (path != NULL && string::strlen(path) >= 1 && path[0] == PATH_SEPARATOR);
+#elif CROWN_PLATFORM_WINDOWS
+	return (path != NULL && string::strlen(path) >= 3 && string::is_alpha(path[0]) &&
+		path[1] == ':' && path[2] == PATH_SEPARATOR;
+#endif
+}
+
+inline bool exists(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	return access(path, F_OK) != -1;
+#elif CROWN_PLATFORM_WINDOWS
+	#error "impl"
+#endif
+}
+
+/// Returns whether the path is a directory.
+inline bool is_directory(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	struct stat info;
+	memset(&info, 0, sizeof(struct stat));
+	int err = lstat(path, &info);
+	CE_ASSERT(err == 0, "lstat: errno = %d", errno);
+	CE_UNUSED(err);
+	return ((S_ISDIR(info.st_mode) == 1) && (S_ISLNK(info.st_mode) == 0));
+#elif CROWN_PLATFORM_WINDOWS
+	DWORD fattr = GetFileAttributes(path);
+	return (fattr != INVALID_FILE_ATTRIBUTES && (fattr & FILE_ATTRIBUTE_DIRECTORY) != 0);
+#endif
+}
+
+/// Returns whether the path is a regular file.
+inline bool is_file(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	struct stat info;
+	memset(&info, 0, sizeof(struct stat));
+	int err = lstat(path, &info);
+	CE_ASSERT(err == 0, "lstat: errno = %d", errno);
+	CE_UNUSED(err);
+	return ((S_ISREG(info.st_mode) == 1) && (S_ISLNK(info.st_mode) == 0));
+#elif CROWN_PLATFORM_WINDOWS
+	DWORD fattr = GetFileAttributes(path);
+	return (fattr != INVALID_FILE_ATTRIBUTES && (fattr & FILE_ATTRIBUTE_DIRECTORY) == 0);
+#endif
+}
+
+/// Creates a regular file.
+inline void create_file(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	// Permission mask: rw-r--r--
+	int err = ::mknod(path, S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, 0);
+	CE_ASSERT(err == 0, "mknod: errno = %d", errno);
+	CE_UNUSED(err);
+#elif CROWN_PLATFORM_WINDOWS
+	HANDLE hFile = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+	if (hFile == INVALID_HANDLE_VALUE)
+		return false;
+
+	CloseHandle(hFile);
+	return true;
+#endif
+}
+
+/// Deletes a regular file.
+inline void delete_file(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	int err = ::unlink(path);
+	CE_ASSERT(err == 0, "unlink: errno = %d", errno);
+	CE_UNUSED(err);
+#elif CROWN_PLATFORM_WINDOWS
+	return DeleteFile(path) == TRUE;
+#endif
+}
+
+/// Creates a directory. Returns true if success, false if not
+inline void create_directory(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	// rwxr-xr-x
+	int err = ::mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
+	CE_ASSERT(err == 0, "mkdir: errno = %d", errno);
+	CE_UNUSED(err);
+#elif CROWN_PLATFORM_WINDOWS
+	return CreateDirectory(path, NULL) == TRUE;
+#endif
+}
+
+/// Deletes a directory. Returns true if success, false if not
+inline void delete_directory(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	int err = ::rmdir(path);
+	CE_ASSERT(err == 0, "rmdir: errno = %d", errno);
+	CE_UNUSED(err);
+#elif CROWN_PLATFORM_WINDOWS
+	return RemoveDirectory(path) == TRUE;
+#endif
+}
+
+/// Returns the list of @a files in the given @a dir directory. Optionally walks into
+/// subdirectories whether @a recursive is true.
+/// @note
+/// Does not follow symbolic links.
+inline void list_files(const char* path, Vector<DynamicString>& files)
+{
+#if CROWN_PLATFORM_POSIX
+	DIR *dir;
+	struct dirent *entry;
+
+	if (!(dir = opendir(path)))
+	{
+		return;
+	}
+
+	while ((entry = readdir(dir)))
+	{
+		if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
+		{
+			continue;
+		}
+
+		DynamicString filename(default_allocator());
+
+		filename = entry->d_name;
+		vector::push_back(files, filename);
+	}
+
+	closedir(dir);
+#elif CROWN_PLATFORM_WINDOWS
+	HANDLE file = INVALID_HANDLE_VALUE;
+	WIN32_FIND_DATA ffd;
+
+	char cur_path[MAX_PATH_LENGTH];
+
+	string::strncpy(cur_path, path, string::strlen(path) + 1);
+	string::strncat(cur_path, "\\*", 2);
+
+	file = FindFirstFile(cur_path, &ffd);
+
+	do
+	{
+		CE_ASSERT(file != INVALID_HANDLE_VALUE, "Unable to list files. errono %d", GetLastError());
+
+		if ((string::strcmp(ffd.cFileName, ".") == 0) || (string::strcmp(ffd.cFileName, "..") == 0))
+		{
+			continue;
+		}
+
+		DynamicString filename(default_allocator());
+
+		filename = ffd.cFileName;
+		vector::push_back(files, filename);
+	}
+	while (FindNextFile(file, &ffd) != 0);
+
+	FindClose(file);
+#endif
+}
+
+/// Returns os-dependent path from os-indipendent @a path
+inline const char* normalize_path(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	static char norm[MAX_PATH_LENGTH];
+	char* cur = norm;
+
+	while ((*path) != '\0')
+	{
+		if ((*path) == '\\')
+		{
+			(*cur) = PATH_SEPARATOR;
+		}
+		else
+		{
+			(*cur) = (*path);
+		}
+
+		path++;
+		cur++;
+	}
+
+	return norm;
+#elif CROWN_PLATFORM_WINDOWS
+	static char norm[MAX_PATH_LENGTH];
+
+	for (uint32_t i = 0; i < string::strlen(path)+1; i++)
+	{
+		if (path[i] == '/')
+		{
+			norm[i] = '\\';
+		}
+		else
+		{
+			norm[i] = path[i];
+		}
+	}
+
+	return norm;
+#endif
+}
+
+inline const char* getcwd(char* buf, size_t size)
+{
+#if CROWN_PLATFORM_POSIX
+	return ::getcwd(buf, size);
+#elif CROWN_PLATFORM_WINDOWS
+	GetCurrentDirectory(size, buf);
+	return buf;
+#endif
+}
+
+inline const char* getenv(const char* name)
+{
+#if CROWN_PLATFORM_POSIX
+	return ::getenv(name);
+#elif CROWN_PLATFORM_WINDOWS
+	// GetEnvironmentVariable(name, buf, size);
+#endif
+}
+
+inline int64_t clocktime()
+{
+#if CROWN_PLATFORM_POSIX
+	timespec ttime;
+	clock_gettime(CLOCK_MONOTONIC, &ttime);
+	return ttime.tv_sec * int64_t(1000000000) + ttime.tv_nsec;
+#elif CROWN_PLATFORM_WINDOWS
+	LARGE_INTEGER ttime;
+	QueryPerformanceCounter(&ttime);
+	return (int64_t) ttime.QuadPart;
+#endif
+}
+
+inline int64_t clockfrequency()
+{
+#if CROWN_PLATFORM_POSIX
+	return int32_t(1000000000);
+#elif CROWN_PLATFORM_WINDOWS
+	LARGE_INTEGER freq;
+	QueryPerformanceFrequency(&freq);
+	return (int64_t) freq.QuadPart;
+#endif
+}
+
+inline void* open_library(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	return ::dlopen(path, RTLD_LAZY);
+#elif CROWN_PLATFORM_WINDOWS
+	return (void*) LoadLibraryA(path);
+#endif
+}
+
+inline void close_library(void* library)
+{
+#if CROWN_PLATFORM_POSIX
+	dlclose(library);
+#elif CROWN_PLATFORM_WINDOWS
+	FreeLibrary((HMODULE) library);
+#endif
+}
+
+inline void* lookup_symbol(void* library, const char* name)
+{
+#if CROWN_PLATFORM_POSIX
+	return ::dlsym(library, name);
+#elif CROWN_PLATFORM_WINDOWS
+	return (void*) GetProcAddress((HMODULE) library, name);
+#endif
+}
+
+/// Executes a process.
+/// @a args is an array of arguments where:
+/// @a args[0] is the path to the program executable,
+/// @a args[1, 2, ..., n-1] is a list of arguments to pass to the executable,
+/// @a args[n] is NULL.
+inline void execute_process(const char* args[])
+{
+#if CROWN_PLATFORM_POSIX
+	pid_t pid = fork();
+	CE_ASSERT(pid != -1, "fork: errno = %d", errno);
+	if (pid)
+	{
+		int32_t dummy;
+		wait(&dummy);
+	}
+	else
+	{
+		int err = execv(args[0], (char* const*)args);
+		CE_ASSERT(err != -1, "execv: errno = %d", errno);
+		CE_UNUSED(err);
+		exit(EXIT_SUCCESS);
+	}
+#elif CROWN_PLATFORM_WINDOWS
+	STARTUPINFO info;
+	memset(&info, 0, sizeof(info));
+	info.cb = sizeof(info);
+
+	PROCESS_INFORMATION process;
+	memset(&process, 0, sizeof(process));
+
+	DynamicString cmds(default_allocator());
+
+	for (uint32_t i = 0; args[i] != NULL; i++)
+	{
+		cmds += args[i];
+		cmds += ' ';
+	}
+
+	// Necessary because CreateProcess second argument must be non-const
+	char tmp[1024];
+	string::strncpy(tmp, normalize_path(cmds.c_str()), string::strlen(cmds.c_str()));
+
+	int err = CreateProcess(args[0], tmp, NULL, NULL, TRUE, 0, NULL, NULL, &info, &process);
+	CE_ASSERT(err != 0, "CreateProcess: GetLastError = %d", GetLastError());
+	CE_UNUSED(err);
+
+	::WaitForSingleObject(process.hProcess, INFINITE);
+	CloseHandle(process.hProcess);
+	CloseHandle(process.hThread);
+#endif
+}
+
+} // namespace os
+} // namespace crown

+ 0 - 2
engine/core/strings/string_utils.h

@@ -39,8 +39,6 @@ namespace crown
 namespace string
 {
 
-const char* const	EMPTY = "";
-
 //-----------------------------------------------------------------------------
 inline bool is_alpha(char c)
 {

+ 7 - 7
engine/device.cpp

@@ -1,3 +1,4 @@
+
 /*
 Copyright (c) 2013 Daniele Bartolini, Michele Rossi
 Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
@@ -101,7 +102,7 @@ Device::Device()
 	, m_world_manager(NULL)
 {
 	// Bundle dir is current dir by default.
-	string::strncpy(m_bundle_dir, os::get_cwd(), MAX_PATH_LENGTH);
+	os::getcwd(m_bundle_dir, MAX_PATH_LENGTH);
 	string::strncpy(m_source_dir, "", MAX_PATH_LENGTH);
 	string::strncpy(m_boot_file, "lua/game", MAX_PATH_LENGTH);
 }
@@ -315,7 +316,7 @@ void Device::start()
 	CE_ASSERT(m_is_init, "Cannot start uninitialized engine.");
 
 	m_is_running = true;
-	m_last_time = os::milliseconds();
+	m_last_time = os::clocktime();
 }
 
 //-----------------------------------------------------------------------------
@@ -367,22 +368,21 @@ double Device::time_since_start() const
 //-----------------------------------------------------------------------------
 void Device::frame()
 {
-	m_current_time = os::microseconds();
-	m_last_delta_time = (m_current_time - m_last_time) / 1000000.0f;
+	m_current_time = os::clocktime();
+	const int64_t time = m_current_time - m_last_time;
 	m_last_time = m_current_time;
+	const double freq = (double) os::clockfrequency();
+	m_last_delta_time = time * (1.0 / freq);
 	m_time_since_start += m_last_delta_time;
 
 	if (!m_is_paused)
 	{
 		m_resource_manager->complete_requests();
-
 		m_lua_environment->call_global("frame", 1, ARGUMENT_FLOAT, last_delta_time());
-
 		m_renderer->frame();
 	}
 
 	lua_system::clear_temporaries();
-
 	m_frame_count++;
 }
 

+ 2 - 2
engine/device.h

@@ -194,8 +194,8 @@ protected:
 
 	uint64_t m_frame_count;
 
-	uint64_t m_last_time;
-	uint64_t m_current_time;
+	int64_t m_last_time;
+	int64_t m_current_time;
 	float m_last_delta_time;
 	double m_time_since_start;
 

+ 0 - 85
engine/os/android/android.cpp

@@ -1,85 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include <jni.h>
-#include <android/log.h>
-#include <cstdarg>
-#include <cstdio>
-#include <cstdlib>
-#include <dirent.h>
-#include <dlfcn.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "os.h"
-#include "assert.h"
-#include "string_utils.h"
-#include "os_types.h"
-
-namespace crown
-{
-namespace os
-{
-
-extern timespec g_base_time;
-
-//-----------------------------------------------------------------------------
-void log_debug(const char* string, va_list arg)
-{
-	__android_log_vprint(ANDROID_LOG_DEBUG, "crown", string, arg);
-}
-
-//-----------------------------------------------------------------------------
-void log_error(const char* string, va_list arg)
-{
-	__android_log_vprint(ANDROID_LOG_ERROR, "crown", string, arg);
-}
-
-//-----------------------------------------------------------------------------
-void log_warning(const char* string, va_list arg)
-{
-	__android_log_vprint(ANDROID_LOG_WARN, "crown", string, arg);
-}
-
-//-----------------------------------------------------------------------------
-void log_info(const char* string, va_list arg)
-{
-	__android_log_vprint(ANDROID_LOG_INFO, "crown", string, arg);
-}
-
-//-----------------------------------------------------------------------------
-void init_os()
-{
-	// Initilize the base time
-	clock_gettime(CLOCK_MONOTONIC, &g_base_time);
-}
-
-} // namespace os
-} // namespace crown

+ 0 - 94
engine/os/linux/linux.cpp

@@ -1,94 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "assert.h"
-#include <X11/Xlib.h>
-#include <cstdarg>
-#include <cstdio>
-#include <cstdlib>
-#include <dirent.h>
-#include <dlfcn.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "os.h"
-#include "string_utils.h"
-#include "temp_allocator.h"
-
-namespace crown
-{
-namespace os
-{
-
-extern timespec g_base_time;
-
-//-----------------------------------------------------------------------------
-void vprintf(const char* string, va_list arg)
-{
-	::vprintf(string, arg);
-}
-
-//-----------------------------------------------------------------------------
-void log_debug(const char* string, va_list arg)
-{
-	vprintf(string, arg);
-	printf("\n");
-}
-
-//-----------------------------------------------------------------------------
-void log_error(const char* string, va_list arg)
-{
-	vprintf(string, arg);
-	printf("\n");
-}
-
-//-----------------------------------------------------------------------------
-void log_warning(const char* string, va_list arg)
-{
-	vprintf(string, arg);
-	printf("\n");
-}
-
-//-----------------------------------------------------------------------------
-void log_info(const char* string, va_list arg)
-{
-	vprintf(string, arg);
-	printf("\n");
-}
-
-//-----------------------------------------------------------------------------
-void init_os()
-{
-	// Initilize the base time
-	clock_gettime(CLOCK_MONOTONIC, &g_base_time);
-}
-
-} // namespace os
-} // namespace crown

+ 1 - 2
engine/os/linux/main.cpp

@@ -46,7 +46,6 @@ extern void set_x11_display_and_window(Display* dpy, Window win);
 void init()
 {
 	crown::memory::init();
-	crown::os::init_os();
 }
 
 //-----------------------------------------------------------------------------
@@ -637,7 +636,7 @@ public:
 				case '?':
 				default:
 				{
-					os::printf(help_message);
+					printf(help_message);
 					exit(EXIT_FAILURE);
 				}
 			}

+ 0 - 154
engine/os/os.h

@@ -1,154 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "config.h"
-#include "types.h"
-#include "vector.h"
-#include "dynamic_string.h"
-#include <cstdarg>
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-#if CROWN_PLATFORM_LINUX
-	const size_t	MAX_PATH_LENGTH = 1024;
-	const char		PATH_SEPARATOR = '/';
-#elif CROWN_PLATFORM_WINDOWS
-	const size_t	MAX_PATH_LENGTH = 1024;
-	const char		PATH_SEPARATOR = '\\';
-	#define snprintf _snprintf
-#elif CROWN_PLATFORM_ANDROID
-	const size_t	MAX_PATH_LENGTH = 1024;
-	const char		PATH_SEPARATOR = '/';
-#endif
-
-namespace os
-{
-//-----------------------------------------------------------------------------
-// Print and log functions
-//-----------------------------------------------------------------------------
-void CE_EXPORT	printf(const char* string, ...);				//!< Printf wrapper
-void			vprintf(const char* string, va_list arg);		//!< VPrintf wrapper
-
-void			log_debug(const char* string, va_list arg);		//!< Print debug message
-void			log_error(const char* string, va_list arg);		//!< Print error message
-void			log_warning(const char* string, va_list arg);	//!< Print warning message
-void			log_info(const char* string, va_list arg);		//!< Print info message
-
-//-----------------------------------------------------------------------------
-// Paths
-//-----------------------------------------------------------------------------
-bool CE_EXPORT	is_root_path(const char* path);
-bool CE_EXPORT	is_absolute_path(const char* path);
-
-//-----------------------------------------------------------------------------
-// File management
-//-----------------------------------------------------------------------------
-
-/// Returns whether the path is a file or directory on the disk
-bool			exists(const char* path);
-
-/// Returns whether the path is a directory. (May not resolve symlinks.)
-bool			is_directory(const char* path);
-
-/// Returns whether the path is a regular file. (May not resolve symlinks.)
-bool			is_file(const char* path);
-
-/// Creates a regular file. Returns true if success, false if not
-bool			create_file(const char* path);
-
-/// Deletes a regular file. Returns true if success, false if not
-bool			delete_file(const char* path);
-
-/// Creates a directory. Returns true if success, false if not
-bool			create_directory(const char* path);
-
-/// Deletes a directory. Returns true if success, false if not
-bool			delete_directory(const char* path);
-
-/// Returns the list of @a files in the given @a dir directory. Optionally walks into
-/// subdirectories whether @a recursive is true.
-/// @note
-/// Does not follow symbolic links.
-void			list_files(const char* path, Vector<DynamicString>& files);
-
-/// Returns os-dependent path from os-indipendent @a path
-const char*		normalize_path(const char* path);
-
-//-----------------------------------------------------------------------------
-// OS ambient variables
-//-----------------------------------------------------------------------------
-
-/// Fills ret with the path of the current working directory. Returns true if success, false if not
-const char*		get_cwd();
-
-/// Fills ret with the path of the user home directory
-const char*		get_home();
-
-/// Returns the content of the 'env' environment variable or the empty string
-const char*		get_env(const char* env);
-
-//-----------------------------------------------------------------------------
-// Render window and input management
-//-----------------------------------------------------------------------------
-CE_EXPORT void	init_os();
-
-void			get_cursor_xy(int32_t& x, int32_t& y);
-void			set_cursor_xy(int32_t x, int32_t y);
-
-//-----------------------------------------------------------------------------
-// Timing
-//-----------------------------------------------------------------------------
-uint64_t		milliseconds();
-uint64_t		microseconds();
-
-//-----------------------------------------------------------------------------
-// Dynamic libraries
-//-----------------------------------------------------------------------------
-void*			open_library(const char* path);
-void			close_library(void* library);
-void*			lookup_symbol(void* library, const char* name);
-
-//-----------------------------------------------------------------------------
-// Process execution
-//-----------------------------------------------------------------------------
-
-/// Executes a process.
-/// @a args is an array of arguments where:
-/// @a args[0] is the path to the program executable,
-/// @a args[1, 2, ..., n-1] is a list of arguments to pass to the executable,
-/// @a args[n] is NULL.
-void			execute_process(const char* args[]);
-
-//-----------------------------------------------------------------------------
-
-} // namespace os
-
-} // namespace crown
-

+ 0 - 313
engine/os/posix/posix.cpp

@@ -1,313 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "assert.h"
-#include <cstdarg>
-#include <cstdio>
-#include <cstdlib>
-#include <dirent.h>
-#include <dlfcn.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "os.h"
-#include "string_utils.h"
-#include "temp_allocator.h"
-
-namespace crown
-{
-namespace os
-{
-
-timespec g_base_time;
-
-//-----------------------------------------------------------------------------
-void printf(const char* string, ...)
-{
-	va_list args;
-
-	va_start(args, string);
-	::vprintf(string, args);
-	va_end(args);
-}
-
-//-----------------------------------------------------------------------------
-bool is_root_path(const char* path)
-{
-	CE_ASSERT(path != NULL, "Path must be != NULL");
-
-	if (string::strlen(path) == 1)
-	{
-		if (path[0] == PATH_SEPARATOR)
-		{
-			return true;
-		}
-	}
-
-	return false;
-}
-
-//-----------------------------------------------------------------------------
-bool is_absolute_path(const char* path)
-{
-	CE_ASSERT(path != NULL, "Path must be != NULL");
-
-	if (string::strlen(path) > 0)
-	{
-		if (path[0] == PATH_SEPARATOR)
-		{
-			return true;
-		}
-	}
-
-	return false;
-}
-
-//-----------------------------------------------------------------------------
-bool exists(const char* path)
-{
-	struct stat dummy;
-	return (stat(path, &dummy) == 0);
-}
-
-//-----------------------------------------------------------------------------
-bool is_directory(const char* path)
-{
-	struct stat info;
-	memset(&info, 0, sizeof(struct stat));
-	lstat(path, &info);
-	return ((S_ISDIR(info.st_mode) == 1) && (S_ISLNK(info.st_mode) == 0));
-}
-
-//-----------------------------------------------------------------------------
-bool is_file(const char* path)
-{
-	struct stat info;
-	memset(&info, 0, sizeof(struct stat));
-	lstat(path, &info);
-	return ((S_ISREG(info.st_mode) == 1) && (S_ISLNK(info.st_mode) == 0));
-}
-
-//-----------------------------------------------------------------------------
-bool create_file(const char* path)
-{
-	// Permission mask: rw-r--r--
-	return ::mknod(path, S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, 0) == 0;
-}
-
-//-----------------------------------------------------------------------------
-bool delete_file(const char* path)
-{
-	return (::unlink(path) == 0);
-}
-
-//-----------------------------------------------------------------------------
-bool create_directory(const char* path)
-{
-	// rwxr-xr-x permission mask
-	return (::mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0);
-}
-
-//-----------------------------------------------------------------------------
-bool delete_directory(const char* path)
-{
-	return (::rmdir(path) == 0);
-}
-
-//-----------------------------------------------------------------------------
-void list_files(const char* path, Vector<DynamicString>& files)
-{
-	DIR *dir;
-	struct dirent *entry;
-
-	if (!(dir = opendir(path)))
-	{
-		return;
-	}
-
-	while ((entry = readdir(dir)))
-	{
-		if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
-		{
-			continue;
-		}
-
-		DynamicString filename(default_allocator());
-
-		filename = entry->d_name;
-		vector::push_back(files, filename);
-	}
-
-	closedir(dir);
-}
-
-//-----------------------------------------------------------------------------
-const char* normalize_path(const char* path)
-{
-	static char norm[MAX_PATH_LENGTH];
-	char* cur = norm;
-
-	while ((*path) != '\0')
-	{
-		if ((*path) == '\\')
-		{
-			(*cur) = PATH_SEPARATOR;
-		}
-		else
-		{
-			(*cur) = (*path);
-		}
-
-		path++;
-		cur++;
-	}
-
-	return norm;
-}
-
-//-----------------------------------------------------------------------------
-const char* get_cwd()
-{
-	static char cwdBuf[MAX_PATH_LENGTH];
-	if (getcwd(cwdBuf, MAX_PATH_LENGTH) == NULL)
-	{
-		return string::EMPTY;
-	}
-
-	return cwdBuf;
-}
-
-//-----------------------------------------------------------------------------
-const char* get_home()
-{
-	char* envHome = NULL;
-	envHome = getenv("HOME");
-
-	if (envHome == NULL)
-	{
-		return string::EMPTY;
-	}
-
-	return envHome;
-}
-
-//-----------------------------------------------------------------------------
-const char* get_env(const char* env)
-{
-	char* envDevel = NULL;
-	envDevel = getenv(env);
-
-	if (envDevel == NULL)
-	{
-		return string::EMPTY;
-	}
-
-	return envDevel;
-}
-
-//-----------------------------------------------------------------------------
-uint64_t milliseconds()
-{
-	timespec tmp;
-
-	clock_gettime(CLOCK_MONOTONIC, &tmp);
-
-	return (tmp.tv_sec - g_base_time.tv_sec) * 1000 + (tmp.tv_nsec - g_base_time.tv_nsec) / 1000000;
-}
-
-//-----------------------------------------------------------------------------
-uint64_t microseconds()
-{
-	timespec tmp;
-	clock_gettime(CLOCK_MONOTONIC, &tmp);
-	return (tmp.tv_sec - g_base_time.tv_sec) * 1000000 + (tmp.tv_nsec - g_base_time.tv_nsec) / 1000;
-}
-
-//-----------------------------------------------------------------------------
-void* open_library(const char* path)
-{
-	void* library = dlopen(path, RTLD_NOW);
-
-	if (library == NULL)
-	{
-		os::printf("OS: ERROR: Unable to load library '%s' with error: %s\n", path, dlerror());
-		return NULL;
-	}
-
-	return library;
-}
-
-//-----------------------------------------------------------------------------
-void close_library(void* library)
-{
-	CE_ASSERT(dlclose(library) == 0, "Failed to close library");
-}
-
-//-----------------------------------------------------------------------------
-void* lookup_symbol(void* library, const char* name)
-{
-	dlerror();
-
-	void* symbol = dlsym(library, name);
-
-	const char* error = dlerror();
-
-	if (error)
-	{
-		os::printf("OS: ERROR: Unable to lookup symbol '%s' with error: %s\n", name, error);
-		return NULL;
-	}
-
-	return symbol;
-}
-
-//-----------------------------------------------------------------------------
-void execute_process(const char* args[])
-{
-	pid_t pid = fork();
-	CE_ASSERT(pid != -1, "Unable to fork");
-
-	if (pid)
-	{
-		int32_t dummy;
-		wait(&dummy);
-	}
-	else
-	{
-		int res = execv(args[0], (char* const*)args);
-		CE_ASSERT(res != -1, "Unable to exec '%s'. errno %d", args[0], res);
-		CE_UNUSED(res);
-		exit(EXIT_SUCCESS);
-	}
-}
-
-
-} // namespace os
-} // namespace crown

+ 0 - 357
engine/os/win/win_os.cpp

@@ -1,357 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "win_headers.h"
-#include <cstdio>
-#include <cstdarg>
-#include "string_utils.h"
-
-#include "os.h"
-
-namespace crown
-{
-namespace os
-{
-
-LARGE_INTEGER frequency;
-LARGE_INTEGER base_time;
-
-//-----------------------------------------------------------------------------
-void printf(const char* string, ...)
-{
-	va_list args;
-
-	va_start(args, string);
-	::vprintf(string, args);
-	va_end(args);
-}
-
-//-----------------------------------------------------------------------------
-void vprintf(const char* string, va_list arg)
-{
-	::vprintf(string, arg);
-}
-
-//-----------------------------------------------------------------------------
-void log_debug(const char* string, va_list arg)
-{
-	printf("D: ");
-	vprintf(string, arg);
-	printf("\n");
-}
-
-//-----------------------------------------------------------------------------
-void log_error(const char* string, va_list arg)
-{
-	printf("E: ");
-	vprintf(string, arg);
-	printf("\n");
-}
-
-//-----------------------------------------------------------------------------
-void log_warning(const char* string, va_list arg)
-{
-	printf("W: ");
-	vprintf(string, arg);
-	printf("\n");
-}
-
-//-----------------------------------------------------------------------------
-void log_info(const char* string, va_list arg)
-{
-	printf("I: ");
-	vprintf(string, arg);
-	printf("\n");
-}
-
-//-----------------------------------------------------------------------------
-bool is_root_path(const char* path)
-{
-	CE_ASSERT(path != NULL, "Path must be != NULL");
-
-	if (string::strlen(path) == 1)
-	{
-		if ((path[0] >= 65 && path[0] <= 90) || (path[0] >= 97 && path[0] <= 122))
-		{
-			return true;
-		}
-	}
-
-	return false;
-}
-
-//-----------------------------------------------------------------------------
-bool is_absolute_path(const char* path)
-{
-	CE_ASSERT(path != NULL, "Path must be != NULL");
-
-	if (string::strlen(path) > 0)
-	{
-		if ((path[0] >= 'c' && path[0] <= 'z') || (path[0] >= 'C' && path[0] <= 'Z'))
-		{
-			if (path[1] == ':')
-			{
-				return true;
-			}
-		}
-	}
-
-	return false;
-}
-
-//-----------------------------------------------------------------------------
-bool exists(const char* path)
-{
-	DWORD fileAttr;
-	fileAttr = GetFileAttributes(path);
-	return (fileAttr != INVALID_FILE_ATTRIBUTES);
-}
-
-//-----------------------------------------------------------------------------
-bool is_directory(const char* path)
-{
-	DWORD fileAttr;
-	fileAttr = GetFileAttributes(path);
-	return (fileAttr != INVALID_FILE_ATTRIBUTES && (fileAttr & FILE_ATTRIBUTE_DIRECTORY) != 0);
-}
-
-//-----------------------------------------------------------------------------
-bool is_file(const char* path)
-{
-	DWORD fileAttr;
-	fileAttr = GetFileAttributes(path);
-	return (fileAttr != INVALID_FILE_ATTRIBUTES && (fileAttr & FILE_ATTRIBUTE_DIRECTORY) == 0);
-}
-
-//-----------------------------------------------------------------------------
-bool create_file(const char* path)
-{
-	HANDLE hFile = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
-	if (hFile == INVALID_HANDLE_VALUE)
-		return false;
-
-	CloseHandle(hFile);
-	return true;
-}
-
-//-----------------------------------------------------------------------------
-bool delete_file(const char* path)
-{
-	return DeleteFile(path) == TRUE;
-}
-
-//-----------------------------------------------------------------------------
-bool create_directory(const char* path)
-{
-	return CreateDirectory(path, NULL) == TRUE;
-}
-
-//-----------------------------------------------------------------------------
-bool delete_directory(const char* path)
-{
-	return RemoveDirectory(path) == TRUE;
-}
-
-//-----------------------------------------------------------------------------
-const char* get_cwd()
-{
-	static char cwdBuf[1024];
-	int32_t len = GetCurrentDirectory(1024, cwdBuf);
-
-	if (len == 0)
-	{
-		return string::EMPTY;
-	}
-
-	return cwdBuf;
-}
-
-//-----------------------------------------------------------------------------
-const char* get_home()
-{
-	// TODO
-	return string::EMPTY;
-}
-
-//-----------------------------------------------------------------------------
-const char* get_env(const char* env)
-{
-	static char envBuf[1024];
-	int32_t len = GetEnvironmentVariable(env, envBuf, 1024);
-
-	if (len == 0)
-	{
-		return string::EMPTY;
-	}
-
-	return envBuf;
-}
-
-//-----------------------------------------------------------------------------
-void list_files(const char* path, Vector<DynamicString>& files)
-{
-	HANDLE file = INVALID_HANDLE_VALUE;
-	WIN32_FIND_DATA ffd;
-
-	char cur_path[MAX_PATH_LENGTH];
-
-	string::strncpy(cur_path, path, string::strlen(path) + 1);
-	string::strncat(cur_path, "\\*", 2);
-
-	file = FindFirstFile(cur_path, &ffd);
-
-	do
-	{
-		CE_ASSERT(file != INVALID_HANDLE_VALUE, "Unable to list files. errono %d", GetLastError());
-
-		if ((string::strcmp(ffd.cFileName, ".") == 0) || (string::strcmp(ffd.cFileName, "..") == 0))
-		{
-			continue;
-		}
-
-		DynamicString filename(default_allocator());
-
-		filename = ffd.cFileName;
-		vector::push_back(files, filename);
-	}
-	while (FindNextFile(file, &ffd) != 0);
-
-	FindClose(file);
-}
-
-//-----------------------------------------------------------------------------
-const char* normalize_path(const char* path)
-{
-	static char norm[MAX_PATH_LENGTH];
-
-	for (uint32_t i = 0; i < string::strlen(path)+1; i++)
-	{
-		if (path[i] == '/')
-		{
-			norm[i] = '\\';
-		}
-		else
-		{
-			norm[i] = path[i];
-		}
-	}
-
-	return norm;
-}
-
-//-----------------------------------------------------------------------------
-void init_os()
-{
-	QueryPerformanceFrequency(&frequency);
-
-	CE_ASSERT(frequency.QuadPart > 0, "Hardware does not support high resolution performance counter.\n");
-
-	QueryPerformanceCounter(&base_time);
-}
-
-//-----------------------------------------------------------------------------
-uint64_t milliseconds()
-{
-	LARGE_INTEGER current_time;
-
-	QueryPerformanceCounter(&current_time);
-
-	return (uint64_t) (current_time.QuadPart - base_time.QuadPart) / (frequency.QuadPart / 1000);
-}
-
-//-----------------------------------------------------------------------------
-uint64_t microseconds()
-{
-	LARGE_INTEGER current_time;
-
-	QueryPerformanceCounter(&current_time);
-
-	return (uint64_t) (current_time.QuadPart - base_time.QuadPart) / (frequency.QuadPart / 1000000);
-}
-
-//-----------------------------------------------------------------------------
-void* open_library(const char* path)
-{
-
-	HMODULE library = LoadLibrary(path);
-
-	CE_ASSERT(library  != NULL, "Unable to load library '%s' with error: %d\n", path, GetLastError());
-
-	return library;
-}
-
-//-----------------------------------------------------------------------------
-void close_library(void* library)
-{
-	BOOL freed = FreeLibrary((HMODULE)library);
-
-	CE_ASSERT(freed,  "Failed to close library\n with error: %d\n", GetLastError());
-}
-
-//-----------------------------------------------------------------------------
-void* lookup_symbol(void* library, const char* name)
-{
-	FARPROC symbol = GetProcAddress((HMODULE)library, name);
-
-	CE_ASSERT(symbol  != NULL, "Unable to export symbol '%s' with error: %d\n", name, GetLastError());
-	return symbol;
-}
-
-//-----------------------------------------------------------------------------
-void execute_process(const char* args[])
-{
-	STARTUPINFO info;
-	memset(&info, 0, sizeof(info));
-	info.cb = sizeof(info);
-
-	PROCESS_INFORMATION process;
-	memset(&process, 0, sizeof(process));
-
-	DynamicString cmds(default_allocator());
-
-	for (uint32_t i = 0; args[i] != NULL; i++)
-	{
-		cmds += args[i];
-		cmds += ' ';
-	}
-
-	// Necessary because CreateProcess second argument must be non-const
-	char tmp[1024];
-	string::strncpy(tmp, normalize_path(cmds.c_str()), string::strlen(cmds.c_str()));
-
-	int32_t res;
-	if (res = CreateProcess(args[0], tmp, NULL, NULL, TRUE, 0, NULL, NULL, &info, &process))
-	{
-	    ::WaitForSingleObject(process.hProcess, INFINITE);
-   		CloseHandle(process.hProcess);
-    	CloseHandle(process.hThread);
-	}
-
-	CE_ASSERT(res != 0, "Unable to create process for %s, errno: %d\n", args[0], GetLastError());
-}
-
-} // namespace os
-} // namespace crown

+ 2 - 2
engine/resource/unit_resource.cpp

@@ -342,7 +342,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	unit_name.strip_trailing(".unit");
 	DynamicString physics_name = unit_name;
 	physics_name += ".physics";
-	if (fs.is_file(physics_name.c_str()))
+	if (fs.exists(physics_name.c_str()))
 	{
 		m_physics_resource = ResourceId("physics", unit_name.c_str());
 	}
@@ -354,7 +354,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	// Check if the unit has a .material resource
 	DynamicString material_name = unit_name;
 	material_name += ".material";
-	if (fs.is_file(material_name.c_str()))
+	if (fs.exists(material_name.c_str()))
 	{
 		m_material_resource = ResourceId("material", unit_name.c_str());
 	}