From 2e561248b861ddbdc79337e4c9bffa523b765829 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Tue, 27 Mar 2012 22:54:58 +0200 Subject: [PATCH 1/3] parseHex --- base/stringutil.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ base/stringutil.h | 5 ++++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 base/stringutil.cpp diff --git a/base/stringutil.cpp b/base/stringutil.cpp new file mode 100644 index 000000000..3e977ba9b --- /dev/null +++ b/base/stringutil.cpp @@ -0,0 +1,41 @@ +#include +#include "base/stringutil.h" + +unsigned int parseHex(const char *_szValue) +{ + DWORD Count, Value = 0; + size_t Finish = strlen(_szValue); + if (Finish > 8 ) { Finish = 8; } + + for (Count = 0; Count < Finish; Count++) { + Value = (Value << 4); + switch( _szValue[Count] ) { + case '0': break; + case '1': Value += 1; break; + case '2': Value += 2; break; + case '3': Value += 3; break; + case '4': Value += 4; break; + case '5': Value += 5; break; + case '6': Value += 6; break; + case '7': Value += 7; break; + case '8': Value += 8; break; + case '9': Value += 9; break; + case 'A': Value += 10; break; + case 'a': Value += 10; break; + case 'B': Value += 11; break; + case 'b': Value += 11; break; + case 'C': Value += 12; break; + case 'c': Value += 12; break; + case 'D': Value += 13; break; + case 'd': Value += 13; break; + case 'E': Value += 14; break; + case 'e': Value += 14; break; + case 'F': Value += 15; break; + case 'f': Value += 15; break; + default: + Value = (Value >> 4); + Count = Finish; + } + } + return Value; +} \ No newline at end of file diff --git a/base/stringutil.h b/base/stringutil.h index e5dfa8792..17048fd05 100644 --- a/base/stringutil.h +++ b/base/stringutil.h @@ -15,4 +15,7 @@ public: inline bool endsWith(const std::string &str, const std::string &what) { return str.substr(str.size() - what.size()) == what; -} \ No newline at end of file +} + +// highly unsafe and not recommended. +unsigned int parseHex(const char* _szValue); \ No newline at end of file From a4b7a0cb1363b911c41dad977e0820202a766efc Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Tue, 27 Mar 2012 23:39:13 +0200 Subject: [PATCH 2/3] Add code to set the thread name --- base/threadutil.cpp | 35 +++++++++++++++++++++++++++++++++++ base/threadutil.h | 3 +++ 2 files changed, 38 insertions(+) create mode 100644 base/threadutil.cpp create mode 100644 base/threadutil.h diff --git a/base/threadutil.cpp b/base/threadutil.cpp new file mode 100644 index 000000000..d8447e039 --- /dev/null +++ b/base/threadutil.cpp @@ -0,0 +1,35 @@ +#ifdef _WIN32 +#include +#endif +#include "base/threadutil.h" + +void setCurrentThreadName(const char* szThreadName) +{ +#ifdef _WIN32 + static const DWORD MS_VC_EXCEPTION = 0x406D1388; + +#pragma pack(push,8) + struct THREADNAME_INFO + { + DWORD dwType; // must be 0x1000 + LPCSTR szName; // pointer to name (in user addr space) + DWORD dwThreadID; // thread ID (-1=caller thread) + DWORD dwFlags; // reserved for future use, must be zero + } info; +#pragma pack(pop) + + info.dwType = 0x1000; + info.szName = szThreadName; + info.dwThreadID = -1; //dwThreadID; + info.dwFlags = 0; + + __try + { + RaiseException(MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info); + } + __except(EXCEPTION_CONTINUE_EXECUTION) + {} +#else + // Do nothing +#endif +} diff --git a/base/threadutil.h b/base/threadutil.h new file mode 100644 index 000000000..15e6a477d --- /dev/null +++ b/base/threadutil.h @@ -0,0 +1,3 @@ +#pragma once + +void setCurrentThreadName(const char *name); \ No newline at end of file From b86a912752df9a792525e0c2d3c148fcdd12cd15 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Fri, 30 Mar 2012 00:45:16 +0200 Subject: [PATCH 3/3] Tweaks --- gfx_es2/glsl_program.cpp | 15 ++++++++++----- math/lin/matrix4x4.cpp | 5 +++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/gfx_es2/glsl_program.cpp b/gfx_es2/glsl_program.cpp index 20b340f3b..3cc6bad08 100644 --- a/gfx_es2/glsl_program.cpp +++ b/gfx_es2/glsl_program.cpp @@ -48,7 +48,7 @@ GLSLProgram *glsl_create(const char *vshader, const char *fshader) { program->program_ = 0; program->vsh_ = 0; program->fsh_ = 0; - strcpy(program->name, vshader + strlen(vshader) - 16); + strcpy(program->name, vshader + strlen(vshader) - 15); strcpy(program->vshader_filename, vshader); strcpy(program->fshader_filename, fshader); if (glsl_recompile(program)) { @@ -82,10 +82,15 @@ void glsl_refresh() { bool glsl_recompile(GLSLProgram *program) { struct stat vs, fs; - stat(program->vshader_filename, &vs); - stat(program->fshader_filename, &fs); - program->vshader_mtime = vs.st_mtime; - program->fshader_mtime = fs.st_mtime; + if (0 == stat(program->vshader_filename, &vs)) + program->vshader_mtime = vs.st_mtime; + else + program->vshader_mtime = 0; + + if (0 == stat(program->fshader_filename, &fs)) + program->fshader_mtime = fs.st_mtime; + else + program->fshader_mtime = 0; size_t sz; char *vsh_src = (char *)VFSReadFile(program->vshader_filename, &sz); diff --git a/math/lin/matrix4x4.cpp b/math/lin/matrix4x4.cpp index a2e7f32c9..14c114076 100644 --- a/math/lin/matrix4x4.cpp +++ b/math/lin/matrix4x4.cpp @@ -5,6 +5,11 @@ #include "math/lin/vec3.h" #include "math/lin/quat.h" +#ifdef _WIN32 +#undef far +#undef near +#endif + // See http://code.google.com/p/oolongengine/source/browse/trunk/Oolong+Engine2/Math/neonmath/neon_matrix_impl.cpp?spec=svn143&r=143 when we need speed // no wait. http://code.google.com/p/math-neon/