فهرست منبع

Fix windows build

Daniele Bartolini 11 سال پیش
والد
کامیت
5344024e51
5فایلهای تغییر یافته به همراه58 افزوده شده و 34 حذف شده
  1. 1 0
      engine/compilers/bundle_compiler.cpp
  2. 31 27
      engine/core/log.h
  3. 2 3
      engine/core/os.h
  4. 22 3
      engine/core/strings/string_utils.h
  5. 2 1
      engine/renderers/shader.cpp

+ 1 - 0
engine/compilers/bundle_compiler.cpp

@@ -42,6 +42,7 @@ bool BundleCompiler::compile(const char* type, const char* name, Platform::Enum
 	CompileOptions opts(_source_fs, outf, platform);
 	resource_on_compile(id.type, path, opts);
 	_bundle_fs.close(outf);
+	return true;
 }
 
 bool BundleCompiler::compile_all(Platform::Enum platform)

+ 31 - 27
engine/core/log.h

@@ -6,39 +6,43 @@
 #pragma once
 
 #if defined(CROWN_DEBUG)
-	#include "console_server.h"
-	#include "os.h"
-	namespace log_internal
-	{
-		using namespace crown;
-		inline void logx(LogSeverity::Enum sev, const char* msg, va_list args)
-		{
-			char buf[2048];
-			int len = vsnprintf(buf, sizeof(buf), msg, args);
-			if (len > (int)sizeof(buf))
-				len = sizeof(buf) - 1;
 
-			buf[len] = '\0';
-			console_server_globals::console().log_to_all(buf, sev);
-			os::log(buf);
-		}
+#include "console_server.h"
+#include "string_utils.h"
+#include "os.h"
+
+namespace crown
+{
+namespace log_internal
+{
+	inline void logx(LogSeverity::Enum sev, const char* msg, va_list args)
+	{
+		char buf[2048];
+		int len = vsnprintf(buf, sizeof(buf), msg, args);
+		if (len > (int)sizeof(buf))
+			len = sizeof(buf) - 1;
 
-		inline void logx(LogSeverity::Enum sev, const char* msg, ...)
-		{
-			va_list args;
-			va_start(args, msg);
-			logx(sev, msg, args);
-			va_end(args);
-		}
+		buf[len] = '\0';
+		console_server_globals::console().log_to_all(buf, sev);
+		os::log(buf);
 	}
 
-	#define CE_LOGI(msg, ...) log_internal::logx(crown::LogSeverity::INFO, msg, ##__VA_ARGS__)
-	#define CE_LOGD(msg, ...) log_internal::logx(crown::LogSeverity::DEBUG, msg, ##__VA_ARGS__)
-	#define CE_LOGE(msg, ...) log_internal::logx(crown::LogSeverity::ERROR, msg, ##__VA_ARGS__)
-	#define CE_LOGW(msg, ...) log_internal::logx(crown::LogSeverity::WARN, msg, ##__VA_ARGS__)
+	inline void logx(LogSeverity::Enum sev, const char* msg, ...)
+	{
+		va_list args;
+		va_start(args, msg);
+		logx(sev, msg, args);
+		va_end(args);
+	}
+} // namespace log_internal
+} // namespace crown
+	#define CE_LOGI(msg, ...) crown::log_internal::logx(crown::LogSeverity::INFO, msg, ##__VA_ARGS__)
+	#define CE_LOGD(msg, ...) crown::log_internal::logx(crown::LogSeverity::DEBUG, msg, ##__VA_ARGS__)
+	#define CE_LOGE(msg, ...) crown::log_internal::logx(crown::LogSeverity::ERROR, msg, ##__VA_ARGS__)
+	#define CE_LOGW(msg, ...) crown::log_internal::logx(crown::LogSeverity::WARN, msg, ##__VA_ARGS__)
 #else
 	#define CE_LOGI(msg, ...) ((void)0)
 	#define CE_LOGD(msg, ...) ((void)0)
 	#define CE_LOGE(msg, ...) ((void)0)
 	#define CE_LOGW(msg, ...) ((void)0)
-#endif
+#endif // defined(CROWN_DEBUG)

+ 2 - 3
engine/core/os.h

@@ -42,7 +42,6 @@ namespace crown
 #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 = '/';
@@ -65,7 +64,7 @@ namespace os
 #if CROWN_PLATFORM_POSIX
 		return (path != NULL && strlen(path) == 1 && path[0] == PATH_SEPARATOR);
 #elif CROWN_PLATFORM_WINDOWS
-		return (path != NULL && strlen(path) == 3 && is_alpha(path[0]) &&
+		return (path != NULL && strlen(path) == 3 && isalpha(path[0]) &&
 			path[1] == ':' && path[2] == PATH_SEPARATOR);
 #endif
 	}
@@ -75,7 +74,7 @@ namespace os
 #if CROWN_PLATFORM_POSIX
 		return (path != NULL && strlen(path) >= 1 && path[0] == PATH_SEPARATOR);
 #elif CROWN_PLATFORM_WINDOWS
-		return (path != NULL && strlen(path) >= 3 && is_alpha(path[0]) &&
+		return (path != NULL && strlen(path) >= 3 && isalpha(path[0]) &&
 			path[1] == ':' && path[2] == PATH_SEPARATOR);
 #endif
 	}

+ 22 - 3
engine/core/strings/string_utils.h

@@ -5,13 +5,13 @@
 
 #pragma once
 
-#include <cstdio>
-#include <cstring>
-
 #include "assert.h"
 #include "types.h"
 #include "config.h"
 #include "macros.h"
+#include <cstdio>
+#include <cstring>
+#include <cstdarg>
 
 namespace crown
 {
@@ -54,6 +54,25 @@ inline char* strncat(char* dest, const char* src, size_t len)
 	return ::strncat(dest, src, len);
 }
 
+inline int32_t vsnprintf(char* str, size_t num, const char* format, va_list args)
+{
+#if CROWN_COMPILER_MSVC
+	int32_t len = _vsnprintf_s(str, num, _TRUNCATE, format, args);
+	return (len == 1) ? _vscprintf(format, args) : len;
+#else
+	return ::vsnprintf(str, num, format, args);
+#endif // CROWN_COMPILER_MSVC
+}
+
+inline int32_t snprintf(char* str, size_t n, const char* format, ...)
+{
+	va_list args;
+	va_start(args, format);
+	int32_t len = vsnprintf(str, n, format, args);
+	va_end(args);
+	return len;
+}
+
 inline const char* begin(const char* str)
 {
 	CE_ASSERT(str != NULL, "Str must be != NULL");

+ 2 - 1
engine/renderers/shader.cpp

@@ -17,8 +17,9 @@
 #else
 		#define SHADERC_NAME "shadercRelease"
 #endif // CROWN_DEBUG
+#if CROWN_PLATFORM_LINUX
 		#define SHADERC_PATH SHADERC_NAME
-#if CROWN_PLATFORM_WINDOWS
+#elif CROWN_PLATFORM_WINDOWS
 		#define SHADERC_PATH SHADERC_NAME".exe"
 #endif // CROWN_PLATFORM_WINDOWS