diff --git a/.gitignore b/.gitignore index 542b906..bb6b2b7 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,8 @@ build/* 3rdparty/bgfx/3rdparty/dxsdk/** 3rdparty/bgfx/3rdparty/scintilla/** +3rdparty/RuntimeCompiledCpp/Assets/** +3rdparty/RuntimeCompiledCpp/Aurora** +3rdparty/RuntimeCompiledCpp/External/** +3rdparty/RuntimeCompiledCpp/Examples/SimpleTest/** + diff --git a/3rdparty/RuntimeCompiledCpp/CMakeLists.txt b/3rdparty/RuntimeCompiledCpp/CMakeLists.txt new file mode 100644 index 0000000..0467b73 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/CMakeLists.txt @@ -0,0 +1,169 @@ +cmake_minimum_required(VERSION 2.8) + +project( RuntimeCompiledCPlusPlus ) +# +# Options +# +option(BUILD_EXAMPLES "Build example applications" ON) +option(GLFW_SYSTEM "Use the operating system glfw library" OFF) + +find_package(OpenGL REQUIRED) + +if(UNIX AND NOT APPLE) + set(BUILD_TYPE SHARED) +else() + set(BUILD_TYPE STATIC) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +endif() + +include(cmake/ProjectFiles.cmake) + +# +# RuntimeCompiler +# +add_library(RuntimeCompiler ${BUILD_TYPE} ${RuntimeCompiler_SRCS}) + +# +# RuntimeObjectSystem +# +add_library(RuntimeObjectSystem ${BUILD_TYPE} ${RuntimeObjectSystem_SRCS}) +target_link_libraries(RuntimeObjectSystem RuntimeCompiler) +if(UNIX) + target_link_libraries(RuntimeObjectSystem dl) +endif() + +# +# Make Install +# +install(DIRECTORY RuntimeObjectSystem/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include/RuntimeObjectSystem + FILES_MATCHING PATTERN "*.h") +install(DIRECTORY RuntimeCompiler/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include/RuntimeCompiler + FILES_MATCHING PATTERN "*.h") +install(TARGETS RuntimeObjectSystem RuntimeCompiler + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/) + +if(BUILD_EXAMPLES) + + # + # ConsoleExample + # + + add_executable(ConsoleExample ${ConsoleExample_SRCS}) + target_link_libraries(ConsoleExample RuntimeCompiler RuntimeObjectSystem) + + # + # Renderer + # + + add_library(Renderer ${BUILD_TYPE} ${Renderer_SRCS}) + target_link_libraries(Renderer ${OPENGL_LIBRARIES} ${ASSIMP_LIBRARIES}) + + # + # Systems + # + + add_library(Systems ${BUILD_TYPE} ${Systems_SRCS}) + + # + # Freetype WIN32 + # + + if(WIN32) + set(FREETYPE_INCLUDE_DIR_freetype2 ${CMAKE_SOURCE_DIR}/External/support/freetype/include/freetype) + set(FREETYPE_INCLUDE_DIR_ft2build ${CMAKE_SOURCE_DIR}/External/support/freetype/include) + if(${CMAKE_CL_64}) + set(FREETYPE_LIBRARY ${CMAKE_SOURCE_DIR}/External/support/lib/freetype2410MTx64.lib) + else() + set(FREETYPE_LIBRARY ${CMAKE_SOURCE_DIR}/External/support/lib/freetype2410MT.lib) + endif() + elseif(APPLE) + set(FREETYPE_INCLUDE_DIR_freetype2 ${CMAKE_SOURCE_DIR}/External/support/freetype/include/freetype) + set(FREETYPE_INCLUDE_DIR_ft2build ${CMAKE_SOURCE_DIR}/External/support/freetype/include) + FIND_LIBRARY(ZLIB_LIBRARY libs) + MARK_AS_ADVANCED(ZLIB_LIBRARY) + set(FREETYPE_LIBRARY ${CMAKE_SOURCE_DIR}/External/support/lib/MacOSX/libfreetype.a ${ZLIB_LIBRARY}) + endif() + + # + # glfw + # + if(GLFW_SYSTEM) + set(GLFW_LIBRARIES glfw) + else() + include_directories(External/glfw/include) + if(WIN32) + set(GLFW_LIBRARIES glfw winmm) + add_subdirectory( ${CMAKE_SOURCE_DIR}/External/glfw/projects ) + else() + add_library( glfw STATIC IMPORTED ) + if(APPLE) + FIND_LIBRARY(COCOA_LIBRARY Cocoa) + FIND_LIBRARY(IOKIT_LIBRARY IOKit) + MARK_AS_ADVANCED(COCOA_LIBRARY IOKIT_LIBRARY) + set_target_properties( glfw PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/External/glfw/libOSX/libglfw.a ) + set(GLFW_LIBRARIES glfw ${COCOA_LIBRARY} ${IOKIT_LIBRARY}) + else() + set_target_properties( glfw PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/External/glfw/libX11/libglfw.a ) + set(GLFW_LIBRARIES glfw X11 pthread) + endif() + endif() + endif() + + # + # assimp + # + + if(WIN32) + add_library( assimp STATIC IMPORTED ) + set(ASSIMP_LIBRARIES assimp) + if(${CMAKE_CL_64}) + set_target_properties( assimp PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/External/assimp/lib/assimp_release-dll_x64/assimp.lib ) + set(ASSIMP_DLL ${CMAKE_SOURCE_DIR}/External/assimp/bin/assimp_release-dll_win32/Assimp64.dll) + else() + set_target_properties( assimp PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/External/assimp/lib/assimp_release-dll_win32/assimp.lib ) + set(ASSIMP_DLL ${CMAKE_SOURCE_DIR}/External/assimp/bin/assimp_release-dll_win32/Assimp32.dll) + endif() + if(CMAKE_GENERATOR STREQUAL "NMake Makefiles") + file(COPY ${ASSIMP_DLL} DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) + else() + foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) + file(COPY ${ASSIMP_DLL} DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${OUTPUTCONFIG}) + endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES ) + endif() + endif() + + # + # SimpleTest + # + + add_subdirectory(External/libRocket/Build) + include_directories( + ${OPENGL_INCLUDE_DIR} + External/libRocket/Include + External/assimp/include + ) + if(WIN32) + add_executable(SimpleTest WIN32 ${SimpleTest_SRCS}) + else() + add_executable(SimpleTest ${SimpleTest_SRCS}) + endif() + target_link_libraries(SimpleTest + RuntimeCompiler + RuntimeObjectSystem + Renderer + Systems + RocketCore + RocketControls + RocketDebugger + ${OPENGL_LIBRARIES} + ${GLFW_LIBRARIES} + ${ASSIMP_LIBRARIES} + ) + if(MSVC) + set_target_properties(SimpleTest ConsoleExample PROPERTIES COMPILE_FLAGS "/FC") + else() + Set(CMAKE_CXX_FLAGS "-DCOMPILE_PATH=\"\\\"$(PWD)\\\"\"") + endif() +endif() diff --git a/3rdparty/RuntimeCompiledCpp/Common/.project b/3rdparty/RuntimeCompiledCpp/Common/.project new file mode 100644 index 0000000..99b30ec --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Common/.project @@ -0,0 +1,11 @@ + + + Common + + + + + + + + diff --git a/3rdparty/RuntimeCompiledCpp/Common/AUColor.inl b/3rdparty/RuntimeCompiledCpp/Common/AUColor.inl new file mode 100644 index 0000000..ba57182 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Common/AUColor.inl @@ -0,0 +1,55 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once +#ifndef AUCOLOR_DEF +#define AUCOLOR_DEF + +#include // for memcpy on linux + +class AUColor +{ +public: + AUColor(float Red = 0.0f, float Green = 0.0f, float Blue = 0.0f, float Alpha = 0.0f) + { + m_Color.r = Red; + m_Color.g = Green; + m_Color.b = Blue; + m_Color.a = Alpha; + } + + AUColor( const float rgba[4] ) + { + memcpy( m_Color.rgba, rgba, sizeof( m_Color.rgba ) ); + } + + union ColorUnion + { + struct + { + float r; + float g; + float b; + float a; + }; + float rgba[4]; + } m_Color; + +}; + + +#endif //AUCOLOR_DEF \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Common/AUOrientation3D.inl b/3rdparty/RuntimeCompiledCpp/Common/AUOrientation3D.inl new file mode 100644 index 0000000..6d90529 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Common/AUOrientation3D.inl @@ -0,0 +1,184 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once +#ifndef AUDORIENTATION3D_DEFINED +#define AUDORIENTATION3D_DEFINED + +#include "AUVec3f.inl" //interface relies on class AUVec3f +#include //for numerical limits + + +class AUOrientation3D +{ +public: + AUOrientation3D() : + m_v3dForwards( 1.0f, 0.0f, 0.0f ), + m_v3dUp( 0.0f, 1.0f, 0.0f ), + m_v3dRight( 0.0f, 0.0f, 1.0f ) + { + } + + AUOrientation3D( const AUVec3f& v3dForwards_, const AUVec3f& v3dUp_) : + m_v3dForwards( v3dForwards_ ), + m_v3dUp( v3dUp_ ) + { + OrthoNormalise(); + } + + //Inspectors + const AUVec3f& GetForwards() const { return m_v3dForwards; } + const AUVec3f& GetUp() const { return m_v3dUp; } + const AUVec3f& GetRight() const { return m_v3dRight; } + + void LoadglViewMatrix( float *const fglMatrix_ ) const + { + //note: OpenGL camera defaults to looking down -z, thus orient z with Forwards + fglMatrix_[0] = m_v3dRight.x; + fglMatrix_[1] = m_v3dUp.x; + fglMatrix_[2] = -m_v3dForwards.x; + fglMatrix_[3] = 0.0f; + + fglMatrix_[4] = m_v3dRight.y; + fglMatrix_[5] = m_v3dUp.y; + fglMatrix_[6] = -m_v3dForwards.y; + fglMatrix_[7] = 0.0f; + + fglMatrix_[8] = m_v3dRight.z; + fglMatrix_[9] = m_v3dUp.z; + fglMatrix_[10] = -m_v3dForwards.z; + fglMatrix_[11] = 0.0f; + + fglMatrix_[12] = 0.0f; + fglMatrix_[13] = 0.0f; + fglMatrix_[14] = 0.0f; + fglMatrix_[15] = 1.0f; + } + + void LoadglObjectMatrix( float *const fglMatrix_ ) const + { + //note: OpenGL camera defaults to looking down -z, thus orient z with Forwards + fglMatrix_[0] = m_v3dForwards.x; + fglMatrix_[1] = m_v3dForwards.y; + fglMatrix_[2] = m_v3dForwards.z; + fglMatrix_[3] = 0.0f; + + fglMatrix_[4] = m_v3dUp.x; + fglMatrix_[5] = m_v3dUp.y; + fglMatrix_[6] = m_v3dUp.z; + fglMatrix_[7] = 0.0f; + + fglMatrix_[8] = m_v3dRight.x; + fglMatrix_[9] = m_v3dRight.y; + fglMatrix_[10] = m_v3dRight.z; + fglMatrix_[11] = 0.0f; + + fglMatrix_[12] = 0.0f; + fglMatrix_[13] = 0.0f; + fglMatrix_[14] = 0.0f; + fglMatrix_[15] = 1.0f; + } + + //Mutators + AUVec3f& GetForwards() { return m_v3dForwards; } + AUVec3f& GetUp() { return m_v3dUp; } + AUVec3f& GetRight() { return m_v3dRight; } + + void Set( const AUVec3f& v3dForwards_, const AUVec3f& v3dUp_) + { + m_v3dForwards = v3dForwards_; + m_v3dUp = v3dUp_; + OrthoNormalise(); + } + + void Rotate( const AUVec3f& v3dAxis_, float fTheta_) + { + float fCosTheta = static_cast( cos(fTheta_ ) ); + float fSinTheta = static_cast( sin(fTheta_ ) ); + + AUVec3f v3dtemp = v3dAxis_.Cross( m_v3dForwards ); + m_v3dForwards += fSinTheta * v3dtemp + + ( fCosTheta - 1.0f ) * v3dAxis_.Cross( v3dtemp ); + v3dtemp = v3dAxis_.Cross( m_v3dUp ); + m_v3dUp += fSinTheta * v3dtemp + + ( fCosTheta - 1.0f ) * v3dAxis_.Cross( v3dtemp ); + + //orthonormalise coordinate system + OrthoNormalise(); + } + +protected: + void OrthoNormalise() + { + if( true == m_v3dForwards.Normalise() ) + { + //have a normalised forwards vector + m_v3dRight = m_v3dForwards.Cross( m_v3dUp ); + if( true == m_v3dRight.Normalise() ) + { + //and now have a normalised right vector so safe to generate cross. + m_v3dUp = m_v3dRight.Cross( m_v3dForwards ); + } + else + { + //have a forwards vector only, so generate an arbitary `up'. + m_v3dUp.SetX( m_v3dForwards.z ); + m_v3dUp.SetY( m_v3dForwards.x ); + m_v3dUp.SetZ( m_v3dForwards.y ); + + //will now get a 'guaranteed' right from this + m_v3dRight = m_v3dForwards.Cross( m_v3dUp ); + + //and so can generate a true up + m_v3dUp = m_v3dRight.Cross( m_v3dForwards ); + } + } + else + { + //can't use forwards as our main vector, so try up + if( true == m_v3dUp.Normalise() ) + { + //have a up vector only, so generate an arbitary `up'. + m_v3dForwards.SetX( m_v3dUp.z ); + m_v3dForwards.SetY( m_v3dUp.x ); + m_v3dForwards.SetZ( m_v3dUp.y ); + + //will now get a 'guaranteed' right from this + m_v3dRight = m_v3dForwards.Cross( m_v3dUp ); + + //and so can generate a true forwards + m_v3dForwards = m_v3dUp.Cross( m_v3dRight ); + } + else + { + //have no appropriate starting vectors, so fake it. + m_v3dForwards.Set( 1.0f, 0.0f, 0.0f ); + m_v3dUp.Set( 0.0f, 1.0f, 0.0f ); + m_v3dRight.Set( 0.0f, 0.0f, 1.0f ); + } + + } + } + +private: + AUVec3f m_v3dForwards; + AUVec3f m_v3dUp; + AUVec3f m_v3dRight; + +}; + +#endif //AUDORIENTATION3D_DEFINED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Common/AUVec3f.inl b/3rdparty/RuntimeCompiledCpp/Common/AUVec3f.inl new file mode 100644 index 0000000..b79e11f --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Common/AUVec3f.inl @@ -0,0 +1,211 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once +#ifndef AUVEC3F_DEFINED +#define AUVEC3F_DEFINED + +#include +#include + + +class AUVec3f +{ +public: + AUVec3f(float fX_ = 0.0f, float fY_ = 0.0f, float fZ_ = 0.0f) : + x( fX_ ), + y( fY_ ), + z( fZ_ ) + { + + } + + AUVec3f( const AUVec3f& v3din_ ) : + x( v3din_.x ), + y( v3din_.y ), + z( v3din_.z ) + { + } + + //Mutators + void SetX( float fX_ ) { x = fX_; } + void SetY( float fY_ ) { y = fY_; } + void SetZ( float fZ_ ) { z = fZ_; } + void Set( float fX_, float fY_, float fZ_ ) + { + x = fX_; + y = fY_; + z = fZ_; + } + + float Dot( const AUVec3f& V_ ) const + { + return x * V_.x + + y * V_.y + + z * V_.z; + } + + AUVec3f Cross( const AUVec3f& V_ ) const + { + AUVec3f newV( y * V_.z - z * V_.y, + z * V_.x - x * V_.z, + x * V_.y - y * V_.x ); + + return newV; + } + + bool Normalise() + { + float fMagnitude = Magnitude(); + if(fMagnitude != 0.0f) + { + x /= fMagnitude; + y /= fMagnitude; + z /= fMagnitude; + return true; + } + else + { + return false; + } + } + + AUVec3f GetNormalised() const + { + AUVec3f v = *this; + v.Normalise(); + return v; + } + + AUVec3f Lerp( const AUVec3f& V_, float t ) const + { + return (*this + (V_ - *this) * t); + } + + bool IsInfinite() const + { + float inf = std::numeric_limits::infinity(); + return ( x == inf || y == inf || z == inf ); + } + + void SetInfinite() + { + x = y = z = std::numeric_limits::infinity(); + } + + bool IsZero() const + { + return (x == 0.0f && y == 0.0f && z == 0.0f); + } + + //Operators + AUVec3f& operator+=( const AUVec3f& V_ ) + { + x += V_.x; + y += V_.y; + z += V_.z; + return *this; + } + + AUVec3f& operator-=( const AUVec3f& V_ ) + { + x -= V_.x; + y -= V_.y; + z -= V_.z; + return *this; + } + + AUVec3f& operator*=( const float& fScalar_ ) + { + x *= fScalar_; + y *= fScalar_; + z *= fScalar_; + return *this; + } + + AUVec3f& operator/=( const float& fScalar_ ) + { + x /= fScalar_; + y /= fScalar_; + z /= fScalar_; + return *this; + } + + bool operator==( const AUVec3f& V_ ) const + { + return ( x == V_.x ) && ( y == V_.y ) && ( z == V_.z ); + } + + bool operator!=( const AUVec3f& V_ ) const + { + return !(*this == V_); + } + + float Magnitude() const + { + return static_cast( sqrt( Dot( *this ) ) ); + } + + float MagnitudeSqr() const + { + return static_cast( Dot( *this ) ); + } + + AUVec3f operator+( const AUVec3f& V2_ ) const + { + AUVec3f newV_( *this ); + return ( newV_ += V2_ ); + } + + AUVec3f operator-( const AUVec3f& V2_ ) const + { + AUVec3f newV_( *this ); + return ( newV_ -= V2_ ); + } + + AUVec3f operator*( const float& fScalar_ ) const + { + AUVec3f newV_( *this ); + return ( newV_ *= fScalar_ ); + } + + + AUVec3f operator/( const float& fScalar_ ) + { + AUVec3f newV_( *this ); + return ( newV_ /= fScalar_ ); + } + + AUVec3f operator-() + { + AUVec3f newV_( -x, -y, -z ); + return newV_; + } + + float x; + float y; + float z; +}; + + +//functions which do not have to be members +inline AUVec3f operator*( const float& fScalar_, const AUVec3f& V1_ ) +{ + return V1_ * fScalar_; +} + +#endif //AUVEC3F_DEFINED diff --git a/3rdparty/RuntimeCompiledCpp/Common/Common_2010.vcxproj b/3rdparty/RuntimeCompiledCpp/Common/Common_2010.vcxproj new file mode 100644 index 0000000..881fec1 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Common/Common_2010.vcxproj @@ -0,0 +1,141 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + + {2947A63C-A245-4853-B4CC-476354188AEE} + Win32Proj + Common + + + + StaticLibrary + true + Unicode + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + + + + + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + + + + + + + Windows + true + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + + + + + + + Windows + true + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + + + + \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Common/Math.inl b/3rdparty/RuntimeCompiledCpp/Common/Math.inl new file mode 100644 index 0000000..f132258 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Common/Math.inl @@ -0,0 +1,46 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once +#ifndef AUMATH_DEFINED +#define AUMATH_DEFINED + +#define _USE_MATH_DEFINES +#include + +/* Adds some helpful macros and exposes the non-standard constants available in math.h (may not be portable): + * M_E - e + * M_LOG2E - log2(e) + * M_LOG10E - log10(e) + * M_LN2 - ln(2) + * M_LN10 - ln(10) + * M_PI - pi + * M_PI_2 - pi/2 + * M_PI_4 - pi/4 + * M_1_PI - 1/pi + * M_2_PI - 2/pi + * M_2_SQRTPI - 2/sqrt(pi) + * M_SQRT2 - sqrt(2) + * M_SQRT1_2 - 1/sqrt(2) + */ + +#define DEG2RAD(deg) ((deg)*((PI)/(180.0))) +#define RAD2DEG(rad) ((rad)*((180.0)/(PI))) +#define LERP(a, b, t) ((a) + (t) * ((b) - (a))) + + +#endif // AUMATH_DEFINED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/.cproject b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/.cproject new file mode 100644 index 0000000..a56e650 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/.cproject @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/.project b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/.project new file mode 100644 index 0000000..8c515b8 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/.project @@ -0,0 +1,29 @@ + + + ConsoleExample + + + RuntimeCompiler + RuntimeObjectSystem + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/.settings/org.eclipse.cdt.codan.core.prefs b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/.settings/org.eclipse.cdt.codan.core.prefs new file mode 100644 index 0000000..77386c2 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/.settings/org.eclipse.cdt.codan.core.prefs @@ -0,0 +1,67 @@ +eclipse.preferences.version=1 +org.eclipse.cdt.codan.checkers.errnoreturn=Warning +org.eclipse.cdt.codan.checkers.errnoreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},implicit\=>false} +org.eclipse.cdt.codan.checkers.errreturnvalue=Error +org.eclipse.cdt.codan.checkers.errreturnvalue.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.checkers.noreturn=Error +org.eclipse.cdt.codan.checkers.noreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},implicit\=>false} +org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation=Error +org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem=Error +org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem=Warning +org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem=Error +org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem=Warning +org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},no_break_comment\=>"no break",last_case_param\=>false,empty_case_param\=>false} +org.eclipse.cdt.codan.internal.checkers.CatchByReference=Warning +org.eclipse.cdt.codan.internal.checkers.CatchByReference.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},unknown\=>false,exceptions\=>()} +org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem=Error +org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization=Warning +org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},skip\=>true} +org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.InvalidArguments=Error +org.eclipse.cdt.codan.internal.checkers.InvalidArguments.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem=Error +org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem=Error +org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem=Error +org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker=-Info +org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},pattern\=>"^[a-z]",macro\=>true,exceptions\=>()} +org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem=Warning +org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.OverloadProblem=Error +org.eclipse.cdt.codan.internal.checkers.OverloadProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem=Error +org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem=Error +org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem=-Warning +org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem=-Warning +org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem=Warning +org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true,exceptions\=>()} +org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem=Warning +org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},paramNot\=>false} +org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem=Warning +org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},else\=>false,afterelse\=>false} +org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} +org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem=Warning +org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true} +org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem=Warning +org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true} +org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem=Warning +org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true,exceptions\=>("@(\#)","$Id")} +org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/.settings/org.eclipse.cdt.core.prefs b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/.settings/org.eclipse.cdt.core.prefs new file mode 100644 index 0000000..9fc0987 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/.settings/org.eclipse.cdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +environment/project/cdt.managedbuild.config.gnu.exe.debug.1276108983/append=true +environment/project/cdt.managedbuild.config.gnu.exe.debug.1276108983/appendContributed=true +environment/project/cdt.managedbuild.config.gnu.exe.release.190462196/CWD/delimiter=\: +environment/project/cdt.managedbuild.config.gnu.exe.release.190462196/CWD/operation=replace +environment/project/cdt.managedbuild.config.gnu.exe.release.190462196/CWD/value=/media/psf/Home/Documents/Github/dougbinks/RuntimeCompiledCPlusPlus/Aurora/Examples/ConsoleExample/Release +environment/project/cdt.managedbuild.config.gnu.exe.release.190462196/append=true +environment/project/cdt.managedbuild.config.gnu.exe.release.190462196/appendContributed=true diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleExample.cpp b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleExample.cpp new file mode 100644 index 0000000..87e8dbf --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleExample.cpp @@ -0,0 +1,45 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +// ConsoleExample.cpp : simple example using console command line + + +#include "ConsoleGame.h" +#include +#ifdef _WIN32 +#include +#endif + + +int main(int argc, char* argv[]) +{ + ConsoleGame game; + if( game.Init() ) + { + while( game.MainLoop() ) + { + } + } + else + { + std::cout << "\nFailed Initialisation, press a key to exit.\n"; + _getche(); + } + + std::cout << "Exiting...\n"; + return 0; +} \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleExample.vcxproj b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleExample.vcxproj new file mode 100644 index 0000000..cc384f6 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleExample.vcxproj @@ -0,0 +1,178 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {B95544FF-96D5-4395-8E62-C02A512534D7} + Win32Proj + ConsoleExample + + + + Application + true + Unicode + + + Application + true + Unicode + + + Application + false + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + + + true + + + Console + true + RuntimeObjectSystem.lib;RuntimeCompiler_VS2010.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)$(Configuration); + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + + + true + + + Console + true + RuntimeObjectSystem.lib;RuntimeCompiler_VS2010.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)$(Platform)\$(Configuration)\ + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + true + + + Console + true + true + true + RuntimeObjectSystem.lib;RuntimeCompiler_VS2010.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)$(Configuration); + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + true + + + Console + true + true + true + RuntimeObjectSystem.lib;RuntimeCompiler_VS2010.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)$(Platform)\$(Configuration)\ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleExample.vcxproj.filters b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleExample.vcxproj.filters new file mode 100644 index 0000000..c94815f --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleExample.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + + + + Runtime Modifiable + + + + + + + + + + + \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleExample.xcodeproj/project.pbxproj b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleExample.xcodeproj/project.pbxproj new file mode 100644 index 0000000..b4d8889 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleExample.xcodeproj/project.pbxproj @@ -0,0 +1,252 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 91977BBD16EB398A003FAE7A /* libRuntimeCompiler.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 91977BBB16EB398A003FAE7A /* libRuntimeCompiler.a */; }; + 91977BBE16EB398A003FAE7A /* libRuntimeObjectSystem.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 91977BBC16EB398A003FAE7A /* libRuntimeObjectSystem.a */; }; + 91DE41E7161B1BB800BE0D16 /* ConsoleExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91DE41DF161B1BB800BE0D16 /* ConsoleExample.cpp */; }; + 91DE41E8161B1BB800BE0D16 /* ConsoleGame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91DE41E0161B1BB800BE0D16 /* ConsoleGame.cpp */; }; + 91DE41E9161B1BB800BE0D16 /* RuntimeObject01.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91DE41E4161B1BB800BE0D16 /* RuntimeObject01.cpp */; }; + 91DE41EA161B1BB800BE0D16 /* StdioLogSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91DE41E5161B1BB800BE0D16 /* StdioLogSystem.cpp */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 91A171CC161B175E004B5954 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 12; + dstPath = ""; + dstSubfolderSpec = 16; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 91977BBB16EB398A003FAE7A /* libRuntimeCompiler.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libRuntimeCompiler.a; path = "../../../../../../../Library/Developer/Xcode/DerivedData/Aurora-amgiihqkoasuvzdugsovjupxbfdk/Build/Products/Debug/libRuntimeCompiler.a"; sourceTree = ""; }; + 91977BBC16EB398A003FAE7A /* libRuntimeObjectSystem.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libRuntimeObjectSystem.a; path = "../../../../../../../Library/Developer/Xcode/DerivedData/Aurora-amgiihqkoasuvzdugsovjupxbfdk/Build/Products/Debug/libRuntimeObjectSystem.a"; sourceTree = ""; }; + 91A171CE161B175E004B5954 /* ConsoleExample */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ConsoleExample; sourceTree = BUILT_PRODUCTS_DIR; }; + 91DE41DF161B1BB800BE0D16 /* ConsoleExample.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConsoleExample.cpp; sourceTree = ""; }; + 91DE41E0161B1BB800BE0D16 /* ConsoleGame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConsoleGame.cpp; sourceTree = ""; }; + 91DE41E1161B1BB800BE0D16 /* ConsoleGame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConsoleGame.h; sourceTree = ""; }; + 91DE41E2161B1BB800BE0D16 /* InterfaceIds.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InterfaceIds.h; sourceTree = ""; }; + 91DE41E3161B1BB800BE0D16 /* IUpdateable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IUpdateable.h; sourceTree = ""; }; + 91DE41E4161B1BB800BE0D16 /* RuntimeObject01.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuntimeObject01.cpp; sourceTree = ""; }; + 91DE41E5161B1BB800BE0D16 /* StdioLogSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StdioLogSystem.cpp; sourceTree = ""; }; + 91DE41E6161B1BB800BE0D16 /* StdioLogSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StdioLogSystem.h; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 91A171CB161B175E004B5954 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 91977BBD16EB398A003FAE7A /* libRuntimeCompiler.a in Frameworks */, + 91977BBE16EB398A003FAE7A /* libRuntimeObjectSystem.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 91A171C3161B175E004B5954 = { + isa = PBXGroup; + children = ( + 91977BBB16EB398A003FAE7A /* libRuntimeCompiler.a */, + 91977BBC16EB398A003FAE7A /* libRuntimeObjectSystem.a */, + 91DE41DF161B1BB800BE0D16 /* ConsoleExample.cpp */, + 91DE41E0161B1BB800BE0D16 /* ConsoleGame.cpp */, + 91DE41E1161B1BB800BE0D16 /* ConsoleGame.h */, + 91DE41E2161B1BB800BE0D16 /* InterfaceIds.h */, + 91DE41E3161B1BB800BE0D16 /* IUpdateable.h */, + 91DE41E4161B1BB800BE0D16 /* RuntimeObject01.cpp */, + 91DE41E5161B1BB800BE0D16 /* StdioLogSystem.cpp */, + 91DE41E6161B1BB800BE0D16 /* StdioLogSystem.h */, + 91A171CF161B175E004B5954 /* Products */, + ); + sourceTree = ""; + }; + 91A171CF161B175E004B5954 /* Products */ = { + isa = PBXGroup; + children = ( + 91A171CE161B175E004B5954 /* ConsoleExample */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 91A171CD161B175E004B5954 /* ConsoleExample */ = { + isa = PBXNativeTarget; + buildConfigurationList = 91A171D8161B175E004B5954 /* Build configuration list for PBXNativeTarget "ConsoleExample" */; + buildPhases = ( + 91A171CA161B175E004B5954 /* Sources */, + 91A171CB161B175E004B5954 /* Frameworks */, + 91A171CC161B175E004B5954 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ConsoleExample; + productName = ConsoleExample; + productReference = 91A171CE161B175E004B5954 /* ConsoleExample */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 91A171C5161B175E004B5954 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0440; + ORGANIZATIONNAME = "Doug Binks"; + }; + buildConfigurationList = 91A171C8161B175E004B5954 /* Build configuration list for PBXProject "ConsoleExample" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 91A171C3161B175E004B5954; + productRefGroup = 91A171CF161B175E004B5954 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 91A171CD161B175E004B5954 /* ConsoleExample */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 91A171CA161B175E004B5954 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 91DE41E7161B1BB800BE0D16 /* ConsoleExample.cpp in Sources */, + 91DE41E8161B1BB800BE0D16 /* ConsoleGame.cpp in Sources */, + 91DE41E9161B1BB800BE0D16 /* RuntimeObject01.cpp in Sources */, + 91DE41EA161B1BB800BE0D16 /* StdioLogSystem.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 91A171D6161B175E004B5954 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + ../../External/boost, + ../External/boost, + ); + LIBRARY_SEARCH_PATHS = ""; + MACOSX_DEPLOYMENT_TARGET = 10.8; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + 91A171D7161B175E004B5954 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + ../../External/boost, + ../External/boost, + ); + LIBRARY_SEARCH_PATHS = ""; + MACOSX_DEPLOYMENT_TARGET = 10.8; + SDKROOT = macosx; + }; + name = Release; + }; + 91A171D9161B175E004B5954 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + HEADER_SEARCH_PATHS = ../../External/boost; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "\"$(SRCROOT)/../../External/boost/stage/libOSX\"", + "\"$(SRCROOT)/../../../../../../../Library/Developer/Xcode/DerivedData/Aurora-amgiihqkoasuvzdugsovjupxbfdk/Build/Products/Debug\"", + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = ""; + }; + name = Debug; + }; + 91A171DA161B175E004B5954 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + HEADER_SEARCH_PATHS = ../../External/boost; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "\"$(SRCROOT)/../../External/boost/stage/libOSX\"", + "\"$(SRCROOT)/../../../../../../../Library/Developer/Xcode/DerivedData/Aurora-amgiihqkoasuvzdugsovjupxbfdk/Build/Products/Debug\"", + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = ""; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 91A171C8161B175E004B5954 /* Build configuration list for PBXProject "ConsoleExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 91A171D6161B175E004B5954 /* Debug */, + 91A171D7161B175E004B5954 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 91A171D8161B175E004B5954 /* Build configuration list for PBXNativeTarget "ConsoleExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 91A171D9161B175E004B5954 /* Debug */, + 91A171DA161B175E004B5954 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 91A171C5161B175E004B5954 /* Project object */; +} diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..e6be109 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleGame.cpp b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleGame.cpp new file mode 100644 index 0000000..cac5c55 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleGame.cpp @@ -0,0 +1,175 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "ConsoleGame.h" + + +#include "../../RuntimeCompiler/AUArray.h" +#include "../../RuntimeCompiler/BuildTool.h" +#include "../../RuntimeCompiler/ICompilerLogger.h" +#include "../../RuntimeCompiler/FileChangeNotifier.h" +#include "../../RuntimeObjectSystem/IObjectFactorySystem.h" +#include "../../RuntimeObjectSystem/ObjectFactorySystem/ObjectFactorySystem.h" +#include "../../RuntimeObjectSystem/RuntimeObjectSystem.h" + +#include "StdioLogSystem.h" + +#include "../../RuntimeObjectSystem/IObject.h" +#include "IUpdateable.h" +#include "InterfaceIds.h" + +#include +#ifdef WIN32 +#include +#include +#else +#include +int _getche() +{ + int ret = getchar(); + return ret; +} +int _kbhit() +{ + std::cout << "This port needs a fix, CTRL-C to quit\n"; + return 0; +} + +int Sleep( int msecs ) +{ + return usleep( msecs * 1000); +} +#endif +#include +#include +#include +#include +#include + +// Remove windows.h define of GetObject which conflicts with EntitySystem GetObject +#if defined _WINDOWS_ && defined GetObject +#undef GetObject +#endif +using FileSystemUtils::Path; + +ConsoleGame::ConsoleGame() + : m_pCompilerLogger(0) + , m_pRuntimeObjectSystem(0) + , m_pUpdateable(0) +{ +} + +ConsoleGame::~ConsoleGame() +{ + if( m_pRuntimeObjectSystem ) + { + // clean temp object files + m_pRuntimeObjectSystem->CleanObjectFiles(); + } + + if( m_pRuntimeObjectSystem && m_pRuntimeObjectSystem->GetObjectFactorySystem() ) + { + m_pRuntimeObjectSystem->GetObjectFactorySystem()->RemoveListener(this); + + // delete object via correct interface + IObject* pObj = m_pRuntimeObjectSystem->GetObjectFactorySystem()->GetObject( m_ObjectId ); + delete pObj; + } + + delete m_pRuntimeObjectSystem; + delete m_pCompilerLogger; +} + + +bool ConsoleGame::Init() +{ + //Initialise the RuntimeObjectSystem + m_pRuntimeObjectSystem = new RuntimeObjectSystem; + m_pCompilerLogger = new StdioLogSystem(); + if( !m_pRuntimeObjectSystem->Initialise(m_pCompilerLogger, 0) ) + { + m_pRuntimeObjectSystem = 0; + return false; + } + m_pRuntimeObjectSystem->GetObjectFactorySystem()->AddListener(this); + + + // construct first object + IObjectConstructor* pCtor = m_pRuntimeObjectSystem->GetObjectFactorySystem()->GetConstructor( "RuntimeObject01" ); + if( pCtor ) + { + IObject* pObj = pCtor->Construct(); + pObj->GetInterface( &m_pUpdateable ); + if( 0 == m_pUpdateable ) + { + delete pObj; + m_pCompilerLogger->LogError("Error - no updateable interface found\n"); + return false; + } + m_ObjectId = pObj->GetObjectId(); + + } + + return true; +} + +void ConsoleGame::OnConstructorsAdded() +{ + // This could have resulted in a change of object pointer, so release old and get new one. + if( m_pUpdateable ) + { + IObject* pObj = m_pRuntimeObjectSystem->GetObjectFactorySystem()->GetObject( m_ObjectId ); + pObj->GetInterface( &m_pUpdateable ); + if( 0 == m_pUpdateable ) + { + delete pObj; + m_pCompilerLogger->LogError( "Error - no updateable interface found\n"); + } + } +} + + + +bool ConsoleGame::MainLoop() +{ + //check status of any compile + if( m_pRuntimeObjectSystem->GetIsCompiledComplete() ) + { + // load module when compile complete + m_pRuntimeObjectSystem->LoadCompiledModule(); + } + + if( !m_pRuntimeObjectSystem->GetIsCompiling() ) + { + static int numUpdates = 0; + std::cout << "\nMain Loop - press q to quit. Updates every second. Update: " << numUpdates++ << "\n"; + if( _kbhit() ) + { + int ret = _getche(); + if( 'q' == ret ) + { + return false; + } + } + const float deltaTime = 1.0f; + m_pRuntimeObjectSystem->GetFileChangeNotifier()->Update( deltaTime ); + m_pUpdateable->Update( deltaTime ); + Sleep(1000); + } + + return true; +} diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleGame.h b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleGame.h new file mode 100644 index 0000000..432b74d --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/ConsoleGame.h @@ -0,0 +1,64 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef CONSOLEGAME_INCLUDED +#define CONSOLEGAME_INCLUDED + +#include "../../RuntimeObjectSystem/IObjectFactorySystem.h" +#include "../../RuntimeObjectSystem/ObjectInterface.h" +#include "../../RuntimeCompiler/AUArray.h" + +#ifndef _WIN32 +int _getche(); +#endif + + +struct IUpdateable; +struct IRuntimeObjectSystem; + +class ConsoleGame : public IObjectFactoryListener +{ +public: + ConsoleGame(); + virtual ~ConsoleGame(); + + bool Init(); + bool MainLoop(); + + + // IObjectFactoryListener + + virtual void OnConstructorsAdded(); + + // ~IObjectFactoryListener + + +private: + + // Runtime Systems + ICompilerLogger* m_pCompilerLogger; + IRuntimeObjectSystem* m_pRuntimeObjectSystem; + + // Runtime object + IUpdateable* m_pUpdateable; + ObjectId m_ObjectId; + +}; + +#endif // CONSOLEGAME_INCLUDED diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/IUpdateable.h b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/IUpdateable.h new file mode 100644 index 0000000..e12e477 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/IUpdateable.h @@ -0,0 +1,30 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef IUPDATEABLE_INCLUDED +#define IUPDATEABLE_INCLUDED + +#include "../../RuntimeObjectSystem/IObject.h" + +struct IUpdateable : public IObject +{ + virtual void Update( float deltaTime ) = 0; +}; + +#endif // IUPDATEABLE_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/InterfaceIds.h b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/InterfaceIds.h new file mode 100644 index 0000000..771e839 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/InterfaceIds.h @@ -0,0 +1,41 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +//////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// InterfaceId header file. +// +// Specifys interface ids for getting hold of interfaces +// +//////////////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#ifndef INTERFACEIDS_INCLUDED +#define INTERFACEIDS_INCLUDED + +#include "../../RuntimeObjectSystem/IObject.h" + +enum InterfaceIDEnumConsoleExample +{ + IID_IUPDATEABLE = IID_ENDInterfaceID, + + IID_ENDInterfaceIDEnumConsoleExample +}; + + +#endif //INTERFACEIDS_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/RuntimeObject01.cpp b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/RuntimeObject01.cpp new file mode 100644 index 0000000..7e602d2 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/RuntimeObject01.cpp @@ -0,0 +1,18 @@ +#include "../../RuntimeObjectSystem/ObjectInterfacePerModule.h" + +#include "../../RuntimeObjectSystem/IObject.h" +#include "IUpdateable.h" +#include "InterfaceIds.h" +#include + + +class RuntimeObject01 : public TInterface +{ +public: + virtual void Update( float deltaTime ) + { + std::cout << "Runtime Object 01231 update called!\n"; + } +}; + +REGISTERCLASS(RuntimeObject01); diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/StdioLogSystem.cpp b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/StdioLogSystem.cpp new file mode 100644 index 0000000..b9001d2 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/StdioLogSystem.cpp @@ -0,0 +1,62 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "StdioLogSystem.h" + +// Currently we create the file on first real output, and only close it on shutdown + +#include +#include +#include + +#ifdef _WIN32 + #include "Windows.h" + #pragma warning( disable : 4996 4800 ) +#endif + + +void StdioLogSystem::LogError(const char * format, ...) +{ + va_list args; + va_start(args, format); + LogInternal(format, args); +} + +void StdioLogSystem::LogWarning(const char * format, ...) +{ + va_list args; + va_start(args, format); + LogInternal(format, args); +} + +void StdioLogSystem::LogInfo(const char * format, ...) +{ + va_list args; + va_start(args, format); + LogInternal(format, args); +} +void StdioLogSystem::LogInternal(const char * format, va_list args) +{ + int result = vsnprintf(m_buff, LOGSYSTEM_MAX_BUFFER-1, format, args); + // Make sure there's a limit to the amount of rubbish we can output + m_buff[LOGSYSTEM_MAX_BUFFER-1] = '\0'; + + std::cout << m_buff; +#ifdef _WIN32 + OutputDebugStringA( m_buff ); +#endif +} diff --git a/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/StdioLogSystem.h b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/StdioLogSystem.h new file mode 100644 index 0000000..1de4138 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/StdioLogSystem.h @@ -0,0 +1,45 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef STDIOLOGSYSTEM_INCLUDED +#define STDIOLOGSYSTEM_INCLUDED + +#include "../../RuntimeCompiler/ICompilerLogger.h" + +#include +#include + +// StdioLogSystem for compiler + +const size_t LOGSYSTEM_MAX_BUFFER = 4096; + +class StdioLogSystem : public ICompilerLogger +{ +public: + virtual void LogError(const char * format, ...); + virtual void LogWarning(const char * format, ...); + virtual void LogInfo(const char * format, ...); + +protected: + void LogInternal(const char * format, va_list args); + char m_buff[LOGSYSTEM_MAX_BUFFER]; +}; + + +#endif //STDIOLOGSYSTEM_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Renderer/.cproject b/3rdparty/RuntimeCompiledCpp/Renderer/.cproject new file mode 100644 index 0000000..41d8619 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Renderer/.cproject @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/3rdparty/RuntimeCompiledCpp/Renderer/.project b/3rdparty/RuntimeCompiledCpp/Renderer/.project new file mode 100644 index 0000000..f90c1bc --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Renderer/.project @@ -0,0 +1,27 @@ + + + Renderer + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/3rdparty/RuntimeCompiledCpp/Renderer/.settings/org.eclipse.cdt.managedbuilder.core.prefs b/3rdparty/RuntimeCompiledCpp/Renderer/.settings/org.eclipse.cdt.managedbuilder.core.prefs new file mode 100644 index 0000000..be844b5 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Renderer/.settings/org.eclipse.cdt.managedbuilder.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.lib.debug.608542581/CPATH/delimiter=\: +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.lib.debug.608542581/CPATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.lib.debug.608542581/CPLUS_INCLUDE_PATH/delimiter=\: +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.lib.debug.608542581/CPLUS_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.lib.debug.608542581/C_INCLUDE_PATH/delimiter=\: +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.lib.debug.608542581/C_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.lib.debug.608542581/append=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.lib.debug.608542581/appendContributed=true diff --git a/3rdparty/RuntimeCompiledCpp/Renderer/AURenMesh.cpp b/3rdparty/RuntimeCompiledCpp/Renderer/AURenMesh.cpp new file mode 100644 index 0000000..0954edd --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Renderer/AURenMesh.cpp @@ -0,0 +1,438 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + + +#include "AURenMesh.h" + + +#ifndef _WIN32 + #define NO_ASSIMP //Currently not adding assimp support to other platforms +#endif + + +#include "../Common/AUVec3f.inl" //for cross product used in calculateing normals + +// Windows Requirements +#ifdef _WIN32 + #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers + #include +#endif //_WIN32 + + +#ifdef __MACH__ +#include +#else +// OpenGL requirements +#include +#endif //__MACH__ + +#ifndef NO_ASSIMP + #include + #include + #include +#endif //NO_ASSIMP + +#ifndef _WIN32 +#include +int _stricmp( const char* pS1, const char* pS2 ) +{ + return strcasecmp( pS1, pS2 ); +} +#endif + +#include +#include + +AURenMesh::AURenMesh() : + m_pafVertexCoordinates( NULL ), + m_pafTextureCoordinates( NULL ), + m_pafNormals( NULL ), + m_pausTriangleIndices( NULL ), + m_uiNumVertices( 0 ), + m_uiNumTriangles( 0 ) +{ +} + +AURenMesh::~AURenMesh() +{ + Clear(); +} + +void AURenMesh::Clear() +{ + delete[] m_pafNormals; + delete[] m_pafVertexCoordinates; + delete[] m_pafTextureCoordinates; + delete[] m_pausTriangleIndices; +} + +bool AURenMesh::LoadFromFile( const std::string& strFilename ) +{ + // Safely delete any existing data before loading new mesh + Clear(); + + int index = (int)strFilename.size() - 3; + std::string extension = index >= 0 ? strFilename.substr(index, 3) : ""; + if (!_stricmp(extension.c_str(), "aml")) + { + return LoadFromFileAML(strFilename); + } + else + { + return LoadFromFileImport(strFilename); + } +} + +bool AURenMesh::SaveToFile( const std::string& strFilename ) +{ + std::ofstream outFile; + outFile.open(strFilename.c_str(), std::ios::binary); + + if( !outFile ) + { + return false; + } + + outFile << "AML Aurora File" << std::endl; + outFile << 1 << std::endl; // version + outFile << m_uiNumVertices << std::endl; + outFile << m_uiNumTriangles << std::endl; + + outFile.write( reinterpret_cast( m_pafVertexCoordinates ), 3 * m_uiNumVertices * sizeof( float ) ); + outFile.write( reinterpret_cast( m_pafTextureCoordinates ), 2 * m_uiNumVertices * sizeof( float ) ); + outFile.write( reinterpret_cast( m_pafNormals ), 3 * m_uiNumVertices * sizeof( float ) ); + outFile.write( reinterpret_cast( m_pausTriangleIndices ), 3 * m_uiNumTriangles * sizeof( unsigned short ) ); + + outFile.close(); + + return true; +} + +bool AURenMesh::LoadFromFileAML( const std::string& strFilename_ ) +{ + std::ifstream inFile; + inFile.open(strFilename_.c_str(), std::ios::binary); + + if( !inFile ) + { + return false; + } + + inFile.ignore(10000,'\n'); //ignore first line + + int iVersion; + inFile >> iVersion; //currently ignore version number + + inFile >> m_uiNumVertices; + + inFile >> m_uiNumTriangles; + + //now discard end of line + inFile.ignore(10000,'\n'); + + m_pafVertexCoordinates = new float[ 3 * m_uiNumVertices ]; + m_pafNormals = new float[ 3 * m_uiNumVertices ]; + m_pafTextureCoordinates = new float[ 2 * m_uiNumVertices ]; + m_pausTriangleIndices = new unsigned short[ 3 * m_uiNumTriangles ]; + + inFile.read( reinterpret_cast( m_pafVertexCoordinates ), 3 * m_uiNumVertices * sizeof( float ) ); + inFile.read( reinterpret_cast( m_pafTextureCoordinates ), 2 * m_uiNumVertices * sizeof( float ) ); + inFile.read( reinterpret_cast( m_pafNormals ), 3 * m_uiNumVertices * sizeof( float ) ); + inFile.read( reinterpret_cast( m_pausTriangleIndices ), 3 * m_uiNumTriangles * sizeof( unsigned short ) ); + + + return true; +} + +bool AURenMesh::LoadFromFileImport( const std::string& strFilename ) +{ +#ifndef NO_ASSIMP + Assimp::Importer importer; + + const aiScene* pScene = importer.ReadFile( strFilename, aiProcessPreset_TargetRealtime_Fast ); + + if (!pScene || pScene->mNumMeshes == 0) + { + return false; + } + + ProcessScene(pScene); + + return true; +#else + assert( false ); + return false; +#endif +} + +void AURenMesh::ProcessScene( const aiScene* pScene ) +{ +#ifndef NO_ASSIMP + // Calculate total number of verts and tris across all meshes in scene + m_uiNumVertices = 0; + m_uiNumTriangles = 0; + for (unsigned int i=0; imNumMeshes; ++i) + { + aiMesh* pMesh = pScene->mMeshes[i]; + m_uiNumVertices += pMesh->mNumVertices; + m_uiNumTriangles += pMesh->mNumFaces; + } + + // Allocate sufficent space for all data + m_pafVertexCoordinates = new float[ 3 * m_uiNumVertices ]; + m_pafNormals = new float[ 3 * m_uiNumVertices ]; + m_pafTextureCoordinates = new float[ 2 * m_uiNumVertices ]; + m_pausTriangleIndices = new unsigned short[ 3 * m_uiNumTriangles ]; + + // Iterate through all meshes and load data + int vertIndex = 0; + int normalIndex = 0; + int texIndex = 0; + int triIndex = 0; + for (unsigned int i=0; imNumMeshes; ++i) + { + aiMesh* pMesh = pScene->mMeshes[i]; + + // Load Verts + for (unsigned int j=0; jmNumVertices; ++j) + { + const aiVector3D& vec = pMesh->mVertices[j]; + m_pafVertexCoordinates[vertIndex] = vec.x; + m_pafVertexCoordinates[vertIndex+1] = vec.y; + m_pafVertexCoordinates[vertIndex+2] = vec.z; + vertIndex += 3; + } + + // Load Normals + for (unsigned int j=0; jmNumVertices; ++j) + { + const aiVector3D& vec = pMesh->mNormals[j]; + m_pafNormals[normalIndex] = vec.x; + m_pafNormals[normalIndex+1] = vec.y; + m_pafNormals[normalIndex+2] = vec.z; + normalIndex += 3; + } + + // Load Tex Coords + if (pMesh->HasTextureCoords(0)) + { + for (unsigned int j=0; jmNumVertices; ++j) + { + const aiVector3D& vec = pMesh->mTextureCoords[0][j]; + m_pafTextureCoordinates[texIndex] = vec.x; + m_pafTextureCoordinates[texIndex+1] = vec.y; + texIndex += 2; + } + } + + + // Load Tris + for (unsigned int j=0; jmNumFaces; ++j) + { + const aiFace& tri = pMesh->mFaces[j]; + m_pausTriangleIndices[triIndex] = tri.mIndices[0]; + m_pausTriangleIndices[triIndex+1] = tri.mIndices[1]; + m_pausTriangleIndices[triIndex+2] = tri.mIndices[2]; + triIndex += 3; + } + } +#endif +} + +////////////////////////////////////////////////////////////////////////////////////////// +// Function: AURenMesh::AURenMesh +// +// Last Modified by: Douglas John Binks (DJB) +// +// Last Modified: 21 June 2000 +// +// Purpose: Normalises the size and position of the object to be +// centered around the origin and of the correct BCube extent. +// +// Inputs: fBCubeHalfWidth_ : float giving the half width of the +// bounding cube. +// +// Outputs: None. +// +// Returns: None. +// +////////////////////////////////////////////////////////////////////////////////////////// +void AURenMesh::NormaliseToBCubeHalfWidth( float fBCubeHalfWidth_ ) +{ + //set up min and max variablse for each axis and use a real value from the + //array to initialise (as a `made up' value may be wrong unless we use + //floatmax for min etc.). + float fMinX = m_pafVertexCoordinates[0]; + float fMaxX = m_pafVertexCoordinates[0]; + float fMinY = m_pafVertexCoordinates[1]; + float fMaxY = m_pafVertexCoordinates[1]; + float fMinZ = m_pafVertexCoordinates[2]; + float fMaxZ = m_pafVertexCoordinates[2]; + + //Go through array of vertices to find the real min and max + unsigned int uiCountCoords; + for( uiCountCoords = 0; + uiCountCoords < 3 * m_uiNumVertices; + uiCountCoords += 3 ) + { + if( fMinX > m_pafVertexCoordinates[ uiCountCoords ] ) + { + fMinX = m_pafVertexCoordinates[ uiCountCoords ]; + } + else + { + if( fMaxX < m_pafVertexCoordinates[ uiCountCoords ] ) + { + fMaxX = m_pafVertexCoordinates[ uiCountCoords ]; + } + } + + if( fMinY > m_pafVertexCoordinates[ uiCountCoords + 1 ] ) + { + fMinY = m_pafVertexCoordinates[ uiCountCoords + 1 ]; + } + else + { + if( fMaxY < m_pafVertexCoordinates[ uiCountCoords + 1 ] ) + { + fMaxY = m_pafVertexCoordinates[ uiCountCoords + 1 ]; + } + } + + if( fMinZ > m_pafVertexCoordinates[ uiCountCoords + 2 ] ) + { + fMinZ = m_pafVertexCoordinates[ uiCountCoords + 2 ]; + } + else + { + if( fMaxZ < m_pafVertexCoordinates[ uiCountCoords + 2 ] ) + { + fMaxZ = m_pafVertexCoordinates[ uiCountCoords + 2 ]; + } + } + } + + //calulate the current center + float fCenterX = ( fMaxX + fMinX )/2.0f; + float fCenterY = ( fMaxY + fMinY )/2.0f; + float fCenterZ = ( fMaxZ + fMinZ )/2.0f; + + //calculate the largest distance^2 from the center + float fMaxDistance2 = 0.0f; + float fDistance2; + float fX2, fY2, fZ2; + for( uiCountCoords = 0; + uiCountCoords < 3 * m_uiNumVertices; + uiCountCoords += 3 ) + { + fX2 = m_pafVertexCoordinates[ uiCountCoords ] - fCenterX; + fX2 *= fX2; + fY2 = m_pafVertexCoordinates[ uiCountCoords + 1 ] - fCenterY; + fY2 *= fY2; + fZ2 = m_pafVertexCoordinates[ uiCountCoords + 2 ] - fCenterZ; + fZ2 *= fZ2; + fDistance2 = fX2 + fY2 + fZ2; + if( fDistance2 > fMaxDistance2 ) + { + fMaxDistance2 = fDistance2; + } + } + + //calculate normalising coefficient such that Xnew = cf * Xold + float fCoefficient = fBCubeHalfWidth_ / sqrt( fMaxDistance2 ); + + //now do normalisation ( use seperate calcs for X,Y,Z so as to use possible + //parallel floating point units). + for( uiCountCoords = 0; + uiCountCoords < 3 * m_uiNumVertices; + uiCountCoords += 3 ) + { + m_pafVertexCoordinates[ uiCountCoords ] = + fCoefficient * ( m_pafVertexCoordinates[ uiCountCoords ] - fCenterX ); + m_pafVertexCoordinates[ uiCountCoords + 1 ] = + fCoefficient * ( m_pafVertexCoordinates[ uiCountCoords + 1 ] - fCenterY ); + m_pafVertexCoordinates[ uiCountCoords + 2 ] = + fCoefficient * ( m_pafVertexCoordinates[ uiCountCoords + 2 ] - fCenterZ ); + } + +} + +////////////////////////////////////////////////////////////////////////////////////////// +// Function: AURenMesh::Render +// +// Last Modified by: Douglas John Binks (DJB) +// +// Last Modified: 25 July 2000 +// +// Purpose: Draws the mesh. +// +// Inputs: None. +// +// Outputs: None. +// +// Returns: None. +// +////////////////////////////////////////////////////////////////////////////////////////// +void AURenMesh::Render(const AUColor* pCol ) const +{ + if( 0 == m_uiNumVertices ) + { + return; + } + + const GLfloat pafDiffuseColor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + const GLfloat pafSpecularColor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + const GLfloat fShininess = 40.0f; + + + if( 0 == pCol ) + { + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, pafDiffuseColor); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pafDiffuseColor); + } + else + { + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, pCol->m_Color.rgba ); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pCol->m_Color.rgba); + } + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pafSpecularColor); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, fShininess); + + const GLint iNumCoordinatesPerVertex = 3; + const GLsizei iStride = 0; + + //set up vertex arrays + glEnableClientState( GL_VERTEX_ARRAY ); + glEnableClientState( GL_NORMAL_ARRAY ); + glVertexPointer( iNumCoordinatesPerVertex, GL_FLOAT, iStride, + (const GLvoid*)m_pafVertexCoordinates ); + glNormalPointer( GL_FLOAT, iStride, + (const GLvoid*)m_pafNormals ); + glEnableClientState( GL_TEXTURE_COORD_ARRAY ); + glTexCoordPointer( 2, GL_FLOAT, iStride, + (const GLvoid*)m_pafTextureCoordinates ); + + //do actual drawing + glDrawElements( GL_TRIANGLES, 3 * m_uiNumTriangles, GL_UNSIGNED_SHORT, m_pausTriangleIndices ); + + + //unset vertex arrays + glDisableClientState( GL_TEXTURE_COORD_ARRAY ); + glDisableClientState( GL_VERTEX_ARRAY ); + glDisableClientState( GL_NORMAL_ARRAY ); + +} diff --git a/3rdparty/RuntimeCompiledCpp/Renderer/AURenMesh.h b/3rdparty/RuntimeCompiledCpp/Renderer/AURenMesh.h new file mode 100644 index 0000000..8971808 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Renderer/AURenMesh.h @@ -0,0 +1,85 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once +#ifndef AURENDMESH_DEF +#define AURENDMESH_DEF + +#include +#include "../Common/AUColor.inl" +#include "IAURenderable.h" + +struct aiScene; + +class AURenMesh +{ +public: + AURenMesh(); + bool LoadFromFile( const std::string& strFilename ); + bool SaveToFile( const std::string& strFilename ); // Saves as AML + virtual ~AURenMesh(); + + void NormaliseToBCubeHalfWidth( float fBCubeHalfWidth ); + void Render( const AUColor* pCol = 0 ) const; + +protected: + bool LoadFromFileAML( const std::string& strFilename ); // For native AML format + bool LoadFromFileImport( const std::string& strFilename ); // Use AssImp library for other formats + void ProcessScene( const aiScene* pScene ); // Convert AssImp imported scene into internal data structures + void Clear(); + float* m_pafVertexCoordinates; + float* m_pafTextureCoordinates; + float* m_pafNormals; + unsigned short* m_pausTriangleIndices; + unsigned int m_uiNumVertices; + unsigned int m_uiNumTriangles; + +}; + +class AURenderableMesh : public IAURenderableMesh +{ +public: + AURenderableMesh( AURenMesh* pMesh ) : + m_pMesh( pMesh ), + m_Color( 1.0f, 1.0f, 1.0f, 1.0f ) + { + } + + virtual const AUColor& GetColor() const + { + return m_Color; + } + virtual void SetColor( const AUColor& color ) + { + m_Color = color; + } + + virtual void Render() const + { + m_pMesh->Render( &m_Color ); + } + + AURenMesh* GetMesh() + { + return m_pMesh; + } +private: + AURenMesh* m_pMesh; + AUColor m_Color; +}; + +#endif //AURENDMESH_DEF diff --git a/3rdparty/RuntimeCompiledCpp/Renderer/AURenderContext.cpp b/3rdparty/RuntimeCompiledCpp/Renderer/AURenderContext.cpp new file mode 100644 index 0000000..8ef3c55 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Renderer/AURenderContext.cpp @@ -0,0 +1,82 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "AURenderContext.h" + +#include "IAURenderable.h" + +// Windows Requirements +#ifdef _WIN32 + #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers + #include +#endif //_WIN32 + +#ifdef __MACH__ +#include +#else +// OpenGL requirements +#include +#endif //__MACH__ + + +AURenderContext::AURenderContext() +{ +} + + +AURenderContext::~AURenderContext() +{ +} + +AUDynArray g_entities; + +void AURenderContext::Render( IEntitySystem* pEntitySystem ) +{ + //loop through setting matrices and calling render. + pEntitySystem->GetAll( g_entities ); + + for( size_t i = 0; i < g_entities.Size(); ++i ) + { + + IAUEntity* pEntity = pEntitySystem->Get( g_entities[ i ] ); + IAURenderable* pRenderable = pEntity->GetRenderable(); + if( pRenderable ) + { + glPushMatrix(); + + glMatrixMode(GL_MODELVIEW); + + // Translation + const AUVec3f& t = pEntity->GetPosition(); + glTranslatef( t.x, t.y, t.z ); + + // Rotation + float fglMatrix[16]; + pEntity->GetOrientation().LoadglObjectMatrix(fglMatrix); + glMultMatrixf(fglMatrix); + + // Scale + glEnable(GL_NORMALIZE); // Needed so normals don't get wrecked by scaling - not sure how costly it is though + const AUVec3f& s = pEntity->GetScale(); + glScalef( s.x, s.y, s.z ); + + pRenderable->Render(); + glPopMatrix(); + } + } + +} \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Renderer/AURenderContext.h b/3rdparty/RuntimeCompiledCpp/Renderer/AURenderContext.h new file mode 100644 index 0000000..1f83ce7 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Renderer/AURenderContext.h @@ -0,0 +1,29 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once +#include "../Systems/IEntitySystem.h" + +class AURenderContext +{ +public: + AURenderContext(); + ~AURenderContext(); + + void Render( IEntitySystem* pEntitySystem ); +}; + diff --git a/3rdparty/RuntimeCompiledCpp/Renderer/IAURenderable.h b/3rdparty/RuntimeCompiledCpp/Renderer/IAURenderable.h new file mode 100644 index 0000000..d751a2a --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Renderer/IAURenderable.h @@ -0,0 +1,37 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once +#ifndef IAURENDMESH_DEF +#define IAURENDMESH_DEF + +#include "../Common/AUColor.inl" + +struct IAURenderable +{ + virtual ~IAURenderable() {} + + virtual void Render() const = 0; //should not be publically exposed. +}; + +struct IAURenderableMesh : public IAURenderable +{ + virtual const AUColor& GetColor() const = 0; + virtual void SetColor( const AUColor& color ) = 0; +}; + +#endif //IAURENDMESH_DEF \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Renderer/Renderer.xcodeproj/project.pbxproj b/3rdparty/RuntimeCompiledCpp/Renderer/Renderer.xcodeproj/project.pbxproj new file mode 100644 index 0000000..12743d3 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Renderer/Renderer.xcodeproj/project.pbxproj @@ -0,0 +1,218 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 910A9D8C1623026D0032E310 /* AURenderContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 910A9D861623026D0032E310 /* AURenderContext.cpp */; }; + 910A9D8D1623026D0032E310 /* AURenderContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 910A9D871623026D0032E310 /* AURenderContext.h */; }; + 910A9D8E1623026D0032E310 /* AURenMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 910A9D881623026D0032E310 /* AURenMesh.cpp */; }; + 910A9D8F1623026D0032E310 /* AURenMesh.h in Headers */ = {isa = PBXBuildFile; fileRef = 910A9D891623026D0032E310 /* AURenMesh.h */; }; + 910A9D911623026D0032E310 /* IAURenderable.h in Headers */ = {isa = PBXBuildFile; fileRef = 910A9D8B1623026D0032E310 /* IAURenderable.h */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 910A9D7C162302540032E310 /* libRenderer.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRenderer.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 910A9D861623026D0032E310 /* AURenderContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AURenderContext.cpp; sourceTree = ""; }; + 910A9D871623026D0032E310 /* AURenderContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AURenderContext.h; sourceTree = ""; }; + 910A9D881623026D0032E310 /* AURenMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AURenMesh.cpp; sourceTree = ""; }; + 910A9D891623026D0032E310 /* AURenMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AURenMesh.h; sourceTree = ""; }; + 910A9D8B1623026D0032E310 /* IAURenderable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IAURenderable.h; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 910A9D79162302540032E310 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 910A9D71162302540032E310 = { + isa = PBXGroup; + children = ( + 910A9D861623026D0032E310 /* AURenderContext.cpp */, + 910A9D871623026D0032E310 /* AURenderContext.h */, + 910A9D881623026D0032E310 /* AURenMesh.cpp */, + 910A9D891623026D0032E310 /* AURenMesh.h */, + 910A9D8B1623026D0032E310 /* IAURenderable.h */, + 910A9D7D162302540032E310 /* Products */, + ); + sourceTree = ""; + }; + 910A9D7D162302540032E310 /* Products */ = { + isa = PBXGroup; + children = ( + 910A9D7C162302540032E310 /* libRenderer.a */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 910A9D7A162302540032E310 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 910A9D8D1623026D0032E310 /* AURenderContext.h in Headers */, + 910A9D8F1623026D0032E310 /* AURenMesh.h in Headers */, + 910A9D911623026D0032E310 /* IAURenderable.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 910A9D7B162302540032E310 /* Renderer */ = { + isa = PBXNativeTarget; + buildConfigurationList = 910A9D80162302540032E310 /* Build configuration list for PBXNativeTarget "Renderer" */; + buildPhases = ( + 910A9D78162302540032E310 /* Sources */, + 910A9D79162302540032E310 /* Frameworks */, + 910A9D7A162302540032E310 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Renderer; + productName = Renderer; + productReference = 910A9D7C162302540032E310 /* libRenderer.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 910A9D73162302540032E310 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0440; + ORGANIZATIONNAME = "Doug Binks"; + }; + buildConfigurationList = 910A9D76162302540032E310 /* Build configuration list for PBXProject "Renderer" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 910A9D71162302540032E310; + productRefGroup = 910A9D7D162302540032E310 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 910A9D7B162302540032E310 /* Renderer */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 910A9D78162302540032E310 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 910A9D8C1623026D0032E310 /* AURenderContext.cpp in Sources */, + 910A9D8E1623026D0032E310 /* AURenMesh.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 910A9D7E162302540032E310 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.8; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + 910A9D7F162302540032E310 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.8; + SDKROOT = macosx; + }; + name = Release; + }; + 910A9D81162302540032E310 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + EXECUTABLE_PREFIX = lib; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = ""; + }; + name = Debug; + }; + 910A9D82162302540032E310 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + EXECUTABLE_PREFIX = lib; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = ""; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 910A9D76162302540032E310 /* Build configuration list for PBXProject "Renderer" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 910A9D7E162302540032E310 /* Debug */, + 910A9D7F162302540032E310 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 910A9D80162302540032E310 /* Build configuration list for PBXNativeTarget "Renderer" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 910A9D81162302540032E310 /* Debug */, + 910A9D82162302540032E310 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 910A9D73162302540032E310 /* Project object */; +} diff --git a/3rdparty/RuntimeCompiledCpp/Renderer/Renderer.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/3rdparty/RuntimeCompiledCpp/Renderer/Renderer.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..0596502 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Renderer/Renderer.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/3rdparty/RuntimeCompiledCpp/Renderer/Renderer_VS2010.vcxproj b/3rdparty/RuntimeCompiledCpp/Renderer/Renderer_VS2010.vcxproj new file mode 100644 index 0000000..d8f47df --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Renderer/Renderer_VS2010.vcxproj @@ -0,0 +1,191 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + + + {26DDDB96-4A8E-4A1B-997C-970DE0CCCE37} + Win32Proj + Renderer + + + + StaticLibrary + true + Unicode + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + GLEW_STATIC ;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + $(SolutionDir)\External\glew-1.6.0\include;$(SolutionDir)\External\libRocket\Include;$(SolutionDir)\External\assimp\include;$(SolutionDir)\External\Independant JPEG Group\jpeg-6b\;%(AdditionalIncludeDirectories) + false + + + Windows + true + + + opengl32.lib;glu32.lib;assimp.lib; + $(SolutionDir)\External\assimp\lib\assimp_release-dll_win32 + + + xcopy /y "$(SolutionDir)\External\assimp\bin\assimp_release-dll_win32\*.dll" "$(OutDir)" + + + copy dlls for assimp + + + + + + + Level3 + Disabled + GLEW_STATIC ;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + $(SolutionDir)\External\glew-1.6.0\include;$(SolutionDir)\External\libRocket\Include;$(SolutionDir)\External\assimp\include;$(SolutionDir)\External\Independant JPEG Group\jpeg-6b\;%(AdditionalIncludeDirectories) + false + + + Windows + true + + + opengl32.lib;glu32.lib;assimp.lib; + $(SolutionDir)\External\assimp\lib\assimp_release-dll_x64 + + + xcopy /y "$(SolutionDir)\External\assimp\bin\assimp_release-dll_win32\*.dll" "$(OutDir)" + + + copy dlls for assimp + + + + + Level3 + + + MaxSpeed + true + true + GLEW_STATIC ;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + $(SolutionDir)\External\glew-1.6.0\include;$(SolutionDir)\External\libRocket\Include;$(SolutionDir)\External\assimp\include;$(SolutionDir)\External\Independant JPEG Group\jpeg-6b\;%(AdditionalIncludeDirectories) + false + + + Windows + true + true + true + + + opengl32.lib;glu32.lib;assimp.lib + $(SolutionDir)\External\assimp\lib\assimp_release-dll_win32 + + + xcopy /y "$(SolutionDir)\External\assimp\bin\assimp_release-dll_win32\*.dll" "$(OutDir)" + + + copy dlls for assimp + + + + + Level3 + + + MaxSpeed + true + true + GLEW_STATIC ;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + $(SolutionDir)\External\glew-1.6.0\include;$(SolutionDir)\External\libRocket\Include;$(SolutionDir)\External\assimp\include;$(SolutionDir)\External\Independant JPEG Group\jpeg-6b\;%(AdditionalIncludeDirectories) + false + + + Windows + true + true + true + + + opengl32.lib;glu32.lib;assimp.lib + $(SolutionDir)\External\assimp\lib\assimp_release-dll_x64 + + + xcopy /y "$(SolutionDir)\External\assimp\bin\assimp_release-dll_win32\*.dll" "$(OutDir)" + + + copy dlls for assimp + + + + + + \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/.cproject b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/.cproject new file mode 100644 index 0000000..06d44ad --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/.cproject @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/.project b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/.project new file mode 100644 index 0000000..8164332 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/.project @@ -0,0 +1,27 @@ + + + RuntimeCompiler + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/AUArray.h b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/AUArray.h new file mode 100644 index 0000000..873598d --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/AUArray.h @@ -0,0 +1,93 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once +#ifndef AUARRAY_DEFINED +#define AUARRAY_DEFINED + +#include +#include + + +// Here we define a semi-virtualised wrapper for a vector-like object so that it can +// be used to pass results across DLL boundaries including resizing without memory +// manager problems. +// Ideally it should not use std::vector as this may not work if one side was compiled +// using debug and the other optimised. + +template class IAUDynArray +{ +protected: + IAUDynArray() {} + ~IAUDynArray() {} + +public: + virtual void Resize(size_t size) = 0; + + virtual void Add(const T& item) = 0; + + size_t Size() const + { + return m_vec.size(); + } + + void Clear() + { + Resize(0); + } + + T& operator[] (size_t i) + { + return m_vec[i]; + } + + const T& operator[] (size_t i) const + { + return m_vec[i]; + } + +protected: + std::vector m_vec; +}; + + +template class AUDynArray : public IAUDynArray +{ +public: + AUDynArray(size_t size = 0) + { + this->m_vec.resize(size); + } + + ~AUDynArray() + { + // Ensure this code is created, despite the templates + Resize(0); + } + + void Resize(size_t size) + { + this->m_vec.resize(size); + } + + void Add(const T& item) + { + this->m_vec.push_back(item); + } +}; + +#endif //AUARRAY_DEFINED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/BuildTool.cpp b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/BuildTool.cpp new file mode 100644 index 0000000..43569f7 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/BuildTool.cpp @@ -0,0 +1,126 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "BuildTool.h" +#include "Compiler.h" +#include +#include +#include "ICompilerLogger.h" + +using namespace std; +using namespace FileSystemUtils; + +BuildTool::BuildTool() +{ +} + + +BuildTool::~BuildTool() +{ +} + +void BuildTool::Clean( const FileSystemUtils::Path& temporaryPath_ ) const +{ + // Remove any existing intermediate directory + FileSystemUtils::PathIterator pathIter( temporaryPath_ ); + std::string obj_extension = m_Compiler.GetObjectFileExtension(); + while( ++pathIter ) + { + if( pathIter.GetPath().Extension() == obj_extension ) + { + if( m_pLogger ) + { + m_pLogger->LogInfo( "Deleting temp RCC++ obj file: %s\n", pathIter.GetPath().c_str() ); + } + pathIter.GetPath().Remove(); + } + } +} + + +void BuildTool::Initialise( ICompilerLogger * pLogger ) +{ + m_pLogger = pLogger; + m_Compiler.Initialise(pLogger); +} + +void BuildTool::BuildModule( const std::vector& buildFileList_, + const CompilerOptions& compilerOptions_, + std::vector linkLibraryList_, + const FileSystemUtils::Path& moduleName_ ) +{ + // Initial version is very basic, simply compiles them. + Path objectFileExtension = m_Compiler.GetObjectFileExtension(); + vector compileFileList; // List of files we pass to the compiler + compileFileList.reserve( buildFileList_.size() ); + vector forcedCompileFileList; // List of files which must be compiled even if object file exists + vector nonForcedCompileFileList; // List of files which can be linked if already compiled + + // Seperate into seperate file lists of force and non-forced, + // so we can ensure we don't have the same file in both + for( size_t i = 0; i < buildFileList_.size(); ++i ) + { + Path buildFile = buildFileList_[i].filePath; + if( buildFileList_[i].forceCompile ) + { + if( find( forcedCompileFileList.begin(), forcedCompileFileList.end(), buildFile ) == forcedCompileFileList.end() ) + { + forcedCompileFileList.push_back( buildFile ); + } + } + else + { + if( find( nonForcedCompileFileList.begin(), nonForcedCompileFileList.end(), buildFile ) == nonForcedCompileFileList.end() ) + { + nonForcedCompileFileList.push_back( buildFile ); + } + } + } + + // Add all forced compile files to build list + for( size_t i = 0; i < forcedCompileFileList.size(); ++i ) + { + compileFileList.push_back( forcedCompileFileList[i] ); + } + + // runtime folder needs to be aware of compilation level and debug/ + + // Add non forced files, but only if they don't exist in forced compile list + for( size_t i = 0; i < nonForcedCompileFileList.size(); ++i ) + { + Path buildFile = nonForcedCompileFileList[i]; + if( find( forcedCompileFileList.begin(), forcedCompileFileList.end(), buildFile ) == forcedCompileFileList.end() ) + { + // Check if we have a pre-compiled object version of this file, and if so use that. + Path objectFileName = compilerOptions_.intermediatePath / buildFile.Filename(); + objectFileName.ReplaceExtension(objectFileExtension.c_str()); + + if( objectFileName.Exists() && buildFile.Exists() ) + { + FileSystemUtils::filetime_t objTime = objectFileName.GetLastWriteTime(); + if( objTime > buildFile.GetLastWriteTime() ) + { + // we only want to use the object file if it's newer than the source file + buildFile = objectFileName; + } + } + compileFileList.push_back(buildFile); + } + } + + m_Compiler.RunCompile( compileFileList, compilerOptions_, linkLibraryList_, moduleName_ ); +} diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/BuildTool.h b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/BuildTool.h new file mode 100644 index 0000000..4abefa1 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/BuildTool.h @@ -0,0 +1,72 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#include +#include +#include "Compiler.h" + +#include "FileSystemUtils.h" + +class BuildTool +{ +public: + BuildTool(); + ~BuildTool(); + void Initialise( ICompilerLogger * pLogger ); + + // Clean - cleans up the intermediate files + void Clean( const FileSystemUtils::Path& temporaryPath_ ) const; + + struct FileToBuild + { + FileToBuild( const FileSystemUtils::Path& filePath_ ) + : filePath( filePath_ ) + , forceCompile( false ) + { + } + FileToBuild( const FileSystemUtils::Path& filePath_, bool forceCompile_ ) + : filePath( filePath_ ) + , forceCompile( forceCompile_ ) + { + } + FileSystemUtils::Path filePath; + bool forceCompile; //if true the file is compiled even if object file is present + }; + + void BuildModule( const std::vector& buildFileList_, + const CompilerOptions& compilerOptions_, + std::vector linkLibraryList_, + const FileSystemUtils::Path& moduleName_ ); + + bool GetIsComplete() + { + return m_Compiler.GetIsComplete(); + } + + void SetFastCompileMode( bool bFast ) + { + m_Compiler.SetFastCompileMode( bFast ); + } + + +private: + Compiler m_Compiler; + ICompilerLogger* m_pLogger; +}; + diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/CompileOptions.h b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/CompileOptions.h new file mode 100644 index 0000000..bba72e3 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/CompileOptions.h @@ -0,0 +1,49 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +enum RCppOptimizationLevel +{ + RCCPPOPTIMIZATIONLEVEL_DEFAULT = 0, // RCCPPOPTIMIZATIONLEVEL_DEBUG in DEBUG, RCCPPOPTIMIZATIONLEVEL_PERF in release. This is the default state. + RCCPPOPTIMIZATIONLEVEL_DEBUG, // Low optimization, improve debug experiece. Default in DEBUG + RCCPPOPTIMIZATIONLEVEL_PERF, // Optimization for performance, debug experience may suffer. Default in RELEASE + RCCPPOPTIMIZATIONLEVEL_NOT_SET, // No optimization set in compile, so either underlying compiler default or set through SetAdditionalCompileOptions + RCCPPOPTIMIZATIONLEVEL_SIZE, // Size of enum, do not use to set opt level +}; + +static const char* RCppOptimizationLevelStrings[] = +{ + "DEFAULT", + "DEBUG", + "PERF", + "NOT_SET", +}; + +// GetActualOptimizationLevel - translates DEFAULT into DEUG or PERF +inline RCppOptimizationLevel GetActualOptimizationLevel( RCppOptimizationLevel optimizationLevel_ ) +{ + if( RCCPPOPTIMIZATIONLEVEL_DEFAULT == optimizationLevel_ ) + { + #ifdef _DEBUG + optimizationLevel_ = RCCPPOPTIMIZATIONLEVEL_DEBUG; + #else + optimizationLevel_ = RCCPPOPTIMIZATIONLEVEL_PERF; + #endif + } + return optimizationLevel_; +} \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/Compiler.h b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/Compiler.h new file mode 100644 index 0000000..3c0f71f --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/Compiler.h @@ -0,0 +1,73 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#include +#include + +#include "FileSystemUtils.h" +#include "CompileOptions.h" + +class PlatformCompilerImplData; +struct ICompilerLogger; + +struct CompilerOptions +{ + std::vector includeDirList; + std::vector libraryDirList; + std::string compileOptions; + std::string linkOptions; + RCppOptimizationLevel optimizationLevel; + FileSystemUtils::Path baseIntermediatePath; + FileSystemUtils::Path intermediatePath; + FileSystemUtils::Path compilerLocation; +}; + +class Compiler +{ +public: + Compiler(); + ~Compiler(); + void Initialise( ICompilerLogger * pLogger ); + + // On Win32 the compile command line process can be preserved in between compiles for improved performance, + // however this can result in Zombie processes and also prevent handles such as sockets from being closed. + // This function is safe to call at any time, but will only have an effect on Win32 compiles from the second + // compile on after the call (as the first must launch the process and set the VS environment). + // + // Defaults to m_bFastCompileMode = false + void SetFastCompileMode( bool bFast ) + { + m_bFastCompileMode = bFast; + + // call GetIsComplete() to ensure this stops process + GetIsComplete(); + } + + std::string GetObjectFileExtension() const; + void RunCompile( const std::vector& filesToCompile_, + const CompilerOptions& compilerOptions_, + std::vector linkLibraryList_, + const FileSystemUtils::Path& moduleName_ ); + + + bool GetIsComplete() const; +private: + PlatformCompilerImplData* m_pImplData; + bool m_bFastCompileMode; +}; diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/Compiler_PlatformPosix.cpp b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/Compiler_PlatformPosix.cpp new file mode 100644 index 0000000..a1deba0 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/Compiler_PlatformPosix.cpp @@ -0,0 +1,290 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +// +// Notes: +// - We use a single intermediate directory for compiled .obj files, which means +// we don't support compiling multiple files with the same name. Could fix this +// with either mangling names to include paths, or recreating folder structure +// +// + +#include "Compiler.h" + +#include +#include +#include + +#include +#include + +#include "assert.h" +#include + +#include "ICompilerLogger.h" + +using namespace std; +const char c_CompletionToken[] = "_COMPLETION_TOKEN_" ; + +class PlatformCompilerImplData +{ +public: + PlatformCompilerImplData() + : m_bCompileIsComplete( false ) + , m_pLogger( 0 ) + , m_ChildForCompilationPID( 0 ) + { + m_PipeStdOut[0] = 0; + m_PipeStdOut[1] = 1; + m_PipeStdErr[0] = 0; + m_PipeStdErr[1] = 1; + } + + volatile bool m_bCompileIsComplete; + ICompilerLogger* m_pLogger; + pid_t m_ChildForCompilationPID; + int m_PipeStdOut[2]; + int m_PipeStdErr[2]; +}; + +Compiler::Compiler() + : m_pImplData( 0 ) +{ +} + +Compiler::~Compiler() +{ + delete m_pImplData; +} + +std::string Compiler::GetObjectFileExtension() const +{ + return ".o"; +} + +bool Compiler::GetIsComplete() const +{ + if( !m_pImplData->m_bCompileIsComplete && m_pImplData->m_ChildForCompilationPID ) + { + + // check for whether process is closed + int procStatus; + pid_t ret = waitpid( m_pImplData->m_ChildForCompilationPID, &procStatus, WNOHANG); + if( ret && ( WIFEXITED(procStatus) || WIFSIGNALED(procStatus) ) ) + { + m_pImplData->m_bCompileIsComplete = true; + m_pImplData->m_ChildForCompilationPID = 0; + + // get output and log + if( m_pImplData->m_pLogger ) + { + const size_t buffSize = 256 * 80; //should allow for a few lines... + char buffer[buffSize]; + ssize_t numread = 0; + while( ( numread = read( m_pImplData->m_PipeStdOut[0], buffer, buffSize-1 ) ) > 0 ) + { + buffer[numread] = 0; + m_pImplData->m_pLogger->LogInfo( buffer ); + } + + while( ( numread = read( m_pImplData->m_PipeStdErr[0], buffer, buffSize-1 ) )> 0 ) + { + buffer[numread] = 0; + m_pImplData->m_pLogger->LogError( buffer ); //TODO: seperate warnings from errors. + } + } + + // close the pipes as this process no longer needs them. + close( m_pImplData->m_PipeStdOut[0] ); + m_pImplData->m_PipeStdOut[0] = 0; + close( m_pImplData->m_PipeStdErr[0] ); + m_pImplData->m_PipeStdErr[0] = 0; + } + } + return m_pImplData->m_bCompileIsComplete; +} + +void Compiler::Initialise( ICompilerLogger * pLogger ) +{ + m_pImplData = new PlatformCompilerImplData; + m_pImplData->m_pLogger = pLogger; +} + +void Compiler::RunCompile( const std::vector& filesToCompile_, + const CompilerOptions& compilerOptions_, + std::vector linkLibraryList_, + const FileSystemUtils::Path& moduleName_ ) + +{ + const std::vector& includeDirList = compilerOptions_.includeDirList; + const std::vector& libraryDirList = compilerOptions_.libraryDirList; + const char* pCompileOptions = compilerOptions_.compileOptions.c_str(); + const char* pLinkOptions = compilerOptions_.linkOptions.c_str(); + + std::string compilerLocation = compilerOptions_.compilerLocation.m_string; + if (compilerLocation.size()==0){ +#ifdef __clang__ + compilerLocation = "clang++ "; +#else // default to g++ + compilerLocation = "g++ "; +#endif //__clang__ + } + + //NOTE: Currently doesn't check if a prior compile is ongoing or not, which could lead to memory leaks + m_pImplData->m_bCompileIsComplete = false; + + //create pipes + if ( pipe( m_pImplData->m_PipeStdOut ) != 0 ) + { + if( m_pImplData->m_pLogger ) + { + m_pImplData->m_pLogger->LogError( "Error in Compiler::RunCompile, cannot create pipe - perhaps insufficient memory?\n"); + } + return; + } + //create pipes + if ( pipe( m_pImplData->m_PipeStdErr ) != 0 ) + { + if( m_pImplData->m_pLogger ) + { + m_pImplData->m_pLogger->LogError( "Error in Compiler::RunCompile, cannot create pipe - perhaps insufficient memory?\n"); + } + return; + } + + pid_t retPID; + switch( retPID = fork() ) + { + case -1: // error, no fork + if( m_pImplData->m_pLogger ) + { + m_pImplData->m_pLogger->LogError( "Error in Compiler::RunCompile, cannot fork() process - perhaps insufficient memory?\n"); + } + return; + case 0: // child process - carries on below. + break; + default: // current process - returns to allow application to run whilst compiling + close( m_pImplData->m_PipeStdOut[1] ); + m_pImplData->m_PipeStdOut[1] = 0; + close( m_pImplData->m_PipeStdErr[1] ); + m_pImplData->m_PipeStdErr[1] = 0; + m_pImplData->m_ChildForCompilationPID = retPID; + return; + } + + //duplicate the pipe to stdout, so output goes to pipe + dup2( m_pImplData->m_PipeStdErr[1], STDERR_FILENO ); + dup2( m_pImplData->m_PipeStdOut[1], STDOUT_FILENO ); + close( m_pImplData->m_PipeStdOut[0] ); + m_pImplData->m_PipeStdOut[0] = 0; + close( m_pImplData->m_PipeStdErr[0] ); + m_pImplData->m_PipeStdErr[0] = 0; + + std::string compileString = compilerLocation + " " + "-g -fPIC -fvisibility=hidden -shared "; + +#ifndef __LP64__ + compileString += "-m32 "; +#endif + + RCppOptimizationLevel optimizationLevel = GetActualOptimizationLevel( compilerOptions_.optimizationLevel ); + switch( optimizationLevel ) + { + case RCCPPOPTIMIZATIONLEVEL_DEFAULT: + assert(false); + case RCCPPOPTIMIZATIONLEVEL_DEBUG: + compileString += "-O0 "; + break; + case RCCPPOPTIMIZATIONLEVEL_PERF: + compileString += "-Os "; + break; + case RCCPPOPTIMIZATIONLEVEL_NOT_SET:; + } + + // Check for intermediate directory, create it if required + // There are a lot more checks and robustness that could be added here + if( !compilerOptions_.intermediatePath.Exists() ) + { + bool success = compilerOptions_.intermediatePath.CreateDir(); + if( success && m_pImplData->m_pLogger ) { m_pImplData->m_pLogger->LogInfo("Created intermediate folder \"%s\"\n", compilerOptions_.intermediatePath.c_str()); } + else if( m_pImplData->m_pLogger ) { m_pImplData->m_pLogger->LogError("Error creating intermediate folder \"%s\"\n", compilerOptions_.intermediatePath.c_str()); } + } + + FileSystemUtils::Path output = moduleName_; + bool bCopyOutput = false; + if( compilerOptions_.intermediatePath.Exists() ) + { + // add save object files + compileString = "cd \"" + compilerOptions_.intermediatePath.m_string + "\"\n" + compileString + " --save-temps "; + output = compilerOptions_.intermediatePath / "a.out"; + bCopyOutput = true; + } + + + // include directories + for( size_t i = 0; i < includeDirList.size(); ++i ) + { + compileString += "-I\"" + includeDirList[i].m_string + "\" "; + } + + // library and framework directories + for( size_t i = 0; i < libraryDirList.size(); ++i ) + { + compileString += "-L\"" + libraryDirList[i].m_string + "\" "; + compileString += "-F\"" + libraryDirList[i].m_string + "\" "; + } + + if( !bCopyOutput ) + { + // output file + compileString += "-o " + output.m_string + " "; + } + + + if( pCompileOptions ) + { + compileString += pCompileOptions; + compileString += " "; + } + if( pLinkOptions && strlen(pLinkOptions) ) + { + compileString += "-Wl,"; + compileString += pLinkOptions; + compileString += " "; + } + + // files to compile + for( size_t i = 0; i < filesToCompile_.size(); ++i ) + { + compileString += "\"" + filesToCompile_[i].m_string + "\" "; + } + + // libraries to link + for( size_t i = 0; i < linkLibraryList_.size(); ++i ) + { + compileString += " " + linkLibraryList_[i].m_string + " "; + } + + if( bCopyOutput ) + { + compileString += "\n mv \"" + output.m_string + "\" \"" + moduleName_.m_string + "\"\n"; + } + + + std::cout << compileString << std::endl << std::endl; + + execl("/bin/sh", "sh", "-c", compileString.c_str(), (const char*)NULL); +} diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/Compiler_PlatformWindows.cpp b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/Compiler_PlatformWindows.cpp new file mode 100644 index 0000000..4a90b26 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/Compiler_PlatformWindows.cpp @@ -0,0 +1,567 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +// RuntimeDLLTest01.cpp : Defines the entry point for the console application. +// +// Notes: +// - We use a single intermediate directory for compiled .obj files, which means +// we don't support compiling multiple files with the same name. Could fix this +// with either mangling names to include paths, or recreating folder structure +// +// + +#include "Compiler.h" + +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include +#include "FileSystemUtils.h" + +#include "assert.h" +#include + +#include "ICompilerLogger.h" + +using namespace std; +using namespace FileSystemUtils; + +struct VSVersionInfo +{ + int Version; + std::string Path; +}; + +const std::string c_CompletionToken( "_COMPLETION_TOKEN_" ); + +void GetPathsOfVisualStudioInstalls( std::vector* pVersions ); + +void ReadAndHandleOutputThread( LPVOID arg ); +void WriteInput( HANDLE hPipeWrite, std::string& input ); + +class PlatformCompilerImplData +{ +public: + PlatformCompilerImplData() + : m_bCompileIsComplete( false ) + , m_CmdProcessOutputRead( NULL ) + , m_CmdProcessInputWrite( NULL ) + { + ZeroMemory( &m_CmdProcessInfo, sizeof(m_CmdProcessInfo) ); + } + + void InitialiseProcess() + { + //init compile process + STARTUPINFOW si; + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof(si); + +#ifndef _WIN64 + std::string cmdSetParams = "@PROMPT $ \n\"" + m_VSPath + "Vcvarsall.bat\" x86\n"; +#else + std::string cmdSetParams = "@PROMPT $ \n\"" + m_VSPath + "Vcvarsall.bat\" x86_amd64\n"; +#endif + // Set up the security attributes struct. + SECURITY_ATTRIBUTES sa; + sa.nLength= sizeof(SECURITY_ATTRIBUTES); + sa.lpSecurityDescriptor = NULL; + sa.bInheritHandle = TRUE; + + + // Create the child output pipe. + //redirection of output + si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; + si.wShowWindow = SW_HIDE; + HANDLE hOutputReadTmp = NULL, hOutputWrite = NULL, hErrorWrite = NULL; + if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,20*1024)) + { + if( m_pLogger ) m_pLogger->LogError("[RuntimeCompiler] Failed to create output redirection pipe\n"); + goto ERROR_EXIT; + } + si.hStdOutput = hOutputWrite; + + // Create a duplicate of the output write handle for the std error + // write handle. This is necessary in case the child application + // closes one of its std output handles. + if (!DuplicateHandle(GetCurrentProcess(),hOutputWrite, + GetCurrentProcess(),&hErrorWrite,0, + TRUE,DUPLICATE_SAME_ACCESS)) + { + if( m_pLogger ) m_pLogger->LogError("[RuntimeCompiler] Failed to duplicate error output redirection pipe\n"); + goto ERROR_EXIT; + } + si.hStdError = hErrorWrite; + + + // Create new output read handle and the input write handles. Set + // the Properties to FALSE. Otherwise, the child inherits the + // properties and, as a result, non-closeable handles to the pipes + // are created. + if( si.hStdOutput ) + { + if (!DuplicateHandle(GetCurrentProcess(),hOutputReadTmp, + GetCurrentProcess(), + &m_CmdProcessOutputRead, // Address of new handle. + 0,FALSE, // Make it uninheritable. + DUPLICATE_SAME_ACCESS)) + { + if( m_pLogger ) m_pLogger->LogError("[RuntimeCompiler] Failed to duplicate output read pipe\n"); + goto ERROR_EXIT; + } + CloseHandle( hOutputReadTmp ); + hOutputReadTmp = NULL; + } + + + HANDLE hInputRead,hInputWriteTmp; + // Create a pipe for the child process's STDIN. + if (!CreatePipe(&hInputRead, &hInputWriteTmp, &sa, 4096)) + { + if( m_pLogger ) m_pLogger->LogError("[RuntimeCompiler] Failed to create input pipes\n"); + goto ERROR_EXIT; + } + si.hStdInput = hInputRead; + + // Create new output read handle and the input write handles. Set + // the Properties to FALSE. Otherwise, the child inherits the + // properties and, as a result, non-closeable handles to the pipes + // are created. + if( si.hStdOutput ) + { + if (!DuplicateHandle(GetCurrentProcess(),hInputWriteTmp, + GetCurrentProcess(), + &m_CmdProcessInputWrite, // Address of new handle. + 0,FALSE, // Make it uninheritable. + DUPLICATE_SAME_ACCESS)) + { + if( m_pLogger ) m_pLogger->LogError("[RuntimeCompiler] Failed to duplicate input write pipe\n"); + goto ERROR_EXIT; + } + } + /* + // Ensure the write handle to the pipe for STDIN is not inherited. + if ( !SetHandleInformation(hInputWrite, HANDLE_FLAG_INHERIT, 0) ) + { + m_pLogger->LogError("[RuntimeCompiler] Failed to make input write pipe non inheritable\n"); + goto ERROR_EXIT; + } + */ + + wchar_t* pCommandLine = L"cmd /q"; + //CreateProcessW won't accept a const pointer, so copy to an array + wchar_t pCmdLineNonConst[1024]; + wcscpy_s( pCmdLineNonConst, pCommandLine ); + CreateProcessW( + NULL, //__in_opt LPCTSTR lpApplicationName, + pCmdLineNonConst, //__inout_opt LPTSTR lpCommandLine, + NULL, //__in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes, + NULL, //__in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, + TRUE, //__in BOOL bInheritHandles, + 0, //__in DWORD dwCreationFlags, + NULL, //__in_opt LPVOID lpEnvironment, + NULL, //__in_opt LPCTSTR lpCurrentDirectory, + &si, //__in LPSTARTUPINFO lpStartupInfo, + &m_CmdProcessInfo //__out LPPROCESS_INFORMATION lpProcessInformation + ); + + //send initial set up command + WriteInput( m_CmdProcessInputWrite, cmdSetParams ); + + //launch threaded read. + _beginthread( ReadAndHandleOutputThread, 0, this ); //this will exit when process for compile is closed + + + ERROR_EXIT: + if( hOutputReadTmp ) + { + CloseHandle( hOutputReadTmp ); + } + if( hOutputWrite ) + { + CloseHandle( hOutputWrite ); + } + if( hErrorWrite ) + { + CloseHandle( hErrorWrite ); + } + } + + void CleanupProcessAndPipes() + { + // do not reset m_bCompileIsComplete and other members here, just process and pipes + if( m_CmdProcessInfo.hProcess ) + { + TerminateProcess( m_CmdProcessInfo.hProcess, 0 ); + TerminateThread( m_CmdProcessInfo.hThread, 0 ); + CloseHandle( m_CmdProcessInfo.hThread ); + ZeroMemory( &m_CmdProcessInfo, sizeof(m_CmdProcessInfo) ); + CloseHandle( m_CmdProcessInputWrite ); + m_CmdProcessInputWrite = 0; + CloseHandle( m_CmdProcessOutputRead ); + m_CmdProcessOutputRead = 0; + } + + } + + + ~PlatformCompilerImplData() + { + CleanupProcessAndPipes(); + } + + std::string m_VSPath; + PROCESS_INFORMATION m_CmdProcessInfo; + HANDLE m_CmdProcessOutputRead; + HANDLE m_CmdProcessInputWrite; + volatile bool m_bCompileIsComplete; + ICompilerLogger* m_pLogger; +}; + +Compiler::Compiler() + : m_pImplData( 0 ) + , m_bFastCompileMode( false ) +{ +} + +Compiler::~Compiler() +{ + delete m_pImplData; +} + +std::string Compiler::GetObjectFileExtension() const +{ + return ".obj"; +} + +bool Compiler::GetIsComplete() const +{ + bool bComplete = m_pImplData->m_bCompileIsComplete; + if( bComplete & !m_bFastCompileMode ) + { + m_pImplData->CleanupProcessAndPipes(); + } + return bComplete; +} + +void Compiler::Initialise( ICompilerLogger * pLogger ) +{ + m_pImplData = new PlatformCompilerImplData; + m_pImplData->m_pLogger = pLogger; + // get VS compiler path + std::vector Versions; + GetPathsOfVisualStudioInstalls( &Versions ); + + if( !Versions.empty() ) + { + m_pImplData->m_VSPath = Versions[0].Path; + } + else + { + m_pImplData->m_VSPath = ""; + if( m_pImplData->m_pLogger ) + { + m_pImplData->m_pLogger->LogError("No Supported Compiler for RCC++ found.\n"); + } + } +} + + +void Compiler::RunCompile( const std::vector& filesToCompile_, + const CompilerOptions& compilerOptions_, + std::vector linkLibraryList_, + const FileSystemUtils::Path& moduleName_ ) +{ + if( m_pImplData->m_VSPath.empty() ) + { + if (m_pImplData->m_pLogger) { m_pImplData->m_pLogger->LogError("No Supported Compiler for RCC++ found, cannot compile changes.\n"); } + m_pImplData->m_bCompileIsComplete = true; + return; + } + m_pImplData->m_bCompileIsComplete = false; + //optimization and c runtime +#ifdef _DEBUG + std::string flags = "/nologo /Zi /FC /MDd /LDd "; +#else + std::string flags = "/nologo /Zi /FC /MD /LD "; //also need debug information in release +#endif + + RCppOptimizationLevel optimizationLevel = GetActualOptimizationLevel( compilerOptions_.optimizationLevel ); + switch( optimizationLevel ) + { + case RCCPPOPTIMIZATIONLEVEL_DEFAULT: + assert(false); + case RCCPPOPTIMIZATIONLEVEL_DEBUG: + flags += "/Od "; + break; + case RCCPPOPTIMIZATIONLEVEL_PERF: + flags += "/O2 /Oi "; + +// Add improved debugging options if available: http://randomascii.wordpress.com/2013/09/11/debugging-optimized-codenew-in-visual-studio-2012/ +#if (_MSC_VER >= 1700) + flags += "/d2Zi+ "; +#endif + break; + case RCCPPOPTIMIZATIONLEVEL_NOT_SET:; + } + + if( NULL == m_pImplData->m_CmdProcessInfo.hProcess ) + { + m_pImplData->InitialiseProcess(); + } + + flags += compilerOptions_.compileOptions; + flags += " "; + + std::string linkOptions; + bool bHaveLinkOptions = ( 0 != compilerOptions_.linkOptions.length() ); + if( compilerOptions_.libraryDirList.size() || bHaveLinkOptions ) + { + linkOptions = " /link "; + for( size_t i = 0; i < compilerOptions_.libraryDirList.size(); ++i ) + { + linkOptions += " /LIBPATH:\"" + compilerOptions_.libraryDirList[i].m_string + "\""; + } + + if( bHaveLinkOptions ) + { + linkOptions += compilerOptions_.linkOptions; + linkOptions += " "; + } + } + // faster linking if available: https://randomascii.wordpress.com/2015/07/27/programming-is-puzzles/ + #if (_MSC_VER >= 1900) + if( linkOptions.empty() ) + { + linkOptions = " /link "; + } + linkOptions += "/DEBUG:FASTLINK "; + #endif + + // Check for intermediate directory, create it if required + // There are a lot more checks and robustness that could be added here + if ( !compilerOptions_.intermediatePath.Exists() ) + { + bool success = compilerOptions_.intermediatePath.CreateDir(); + if( success && m_pImplData->m_pLogger ) { m_pImplData->m_pLogger->LogInfo("Created intermediate folder \"%s\"\n", compilerOptions_.intermediatePath.c_str()); } + else if( m_pImplData->m_pLogger ) { m_pImplData->m_pLogger->LogError("Error creating intermediate folder \"%s\"\n", compilerOptions_.intermediatePath.c_str()); } + } + + + //create include path search string + std::string strIncludeFiles; + for( size_t i = 0; i < compilerOptions_.includeDirList.size(); ++i ) + { + strIncludeFiles += " /I \"" + compilerOptions_.includeDirList[i].m_string + "\""; + } + + + // When using multithreaded compilation, listing a file for compilation twice can cause errors, hence + // we do a final filtering of input here. + // See http://msdn.microsoft.com/en-us/library/bb385193.aspx - "Source Files and Build Order" + + // Create compile path search string + std::string strFilesToCompile; + std::set filteredPaths; + for( size_t i = 0; i < filesToCompile_.size(); ++i ) + { + std::string strPath = filesToCompile_[i].m_string; + FileSystemUtils::ToLowerInPlace(strPath); + + std::set::const_iterator it = filteredPaths.find(strPath); + if (it == filteredPaths.end()) + { + strFilesToCompile += " \"" + strPath + "\""; + filteredPaths.insert(strPath); + } + } + + std::string strLinkLibraries; + for( size_t i = 0; i < linkLibraryList_.size(); ++i ) + { + strLinkLibraries += " \"" + linkLibraryList_[i].m_string + "\" "; + } + + + + +char* pCharTypeFlags = ""; +#ifdef UNICODE + pCharTypeFlags = "/D UNICODE /D _UNICODE "; +#endif + + // /MP - use multiple processes to compile if possible. Only speeds up compile for multiple files and not link + std::string cmdToSend = "cl " + flags + pCharTypeFlags + + " /MP /Fo\"" + compilerOptions_.intermediatePath.m_string + "\\\\\" " + + "/D WIN32 /EHa /Fe" + moduleName_.m_string; + cmdToSend += " " + strIncludeFiles + " " + strFilesToCompile + strLinkLibraries + linkOptions + + "\necho "; + if( m_pImplData->m_pLogger ) m_pImplData->m_pLogger->LogInfo( "%s", cmdToSend.c_str() ); // use %s to prevent any tokens in compile string being interpreted as formating + cmdToSend += c_CompletionToken + "\n"; + WriteInput( m_pImplData->m_CmdProcessInputWrite, cmdToSend ); +} + + +void GetPathsOfVisualStudioInstalls( std::vector* pVersions ) +{ + //HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\\Setup\VS\ + std::string keyName = "SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VC7"; + + const size_t NUMNAMESTOCHECK = 6; + + // supporting: VS2005, VS2008, VS2010, VS2011, VS2013, VS2015 + std::string valueName[NUMNAMESTOCHECK] = {"8.0","9.0","10.0","11.0","12.0","14.0"}; + + // we start searching for a compatible compiler from the current version backwards + int startVersion = NUMNAMESTOCHECK - 1; + //switch around prefered compiler to the one we've used to compile this file + const unsigned int MSCVERSION = _MSC_VER; + switch( MSCVERSION ) + { + case 1400: //VS 2005 + startVersion = 0; + break; + case 1500: //VS 2008 + startVersion = 1; + break; + case 1600: //VS 2010 + startVersion = 2; + break; + case 1700: //VS 2012 + startVersion = 3; + break; + case 1800: //VS 2013 + startVersion = 4; + break; + case 1900: //VS 2015 + startVersion = 5; + break; + default: + assert( false ); //unsupported compiler, find MSCVERSION to add case, increase NUMNAMESTOCHECK and add valueName. + } + + + + char value[MAX_PATH]; + DWORD size = MAX_PATH; + + HKEY key; + LONG retKeyVal = RegOpenKeyExA( + HKEY_LOCAL_MACHINE, //__in HKEY hKey, + keyName.c_str(), //__in_opt LPCTSTR lpSubKey, + 0, //__reserved DWORD ulOptions, + KEY_READ | KEY_WOW64_32KEY, //__in REGSAM samDesired, + &key //__out PHKEY phkResult + ); + + int loopCount = 1; + if( startVersion != NUMNAMESTOCHECK - 1 ) + { + // we potentially need to restart search from top + loopCount = 2; + } + for( int loop = 0; loop < loopCount; ++loop ) + { + for( int i = startVersion; i >= 0; --i ) + { + + LONG retVal = RegQueryValueExA( + key, //__in HKEY hKey, + valueName[i].c_str(), //__in_opt LPCTSTR lpValueName, + NULL, //__reserved LPDWORD lpReserved, + NULL , //__out_opt LPDWORD lpType, + (LPBYTE)value, //__out_opt LPBYTE lpData, + &size //__inout_opt LPDWORD lpcbData + ); + if( ERROR_SUCCESS == retVal ) + { + VSVersionInfo vInfo; + vInfo.Version = i + 8; + vInfo.Path = value; + pVersions->push_back( vInfo ); + } + } + startVersion = NUMNAMESTOCHECK - 1; // if we loop around again make sure it's from the top + } + + RegCloseKey( key ); + + return; +} + + +void ReadAndHandleOutputThread( LPVOID arg ) +{ + PlatformCompilerImplData* pImpl = (PlatformCompilerImplData*)arg; + + CHAR lpBuffer[1024]; + DWORD nBytesRead; + bool bReadActive = true; + bool bReadOneMore = false; + while( bReadActive ) + { + if (!ReadFile(pImpl->m_CmdProcessOutputRead,lpBuffer,sizeof(lpBuffer)-1, + &nBytesRead,NULL) || !nBytesRead) + { + bReadActive = false; + if (GetLastError() != ERROR_BROKEN_PIPE) //broken pipe is OK + { + if( pImpl->m_pLogger ) pImpl->m_pLogger->LogError( "[RuntimeCompiler] Redirect of compile output failed on read\n" ); + } + } + else + { + // Display the characters read in logger. + lpBuffer[nBytesRead]=0; + + //fist check for completion token... + std::string buffer( lpBuffer ); + size_t found = buffer.find( c_CompletionToken ); + if( found != std::string::npos ) + { + //we've found the completion token, which means we quit + buffer = buffer.substr( 0, found ); + if( pImpl->m_pLogger ) pImpl->m_pLogger->LogInfo("[RuntimeCompiler] Complete\n"); + pImpl->m_bCompileIsComplete = true; + } + if( bReadActive || buffer.length() ) //don't output blank last line + { + //check if this is an error + size_t errorFound = buffer.find( " : error " ); + size_t fatalErrorFound = buffer.find( " : fatal error " ); + if( ( errorFound != std::string::npos ) || ( fatalErrorFound != std::string::npos ) ) + { + if( pImpl->m_pLogger ) pImpl->m_pLogger->LogError( "%s", buffer.c_str() ); + } + else + { + if( pImpl->m_pLogger ) pImpl->m_pLogger->LogInfo( "%s", buffer.c_str() ); + } + } + } + } + +} + +void WriteInput( HANDLE hPipeWrite, std::string& input ) +{ + DWORD nBytesWritten; + DWORD length = (DWORD)input.length(); + WriteFile( hPipeWrite, input.c_str() , length, &nBytesWritten, NULL ); +} diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/FileChangeNotifier.cpp b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/FileChangeNotifier.cpp new file mode 100644 index 0000000..e2526b9 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/FileChangeNotifier.cpp @@ -0,0 +1,196 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "FileChangeNotifier.h" + +#include +using namespace std; + +#define DEFAULT_MIN_TIME_BETWEEN_RECOMPILES 1.0f +#define DEFAULT_NOTIFY_DELAY 0.1f +#define FILE_CHANGE_SPAM_TIME 1.0f + + +FileChangeNotifier::FileChangeNotifier() + : m_bActive(true) + , m_bRecompilePending(false) + , m_fMinTimeBetweenNotifications(DEFAULT_MIN_TIME_BETWEEN_RECOMPILES) + , m_fChangeNotifyDelay(DEFAULT_NOTIFY_DELAY) + , m_fTimeUntilNextAllowedRecompile(0.0f) + , m_fFileChangeSpamTimeRemaining(0.0f) + , m_pFileWatcher( new FW::FileWatcher() ) // Create the file watch object +{ + m_LastFileChanged = ""; +} + + +FileChangeNotifier::~FileChangeNotifier() +{ + delete m_pFileWatcher; +} + + +void FileChangeNotifier::SetMinTimeBetweenNotifications( float fMinTime ) +{ + m_fMinTimeBetweenNotifications = max(0.0f, fMinTime); +} + +void FileChangeNotifier::SetChangeNotifyDelay( float fDelay) +{ + m_fChangeNotifyDelay = max(0.0f, fDelay); +} + +void FileChangeNotifier::Update( float fDeltaTime ) +{ + if (m_bActive) + { + m_pFileWatcher->update(); + m_fTimeUntilNextAllowedRecompile = max(0.0f, m_fTimeUntilNextAllowedRecompile - fDeltaTime); + m_fFileChangeSpamTimeRemaining = max(0.0f, m_fFileChangeSpamTimeRemaining - fDeltaTime); + + if (m_bRecompilePending) + { + TriggerNotificationIfPossible(); + } + } +} + + +void FileChangeNotifier::Watch( const FileSystemUtils::Path& filename, IFileChangeListener *pListener ) +{ + FileSystemUtils::Path fixedFilename = filename.DelimitersToOSDefault(); // Note this doesn't handle ../ + + fixedFilename = fixedFilename.GetCleanPath(); + fixedFilename.ToOSCanonicalCase(); + + if( m_fileListenerMap[fixedFilename].insert(pListener).second ) + { + bool bPathIsDir = !fixedFilename.HasExtension(); + FileSystemUtils::Path pathDir = bPathIsDir ? fixedFilename : fixedFilename.ParentPath(); + if( m_WatchedDirs.insert( pathDir.m_string ).second ) + { + m_pFileWatcher->addWatch( pathDir.m_string, this ); + } + } + pListener->OnRegisteredWithNotifier(this); +} + + +void FileChangeNotifier::Watch( const char *filename, IFileChangeListener *pListener ) +{ + Watch(FileSystemUtils::Path(filename), pListener); +} + +void FileChangeNotifier::RemoveListener( IFileChangeListener *pListener ) +{ + TFileListenerMap::iterator it = m_fileListenerMap.begin(); + TFileListenerMap::iterator itEnd = m_fileListenerMap.end(); + while (it != itEnd) + { + it->second.erase(pListener); + ++it; + } + + pListener->OnRegisteredWithNotifier(NULL); +} + +void FileChangeNotifier::handleFileAction( FW::WatchID watchid, const FW::String& dir, const FW::String& filename, + FW::Action action ) +{ + if (m_bActive) + { + FileSystemUtils::Path filePath(filename); + if( !filename.HasParentPath() ) + { + filePath = dir / filePath; + } + + filePath = filePath.DelimitersToOSDefault(); + filePath.ToOSCanonicalCase(); + + + // Check for multiple hits on the same file in close succession + // (Can be caused by NTFS system making multiple changes even though only + // one actual change occurred) + bool bIgnoreFileChange = (filePath == m_LastFileChanged) && + m_fFileChangeSpamTimeRemaining > 0.0f; + m_LastFileChanged = filePath; + + if (!bIgnoreFileChange) + { + m_changedFileList.insert(filePath.m_string); + + if (!m_bRecompilePending) + { + m_bRecompilePending = true; + m_fTimeUntilNextAllowedRecompile = max(m_fTimeUntilNextAllowedRecompile, m_fChangeNotifyDelay); + } + + m_fFileChangeSpamTimeRemaining = FILE_CHANGE_SPAM_TIME; + TriggerNotificationIfPossible(); + } + } +} + +void FileChangeNotifier::TriggerNotificationIfPossible() +{ + if (m_fTimeUntilNextAllowedRecompile <= 0.0f) + { + m_fTimeUntilNextAllowedRecompile = m_fMinTimeBetweenNotifications; + m_bRecompilePending = false; + + NotifyListeners(); + + m_changedFileList.clear(); + } + else + { + m_bRecompilePending = true; + } +} + +void FileChangeNotifier::NotifyListeners() +{ + std::map > interestedListenersMap; + + // Determine which listeners are interested in which changed files + TPathNameList::const_iterator fileIt = m_changedFileList.begin(); + TPathNameList::const_iterator fileItEnd = m_changedFileList.end(); + while (fileIt != fileItEnd) + { + TFileChangeListeners& listeners = m_fileListenerMap[*fileIt]; + TFileChangeListeners::iterator listenerIt = listeners.begin(); + TFileChangeListeners::iterator listenerItEnd = listeners.end(); + while (listenerIt != listenerItEnd) + { + interestedListenersMap[*listenerIt].Add(fileIt->c_str()); + ++listenerIt; + } + + ++fileIt; + } + + // Notify each listener with an appropriate file list + std::map >::iterator finalIt = interestedListenersMap.begin(); + std::map >::iterator finalItEnd = interestedListenersMap.end(); + while (finalIt != finalItEnd) + { + finalIt->first->OnFileChange(finalIt->second); + ++finalIt; + } +} + diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/FileChangeNotifier.h b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/FileChangeNotifier.h new file mode 100644 index 0000000..6a0990d --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/FileChangeNotifier.h @@ -0,0 +1,111 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef FILECHANGENOTIFIER_INCLUDED +#define FILECHANGENOTIFIER_INCLUDED + +#include "IFileChangeNotifier.h" +#include "SimpleFileWatcher/FileWatcher.h" +#include +#include +#include + +#include "FileSystemUtils.h" + + +// Manages the registering of files with the file monitor and triggering +// Of compilation when a registered file changes +class FileChangeNotifier : public IFileChangeNotifier, public FW::FileWatchListener +{ +public: + FileChangeNotifier(); + virtual ~FileChangeNotifier(); + + // IFileChangeNotifier + + virtual bool IsMonitoringActive() const + { + return m_bActive; + } + + virtual void SetMonitoringActive( bool bActive ) + { + m_bActive = bActive; + } + + virtual float GetMinTimeBetweenNotifications() const + { + return m_fMinTimeBetweenNotifications; + } + + virtual void SetMinTimeBetweenNotifications( float fMinTime ); + + virtual float GetChangeNotifyDelay() const + { + return m_fChangeNotifyDelay; + } + + virtual void SetChangeNotifyDelay( float fDelay ); + + virtual void Update( float fDeltaTime ); + + // Add file to trigger compilation when it changes + virtual void Watch( const FileSystemUtils::Path& filename, IFileChangeListener *pListener ); + virtual void Watch( const char *filename, IFileChangeListener *pListener ); + + virtual void RemoveListener( IFileChangeListener *pListener ); + + // ~IFileChangeNotifier + + + // FW::FileWatchListener + + void handleFileAction(FW::WatchID watchid, const FW::String& dir, const FW::String& filename, + FW::Action action); + + // ~FW::FileWatchListener + + +private: + + void TriggerNotificationIfPossible(); + void NotifyListeners(); + + typedef std::set TFileChangeListeners; + typedef std::map TFileListenerMap; + typedef std::set TPathNameList; + + // Private members + FW::FileWatcher* m_pFileWatcher; + TPathNameList m_WatchedDirs; + + TFileListenerMap m_fileListenerMap; + TPathNameList m_changedFileList; + + bool m_bActive; + bool m_bRecompilePending; + + float m_fMinTimeBetweenNotifications; + float m_fChangeNotifyDelay; + float m_fTimeUntilNextAllowedRecompile; + float m_fFileChangeSpamTimeRemaining; + FileSystemUtils::Path m_LastFileChanged; +}; + +#endif //FILECHANGENOTIFIER_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/FileSystemUtils.h b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/FileSystemUtils.h new file mode 100644 index 0000000..961ae98 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/FileSystemUtils.h @@ -0,0 +1,584 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. +#pragma once + +// we use std::string as there are many string types in the community +// and this can be easily swapped for your own implementation if desired +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN32 + #include + #include + #define WIN32_LEAN_AND_MEAN + #define NOMINMAX + #include + #undef GetObject + #undef GetCurrentTime + + #define FILESYSTEMUTILS_SEPERATORS "/\\" +#else + #include + #include + #include + #include + #define FILESYSTEMUTILS_SEPERATORS "/" +#endif + + +namespace FileSystemUtils +{ +#ifdef _WIN32 + typedef __time64_t filetime_t; +#else + typedef time_t filetime_t; +#endif + + class Path + { + public: + std::string m_string; + + Path() + { + } + + Path( const std::string& rhs_ ) + : m_string( rhs_ ) + { + } + + Path( const char* rhs_ ) + : m_string( rhs_ ) + { + } + virtual ~Path() {} // for RCC++ + + const char* c_str() const; + + Path& operator=( const std::string& rhs_ ); + Path& operator=( const char* rhs_ ); + + bool Exists() const; + bool CreateDir() const; + bool Remove() const; + filetime_t GetLastWriteTime() const; + void SetLastWriteTime( filetime_t time_ ) const; + uint64_t GetFileSize() const; + bool HasExtension() const; + bool HasParentPath() const; + std::string Extension() const; + + // returns filename - i.e. part after final seperator: ./dirone/hello.txt > hello.txt ; ./dirone/hello > hello ; ./dirone/ > [empty string] + Path Filename() const; + Path ParentPath() const; + Path DelimitersToOSDefault() const; + + // returns a path cleaned of /../ by removing prior dir + Path GetCleanPath() const; + void ToOSCanonicalCase(); // lower case on Windows, preserve case on Linux + + // replaces extension if one exists, or adds it if not + void ReplaceExtension( const std::string& ext ); + +#ifdef _WIN32 + static const char seperator = '\\'; + static const char altseperator = '/'; +#else + static const char seperator = '/'; + static const char altseperator = '\\'; +#endif + }; + + + inline void ToLowerInPlace( std::string& inout_str ) + { + for( size_t i = 0; i < inout_str.size(); ++i ) + { + if( inout_str[i] >= 'A' && inout_str[i] <= 'Z' ) + { + //tolower + inout_str[i] -= 'A'-'a'; + } + } + } + + + /////////////////////////////////////////////////////////////////// + // Path function definitions + + inline const char* Path::c_str() const + { + return m_string.c_str(); + } + + inline Path& Path::operator=( const std::string& rhs_ ) + { + m_string = rhs_; + return *this; + } + + inline Path& Path::operator=( const char* rhs_ ) + { + m_string = rhs_; + return *this; + } + + inline bool Path::Exists() const + { + + int error = -1; +#ifdef _WIN32 + struct _stat buffer; + error = _stat( m_string.c_str(), &buffer ); +#else + struct stat buffer; + error = stat( m_string.c_str(), &buffer ); +#endif + if( 0 == error ) + { + return true; + } + return false; + } + + inline bool Path::CreateDir() const + { + if( m_string.length() == 0 ) + { + return false; + } + if( Exists() ) + { + return false; + } + + // we may need to create the parent path recursively + Path parentpath = ParentPath(); + if( !parentpath.Exists() ) + { + parentpath.CreateDir(); + } + + int error = -1; +#ifdef _WIN32 + error = _mkdir( m_string.c_str() ); +#else + error = mkdir( m_string.c_str(), 0777 ); +#endif + if( 0 == error ) + { + return true; + } + return false; + } + + inline filetime_t Path::GetLastWriteTime() const + { + filetime_t lastwritetime = 0; + int error = -1; +#ifdef _WIN32 + struct _stat64 buffer; + error = _stat64( c_str(), &buffer ); +#else + struct stat buffer; + error = stat( c_str(), &buffer ); +#endif + if( 0 == error ) + { + lastwritetime = buffer.st_mtime; + } + return lastwritetime; + } + + inline void Path::SetLastWriteTime( filetime_t time_ ) const + { +#ifdef _WIN32 + __utimbuf64 modtime = { time_, time_ }; + _utime64( c_str(), &modtime ); +#else + utimbuf modtime = { time_, time_ }; + utime( c_str(), &modtime ); +#endif + } + + inline filetime_t GetCurrentTime() + { + filetime_t timer; +#ifdef _WIN32 + _time64(&timer); +#else + time(&timer); +#endif + return timer; + } + + inline tm GetTimeStruct( filetime_t time ) + { + tm ret; +#ifdef _WIN32 + _gmtime64_s(&ret, &time); +#else + gmtime_r(&time, &ret); +#endif + return ret; + } + + inline bool Path::Remove() const + { + int error = remove( c_str() ); + if( !error ) + { + return true; + } + return false; + } + + inline uint64_t Path::GetFileSize() const + { + uint64_t filesize = 0; + int error = -1; +#ifdef _WIN32 + struct _stat64 buffer; + error = _stat64( c_str(), &buffer ); +#else + struct stat buffer; + error = stat( c_str(), &buffer ); +#endif + if( 0 == error ) + { + filesize = buffer.st_size; + } + return filesize; + } + + inline bool Path::HasExtension() const + { + size_t posdot = m_string.find_last_of( '.' ); + if( posdot != std::string::npos ) + { + size_t posseperator = m_string.find_last_of( seperator ); + if( posseperator != std::string::npos && posseperator > posdot ) + { + return false; // the dot is for a directory such as ./ or ../ or the path is malformed + } + size_t posaltseperator = m_string.find_last_of( altseperator ); + if( posaltseperator != std::string::npos && posaltseperator > posdot ) + { + return false; // the dot is for a directory such as ./ or ../ or the path is malformed + } + return true; + } + return false; + } + + inline bool Path::HasParentPath() const + { + size_t posseperator = m_string.find_last_of( seperator ); + if( posseperator != std::string::npos && posseperator > 0 ) + { + return true; + } + size_t posaltseperator = m_string.find_last_of( altseperator ); + if( posaltseperator != std::string::npos && posaltseperator > 0 ) + { + return true; + } + return false; + } + + inline std::string Path::Extension() const + { + std::string ext; + if( HasExtension() ) + { + size_t pos = m_string.find_last_of( '.' ); + if( pos < m_string.length() ) + { + ext = m_string.substr( pos ); + } + } + return ext; + } + + + + inline Path Path::Filename() const + { + Path filename; + size_t pos = m_string.find_last_of( seperator ) + 1; + if( pos <= m_string.length() ) + { + filename = m_string.substr(pos); + } + + return filename; + } + + inline Path Path::ParentPath() const + { + Path parentpath = m_string; + + if( parentpath.m_string.length() == 0 ) + { + return parentpath; + } + //remove any trailing seperators + while( parentpath.m_string.find_last_of( FILESYSTEMUTILS_SEPERATORS ) == parentpath.m_string.length()-1 ) + { + parentpath.m_string.erase(parentpath.m_string.length()-1, 1); + } + + size_t pos = parentpath.m_string.find_last_of( FILESYSTEMUTILS_SEPERATORS ); + if( pos < parentpath.m_string.length() ) + { + parentpath = parentpath.m_string.substr(0, pos); + + //remove any trailing seperators + while( parentpath.m_string.find_last_of( FILESYSTEMUTILS_SEPERATORS ) == parentpath.m_string.length()-1) + { + parentpath.m_string.erase(parentpath.m_string.length()-1, 1); + } + } + + return parentpath; + } + + inline Path Path::DelimitersToOSDefault() const + { + Path path = m_string; + for( size_t i = 0; i < path.m_string.size(); ++i ) + { + if( path.m_string[i] == altseperator ) + { + path.m_string[i] = seperator; + } + } + return path; + } + + inline void Path::ReplaceExtension( const std::string& ext ) + { + if( HasExtension() ) + { + size_t pos = m_string.find_last_of( '.' ); + if( pos < m_string.length() ) + { + m_string.erase( m_string.begin() + pos, m_string.end() ); + } + } + m_string += ext; + } + + + inline Path operator/( const Path& lhs_, const Path& rhs_ ) + { + if( 0 == lhs_.m_string.length() ) + { + return rhs_; + } + if( 0 == rhs_.m_string.length() ) + { + return lhs_; + } + std::string strlhs = lhs_.m_string; + while( strlhs.length() && strlhs.find_last_of( FILESYSTEMUTILS_SEPERATORS ) == strlhs.length()-1 ) + { + strlhs.erase(strlhs.length()-1, 1); + } + + //note: should probably remove preceding seperators to rhs_, but this has not as yet occured + Path join = strlhs + Path::seperator + rhs_.m_string; + return join; + } + + inline bool operator==( const Path& lhs_, const Path& rhs_ ) + { + return lhs_.m_string == rhs_.m_string; + } + + inline bool operator<( const Path& lhs_, const Path& rhs_ ) + { + return lhs_.m_string < rhs_.m_string; + } + + inline Path GetCurrentPath() + { + Path currPath; +#ifdef _WIN32 + char currdir[MAX_PATH]; + GetCurrentDirectoryA( sizeof( currdir ), currdir ); + currPath = currdir; +#else + char* currdir = getcwd(0,0); + currPath = currdir; + free( currdir ); +#endif + + return currPath; + } + + inline Path Path::GetCleanPath() const + { + Path path = m_string; + bool bFound = false; + do + { + bFound = false; + size_t pos = path.m_string.find( ".." ); + if( pos != std::string::npos && pos+3 < path.m_string.length() && pos > 0 ) + { + Path a = path.m_string.substr(0,pos-1); // pos-1 as we don't want delimiter + Path b = path.m_string.substr(pos+3,path.m_string.length()); // pos+3 as we don't want delimiter + a = a.ParentPath(); + path = a / b; + bFound = true; + } + } while( bFound ); + + return path; + } + + inline void Path::ToOSCanonicalCase() + { +#ifdef _WIN32 + ToLowerInPlace( m_string ); +#endif + } + + + class PathIterator + { + private: + Path m_dir; + Path m_path; + bool m_bIsValid; +#ifdef _WIN32 + void ImpCtor() + { + Path test = m_dir / "*"; + m_path = m_dir; + m_hFind = INVALID_HANDLE_VALUE; + m_hFind = FindFirstFileA(test.c_str(), &m_ffd); + m_bIsValid = INVALID_HANDLE_VALUE != m_hFind; + } + bool ImpNext() + { + if( m_bIsValid ) + { + m_bIsValid = 0 != FindNextFileA( m_hFind, &m_ffd ); + if( m_bIsValid ) + { + m_path = m_dir / m_ffd.cFileName; + if( m_path.Filename() == ".." ) + { + return ImpNext(); + } + } + } + return m_bIsValid; + } + void ImpDtor() + { + FindClose( m_hFind ); + } + + HANDLE m_hFind; + WIN32_FIND_DATAA m_ffd; +#else + void ImpCtor() + { + Path test = m_dir / "*"; + m_path = m_dir; + m_numFilesInList = scandir( m_path.c_str(), &m_paDirFileList, 0, alphasort); + m_bIsValid = m_numFilesInList > 0; + m_currFile = 0; + if( !m_bIsValid ) + { + m_paDirFileList = 0; + } + } + bool ImpNext() + { + if( m_bIsValid ) + { + ++m_currFile; + m_bIsValid = m_currFile < m_numFilesInList; + if( m_bIsValid ) + { + m_path = m_dir / m_paDirFileList[ m_currFile ]->d_name; + if( strcmp( m_paDirFileList[ m_currFile ]->d_name, "." ) == 0 || + strcmp( m_paDirFileList[ m_currFile ]->d_name, ".." ) == 0 ) + { + return ImpNext(); + } + } + } + return m_bIsValid; + } + void ImpDtor() + { + free(m_paDirFileList); + } + struct dirent **m_paDirFileList; + int m_numFilesInList; + int m_currFile; + +#endif + public: + PathIterator( const Path& path_ ) + : m_dir( path_ ) + { + ImpCtor(); + } + ~PathIterator() + { + ImpDtor(); + } + + bool operator++() + { + return ImpNext(); + } + + bool IsValid() const + { + return m_bIsValid; + } + const Path& GetPath() const + { + return m_path; + } + + }; + + +} + + +inline FileSystemUtils::Path operator/( const std::string& lhs_, const std::string& rhs_ ) +{ + //remove any trailing seperators + FileSystemUtils::Path pathlhs = lhs_; + FileSystemUtils::Path pathrhs = rhs_; + return pathlhs / pathrhs; +} diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/ICompilerLogger.h b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/ICompilerLogger.h new file mode 100644 index 0000000..fee9704 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/ICompilerLogger.h @@ -0,0 +1,34 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +// Compiler Logger - implement this interface to recieve logging from the RuntimeCompiler module +// In Aurora, this interface exists to avoid dependency on the Systems project + +#ifndef ICOMPILERLOGGER_INCLUDED +#define ICOMPILERLOGGER_INCLUDED + +struct ICompilerLogger +{ + virtual void LogError(const char * format, ...) = 0; + virtual void LogWarning(const char * format, ...) = 0; + virtual void LogInfo(const char * format, ...) = 0; + virtual ~ICompilerLogger() {} +}; + +#endif // ICOMPILERLOGGER_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/IFileChangeNotifier.h b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/IFileChangeNotifier.h new file mode 100644 index 0000000..bca590b --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/IFileChangeNotifier.h @@ -0,0 +1,78 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef IFILECHANGENOTIFIER_INCLUDED +#define IFILECHANGENOTIFIER_INCLUDED + +#include "../RuntimeCompiler/AUArray.h" +#include + +struct IFileChangeListener; + +struct IFileChangeNotifier +{ + virtual bool IsMonitoringActive() const = 0; + virtual void SetMonitoringActive( bool bActive ) = 0; + + virtual float GetMinTimeBetweenNotifications() const = 0; + virtual void SetMinTimeBetweenNotifications( float fMinTime ) = 0; + + // Delay to allow multiple file changes to accumulate before notifying listeners + virtual float GetChangeNotifyDelay() const = 0; + virtual void SetChangeNotifyDelay( float fDelay ) = 0; + + virtual void Update( float fTimeDelta ) = 0; + virtual void Watch( const char *filename, IFileChangeListener *pListener ) = 0; // can be file or directory + + virtual void RemoveListener( IFileChangeListener *pListener ) = 0; + virtual ~IFileChangeNotifier() {} +}; + + +// IFileChangeListener will automatically deregister with FileChangeNotifier +// it registered with (via Watch method) on destruction +// Will not give expected results if the listener registers with multiple notifiers +struct IFileChangeListener +{ + IFileChangeListener() : _registeredNotifier(0) {} + virtual ~IFileChangeListener() + { + if (_registeredNotifier) + { + _registeredNotifier->RemoveListener(this); + } + } + + + // Listener must make copies of strings if it wants to store them + virtual void OnFileChange( const IAUDynArray& filelist ) = 0; + + + // Should be called by IFileChangeNotifier implementation only + void OnRegisteredWithNotifier( IFileChangeNotifier* pNotifier ) + { + _registeredNotifier = pNotifier; + } + +private: + IFileChangeNotifier* _registeredNotifier; +}; + + +#endif // IFILECHANGENOTIFIER_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/RuntimeCompiler.xcodeproj/project.pbxproj b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/RuntimeCompiler.xcodeproj/project.pbxproj new file mode 100644 index 0000000..2817b7f --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/RuntimeCompiler.xcodeproj/project.pbxproj @@ -0,0 +1,264 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 9106B90116AE8B9A003D2CD9 /* FileSystemUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 9106B90016AE8B9A003D2CD9 /* FileSystemUtils.h */; }; + 915C293416EB817400654B4E /* Compiler_PlatformPosix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 915C293316EB817400654B4E /* Compiler_PlatformPosix.cpp */; }; + 91CDEF8D1619F0D70061B76E /* BuildTool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91CDEF7D1619F0D70061B76E /* BuildTool.cpp */; }; + 91CDEF8E1619F0D70061B76E /* BuildTool.h in Headers */ = {isa = PBXBuildFile; fileRef = 91CDEF7E1619F0D70061B76E /* BuildTool.h */; }; + 91CDEF901619F0D70061B76E /* Compiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 91CDEF801619F0D70061B76E /* Compiler.h */; }; + 91CDEF911619F0D70061B76E /* FileChangeNotifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91CDEF811619F0D70061B76E /* FileChangeNotifier.cpp */; }; + 91CDEF921619F0D70061B76E /* FileChangeNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 91CDEF821619F0D70061B76E /* FileChangeNotifier.h */; }; + 91CDEF951619F0D70061B76E /* ICompilerLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = 91CDEF851619F0D70061B76E /* ICompilerLogger.h */; }; + 91CDEF961619F0D70061B76E /* IFileChangeNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 91CDEF861619F0D70061B76E /* IFileChangeNotifier.h */; }; + 91CDEF981619F0D70061B76E /* FileWatcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91CDEF881619F0D70061B76E /* FileWatcher.cpp */; }; + 91CDEF991619F0D70061B76E /* FileWatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 91CDEF891619F0D70061B76E /* FileWatcher.h */; }; + 91CDEF9A1619F0D70061B76E /* FileWatcherImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 91CDEF8A1619F0D70061B76E /* FileWatcherImpl.h */; }; + 91CDEF9B1619F0D70061B76E /* FileWatcherOSX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91CDEF8B1619F0D70061B76E /* FileWatcherOSX.cpp */; }; + 91CDEF9C1619F0D70061B76E /* FileWatcherOSX.h in Headers */ = {isa = PBXBuildFile; fileRef = 91CDEF8C1619F0D70061B76E /* FileWatcherOSX.h */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 9106B90016AE8B9A003D2CD9 /* FileSystemUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileSystemUtils.h; sourceTree = ""; }; + 915C293316EB817400654B4E /* Compiler_PlatformPosix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Compiler_PlatformPosix.cpp; sourceTree = ""; }; + 919FE7001619F04600A269B6 /* libRuntimeCompiler.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRuntimeCompiler.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 91CDEF7D1619F0D70061B76E /* BuildTool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BuildTool.cpp; sourceTree = ""; }; + 91CDEF7E1619F0D70061B76E /* BuildTool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BuildTool.h; sourceTree = ""; }; + 91CDEF801619F0D70061B76E /* Compiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Compiler.h; sourceTree = ""; }; + 91CDEF811619F0D70061B76E /* FileChangeNotifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileChangeNotifier.cpp; sourceTree = ""; }; + 91CDEF821619F0D70061B76E /* FileChangeNotifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileChangeNotifier.h; sourceTree = ""; }; + 91CDEF851619F0D70061B76E /* ICompilerLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ICompilerLogger.h; sourceTree = ""; }; + 91CDEF861619F0D70061B76E /* IFileChangeNotifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IFileChangeNotifier.h; sourceTree = ""; }; + 91CDEF881619F0D70061B76E /* FileWatcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileWatcher.cpp; path = SimpleFileWatcher/FileWatcher.cpp; sourceTree = ""; }; + 91CDEF891619F0D70061B76E /* FileWatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileWatcher.h; path = SimpleFileWatcher/FileWatcher.h; sourceTree = ""; }; + 91CDEF8A1619F0D70061B76E /* FileWatcherImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileWatcherImpl.h; path = SimpleFileWatcher/FileWatcherImpl.h; sourceTree = ""; }; + 91CDEF8B1619F0D70061B76E /* FileWatcherOSX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileWatcherOSX.cpp; path = SimpleFileWatcher/FileWatcherOSX.cpp; sourceTree = ""; }; + 91CDEF8C1619F0D70061B76E /* FileWatcherOSX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileWatcherOSX.h; path = SimpleFileWatcher/FileWatcherOSX.h; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 919FE6FD1619F04600A269B6 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 919FE6F51619F04600A269B6 = { + isa = PBXGroup; + children = ( + 915C293316EB817400654B4E /* Compiler_PlatformPosix.cpp */, + 9106B90016AE8B9A003D2CD9 /* FileSystemUtils.h */, + 91CDEF9E1619F0E30061B76E /* SimpleFileWatcher */, + 91CDEF7D1619F0D70061B76E /* BuildTool.cpp */, + 91CDEF7E1619F0D70061B76E /* BuildTool.h */, + 91CDEF801619F0D70061B76E /* Compiler.h */, + 91CDEF811619F0D70061B76E /* FileChangeNotifier.cpp */, + 91CDEF821619F0D70061B76E /* FileChangeNotifier.h */, + 91CDEF851619F0D70061B76E /* ICompilerLogger.h */, + 91CDEF861619F0D70061B76E /* IFileChangeNotifier.h */, + 919FE7011619F04600A269B6 /* Products */, + ); + sourceTree = ""; + }; + 919FE7011619F04600A269B6 /* Products */ = { + isa = PBXGroup; + children = ( + 919FE7001619F04600A269B6 /* libRuntimeCompiler.a */, + ); + name = Products; + sourceTree = ""; + }; + 91CDEF9E1619F0E30061B76E /* SimpleFileWatcher */ = { + isa = PBXGroup; + children = ( + 91CDEF881619F0D70061B76E /* FileWatcher.cpp */, + 91CDEF891619F0D70061B76E /* FileWatcher.h */, + 91CDEF8A1619F0D70061B76E /* FileWatcherImpl.h */, + 91CDEF8B1619F0D70061B76E /* FileWatcherOSX.cpp */, + 91CDEF8C1619F0D70061B76E /* FileWatcherOSX.h */, + ); + name = SimpleFileWatcher; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 919FE6FE1619F04600A269B6 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 91CDEF8E1619F0D70061B76E /* BuildTool.h in Headers */, + 91CDEF901619F0D70061B76E /* Compiler.h in Headers */, + 91CDEF921619F0D70061B76E /* FileChangeNotifier.h in Headers */, + 91CDEF951619F0D70061B76E /* ICompilerLogger.h in Headers */, + 91CDEF961619F0D70061B76E /* IFileChangeNotifier.h in Headers */, + 91CDEF991619F0D70061B76E /* FileWatcher.h in Headers */, + 91CDEF9A1619F0D70061B76E /* FileWatcherImpl.h in Headers */, + 91CDEF9C1619F0D70061B76E /* FileWatcherOSX.h in Headers */, + 9106B90116AE8B9A003D2CD9 /* FileSystemUtils.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 919FE6FF1619F04600A269B6 /* RuntimeCompiler */ = { + isa = PBXNativeTarget; + buildConfigurationList = 919FE7041619F04600A269B6 /* Build configuration list for PBXNativeTarget "RuntimeCompiler" */; + buildPhases = ( + 919FE6FC1619F04600A269B6 /* Sources */, + 919FE6FD1619F04600A269B6 /* Frameworks */, + 919FE6FE1619F04600A269B6 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = RuntimeCompiler; + productName = RuntimeCompiler; + productReference = 919FE7001619F04600A269B6 /* libRuntimeCompiler.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 919FE6F71619F04600A269B6 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0440; + ORGANIZATIONNAME = "Doug Binks"; + }; + buildConfigurationList = 919FE6FA1619F04600A269B6 /* Build configuration list for PBXProject "RuntimeCompiler" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 919FE6F51619F04600A269B6; + productRefGroup = 919FE7011619F04600A269B6 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 919FE6FF1619F04600A269B6 /* RuntimeCompiler */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 919FE6FC1619F04600A269B6 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 91CDEF8D1619F0D70061B76E /* BuildTool.cpp in Sources */, + 91CDEF911619F0D70061B76E /* FileChangeNotifier.cpp in Sources */, + 91CDEF981619F0D70061B76E /* FileWatcher.cpp in Sources */, + 91CDEF9B1619F0D70061B76E /* FileWatcherOSX.cpp in Sources */, + 915C293416EB817400654B4E /* Compiler_PlatformPosix.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 919FE7021619F04600A269B6 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ../External/boost/; + MACOSX_DEPLOYMENT_TARGET = 10.8; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + 919FE7031619F04600A269B6 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ../External/boost/; + MACOSX_DEPLOYMENT_TARGET = 10.8; + SDKROOT = macosx; + }; + name = Release; + }; + 919FE7051619F04600A269B6 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + EXECUTABLE_PREFIX = lib; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = ""; + }; + name = Debug; + }; + 919FE7061619F04600A269B6 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + EXECUTABLE_PREFIX = lib; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = ""; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 919FE6FA1619F04600A269B6 /* Build configuration list for PBXProject "RuntimeCompiler" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 919FE7021619F04600A269B6 /* Debug */, + 919FE7031619F04600A269B6 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 919FE7041619F04600A269B6 /* Build configuration list for PBXNativeTarget "RuntimeCompiler" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 919FE7051619F04600A269B6 /* Debug */, + 919FE7061619F04600A269B6 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 919FE6F71619F04600A269B6 /* Project object */; +} diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/RuntimeCompiler.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/RuntimeCompiler.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..6929919 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/RuntimeCompiler.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/RuntimeCompiler_VS2010.vcxproj b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/RuntimeCompiler_VS2010.vcxproj new file mode 100644 index 0000000..6cd2486 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/RuntimeCompiler_VS2010.vcxproj @@ -0,0 +1,164 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + Win32Proj + {790D95ED-C6E6-24E5-345B-37FB1E098082} + + + + StaticLibrary + true + Unicode + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + Unicode + + + StaticLibrary + false + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + MultiThreadedDebugDLL + Level3 + ProgramDatabase + Disabled + Async + false + %(AdditionalIncludeDirectories) + + + + + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + MultiThreadedDebugDLL + Level3 + ProgramDatabase + Disabled + Async + false + %(AdditionalIncludeDirectories) + + + + + + + false + %(AdditionalIncludeDirectories) + + + + + + + false + %(AdditionalIncludeDirectories) + + + + + true + true + true + true + + + + + + + true + true + true + true + + + true + true + true + true + + + + + + + + + + + + + + + + true + true + true + true + + + true + true + true + true + + + + + + + + \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/RuntimeCompiler_VS2010.vcxproj.filters b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/RuntimeCompiler_VS2010.vcxproj.filters new file mode 100644 index 0000000..ef39dd0 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/RuntimeCompiler_VS2010.vcxproj.filters @@ -0,0 +1,54 @@ + + + + + + + + SimpleFileWatcher + + + SimpleFileWatcher + + + + SimpleFileWatcher + + + SimpleFileWatcher + + + + + + + + + + SimpleFileWatcher + + + SimpleFileWatcher + + + SimpleFileWatcher + + + + SimpleFileWatcher + + + + SimpleFileWatcher + + + SimpleFileWatcher + + + + + + {0baef244-e3d1-4bf8-b037-fb5e814ef3d4} + + + \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcher.cpp b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcher.cpp new file mode 100644 index 0000000..4b0e335 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcher.cpp @@ -0,0 +1,83 @@ +/** + Copyright (c) 2009 James Wynn (james@jameswynn.com) + + 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 "FileWatcher.h" +#include "FileWatcherImpl.h" + +#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_WIN32 +# include "FileWatcherWin32.h" +# define FILEWATCHER_IMPL FileWatcherWin32 +#elif FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_KQUEUE +# include "FileWatcherOSX.h" +# define FILEWATCHER_IMPL FileWatcherOSX +#elif FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_LINUX +# include "FileWatcherLinux.h" +# define FILEWATCHER_IMPL FileWatcherLinux +#endif + +namespace FW +{ + + //-------- + FileWatcher::FileWatcher() + { + mImpl = new FILEWATCHER_IMPL(); + } + + //-------- + FileWatcher::~FileWatcher() + { + delete mImpl; + mImpl = 0; + } + + //-------- + WatchID FileWatcher::addWatch(const String& directory, FileWatchListener* watcher) + { + return mImpl->addWatch(directory, watcher, false); + } + + //-------- + WatchID FileWatcher::addWatch(const String& directory, FileWatchListener* watcher, bool recursive) + { + return mImpl->addWatch(directory, watcher, recursive); + } + + //-------- + void FileWatcher::removeWatch(const String& directory) + { + mImpl->removeWatch(directory); + } + + //-------- + void FileWatcher::removeWatch(WatchID watchid) + { + mImpl->removeWatch(watchid); + } + + //-------- + void FileWatcher::update() + { + mImpl->update(); + } + +};//namespace FW diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcher.h b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcher.h new file mode 100644 index 0000000..7a0a156 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcher.h @@ -0,0 +1,123 @@ +/** + Main header for the FileWatcher class. Declares all implementation + classes to reduce compilation overhead. + + @author James Wynn + @date 4/15/2009 + + Copyright (c) 2009 James Wynn (james@jameswynn.com) + + 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. +*/ + +#ifndef _FW_FILEWATCHER_H_ +#define _FW_FILEWATCHER_H_ +#pragma once + +#include +#include + +#include "../FileSystemUtils.h" + +namespace FW +{ + /// Type for a string + typedef FileSystemUtils::Path String; + /// Type for a watch id + typedef unsigned long WatchID; + + // forward declarations + class FileWatcherImpl; + class FileWatchListener; + + + /// Actions to listen for. Rename will send two events, one for + /// the deletion of the old file, and one for the creation of the + /// new file. + namespace Actions + { + enum Action + { + /// Sent when a file is created or renamed + Add = 1, + /// Sent when a file is deleted or renamed + Delete = 2, + /// Sent when a file is modified + Modified = 4 + }; + }; + typedef Actions::Action Action; + + /// Listens to files and directories and dispatches events + /// to notify the parent program of the changes. + /// @class FileWatcher + class FileWatcher + { + public: + /// + /// + FileWatcher(); + + /// + /// + virtual ~FileWatcher(); + + /// Add a directory watch. Same as the other addWatch, but doesn't have recursive option. + /// For backwards compatibility. + WatchID addWatch(const String& directory, FileWatchListener* watcher); + + /// Add a directory watch + WatchID addWatch(const String& directory, FileWatchListener* watcher, bool recursive); + + /// Remove a directory watch. This is a brute force search O(nlogn). + void removeWatch(const String& directory); + + /// Remove a directory watch. This is a map lookup O(logn). + void removeWatch(WatchID watchid); + + /// Updates the watcher. Must be called often. + void update(); + + private: + /// The implementation + FileWatcherImpl* mImpl; + + };//end FileWatcher + + + /// Basic interface for listening for file events. + /// @class FileWatchListener + class FileWatchListener + { + public: + FileWatchListener() {} + virtual ~FileWatchListener() {} + + /// Handles the action file action + /// @param watchid The watch id for the directory + /// @param dir The directory + /// @param filename The filename that was accessed (not full path) + /// @param action Action that was performed + virtual void handleFileAction(WatchID watchid, const String& dir, const String& filename, Action action) = 0; + + };//class FileWatchListener + +};//namespace FW + +#endif//_FW_FILEWATCHER_H_ diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherImpl.h b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherImpl.h new file mode 100644 index 0000000..679420f --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherImpl.h @@ -0,0 +1,78 @@ +/** + Basic interface for the FileWatcher backend. + + @author James Wynn + @date 5/11/2009 + + Copyright (c) 2009 James Wynn (james@jameswynn.com) + + 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. +*/ +#ifndef _FW_FILEWATCHERIMPL_H_ +#define _FW_FILEWATCHERIMPL_H_ +#pragma once + +#include "FileWatcher.h" + +#define FILEWATCHER_PLATFORM_WIN32 1 +#define FILEWATCHER_PLATFORM_LINUX 2 +#define FILEWATCHER_PLATFORM_KQUEUE 3 + +#if defined(_WIN32) +# define FILEWATCHER_PLATFORM FILEWATCHER_PLATFORM_WIN32 +#elif defined(__APPLE_CC__) || defined(BSD) +# define FILEWATCHER_PLATFORM FILEWATCHER_PLATFORM_KQUEUE +#elif defined(__linux__) +# define FILEWATCHER_PLATFORM FILEWATCHER_PLATFORM_LINUX +#endif + +namespace FW +{ + struct WatchStruct; + + class FileWatcherImpl + { + public: + /// + /// + FileWatcherImpl() {} + + /// + /// + virtual ~FileWatcherImpl() {} + + /// Add a directory watch + virtual WatchID addWatch(const String& directory, FileWatchListener* watcher, bool recursive) = 0; + + /// Remove a directory watch. This is a brute force lazy search O(nlogn). + virtual void removeWatch(const String& directory) = 0; + + /// Remove a directory watch. This is a map lookup O(logn). + virtual void removeWatch(WatchID watchid) = 0; + + /// Updates the watcher. Must be called often. + virtual void update() = 0; + + /// Handles the action + virtual void handleAction(WatchStruct* watch, const String& filename, unsigned long action) = 0; + + };//end FileWatcherImpl +};//namespace FW + +#endif//_FW_FILEWATCHERIMPL_H_ diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherLinux.cpp b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherLinux.cpp new file mode 100644 index 0000000..45addb7 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherLinux.cpp @@ -0,0 +1,176 @@ +/** + Copyright (c) 2009 James Wynn (james@jameswynn.com) + + 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. + + James Wynn james@jameswynn.com +*/ + +#include "FileWatcherLinux.h" + +#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_LINUX + +#include +#include +#include +#include +#include +#include + +#define BUFF_SIZE ((sizeof(struct inotify_event)+FILENAME_MAX)*1024) + +namespace FW +{ + + struct WatchStruct + { + WatchID mWatchID; + String mDirName; + FileWatchListener* mListener; + }; + + //-------- + FileWatcherLinux::FileWatcherLinux() + { + mFD = inotify_init(); + if (mFD < 0) + fprintf (stderr, "Error: %s\n", strerror(errno)); + + mTimeOut.tv_sec = 0; + mTimeOut.tv_usec = 0; + + FD_ZERO(&mDescriptorSet); + } + + //-------- + FileWatcherLinux::~FileWatcherLinux() + { + WatchMap::iterator iter = mWatches.begin(); + WatchMap::iterator end = mWatches.end(); + for(; iter != end; ++iter) + { + delete iter->second; + } + mWatches.clear(); + } + + //-------- + WatchID FileWatcherLinux::addWatch(const String& directory, FileWatchListener* watcher, bool recursive) + { + const char* pDir = directory.c_str(); + int wd = inotify_add_watch (mFD, pDir, + IN_CLOSE_WRITE | IN_MOVED_TO | IN_CREATE | IN_MOVED_FROM | IN_DELETE | IN_MODIFY | IN_ATTRIB ); + + WatchStruct* pWatch = new WatchStruct(); + pWatch->mListener = watcher; + pWatch->mWatchID = wd; + pWatch->mDirName = directory; + + mWatches.insert(std::make_pair(wd, pWatch)); + + return wd; + } + + //-------- + void FileWatcherLinux::removeWatch(const String& directory) + { + WatchMap::iterator iter = mWatches.begin(); + WatchMap::iterator end = mWatches.end(); + for(; iter != end; ++iter) + { + if(directory == iter->second->mDirName) + { + removeWatch(iter->first); + return; + } + } + } + + //-------- + void FileWatcherLinux::removeWatch(WatchID watchid) + { + WatchMap::iterator iter = mWatches.find(watchid); + + if(iter == mWatches.end()) + return; + + WatchStruct* watch = iter->second; + mWatches.erase(iter); + + inotify_rm_watch(mFD, watchid); + + delete watch; + watch = 0; + } + + //-------- + void FileWatcherLinux::update() + { + FD_SET(mFD, &mDescriptorSet); + + int ret = select(mFD + 1, &mDescriptorSet, NULL, NULL, &mTimeOut); + if(ret < 0) + { + perror("select"); + } + else if(FD_ISSET(mFD, &mDescriptorSet)) + { + ssize_t len, i = 0; + //char action[81+FILENAME_MAX] = {0}; + char buff[BUFF_SIZE] = {0}; + + len = read (mFD, buff, BUFF_SIZE); + + while (i < len) + { + struct inotify_event *pevent = (struct inotify_event *)&buff[i]; + + WatchStruct* watch = mWatches[pevent->wd]; + handleAction(watch, pevent->name, pevent->mask); + i += sizeof(struct inotify_event) + pevent->len; + } + } + } + + //-------- + void FileWatcherLinux::handleAction(WatchStruct* watch, const String& filename, unsigned long action) + { + if(!watch->mListener) + return; + + if( (IN_CLOSE_WRITE & action) || (IN_MODIFY & action) || ( IN_ATTRIB & action ) ) + { + watch->mListener->handleFileAction(watch->mWatchID, watch->mDirName, filename, + Actions::Modified); + } + if( ( IN_MOVED_TO & action ) || ( IN_CREATE & action ) ) + { + watch->mListener->handleFileAction(watch->mWatchID, watch->mDirName, filename, + Actions::Add); + } + if(( IN_MOVED_FROM & action ) || ( IN_DELETE & action ) ) + { + watch->mListener->handleFileAction(watch->mWatchID, watch->mDirName, filename, + Actions::Delete); + } + } + +};//namespace FW + +#endif//FILEWATCHER_PLATFORM_LINUX diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherLinux.cpp~ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherLinux.cpp~ new file mode 100644 index 0000000..7188639 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherLinux.cpp~ @@ -0,0 +1,176 @@ +/** + Copyright (c) 2009 James Wynn (james@jameswynn.com) + + 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. + + James Wynn james@jameswynn.com +*/ + +#include "FileWatcherLinux.h" + +#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_LINUX + +#include +#include +#include +#include +#include +#include + +#define BUFF_SIZE ((sizeof(struct inotify_event)+FILENAME_MAX)*1024) + +namespace FW +{ + + struct WatchStruct + { + WatchID mWatchID; + String mDirName; + FileWatchListener* mListener; + }; + + //-------- + FileWatcherLinux::FileWatcherLinux() + { + mFD = inotify_init(); + if (mFD < 0) + fprintf (stderr, "Error: %s\n", strerror(errno)); + + mTimeOut.tv_sec = 0; + mTimeOut.tv_usec = 0; + + FD_ZERO(&mDescriptorSet); + } + + //-------- + FileWatcherLinux::~FileWatcherLinux() + { + WatchMap::iterator iter = mWatches.begin(); + WatchMap::iterator end = mWatches.end(); + for(; iter != end; ++iter) + { + delete iter->second; + } + mWatches.clear(); + } + + //-------- + WatchID FileWatcherLinux::addWatch(const String& directory, FileWatchListener* watcher, bool recursive) + { + const char* pDir = directory.c_str(); + int wd = inotify_add_watch (mFD, pDir, + IN_CLOSE_WRITE | IN_MOVED_TO | IN_CREATE | IN_MOVED_FROM | IN_DELETE | IN_MODIFY | IN_ATTRIB ); + + WatchStruct* pWatch = new WatchStruct(); + pWatch->mListener = watcher; + pWatch->mWatchID = wd; + pWatch->mDirName = directory; + + mWatches.insert(std::make_pair(wd, pWatch)); + + return wd; + } + + //-------- + void FileWatcherLinux::removeWatch(const String& directory) + { + WatchMap::iterator iter = mWatches.begin(); + WatchMap::iterator end = mWatches.end(); + for(; iter != end; ++iter) + { + if(directory == iter->second->mDirName) + { + removeWatch(iter->first); + return; + } + } + } + + //-------- + void FileWatcherLinux::removeWatch(WatchID watchid) + { + WatchMap::iterator iter = mWatches.find(watchid); + + if(iter == mWatches.end()) + return; + + WatchStruct* watch = iter->second; + mWatches.erase(iter); + + inotify_rm_watch(mFD, watchid); + + delete watch; + watch = 0; + } + + //-------- + void FileWatcherLinux::update() + { + FD_SET(mFD, &mDescriptorSet); + + int ret = select(mFD + 1, &mDescriptorSet, NULL, NULL, &mTimeOut); + if(ret < 0) + { + perror("select"); + } + else if(FD_ISSET(mFD, &mDescriptorSet)) + { + ssize_t len, i = 0; + //char action[81+FILENAME_MAX] = {0}; + char buff[BUFF_SIZE] = {0}; + + len = read (mFD, buff, BUFF_SIZE); + + while (i < len) + { + struct inotify_event *pevent = (struct inotify_event *)&buff[i]; + + WatchStruct* watch = mWatches[pevent->wd]; + handleAction(watch, pevent->name, pevent->mask); + i += sizeof(struct inotify_event) + pevent->len; + } + } + } + + //-------- + void FileWatcherLinux::handleAction(WatchStruct* watch, const String& filename, unsigned long action) + { + if(!watch->mListener) + return; + + if( (IN_CLOSE_WRITE & action) || (IN_MODIFY & action) ) + { + watch->mListener->handleFileAction(watch->mWatchID, watch->mDirName, filename, + Actions::Modified); + } + if( ( IN_MOVED_TO & action ) || ( IN_CREATE & action ) ) + { + watch->mListener->handleFileAction(watch->mWatchID, watch->mDirName, filename, + Actions::Add); + } + if(( IN_MOVED_FROM & action ) || ( IN_DELETE & action ) ) + { + watch->mListener->handleFileAction(watch->mWatchID, watch->mDirName, filename, + Actions::Delete); + } + } + +};//namespace FW + +#endif//FILEWATCHER_PLATFORM_LINUX diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherLinux.h b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherLinux.h new file mode 100644 index 0000000..f77b9c4 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherLinux.h @@ -0,0 +1,91 @@ +/** + Implementation header file for Linux based on inotify. + + @author James Wynn + @date 4/15/2009 + + Copyright (c) 2009 James Wynn (james@jameswynn.com) + + 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. +*/ +#ifndef _FW_FILEWATCHERLINUX_H_ +#define _FW_FILEWATCHERLINUX_H_ +#pragma once + +#include "FileWatcherImpl.h" + +#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_LINUX + +#include +#include + +namespace FW +{ + /// Implementation for Linux based on inotify. + /// @class FileWatcherLinux + class FileWatcherLinux : public FileWatcherImpl + { + public: + /// type for a map from WatchID to WatchStruct pointer + typedef std::map WatchMap; + + public: + /// + /// + FileWatcherLinux(); + + /// + /// + virtual ~FileWatcherLinux(); + + /// Add a directory watch + /// @exception FileNotFoundException Thrown when the requested directory does not exist + WatchID addWatch(const String& directory, FileWatchListener* watcher, bool recursive); + + /// Remove a directory watch. This is a brute force lazy search O(nlogn). + void removeWatch(const String& directory); + + /// Remove a directory watch. This is a map lookup O(logn). + void removeWatch(WatchID watchid); + + /// Updates the watcher. Must be called often. + void update(); + + /// Handles the action + void handleAction(WatchStruct* watch, const String& filename, unsigned long action); + + private: + /// Map of WatchID to WatchStruct pointers + WatchMap mWatches; + /// The last watchid + WatchID mLastWatchID; + /// inotify file descriptor + int mFD; + /// time out data + struct timeval mTimeOut; + /// File descriptor set + fd_set mDescriptorSet; + + };//end FileWatcherLinux + +};//namespace FW + +#endif//FILEWATCHER_PLATFORM_LINUX + +#endif//_FW_FILEWATCHERLINUX_H_ diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherOSX.cpp b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherOSX.cpp new file mode 100644 index 0000000..861b6ec --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherOSX.cpp @@ -0,0 +1,400 @@ +/** + Copyright (c) 2009 James Wynn (james@jameswynn.com) + + 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. + + James Wynn james@jameswynn.com +*/ + +/** + Major changes Doug Binks + **/ + +#include "FileWatcherOSX.h" + +#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_KQUEUE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace FW +{ + +#define MAX_FILELIST_SIZE 2048 + + typedef struct kevent KEvent; + + struct FileInfo + { + FileInfo() + : mFilename(0), mModifiedTime(0) + { + } + const char* mFilename; + time_t mModifiedTime; + }; + + int comparator(const void* f1, const void* f2) + { + FileInfo* finfo1 = (FileInfo*)f1; + FileInfo* finfo2 = (FileInfo*)f2; + + int retVal = strcmp(finfo1->mFilename, finfo2->mFilename); + + return retVal; + } + + + struct WatchStruct + { + WatchID mWatchID; + String mDirName; + FileWatchListener* mListener; + KEvent mDirKevent; + + FileInfo mFileList[MAX_FILELIST_SIZE]; + size_t mFileListCount; + + WatchStruct(WatchID watchid, const String& dirname, FileWatchListener* listener) + : mWatchID(watchid), mDirName(dirname), mListener(listener), mFileListCount( 0 ) + { + addAll(true); + } + + ~WatchStruct() + { + removeAll(); + } + + void addFile(const std::string& name) + { + // create entry in file list + struct stat attrib; + stat(name.c_str(), &attrib); + + char* namecopy = new char[name.length() + 1]; + strncpy(namecopy, name.c_str(), name.length()); + namecopy[name.length()] = 0; + mFileList[mFileListCount].mFilename = namecopy; + mFileList[mFileListCount].mModifiedTime = attrib.st_mtime; + ++mFileListCount; + + } + void removeFile(const std::string& name) + { + // bsearch + FileInfo key; + key.mFilename = name.c_str(); + FileInfo* found = (FileInfo*)bsearch(&key, &mFileList, mFileListCount, sizeof(FileInfo), comparator); + if(!found) + { + return; + } + + key.mFilename = 0; // prevent deletion of key string + delete found->mFilename; + found->mFilename = 0; + + assert( mFileListCount > 1 ); + // move end to current + memcpy(found, &mFileList[mFileListCount-1], sizeof(FileInfo)); + memset(&mFileList[mFileListCount-1], 0, sizeof(FileInfo)); + --mFileListCount; + } + + // called when the directory is actually changed + // means a file has been added or removed + // rescans the watched directory adding/removing files and sending notices + void rescan() + { + // if new file, call addFile + // if missing file, call removeFile + // if timestamp modified, call handleAction(filename, ACTION_MODIFIED); + DIR* dir = opendir(mDirName.c_str()); + if(!dir) + return; + + struct dirent* dentry; + size_t fileIndex = 0; + struct stat attrib; + bool bRescanRequired = false; //if files are added or deleted we need a rescan. + while((dentry = readdir(dir)) != NULL) + { + std::string fname = mDirName.m_string + "/" + dentry->d_name; + stat(fname.c_str(), &attrib); + if(!S_ISREG(attrib.st_mode)) + continue; + + if( fileIndex < mFileListCount ) + { + FileInfo& entry = mFileList[fileIndex]; + int result = strcmp(entry.mFilename, fname.c_str()); + if(result == 0) + { + stat(entry.mFilename, &attrib); + time_t timestamp = attrib.st_mtime; + + if(entry.mModifiedTime != timestamp) + { + entry.mModifiedTime = timestamp; + handleAction(entry.mFilename, Actions::Modified); + } + ++fileIndex; + } + else + { + // file might have been added or deleted + // if we find the file in our list, then we have some deletions up to that point + // otherwise we have an add + bRescanRequired = true; + size_t currFile = fileIndex+1; + while( currFile < mFileListCount ) + { + FileInfo& entry = mFileList[currFile]; + int res = strcmp(entry.mFilename, fname.c_str()); + if(res == 0) + { + //have found the file in our list + break; + } + ++currFile; + } + + //process events but don't add/remove to list. + if( currFile < mFileListCount ) + { + //have some deletions. + while( fileIndex < currFile ) + { + FileInfo& entry = mFileList[currFile]; + handleAction(entry.mFilename, Actions::Delete); + ++fileIndex; + } + ++fileIndex; + } + else + { + //we don't increment fileIndex here as it's an add in the middle. + handleAction(fname.c_str(), Actions::Add); + } + } + } + else + { + // just add + addFile(fname); + handleAction(fname.c_str(), Actions::Add); + ++fileIndex; + } + }//end while + + closedir(dir); + + while( fileIndex < mFileListCount ) + { + // the last files have been deleted... + bRescanRequired = true; + FileInfo& entry = mFileList[fileIndex]; + handleAction(entry.mFilename, Actions::Delete); + ++fileIndex; + } + + if( bRescanRequired ) + { + removeAll(); + addAll(false); + } + }; + + void handleAction(const String& filename, FW::Action action) + { + mListener->handleFileAction(mWatchID, mDirName, filename, action); + } + + void addAll( bool bCreatedirevent ) + { + if( bCreatedirevent ) + { + // add base dir + int fd = open(mDirName.c_str(), O_RDONLY); + EV_SET(&mDirKevent, fd, EVFILT_VNODE, + EV_ADD | EV_ENABLE | EV_CLEAR, + NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_ATTRIB | NOTE_RENAME | NOTE_REVOKE, + 0, 0); + } + + //fprintf(stderr, "ADDED: %s\n", mDirName.c_str()); + + // scan directory and call addFile(name, false) on each file + DIR* dir = opendir(mDirName.c_str()); + if(!dir) + return; + + struct dirent* entry; + struct stat attrib; + while((entry = readdir(dir)) != NULL) + { + std::string fname = (mDirName.m_string + "/" + std::string(entry->d_name)); + stat(fname.c_str(), &attrib); + if(S_ISREG(attrib.st_mode)) + addFile(fname); + //else + // fprintf(stderr, "NOT ADDED: %s (%d)\n", fname.c_str(), attrib.st_mode); + + }//end while + + closedir(dir); + } + + void removeAll() + { + // go through list removing each file but not the directory + for(int i = 0; i < mFileListCount; ++i) + { + FileInfo& entry = mFileList[i]; + // delete + delete[] entry.mFilename; + entry.mModifiedTime = 0; + } + mFileListCount = 0; + } + }; + + void FileWatcherOSX::update() + { + int nev = 0; + struct kevent event; + + // DJB updated code to handle multiple directories correctly + // first look for events which have occurred in our queue + while((nev = kevent(mDescriptor, 0, 0, &event, 1, &mTimeOut)) != 0) + { + if(nev == -1) + perror("kevent"); + else + { + // have an event, need to find the watch which has this event + WatchMap::iterator iter = mWatches.begin(); + WatchMap::iterator end = mWatches.end(); + for(; iter != end; ++iter) + { + WatchStruct* watch = iter->second; + if( event.ident == watch->mDirKevent.ident ) + { + watch->rescan(); + break; + } + } + } + } + } + + //-------- + FileWatcherOSX::FileWatcherOSX() + { + mDescriptor = kqueue(); + mTimeOut.tv_sec = 0; + mTimeOut.tv_nsec = 0; + } + + //-------- + FileWatcherOSX::~FileWatcherOSX() + { + WatchMap::iterator iter = mWatches.begin(); + WatchMap::iterator end = mWatches.end(); + for(; iter != end; ++iter) + { + delete iter->second; + } + mWatches.clear(); + + close(mDescriptor); + } + + //-------- + WatchID FileWatcherOSX::addWatch(const String& directory, FileWatchListener* watcher, bool recursive) + { +/* int fd = open(directory.c_str(), O_RDONLY); + if(fd == -1) + perror("open"); + + EV_SET(&change, fd, EVFILT_VNODE, + EV_ADD | EV_ENABLE | EV_ONESHOT, + NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_ATTRIB, + 0, (void*)"testing"); +*/ + + WatchStruct* watch = new WatchStruct(++mLastWatchID, directory, watcher); + mWatches.insert(std::make_pair(mLastWatchID, watch)); + + // DJB we add the event to our kqueue (but don't request any return events, these are looked for in update loop + kevent(mDescriptor, (KEvent*)&(watch->mDirKevent), 1, 0, 0, 0); + + return mLastWatchID; + } + + //-------- + void FileWatcherOSX::removeWatch(const String& directory) + { + WatchMap::iterator iter = mWatches.begin(); + WatchMap::iterator end = mWatches.end(); + for(; iter != end; ++iter) + { + if(directory == iter->second->mDirName) + { + removeWatch(iter->first); + return; + } + } + } + + //-------- + void FileWatcherOSX::removeWatch(WatchID watchid) + { + WatchMap::iterator iter = mWatches.find(watchid); + + if(iter == mWatches.end()) + return; + + WatchStruct* watch = iter->second; + mWatches.erase(iter); + + //inotify_rm_watch(mFD, watchid); + + delete watch; // Note: this also removes the event for the watch from the queue + watch = 0; + } + + //-------- + void FileWatcherOSX::handleAction(WatchStruct* watch, const String& filename, unsigned long action) + { + assert(false);//should not get here for OSX impl + } + +};//namespace FW + +#endif//FILEWATCHER_PLATFORM_KQUEUE diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherOSX.h b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherOSX.h new file mode 100644 index 0000000..579a7df --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherOSX.h @@ -0,0 +1,88 @@ +/** + Implementation header file for OSX based on KEvent. + + @author James Wynn + @date 4/15/2009 + + Copyright (c) 2009 James Wynn (james@jameswynn.com) + + 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. +*/ +#ifndef _FW_FILEWATCHEROSX_H_ +#define _FW_FILEWATCHEROSX_H_ +#pragma once + +#include "FileWatcherImpl.h" + +#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_KQUEUE + +#include +#include + +namespace FW +{ + /// Implementation for OSX based on kqueue. + /// @class FileWatcherOSX + class FileWatcherOSX : public FileWatcherImpl + { + public: + /// type for a map from WatchID to WatchStruct pointer + typedef std::map WatchMap; + + public: + /// + /// + FileWatcherOSX(); + + /// + /// + virtual ~FileWatcherOSX(); + + /// Add a directory watch + WatchID addWatch(const String& directory, FileWatchListener* watcher, bool recursive); + + /// Remove a directory watch. This is a brute force lazy search O(nlogn). + void removeWatch(const String& directory); + + /// Remove a directory watch. This is a map lookup O(logn). + void removeWatch(WatchID watchid); + + /// Updates the watcher. Must be called often. + void update(); + + /// Handles the action + void handleAction(WatchStruct* watch, const String& filename, unsigned long action); + + private: + /// Map of WatchID to WatchStruct pointers + WatchMap mWatches; + /// The descriptor for the kqueue + int mDescriptor; + /// time out data + struct timespec mTimeOut; + /// WatchID allocator + int mLastWatchID; + + };//end FileWatcherOSX + +};//namespace FW + +#endif//__APPLE_CC__ + +#endif//_FW_FILEWATCHEROSX_H_ diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherWin32.cpp b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherWin32.cpp new file mode 100644 index 0000000..86ecf0c --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherWin32.cpp @@ -0,0 +1,361 @@ +/** + Copyright (c) 2009 James Wynn (james@jameswynn.com) + + 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 "FileWatcherWin32.h" + +#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_WIN32 + +#include + +#if defined(_MSC_VER) +#pragma comment(lib, "comctl32.lib") +#pragma comment(lib, "user32.lib") +#pragma comment(lib, "ole32.lib") + +// disable secure warnings +#pragma warning (disable: 4996) +#endif + +namespace FW +{ + /// Internal watch data + struct WatchStruct + { + OVERLAPPED mOverlapped; + HANDLE mDirHandle; + BYTE mBuffer[32 * 1024]; + LPARAM lParam; + DWORD mNotifyFilter; + bool mStopNow; + FileWatcherImpl* mFileWatcher; + FileWatchListener* mFileWatchListener; + char* mDirName; + WatchID mWatchid; + bool mIsRecursive; + }; + +#pragma region Internal Functions + + // forward decl + bool RefreshWatch(WatchStruct* pWatch, bool _clear = false); + + /// Unpacks events and passes them to a user defined callback. + void CALLBACK WatchCallback(DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped) + { +#ifndef WIN32_FW_USE_FINDFIRST_API + char szFile[MAX_PATH]; + PFILE_NOTIFY_INFORMATION pNotify; + WatchStruct* pWatch = (WatchStruct*) lpOverlapped; + size_t offset = 0; + + if(dwNumberOfBytesTransfered == 0) + return; + + if (dwErrorCode == ERROR_SUCCESS) + { + do + { + pNotify = (PFILE_NOTIFY_INFORMATION) &pWatch->mBuffer[offset]; + offset += pNotify->NextEntryOffset; + + + int count = WideCharToMultiByte(CP_ACP, 0, pNotify->FileName, + pNotify->FileNameLength / sizeof(WCHAR), + szFile, MAX_PATH - 1, NULL, NULL); + szFile[count] = TEXT('\0'); + + + pWatch->mFileWatcher->handleAction(pWatch, szFile, pNotify->Action); + + } while (pNotify->NextEntryOffset != 0); + } + + if (!pWatch->mStopNow) + { + RefreshWatch(pWatch); + } +#endif + } + + /// Refreshes the directory monitoring. + bool RefreshWatch(WatchStruct* pWatch, bool _clear) + { +#ifndef WIN32_FW_USE_FINDFIRST_API + return ReadDirectoryChangesW( + pWatch->mDirHandle, pWatch->mBuffer, sizeof(pWatch->mBuffer), pWatch->mIsRecursive, + pWatch->mNotifyFilter, NULL, &pWatch->mOverlapped, _clear ? 0 : WatchCallback) != 0; +#else + return true; +#endif + } + + /// Stops monitoring a directory. + void DestroyWatch(WatchStruct* pWatch) + { + if (pWatch) + { + pWatch->mStopNow = TRUE; + +#ifndef WIN32_FW_USE_FINDFIRST_API + CancelIo(pWatch->mDirHandle); + + RefreshWatch(pWatch, true); + + if (!HasOverlappedIoCompleted(&pWatch->mOverlapped)) + { + SleepEx(5, TRUE); + } + + CloseHandle(pWatch->mOverlapped.hEvent); + CloseHandle(pWatch->mDirHandle); +#endif + + delete[] pWatch->mDirName; + HeapFree(GetProcessHeap(), 0, pWatch); + } + } + + /// Starts monitoring a directory. + WatchStruct* CreateWatch(const char* szDirectory, bool recursive, DWORD mNotifyFilter) + { + WatchStruct* pWatch; + size_t ptrsize = sizeof(*pWatch); + pWatch = static_cast(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ptrsize)); + +#ifndef WIN32_FW_USE_FINDFIRST_API + pWatch->mDirHandle = CreateFileA(szDirectory, FILE_LIST_DIRECTORY, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, + OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL); + + if (pWatch->mDirHandle != INVALID_HANDLE_VALUE) + { + pWatch->mOverlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + pWatch->mNotifyFilter = mNotifyFilter; + pWatch->mIsRecursive = recursive; + + if (RefreshWatch(pWatch)) + { + return pWatch; + } + else + { + CloseHandle(pWatch->mOverlapped.hEvent); + CloseHandle(pWatch->mDirHandle); + } + } + + HeapFree(GetProcessHeap(), 0, pWatch); + return NULL; +#else + + return pWatch; + +#endif + } + +#pragma endregion + + //-------- + FileWatcherWin32::FileWatcherWin32() + : mLastWatchID(0) + { + } + + //-------- + FileWatcherWin32::~FileWatcherWin32() + { + WatchMap::iterator iter = mWatches.begin(); + WatchMap::iterator end = mWatches.end(); + for(; iter != end; ++iter) + { + DestroyWatch(iter->second); + } + mWatches.clear(); + } + + //-------- + WatchID FileWatcherWin32::addWatch(const String& directory, FileWatchListener* watcher, bool recursive) + { + WatchStruct* watch = CreateWatch(directory.c_str(), recursive, + FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_FILE_NAME); + + #ifdef WIN32_FW_USE_FINDFIRST_API + WatchID watchid = (unsigned long)fw.add( directory.m_string ); + #else + WatchID watchid = ++mLastWatchID; + #endif + + if(watch) + { + watch->mWatchid = watchid; + watch->mFileWatcher = this; + watch->mFileWatchListener = watcher; + watch->mDirName = new char[directory.m_string.length()+1]; + strcpy(watch->mDirName, directory.c_str()); + } + + + mWatches.insert(std::make_pair(watchid, watch)); + + + + return watchid; + } + + //-------- + void FileWatcherWin32::removeWatch(const String& directory) + { + WatchMap::iterator iter = mWatches.begin(); + WatchMap::iterator end = mWatches.end(); + for(; iter != end; ++iter) + { + if(directory == iter->second->mDirName) + { + removeWatch(iter->first); + return; + } + } + } + + //-------- + void FileWatcherWin32::removeWatch(WatchID watchid) + { + WatchMap::iterator iter = mWatches.find(watchid); + + if(iter == mWatches.end()) + return; + + WatchStruct* watch = iter->second; + +#ifdef WIN32_FW_USE_FINDFIRST_API + fw.remove(watch->mWatchid); +#endif + + mWatches.erase(iter); + + DestroyWatch(watch); + } + + //-------- + void FileWatcherWin32::update() + { +#ifndef WIN32_FW_USE_FINDFIRST_API + MsgWaitForMultipleObjectsEx(0, NULL, 0, QS_ALLINPUT, MWMO_ALERTABLE); +#endif + +#ifdef WIN32_FW_USE_FINDFIRST_API + static std::vector events; + events.clear(); + + fw.watch(events); + + for( size_t c = 0; c != events.size(); ++c ) + { + WatchMap::iterator iter = mWatches.find(events[c].id); + if(iter == mWatches.end()) + continue; + + + switch(events[c].ty) + { + case FileWatcherWin32_AltImpl::CHANGE_SIZE: + { + std::string old_name; + DWORD fni; + std::string new_name = fw.get_event_filename( iter->second->mDirName, events[c].id, events[c].ty, fni, old_name ); + + if( !new_name.empty() ) + { + handleAction(iter->second, new_name.c_str(), fni ); + } + + break; + } + case FileWatcherWin32_AltImpl::CHANGE_FILE_NAME: + { + std::string old_name; + DWORD fni; + std::string new_name = fw.get_event_filename( iter->second->mDirName, events[c].id, events[c].ty, fni, old_name ); + + if( !new_name.empty() ) + { + //changed from-to + if( !old_name.empty() ) + { + handleAction(iter->second, old_name.c_str(), FILE_ACTION_RENAMED_OLD_NAME ); + handleAction(iter->second, new_name.c_str(), FILE_ACTION_RENAMED_NEW_NAME ); + } + else + { + handleAction(iter->second, new_name.c_str(), fni ); + } + } + + break; + } + case FileWatcherWin32_AltImpl::CHANGE_LAST_WRITE: + case FileWatcherWin32_AltImpl::CHANGE_CREATION: + { + std::string old_name; + DWORD fni; + std::string new_name = fw.get_event_filename( iter->second->mDirName, events[c].id, events[c].ty, fni, old_name ); + + if( !new_name.empty() ) + { + handleAction(iter->second, new_name.c_str(), fni ); + } + + break; + } + default: + break; + } + } +#endif + } + + //-------- + void FileWatcherWin32::handleAction(WatchStruct* watch, const String& filename, unsigned long action) + { + Action fwAction; + + switch(action) + { + case FILE_ACTION_RENAMED_NEW_NAME: + case FILE_ACTION_ADDED: + fwAction = Actions::Add; + break; + case FILE_ACTION_RENAMED_OLD_NAME: + case FILE_ACTION_REMOVED: + fwAction = Actions::Delete; + break; + case FILE_ACTION_MODIFIED: + fwAction = Actions::Modified; + break; + }; + + watch->mFileWatchListener->handleFileAction(watch->mWatchid, watch->mDirName, filename, fwAction); + } + +};//namespace FW + +#endif//_WIN32 diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherWin32.h b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherWin32.h new file mode 100644 index 0000000..097277a --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherWin32.h @@ -0,0 +1,98 @@ +/** + Implementation for Windows. Uses ReadDirectoryChangesW to watch for + file system changes. + + @author James Wynn + @date 4/15/2009 + + Copyright (c) 2009 James Wynn (james@jameswynn.com) + + 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. +*/ + +#ifndef _FW_FILEWATCHERWIN32_H_ +#define _FW_FILEWATCHERWIN32_H_ +#pragma once + +#include "FileWatcherImpl.h" + +#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_WIN32 + +// Uncomment define below or include in build options to use FindFirstChangeNotification +// rather than ReadDirectoryChanges +// #define WIN32_FW_USE_FINDFIRST_API + +#ifdef WIN32_FW_USE_FINDFIRST_API +#include "FileWatcherWin32_AltImpl.h" +#endif + + +#include + +namespace FW +{ + /// Implementation for Win32 based on ReadDirectoryChangesW. + /// @class FileWatcherWin32 + class FileWatcherWin32 : public FileWatcherImpl + { + public: + /// type for a map from WatchID to WatchStruct pointer + typedef std::map WatchMap; + + public: + /// + /// + FileWatcherWin32(); + + /// + /// + virtual ~FileWatcherWin32(); + + /// Add a directory watch + WatchID addWatch(const String& directory, FileWatchListener* watcher, bool recursive); + + /// Remove a directory watch. This is a brute force lazy search O(nlogn). + void removeWatch(const String& directory); + + /// Remove a directory watch. This is a map lookup O(logn). + void removeWatch(WatchID watchid); + + /// Updates the watcher. Must be called often. + void update(); + + /// Handles the action + void handleAction(WatchStruct* watch, const String& filename, unsigned long action); + + private: + /// Map of WatchID to WatchStruct pointers + WatchMap mWatches; + /// The last watchid + WatchID mLastWatchID; + +#ifdef WIN32_FW_USE_FINDFIRST_API + FileWatcherWin32_AltImpl fw; +#endif + + };//end FileWatcherWin32 + +};//namespace FW + +#endif//FILEWATCHER_PLATFORM_WIN32 + +#endif//_FW_FILEWATCHERWIN32_H_ diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherWin32_AltImpl.h b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherWin32_AltImpl.h new file mode 100644 index 0000000..acb2d0e --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherWin32_AltImpl.h @@ -0,0 +1,367 @@ +// +// Copyright (c) 2013 Márton Tamás +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +// Minor modifications by Doug Binks +// This implementation for FileWatcherWin32 uses FindFirstChangeNotification rather +// than ReadDirectoryChanges + +#ifndef _FileWatcherWin32_AltImpl_h_ +#define _FileWatcherWin32_AltImpl_h_ +#pragma once + + +#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_WIN32 + +#include +#include +#include + +#define WIN32_LEAN_AND_MEAN +#include + +namespace FW +{ + const static int fw_types[] = { FILE_NOTIFY_CHANGE_LAST_WRITE, FILE_NOTIFY_CHANGE_CREATION, FILE_NOTIFY_CHANGE_SIZE, FILE_NOTIFY_CHANGE_FILE_NAME }; + const static size_t NUMTYPES = sizeof(fw_types)/sizeof(int); + + class FileWatcherWin32_AltImpl + { + struct filedata + { + std::string fname; + LARGE_INTEGER fsize; + FILETIME ftime; + FILETIME fwritetime; + filedata( std::string n = std::string(), LARGE_INTEGER s = LARGE_INTEGER(), FILETIME t = FILETIME(), FILETIME tw = FILETIME()) + { + fname = n; + fsize = s; + ftime = t; + fwritetime = tw; + } + }; + + std::vector< HANDLE > handles[NUMTYPES]; + std::vector< std::vector< filedata > > dir_contents; + + void get_dir_contents( const std::string& path, std::vector< filedata >& contents ) + { + WIN32_FIND_DATAA fd; + HANDLE dir_lister = FindFirstFileA( (path + "\\*").c_str(), &fd ); + + if( dir_lister == INVALID_HANDLE_VALUE ) + { + std::cout << "Couldn't list files." << std::endl; + return; + } + + do + { + if( !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) + { + LARGE_INTEGER fsize; + fsize.LowPart = fd.nFileSizeLow; + fsize.HighPart = fd.nFileSizeHigh; + FILETIME ftime; + ftime = fd.ftCreationTime; + FILETIME fwritetime; + fwritetime = fd.ftLastWriteTime; + contents.push_back(filedata( fd.cFileName, fsize, ftime, fwritetime )); + } + } + while(FindNextFileA(dir_lister, &fd) != 0); + + FindClose(dir_lister); + } + public: + + ~FileWatcherWin32_AltImpl() + { + for( int c = 0; c < NUMTYPES; ++c ) + { + for( size_t d = 0; d != handles[c].size(); ++d ) + { + FindCloseChangeNotification(handles[c][d]); + } + } + } + + enum type + { + CHANGE_LAST_WRITE = 0, CHANGE_CREATION, CHANGE_SIZE, CHANGE_FILE_NAME, CHANGE_NONE + }; + + struct fw_event + { + size_t id; + type ty; + fw_event( size_t i = -1, type t = CHANGE_NONE ) + { + id = i; + ty = t; + } + }; + + size_t add( const std::string& path ) + { + size_t id = handles[0].size(); + + for( int c = 0; c < NUMTYPES; ++c ) + { + handles[c].push_back( FindFirstChangeNotificationA( path.c_str(), false, fw_types[c] ) ); + } + + for( int c = 0; c < NUMTYPES; ++c ) + { + if( handles[c][id] == INVALID_HANDLE_VALUE ) + { + std::cerr << "Couldn't create handle." << std::endl; + return -1; + } + } + + dir_contents.resize(id + 1); + get_dir_contents( path, dir_contents[id] ); + + return id; + } + + bool watch(std::vector& ids) + { + for( int c = 0; c < NUMTYPES; ++c ) + { + DWORD status = WaitForMultipleObjects(handles[c].size(), &handles[c][0], false, 0); + + for( size_t d = 0; d < handles[c].size(); ++d ) + { + if( status == WAIT_OBJECT_0 + d ) + { + ids.push_back( fw_event( d, (type)c ) ); + if( FindNextChangeNotification( handles[c][d] ) == false ) + { + return false; + } + } + } + } + + return true; + } + + std::string get_event_filename( const std::string& path, size_t id, type ty, DWORD& fni, std::string& old_name ) + { + static std::vector< filedata > contents; + contents.clear(); + + get_dir_contents( path, contents ); + + switch(ty) + { + //change in file write time + //find the not matching write time + case CHANGE_LAST_WRITE: + { + for( auto c = contents.begin(); c != contents.end(); ++c ) + { + for( auto d = dir_contents[id].begin(); d != dir_contents[id].end(); ++d ) + { + if( c->fname == d->fname && + ( c->fwritetime.dwLowDateTime != d->fwritetime.dwLowDateTime || + c->fwritetime.dwHighDateTime != d->fwritetime.dwHighDateTime ) + ) + { + //make sure we 'neutralize' the event + d->fwritetime.dwLowDateTime = c->fwritetime.dwLowDateTime; + d->fwritetime.dwHighDateTime = c->fwritetime.dwHighDateTime; + fni = FILE_ACTION_MODIFIED; + return d->fname; + } + } + } + break; + } + //change in file creation time + //find the not matching creation time + case CHANGE_CREATION: + { + for( auto c = contents.begin(); c != contents.end(); ++c ) + { + for( auto d = dir_contents[id].begin(); d != dir_contents[id].end(); ++d ) + { + if( c->fname == d->fname && + ( c->ftime.dwLowDateTime != d->ftime.dwLowDateTime || + c->ftime.dwHighDateTime != d->ftime.dwHighDateTime ) + ) + { + //make sure we 'neutralize' the event + d->ftime.dwLowDateTime = c->ftime.dwLowDateTime; + d->ftime.dwHighDateTime = c->ftime.dwHighDateTime; + fni = FILE_ACTION_ADDED; + return d->fname; + } + } + } + break; + } + //change in file name + //find the new filename, and add it + //remove the old filename + case CHANGE_FILE_NAME: + { + std::string filename; + + bool file_deleted = contents.size() < dir_contents[id].size(); + + for( auto c = contents.begin(); c != contents.end(); ++c ) + { + bool found = false; + for( auto d = dir_contents[id].begin(); d != dir_contents[id].end(); ++d ) + { + if( c->fname == d->fname ) + { + found = true; + break; + } + } + + if( !found ) + { + //this is what we are looking for, the new filename + filename = c->fname; + dir_contents[id].push_back(*c); //add the new file + fni = FILE_ACTION_ADDED; + break; + } + } + + for( auto c = dir_contents[id].begin(); c != dir_contents[id].end(); ++c ) + { + bool found = false; + + for( auto d = contents.begin(); d != contents.end(); ++d ) + { + if( c->fname == d->fname ) + { + found = true; + break; + } + } + + if( !found ) + { + //this is the old filename + + if( file_deleted ) //file removed + { + filename = c->fname; + fni = FILE_ACTION_REMOVED; + } + else + { + old_name = c->fname; + fni = FILE_ACTION_MODIFIED; + } + + dir_contents[id].erase(c); + return filename; + } + } + + //in case a new file was created + if( !filename.empty() ) + { + fni = FILE_ACTION_ADDED; + return filename; + } + + break; + } + //change in file size + //find the not matching file size + case CHANGE_SIZE: + { + for( auto c = contents.begin(); c != contents.end(); ++c ) + { + for( auto d = dir_contents[id].begin(); d != dir_contents[id].end(); ++d ) + { + if( c->fname == d->fname && + ( c->fsize.LowPart != d->fsize.LowPart || + c->fsize.HighPart != d->fsize.HighPart ) + ) + { + //make sure we 'neutralize' the event + d->fsize.LowPart = c->fsize.LowPart; + d->fsize.HighPart = c->fsize.HighPart; + fni = FILE_ACTION_MODIFIED; + return d->fname; + } + } + } + + //new file + for( auto c = contents.begin(); c != contents.end(); ++c ) + { + bool found = false; + for( auto d = dir_contents[id].begin(); d != dir_contents[id].end(); ++d ) + { + if( c->fname == d->fname ) + { + found = true; + break; + } + } + + if( !found ) + { + //this is what we are looking for, the new filename + fni = FILE_ACTION_ADDED; + return c->fname; + } + } + + break; + } + default: + break; + } + + return ""; + } + + void remove( size_t id ) + { + for( int c = 0; c < NUMTYPES; ++c ) + { + auto it = handles[c].begin(); + auto it2 = dir_contents.begin(); + for( int d = 0; d < id; ++d ) + { + ++it; + ++it2; + }; + FindCloseChangeNotification( handles[c][id] ); + handles[c].erase(it); + dir_contents.erase(it2); + } + } + }; + +} + +#endif + +#endif \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/.cproject b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/.cproject new file mode 100644 index 0000000..a04f8ac --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/.cproject @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/.project b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/.project new file mode 100644 index 0000000..d4187d1 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/.project @@ -0,0 +1,27 @@ + + + RuntimeObjectSystem + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/IObject.h b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/IObject.h new file mode 100644 index 0000000..1519aeb --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/IObject.h @@ -0,0 +1,141 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +//////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// IObject header file. +// +// The RuntimeCompiler library does not declare an IObject interface, only forward declares it. +// Hence each project can define their own base interface for objects they want to runtime compile +// and construct by using their own declaration of IObject in their own header file. +// +//////////////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#ifndef IOBJECT_INCLUDED +#define IOBJECT_INCLUDED + +#include "ObjectInterface.h" + +struct ISimpleSerializer; +class ObjectFactorySystem; + +// IIDs +enum InterfaceIDEnum +{ + IID_IOBJECT, + + IID_ENDInterfaceID +}; + +typedef unsigned int InterfaceID; + +// Template to help with IIDs +template< InterfaceID Tiid, typename TSuper> struct TInterface : public TSuper +{ + static const InterfaceID s_interfaceID = Tiid; + virtual void GetInterface( InterfaceID _iid, void** pReturn ) + { + switch(_iid) + { + case Tiid: + *pReturn= this; + break; + default: + TSuper::GetInterface(_iid, pReturn); + } + } +}; + +// IObject itself below is a special case as the base class +// Also it doesn't hurt to have it coded up explicitly for reference + +struct IObject +{ + static const InterfaceID s_interfaceID = IID_IOBJECT; + + virtual void GetInterface( InterfaceID iid, void** pReturn ) + { + switch( iid ) + { + case IID_IOBJECT: + *pReturn = this; + break; + default: + *pReturn = NULL; + } + } + + template< typename T> void GetInterface( T** pReturn ) + { + GetInterface( T::s_interfaceID, (void**)pReturn ); + } + + + IObject() : _isRuntimeDelete(false) {} + virtual ~IObject() + { + } + + // Perform any object initialization + // Should be called with isFirstInit=true on object creation + // Will automatically be called with isFirstInit=false whenever a system serialization is performed + virtual void Init( bool isFirstInit ) + { + } + + //return the PerTypeObjectId of this object, which is unique per class + virtual PerTypeObjectId GetPerTypeId() const = 0; + + virtual void GetObjectId( ObjectId& id ) const + { + id.m_ConstructorId = GetConstructor()->GetConstructorId(); + id.m_PerTypeId = GetPerTypeId(); + } + virtual ObjectId GetObjectId() const + { + ObjectId ret; + GetObjectId( ret ); + return ret; + } + + + //return the constructor for this class + virtual IObjectConstructor* GetConstructor() const = 0; + + //serialise is not pure virtual as many objects do not need state + virtual void Serialize(ISimpleSerializer *pSerializer) {}; + + virtual const char* GetTypeName() const = 0; + + +protected: + bool IsRuntimeDelete() { return _isRuntimeDelete; } + +private: + friend class ObjectFactorySystem; + + // Set to true when object is being deleted because a new version has been created + // Destructor should use this information to not delete other IObjects in this case + // since these objects will still be needed + bool _isRuntimeDelete; +}; + + + +#endif //IOBJECT_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/IObjectFactorySystem.h b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/IObjectFactorySystem.h new file mode 100644 index 0000000..e2474d7 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/IObjectFactorySystem.h @@ -0,0 +1,74 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef IOBJECTFACTORYSYSTEM_INCLUDED +#define IOBJECTFACTORYSYSTEM_INCLUDED + +#include "../RuntimeCompiler/AUArray.h" +#include "../RuntimeObjectSystem/ObjectInterface.h" +#include "../RuntimeCompiler/ICompilerLogger.h" +struct IRuntimeObjectSystem; + +struct IObjectFactoryListener +{ + // Called after a full serialization of objects is done when a new + // object constructor is added, so listeners can update any object + // pointers they're holding + virtual void OnConstructorsAdded() = 0; + virtual ~IObjectFactoryListener() {} +}; + +struct IObjectFactorySystem +{ + virtual IObjectConstructor* GetConstructor( const char* type ) const = 0; + virtual ConstructorId GetConstructorId( const char* type ) const = 0; + virtual IObjectConstructor* GetConstructor( ConstructorId id ) const = 0; + virtual void AddConstructors(IAUDynArray &constructors) = 0; + virtual void GetAll(IAUDynArray &constructors) const = 0; + virtual IObject* GetObject( ObjectId id ) const = 0; + + virtual void AddListener(IObjectFactoryListener* pListener) = 0; + virtual void RemoveListener(IObjectFactoryListener* pListener) = 0; + virtual void SetLogger( ICompilerLogger* pLogger ) = 0; + virtual void SetRuntimeObjectSystem( IRuntimeObjectSystem* pRuntimeObjectSystem ) = 0; + virtual void SetTestSerialization( bool bTest ) = 0; + virtual bool GetTestSerialization() const = 0; + virtual ~IObjectFactorySystem() {} + + // sets the history of object constructors to a given size + // if set to smaller than before, will preserve the latest + // will not resize smaller than required to preserve current undo state + // default history size is 0, which means history is off (no undo & redo) + // if AddConstructors is called when the current history location is -ve, + // the constructors are updated to locatin 0 (current) prior to adding. + virtual void SetObjectConstructorHistorySize( int num_ ) = 0; + virtual int GetObjectConstructorHistorySize() = 0; + + // undo & redo object constructor changes + // this will only undo swapped constructors, not new ones + virtual bool UndoObjectConstructorChange() = 0; + virtual bool RedoObjectConstructorChange() = 0; + + // history location is 0 for current, +ve number for a previous location + // undo calls causes location +1, redo -1 bounded by HistorySize and 0. + virtual int GetObjectContstructorHistoryLocation() = 0; +}; + + +#endif //IOBJECTFACTORYSYSTEM_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/IRuntimeObjectSystem.h b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/IRuntimeObjectSystem.h new file mode 100644 index 0000000..7b4e79c --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/IRuntimeObjectSystem.h @@ -0,0 +1,144 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef IRUNTIMEOBJECTSYSTEM_INCLUDED +#define IRUNTIMEOBJECTSYSTEM_INCLUDED + +#include "../RuntimeCompiler/CompileOptions.h" + +struct ICompilerLogger; +struct IObjectFactorySystem; +struct IFileChangeNotifier; +class BuildTool; +struct RuntimeProtector; +struct SystemTable; +struct IPerModuleInterface; + +enum TestBuildResult +{ + TESTBUILDRRESULT_SUCCESS, // SUCCESS, yay! + TESTBUILDRRESULT_NO_FILES_TO_BUILD, // file registration error or no runtime files of this type + TESTBUILDRRESULT_BUILD_FILE_GONE, // the file is no longer present + TESTBUILDRRESULT_BUILD_NOT_STARTED, // file change detection could be broken, or if an include may not be included anywhere + TESTBUILDRRESULT_BUILD_FAILED, // a build was started, but it failed or module failed to load. See log. + TESTBUILDRRESULT_OBJECT_SWAP_FAIL, // build succeeded, module loaded but errors on swapping +}; + + +struct ITestBuildNotifier +{ + // Notifier gets name of file which and result type. + // Errors will also be output to log in 'standard' RCC++ way. + // file may be NULL if type TESTBUILDFAILTYPE_NO_FILES_TO_BUILD. + // The default callback outputs result and file to log, and returns true. + // + // Return true to continue with testing more files or false to end test. + virtual bool TestBuildCallback(const char* file, TestBuildResult type) = 0; + + // Notifier should implement sleep function for a small interval - say 10-100ms. + // Additionally, any message queues / view updates should be handled here, especially + // on Win32 where the file change notifiers need the message queue to be processed. + // Default uses usleep or Sleep, dispatches messages on Win32 and returns true. + // + // Return true to continue with testing or false to end test. + virtual bool TestBuildWaitAndUpdate() = 0; +}; + +namespace FileSystemUtils +{ + class Path; +} + +struct IRuntimeObjectSystem : public ITestBuildNotifier +{ + // Initialise RuntimeObjectSystem. pLogger and pSystemTable should be deleted by creator. + // Both pLogger and pSystemTable can be 0 + virtual bool Initialise( ICompilerLogger * pLogger, SystemTable* pSystemTable ) = 0; + + virtual bool GetIsCompiling() = 0; + virtual bool GetIsCompiledComplete() = 0; + virtual bool LoadCompiledModule() = 0; + virtual bool GetLastLoadModuleSuccess() const = 0; + + // GetNumberLoadedModules() returns total number successfully loaded, not current number loaded + // Mainly useful for detected wether a new module has been loaded by checking for change + virtual unsigned int GetNumberLoadedModules() const = 0; + + virtual IObjectFactorySystem* GetObjectFactorySystem() const = 0; + virtual IFileChangeNotifier* GetFileChangeNotifier() const = 0; + + virtual void CompileAll( bool bForceRecompile ) = 0; + + // Compile & Link settings can be associated with a project identifier. + // This identifier should be defined by the application using RCC++, + // for example using enums or an identifier service. + // Identifier 0 is the default for all code not using the project identifiers. + // The backing storage will use the an array lookup, so use compact identifiers + // such as (0, 1, 2, 3) and not (20,39,42,250). + virtual void CompileAllInProject( bool bForcerecompile_, unsigned short projectId_ = 0 ) = 0; + virtual void AddToRuntimeFileList( const char* filename, unsigned short projectId_ = 0 ) = 0; + virtual void RemoveFromRuntimeFileList( const char* filename, unsigned short projectId_ = 0 ) = 0; + virtual void AddIncludeDir( const char *path_, unsigned short projectId_ = 0 ) = 0; + virtual void AddLibraryDir( const char *path_, unsigned short projectId_ = 0 ) = 0; + virtual void SetAdditionalCompileOptions( const char *options, unsigned short projectId_ = 0 ) = 0; + virtual void SetAdditionalLinkOptions( const char *options, unsigned short projectId_ = 0 ) = 0; + virtual void SetCompilerLocation ( const char* path, unsigned short projectId_ = 0 ) = 0; + virtual void SetOptimizationLevel( RCppOptimizationLevel optimizationLevel_, unsigned short projectId_ = 0 ) = 0; + virtual RCppOptimizationLevel GetOptimizationLevel( unsigned short projectId_ = 0 ) = 0; + + // Intermediate Dir has DEBUG in debug or RELEASE plus project optimization level appended to it. + // defaults to current directory plus /Runtime + virtual void SetIntermediateDir( const char* path_, unsigned short projectId_ = 0 ) = 0; + + virtual void SetAutoCompile( bool autoCompile ) = 0; + virtual bool GetAutoCompile() const = 0; + + // see Compiler::SetFastCompileMode + virtual void SetFastCompileMode( bool bFast ) = 0; + + // clean up temporary object files + virtual void CleanObjectFiles() const = 0; + + virtual void SetupObjectConstructors(IPerModuleInterface* pPerModuleInterface) = 0; + + //ensure subclasses are deleted correctly + virtual ~IRuntimeObjectSystem(){}; + + // exception handling to catch and protect main app from crashing when using runtime compiling + virtual void SetProtectionEnabled( bool bProtectionEnabled_ ) = 0; + virtual bool IsProtectionEnabled() const = 0; + virtual bool TryProtectedFunction( RuntimeProtector* pProtectedObject_ ) = 0; + + // tests one by one touching each runtime modifiable source file + // returns the number of errors - 0 if all passed. + virtual int TestBuildAllRuntimeSourceFiles( ITestBuildNotifier* callback, bool bTestFileTracking ) = 0; + + // tests touching each header which has RUNTIME_MODIFIABLE_INCLUDE. + // returns the number of errors - 0 if all passed. + virtual int TestBuildAllRuntimeHeaders( ITestBuildNotifier* callback, bool bTestFileTracking ) = 0; + + // FindFile - attempts to find the file in a source directory + virtual FileSystemUtils::Path FindFile( const FileSystemUtils::Path& input ) = 0; + + // AddPathToSourceSearch - adds a path to help source search. Can be called multiple times to add paths. + virtual void AddPathToSourceSearch( const char* path ) = 0; + +}; + +#endif // IRUNTIMEOBJECTSYSTEM_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ISimpleSerializer.h b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ISimpleSerializer.h new file mode 100644 index 0000000..0070d08 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ISimpleSerializer.h @@ -0,0 +1,148 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + + +#ifndef ISIMPLESERIALIZER_INCLUDED +#define ISIMPLESERIALIZER_INCLUDED + +// Currently this system is more of a 'property store' rather than a serializer, +// but could be modified in future in that direction if needed, though more likely +// will be scrapped for something more sophisticated + + +#include "../RuntimeObjectSystem/ObjectInterface.h" + + +#define SERIALIZE(prop) pSerializer->SerializeProperty(#prop, prop); + + + + +struct ISerializedValue { + virtual ~ISerializedValue() + { + } +}; + +template +struct SerializedValue : ISerializedValue +{ + // NOTE: this requires value being serialized to have a correct copy constructor that + // will copy all values that would otherwise be deleted when object being serialized + // is deleted + SerializedValue(const T& value) : value(value) + { + } + + const T value; +}; + + +struct ISimpleSerializer +{ + virtual void Clear() = 0; + virtual void Clear(ObjectId ownerId) = 0; + virtual void Clear(ObjectId ownerId, const char* propertyName) = 0; + + virtual bool IsLoading() const = 0; + + // Stores a copy of the value when loading is false + // Returns true on successful property load, or always when saving a value + template bool SerializeProperty(const char* propertyName, T& value); + + // Array of T version of SerializeProperty + // Stores a copy of the value when loading is false + // Returns true on successful property load, or always when saving a value + template bool SerializeProperty(const char* propertyName, T (&arrayIn)[N] ); + + virtual ~ISimpleSerializer( ) {} +private: + // Implementation requires backing the following functions with keyed storage + // pValue should be deleted by implementation in destructor. + virtual void SetISerializedValue(const char* propertyName, const ISerializedValue* pValue) = 0; + virtual const ISerializedValue* GetISerializedValue(const char* propertyName) const = 0; + +}; + + +// NOTE: this is less efficient than having separate functions for setting and getting properties, +// but allows for user code to generally have much simpler serialization methods without needing to +// handle save and load separately (in most cases) +template +inline bool ISimpleSerializer::SerializeProperty(const char* propertyName, T& value) +{ + if (IsLoading()) + { + const SerializedValue* pSV = static_cast*>(GetISerializedValue(propertyName)); + if (!pSV) + { + return false; + } + + value = pSV->value; + } + else + { + const SerializedValue* pSv = new SerializedValue(value); + SetISerializedValue(propertyName, pSv); + } + + return true; +} + +template +struct SerializedValueArray : ISerializedValue +{ + // NOTE: this requires value being serialized to have a correct copy constructor that + // will copy all values that would otherwise be deleted when object being serialized + // is deleted + SerializedValueArray(const T (&arrayIn)[N] ) + { + memcpy( valueArray, arrayIn, sizeof( valueArray) ); + } + + T valueArray[N]; +}; + +// NOTE: this is less efficient than having separate functions for setting and getting properties, +// but allows for user code to generally have much simpler serialization methods without needing to +// handle save and load separately (in most cases) +template +inline bool ISimpleSerializer::SerializeProperty(const char* propertyName, T (&arrayIn)[N]) +{ + if (IsLoading()) + { + const SerializedValueArray* pSV = static_cast*>(GetISerializedValue(propertyName)); + if (!pSV) + { + return false; + } + + memcpy( arrayIn, pSV->valueArray, sizeof( arrayIn ) ); + } + else + { + const SerializedValueArray* pSv = new SerializedValueArray(arrayIn); + SetISerializedValue(propertyName, pSv); + } + + return true; +} + +#endif //ISIMPLESERIALIZER_INCLUDED diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectFactorySystem/ObjectFactorySystem.cpp b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectFactorySystem/ObjectFactorySystem.cpp new file mode 100644 index 0000000..8012f0d --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectFactorySystem/ObjectFactorySystem.cpp @@ -0,0 +1,454 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "ObjectFactorySystem.h" + +#include "../ObjectInterface.h" +#include "../ObjectInterfacePerModule.h" +#include "../IObject.h" +#include "../IRuntimeObjectSystem.h" + + +IObjectConstructor* ObjectFactorySystem::GetConstructor( const char* type ) const +{ + CONSTRUCTORMAP::const_iterator found = m_ConstructorIds.find( type ); + if( found != m_ConstructorIds.end() ) + { + return m_Constructors[ found->second ]; + } + return 0; +} + +ConstructorId ObjectFactorySystem::GetConstructorId( const char* type ) const +{ + CONSTRUCTORMAP::const_iterator found = m_ConstructorIds.find( type ); + if( found != m_ConstructorIds.end() ) + { + return found->second; + } + return InvalidId; +} + +IObjectConstructor* ObjectFactorySystem::GetConstructor( ConstructorId id ) const +{ + if( id < m_Constructors.size() ) + { + return m_Constructors[ id ]; + } + return 0; +} + +void ObjectFactorySystem::ProtectedObjectSwapper::ProtectedFunc() +{ + m_ProtectedPhase = PHASE_SERIALIZEOUT; + + // serialize all out + if( m_pLogger ) m_pLogger->LogInfo( "Serializing out from %d old constructors...\n", (int)m_ConstructorsOld.size()); + + // use a temporary serializer in case there is an exception, so preserving any old state (if there is any) + m_Serializer.SetIsLoading( false ); + for( size_t i = 0; i < m_ConstructorsOld.size(); ++i ) + { + IObjectConstructor* pOldConstructor = m_ConstructorsOld[i]; + size_t numObjects = pOldConstructor->GetNumberConstructedObjects(); + for( size_t j = 0; j < numObjects; ++j ) + { + IObject* pOldObject = pOldConstructor->GetConstructedObject( j ); + if (pOldObject) + { + m_Serializer.Serialize( pOldObject ); + } + } + } + // swap serializer + if( m_pLogger ) m_pLogger->LogInfo( "Swapping in and creating objects for %d new constructors...\n", (int)m_ConstructorsToAdd.size()); + + m_ProtectedPhase = PHASE_CONSTRUCTNEW; + TConstructors& constructorsNew = m_pObjectFactorySystem->m_Constructors; + + //swap old constructors with new ones and create new objects + for( size_t i = 0; i < m_ConstructorsToAdd.size(); ++i ) + { + IObjectConstructor* pConstructor = m_ConstructorsToAdd[i]; + //replace constructor, but if one exists then replace objects + IObjectConstructor* pOldConstructor = m_pObjectFactorySystem->GetConstructor( pConstructor->GetName() ); + + if( pOldConstructor == pConstructor ) + { + // don't add constructor if it's already in existance + continue; + } + + // Reconstruct objects, starting at end to reduce overhead in factory container + if( pOldConstructor ) + { + // replace and construct + pConstructor->SetConstructorId( pOldConstructor->GetConstructorId() ); + constructorsNew[ pConstructor->GetConstructorId() ] = pConstructor; + for( PerTypeObjectId objId = 0; objId < pOldConstructor->GetNumberConstructedObjects(); ++ objId ) + { + // create new object + if( pOldConstructor->GetConstructedObject( objId ) ) + { + pConstructor->Construct(); + } + else + { + pConstructor->ConstructNull(); + } + } + m_ConstructorsReplaced.push_back( pOldConstructor ); + } + else + { + ConstructorId id = constructorsNew.size(); + m_pObjectFactorySystem->m_ConstructorIds[ pConstructor->GetName() ] = id; + constructorsNew.push_back( pConstructor ); + pConstructor->SetConstructorId( id ); + } + } + + if( m_pLogger ) m_pLogger->LogInfo( "Serialising in...\n"); + + //serialize back + m_ProtectedPhase = PHASE_SERIALIZEIN; + m_Serializer.SetIsLoading( true ); + for( size_t i = 0; i < constructorsNew.size(); ++i ) + { + IObjectConstructor* pConstructor = constructorsNew[i]; + for( PerTypeObjectId objId = 0; objId < pConstructor->GetNumberConstructedObjects(); ++ objId ) + { + // Serialize new object + IObject* pObject = pConstructor->GetConstructedObject( objId ); + if (pObject) + { + m_Serializer.Serialize( pObject ); + } + } + } + + // auto construct singletons + // now in 2 phases - construct then init + m_ProtectedPhase = PHASE_AUTOCONSTRUCTSINGLETONS; + std::vector bSingletonConstructed( constructorsNew.size(), false ); + if( m_pLogger ) m_pLogger->LogInfo( "Auto Constructing Singletons...\n"); + for( size_t i = 0; i < constructorsNew.size(); ++i ) + { + IObjectConstructor* pConstructor = constructorsNew[i]; + if( pConstructor->GetIsAutoConstructSingleton() ) + { + if( 0 == pConstructor->GetNumberConstructedObjects() ) + { + pConstructor->GetSingleton(); + bSingletonConstructed[i] = true; + } + } + } + + + // Do a second pass, initializing objects now that they've all been serialized + // and testing serialization if required + m_ProtectedPhase = PHASE_INITANDSERIALIZEOUTTEST; + if( m_bTestSerialization ) + { + if( m_pLogger ) m_pLogger->LogInfo( "Initialising and testing new serialisation...\n"); + } + else + { + if( m_pLogger ) m_pLogger->LogInfo( "Initialising...\n"); + } + + for( size_t i = 0; i < constructorsNew.size(); ++i ) + { + IObjectConstructor* pConstructor = constructorsNew[i]; + for( PerTypeObjectId objId = 0; objId < pConstructor->GetNumberConstructedObjects(); ++ objId ) + { + IObject* pObject = pConstructor->GetConstructedObject( objId ); + if (pObject) + { + // if a singleton was newly constructed in earlier phase, pass true to init. + pObject->Init( bSingletonConstructed[i] ); + + if( m_bTestSerialization && ( m_ConstructorsOld.size() <= i || m_ConstructorsOld[ i ] != constructorsNew[ i ] ) ) + { + //test serialize out for all new objects, we assume old objects are OK. + SimpleSerializer tempSerializer; + tempSerializer.SetIsLoading( false ); + tempSerializer.Serialize( pObject ); + } + } + } + } + + m_ProtectedPhase = PHASE_DELETEOLD; + //delete old objects which have been replaced + for( size_t i = 0; i < m_ConstructorsOld.size(); ++i ) + { + if( m_ConstructorsOld[i] != constructorsNew[i] ) + { + //TODO: could put a constructor around this. + //constructor has been replaced + IObjectConstructor* pOldConstructor = m_ConstructorsOld[i]; + size_t numObjects = pOldConstructor->GetNumberConstructedObjects(); + for( size_t j = 0; j < numObjects; ++j ) + { + IObject* pOldObject = pOldConstructor->GetConstructedObject( j ); + if( pOldObject ) + { + pOldObject->_isRuntimeDelete = true; + delete pOldObject; + } + } + pOldConstructor->ClearIfAllDeleted(); + assert( 0 == pOldConstructor->GetNumberConstructedObjects() ); + } + } +} + +bool ObjectFactorySystem::HandleRedoUndo( const TConstructors& constructors ) +{ + if( constructors.size() == 0 ) + { + m_pLogger->LogInfo( "ObjectFactorySystem::HandleRedoUndo() called with no constructors.\n" ); + return true; + } + + ProtectedObjectSwapper swapper; + swapper.m_ConstructorsToAdd = constructors; + swapper.m_ConstructorsOld = m_Constructors; + swapper.m_pLogger = m_pLogger; + swapper.m_pObjectFactorySystem = this; + swapper.m_bTestSerialization = false; // we don't need to test as this should alraedy have been done + + swapper.m_ProtectedPhase = PHASE_NONE; + // we use the protected function to do all serialization + m_pRuntimeObjectSystem->TryProtectedFunction( &swapper ); + + CompleteConstructorSwap( swapper ); + + return !swapper.HasHadException() || ( PHASE_DELETEOLD == swapper.m_ProtectedPhase ); +} + +void ObjectFactorySystem::AddConstructors( IAUDynArray &constructors ) +{ + if( constructors.Size() == 0 ) + { + m_pLogger->LogInfo( "ObjectFactorySystem::AddConstructors() called with no constructors.\n" ); + return; + } + + if( m_HistoryCurrentLocation ) + { + m_pLogger->LogInfo( "Need to fast forward undo system to current state of source code.\n" ); + while( RedoObjectConstructorChange() ) {} + } + + ProtectedObjectSwapper swapper; + swapper.m_ConstructorsToAdd.assign( &constructors[0], &constructors[constructors.Size() - 1] + 1 ); + swapper.m_ConstructorsOld = m_Constructors; + swapper.m_pLogger = m_pLogger; + swapper.m_pObjectFactorySystem = this; + swapper.m_bTestSerialization = m_bTestSerialization; + + swapper.m_ProtectedPhase = PHASE_NONE; + // we use the protected function to do all serialization + m_pRuntimeObjectSystem->TryProtectedFunction( &swapper ); + + CompleteConstructorSwap( swapper ); + + if( m_HistoryMaxSize ) + { + HistoryPoint historyPoint = { swapper.m_ConstructorsReplaced, swapper.m_ConstructorsToAdd }; + m_HistoryConstructors.push_back( historyPoint ); + if( (int)m_HistoryConstructors.size() > m_HistoryMaxSize ) + { + m_HistoryConstructors.erase( m_HistoryConstructors.begin() ); + } + } +} + +void ObjectFactorySystem::CompleteConstructorSwap( ProtectedObjectSwapper& swapper ) +{ + if( swapper.HasHadException() && PHASE_DELETEOLD != swapper.m_ProtectedPhase ) + { + if( m_pLogger ) + { + m_pLogger->LogError( "Exception during object swapping, switching back to previous objects.\n" ); + switch( swapper.m_ProtectedPhase ) + { + case PHASE_NONE: + AU_ASSERT( false ); + break; + case PHASE_SERIALIZEOUT: + m_pLogger->LogError( "\tError occured during serialize out old objects phase.\n" ); + break; + case PHASE_CONSTRUCTNEW: + m_pLogger->LogError( "\tError occured during constructing new objects phase.\n" ); + break; + case PHASE_SERIALIZEIN: + m_pLogger->LogError( "\tError occured during serialize into the new objects phase.\n" ); + break; + case PHASE_AUTOCONSTRUCTSINGLETONS: + m_pLogger->LogError( "\tError occured during auto construct singletons phase.\n" ); + break; + case PHASE_INITANDSERIALIZEOUTTEST: + if( m_bTestSerialization ) + { + m_pLogger->LogError( "\tError occured during Initialization and serialize test of new objects phase.\n" ); + } + else + { + m_pLogger->LogError( "\tError occured during Initialization phase.\n" ); + } + break; + case PHASE_DELETEOLD: + break; + } + } + + //swap back to new constructors before everything is serialized back in + m_Constructors = swapper.m_ConstructorsOld; + if( PHASE_SERIALIZEOUT != swapper.m_ProtectedPhase ) + { + //serialize back with old objects - could cause exception which isn't handled, but hopefully not. + swapper.m_Serializer.SetIsLoading( true ); + for( size_t i = 0; i < m_Constructors.size(); ++i ) + { + IObjectConstructor* pConstructor = m_Constructors[i]; + for( PerTypeObjectId objId = 0; objId < pConstructor->GetNumberConstructedObjects(); ++ objId ) + { + // Iserialize new object + IObject* pObject = pConstructor->GetConstructedObject( objId ); + if (pObject) + { + swapper.m_Serializer.Serialize( pObject ); + } + } + } + + // Do a second pass, initializing objects now that they've all been serialized + for( size_t i = 0; i < m_Constructors.size(); ++i ) + { + IObjectConstructor* pConstructor = m_Constructors[i]; + for( PerTypeObjectId objId = 0; objId < pConstructor->GetNumberConstructedObjects(); ++ objId ) + { + IObject* pObject = pConstructor->GetConstructedObject( objId ); + if (pObject) + { + pObject->Init(false); + } + } + } + } + } + else + { + if( m_pLogger ) m_pLogger->LogInfo( "Object swap completed\n"); + if( swapper.HasHadException() && PHASE_DELETEOLD == swapper.m_ProtectedPhase ) + { + if( m_pLogger ) m_pLogger->LogError( "Exception during object destruction of old objects, leaking.\n" ); + } + } + + // Notify any listeners that constructors have changed + TObjectFactoryListeners::iterator it = m_Listeners.begin(); + TObjectFactoryListeners::iterator itEnd = m_Listeners.end(); + while (it != itEnd) + { + (*it)->OnConstructorsAdded(); + ++it; + } +} + +void ObjectFactorySystem::GetAll(IAUDynArray &constructors) const +{ + constructors.Resize(m_Constructors.size()); + std::vector::const_iterator it = m_Constructors.begin(); + std::vector::const_iterator itEnd = m_Constructors.end(); + for(int i = 0; it != itEnd; ++it, ++i) + { + constructors[i] = *it; + } +} + +IObject* ObjectFactorySystem::GetObject( ObjectId id ) const +{ + IObjectConstructor* pConstructor = ObjectFactorySystem::GetConstructor( id.m_ConstructorId ); + if( pConstructor ) + { + return pConstructor->GetConstructedObject( id.m_PerTypeId ); + } + return 0; +} + +void ObjectFactorySystem::AddListener(IObjectFactoryListener* pListener) +{ + m_Listeners.insert(pListener); +} + +void ObjectFactorySystem::RemoveListener(IObjectFactoryListener* pListener) +{ + m_Listeners.erase(pListener); +} + + +void ObjectFactorySystem::SetObjectConstructorHistorySize( int num_ ) +{ + if( num_ >= m_HistoryCurrentLocation ) + { + m_HistoryMaxSize = num_; + } + + while( m_HistoryMaxSize < (int)m_HistoryConstructors.size() ) + { + m_HistoryConstructors.erase( m_HistoryConstructors.begin() ); + } +} + +int ObjectFactorySystem::GetObjectConstructorHistorySize() +{ + return m_HistoryMaxSize; +} + +bool ObjectFactorySystem::UndoObjectConstructorChange() +{ + if( m_HistoryCurrentLocation < (int)m_HistoryConstructors.size() ) + { + ++m_HistoryCurrentLocation; + size_t loc = m_HistoryConstructors.size() - m_HistoryCurrentLocation; + return HandleRedoUndo( m_HistoryConstructors[ loc ].before ); + } + + return false; +} + +bool ObjectFactorySystem::RedoObjectConstructorChange() +{ + if( m_HistoryCurrentLocation > 0 ) + { + size_t loc = m_HistoryConstructors.size() - m_HistoryCurrentLocation; + --m_HistoryCurrentLocation; + return HandleRedoUndo( m_HistoryConstructors[ loc ].after ); + } + + return false; +} + +int ObjectFactorySystem::GetObjectContstructorHistoryLocation() +{ + return m_HistoryCurrentLocation; +} diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectFactorySystem/ObjectFactorySystem.h b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectFactorySystem/ObjectFactorySystem.h new file mode 100644 index 0000000..cffc199 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectFactorySystem/ObjectFactorySystem.h @@ -0,0 +1,136 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef OBJECTFACTORYSYSTEM_INCLUDED +#define OBJECTFACTORYSYSTEM_INCLUDED + +#include "../IObjectFactorySystem.h" +#include "../SimpleSerializer/SimpleSerializer.h" +#include "../RuntimeProtector.h" +#include +#include +#include + +// class ObjectFactorySystem +// implements interface IObjectFactorySystem +// also implements RuntimeProtector so that when new constructors are added and used, +// exceptions can be caught by the runtime system to allow fixing on the fly. +class ObjectFactorySystem : public IObjectFactorySystem +{ +public: + ObjectFactorySystem() + : m_pLogger( 0 ) + , m_pRuntimeObjectSystem( 0 ) + , m_bTestSerialization(true) + , m_HistoryMaxSize( 0 ) + , m_HistoryCurrentLocation( 0 ) + { + } + + virtual IObjectConstructor* GetConstructor( const char* type ) const; + virtual ConstructorId GetConstructorId( const char* type ) const; + virtual IObjectConstructor* GetConstructor( ConstructorId id ) const; + virtual void AddConstructors(IAUDynArray &constructors); + virtual void GetAll(IAUDynArray &constructors) const; + virtual IObject* GetObject( ObjectId id ) const; + + virtual void AddListener(IObjectFactoryListener* pListener); + virtual void RemoveListener(IObjectFactoryListener* pListener); + virtual void SetLogger( ICompilerLogger * pLogger ) + { + m_pLogger = pLogger; + } + virtual void SetRuntimeObjectSystem( IRuntimeObjectSystem* pRuntimeObjectSystem ) + { + m_pRuntimeObjectSystem = pRuntimeObjectSystem; + } + virtual void SetTestSerialization( bool bTest ) + { + m_bTestSerialization = bTest; + } + virtual bool GetTestSerialization() const + { + return m_bTestSerialization; + } + + virtual void SetObjectConstructorHistorySize( int num_ ); + virtual int GetObjectConstructorHistorySize(); + virtual bool UndoObjectConstructorChange(); + virtual bool RedoObjectConstructorChange(); + virtual int GetObjectContstructorHistoryLocation(); + + +private: + typedef std::map CONSTRUCTORMAP; + typedef std::set TObjectFactoryListeners; + typedef std::vector TConstructors; + + CONSTRUCTORMAP m_ConstructorIds; + TConstructors m_Constructors; + TObjectFactoryListeners m_Listeners; + ICompilerLogger* m_pLogger; + IRuntimeObjectSystem* m_pRuntimeObjectSystem; + bool m_bTestSerialization; + + // History + int m_HistoryMaxSize; + int m_HistoryCurrentLocation; // positive non-zero number means previous + struct HistoryPoint + { + TConstructors before; + TConstructors after; + }; + std::vector m_HistoryConstructors; + + bool HandleRedoUndo( const TConstructors& constructors ); + + enum ProtectedPhase + { + PHASE_NONE, + PHASE_SERIALIZEOUT, + PHASE_CONSTRUCTNEW, + PHASE_SERIALIZEIN, + PHASE_AUTOCONSTRUCTSINGLETONS, + PHASE_INITANDSERIALIZEOUTTEST, + PHASE_DELETEOLD, + }; + + // temp data needed during object swap + struct ProtectedObjectSwapper: public RuntimeProtector + { + TConstructors m_ConstructorsToAdd; + TConstructors m_ConstructorsOld; + TConstructors m_ConstructorsReplaced; + SimpleSerializer m_Serializer; + ICompilerLogger* m_pLogger; + ObjectFactorySystem* m_pObjectFactorySystem; + bool m_bTestSerialization; + + ProtectedPhase m_ProtectedPhase; + + // RuntimeProtector implementation + virtual void ProtectedFunc(); + }; + friend struct ProtectedObjectSwapper; + + void CompleteConstructorSwap( ProtectedObjectSwapper& swapper ); +}; + + +#endif //OBJECTFACTORYSYSTEM_INCLUDED diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectInterface.h b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectInterface.h new file mode 100644 index 0000000..4f922c1 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectInterface.h @@ -0,0 +1,119 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef OBJECTINTERFACE_INCLUDED +#define OBJECTINTERFACE_INCLUDED + +#include +#include + +struct SystemTable; //This is the interface to your own engine code, which you need to define yourself if required. +struct IObject; + + +const size_t InvalidId = (size_t)-1; +typedef size_t PerTypeObjectId; +typedef size_t ConstructorId; + +struct ObjectId +{ + ObjectId() : m_PerTypeId(InvalidId), m_ConstructorId(InvalidId) {} + + PerTypeObjectId m_PerTypeId; + ConstructorId m_ConstructorId; + bool operator<( ObjectId lhs ) const + { + if( m_ConstructorId < lhs.m_ConstructorId ) + { + return true; + } + if( m_ConstructorId == lhs.m_ConstructorId ) + { + return m_PerTypeId < lhs.m_PerTypeId; + } + return false; + } + bool operator==( const ObjectId& rhs) const + { + return (m_ConstructorId == rhs.m_ConstructorId && m_PerTypeId == rhs.m_PerTypeId); + } + bool IsValid() const + { + return (m_ConstructorId != InvalidId && m_PerTypeId != InvalidId); + } + void SetInvalid() + { + m_ConstructorId = InvalidId; + m_PerTypeId = InvalidId; + } +}; + +struct SourceDependencyInfo; + +struct IObjectConstructor +{ + virtual IObject* Construct() = 0; + virtual void ConstructNull() = 0; //for use in object replacement, ensures a deleted object can be replaced + virtual const char* GetName() = 0; + virtual const char* GetFileName() = 0; + virtual const char* GetCompiledPath() = 0; + virtual size_t GetMaxNumIncludeFiles() const = 0; + virtual const char* GetIncludeFile( size_t Num_ ) const = 0; + virtual size_t GetMaxNumLinkLibraries() const = 0; + virtual const char* GetLinkLibrary( size_t Num_ ) const = 0; + virtual size_t GetMaxNumSourceDependencies() const = 0; + virtual SourceDependencyInfo GetSourceDependency( size_t Num_ ) const = 0; + virtual void SetProjectId( unsigned short projectId_ ) = 0; + virtual unsigned short GetProjectId() const = 0; + + // Singleton functions + virtual bool GetIsSingleton() const = 0; + virtual bool GetIsAutoConstructSingleton() const = 0; + IObject* GetSingleton() + { + return Construct(); + } + + virtual IObject* GetConstructedObject( PerTypeObjectId num ) const = 0; //should return 0 for last or deleted object + virtual size_t GetNumberConstructedObjects() const = 0; + virtual ConstructorId GetConstructorId() const = 0; + virtual void SetConstructorId( ConstructorId id ) = 0; //take care how you use this - should only be used by id service + virtual void ClearIfAllDeleted() = 0; //if there are no objects left then clear internal memory (does not reduce memory consumption) + virtual ~IObjectConstructor() {} +}; + +struct IPerModuleInterface +{ + virtual std::vector& GetConstructors() = 0; + virtual void SetProjectIdForAllConstructors( unsigned short projectId_ ) = 0; + virtual void SetSystemTable( SystemTable* pSystemTable ) = 0; + virtual const std::vector& GetRequiredSourceFiles() const = 0; + virtual void AddRequiredSourceFiles( const char* file_ ) = 0; + virtual void SetModuleFileName( const char* name ) = 0; + virtual ~IPerModuleInterface() {} +}; + +#ifdef _WIN32 +typedef IPerModuleInterface* (__cdecl *GETPerModuleInterface_PROC)(void); +#else +typedef IPerModuleInterface* ( *GETPerModuleInterface_PROC)(void); +#endif + + +#endif //OBJECTINTERFACE_INCLUDED diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectInterfacePerModule.h b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectInterfacePerModule.h new file mode 100644 index 0000000..f142c7d --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectInterfacePerModule.h @@ -0,0 +1,395 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef OBJECTINTERFACEPERMODULE_INCLUDED +#define OBJECTINTERFACEPERMODULE_INCLUDED + +#include "ObjectInterface.h" +#include "RuntimeInclude.h" +#include "RuntimeLinkLibrary.h" +#include "RuntimeSourceDependency.h" +#include +#include +#include + +#ifndef RCCPPOFF + #define AU_ASSERT( statement ) do { if (!(statement)) { volatile int* p = 0; int a = *p; if(a) {} } } while(0) +#else + #define AU_ASSERT( statement ) assert( statement ) +#endif //RCCPPOFF + +class PerModuleInterface : public IPerModuleInterface +{ +public: + static PerModuleInterface* GetInstance(); + static SystemTable* g_pSystemTable; + + void AddConstructor( IObjectConstructor* pConstructor ); + + virtual std::vector& GetConstructors(); + virtual void SetProjectIdForAllConstructors( unsigned short projectId_ ); + virtual void SetSystemTable( SystemTable* pSystemTable ); + + SystemTable* GetSystemTable() + { + return g_pSystemTable; + } + + virtual const std::vector& GetRequiredSourceFiles() const; + virtual void AddRequiredSourceFiles( const char* file_ ); + virtual void SetModuleFileName( const char* name ) + { + m_ModuleFilename = name; + } + const char* GetCompiledPath() const + { +#ifdef COMPILE_PATH + return COMPILE_PATH; +#else + return ""; +#endif + } + +private: + PerModuleInterface(); + + ~PerModuleInterface() + { + } + + + static PerModuleInterface* ms_pObjectManager; + std::vector m_ObjectConstructors; + std::vector m_RequiredSourceFiles; + std::string m_ModuleFilename; +}; + + + + + +template class TObjectConstructorConcrete: public IObjectConstructor +{ +public: + TObjectConstructorConcrete( +#ifndef RCCPPOFF + const char* Filename, + IRuntimeIncludeFileList* pIncludeFileList_, + IRuntimeSourceDependencyList* pSourceDependencyList_, + IRuntimeLinkLibraryList* pLinkLibraryList, +#endif + bool bIsSingleton, + bool bIsAutoConstructSingleton) + : m_bIsSingleton( bIsSingleton ) + , m_bIsAutoConstructSingleton( bIsAutoConstructSingleton ) + , m_pModuleInterface(0) + , m_Project(0) +#ifndef RCCPPOFF + , m_FileName( Filename ) + , m_pIncludeFileList(pIncludeFileList_) + , m_pSourceDependencyList(pSourceDependencyList_) + , m_pLinkLibraryList(pLinkLibraryList) +#endif + { +#ifndef RCCPPOFF + // add path to filename + #ifdef COMPILE_PATH + m_FileName = COMPILE_PATH + m_FileName; + #endif +#endif + PerModuleInterface::GetInstance()->AddConstructor( this ); + m_pModuleInterface = PerModuleInterface::GetInstance(); + m_Id = InvalidId; + } + + virtual IObject* Construct() + { + T* pT = 0; + if( m_bIsSingleton && m_ConstructedObjects.size() && m_ConstructedObjects[0] ) + { + return m_ConstructedObjects[0]; + } + + if( m_FreeIds.empty() ) + { + PerTypeObjectId id = m_ConstructedObjects.size(); + + pT = new T(); + pT->SetPerTypeId( id ); + m_ConstructedObjects.push_back( pT ); + } + else + { + PerTypeObjectId id = m_FreeIds.back(); + m_FreeIds.pop_back(); + pT = new T(); + pT->SetPerTypeId( id ); + AU_ASSERT( 0 == m_ConstructedObjects[ id ] ); + m_ConstructedObjects[ id ] = pT; + + } + return pT; + } + + virtual void ConstructNull() + { + // should not occur for singletons + AU_ASSERT( !m_bIsSingleton ); + m_ConstructedObjects.push_back( NULL ); + } + + virtual const char* GetName() + { + return T::GetTypeNameStatic(); + } + + virtual void SetProjectId( unsigned short projectId_ ) + { + m_Project = projectId_; + } + + virtual unsigned short GetProjectId() const + { + return m_Project; + } + + virtual const char* GetFileName() + { +#ifndef RCCPPOFF + return m_FileName.c_str(); +#else + return 0; +#endif + } + + virtual const char* GetCompiledPath() + { +#ifndef RCCPPOFF + #ifdef COMPILE_PATH + return COMPILE_PATH; + #else + return ""; + #endif +#else + return 0; +#endif + } + + virtual const char* GetIncludeFile( size_t Num_ ) const + { +#ifndef RCCPPOFF + if( m_pIncludeFileList ) + { + return m_pIncludeFileList->GetIncludeFile( Num_ ); + } +#endif + return 0; + } + + virtual size_t GetMaxNumIncludeFiles() const + { +#ifndef RCCPPOFF + if( m_pIncludeFileList ) + { + return m_pIncludeFileList->MaxNum; + } +#endif + return 0; + } + + virtual const char* GetLinkLibrary( size_t Num_ ) const + { +#ifndef RCCPPOFF + if( m_pLinkLibraryList ) + { + return m_pLinkLibraryList->GetLinkLibrary( Num_ ); + } +#endif + return 0; + } + + virtual size_t GetMaxNumLinkLibraries() const + { +#ifndef RCCPPOFF + if( m_pLinkLibraryList ) + { + return m_pLinkLibraryList->MaxNum; + } +#endif + return 0; + } + + virtual SourceDependencyInfo GetSourceDependency( size_t Num_ ) const + { +#ifndef RCCPPOFF + if( m_pSourceDependencyList ) + { + return m_pSourceDependencyList->GetSourceDependency( Num_ ); + } +#endif + return SourceDependencyInfo::GetNULL(); + } + + virtual size_t GetMaxNumSourceDependencies() const + { +#ifndef RCCPPOFF + if( m_pSourceDependencyList ) + { + return m_pSourceDependencyList->MaxNum; + } +#endif + return 0; + } + + virtual bool GetIsSingleton() const + { + return m_bIsSingleton; + } + virtual bool GetIsAutoConstructSingleton() const + { + return m_bIsSingleton && m_bIsAutoConstructSingleton; + } + + + virtual IObject* GetConstructedObject( PerTypeObjectId id ) const + { + if( m_ConstructedObjects.size() > id ) + { + return m_ConstructedObjects[id]; + } + return 0; + } + virtual size_t GetNumberConstructedObjects() const + { + return m_ConstructedObjects.size(); + } + virtual ConstructorId GetConstructorId() const + { + return m_Id; + } + virtual void SetConstructorId( ConstructorId id ) + { + if( InvalidId == m_Id ) + { + m_Id = id; + } + } + + void DeRegister( PerTypeObjectId id ) + { + //remove from constructed objects. + //use swap with last one + if( m_ConstructedObjects.size() - 1 == id ) + { + //it's the last one, just remove it. + m_ConstructedObjects.pop_back(); + } + else + { + m_FreeIds.push_back( id ); + m_ConstructedObjects[ id ] = 0; + } + } + virtual void ClearIfAllDeleted() + { + m_FreeIds.clear(); + m_ConstructedObjects.clear(); + } + +private: + bool m_bIsSingleton; + bool m_bIsAutoConstructSingleton; + std::vector m_ConstructedObjects; + std::vector m_FreeIds; + ConstructorId m_Id; + PerModuleInterface* m_pModuleInterface; + unsigned short m_Project; +#ifndef RCCPPOFF + std::string m_FileName; + IRuntimeIncludeFileList* m_pIncludeFileList; + IRuntimeSourceDependencyList* m_pSourceDependencyList; + IRuntimeLinkLibraryList* m_pLinkLibraryList; +#endif +}; + + +template class TActual: public T +{ +public: + // overload new/delete to get alignment correct +#ifdef _WIN32 + void* operator new(size_t size) + { + size_t align = __alignof( TActual ); + return _aligned_malloc( size, align ); + } + void operator delete(void* p) + { + _aligned_free( p ); + } +#else + void* operator new(size_t size) + { + size_t align = __alignof__( TActual ); + void* pRet; + int retval = posix_memalign( &pRet, align, size ); + (void)retval; //unused + return pRet; + } + void operator delete(void* p) + { + free( p ); + } +#endif //_WIN32 + friend class TObjectConstructorConcrete; + virtual ~TActual() { m_Constructor.DeRegister( m_Id ); } + virtual PerTypeObjectId GetPerTypeId() const { return m_Id; } + virtual IObjectConstructor* GetConstructor() const { return &m_Constructor; } + static const char* GetTypeNameStatic(); + virtual const char* GetTypeName() const + { + return GetTypeNameStatic(); + } +private: + void SetPerTypeId( PerTypeObjectId id ) { m_Id = id; } + PerTypeObjectId m_Id; + static TObjectConstructorConcrete m_Constructor; +}; +#ifndef RCCPPOFF + #define REGISTERBASE( T, bIsSingleton, bIsAutoConstructSingleton ) \ + static RuntimeIncludeFiles< __COUNTER__ > g_includeFileList_##T; \ + static RuntimeSourceDependency< __COUNTER__ > g_sourceDependencyList_##T; \ + static RuntimeLinkLibrary< __COUNTER__ > g_linkLibraryList_##T; \ + template<> TObjectConstructorConcrete< TActual< T > > TActual< T >::m_Constructor( __FILE__, &g_includeFileList_##T, &g_sourceDependencyList_##T, &g_linkLibraryList_##T, bIsSingleton, bIsAutoConstructSingleton );\ + template<> const char* TActual< T >::GetTypeNameStatic() { return #T; } \ + template class TActual< T >; +#else + #define REGISTERBASE( T, bIsSingleton, bIsAutoConstructSingleton ) \ + template<> TObjectConstructorConcrete< TActual< T > > TActual< T >::m_Constructor( bIsSingleton, bIsAutoConstructSingleton); \ + template<> const char* TActual< T >::GetTypeNameStatic() { return #T; } \ + template class TActual< T >; +#endif + +//NOTE: the file macro will only emit the full path if /FC option is used in visual studio or /ZI (Which forces /FC) +#define REGISTERCLASS( T ) REGISTERBASE( T, false, false ) + +#define REGISTERSINGLETON( T, bIsAutoConstructSingleton ) REGISTERBASE( T, true, bIsAutoConstructSingleton ) + + +#endif // OBJECTINTERFACEPERMODULE_INCLUDED diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectInterfacePerModuleSource.cpp b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectInterfacePerModuleSource.cpp new file mode 100644 index 0000000..b4ceb2d --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectInterfacePerModuleSource.cpp @@ -0,0 +1,83 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +// ObjectInterfaceOerDllSource.cpp : Defines the entry point for the DLL application. +#include "ObjectInterfacePerModule.h" + +PerModuleInterface* PerModuleInterface::ms_pObjectManager = NULL; + +SystemTable* PerModuleInterface::g_pSystemTable = 0; + +extern "C" +#ifdef _WIN32 + __declspec(dllexport) //should create file with export import macros etc. +#else +__attribute__((visibility("default"))) +#endif +IPerModuleInterface* GetPerModuleInterface() +{ + return PerModuleInterface::GetInstance(); +} + +PerModuleInterface* PerModuleInterface::GetInstance() +{ + if( !ms_pObjectManager ) + { + ms_pObjectManager = new PerModuleInterface; + } + return ms_pObjectManager; +} + +void PerModuleInterface::AddConstructor( IObjectConstructor* pConstructor ) +{ + m_ObjectConstructors.push_back( pConstructor ); +} + +std::vector& PerModuleInterface::GetConstructors() +{ + return m_ObjectConstructors; +} + +void PerModuleInterface::SetProjectIdForAllConstructors( unsigned short projectId_ ) +{ + for( size_t i = 0; i < m_ObjectConstructors.size(); ++i ) + { + m_ObjectConstructors[ i ]->SetProjectId( projectId_ ); + } +} + + +void PerModuleInterface::SetSystemTable( SystemTable* pSystemTable ) +{ + g_pSystemTable = pSystemTable; +} + +PerModuleInterface::PerModuleInterface() +{ + //ensure this file gets compiled + AddRequiredSourceFiles( __FILE__ ); +} + +const std::vector& PerModuleInterface::GetRequiredSourceFiles() const +{ + return m_RequiredSourceFiles; +} + +void PerModuleInterface::AddRequiredSourceFiles( const char* file_ ) +{ + m_RequiredSourceFiles.push_back( file_ ); +} \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeInclude.h b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeInclude.h new file mode 100644 index 0000000..9388242 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeInclude.h @@ -0,0 +1,112 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef RUNTIMEINCLUDE_INCLUDED +#define RUNTIMEINCLUDE_INCLUDED + +#include + +#ifndef RCCPPOFF + +//NOTE: the file macro will only emit the full path if /FC option is used in visual studio or /ZI (Which forces /FC) +//Following creates a list of files which are runtime modifiable, to be used in headers +//requires use of __COUNTER__ predefined macro, which is in gcc 4.3+, clang/llvm and MSVC + +struct IRuntimeIncludeFileList +{ + IRuntimeIncludeFileList( size_t max ) : MaxNum( max ) + { + } + + // GetIncludeFile may return 0, so you should iterate through to GetMaxNum() ignoring 0 returns + virtual const char* GetIncludeFile( size_t Num_ ) const + { + return 0; + } + size_t MaxNum; // initialized in constructor below +}; + + +namespace +{ + +template< size_t COUNT > struct RuntimeIncludeFiles : public RuntimeIncludeFiles +{ + RuntimeIncludeFiles( size_t max ) : RuntimeIncludeFiles( max ) + { + } + RuntimeIncludeFiles() : RuntimeIncludeFiles( COUNT ) + { + } + + virtual const char* GetIncludeDir( size_t Num_ ) const + { + if( Num_ < COUNT ) + { + return this->RuntimeIncludeFiles< COUNT-1 >::GetIncludeDir( Num_ ); + } + else return 0; + } +}; + +template<> struct RuntimeIncludeFiles<0> : public IRuntimeIncludeFileList +{ + RuntimeIncludeFiles( size_t max ) : IRuntimeIncludeFileList( max ) + { + } + RuntimeIncludeFiles() : IRuntimeIncludeFileList( 0 ) + { + } + + virtual const char* GetIncludeDir( size_t Num_ ) const + { + return 0; + } +}; + + + +#define RUNTIME_MODIFIABLE_INCLUDE_BASE( N ) \ + template<> struct RuntimeIncludeFiles< N + 1 > : public RuntimeIncludeFiles< N >\ + { \ + RuntimeIncludeFiles( size_t max ) : RuntimeIncludeFiles( max ) {} \ + RuntimeIncludeFiles< N + 1 >() : RuntimeIncludeFiles( N + 1 ) {} \ + virtual const char* GetIncludeFile( size_t Num_ ) const \ + { \ + if( Num_ <= N ) \ + { \ + if( Num_ == N ) \ + { \ + return __FILE__; \ + } \ + else return this->RuntimeIncludeFiles< N >::GetIncludeFile( Num_ ); \ + } \ + else return 0; \ + } \ + }; \ + + +#define RUNTIME_MODIFIABLE_INCLUDE namespace { RUNTIME_MODIFIABLE_INCLUDE_BASE( __COUNTER__ ) } + +} +#else +#define RUNTIME_MODIFIABLE_INCLUDE +#endif //RCCPPOFF + +#endif //RUNTIMEINCLUDE_INCLUDED diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeLinkLibrary.h b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeLinkLibrary.h new file mode 100644 index 0000000..458bc94 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeLinkLibrary.h @@ -0,0 +1,111 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef RUNTIMELINKLIBRARY_INCLUDED +#define RUNTIMELINKLIBRARY_INCLUDED + + +#ifndef RCCPPOFF +//NOTE: the file macro will only emit the full path if /FC option is used in visual studio or /ZI (Which forces /FC) +//Following creates a list of files which are runtime modifiable, to be used in headers +//requires use of __COUNTER__ predefined macro, which is in gcc 4.3+, clang/llvm and MSVC + +struct IRuntimeLinkLibraryList +{ + IRuntimeLinkLibraryList( size_t max ) : MaxNum( max ) + { + } + + // GetIncludeFile may return 0, so you should iterate through to GetMaxNum() ignoring 0 returns + virtual const char* GetLinkLibrary( size_t Num_ ) const + { + return 0; + } + size_t MaxNum; // initialized in constructor below +}; + + +namespace +{ + +template< size_t COUNT > struct RuntimeLinkLibrary : public RuntimeLinkLibrary +{ + RuntimeLinkLibrary( size_t max ) : RuntimeLinkLibrary( max ) + { + } + RuntimeLinkLibrary() : RuntimeLinkLibrary( COUNT ) + { + } + + virtual const char* GetLinkLibrary( size_t Num_ ) const + { + if( Num_ < COUNT ) + { + return this->RuntimeLinkLibrary< COUNT-1 >::GetLinkLibrary( Num_ ); + } + else return 0; + } +}; + +template<> struct RuntimeLinkLibrary<0> : public IRuntimeLinkLibraryList +{ + RuntimeLinkLibrary( size_t max ) : IRuntimeLinkLibraryList( max ) + { + } + RuntimeLinkLibrary() : IRuntimeLinkLibraryList( 0 ) + { + } + + virtual const char* GetLinkLibrary( size_t Num_ ) const + { + return 0; + } +}; + + + +#define RUNTIME_COMPILER_LINKLIBRARY_BASE( LIBRARY, N ) \ + template<> struct RuntimeLinkLibrary< N + 1 > : public RuntimeLinkLibrary< N >\ + { \ + RuntimeLinkLibrary( size_t max ) : RuntimeLinkLibrary( max ) {} \ + RuntimeLinkLibrary< N + 1 >() : RuntimeLinkLibrary( N + 1 ) {} \ + virtual const char* GetLinkLibrary( size_t Num_ ) const \ + { \ + if( Num_ <= N ) \ + { \ + if( Num_ == N ) \ + { \ + return LIBRARY; \ + } \ + else return this->RuntimeLinkLibrary< N >::GetLinkLibrary( Num_ ); \ + } \ + else return 0; \ + } \ + }; \ + + +#define RUNTIME_COMPILER_LINKLIBRARY( LIBRARY ) namespace { RUNTIME_COMPILER_LINKLIBRARY_BASE( LIBRARY, __COUNTER__ ) } + +} +#else +#define RUNTIME_COMPILER_LINKLIBRARY( LIBRARY ) +#endif //RCCPPOFF + + +#endif //RUNTIMELINKLIBRARY_INCLUDED diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.cpp b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.cpp new file mode 100644 index 0000000..febd346 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.cpp @@ -0,0 +1,1022 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "RuntimeObjectSystem.h" + +// Remove windows.h define of GetObject which conflicts with EntitySystem GetObject +#if defined _WINDOWS_ && defined GetObject +#undef GetObject +#endif +#include "../RuntimeCompiler/AUArray.h" +#include "../RuntimeCompiler/ICompilerLogger.h" +#include "../RuntimeCompiler/FileChangeNotifier.h" +#include "IObjectFactorySystem.h" +#include "ObjectFactorySystem/ObjectFactorySystem.h" +#include "ObjectInterfacePerModule.h" +#include +#include "IObject.h" + +#ifndef _WIN32 +//TODO: fix below in a better generic fashion. +#define MAX_PATH 256 +#include +#endif + +using FileSystemUtils::Path; + +FileSystemUtils::Path RuntimeObjectSystem::ProjectSettings::ms_DefaultIntermediatePath; + +static Path GetIntermediateFolder( Path basePath_, RCppOptimizationLevel optimizationLevel_ ) +{ + std::string folder; +#ifdef _DEBUG + folder = "DEBUG_"; +#else + folder = "RELEASE_"; +#endif + folder += RCppOptimizationLevelStrings[ GetActualOptimizationLevel( optimizationLevel_ ) ]; + Path runtimeFolder = basePath_ / folder; + return runtimeFolder; +} + + +RuntimeObjectSystem::RuntimeObjectSystem() + : m_pCompilerLogger(0) + , m_pSystemTable(0) + , m_pObjectFactorySystem(new ObjectFactorySystem()) + , m_pFileChangeNotifier(new FileChangeNotifier()) + , m_pBuildTool(new BuildTool()) + , m_bCompiling( false ) + , m_bLastLoadModuleSuccess( false ) + , m_bAutoCompile( true ) + , m_TotalLoadedModulesEver(1) // starts at one for current exe + , m_bProtectionEnabled( true ) + , m_pImpl( 0 ) + , m_CurrentlyBuildingProject( 0 ) +{ + ProjectSettings::ms_DefaultIntermediatePath = FileSystemUtils::GetCurrentPath() / "Runtime"; + CreatePlatformImpl(); +} + +RuntimeObjectSystem::~RuntimeObjectSystem() +{ + m_pFileChangeNotifier->RemoveListener(this); + DeletePlatformImpl(); + delete m_pObjectFactorySystem; + delete m_pFileChangeNotifier; + delete m_pBuildTool; + + // Note we do not delete compiler logger, creator should do this +} + + +bool RuntimeObjectSystem::Initialise( ICompilerLogger * pLogger, SystemTable* pSystemTable ) +{ + m_pCompilerLogger = pLogger; + m_pSystemTable = pSystemTable; + + m_pBuildTool->Initialise(m_pCompilerLogger); + + // We start by using the code in the current module + IPerModuleInterface* pPerModuleInterface = PerModuleInterface::GetInstance(); + pPerModuleInterface->SetModuleFileName( "Main Exe" ); + + m_pObjectFactorySystem->SetLogger( m_pCompilerLogger ); + m_pObjectFactorySystem->SetRuntimeObjectSystem( this ); + + FileSystemUtils::Path initialDir = FileSystemUtils::GetCurrentPath(); + m_FoundSourceDirectoryMappings[initialDir] = initialDir; + + SetupObjectConstructors(pPerModuleInterface); + + //add this dir to list of include dirs + FileSystemUtils::Path includeDir = FindFile(__FILE__); + includeDir = includeDir.ParentPath(); + AddIncludeDir(includeDir.c_str()); + + //also add the runtime compiler dir to list of dirs + includeDir = includeDir.ParentPath() / Path("RuntimeCompiler"); + AddIncludeDir(includeDir.c_str()); + + return true; +} + + +void RuntimeObjectSystem::OnFileChange(const IAUDynArray& filelist) +{ + if( !m_bAutoCompile ) + { + return; + } + + for( unsigned short proj = 0; proj < m_Projects.size(); ++proj ) + { + + std::vector* pBuildFileList = &m_Projects[ proj ].m_BuildFileList; + if( m_bCompiling ) + { + pBuildFileList = &m_Projects[ proj ].m_PendingBuildFileList; + } + + + if (m_pCompilerLogger) { m_pCompilerLogger->LogInfo( "FileChangeNotifier triggered recompile with changes to:\n" ); } + for( size_t i = 0; i < filelist.Size(); ++i ) + { + // check this file is in our project list + TFileList::iterator it = std::find( m_Projects[ proj ].m_RuntimeFileList.begin( ), m_Projects[ proj ].m_RuntimeFileList.end( ), filelist[i] ); + if( it == m_Projects[ proj ].m_RuntimeFileList.end() ) + { + continue; + } + + if (m_pCompilerLogger) { m_pCompilerLogger->LogInfo( " File %s\n", filelist[ i ] ); } + BuildTool::FileToBuild fileToBuild( filelist[ i ] ); + + bool bFindIncludeDependencies = true; // if this is a header or a source dependency need to find include dependencies + bool bForceIncludeDependencies = true; + if( fileToBuild.filePath.Extension() != ".h" ) //TODO: change to check for .cpp and .c as could have .inc files etc.? + { + bFindIncludeDependencies = false; + pBuildFileList->push_back( fileToBuild ); + + // file may be a source dependency, check + TFileToFilesIterator itrCurr = m_Projects[ proj ].m_RuntimeSourceDependencyMap.begin( ); + while( itrCurr != m_Projects[ proj ].m_RuntimeSourceDependencyMap.end( ) ) + { + if( itrCurr->second == fileToBuild.filePath ) + { + BuildTool::FileToBuild fileToBuild( itrCurr->first ); + pBuildFileList->push_back( fileToBuild ); + } + ++itrCurr; + } + } + + if( bFindIncludeDependencies ) + { + TFileToFilesEqualRange range = m_Projects[ proj ].m_RuntimeIncludeMap.equal_range( fileToBuild.filePath ); + for( TFileToFilesIterator it = range.first; it != range.second; ++it ) + { + BuildTool::FileToBuild fileToBuildFromIncludes( ( *it ).second, bForceIncludeDependencies ); + pBuildFileList->push_back( fileToBuildFromIncludes ); + } + } + } + } + + if( !m_bCompiling ) + { + StartRecompile(); + } +} + +bool RuntimeObjectSystem::GetIsCompiledComplete() +{ + return m_bCompiling && m_pBuildTool->GetIsComplete(); +} + +void RuntimeObjectSystem::CompileAllInProject( bool bForceRecompile, unsigned short projectId_ ) +{ + ProjectSettings& project = GetProject( projectId_ ); + // since this is a compile all we can clear any pending compiles + project.m_BuildFileList.clear( ); + + // ensure we have an up to date list of files to commpile if autocompile is off + if( !m_bAutoCompile ) + { + AUDynArray constructors; + m_pObjectFactorySystem->GetAll(constructors); + SetupRuntimeFileTracking(constructors); + } + + // add all files except headers + for( size_t i = 0; i < m_Projects[ projectId_ ].m_RuntimeFileList.size( ); ++i ) + { + BuildTool::FileToBuild fileToBuild( project.m_RuntimeFileList[ i ], true ); //force re-compile on compile all + if( fileToBuild.filePath.Extension() != ".h") //TODO: change to check for .cpp and .c as could have .inc files etc.? + { + project.m_BuildFileList.push_back( fileToBuild ); + } + } + + StartRecompile(); +} + +void RuntimeObjectSystem::CompileAll( bool bForceRecompile ) +{ + for( unsigned short proj = 0; proj < m_Projects.size(); ++proj ) + { + CompileAllInProject( bForceRecompile, proj ); + } +} + +void RuntimeObjectSystem::SetAutoCompile( bool autoCompile ) +{ + m_bAutoCompile = autoCompile; + + if (m_bAutoCompile) + { + AUDynArray constructors; + m_pObjectFactorySystem->GetAll(constructors); + SetupRuntimeFileTracking(constructors); + } +} + +// RuntimeObjectSystem::AddToRuntimeFileList - filename should be cleaned of "/../" etc, see FileSystemUtils::Path::GetCleanPath() +void RuntimeObjectSystem::AddToRuntimeFileList( const char* filename, unsigned short projectId_ ) +{ + ProjectSettings& project = GetProject( projectId_ ); + TFileList::iterator it = std::find( project.m_RuntimeFileList.begin( ), project.m_RuntimeFileList.end( ), filename ); + if( it == project.m_RuntimeFileList.end( ) ) + { + project.m_RuntimeFileList.push_back( filename ); + m_pFileChangeNotifier->Watch( filename, this ); + } +} + +void RuntimeObjectSystem::RemoveFromRuntimeFileList( const char* filename, unsigned short projectId_ ) +{ + ProjectSettings& project = GetProject( projectId_ ); + TFileList::iterator it = std::find( project.m_RuntimeFileList.begin( ), project.m_RuntimeFileList.end( ), filename ); + if( it != project.m_RuntimeFileList.end( ) ) + { + project.m_RuntimeFileList.erase( it ); + } +} + +void RuntimeObjectSystem::StartRecompile() +{ + m_bCompiling = true; + if( m_pCompilerLogger ) { m_pCompilerLogger->LogInfo( "Compiling...\n" ); } + + //Use a temporary filename for the dll +#ifdef _WIN32 + char tempPath[ MAX_PATH ]; + GetTempPathA( MAX_PATH, tempPath ); + char tempFileName[ MAX_PATH ]; + GetTempFileNameA( tempPath, "", 0, tempFileName ); + std::string strTempFileName( tempFileName ); + m_CurrentlyCompilingModuleName = strTempFileName; +#else + char tempPath[] = "/tmp/RCCppTempDylibXXXXXX"; + int fileDesc = mkstemp(tempPath); + assert( fileDesc != -1 ); //TODO: should really handle the error + close( fileDesc ); //we don't actually want to make the file as yet + m_CurrentlyCompilingModuleName = tempPath; + +#endif + + // we step through and build each project in turn if there is anything to build, starting from m_PreviousBuildProject + bool bHaveProjectToBuild = false; + unsigned short project = m_CurrentlyBuildingProject; + if( m_Projects.size( ) ) + { + do + { + ++project; + if( project >= m_Projects.size( ) ) + { + project = 0; + } + if( m_Projects[ project ].m_BuildFileList.size() || m_Projects[ project ].m_PendingBuildFileList.size() ) + { + bHaveProjectToBuild = true; + } + } while( !bHaveProjectToBuild && m_CurrentlyBuildingProject != project ); + m_CurrentlyBuildingProject = project; + } + + if( !bHaveProjectToBuild ) + { + if( m_pCompilerLogger ) { m_pCompilerLogger->LogError( "Error - could not find any files to build in any projects\n" ); } + m_bCompiling = false; + return; + } + + m_Projects[ project ].m_BuildFileList.insert( m_Projects[ project ].m_BuildFileList.end( ), m_Projects[ project ].m_PendingBuildFileList.begin( ), m_Projects[ project ].m_PendingBuildFileList.end( ) ); + m_Projects[ project ].m_PendingBuildFileList.clear( ); + std::vector ourBuildFileList( m_Projects[ project ].m_BuildFileList ); + + + //Add libraries which need linking + std::vector linkLibraryList; + for( size_t i = 0; i < ourBuildFileList.size(); ++ i ) + { + + TFileToFilesEqualRange range = m_Projects[ project ].m_RuntimeLinkLibraryMap.equal_range( ourBuildFileList[ i ].filePath ); + for(TFileToFilesIterator it=range.first; it!=range.second; ++it) + { + linkLibraryList.push_back( it->second ); + } + } + + + //Add required source files + const std::vector vecRequiredFiles = PerModuleInterface::GetInstance()->GetRequiredSourceFiles(); + FileSystemUtils::Path compileDir = PerModuleInterface::GetInstance()->GetCompiledPath(); + for( size_t i = 0; i < vecRequiredFiles.size(); ++i ) + { + FileSystemUtils::Path fullpath = compileDir / vecRequiredFiles[i]; + fullpath = FindFile( fullpath ); + BuildTool::FileToBuild reqFile( fullpath, false ); //don't force compile of these + ourBuildFileList.push_back( reqFile ); + } + + //Add dependency source files + size_t buildListSize = ourBuildFileList.size(); // we will add to the build list, so get the size before the loop + for( size_t i = 0; i < buildListSize; ++ i ) + { + + TFileToFilesEqualRange range = m_Projects[ project ].m_RuntimeSourceDependencyMap.equal_range( ourBuildFileList[ i ].filePath ); + for(TFileToFilesIterator it=range.first; it!=range.second; ++it) + { + BuildTool::FileToBuild reqFile( it->second, false ); //don't force compile of these + ourBuildFileList.push_back( reqFile ); + } + } + + m_Projects[ project ].m_CompilerOptions.intermediatePath = GetIntermediateFolder( m_Projects[ project ].m_CompilerOptions.baseIntermediatePath, + m_Projects[ project ].m_CompilerOptions.optimizationLevel ); + + + m_pBuildTool->BuildModule( ourBuildFileList, + m_Projects[ project ].m_CompilerOptions, + linkLibraryList, m_CurrentlyCompilingModuleName ); +} + +bool RuntimeObjectSystem::LoadCompiledModule() +{ + m_bLastLoadModuleSuccess = false; + m_bCompiling = false; + + // Since the temporary file is created with 0 bytes, loadlibrary can fail with a dialogue we want to prevent. So check size + // We pass in the ec value so the function won't throw an exception on error, but the value itself sometimes seems to + // be set even without an error, so not sure if it should be relied on. + uint64_t sizeOfModule = m_CurrentlyCompilingModuleName.GetFileSize(); + + HMODULE module = 0; + if( sizeOfModule ) + { +#ifdef _WIN32 + module = LoadLibraryA( m_CurrentlyCompilingModuleName.c_str() ); +#else + module = dlopen( m_CurrentlyCompilingModuleName.c_str(), RTLD_NOW ); +#endif + } + + if (!module) + { + if (m_pCompilerLogger) { m_pCompilerLogger->LogError( "Failed to load module %s\n",m_CurrentlyCompilingModuleName.c_str()); } + return false; + } + + GETPerModuleInterface_PROC pPerModuleInterfaceProcAdd = 0; +#ifdef _WIN32 + pPerModuleInterfaceProcAdd = (GETPerModuleInterface_PROC) GetProcAddress(module, "GetPerModuleInterface"); +#else + pPerModuleInterfaceProcAdd = (GETPerModuleInterface_PROC) dlsym(module,"GetPerModuleInterface"); + +#endif + if (!pPerModuleInterfaceProcAdd) + { + if (m_pCompilerLogger) { m_pCompilerLogger->LogError( "Failed GetProcAddress\n"); } + return false; + } + + pPerModuleInterfaceProcAdd()->SetModuleFileName( m_CurrentlyCompilingModuleName.c_str() ); + pPerModuleInterfaceProcAdd( )->SetProjectIdForAllConstructors( m_CurrentlyBuildingProject ); + m_Modules.push_back( module ); + + if (m_pCompilerLogger) { m_pCompilerLogger->LogInfo( "Compilation Succeeded\n"); } + ++m_TotalLoadedModulesEver; + + SetupObjectConstructors(pPerModuleInterfaceProcAdd()); + m_Projects[ m_CurrentlyBuildingProject ].m_BuildFileList.clear( ); // clear the files from our compile list + m_bLastLoadModuleSuccess = true; + + // check if there is another project to build + bool bNeedAnotherCompile = false; + for( unsigned short proj = 0; proj < m_Projects.size( ); ++proj ) + { + if( m_Projects[ proj ].m_BuildFileList.size( ) || m_Projects[ proj ].m_PendingBuildFileList.size( ) ) + { + bNeedAnotherCompile = true; + } + } + + if( bNeedAnotherCompile )// + { + // we have pending files to compile, go ahead and compile them + StartRecompile(); + } + return true; +} + +void RuntimeObjectSystem::SetupObjectConstructors(IPerModuleInterface* pPerModuleInterface) +{ + // Set system Table + pPerModuleInterface->SetSystemTable( m_pSystemTable ); + + // get hold of the constructors + const std::vector &objectConstructors = pPerModuleInterface->GetConstructors(); + AUDynArray constructors(objectConstructors.size()); + for (size_t i = 0, iMax = objectConstructors.size(); i < iMax; ++i) + { + constructors[i] = objectConstructors[i]; + } + + if (m_bAutoCompile) + { + SetupRuntimeFileTracking(constructors); + } + + m_pObjectFactorySystem->AddConstructors(constructors); + +} + +void RuntimeObjectSystem::SetupRuntimeFileTracking(const IAUDynArray& constructors_) +{ +#ifndef RCCPPOFF + // for optimization purposes we skip some actions when running for the first time (i.e. no previous constructors) + static bool bFirstTime = true; + + for (size_t i = 0, iMax = constructors_.Size(); i < iMax; ++i) + { + const char* pFilename = constructors_[i]->GetFileName(); // GetFileName returns full path including GetCompiledPath() + if( !pFilename ) + { + continue; + } + Path filePath = pFilename; + filePath = filePath.GetCleanPath(); + filePath = FindFile( filePath ); + + unsigned short projectId = constructors_[ i ]->GetProjectId(); + ProjectSettings& project = GetProject( projectId ); + AddToRuntimeFileList( filePath.c_str( ), projectId ); + + if( !bFirstTime ) + { + //remove old include file mappings for this file + TFileToFilesIterator itrCurr = project.m_RuntimeIncludeMap.begin( ); + while( itrCurr != project.m_RuntimeIncludeMap.end( ) ) + { + if( itrCurr->second == filePath ) + { + TFileToFilesIterator itrErase = itrCurr; + ++itrCurr; + project.m_RuntimeIncludeMap.erase( itrErase ); + } + else + { + ++itrCurr; + } + } + + //remove previous link libraries for this file + project.m_RuntimeLinkLibraryMap.erase( filePath ); + + //remove previous source dependencies + project.m_RuntimeSourceDependencyMap.erase( filePath ); + } + + //we need the compile path for some platforms where the __FILE__ path is relative to the compile path + FileSystemUtils::Path compileDir = constructors_[i]->GetCompiledPath(); + + //add include file mappings + for (size_t includeNum = 0; includeNum <= constructors_[i]->GetMaxNumIncludeFiles(); ++includeNum) + { + const char* pIncludeFile = constructors_[i]->GetIncludeFile(includeNum); + if( pIncludeFile ) + { + FileSystemUtils::Path pathInc = compileDir / pIncludeFile; + pathInc = FindFile( pathInc.GetCleanPath() ); + TFileToFilePair includePathPair; + includePathPair.first = pathInc; + includePathPair.second = filePath; + AddToRuntimeFileList( pathInc.c_str(), projectId ); + project.m_RuntimeIncludeMap.insert( includePathPair ); + } + } + + + //add link library file mappings + for (size_t linklibraryNum = 0; linklibraryNum <= constructors_[i]->GetMaxNumLinkLibraries(); ++linklibraryNum) + { + const char* pLinkLibrary = constructors_[i]->GetLinkLibrary(linklibraryNum); + if( pLinkLibrary ) + { + // We do not use FindFiles for Linked Libraries as these are searched for on + // the library paths, which are themselves searched for. + TFileToFilePair linklibraryPathPair; + linklibraryPathPair.first = filePath; + linklibraryPathPair.second = pLinkLibrary; + project.m_RuntimeLinkLibraryMap.insert( linklibraryPathPair ); + } + } + + //add source dependency file mappings + for (size_t num = 0; num <= constructors_[i]->GetMaxNumSourceDependencies(); ++num) + { + SourceDependencyInfo sourceDependency = constructors_[i]->GetSourceDependency(num); + FileSystemUtils::Path pathInc[2]; // array of potential include files for later checks + if( sourceDependency.filename ) + { + FileSystemUtils::Path pathSrc; + if( sourceDependency.relativeToPath ) + { + pathSrc = sourceDependency.relativeToPath; + if( pathSrc.HasExtension() ) + { + pathInc[1] = compileDir / pathSrc; + pathSrc = compileDir / pathSrc.ParentPath() / sourceDependency.filename; + } + else + { + pathSrc = compileDir / pathSrc / sourceDependency.filename; + } + } + else + { + pathSrc = compileDir / sourceDependency.filename; + } + pathSrc.ToOSCanonicalCase(); + pathSrc = pathSrc.DelimitersToOSDefault(); + pathSrc = pathSrc.GetCleanPath(); + pathInc[0] = pathSrc; + if( sourceDependency.extension ) + { + pathSrc.ReplaceExtension( sourceDependency.extension ); + } + pathSrc = FindFile( pathSrc.GetCleanPath() ); + TFileToFilePair sourcePathPair; + sourcePathPair.first = filePath; + sourcePathPair.second = pathSrc; + project.m_RuntimeSourceDependencyMap.insert( sourcePathPair ); + + // if the include file with a source dependancy is logged as an runtime include, then we mark this .cpp as compile dependencies on change + for( int inc=0; inc<2; ++inc ) + { + TFileToFilesEqualRange range = project.m_RuntimeIncludeMap.equal_range( pathInc[inc] ); + if( range.first != range.second ) + { + // add source file to runtime file list + AddToRuntimeFileList( pathSrc.c_str(), projectId ); + + // also add this as a source dependency, so it gets force compiled on change of header (and not just compiled) + TFileToFilePair includePathPair; + includePathPair.first = pathInc[inc]; + includePathPair.second = pathSrc; + project.m_RuntimeIncludeMap.insert( includePathPair ); + } + } + } + } + } + + bFirstTime = false; +#endif +} + +RuntimeObjectSystem::ProjectSettings& RuntimeObjectSystem::GetProject( unsigned short projectId_ ) +{ + if( projectId_ >= m_Projects.size() ) + { + m_Projects.resize(projectId_ + 1); + } + return m_Projects[ projectId_ ]; +} + + +void RuntimeObjectSystem::AddIncludeDir( const char *path_, unsigned short projectId_ ) +{ + GetProject( projectId_).m_CompilerOptions.includeDirList.push_back( path_ ); +} + + +void RuntimeObjectSystem::AddLibraryDir( const char *path_, unsigned short projectId_ ) +{ + GetProject( projectId_ ).m_CompilerOptions.libraryDirList.push_back( path_ ); +} + +void RuntimeObjectSystem::SetAdditionalCompileOptions( const char *options, unsigned short projectId_ ) +{ + GetProject( projectId_ ).m_CompilerOptions.compileOptions = options; +} + +void RuntimeObjectSystem::SetCompilerLocation( const char *path, unsigned short projectId_ ) +{ + GetProject( projectId_ ).m_CompilerOptions.compilerLocation = path; +} + +void RuntimeObjectSystem::SetAdditionalLinkOptions( const char *options, unsigned short projectId_ ) +{ + GetProject( projectId_ ).m_CompilerOptions.linkOptions = options; +} + +void RuntimeObjectSystem::SetOptimizationLevel( RCppOptimizationLevel optimizationLevel_, unsigned short projectId_ ) +{ + GetProject( projectId_ ).m_CompilerOptions.optimizationLevel = optimizationLevel_; +} + +RCppOptimizationLevel RuntimeObjectSystem::GetOptimizationLevel( unsigned short projectId_ ) +{ + return GetProject( projectId_ ).m_CompilerOptions.optimizationLevel; +} + +void RuntimeObjectSystem::SetIntermediateDir( const char* path_, unsigned short projectId_ ) +{ + GetProject( projectId_ ).m_CompilerOptions.baseIntermediatePath = path_; +} + +void RuntimeObjectSystem::CleanObjectFiles() const +{ + if( m_pBuildTool ) + { + for( unsigned short proj = 0; proj < m_Projects.size(); ++proj ) + { + for( int optimizationLevel = 0; + optimizationLevel < RCCPPOPTIMIZATIONLEVEL_SIZE; + ++optimizationLevel ) + { + Path intermediateFolder = GetIntermediateFolder( m_Projects[ proj ].m_CompilerOptions.baseIntermediatePath, RCppOptimizationLevel( optimizationLevel ) ); + m_pBuildTool->Clean( intermediateFolder ); + } + } + } +} + +FileSystemUtils::Path RuntimeObjectSystem::FindFile( const FileSystemUtils::Path& input ) +{ + FileSystemUtils::Path requestedDirectory = input; + FileSystemUtils::Path filename; + FileSystemUtils::Path foundFile = input; + bool bIsFile = input.HasExtension(); + if( bIsFile ) + { + requestedDirectory = requestedDirectory.ParentPath(); + filename = input.Filename(); + } + requestedDirectory.ToOSCanonicalCase(); + filename.ToOSCanonicalCase(); + foundFile.ToOSCanonicalCase(); + + // Step 1: Try input directory + if( requestedDirectory.Exists() ) + { + m_FoundSourceDirectoryMappings[ requestedDirectory ] = requestedDirectory; + } + else + { + // Step 2: Attempt to find a pre-existing mapping + bool bFoundMapping = false; + if( m_FoundSourceDirectoryMappings.size() ) + { + FileSystemUtils::Path testDir = requestedDirectory; + FileSystemUtils::Path foundDir; + unsigned int depth = 0; + bool bFound = false; + while( testDir.HasParentPath() ) + { + TFileMapIterator itrFind = m_FoundSourceDirectoryMappings.find( testDir ); + if( itrFind != m_FoundSourceDirectoryMappings.end() ) + { + foundDir = itrFind->second; + bFound = true; + break; + } + + testDir = testDir.ParentPath(); + ++depth; + } + + if( bFound ) + { + if( depth ) + { + // not an exact match + FileSystemUtils::Path directory = requestedDirectory; + directory.m_string.replace( 0, testDir.m_string.length(), foundDir.m_string ); + if( directory.Exists() ) + { + foundFile = directory / filename; + if( foundFile.Exists() ) + { + m_FoundSourceDirectoryMappings[ requestedDirectory ] = directory; + if( m_pCompilerLogger ) { m_pCompilerLogger->LogInfo( "Found Directory Mapping: %s to %s\n", requestedDirectory.c_str(), directory.c_str() ); } + bFoundMapping = true; + } + } + + } + else + { + // exact match + foundFile = foundDir / filename; + bFoundMapping = true; + } + } + + if( !bFoundMapping ) + { + // Step 3: Attempt to find a mapping from a known path + TFileList requestedSubPaths; + FileSystemUtils::Path requestedSubPath = requestedDirectory; + while( requestedSubPath.HasParentPath() ) + { + requestedSubPaths.push_back( requestedSubPath ); + requestedSubPath = requestedSubPath.ParentPath(); + } + + TFileMapIterator itr = m_FoundSourceDirectoryMappings.begin(); + while( ( itr != m_FoundSourceDirectoryMappings.end() ) && !bFoundMapping ) + { + FileSystemUtils::Path existingPath = itr->second; + while( ( existingPath.HasParentPath() ) && !bFoundMapping ) + { + // check all potentials + for( size_t i=0; iLogInfo( "Found Directory Mapping: %s to %s\n", requestedDirectory.c_str(), directory.c_str() ); } + bFoundMapping = true; + break; + } + } + } + } + existingPath = existingPath.ParentPath(); + } + ++itr; + } + } + } + } + + if( !foundFile.Exists() ) + { + if( m_pCompilerLogger ) { m_pCompilerLogger->LogWarning( "Could not find Directory Mapping for: %s\n", input.c_str() ); } + ++m_NumNotFoundSourceFiles; + } + return foundFile; +} + + +void RuntimeObjectSystem::AddPathToSourceSearch( const char* path ) +{ + m_FoundSourceDirectoryMappings[ path ] = path; +} + + +bool RuntimeObjectSystem::TestBuildCallback(const char* file, TestBuildResult type) +{ + switch( type ) + { + case TESTBUILDRRESULT_SUCCESS: // SUCCESS, yay! + if( m_pCompilerLogger ) { m_pCompilerLogger->LogInfo("TESTBUILDRRESULT_SUCCESS: %s\n", file); } + break; + case TESTBUILDRRESULT_NO_FILES_TO_BUILD: // file registration error or no runtime files of this type + if( m_pCompilerLogger ) { m_pCompilerLogger->LogWarning("TESTBUILDRRESULT_NO_FILES_TO_BUILD\n"); } + break; + case TESTBUILDRRESULT_BUILD_FILE_GONE: // the file is no longer present + if( m_pCompilerLogger ) { m_pCompilerLogger->LogError("TESTBUILDRRESULT_BUILD_FILE_GONE: %s\n", file); } + break; + case TESTBUILDRRESULT_BUILD_NOT_STARTED: // file change detection could be broken, or if an include may not be included anywhere + if( m_pCompilerLogger ) { m_pCompilerLogger->LogError("TESTBUILDRRESULT_BUILD_NOT_STARTED: %s\n", file); } + break; + case TESTBUILDRRESULT_BUILD_FAILED: // a build was started, but it failed or module failed to load. See log. + if( m_pCompilerLogger ) { m_pCompilerLogger->LogError("TESTBUILDRRESULT_BUILD_FAILED: %s\n", file); } + break; + case TESTBUILDRRESULT_OBJECT_SWAP_FAIL: // build succeeded, module loaded but errors on swapping + if( m_pCompilerLogger ) { m_pCompilerLogger->LogError("TESTBUILDRRESULT_OBJECT_SWAP_FAIL: %s\n", file); } + break; + default: + assert(false); + break; + } + return true; +} + +// returns 0 on success, -ve number of errors if there is an error and we should quit, +// positive number of errors if there is an error but we should continue +static int TestBuildFile( ICompilerLogger* pLog, RuntimeObjectSystem* pRTObjSys, const Path& file, + ITestBuildNotifier* callback, bool bTestFileTracking ) +{ + assert( callback ); + + if( pLog ) { pLog->LogInfo("Testing change to file: %s\n", file.c_str()); } + + int numErrors = 0; + if( file.Exists() ) + { + if( bTestFileTracking ) + { + FileSystemUtils::filetime_t currTime = FileSystemUtils::GetCurrentTime(); + FileSystemUtils::filetime_t oldModTime = file.GetLastWriteTime(); + if( currTime == oldModTime ) + { + // some files may be auto-generated by the program, so may have just been created so won't + // get a time change unless we force it. + currTime += 1; + } + file.SetLastWriteTime( currTime ); + // we must also change the directories time, as some of our watchers watch the dir + Path directory = file.ParentPath(); + directory.SetLastWriteTime( currTime ); + for( int i=0; i<50; ++i ) + { + // wait up to 100 seconds (make configurable?) + pRTObjSys->GetFileChangeNotifier()->Update( 1.0f ); // force update by using very large time delta + if( pRTObjSys->GetIsCompiling() ) { break; } + if( !callback->TestBuildWaitAndUpdate() ) + { + return -0xD1E; + } + } + } + else + { + AUDynArray filelist; + filelist.Add( file.c_str() ); + pRTObjSys->OnFileChange( filelist ); + } + if( pRTObjSys->GetIsCompiling() ) + { + while( !pRTObjSys->GetIsCompiledComplete() ) + { + if( !callback->TestBuildWaitAndUpdate() ) + { + return -0xD1E; + } + } + int numCurrLoadedModules = pRTObjSys->GetNumberLoadedModules(); + if( pRTObjSys->LoadCompiledModule() ) + { + if( !callback->TestBuildCallback( file.c_str(), TESTBUILDRRESULT_SUCCESS ) ) { return -0xD1E; } + return 0; + } + else + { + ++numErrors; + if( pRTObjSys->GetNumberLoadedModules() == numCurrLoadedModules ) + { + if( !callback->TestBuildCallback( file.c_str(), TESTBUILDRRESULT_BUILD_FAILED ) ) { return -numErrors; } + } + else + { + // loaded the module but some other issue + if( !callback->TestBuildCallback( file.c_str(), TESTBUILDRRESULT_OBJECT_SWAP_FAIL ) ) { return -numErrors; } + } + } + } + else + { + ++numErrors; + if( !callback->TestBuildCallback( file.c_str(), TESTBUILDRRESULT_BUILD_NOT_STARTED ) ) { return -numErrors; } + } + } + else + { + ++numErrors; + if( !callback->TestBuildCallback( file.c_str(), TESTBUILDRRESULT_BUILD_FILE_GONE ) ) { return -numErrors; } + } + return numErrors; +} + +// tests one by one touching each runtime modifiable source file +// returns the number of errors - 0 if all passed. +int RuntimeObjectSystem::TestBuildAllRuntimeSourceFiles( ITestBuildNotifier* callback, bool bTestFileTracking ) +{ + if( m_pCompilerLogger ) { m_pCompilerLogger->LogInfo("TestBuildAllRuntimeSourceFiles Starting\n"); } + + ITestBuildNotifier* failCallbackLocal = callback; + if( !failCallbackLocal ) + { + failCallbackLocal = this; + } + + int numErrors = 0; + + size_t numFilesToBuild = 0; + for( unsigned short proj = 0; proj < m_Projects.size( ); ++proj ) + { + numFilesToBuild += m_Projects[ proj ].m_RuntimeFileList.size( ); + } + + if( 0 == numFilesToBuild ) + { + failCallbackLocal->TestBuildCallback( NULL, TESTBUILDRRESULT_NO_FILES_TO_BUILD ); + } + + for( unsigned short proj = 0; proj < m_Projects.size(); ++proj ) + { + TFileList filesToTest = m_Projects[ proj ].m_RuntimeFileList; // m_RuntimeFileList could change if file content changes (new includes or source dependencies) so make copy to ensure iterators valid. + for( TFileList::iterator it = filesToTest.begin(); it != filesToTest.end(); ++it ) + { + const Path& file = *it; + if( file.Extension() != ".h" ) // exclude headers, use TestBuildAllRuntimeHeaders + { + int fileErrors = TestBuildFile( m_pCompilerLogger, this, file, failCallbackLocal, bTestFileTracking ); + if( fileErrors < 0 ) + { + // this means exit, and the number of errors is -ve so remove, unless -0xD1E is the response (for no error die) + if( fileErrors != -0xD1E ) + { + numErrors -= fileErrors; + } + return numErrors; + } + numErrors += fileErrors; + } + } + } + + if( 0 == numErrors ) + { + if( m_pCompilerLogger ) { m_pCompilerLogger->LogInfo("All Tests Passed\n"); } + } + else + { + if( m_pCompilerLogger ) { m_pCompilerLogger->LogError("Tests Failed: %d\n", numErrors); } + } + return numErrors; +} + +// tests touching each header which has RUNTIME_MODIFIABLE_INCLUDE. +// returns the number of errors - 0 if all passed. +int RuntimeObjectSystem::TestBuildAllRuntimeHeaders( ITestBuildNotifier* callback, bool bTestFileTracking ) +{ + ITestBuildNotifier* failCallbackLocal = callback; + if( !failCallbackLocal ) + { + failCallbackLocal = this; + } + + int numErrors = 0; + + size_t numFilesToBuild = 0; + for( unsigned short proj = 0; proj < m_Projects.size( ); ++proj ) + { + numFilesToBuild += m_Projects[ proj ].m_RuntimeFileList.size( ); + } + + if( 0 == numFilesToBuild ) + { + failCallbackLocal->TestBuildCallback( NULL, TESTBUILDRRESULT_NO_FILES_TO_BUILD ); + } + + for( unsigned short proj = 0; proj < m_Projects.size(); ++proj ) + { + TFileList filesToTest = m_Projects[ proj ].m_RuntimeFileList; // m_RuntimeFileList could change if file content changes (new includes or source dependencies) so make copy to ensure iterators valid. + for( TFileList::iterator it = filesToTest.begin( ); it != filesToTest.end( ); ++it ) + { + const Path& file = *it; + if( file.Extension() == ".h" ) // exclude headers, use TestBuildAllRuntimeHeaders + { + int fileErrors = TestBuildFile( m_pCompilerLogger, this, file, failCallbackLocal, bTestFileTracking ); + if( fileErrors < 0 ) + { + // this means exit, and the number of errors is -ve so remove + return numErrors - fileErrors; + } + numErrors += fileErrors; + } + } + } + + + if( 0 == numErrors ) + { + if( m_pCompilerLogger ) { m_pCompilerLogger->LogInfo("All Tests Passed\n"); } + } + else + { + if( m_pCompilerLogger ) { m_pCompilerLogger->LogError("Tests Failed: %d\n", numErrors); } + } + return numErrors; +} diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.h b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.h new file mode 100644 index 0000000..835487c --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.h @@ -0,0 +1,220 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef RUNTIMEOBJECTSYSTEM_INCLUDED +#define RUNTIMEOBJECTSYSTEM_INCLUDED + +#include "../RuntimeCompiler/IFileChangeNotifier.h" +#include "../RuntimeCompiler/BuildTool.h" +#include "../RuntimeCompiler/AUArray.h" +#include "ObjectInterface.h" +#include "IRuntimeObjectSystem.h" + +#ifdef _WIN32 + #define WIN32_LEAN_AND_MEAN + #include + #undef GetObject +#else + typedef void* HMODULE; +#endif +#include +#include + +#include "../RuntimeCompiler/FileSystemUtils.h" + +struct ICompilerLogger; +struct IObjectFactorySystem; + +class RuntimeObjectSystem : public IRuntimeObjectSystem, IFileChangeListener +{ +public: + RuntimeObjectSystem(); + virtual ~RuntimeObjectSystem(); + + // Initialise RuntimeObjectSystem. pLogger should be deleted by creator + virtual bool Initialise( ICompilerLogger * pLogger, SystemTable* pSystemTable ); + + virtual bool GetIsCompiling() + { + return m_bCompiling; + } + + virtual bool GetIsCompiledComplete(); + + virtual bool LoadCompiledModule(); + + virtual IObjectFactorySystem* GetObjectFactorySystem() const + { + return m_pObjectFactorySystem; + } + virtual IFileChangeNotifier* GetFileChangeNotifier() const + { + return m_pFileChangeNotifier; + } + + virtual void CompileAll( bool bForceRecompile ); + + virtual void CompileAllInProject( bool bForcerecompile_, unsigned short projectId_ = 0 ); + virtual void AddToRuntimeFileList( const char* filename, unsigned short projectId_ = 0 ); + virtual void RemoveFromRuntimeFileList( const char* filename, unsigned short projectId_ = 0 ); + virtual void AddIncludeDir( const char* path_, unsigned short projectId_ = 0 ); + virtual void AddLibraryDir( const char* path_, unsigned short projectId_ = 0 ); + virtual void SetAdditionalCompileOptions( const char* options, unsigned short projectId_ = 0 ); + virtual void SetAdditionalLinkOptions( const char* options, unsigned short projectId_ = 0 ); + virtual void SetCompilerLocation ( const char* path, unsigned short projectId_ = 0 ); + virtual void SetOptimizationLevel( RCppOptimizationLevel optimizationLevel_, unsigned short projectId_ = 0 ); + virtual RCppOptimizationLevel GetOptimizationLevel( unsigned short projectId_ = 0 ); + virtual void SetIntermediateDir( const char* path_, unsigned short projectId_ = 0 ); + + virtual void SetAutoCompile( bool autoCompile ); + virtual bool GetAutoCompile() const + { + return m_bAutoCompile; + } + + virtual void SetFastCompileMode( bool bFast ) + { + if( m_pBuildTool ) + { + m_pBuildTool->SetFastCompileMode( bFast ); + } + } + + virtual void CleanObjectFiles() const; + + virtual bool GetLastLoadModuleSuccess() const + { + return m_bLastLoadModuleSuccess; + } + virtual unsigned int GetNumberLoadedModules() const + { + return m_TotalLoadedModulesEver; + } + + virtual void SetupObjectConstructors(IPerModuleInterface* pPerModuleInterface); + + // exception handling to catch and protect main app from crashing when using runtime compiling + virtual void SetProtectionEnabled( bool bProtectionEnabled_ ); + + virtual bool IsProtectionEnabled() const + { + return m_bProtectionEnabled; + } + virtual bool TryProtectedFunction( RuntimeProtector* pProtectedObject_ ); + + + // tests one by one touching each runtime modifiable source file + // returns the number of errors - 0 if all passed. + virtual int TestBuildAllRuntimeSourceFiles( ITestBuildNotifier* callback, bool bTestFileTracking ); + + // tests touching each header which has RUNTIME_MODIFIABLE_INCLUDE. + // returns the number of errors - 0 if all passed. + virtual int TestBuildAllRuntimeHeaders( ITestBuildNotifier* callback, bool bTestFileTracking ); + + + virtual bool TestBuildCallback(const char* file, TestBuildResult type); + virtual bool TestBuildWaitAndUpdate(); + + // FindFile - attempts to find the file in a source directory + virtual FileSystemUtils::Path FindFile( const FileSystemUtils::Path& input ); + + // AddPathToSourceSearch - adds a path to help source search. Can be called multiple times to add paths. + virtual void AddPathToSourceSearch( const char* path ); + + // IFileChangeListener + + virtual void OnFileChange(const IAUDynArray& filelist); + + // ~IFileChangeListener + + std::vector linkLibraryList; + +private: + typedef std::vector TFileList; + typedef std::map TFileMap; + typedef TFileMap::iterator TFileMapIterator; + typedef std::multimap TFileToFilesMap; + typedef TFileToFilesMap::iterator TFileToFilesIterator; + typedef std::pair TFileToFilePair; + typedef std::pair TFileToFilesEqualRange; + + void StartRecompile(); + void SetupRuntimeFileTracking( const IAUDynArray& constructors_ ); + + // Members set in initialise + ICompilerLogger* m_pCompilerLogger; + SystemTable* m_pSystemTable; + + // Members created by this system + IObjectFactorySystem* m_pObjectFactorySystem; + IFileChangeNotifier* m_pFileChangeNotifier; + BuildTool* m_pBuildTool; + + bool m_bCompiling; + bool m_bLastLoadModuleSuccess; + std::vector m_Modules; // Stores runtime created modules, but not the exe module. + + bool m_bAutoCompile; + FileSystemUtils::Path m_CurrentlyCompilingModuleName; + + // per project information + struct ProjectSettings + { + ProjectSettings() + { + m_CompilerOptions.optimizationLevel = RCCPPOPTIMIZATIONLEVEL_DEFAULT; + m_CompilerOptions.baseIntermediatePath = ms_DefaultIntermediatePath; + } + + CompilerOptions m_CompilerOptions; + + TFileList m_RuntimeFileList; + TFileToFilesMap m_RuntimeIncludeMap; + TFileToFilesMap m_RuntimeLinkLibraryMap; + TFileToFilesMap m_RuntimeSourceDependencyMap; + + std::vector m_BuildFileList; + std::vector m_PendingBuildFileList; // if a compile is already underway, store files here. + + static FileSystemUtils::Path ms_DefaultIntermediatePath; + }; + std::vector m_Projects; + ProjectSettings& GetProject( unsigned short projectId_ ); + unsigned short m_CurrentlyBuildingProject; + + unsigned int m_TotalLoadedModulesEver; + bool m_bProtectionEnabled; + + + // File mappings - we need to map from compiled path to a potentially different path + // on the system the code is running on + TFileMap m_FoundSourceDirectoryMappings; // mappings between directories found and requested + unsigned int m_NumNotFoundSourceFiles; // count of source directories not found + + // platform implementation in RuntimeObjectSystem_Plaform*.cpp +public: + struct PlatformImpl; +private: + PlatformImpl* m_pImpl; + void CreatePlatformImpl(); + void DeletePlatformImpl(); + +}; + +#endif // RUNTIMEOBJECTSYSTEM_INCLUDED diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.vcxproj b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.vcxproj new file mode 100644 index 0000000..00ff194 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.vcxproj @@ -0,0 +1,208 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + true + true + true + true + + + + + + {FA4E24F1-885C-406B-89A8-436F28D090B2} + Systems + + + + StaticLibrary + true + Unicode + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + Async + false + %(AdditionalIncludeDirectories) + true + + + true + + + + + + + + + + + + + + + + + Level3 + Disabled + Async + false + %(AdditionalIncludeDirectories) + true + + + true + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + Async + false + _UNICODE;UNICODE;NDEBUG;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + true + + + true + true + true + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + Async + false + _UNICODE;UNICODE;NDEBUG;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + true + + + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.vcxproj.filters b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.vcxproj.filters new file mode 100644 index 0000000..1c2cfff --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.vcxproj.filters @@ -0,0 +1,42 @@ + + + + + + ObjectFactorySystem + + + SimpleSerializer + + + + + + + + + + + + + ObjectFactorySystem + + + SimpleSerializer + + + + + + + + + + + {d5986d12-394a-47fc-9758-17ebc5c6720c} + + + {59da87f4-0b75-46be-82e1-26feaffac32c} + + + \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.xcodeproj/project.pbxproj b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.xcodeproj/project.pbxproj new file mode 100644 index 0000000..0a783ae --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.xcodeproj/project.pbxproj @@ -0,0 +1,288 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 910584A816D67FF600FDEAC3 /* RuntimeProtector.h in Headers */ = {isa = PBXBuildFile; fileRef = 910584A716D67FF600FDEAC3 /* RuntimeProtector.h */; }; + 910987F416441841006315D5 /* RuntimeLinkLibrary.h in Headers */ = {isa = PBXBuildFile; fileRef = 910987F316441841006315D5 /* RuntimeLinkLibrary.h */; }; + 915C293216EB816D00654B4E /* RuntimeObjectSystem_PlatformPosix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 915C293116EB816D00654B4E /* RuntimeObjectSystem_PlatformPosix.cpp */; }; + 91B4FC2E161A027C0029E1A5 /* IObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 91B4FC1C161A027C0029E1A5 /* IObject.h */; }; + 91B4FC2F161A027C0029E1A5 /* IObjectFactorySystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 91B4FC1D161A027C0029E1A5 /* IObjectFactorySystem.h */; }; + 91B4FC30161A027C0029E1A5 /* IRuntimeObjectSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 91B4FC1E161A027C0029E1A5 /* IRuntimeObjectSystem.h */; }; + 91B4FC31161A027C0029E1A5 /* ISimpleSerializer.h in Headers */ = {isa = PBXBuildFile; fileRef = 91B4FC1F161A027C0029E1A5 /* ISimpleSerializer.h */; }; + 91B4FC32161A027C0029E1A5 /* ObjectFactorySystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91B4FC21161A027C0029E1A5 /* ObjectFactorySystem.cpp */; }; + 91B4FC33161A027C0029E1A5 /* ObjectFactorySystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 91B4FC22161A027C0029E1A5 /* ObjectFactorySystem.h */; }; + 91B4FC34161A027C0029E1A5 /* ObjectInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 91B4FC23161A027C0029E1A5 /* ObjectInterface.h */; }; + 91B4FC35161A027C0029E1A5 /* ObjectInterfacePerModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 91B4FC24161A027C0029E1A5 /* ObjectInterfacePerModule.h */; }; + 91B4FC36161A027C0029E1A5 /* ObjectInterfacePerModuleSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91B4FC25161A027C0029E1A5 /* ObjectInterfacePerModuleSource.cpp */; }; + 91B4FC37161A027C0029E1A5 /* RuntimeInclude.h in Headers */ = {isa = PBXBuildFile; fileRef = 91B4FC26161A027C0029E1A5 /* RuntimeInclude.h */; }; + 91B4FC38161A027C0029E1A5 /* RuntimeObjectSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91B4FC27161A027C0029E1A5 /* RuntimeObjectSystem.cpp */; }; + 91B4FC39161A027C0029E1A5 /* RuntimeObjectSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 91B4FC28161A027C0029E1A5 /* RuntimeObjectSystem.h */; }; + 91B4FC3A161A027C0029E1A5 /* SimpleSerializer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91B4FC2A161A027C0029E1A5 /* SimpleSerializer.cpp */; }; + 91B4FC3B161A027C0029E1A5 /* SimpleSerializer.h in Headers */ = {isa = PBXBuildFile; fileRef = 91B4FC2B161A027C0029E1A5 /* SimpleSerializer.h */; }; + 91EF513F17280D8A009B4B4B /* RuntimeSourceDependency.h in Headers */ = {isa = PBXBuildFile; fileRef = 91EF513E17280D8A009B4B4B /* RuntimeSourceDependency.h */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 910584A716D67FF600FDEAC3 /* RuntimeProtector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeProtector.h; sourceTree = ""; }; + 910987F316441841006315D5 /* RuntimeLinkLibrary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeLinkLibrary.h; sourceTree = ""; }; + 913A25D21619FB7D006AF4C1 /* libRuntimeObjectSystem.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRuntimeObjectSystem.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 915C293116EB816D00654B4E /* RuntimeObjectSystem_PlatformPosix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuntimeObjectSystem_PlatformPosix.cpp; sourceTree = ""; }; + 91B4FC1C161A027C0029E1A5 /* IObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IObject.h; sourceTree = ""; }; + 91B4FC1D161A027C0029E1A5 /* IObjectFactorySystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IObjectFactorySystem.h; sourceTree = ""; }; + 91B4FC1E161A027C0029E1A5 /* IRuntimeObjectSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IRuntimeObjectSystem.h; sourceTree = ""; }; + 91B4FC1F161A027C0029E1A5 /* ISimpleSerializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ISimpleSerializer.h; sourceTree = ""; }; + 91B4FC21161A027C0029E1A5 /* ObjectFactorySystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ObjectFactorySystem.cpp; sourceTree = ""; }; + 91B4FC22161A027C0029E1A5 /* ObjectFactorySystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectFactorySystem.h; sourceTree = ""; }; + 91B4FC23161A027C0029E1A5 /* ObjectInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectInterface.h; sourceTree = ""; }; + 91B4FC24161A027C0029E1A5 /* ObjectInterfacePerModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectInterfacePerModule.h; sourceTree = ""; }; + 91B4FC25161A027C0029E1A5 /* ObjectInterfacePerModuleSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ObjectInterfacePerModuleSource.cpp; sourceTree = ""; }; + 91B4FC26161A027C0029E1A5 /* RuntimeInclude.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeInclude.h; sourceTree = ""; }; + 91B4FC27161A027C0029E1A5 /* RuntimeObjectSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuntimeObjectSystem.cpp; sourceTree = ""; }; + 91B4FC28161A027C0029E1A5 /* RuntimeObjectSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeObjectSystem.h; sourceTree = ""; }; + 91B4FC2A161A027C0029E1A5 /* SimpleSerializer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimpleSerializer.cpp; sourceTree = ""; }; + 91B4FC2B161A027C0029E1A5 /* SimpleSerializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleSerializer.h; sourceTree = ""; }; + 91EF513E17280D8A009B4B4B /* RuntimeSourceDependency.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeSourceDependency.h; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 913A25CF1619FB7D006AF4C1 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 913A25C71619FB7D006AF4C1 = { + isa = PBXGroup; + children = ( + 915C293116EB816D00654B4E /* RuntimeObjectSystem_PlatformPosix.cpp */, + 910987F316441841006315D5 /* RuntimeLinkLibrary.h */, + 910584A716D67FF600FDEAC3 /* RuntimeProtector.h */, + 91B4FC1C161A027C0029E1A5 /* IObject.h */, + 91B4FC1D161A027C0029E1A5 /* IObjectFactorySystem.h */, + 91B4FC1E161A027C0029E1A5 /* IRuntimeObjectSystem.h */, + 91B4FC1F161A027C0029E1A5 /* ISimpleSerializer.h */, + 91B4FC20161A027C0029E1A5 /* ObjectFactorySystem */, + 91B4FC23161A027C0029E1A5 /* ObjectInterface.h */, + 91B4FC24161A027C0029E1A5 /* ObjectInterfacePerModule.h */, + 91B4FC25161A027C0029E1A5 /* ObjectInterfacePerModuleSource.cpp */, + 91B4FC26161A027C0029E1A5 /* RuntimeInclude.h */, + 91EF513E17280D8A009B4B4B /* RuntimeSourceDependency.h */, + 91B4FC27161A027C0029E1A5 /* RuntimeObjectSystem.cpp */, + 91B4FC28161A027C0029E1A5 /* RuntimeObjectSystem.h */, + 91B4FC29161A027C0029E1A5 /* SimpleSerializer */, + 913A25D31619FB7D006AF4C1 /* Products */, + ); + sourceTree = ""; + }; + 913A25D31619FB7D006AF4C1 /* Products */ = { + isa = PBXGroup; + children = ( + 913A25D21619FB7D006AF4C1 /* libRuntimeObjectSystem.a */, + ); + name = Products; + sourceTree = ""; + }; + 91B4FC20161A027C0029E1A5 /* ObjectFactorySystem */ = { + isa = PBXGroup; + children = ( + 91B4FC21161A027C0029E1A5 /* ObjectFactorySystem.cpp */, + 91B4FC22161A027C0029E1A5 /* ObjectFactorySystem.h */, + ); + path = ObjectFactorySystem; + sourceTree = ""; + }; + 91B4FC29161A027C0029E1A5 /* SimpleSerializer */ = { + isa = PBXGroup; + children = ( + 91B4FC2A161A027C0029E1A5 /* SimpleSerializer.cpp */, + 91B4FC2B161A027C0029E1A5 /* SimpleSerializer.h */, + ); + path = SimpleSerializer; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 913A25D01619FB7D006AF4C1 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 91B4FC2E161A027C0029E1A5 /* IObject.h in Headers */, + 91B4FC2F161A027C0029E1A5 /* IObjectFactorySystem.h in Headers */, + 91B4FC30161A027C0029E1A5 /* IRuntimeObjectSystem.h in Headers */, + 91B4FC31161A027C0029E1A5 /* ISimpleSerializer.h in Headers */, + 91B4FC33161A027C0029E1A5 /* ObjectFactorySystem.h in Headers */, + 91B4FC34161A027C0029E1A5 /* ObjectInterface.h in Headers */, + 91B4FC35161A027C0029E1A5 /* ObjectInterfacePerModule.h in Headers */, + 91B4FC37161A027C0029E1A5 /* RuntimeInclude.h in Headers */, + 91B4FC39161A027C0029E1A5 /* RuntimeObjectSystem.h in Headers */, + 91B4FC3B161A027C0029E1A5 /* SimpleSerializer.h in Headers */, + 910987F416441841006315D5 /* RuntimeLinkLibrary.h in Headers */, + 910584A816D67FF600FDEAC3 /* RuntimeProtector.h in Headers */, + 91EF513F17280D8A009B4B4B /* RuntimeSourceDependency.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 913A25D11619FB7D006AF4C1 /* RuntimeObjectSystem */ = { + isa = PBXNativeTarget; + buildConfigurationList = 913A25D61619FB7D006AF4C1 /* Build configuration list for PBXNativeTarget "RuntimeObjectSystem" */; + buildPhases = ( + 913A25CE1619FB7D006AF4C1 /* Sources */, + 913A25CF1619FB7D006AF4C1 /* Frameworks */, + 913A25D01619FB7D006AF4C1 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = RuntimeObjectSystem; + productName = RuntimeObjectSystem; + productReference = 913A25D21619FB7D006AF4C1 /* libRuntimeObjectSystem.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 913A25C91619FB7D006AF4C1 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0440; + ORGANIZATIONNAME = "Doug Binks"; + }; + buildConfigurationList = 913A25CC1619FB7D006AF4C1 /* Build configuration list for PBXProject "RuntimeObjectSystem" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 913A25C71619FB7D006AF4C1; + productRefGroup = 913A25D31619FB7D006AF4C1 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 913A25D11619FB7D006AF4C1 /* RuntimeObjectSystem */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 913A25CE1619FB7D006AF4C1 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 91B4FC32161A027C0029E1A5 /* ObjectFactorySystem.cpp in Sources */, + 91B4FC36161A027C0029E1A5 /* ObjectInterfacePerModuleSource.cpp in Sources */, + 91B4FC38161A027C0029E1A5 /* RuntimeObjectSystem.cpp in Sources */, + 91B4FC3A161A027C0029E1A5 /* SimpleSerializer.cpp in Sources */, + 915C293216EB816D00654B4E /* RuntimeObjectSystem_PlatformPosix.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 913A25D41619FB7D006AF4C1 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.8; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + 913A25D51619FB7D006AF4C1 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.8; + SDKROOT = macosx; + }; + name = Release; + }; + 913A25D71619FB7D006AF4C1 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + EXECUTABLE_PREFIX = lib; + HEADER_SEARCH_PATHS = ../External/boost/; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = ""; + }; + name = Debug; + }; + 913A25D81619FB7D006AF4C1 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + EXECUTABLE_PREFIX = lib; + HEADER_SEARCH_PATHS = ../External/boost/; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = ""; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 913A25CC1619FB7D006AF4C1 /* Build configuration list for PBXProject "RuntimeObjectSystem" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 913A25D41619FB7D006AF4C1 /* Debug */, + 913A25D51619FB7D006AF4C1 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 913A25D61619FB7D006AF4C1 /* Build configuration list for PBXNativeTarget "RuntimeObjectSystem" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 913A25D71619FB7D006AF4C1 /* Debug */, + 913A25D81619FB7D006AF4C1 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 913A25C91619FB7D006AF4C1 /* Project object */; +} diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ad77228 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem_PlatformPosix.cpp b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem_PlatformPosix.cpp new file mode 100644 index 0000000..a4e3708 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem_PlatformPosix.cpp @@ -0,0 +1,163 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "RuntimeObjectSystem.h" +#include "RuntimeProtector.h" + +#ifdef __APPLE__ + // Mach ports requirements + #include +#endif + +#include +#include +#include +#include + +static __thread RuntimeProtector* m_pCurrProtector = 0; // for nested threaded handling, one per thread. + +#ifdef __APPLE__ + static bool ms_bMachPortSet = false; + + const size_t NUM_OLD_EXCEPTION_HANDLERS = 16; + static mach_msg_type_number_t old_count; + static exception_mask_t old_masks[NUM_OLD_EXCEPTION_HANDLERS]; + static mach_port_t old_ports[NUM_OLD_EXCEPTION_HANDLERS]; + static exception_behavior_t old_behaviors[NUM_OLD_EXCEPTION_HANDLERS]; + static thread_state_flavor_t old_flavors[NUM_OLD_EXCEPTION_HANDLERS]; +#endif + +void RuntimeObjectSystem::CreatePlatformImpl() +{ +#ifdef __APPLE__ + if( !ms_bMachPortSet ) + { + // prevent OS X debugger from catching signals in a none re-catchable way + task_get_exception_ports(mach_task_self(), EXC_MASK_BAD_ACCESS | EXC_MASK_BAD_INSTRUCTION, old_masks, &old_count, old_ports, old_behaviors, old_flavors); + task_set_exception_ports(mach_task_self(), EXC_MASK_BAD_ACCESS | EXC_MASK_BAD_INSTRUCTION, MACH_PORT_NULL, EXCEPTION_DEFAULT, MACHINE_THREAD_STATE); + ms_bMachPortSet = true; + } +#endif +} + +void RuntimeObjectSystem::DeletePlatformImpl() +{ +} + +void RuntimeObjectSystem::SetProtectionEnabled( bool bProtectionEnabled_ ) +{ + m_bProtectionEnabled = bProtectionEnabled_; +#ifdef __APPLE__ + if( !m_bProtectionEnabled ) + { + if( ms_bMachPortSet ) + { + for( int i = 0; i < old_count; ++i ) + { + task_set_exception_ports( mach_task_self(), old_masks[i], old_ports[i], old_behaviors[i], old_flavors[i]); + } + } + } + else + { + CreatePlatformImpl(); + } +#endif +} + + + +void signalHandler(int sig, siginfo_t *info, void *context) +{ + // we only handle synchronous signals with this handler, so they come to the correct thread. + assert( m_pCurrProtector ); + + // store exception information + switch( sig ) + { + case SIGILL: + m_pCurrProtector->ExceptionInfo.Type = RuntimeProtector::ESE_InvalidInstruction; + break; + case SIGBUS: + m_pCurrProtector->ExceptionInfo.Type = RuntimeProtector::ESE_AccessViolation; + break; + case SIGSEGV: + m_pCurrProtector->ExceptionInfo.Type = RuntimeProtector::ESE_AccessViolation; + break; + default: assert(false); //should not get here + } + m_pCurrProtector->ExceptionInfo.Addr = info->si_addr; + longjmp(m_pCurrProtector->m_env, sig ); +} + +bool RuntimeObjectSystem::TryProtectedFunction( RuntimeProtector* pProtectedObject_ ) +{ + if( !m_bProtectionEnabled ) + { + pProtectedObject_->ProtectedFunc(); + return true; + } + + // allow cascading by storing prev and current impl + pProtectedObject_->m_pPrevious = m_pCurrProtector; + m_pCurrProtector = pProtectedObject_; + + struct sigaction oldAction[3]; // we need to store old actions, could remove for optimization + + bool bHasJustHadException = false; + if( m_TotalLoadedModulesEver != pProtectedObject_->m_ModulesLoadedCount ) + { + // clear exceptions if we've just loaded a new module + pProtectedObject_->m_ModulesLoadedCount = m_TotalLoadedModulesEver; + pProtectedObject_->m_bHashadException = false; + } + + if( !pProtectedObject_->m_bHashadException ) + { + if( setjmp(m_pCurrProtector->m_env) ) + { + pProtectedObject_->m_bHashadException = true; + bHasJustHadException = true; + } + else + { + struct sigaction newAction; + memset( &newAction, 0, sizeof( newAction )); + newAction.sa_sigaction = signalHandler; + newAction.sa_flags = SA_SIGINFO; //use complex signal hander function sa_sigaction not sa_handler + sigaction(SIGILL, &newAction, &oldAction[0] ); + sigaction(SIGBUS, &newAction, &oldAction[1] ); + sigaction(SIGSEGV, &newAction, &oldAction[2] ); + + pProtectedObject_->ProtectedFunc(); + } + + //reset + sigaction(SIGILL, &oldAction[0], NULL ); + sigaction(SIGBUS, &oldAction[1], NULL ); + sigaction(SIGSEGV, &oldAction[2], NULL ); + } + m_pCurrProtector = pProtectedObject_->m_pPrevious; + return !bHasJustHadException; +} + + +bool RuntimeObjectSystem::TestBuildWaitAndUpdate() +{ + usleep( 100 * 1000 ); + return true; +} diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem_PlatformWindows.cpp b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem_PlatformWindows.cpp new file mode 100644 index 0000000..4485c5e --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem_PlatformWindows.cpp @@ -0,0 +1,197 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "RuntimeProtector.h" +#include "RuntimeObjectSystem.h" + +#define WIN32_LEAN_AND_MEAN +#include "Windows.h" +#include "WinBase.h" +#include "excpt.h" +#include + +// windows includes can cause GetObject to be defined, we undefine it here. +#ifdef GetObject + #undef GetObject +#endif + +struct RuntimeObjectSystem::PlatformImpl +{ + + enum ExceptionState + { + ES_PASS, + ES_CATCH, + }; + + ExceptionState s_exceptionState; + + PlatformImpl() + : s_exceptionState( ES_PASS ) + { + } + + int RuntimeExceptionFilter() + { + if( !AmBeingDebugged() ) + { + // if there's no debugger, we simply continue operating. + // TODO: Should implement a method to ensure this can be + // disabled so process crashes on end user machines + return EXCEPTION_EXECUTE_HANDLER; + } + + int result; + switch (s_exceptionState) + { + case ES_PASS: + // Let pass to debugger once, then catch it + result = EXCEPTION_CONTINUE_SEARCH; + s_exceptionState = ES_CATCH; + break; + case ES_CATCH: + // Catch it now. Reset to catch in debugger again next time. + result = EXCEPTION_EXECUTE_HANDLER; + s_exceptionState = ES_PASS; + break; + default:; + assert(false); + } + + return result; + } + + bool AmBeingDebugged() + { + if( IsDebuggerPresent() ) + { + return true; + } + BOOL bRDebugPresent = FALSE; + CheckRemoteDebuggerPresent( GetModuleHandle(NULL), &bRDebugPresent ); + if( FALSE == bRDebugPresent ) + { + return false; + } + else + { + return true; + } + } + + int SimpleExceptionFilter( void * nativeExceptionInfo, RuntimeProtector* pRuntimeProtector ) + { + EXCEPTION_RECORD *pRecord = ((LPEXCEPTION_POINTERS) nativeExceptionInfo)->ExceptionRecord; + int nCode = pRecord->ExceptionCode; + pRuntimeProtector->ExceptionInfo.Type = RuntimeProtector::ESE_Unknown; + pRuntimeProtector->ExceptionInfo.Addr = 0; + + + if (nCode == EXCEPTION_ACCESS_VIOLATION) + { + ULONG_PTR flavour = pRecord->ExceptionInformation[0]; + switch( flavour ) + { + case 0: + pRuntimeProtector->ExceptionInfo.Type = RuntimeProtector::ESE_AccessViolationRead; + pRuntimeProtector->ExceptionInfo.Addr = (void*)pRecord->ExceptionInformation[1]; + break; + case 1: + pRuntimeProtector->ExceptionInfo.Type = RuntimeProtector::ESE_AccessViolationWrite; + pRuntimeProtector->ExceptionInfo.Addr = (void*)pRecord->ExceptionInformation[1]; + break; + default: + break; + } + } + else if( nCode == EXCEPTION_ILLEGAL_INSTRUCTION ) + { + pRuntimeProtector->ExceptionInfo.Type = RuntimeProtector::ESE_InvalidInstruction; + pRuntimeProtector->ExceptionInfo.Addr = pRecord->ExceptionAddress; + } + + if( !pRuntimeProtector->m_bHintAllowDebug ) + { + // We don't want debugging to catch this + return EXCEPTION_EXECUTE_HANDLER; + } + + // Otherwise fall back + return RuntimeExceptionFilter(); + } +}; + +void RuntimeObjectSystem::CreatePlatformImpl() +{ + m_pImpl = new PlatformImpl(); +} +void RuntimeObjectSystem::DeletePlatformImpl() +{ + delete m_pImpl; +} + +void RuntimeObjectSystem::SetProtectionEnabled( bool bProtectionEnabled_ ) +{ + m_bProtectionEnabled = bProtectionEnabled_; +} + + +bool RuntimeObjectSystem::TryProtectedFunction( RuntimeProtector* pProtectedObject_ ) +{ + bool bJustCaughtException = false; + if( m_TotalLoadedModulesEver != pProtectedObject_->m_ModulesLoadedCount ) + { + // clear exceptions if we've just loaded a new module + pProtectedObject_->m_ModulesLoadedCount = m_TotalLoadedModulesEver; + pProtectedObject_->m_bHashadException = false; + } + if( m_bProtectionEnabled ) + { + if( !pProtectedObject_->m_bHashadException ) + { + __try + { + pProtectedObject_->ProtectedFunc(); + } + __except( m_pImpl->SimpleExceptionFilter( GetExceptionInformation(), pProtectedObject_ ) ) + { + // If we hit any structured exception, exceptionInfo will be initialized + // If it's one we recognise and we hinted for no debugging, we'll go straight here, with info filled out + // If not we'll go to debugger first, then here + pProtectedObject_->m_bHashadException = true; + bJustCaughtException = true; + } + } + } + else + { + pProtectedObject_->m_bHashadException = false; + pProtectedObject_->ProtectedFunc(); + } + return !bJustCaughtException; +} + +bool RuntimeObjectSystem::TestBuildWaitAndUpdate() +{ + Sleep( 100 ); + MSG msg; + while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) + { + DispatchMessage( &msg ); + } + return true; +} diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeProtector.h b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeProtector.h new file mode 100644 index 0000000..7eeb376 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeProtector.h @@ -0,0 +1,86 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + + +#pragma once + +#ifndef _WIN32 + #include // used by posix type systems to chain handling +#endif + +// class RuntimeProtector +// overload void ProtectedFunc() to use, put function context (io) in new members +// do not create threads within protected function +// for threaded usuage use a protector per thread +// amortize virtual function call and exception handling by processing many things in one call +// note this isn't a functor as we prefer the explicit function name, and not using lambda's due to Cx11 +// not being supported sufficiently as yet +struct RuntimeProtector +{ + // consctructor, hint allow debug may be ignored when true if on an OS which has not had this implemented + RuntimeProtector() + : m_bHashadException( false ) + , m_bHintAllowDebug( true ) + , m_ModulesLoadedCount( 0 ) +#ifndef _WIN32 + , m_pPrevious( 0 ) +#endif + { + } + + virtual ~RuntimeProtector() {} + + // don't call this directly, derive a class and implement it for your protected func + virtual void ProtectedFunc() = 0; + + bool HasHadException() const + { + return m_bHashadException; + } + void ClearExceptions() + { + m_bHashadException = false; + } + + //exception information (exposed rather than get/set for simplicity) + enum ExceptionType + { + ESE_Unknown, + ESE_AccessViolation, + ESE_AccessViolationRead, //may just get ESE_AccessViolation + ESE_AccessViolationWrite, //may just get ESE_AccessViolation + ESE_InvalidInstruction + + }; + struct ExceptionInfo_t + { + ExceptionType Type; + void* Addr; //address of data for access voilation, or instruction for invalid instruction + }; + ExceptionInfo_t ExceptionInfo; + + bool m_bHashadException; + bool m_bHintAllowDebug; // some RuntimeProtectors may not want to allow debug + + // internal + unsigned int m_ModulesLoadedCount; // used internally to reset exceptions when a new module is loaded +#ifndef _WIN32 + jmp_buf m_env; + RuntimeProtector* m_pPrevious; // used by posix type systems to chain handling +#endif +}; + diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeSourceDependency.h b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeSourceDependency.h new file mode 100644 index 0000000..701d842 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeSourceDependency.h @@ -0,0 +1,131 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef RUNTIMESOURCEDEPENDENCY_INCLUDED +#define RUNTIMESOURCEDEPENDENCY_INCLUDED + +//NOTE: the file macro will only emit the full path if /FC option is used in visual studio or /ZI (Which forces /FC) +//Following creates a list of files which are runtime modifiable, to be used in headers +//requires use of __COUNTER__ predefined macro, which is in gcc 4.3+, clang/llvm and MSVC + +// Source Dependencies are constructed from a macro template from sources which may include +// the __FILE__ macro, so to reduce inter-dependencies we return three values which are combined +// by the higher level code. The full source dependency filename is then pseudo-code: +// RemoveAnyFileName( relativeToPath ) + ReplaceExtension( filename, extension ) +struct SourceDependencyInfo +{ + static SourceDependencyInfo GetNULL() { SourceDependencyInfo ret = {0,0,0}; return ret; } + const char* filename; // If NULL then no SourceDependencyInfo + const char* extension; // If NULL then use extension in filename + const char* relativeToPath; // If NULL filename is either full or relative to known path +}; + +#ifndef RCCPPOFF + +struct IRuntimeSourceDependencyList +{ + IRuntimeSourceDependencyList( size_t max ) : MaxNum( max ) + { + } + + // GetIncludeFile may return 0, so you should iterate through to GetMaxNum() ignoring 0 returns + virtual SourceDependencyInfo GetSourceDependency( size_t Num_ ) const + { + return SourceDependencyInfo::GetNULL(); + } + + size_t MaxNum; // initialized in constructor below +}; + + +namespace +{ + +template< size_t COUNT > struct RuntimeSourceDependency : RuntimeSourceDependency +{ + RuntimeSourceDependency( size_t max ) : RuntimeSourceDependency( max ) + { + } + RuntimeSourceDependency() : RuntimeSourceDependency( COUNT ) + { + } + + virtual SourceDependencyInfo GetSourceDependency( size_t Num_ ) const + { + if( Num_ < COUNT ) + { + return this->RuntimeSourceDependency< COUNT-1 >::GetSourceDependency( Num_ ); + } + else return SourceDependencyInfo::GetNULL(); + } +}; + +template<> struct RuntimeSourceDependency<0> : IRuntimeSourceDependencyList +{ + RuntimeSourceDependency( size_t max ) : IRuntimeSourceDependencyList( max ) + { + } + RuntimeSourceDependency() : IRuntimeSourceDependencyList( 0 ) + { + } + + virtual SourceDependencyInfo GetSourceDependency( size_t Num_ ) const + { + return SourceDependencyInfo::GetNULL(); + } + +}; + + + +#define RUNTIME_COMPILER_SOURCEDEPENDENCY_BASE( SOURCEFILE, SOURCEEXT, RELATIVEPATHTO, N ) \ + template<> struct RuntimeSourceDependency< N + 1 > : RuntimeSourceDependency< N >\ + { \ + RuntimeSourceDependency( size_t max ) : RuntimeSourceDependency( max ) {} \ + RuntimeSourceDependency< N + 1 >() : RuntimeSourceDependency( N + 1 ) {} \ + virtual SourceDependencyInfo GetSourceDependency( size_t Num_ ) const \ + { \ + if( Num_ <= N ) \ + { \ + if( Num_ == N ) \ + { \ + return { SOURCEFILE, SOURCEEXT, RELATIVEPATHTO }; \ + } \ + else return this->RuntimeSourceDependency< N >::GetSourceDependency( Num_ ); \ + } \ + else return SourceDependencyInfo::GetNULL(); \ + } \ + }; \ + +// The RUNTIME_COMPILER_SOURCEDEPENDENCY macro will return the name of the current file, which should be a header file. +// The runtime system will strip off the extension and add .cpp +#define RUNTIME_COMPILER_SOURCEDEPENDENCY namespace { RUNTIME_COMPILER_SOURCEDEPENDENCY_BASE( __FILE__, ".cpp", 0, __COUNTER__ ) } + +// if you want to specify another extension use this version: +#define RUNTIME_COMPILER_SOURCEDEPENDENCY_EXT( EXT_ ) namespace { RUNTIME_COMPILER_SOURCEDEPENDENCY_BASE( __FILE__, EXT_, 0, __COUNTER__ ) } + +// for complete freedom of which file to specify, use this version (FILE_ is relative to current file path): +#define RUNTIME_COMPILER_SOURCEDEPENDENCY_FILE( FILE_, EXT_ ) namespace { RUNTIME_COMPILER_SOURCEDEPENDENCY_BASE( FILE_, EXT_, __FILE__, __COUNTER__ ) } + +} +#else +#define RUNTIME_COMPILER_SOURCEDEPENDENCY +#endif //RCCPPOFF + +#endif //RUNTIMESOURCEDEPENDENCY_INCLUDED diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/SimpleSerializer/SimpleSerializer.cpp b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/SimpleSerializer/SimpleSerializer.cpp new file mode 100644 index 0000000..475e46e --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/SimpleSerializer/SimpleSerializer.cpp @@ -0,0 +1,130 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "SimpleSerializer.h" +#include +#include "../../RuntimeObjectSystem/IObject.h" + +SimpleSerializer::SimpleSerializer() + : m_numProperties(0) + , m_bLoading( false ) + , m_pCurrentObject( 0 ) +{ +} + +SimpleSerializer::~SimpleSerializer() +{ + Clear(); +} + +void SimpleSerializer::Clear() +{ + TSerializationMap::iterator it = m_map.begin(); + while (it != m_map.end()) + { + TValueGroup::iterator it2 = it->second.begin(); + while (it2 != it->second.end()) + { + delete it2->second; + ++it2; + } + + ++it; + } +} + +void SimpleSerializer::Clear(ObjectId ownerId) +{ + TSerializationMap::iterator found = m_map.find(ownerId); + if (found != m_map.end()) + { + TValueGroup::iterator it = found->second.begin(); + while (it != found->second.end()) + { + delete it->second; + ++it; + } + } +} + +void SimpleSerializer::Clear(ObjectId ownerId, const char* propertyName) +{ + TSerializationMap::iterator found = m_map.find(ownerId); + if (found != m_map.end()) + { + TValueGroup::iterator propertyFound = found->second.find(propertyName); + if (propertyFound != found->second.end()) + { + delete propertyFound->second; + found->second.erase(propertyFound); + } + } +} + +void SimpleSerializer::Serialize( IObject* pObject ) +{ + assert( pObject ); + assert( 0 == m_pCurrentObject ); //should not serialize an object from within another + + m_pCurrentObject = pObject; + ObjectId ownerId; + m_pCurrentObject->GetObjectId(ownerId); + +// gSys->pLogSystem->Log( eLV_COMMENTS, "SimpleSerialiser: Serialising %s object: objectIdtype \"%s\", perTypeID:%d, address:0x%p\n" +// , m_bLoading ? "in" : "out", pObject->GetTypeName(), ownerId.m_PerTypeId, pObject ); + + m_CurrentSerialization = m_map.find(ownerId); + + m_pCurrentObject->Serialize( this ); + + //reset m_pCurrentObject + m_pCurrentObject = 0; +} + +void SimpleSerializer::SetISerializedValue(const char* propertyName, const ISerializedValue* pValue) +{ + assert( m_pCurrentObject ); + assert(pValue); + if( m_CurrentSerialization == m_map.end() ) + { + ObjectId ownerId; + m_pCurrentObject->GetObjectId(ownerId); + m_map[ownerId][propertyName] = pValue; + m_CurrentSerialization = m_map.find(ownerId); + } + m_CurrentSerialization->second[propertyName] = pValue; +} + +const ISerializedValue* SimpleSerializer::GetISerializedValue(const char* propertyName) const +{ + assert( m_pCurrentObject ); + assert( propertyName ); + assert( m_bLoading ); + const ISerializedValue* pRet = NULL; + + //TSerializationMap::const_iterator found = m_map.find(ownerId); + if (m_CurrentSerialization != m_map.end()) + { + TValueGroup::const_iterator propertyFound = m_CurrentSerialization->second.find(propertyName); + if (propertyFound != m_CurrentSerialization->second.end()) + { + pRet = propertyFound->second; + } + } + + return pRet; +} diff --git a/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/SimpleSerializer/SimpleSerializer.h b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/SimpleSerializer/SimpleSerializer.h new file mode 100644 index 0000000..0d6f74d --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/SimpleSerializer/SimpleSerializer.h @@ -0,0 +1,73 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef SIMPLESERIALIZER_INCLUDED +#define SIMPLESERIALIZER_INCLUDED + +#include "../ISimpleSerializer.h" + +#include +#include + +struct IObject; + +class SimpleSerializer : public ISimpleSerializer +{ +public: + + SimpleSerializer(); + virtual ~SimpleSerializer(); + + // ISimpleSerializer + + void Clear(); + void Clear(ObjectId ownerId); + void Clear(ObjectId ownerId, const char* propertyName); + + void Serialize( IObject* Object ); + + void SetISerializedValue(const char* propertyName, const ISerializedValue* pValue); + const ISerializedValue *GetISerializedValue(const char* propertyName) const; + virtual bool IsLoading() const + { + return m_bLoading; + } + void SetIsLoading( bool loading ) + { + m_bLoading = loading; + m_pCurrentObject = 0; + } + + + // ~ISimpleSerializer + +private: + + typedef std::map TValueGroup; + typedef std::map TSerializationMap; + + TSerializationMap m_map; + int m_numProperties; + bool m_bLoading; + IObject* m_pCurrentObject; + TSerializationMap::iterator m_CurrentSerialization; +}; + + +#endif // SIMPLESERIALIZER_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/.cproject b/3rdparty/RuntimeCompiledCpp/Systems/.cproject new file mode 100644 index 0000000..af0e283 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/.cproject @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/3rdparty/RuntimeCompiledCpp/Systems/.project b/3rdparty/RuntimeCompiledCpp/Systems/.project new file mode 100644 index 0000000..6ac145a --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/.project @@ -0,0 +1,28 @@ + + + Systems + + + Renderer + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/3rdparty/RuntimeCompiledCpp/Systems/AssetSystem/AssetSystem.cpp b/3rdparty/RuntimeCompiledCpp/Systems/AssetSystem/AssetSystem.cpp new file mode 100644 index 0000000..8a1d6db --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/AssetSystem/AssetSystem.cpp @@ -0,0 +1,121 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "AssetSystem.h" + +#include "../../Renderer/AURenMesh.h" +#include "../../RuntimeCompiler/FileSystemUtils.h" + +AssetSystem::AssetSystem(const char* AssetDirName_) +{ + //search for asset directory + FileSystemUtils::Path currPath; + currPath = FileSystemUtils::GetCurrentPath(); + bool bAssetDirFound = false; + + //test root and downwards for directory + while( currPath.HasParentPath() ) + { + FileSystemUtils::Path testPath = currPath / AssetDirName_; + if( testPath.Exists() ) + { + bAssetDirFound = true; + m_AssetDirectory = testPath.m_string; + break; + } + currPath = currPath.ParentPath(); + } + + if( !bAssetDirFound ) + { + //could be a development build, so test location of this source file and down + currPath = __FILE__; + if(currPath.Exists() ) + { + while( currPath.HasParentPath() ) + { + FileSystemUtils::Path testPath = currPath / AssetDirName_; + if( testPath.Exists() ) + { + bAssetDirFound = true; + m_AssetDirectory = testPath.m_string; + break; + } + currPath = currPath.ParentPath(); + } + } + } +} + + +AssetSystem::~AssetSystem() +{ + MESHMAP::iterator currMesh = m_Meshes.begin(); + while( currMesh != m_Meshes.end() ) + { + delete currMesh->second; + ++currMesh; + } +} + +IAURenderableMesh* AssetSystem::CreateRenderableMeshFromFile( const char* pFilename ) +{ + IAURenderableMesh* pRenMesh= 0; + std::string filename( pFilename ); + MESHMAP::iterator found = m_Meshes.find( filename ); + if( found != m_Meshes.end() ) + { + pRenMesh = new AURenderableMesh( found->second ); + } + else + { + std::string fileToLoad( pFilename ); + FindFile( fileToLoad ); + AURenMesh* pMesh = new AURenMesh; + pMesh->LoadFromFile( fileToLoad ); + m_Meshes[ filename ] = pMesh; //use passed in filename for map + pRenMesh = new AURenderableMesh( pMesh ); + } + + return pRenMesh; + +} + +void AssetSystem::DestroyRenderableMesh(IAURenderableMesh* pMesh) +{ + delete pMesh; +} + +bool AssetSystem::FindFile( std::string& filename ) +{ + if( FileSystemUtils::Path( filename ).Exists() ) + { + return true; + } + + //else try in asset directory + FileSystemUtils::Path testpath = m_AssetDirectory; + testpath = testpath / filename; + + if( testpath.Exists() ) + { + filename = testpath.m_string; + return true; + } + + return false; +} diff --git a/3rdparty/RuntimeCompiledCpp/Systems/AssetSystem/AssetSystem.h b/3rdparty/RuntimeCompiledCpp/Systems/AssetSystem/AssetSystem.h new file mode 100644 index 0000000..029805b --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/AssetSystem/AssetSystem.h @@ -0,0 +1,50 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef ASSETSYSTEM_INCLUDED +#define ASSETSYSTEM_INCLUDED + +#include "../IAssetSystem.h" +#include +#include + +class AURenMesh; + +class AssetSystem : public IAssetSystem +{ +public: + AssetSystem( const char* AssetDirName_ ); + virtual ~AssetSystem(); + + virtual IAURenderableMesh* CreateRenderableMeshFromFile( const char* pFilename ); + virtual void DestroyRenderableMesh( IAURenderableMesh* pMesh ); + + virtual const char* GetAssetDirectory() const + { + return m_AssetDirectory.c_str(); + } + +private: + bool FindFile( std::string& filename ); + typedef std::map MESHMAP; + MESHMAP m_Meshes; + std::string m_AssetDirectory; +}; + +#endif //ASSETSYSTEM_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/Definitions.inl b/3rdparty/RuntimeCompiledCpp/Systems/Definitions.inl new file mode 100644 index 0000000..9de5f55 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/Definitions.inl @@ -0,0 +1,50 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef DEFINITIONS_DEFINED +#define DEFINITIONS_DEFINED + +#ifndef _WIN32 + //the following won't work with the templated variety + #define _snprintf_s(a,b,c,...) snprintf(a,b,__VA_ARGS__) +#endif + +// All typedefs, defines and macros start AU_ to avoid conflicts + + +typedef int AUEntityId; // (Will be a) salted id for uniquely identifying entities + +struct IRuntimeObjectSystem; +struct IEntitySystem; +struct ITimeSystem; +struct ILogSystem; +struct IAssetSystem; + +struct IAUEntity; +struct IAURenderable; +struct IAURenderableMesh; +struct IAUUpdateable; +struct ISimpleSerializer; +struct IObjectFactorySystem; +struct IGUISystem; +struct IFileChangeNotifier; +struct IGame; +class CalSound; + +#endif // DEFINITIONS_DEFINED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/EntitySystem/EntitySystem.cpp b/3rdparty/RuntimeCompiledCpp/Systems/EntitySystem/EntitySystem.cpp new file mode 100644 index 0000000..189e5f6 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/EntitySystem/EntitySystem.cpp @@ -0,0 +1,138 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +// Implementation + +// Apply salts and buffer reuse later + +#include "EntitySystem.h" +#include "../../Renderer/IAURenderable.h" +#include "../IUpdateable.h" + +#include + +//#include physics etc proxies for delete + +void EntitySystem::Entity::SetName(const char * sName) +{ + if (sName && sName[0]) + { +#ifdef _WIN32 + strncpy_s(m_sName, sName, AU_ENTITY_NAME_LENGTH); +#else + strncpy(m_sName,sName,AU_ENTITY_NAME_LENGTH); +#endif + m_sName[AU_ENTITY_NAME_LENGTH-1] = '\0'; + // Could re length warn here + } + else + { + m_sName[0] = '\0'; + // And here + } +} + +void EntitySystem::Entity::SetObject(IEntityObject *pObject) { m_pObject = pObject; } // Not safe to delete, created in DLLs... + +void EntitySystem::Entity::SetRenderable(IAURenderable *pRenderable) { m_pRenderable = pRenderable; } // Not safe to delete, created in DLLs... + +void EntitySystem::Entity::SetUpdateable(IAUUpdateable *pUpdateable) { m_pUpdateable = pUpdateable; } // Not safe to delete, created in DLLs... + +AUEntityId EntitySystem::Create(const char * sName) +{ + Entity *pEntity = new Entity(m_nextId++); + pEntity->SetName(sName); + m_Entities[pEntity->GetId()] = pEntity; + return pEntity->GetId(); +} + +bool EntitySystem::Destroy(AUEntityId id) +{ + TCESEntities::iterator it = m_Entities.find(id); + if (it != m_Entities.end()) + { + IAUEntity *pEntity = it->second; + delete pEntity; + m_Entities.erase(it); + return true; + } + + return false; +} + +IAUEntity * EntitySystem::Get(AUEntityId id) +{ + TCESEntities::iterator it = m_Entities.find(id); + if (it != m_Entities.end()) + { + return it->second; + } + + return NULL; +} + +IAUEntity * EntitySystem::Get(const char * sName) +{ + if (sName != NULL && *sName != '\0') + { + TCESEntities::iterator it = m_Entities.begin(); + TCESEntities::iterator itEnd = m_Entities.end(); + for (; it != itEnd; ++it) + { + if (!strcmp(it->second->GetName(), sName)) + { + return it->second; + } + } + } + + return NULL; +} + +void EntitySystem::GetAll(IAUDynArray &entities) const +{ + entities.Resize(m_Entities.size()); + TCESEntities::const_iterator it = m_Entities.begin(); + TCESEntities::const_iterator itEnd = m_Entities.end(); + for(int i = 0; it != itEnd; ++it, ++i) + { + entities[i] = it->second->m_id; + } +} + +void EntitySystem::Reset() +{ + AUDynArray entities; + GetAll(entities); + for (size_t i = 0; i < entities.Size(); ++i) + { + Destroy(entities[i]); + } + + assert(m_Entities.size() == 0); +} + + +EntitySystem::EntitySystem(void) : m_nextId(1) +{ +} + +EntitySystem::~EntitySystem(void) +{ +} + + diff --git a/3rdparty/RuntimeCompiledCpp/Systems/EntitySystem/EntitySystem.h b/3rdparty/RuntimeCompiledCpp/Systems/EntitySystem/EntitySystem.h new file mode 100644 index 0000000..51212d0 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/EntitySystem/EntitySystem.h @@ -0,0 +1,105 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#include "../IEntitySystem.h" + +#include + +class EntitySystem : public IEntitySystem +{ +public: + /// IEntitySystem methods + AUEntityId Create(const char * sName); + bool Destroy(AUEntityId id); + IAUEntity * Get(AUEntityId id); + IAUEntity * Get(const char * sName); + void GetAll(IAUDynArray &entities) const; + void Reset(); + + /// New methods + EntitySystem(void); + ~EntitySystem(void); + +protected: + class Entity : public IAUEntity + { + public: + AUEntityId m_id; + IEntityObject* m_pObject; + IAURenderable* m_pRenderable; + //IAUTransform * m_pTransform + IAUUpdateable* m_pUpdateable; + AUVec3f m_vPos; + AUVec3f m_vScale; + AUOrientation3D m_vOrientation; + + char m_sName[AU_ENTITY_NAME_LENGTH]; + + /// IAUEntity methods + + AUEntityId GetId() const { return m_id; } + + const char * GetName() const { return m_sName; } + void SetName(const char * _sName); + + const IEntityObject * GetObject() const { return m_pObject; } + IEntityObject * GetObject() { return m_pObject; } + void SetObject(IEntityObject *pObject); + + const IAURenderable * GetRenderable() const { return m_pRenderable; } + IAURenderable * GetRenderable() { return m_pRenderable; } + void SetRenderable(IAURenderable *pRender); + + const IAUUpdateable * GetUpdateable() const { return m_pUpdateable; } + IAUUpdateable * GetUpdateable() { return m_pUpdateable; } + void SetUpdateable(IAUUpdateable *pUpdateable); + + const AUVec3f& GetPosition() const { return m_vPos; } + AUVec3f& GetPosition() { return m_vPos; } + void SetPosition(const AUVec3f& vPos) { m_vPos = vPos; } + void SetPosition(float x, float y, float z) { m_vPos = AUVec3f(x, y, z); } + + const AUVec3f& GetScale() const { return m_vScale; } + AUVec3f& GetScale() { return m_vScale; } + void SetScale(const AUVec3f& vScale) { m_vScale = vScale; } + void SetScale(float fScale) { m_vScale = AUVec3f(fScale, fScale, fScale); } + + const AUOrientation3D& GetOrientation() const { return m_vOrientation; } + AUOrientation3D& GetOrientation() { return m_vOrientation; } + void SetOrientation(const AUOrientation3D& vOrientation) { m_vOrientation = vOrientation; } + void SetOrientation(float xForward, float yForward, float zForward, float xUp, float yUp, float zUp) + { + m_vOrientation = AUOrientation3D( AUVec3f(xForward, yForward, zForward), AUVec3f(xUp, yUp, zUp) ); + } + + /// New methods + + Entity(AUEntityId id) + : m_id(id) + , m_pRenderable(0) + , m_pUpdateable(0) + , m_vScale(1.0f, 1.0f, 1.0f) + , m_pObject( NULL ) + { m_sName[0] = '\n'; } + }; + + typedef std::map TCESEntities; + TCESEntities m_Entities; + AUEntityId m_nextId; +}; \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUIDocument.cpp b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUIDocument.cpp new file mode 100644 index 0000000..b23431a --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUIDocument.cpp @@ -0,0 +1,58 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "GUIDocument.h" +#include +#include + + +GUIDocument::GUIDocument(IGUIInstancer* pInstancer, Rocket::Core::ElementDocument* pDocument, bool bHoldingRLReference) + : GUIElement(pInstancer, pDocument, bHoldingRLReference) + , m_pDocument(pDocument) +{ + assert(m_pDocument); +} + +GUIDocument::~GUIDocument() +{ + +} + +IGUIElement* GUIDocument::Element() +{ + return this; +} + +void GUIDocument::Show() +{ + m_pDocument->Show(); +} + +void GUIDocument::Hide() +{ + m_pDocument->Hide(); +} + +void GUIDocument::AddReference() +{ + GUIElement::AddReference(); +} + +void GUIDocument::RemoveReference() +{ + GUIElement::RemoveReference(); +} diff --git a/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUIDocument.h b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUIDocument.h new file mode 100644 index 0000000..d923ac4 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUIDocument.h @@ -0,0 +1,51 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef GUIDOCUMENT_INCLUDED +#define GUIDOCUMENT_INCLUDED + +#include "../IGUIDocument.h" +#include "GUIElement.h" + +// Forward declare Rocket::Core::ElementDocument +namespace Rocket { namespace Core { class ElementDocument; } } + + +class GUIDocument : public GUIElement, public IGUIDocument +{ +public: + GUIDocument(IGUIInstancer* pInstancer, Rocket::Core::ElementDocument* pDocument, bool bHoldingRLReference); + ~GUIDocument(); + + // IGUIDocument + + virtual IGUIElement* Element(); + virtual void Show(); + virtual void Hide(); + + virtual void AddReference(); + virtual void RemoveReference(); + + // ~IGUIDocument + +private: + Rocket::Core::ElementDocument* m_pDocument; +}; + +#endif // GUIDOCUMENT_INCLUDED diff --git a/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUIElement.cpp b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUIElement.cpp new file mode 100644 index 0000000..70b4c5b --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUIElement.cpp @@ -0,0 +1,207 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "GUIElement.h" +#include "IGUIInstancer.h" + +#include +#include +#include +#include + +class GUIEvent : public IGUIEvent +{ +public: + GUIEvent( Rocket::Core::Event& event ) + : m_Event( event ) + { + } + virtual void GetParameter(const char* parameter, char* buffer, size_t buffer_size ) const + { + Rocket::Core::String strvalue = ""; + if( m_Event.GetParameters() ) + { + m_Event.GetParameters()->GetInto( parameter, strvalue ); + } + +#ifdef _WIN32 + strcpy_s( buffer, buffer_size, strvalue.CString() ); +#else + strncpy( buffer, strvalue.CString(), buffer_size); //not quite the same, but similar safe effect. +#endif + } +private: + Rocket::Core::Event& m_Event; +}; + +class EventHolder : public Rocket::Core::EventListener +{ +public: + static EventHolder* GetEventHolder( IGUIEventListener* pEvent ) + { + std::map::iterator found = m_EventListeners.find( pEvent ) ; + if( found != m_EventListeners.end() ) + { + return found->second; + } + else + { + return 0; + } + } + + EventHolder( IGUIEventListener* pEvent ) + : m_pEvent( pEvent ) + { + //there should be no events registered for this id + assert( m_EventListeners.find( pEvent ) == m_EventListeners.end()); + m_EventListeners[ pEvent ] = this; + } + ~EventHolder() + { + m_EventListeners.erase( m_pEvent ); + } + + + virtual void ProcessEvent(Rocket::Core::Event& event) + { + GUIEvent guiEvent( event ); + m_pEvent->OnEvent( guiEvent ); + } + + +private: + + EventHolder(); + EventHolder( EventHolder& event ); + EventHolder& operator=( EventHolder& event ); + + IGUIEventListener* m_pEvent; + + static std::map m_EventListeners; +}; +std::map EventHolder::m_EventListeners; + + + +GUIElement::GUIElement(IGUIInstancer* pInstancer, Rocket::Core::Element* pElement, bool bHoldingRLReference) + : m_pInstancer(pInstancer) + , m_pElement(pElement) + , m_bHoldingRLReference(bHoldingRLReference) +{ + assert(m_pInstancer && m_pElement); +} + +GUIElement::~GUIElement() +{ + if (m_bHoldingRLReference) + { + m_pElement->RemoveReference(); + } +} + +void GUIElement::AddReference() +{ + ReferenceCountable::AddReference(); +} + +void GUIElement::RemoveReference() +{ + ReferenceCountable::RemoveReference(); +} + +void GUIElement::OnReferenceDeactivate() +{ + m_pInstancer->Release(this); +} + +const char* GUIElement::GetId() const +{ + return m_pElement->GetId().CString(); +} + +void GUIElement::SetInnerRML(const char* content) +{ + m_pElement->SetInnerRML(content); +} + +void GUIElement::SetProperty(const char* name, const char* value) +{ + m_pElement->SetProperty(name, value); +} + +void GUIElement::GetAttribute(const char* attribute, char* buffer, size_t buffer_size ) const +{ + if( buffer_size && buffer ) + { + buffer[0] = 0; + Rocket::Core::Variant* pVar = m_pElement->GetAttribute(attribute); + if( pVar ) + { + Rocket::Core::String strvalue; + pVar->GetInto( strvalue ); +#ifdef _WIN32 + strcpy_s( buffer, buffer_size, strvalue.CString() ); +#else + strncpy( buffer, strvalue.CString(), buffer_size); //not quite the same, but similar safe effect. +#endif + } + } +} + +void GUIElement::SetAttribute(const char* name, const char* value) +{ + m_pElement->SetAttribute(name, value); +} + +float GUIElement::GetClientWidth() const +{ + return m_pElement->GetClientWidth(); +} + +float GUIElement::GetClientHeight() const +{ + return m_pElement->GetClientHeight(); +} + +IGUIElement* GUIElement::GetElementById(const char* id) +{ + Rocket::Core::Element* pElement = m_pElement->GetElementById(id); + if (pElement) + { + return m_pInstancer->InstanceElement(pElement, false); + } + + return NULL; +} + +void GUIElement::AddEventListener( const char* eventname, IGUIEventListener* pEventListener ) +{ + assert( m_pElement ); + EventHolder* pEvent = new EventHolder( pEventListener ); + m_pElement->AddEventListener( eventname, pEvent ); +} + +void GUIElement::RemoveEventListener( const char* eventname, IGUIEventListener* pEventListener) +{ + assert( m_pElement ); + EventHolder* pEvent = EventHolder::GetEventHolder( pEventListener ); + assert( pEvent ); + m_pElement->RemoveEventListener( eventname, pEvent ); + delete pEvent; + +} diff --git a/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUIElement.h b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUIElement.h new file mode 100644 index 0000000..47d25c1 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUIElement.h @@ -0,0 +1,70 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef GUIELEMENT_INCLUDED +#define GUIELEMENT_INCLUDED + +#include "../IGUIElement.h" +#include "ReferenceCountable.h" + +struct IGUIInstancer; + +// Forward declare Rocket::Core::Element +namespace Rocket { namespace Core { class Element; } } + + +class GUIElement : public ReferenceCountable, public IGUIElement +{ +public: + GUIElement(IGUIInstancer* pInstancer, Rocket::Core::Element* pElement, bool bHoldingRLReference); + virtual ~GUIElement(); + + // IGUIElement + + virtual const char* GetId() const; + virtual void SetInnerRML(const char* content); + virtual void SetProperty(const char* name, const char* value); + virtual IGUIElement* GetElementById(const char* id); + virtual void GetAttribute(const char* attribute, char* buffer, size_t buffer_size ) const; + virtual void SetAttribute(const char* name, const char* value); + virtual float GetClientWidth() const; + virtual float GetClientHeight() const; + + virtual void AddReference(); + virtual void RemoveReference(); + + virtual void AddEventListener( const char* eventname, IGUIEventListener* pEventListener ); + virtual void RemoveEventListener( const char* eventname, IGUIEventListener* pEventListener ); + + // ~IGUIElement + +protected: + // ReferenceCountable + + virtual void OnReferenceDeactivate(); + + // ~ReferenceCountable + +private: + Rocket::Core::Element* m_pElement; + IGUIInstancer* m_pInstancer; + bool m_bHoldingRLReference; +}; + +#endif // GUIELEMENT_INCLUDED diff --git a/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUISystem.cpp b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUISystem.cpp new file mode 100644 index 0000000..45e123b --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUISystem.cpp @@ -0,0 +1,132 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "GUISystem.h" +#include "GUIElement.h" +#include "GUIDocument.h" + +#include +#include +#include + + +GUISystem::GUISystem() : m_pContext(0) +{ +} + +GUISystem::~GUISystem() +{ + TInstancedElements::iterator it = m_instanced.begin(); + TInstancedElements::iterator itEnd = m_instanced.end(); + while (it != itEnd) + { + delete *it; + ++it; + } +} + +void GUISystem::SetContext(Rocket::Core::Context* pContext) +{ + m_pContext = pContext; + assert(m_pContext); +} + +void GUISystem::ClearStyleSheetCache() +{ + Rocket::Core::Factory::ClearStyleSheetCache(); +} + +IGUIDocument* GUISystem::LoadDocument(const char* file, const char* id) +{ + assert(m_pContext); + + // Check for an existing document with this ID + Rocket::Core::ElementDocument* pExisting = m_pContext->GetDocument(id); + + Rocket::Core::ElementDocument* pED = m_pContext->LoadDocument(file); + if (pED) + { + if (pExisting) + { + // Delete existing document now that new one has been successfully loaded + pExisting->Hide(); + m_pContext->UnloadDocument(pExisting); + } + + pED->SetId(id); + return InstanceDocument(pED, true); + } + + return NULL; +} + +IGUIDocument* GUISystem::GetDocument(const char* id) +{ + assert(m_pContext); + + Rocket::Core::ElementDocument* pED = m_pContext->GetDocument(id); + if (pED) + { + return InstanceDocument(pED, false); + } + + return NULL; +} + +IGUIElement* GUISystem::GetLogElement() +{ + Rocket::Core::Element* pElement = Rocket::Debugger::GetLogElement(); + if (pElement) + { + return InstanceElement(pElement, false); + } + + return NULL; +} + +GUIElement* GUISystem::InstanceElement(Rocket::Core::Element* pElement, bool bHoldingRLReference) +{ + GUIElement* pGUIElement = new GUIElement(this, pElement, bHoldingRLReference); + + m_instanced.insert(pGUIElement); + + return pGUIElement; +} + +GUIDocument* GUISystem::InstanceDocument(Rocket::Core::ElementDocument* pDocument, bool bHoldingRLReference) +{ + GUIDocument* pGUIDocument = new GUIDocument(this, pDocument, bHoldingRLReference); + + m_instanced.insert(pGUIDocument); + + return pGUIDocument; +} + +void GUISystem::Release(GUIElement* pElement) +{ + GUIElement* pGUIElement = static_cast(pElement); + + TInstancedElements::iterator it = m_instanced.find(pGUIElement); + assert(it != m_instanced.end()); + if (it != m_instanced.end()) + { + delete *it; + m_instanced.erase(it); + } +} + + diff --git a/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUISystem.h b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUISystem.h new file mode 100644 index 0000000..f7f9b6c --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/GUISystem.h @@ -0,0 +1,67 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef GUISYSTEM_INCLUDED +#define GUISYSTEM_INCLUDED + +#include "../IGUISystem.h" +#include "IGUIInstancer.h" +#include + +// Forward declare Rocket::Core::Context +namespace Rocket { namespace Core { class Context; } } + +class GUIElement; +class GUIDocument; + + +class GUISystem : public IGUISystem, public IGUIInstancer +{ +public: + GUISystem(); + ~GUISystem(); + + // IGUISystem + + virtual void SetContext(Rocket::Core::Context* pContext); + virtual void ClearStyleSheetCache(); + virtual IGUIDocument* LoadDocument(const char* file, const char* id); + virtual IGUIDocument* GetDocument(const char* id); + virtual IGUIElement* GetLogElement(); + + // ~IGUISystem + + // IGUIInstancer + + virtual GUIElement* InstanceElement(Rocket::Core::Element* pElement, bool bHoldingRLReference); + virtual GUIDocument* InstanceDocument(Rocket::Core::ElementDocument* pDocument, bool bHoldingRLReference); + + virtual void Release(GUIElement* pElement); + + // ~IGUIInstancer + +private: + + typedef std::set TInstancedElements; + + Rocket::Core::Context* m_pContext; + TInstancedElements m_instanced; +}; + +#endif // GUISYSTEM_INCLUDED diff --git a/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/IGUIInstancer.h b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/IGUIInstancer.h new file mode 100644 index 0000000..cb4186a --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/IGUIInstancer.h @@ -0,0 +1,41 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef IGUIINSTANCER_INCLUDED +#define IGUIINSTANCER_INCLUDED + +// Forward declare Rocket::Core::Element +namespace Rocket { namespace Core { class Element; } } + +// Forward declare Rocket::Core::ElementDocument +namespace Rocket { namespace Core { class ElementDocument; } } + +class GUIElement; +class GUIDocument; + + +struct IGUIInstancer +{ + virtual GUIElement* InstanceElement(Rocket::Core::Element* pElement, bool bHoldingRLReference) = 0; + virtual GUIDocument* InstanceDocument(Rocket::Core::ElementDocument* pDocument, bool bHoldingRLReference) = 0; + + virtual void Release(GUIElement* pElement) = 0; +}; + +#endif // IGUIINSTANCER_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/ReferenceCountable.cpp b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/ReferenceCountable.cpp new file mode 100644 index 0000000..650c6b6 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/ReferenceCountable.cpp @@ -0,0 +1,70 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "ReferenceCountable.h" +#include + + +ReferenceCountable::ReferenceCountable(int initial_count /* = 1 */) : m_refCount(initial_count) +{ + +} + +ReferenceCountable::~ReferenceCountable() +{ + assert(m_refCount == 0); +} + +int ReferenceCountable::GetReferenceCount() +{ + return m_refCount; +} + +void ReferenceCountable::AddReference() +{ + ++m_refCount; + if (m_refCount == 1) + { + OnReferenceActivate(); + } +} + +void ReferenceCountable::RemoveReference() +{ + assert(m_refCount > 0); + --m_refCount; + if (m_refCount == 0) + { + OnReferenceDeactivate(); + } +} + +ReferenceCountable& ReferenceCountable::operator=(const ReferenceCountable&) +{ + assert(false && "attempting to copy reference countable object. Not a good idea!"); + return *this; +} + +void ReferenceCountable::OnReferenceActivate() +{ + // Hook method +} + +void ReferenceCountable::OnReferenceDeactivate() +{ + // Hook method +} \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/ReferenceCountable.h b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/ReferenceCountable.h new file mode 100644 index 0000000..c18e79c --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/GUISystem/ReferenceCountable.h @@ -0,0 +1,49 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef REFERENCECOUNTABLE_INCLUDED +#define REFERENCECOUNTABLE_INCLUDED + +// Based on libRocket ReferenceCountable class + + +class ReferenceCountable +{ +public: + ReferenceCountable(int initial_count = 1); + virtual ~ReferenceCountable(); + + virtual int GetReferenceCount(); + virtual void AddReference(); + virtual void RemoveReference(); + + // Catches incorrect copy attempts + ReferenceCountable& operator=(const ReferenceCountable& copy); + +protected: + // Hook method for when reference count climbs above zero + virtual void OnReferenceActivate(); + // Hook method for when reference count hits zero + virtual void OnReferenceDeactivate(); + +private: + int m_refCount; +}; + +#endif // REFERENCECOUNTABLE_INCLUDED diff --git a/3rdparty/RuntimeCompiledCpp/Systems/IAssetSystem.h b/3rdparty/RuntimeCompiledCpp/Systems/IAssetSystem.h new file mode 100644 index 0000000..14d4d1f --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/IAssetSystem.h @@ -0,0 +1,35 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + + +#ifndef IASSETSYSTEM_INCLUDED +#define IASSETSYSTEM_INCLUDED + +#include "Definitions.inl" + +struct IAssetSystem +{ + virtual IAURenderableMesh* CreateRenderableMeshFromFile( const char* pFilename ) = 0; + virtual void DestroyRenderableMesh(IAURenderableMesh* pMesh) = 0; // needed so memory allocation and deletion happens in same DLL + + virtual const char* GetAssetDirectory() const = 0; + virtual ~IAssetSystem() {} +}; + +#endif //IASSETSYSTEM_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/IEntity.h b/3rdparty/RuntimeCompiledCpp/Systems/IEntity.h new file mode 100644 index 0000000..6e2d34f --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/IEntity.h @@ -0,0 +1,72 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef IAUENTITY_INCLUDED +#define IAUENTITY_INCLUDED + +#include "Definitions.inl" +#include "../Common/AUOrientation3D.inl" +#include "../Common/AUVec3f.inl" + +#define AU_ENTITY_NAME_LENGTH 32 + +class IEntityObject; + +struct IAUEntity +{ + virtual AUEntityId GetId() const = 0; + + virtual const char * GetName() const = 0; // May return empty string, never NULL + virtual void SetName(const char * sName) = 0; // Up to AU_ENTITY_NAME_LENGTH - 1 bytes plus null terminator, or NULL + + //virtual const IPhysics * GetPhysics() const = 0; + //virtual IPhysics * GetPhysics() = 0; + //virtual void SetPhysics(IPhysics *pPhysics) = 0; + + virtual const IEntityObject * GetObject() const = 0; + virtual IEntityObject * GetObject() = 0; + virtual void SetObject(IEntityObject *pObject) = 0; + + virtual const IAURenderable * GetRenderable() const = 0; + virtual IAURenderable * GetRenderable() = 0; + virtual void SetRenderable(IAURenderable *pRenderable) = 0; + + virtual const IAUUpdateable * GetUpdateable() const = 0; + virtual IAUUpdateable * GetUpdateable() = 0; + virtual void SetUpdateable(IAUUpdateable *pUpdateable) = 0; + + virtual const AUVec3f& GetPosition() const = 0; + virtual AUVec3f& GetPosition() = 0; + virtual void SetPosition(const AUVec3f& vPos) = 0; + virtual void SetPosition(float x, float y, float z) = 0; + + virtual const AUVec3f& GetScale() const = 0; + virtual AUVec3f& GetScale() = 0; + virtual void SetScale(const AUVec3f& vScale) = 0; + virtual void SetScale(float fScale) = 0; + + virtual const AUOrientation3D& GetOrientation() const = 0; + virtual AUOrientation3D& GetOrientation() = 0; + virtual void SetOrientation(const AUOrientation3D& vOrientation) = 0; + virtual void SetOrientation(float xForward, float yForward, float zForward, float xUp, float yUp, float zUp) = 0; + + virtual ~IAUEntity() {} +}; + +#endif // IAUENTITY_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/IEntitySystem.h b/3rdparty/RuntimeCompiledCpp/Systems/IEntitySystem.h new file mode 100644 index 0000000..104ecdf --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/IEntitySystem.h @@ -0,0 +1,55 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef IENTITYSYSTEM_INCLUDED +#define IENTITYSYSTEM_INCLUDED + +// What is an entity? +// I define it to be the glue that holds all the useful components that might be present together +// Position seems somehow special. Lots of things care about positions and positions without physics can make sense. +// Entities include static geometry, Pneumata, some interface elements? + + +#include "../Common/AUVec3f.inl" +#include "../RuntimeCompiler/AUArray.h" +#include "ISystem.h" +#include "IEntity.h" + +#include + + +struct IEntitySystem : public ISystem +{ + /// ISystem interface + //SErrorDescriptor UnitTest(ILogSystem *pLog); // Giving a logger is optional + + /// New methods + virtual ~IEntitySystem() {}; + + virtual void Reset() = 0; + + // Consider renaming with Entity in there? + virtual AUEntityId Create(const char * sName = NULL) = 0; // Create a new, empty entity of this type + virtual bool Destroy(AUEntityId nId) = 0; // Cleanup and destroy an existing entity. Returns false iff no such id. + virtual IAUEntity * Get(AUEntityId id) = 0; + virtual IAUEntity * Get(const char * sName) = 0; // Get first entity that matches this name (not sure if we want to enforce name uniqueness?) + virtual void GetAll(IAUDynArray &entities) const = 0; +}; + +#endif // IENTITYSYSTEM_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/IGUIDocument.h b/3rdparty/RuntimeCompiledCpp/Systems/IGUIDocument.h new file mode 100644 index 0000000..4e8b630 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/IGUIDocument.h @@ -0,0 +1,37 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef IGUIDOCUMENT_INCLUDED +#define IGUIDOCUMENT_INCLUDED + +struct IGUIElement; + + +struct IGUIDocument +{ + virtual IGUIElement* Element() = 0; // access IGUIElement interface, doesn't add a reference + virtual void Show() = 0; + virtual void Hide() = 0; + + // Reference counting + virtual void AddReference() = 0; + virtual void RemoveReference() = 0; +}; + +#endif // IGUIDOCUMENT_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/IGUIElement.h b/3rdparty/RuntimeCompiledCpp/Systems/IGUIElement.h new file mode 100644 index 0000000..ec2fd00 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/IGUIElement.h @@ -0,0 +1,128 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef IGUIELEMENT_INCLUDED +#define IGUIELEMENT_INCLUDED + +#include "IGUIDocument.h" +#include + +struct IGUIEvent +{ + virtual ~IGUIEvent() {} + virtual void GetParameter(const char* parameter, char* buffer, size_t buffer_size ) const = 0; +}; + +struct IGUIEventListener +{ + virtual ~IGUIEventListener() {} + virtual void OnEvent( const IGUIEvent& event_info ) = 0; +}; + +struct IGUIElement +{ +public: + virtual ~IGUIElement() {} + + virtual const char* GetId() const = 0; + virtual void SetInnerRML(const char* content) = 0; + virtual void SetProperty(const char* name, const char* value) = 0; + virtual IGUIElement* GetElementById(const char* id) = 0; + virtual void GetAttribute(const char* attribute, char* buffer, size_t buffer_size ) const = 0; + virtual void SetAttribute(const char* name, const char* value) = 0; + virtual float GetClientWidth() const = 0; + virtual float GetClientHeight() const = 0; + + // Reference counting + virtual void AddReference() = 0; + virtual void RemoveReference() = 0; + + // Add an event listener + virtual void AddEventListener( const char* pName, IGUIEventListener* pEventListener ) = 0; + + // Remove an event listener + virtual void RemoveEventListener( const char* pName, IGUIEventListener* pEventListener ) = 0; +}; + +// IGUISingleEventListener can only listen to single events, but has auto removal for easy usuage +class IGUISingleEventListener : public IGUIEventListener +{ + char* m_pEventname; + IGUIElement* m_pElement; + +public: + IGUISingleEventListener( ) + : m_pEventname( 0 ) + , m_pElement( 0 ) + { + } + + const char* GetName() + { + return m_pEventname; + } + + IGUIElement* GetElement() + { + return m_pElement; + } + + void AddEventToElementInDoc( const char* pEventname, const char* pElementname_, IGUIDocument* pDocument ) + { + IGUIElement* pElement = pDocument->Element()->GetElementById( pElementname_ ); + if( pElement ) + { + AddEventToElement( pEventname, pElement ); + pElement->RemoveReference(); // a ref is added in addevent + } + } + + + // AddEventToElement adds a reference to pElement which it will remove when the + // event is deleted or RemoveEvent is called. + void AddEventToElement( const char* pEventname, IGUIElement* pElement ) + { + RemoveEvent(); + m_pEventname = new char[ strlen( pEventname ) + 1 ]; + strcpy( m_pEventname, pEventname ); + m_pElement = pElement; + m_pElement->AddReference(); + m_pElement->AddEventListener( m_pEventname, this ); + } + + void RemoveEvent() + { + if( m_pElement ) + { + m_pElement->RemoveEventListener( m_pEventname, this ); + m_pElement->RemoveReference(); + m_pElement = 0; + delete[] m_pEventname; + m_pEventname = 0; + } + } + + virtual ~IGUISingleEventListener() + { + RemoveEvent(); + } + +}; + +#endif // IGUIELEMENT_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/IGUISystem.h b/3rdparty/RuntimeCompiledCpp/Systems/IGUISystem.h new file mode 100644 index 0000000..9845ea8 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/IGUISystem.h @@ -0,0 +1,47 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef IGUISYSTEM_INCLUDED +#define IGUISYSTEM_INCLUDED + +// Simple wrapper around libRocket to provide basic functionality to entities that need to +// manipulate the GUI. Quite barebones for now, and we can add specific features as needed + +#include "ISystem.h" +#include "IGUIDocument.h" +#include "IGUIElement.h" + +// Forward declare Rocket::Core::Context +namespace Rocket { namespace Core { class Context; } } + + +struct IGUISystem : public ISystem +{ + //// ISystem methods + //SErrorDescriptor UnitTest(ILogSystem *pLog); + + virtual void SetContext(Rocket::Core::Context* pContext) = 0; + virtual void ClearStyleSheetCache() = 0; + + virtual IGUIDocument* LoadDocument(const char* file, const char* id) = 0; + virtual IGUIDocument* GetDocument(const char* id) = 0; + virtual IGUIElement* GetLogElement() = 0; +}; + +#endif // IGUISYSTEM_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/IGame.h b/3rdparty/RuntimeCompiledCpp/Systems/IGame.h new file mode 100644 index 0000000..5887d4d --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/IGame.h @@ -0,0 +1,39 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef IGAME_INCLUDED +#define IGAME_INCLUDED + +#include "ISystem.h" + +// IGame Interface +// Contains game functions games should override +struct IGame : public ISystem +{ + virtual void Reset() = 0; + virtual void Restart() = 0; + virtual void ToggleConsoleGUI() = 0; + virtual void Exit() = 0; + virtual void GetWindowSize( float& width, float& height ) const = 0; + virtual void RunRCCppTests( bool bTestFileTracking ) = 0; + + virtual void SetSpeed( float speed ) = 0; +}; + +#endif //IGAME_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/ILogSystem.h b/3rdparty/RuntimeCompiledCpp/Systems/ILogSystem.h new file mode 100644 index 0000000..a7222a2 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/ILogSystem.h @@ -0,0 +1,94 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef ILOGSYSTEM_INCLUDED +#define ILOGSYSTEM_INCLUDED + +// I'm not sure if testing the log system makes much sense +// Might be room for a super-verbose debugging log level +// This might genuinely be worth multithreaded +// Differing file/console later. Console buffer later. +// note that eLV_ is probably the thing to grep for, if we insist it must be specified. + +// Add a way to set a callback function that can be used to generate prefixes - in this case frame and time +// a flush might be a useful addition, or two modes, one of which will always flush, and some catch on exit() that will ensure it gets output? + +// The log system is an exception to orthogonality in that it can be passed into UnitTest methods that exist in all other systems. +// Without it, we could not report where our systems were going wrong in a consistent manner. This is part of the reason why ILogSystem +// does _not_ have a proper UnitTest method and instead relies upon external examination. + +//#include "Settings.h" +#include "ISystem.h" +#include // Only simple definitions + +static const int LOGSYSTEM_MAX_BUFFER = 4096; + +enum ELogVerbosity +{ + eLV_NEVER, // Never output, always ignore + eLV_ERRORS, // Only output when broken + eLV_WARNINGS, // ... and output when suspicious + eLV_EVENTS, // ... and output events considered "highest-level" for this system + eLV_COMMENTS, // ... and output everything else that we're doing +}; + +struct ILogSystem : public ISystem +{ +public: + //// ISystem methods + //virtual SErrorDescriptor UnitTest(ILogSystem *pLog) = 0; // Unit testing a logger is awkward - we delegate it + + //// New methods + virtual ~ILogSystem() {}; + + typedef const ELogVerbosity * const TVerbosityPeeker; + + virtual ELogVerbosity GetVerbosity() const = 0; // Get currently set verbosity level + virtual void SetVerbosity(ELogVerbosity eVerbosity) = 0; // Set verbosity level. Defaults to eLV_EVENTS + virtual TVerbosityPeeker GetVerbosityPeeker() const = 0; // Get a pointer to the current verbosity level to store and use for fast "peek" with no function call + // Remains valid for the lifetime of the log instance + + // Log a message with given minimum verbosity level and printf syntax + virtual void Log(ELogVerbosity eVerbosity, const char * format, ...) = 0; + // Log a message with given minimum verbosity level taking a va_list - used when wrapping this logging and re-exposing as printf syntax + // Argument order is chosen to make it harder to accidentally call the variadic version + virtual void LogVa(va_list args, ELogVerbosity eVerbosity, const char * format) = 0; +}; + + + +// Allow avoiding debug code, allow compiling it out, etc. +// Note there are apparently some variations for varaiadic macros - GCC etc. + +#ifndef PN_LOG_LEVEL + #define PN_LOG_LEVEL eLV_COMMENTS +#endif + +#define PN_LOG(env,level,format,...) \ + if ( (level) <= PN_LOG_LEVEL ) {(env)->sys->pLogSystem->Log((level),(format),__VA_ARGS__);} + +#define PN_LOG_EXT(env,level,code_block,format,...) \ + if ( (level) <= PN_LOG_LEVEL ) \ + { \ + code_block ; \ + (env)->sys->pLogSystem->Log((level),(format),__VA_ARGS__); \ + } + + +#endif //ILOGSYSTEM_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/ISystem.h b/3rdparty/RuntimeCompiledCpp/Systems/ISystem.h new file mode 100644 index 0000000..47a9ab9 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/ISystem.h @@ -0,0 +1,41 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef ISYSTEM_INCLUDED +#define ISYSTEM_INCLUDED + +// Skeleton of common interface across all system interfaces +// Should eventually encompass memory statistics etc + +// Some kind of virtual constructor... is perhaps the tricky bit. Best left out actually, to allow for multiple implementations +// Update? + +// Constructors of systems can't fail, but init can fail, returning an error code +// virtual SErrorDescriptor Init() {}; Should this be compulsory? Or does it always need different parameters? + +//#include "Definitions.h" + +struct ISystem +{ + //virtual SErrorDescriptor UnitTest(ILogSystem *pLog = NULL) = 0; // Giving a logger is optional + //virtual SErrorDescriptor Shutdown() { return PN_NO_ERROR; }; // Shutdown to clean state that could be reinitialised + virtual ~ISystem() {}; // Destroy the system +}; + +#endif //ISYSTEM_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/ITimeSystem.h b/3rdparty/RuntimeCompiledCpp/Systems/ITimeSystem.h new file mode 100644 index 0000000..3f0a1fd --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/ITimeSystem.h @@ -0,0 +1,61 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef ITIMESYSTEM_INCLUDED +#define ITIMESYSTEM_INCLUDED + +// Could all systems share an core interface? +// Some kind of virtual constructor... is perhaps the tricky bit. Best left out actually, to allow for multiple implementations +// Destructor, update, unit test, seem plausible. maybe other things? +// Could this help simplify some code? +// What happens to the time between frames? If it counts towards session time but not the time the last frame took, is that inconsistent? +// Is it more or less correct to call last frame time the time between frames? + +#include "ISystem.h" + +struct ITimeSystem : public ISystem +{ + //// ISystem methods + //SErrorDescriptor UnitTest(ILogSystem *pLog); + + //// New methods + virtual void StartSession() = 0; // Universe begins. Nothing that happened before matters. + virtual void EndSession() = 0; // Universe ends. Time ceases to exist. + + virtual void StartFrame() = 0; // We're starting a new frame. Our integration of time in finite steps started a step here. + virtual void EndFrame() = 0; // We're ending a frame. A step is complete. No effect on behaviour except that StartFrame may be called. + + virtual bool IsPaused() const = 0; // Are we paused for our current frame? + virtual void Pause(bool bPause) = 0; // Set whether this frame should be considered a paused one. + // Do this between frames to avoid terrible confusion and indeed assertions. + + virtual double GetFramePlayTime() const = 0; // How much unpaused time had elapsed when we started the frame? + virtual double GetFrameSessionTime() const = 0; // How much total time had elapsed when we started the frame? + + // Rename Frame/Now? + virtual double GetPlayTimeNow() const = 0; // Get unpaused time elapsed this very moment + virtual double GetSessionTimeNow() const = 0; // Get total time elapsed this very moment + virtual double GetFrameTimeNow() const = 0; // How long has this frame taken so far, this very moment + + virtual double GetLastFrameDuration() const = 0; // How long did the last frame actually take? + virtual double GetSmoothFrameDuration() const = 0; // How long do we guess this frame will take? + +}; + +#endif // ITIMESYSTEM_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/IUpdateable.h b/3rdparty/RuntimeCompiledCpp/Systems/IUpdateable.h new file mode 100644 index 0000000..d0e2bfe --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/IUpdateable.h @@ -0,0 +1,28 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef IAUUPDATEABLE_INCLUDED +#define IAUUPDATEABLE_INCLUDED + +struct IAUUpdateable +{ + virtual void Update( float deltaTime ) = 0; +}; + +#endif // IAUUPDATEABLE_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/FileLogSystem/FileLogSystem.cpp b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/FileLogSystem/FileLogSystem.cpp new file mode 100644 index 0000000..721d18b --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/FileLogSystem/FileLogSystem.cpp @@ -0,0 +1,103 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "FileLogSystem.h" + +// Currently we create the file on first real output, and only close it on shutdown + +#include +#include + +#pragma warning( disable : 4996 4800 ) + + +FileLogSystem::FileLogSystem(void) +{ + m_fp = NULL; + m_eVerbosity = eLV_EVENTS; +} + +FileLogSystem::~FileLogSystem(void) +{ + CloseFile(); +} + +bool FileLogSystem::SetLogPath( const char * sPath, bool bTest ) +{ + m_sPath = sPath; + + if (!bTest) return true; + if (!OpenFile()) return false; + if (!CloseFile()) return false; + + return true; +} + +ELogVerbosity FileLogSystem::GetVerbosity() const +{ + return m_eVerbosity; +} + +void FileLogSystem::SetVerbosity(ELogVerbosity eVerbosity) +{ + m_eVerbosity = eVerbosity; +} + +FileLogSystem::TVerbosityPeeker FileLogSystem::GetVerbosityPeeker() const +{ + return (&m_eVerbosity); +} + +void FileLogSystem::Log(ELogVerbosity eVerbosity, const char * format, ...) +{ + va_list args; + va_start(args, format); + LogInternal(eVerbosity, format, args); +} + +void FileLogSystem::LogVa(va_list args, ELogVerbosity eVerbosity, const char * format) +{ + LogInternal(eVerbosity, format, args); +} + +void FileLogSystem::LogInternal(ELogVerbosity eVerbosity, const char * format, va_list args) +{ + if (eVerbosity > m_eVerbosity || eVerbosity == eLV_NEVER) return; + + if (!m_fp) OpenFile(); + if (!m_fp) return; + + int result = vsnprintf(m_buff, LOGSYSTEM_MAX_BUFFER-1, format, args); + // Make sure there's a limit to the amount of rubbish we can output + m_buff[LOGSYSTEM_MAX_BUFFER-1] = '\0'; + fprintf(m_fp, "%s", m_buff); + fflush(m_fp); +} + +bool FileLogSystem::OpenFile() +{ + m_fp = fopen(m_sPath.c_str(),"wt"); + return m_fp; +} + +bool FileLogSystem::CloseFile() +{ + if (!m_fp) return false; + bool bResult = fclose(m_fp); + m_fp = NULL; + return bResult; +} diff --git a/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/FileLogSystem/FileLogSystem.h b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/FileLogSystem/FileLogSystem.h new file mode 100644 index 0000000..216079d --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/FileLogSystem/FileLogSystem.h @@ -0,0 +1,73 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef FILELOGSYSTEM_INCLUDED +#define FILELOGSYSTEM_INCLUDED + +#include "../../ILogSystem.h" + +#include +#include + +// This implementation logs to files only +// When created, it has no files to log to, it must be set + +// Hmm. Would be useful to output the error level of the line, for later filtering. +// And the pretty printing and so on... was thinking of pasing in a callback wasn't I? + +// Might make file flushing optional, and/or get this onto a different thread for performance + +class FileLogSystem : public ILogSystem +{ +public: + //// ILogSystem interface + //SErrorDescriptor UnitTest(ILogSystem *) + // { return SErrorDescriptor(); } // Very awkward to unit test this implementation + + //// Unique to this implementation + + // Could become Init(...) ? + bool SetLogPath( const char * sPath, bool bTest = false ); // Set path of file to use for logging. bTest = true will cause it to try to create and delete the file. + // Test could be useful - but why not separate function? + + FileLogSystem(void); + ~FileLogSystem(void); + + ELogVerbosity GetVerbosity() const; + void SetVerbosity(ELogVerbosity eVerbosity); + TVerbosityPeeker GetVerbosityPeeker() const; + + void Log(ELogVerbosity eVerbosity, const char * format, ...); + void LogVa(va_list args, ELogVerbosity eVerbosity, const char * format); + // Returns false iff a test was attempted and failed. + + +protected: + void LogInternal(ELogVerbosity eVerbosity, const char * format, va_list args); + bool OpenFile(); + bool CloseFile(); + + std::string m_sPath; + ELogVerbosity m_eVerbosity; + FILE *m_fp; + char m_buff[LOGSYSTEM_MAX_BUFFER]; +}; + + +#endif //FILELOGSYSTEM_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/MultiLogSystem/MultiLogSystem.cpp b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/MultiLogSystem/MultiLogSystem.cpp new file mode 100644 index 0000000..3ae3d64 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/MultiLogSystem/MultiLogSystem.cpp @@ -0,0 +1,106 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +// Notes: +// - Might actually make sense to perform the printf once for performance reasons. +// This would probably end up in having a char* form. But wait until its needed. + + +#include "MultiLogSystem.h" + +#include +#include + +#pragma warning( disable : 4996 4800 ) + + +MultiLogSystem::MultiLogSystem(void) +{ + m_eVerbosity = eLV_COMMENTS; // By default, defer any filtering +} + +MultiLogSystem::~MultiLogSystem(void) +{ + for (unsigned int i=0; i m_eVerbosity || eVerbosity == eLV_NEVER) return; + // Possible bug here in all loggers - should also check against "compile out" value + + for (unsigned int i=0; iLogVa(args, eVerbosity, format); +#else + // May need to use a copy + va_list copyArgs; + va_copy(copyArgs, args); + m_logSystems[i]->LogVa(copyArgs, eVerbosity, format); +#endif + } +} diff --git a/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/MultiLogSystem/MultiLogSystem.h b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/MultiLogSystem/MultiLogSystem.h new file mode 100644 index 0000000..d042f4e --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/MultiLogSystem/MultiLogSystem.h @@ -0,0 +1,64 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef MULTILOGSYSTEM_INCLUDED +#define MULTILOGSYSTEM_INCLUDED + +#include "../../ILogSystem.h" +#include + +class MultiLogSystem : public ILogSystem +{ +public: + //// ILogSystem interface + //SErrorDescriptor UnitTest(ILogSystem *) + // { return SErrorDescriptor(); } + + //// New class methods + + MultiLogSystem(void); + + // Destroy this instance and all currently added log instances + ~MultiLogSystem(void); + + // Add a log system instance to the list, if not already present + // Returns true if instance was added + bool AddLogSystem(ILogSystem *pLogSystem); + // Remove a log system instance from the list + // Returns true if found. Does not destroy the instance + bool RemoveLogSystem(ILogSystem *pLogSystem); + + //// ILogSystem interface + + ELogVerbosity GetVerbosity() const; + void SetVerbosity(ELogVerbosity eVerbosity); + TVerbosityPeeker GetVerbosityPeeker() const; + + void Log(ELogVerbosity eVerbosity, const char * format, ...); + void LogVa(va_list args, ELogVerbosity eVerbosity, const char * format); + +protected: + void LogInternal(ELogVerbosity eVerbosity, const char * format, va_list args); + + ELogVerbosity m_eVerbosity; + std::vector m_logSystems; +}; + + +#endif //MULTILOGSYSTEM_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/RocketLogSystem/RocketLogSystem.cpp b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/RocketLogSystem/RocketLogSystem.cpp new file mode 100644 index 0000000..047438c --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/RocketLogSystem/RocketLogSystem.cpp @@ -0,0 +1,147 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "RocketLogSystem.h" + +#include +#include +#include +#include + + + +#pragma warning( disable : 4996 4800 ) + + +struct RocketLogSystem::RLSPlatformImpl +{ + std::vector messageTypes; +}; + +RocketLogSystem::RocketLogSystem(void) +{ + m_pImpl = new RLSPlatformImpl(); + + m_buffIndex = 0; // Start at 0 messages, start of buffer + m_buff[0] = '\0'; + + m_eVerbosity = eLV_COMMENTS; // By default, defer any filtering +} + +RocketLogSystem::~RocketLogSystem(void) +{ + delete m_pImpl; +} + +void RocketLogSystem::Push(void) +{ + + int count = (int)m_pImpl->messageTypes.size(); + + // Make sure there's a limit to the amount of rubbish we can output + m_buff[BUFF_SIZE-1] = '\0'; + + Rocket::Core::SystemInterface *pRocketSystemInterface = Rocket::Core::GetSystemInterface(); + if (!pRocketSystemInterface) + goto Cleanup; + + { + int msgStart=0; + int msgEnd=0; + for (int i=0; iLogMessage(m_pImpl->messageTypes[i], &m_buff[msgStart]); + msgEnd++; + msgStart = msgEnd; + } + } + +Cleanup: + m_buffIndex = 0; + m_buff[0] = '\0'; + m_pImpl->messageTypes.clear(); +} + + +ELogVerbosity RocketLogSystem::GetVerbosity() const +{ + return m_eVerbosity; +} + +void RocketLogSystem::SetVerbosity(ELogVerbosity eVerbosity) +{ + m_eVerbosity = eVerbosity; +} + +RocketLogSystem::TVerbosityPeeker RocketLogSystem::GetVerbosityPeeker() const +{ + return (&m_eVerbosity); +} + +void RocketLogSystem::Log(ELogVerbosity eVerbosity, const char * format, ...) +{ + va_list args; + va_start(args, format); + LogInternal(eVerbosity, format, args); +} + +void RocketLogSystem::LogVa(va_list args, ELogVerbosity eVerbosity, const char * format) +{ + LogInternal(eVerbosity, format, args); +} + +void RocketLogSystem::LogInternal(ELogVerbosity eVerbosity, const char * format, va_list args) +{ + if (eVerbosity > m_eVerbosity || eVerbosity == eLV_NEVER) return; + // Possible bug here in all loggers - should also check against "compile out" value + + // If there may not be space - throw away this message + if (BUFF_SIZE - m_buffIndex < LOGSYSTEM_MAX_BUFFER) + { + return; + } + + Rocket::Core::Log::Type rocketVerbosity; + switch (eVerbosity) + { + case eLV_ERRORS: rocketVerbosity = Rocket::Core::Log::LT_ERROR; break; + case eLV_WARNINGS: rocketVerbosity = Rocket::Core::Log::LT_WARNING; break; + case eLV_EVENTS: rocketVerbosity = Rocket::Core::Log::LT_INFO; break; + case eLV_COMMENTS: rocketVerbosity = Rocket::Core::Log::LT_DEBUG; break; + default: + assert(false); + } + + int result = vsnprintf(&m_buff[m_buffIndex], LOGSYSTEM_MAX_BUFFER-1, format, args); + // Make sure there's a limit to the amount of rubbish we can output + m_buff[m_buffIndex+LOGSYSTEM_MAX_BUFFER-1] = 0; + + m_buffIndex += result + 1; + m_pImpl->messageTypes.push_back(rocketVerbosity); +} \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/RocketLogSystem/RocketLogSystem.h b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/RocketLogSystem/RocketLogSystem.h new file mode 100644 index 0000000..d7dde11 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/RocketLogSystem/RocketLogSystem.h @@ -0,0 +1,71 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef ROCKETLOGSYSTEM_INCLUDED +#define ROCKETLOGSYSTEM_INCLUDED + +#include "../../ILogSystem.h" +//#include +//#include "../libRocket/Include/Rocket/Core.h" + +class RocketLogSystem : public ILogSystem +{ +public: + //// ILogSystem interface + //SErrorDescriptor UnitTest(ILogSystem *) + // { return SErrorDescriptor(); } + + //// New to this implementation + + RocketLogSystem(void); + ~RocketLogSystem(void); + + // RocketLib redraws the logger as part of redrawing the GUI, so only needs to fetch + // state when this occurs, not on every logging call. Hence a polling interface would + // be ideal. + // For now, a push interface gets the same results. Call Push() before RocketLib update. + void Push(); + + struct RLSPlatformImpl; + + //// ILogSystem interface + + ELogVerbosity GetVerbosity() const; + void SetVerbosity(ELogVerbosity eVerbosity); + TVerbosityPeeker GetVerbosityPeeker() const; + + void Log(ELogVerbosity eVerbosity, const char * format, ...); + void LogVa(va_list args, ELogVerbosity eVerbosity, const char * format); + +protected: + void LogInternal(ELogVerbosity eVerbosity, const char * format, va_list args); + + RLSPlatformImpl * m_pImpl; + + ELogVerbosity m_eVerbosity; + + // Give a generous allocation of full-length log messages between updates + // or a great many smaller messages + const static int BUFF_SIZE = LOGSYSTEM_MAX_BUFFER * 20; + char m_buff[BUFF_SIZE]; + int m_buffIndex; +}; + + +#endif //ROCKETLOGSYSTEM_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/ThreadsafeLogSystem/ThreadsafeLogSystem.h b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/ThreadsafeLogSystem/ThreadsafeLogSystem.h new file mode 100644 index 0000000..48ece6d --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/ThreadsafeLogSystem/ThreadsafeLogSystem.h @@ -0,0 +1,74 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef THREADSAFELOGSYSTEM_INCLUDED +#define THREADSAFELOGSYSTEM_INCLUDED + +#include "../../ILogSystem.h" + +class ThreadsafeLogSystem : public ILogSystem +{ +public: + //// ILogSystem interface + //SErrorDescriptor UnitTest(ILogSystem *) + // { return SErrorDescriptor(); } + + //// New to this class + + // There should only be one place that creates the logs, and one place that destroys them + // All theaded logging sources should be shut down before we do this! + ThreadsafeLogSystem(void); + ~ThreadsafeLogSystem(void); + + // Critical section - but should set before any multithreaded logging started + void SetProtectedLogSystem(ILogSystem *pLogSystem); + + // WaitForThreads() functionality here seems useful + // There are various threads that could still be logging and we need to wait until they all exit + + // Pimpl used for OS-specific multithreading primitives + struct TLSPlatformImpl; + + //// ILogSystem interface + + // No critical section - rarely changes, should appear atomic + ELogVerbosity GetVerbosity() const; + + // Critical section + void SetVerbosity(ELogVerbosity eVerbosity); + + // No critical section returned pointer should remain valid + TVerbosityPeeker GetVerbosityPeeker() const; + + // Critical section + void Log(ELogVerbosity eVerbosity, const char * format, ...); + + // Critical section + void LogVa(va_list args, ELogVerbosity eVerbosity, const char * format); + +protected: + void LogInternal(ELogVerbosity eVerbosity, const char * format, va_list args); + + TLSPlatformImpl * m_pImpl; + ELogVerbosity m_eVerbosity; + ILogSystem* m_protectedLogger; +}; + + +#endif //THREADSAFELOGSYSTEM_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/ThreadsafeLogSystem/ThreadsafeLogSystem_PlatformWindows.cpp b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/ThreadsafeLogSystem/ThreadsafeLogSystem_PlatformWindows.cpp new file mode 100644 index 0000000..d1b3105 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/LogSystem/ThreadsafeLogSystem/ThreadsafeLogSystem_PlatformWindows.cpp @@ -0,0 +1,132 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "ThreadsafeLogSystem.h" + +#ifdef _WIN32 + #include + #include +#else +#include + +// Linux / Mac OS X implementation of critical sections +// Not as efficient as a spin lock might be for this purpose, should probably move to one of those at some point +typedef pthread_mutex_t CRITICAL_SECTION; + +void InitializeCriticalSection( CRITICAL_SECTION* pCrit ) +{ + pthread_mutex_init(pCrit, NULL); +} + +void DeleteCriticalSection( CRITICAL_SECTION* pCrit ) +{ + //do nothing +} + +void EnterCriticalSection( CRITICAL_SECTION* pCrit ) +{ + pthread_mutex_lock( pCrit ); +} + +void LeaveCriticalSection( CRITICAL_SECTION* pCrit ) +{ + pthread_mutex_unlock( pCrit ); +} + +#endif + +#include +#include + +#pragma warning( disable : 4996 4800 ) + + +struct ThreadsafeLogSystem::TLSPlatformImpl +{ + CRITICAL_SECTION critSec; +}; + + +ThreadsafeLogSystem::ThreadsafeLogSystem(void) +{ + m_pImpl = new TLSPlatformImpl(); + InitializeCriticalSection(&(m_pImpl->critSec)); + + m_eVerbosity = eLV_COMMENTS; // By default, defer any filtering + m_protectedLogger = NULL; +} + +ThreadsafeLogSystem::~ThreadsafeLogSystem(void) +{ + delete m_protectedLogger; + DeleteCriticalSection(&(m_pImpl->critSec)); + delete m_pImpl; +} + +void ThreadsafeLogSystem::SetProtectedLogSystem(ILogSystem *pLogSystem) +{ + EnterCriticalSection(&(m_pImpl->critSec)); + + if (m_protectedLogger) + delete m_protectedLogger; + m_protectedLogger = pLogSystem; + + LeaveCriticalSection(&(m_pImpl->critSec)); +} + +ELogVerbosity ThreadsafeLogSystem::GetVerbosity() const +{ + return m_eVerbosity; +} + +void ThreadsafeLogSystem::SetVerbosity(ELogVerbosity eVerbosity) +{ + EnterCriticalSection(&(m_pImpl->critSec)); + + m_eVerbosity = eVerbosity; + + LeaveCriticalSection(&(m_pImpl->critSec)); +} + +ThreadsafeLogSystem::TVerbosityPeeker ThreadsafeLogSystem::GetVerbosityPeeker() const +{ + return (&m_eVerbosity); +} + +void ThreadsafeLogSystem::Log(ELogVerbosity eVerbosity, const char * format, ...) +{ + va_list args; + va_start(args, format); + LogInternal(eVerbosity, format, args); +} + +void ThreadsafeLogSystem::LogVa(va_list args, ELogVerbosity eVerbosity, const char * format) +{ + LogInternal(eVerbosity, format, args); +} + +void ThreadsafeLogSystem::LogInternal(ELogVerbosity eVerbosity, const char * format, va_list args) +{ + if (eVerbosity > m_eVerbosity || eVerbosity == eLV_NEVER) return; + + // Possible bug here in all loggers - should also check against "compile out" value + EnterCriticalSection(&(m_pImpl->critSec)); + + m_protectedLogger->LogVa(args, eVerbosity, format); + + LeaveCriticalSection(&(m_pImpl->critSec)); +} diff --git a/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/Input.cpp b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/Input.cpp new file mode 100644 index 0000000..38bc6da --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/Input.cpp @@ -0,0 +1,354 @@ +/* + * This source file is part of libRocket, the HTML/CSS Interface Middleware + * + * For the latest information, see http://www.librocket.com + * + * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd + * + * 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 "Input.h" + +/** + This map contains 4 different mappings from key identifiers to character codes. Each entry represents a different + combination of shift and capslock state. + */ + +char ascii_map[4][51] = +{ + // shift off and capslock off + { + 0, + ' ', + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + 'a', + 'b', + 'c', + 'd', + 'e', + 'f', + 'g', + 'h', + 'i', + 'j', + 'k', + 'l', + 'm', + 'n', + 'o', + 'p', + 'q', + 'r', + 's', + 't', + 'u', + 'v', + 'w', + 'x', + 'y', + 'z', + ';', + '=', + ',', + '-', + '.', + '/', + '`', + '[', + '\\', + ']', + '\'', + 0, + 0 + }, + + // shift on and capslock off + { + 0, + ' ', + ')', + '!', + '@', + '#', + '$', + '%', + '^', + '&', + '*', + '(', + 'A', + 'B', + 'C', + 'D', + 'E', + 'F', + 'G', + 'H', + 'I', + 'J', + 'K', + 'L', + 'M', + 'N', + 'O', + 'P', + 'Q', + 'R', + 'S', + 'T', + 'U', + 'V', + 'W', + 'X', + 'Y', + 'Z', + ':', + '+', + '<', + '_', + '>', + '?', + '~', + '{', + '|', + '}', + '"', + 0, + 0 + }, + + // shift on and capslock on + { + 0, + ' ', + ')', + '!', + '@', + '#', + '$', + '%', + '^', + '&', + '*', + '(', + 'a', + 'b', + 'c', + 'd', + 'e', + 'f', + 'g', + 'h', + 'i', + 'j', + 'k', + 'l', + 'm', + 'n', + 'o', + 'p', + 'q', + 'r', + 's', + 't', + 'u', + 'v', + 'w', + 'x', + 'y', + 'z', + ':', + '+', + '<', + '_', + '>', + '?', + '~', + '{', + '|', + '}', + '"', + 0, + 0 + }, + + // shift off and capslock on + { + 0, + ' ', + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + '0', + 'A', + 'B', + 'C', + 'D', + 'E', + 'F', + 'G', + 'H', + 'I', + 'J', + 'K', + 'L', + 'M', + 'N', + 'O', + 'P', + 'Q', + 'R', + 'S', + 'T', + 'U', + 'V', + 'W', + 'X', + 'Y', + 'Z', + ';', + '=', + ',', + '-', + '.', + '/', + '`', + '[', + '\\', + ']', + '\'', + 0, + 0 + } +}; + +char keypad_map[2][18] = +{ + { + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + '\n', + '*', + '+', + 0, + '-', + '.', + '/', + '=' + }, + + { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + '\n', + '*', + '+', + 0, + '-', + 0, + '/', + '=' + } +}; + + + +Rocket::Core::Context* Input::context = NULL; + + + +// Sets the context to send input events to. +void Input::SetContext(Rocket::Core::Context* _context) +{ + context = _context; +} + + + +// Returns the character code for a key identifer / key modifier combination. +Rocket::Core::word Input::GetCharacterCode(Rocket::Core::Input::KeyIdentifier key_identifier, int key_modifier_state) +{ + // Check if we have a keycode capable of generating characters on the main keyboard (ie, not on the numeric + // keypad; that is dealt with below). + if (key_identifier <= Rocket::Core::Input::KI_OEM_102) + { + // Get modifier states + bool shift = (key_modifier_state & Rocket::Core::Input::KM_SHIFT) > 0; + bool capslock = (key_modifier_state & Rocket::Core::Input::KM_CAPSLOCK) > 0; + + // Return character code based on identifier and modifiers + if (shift && !capslock) + return ascii_map[1][key_identifier]; + + if (shift && capslock) + return ascii_map[2][key_identifier]; + + if (!shift && capslock) + return ascii_map[3][key_identifier]; + + return ascii_map[0][key_identifier]; + } + + // Check if we have a keycode from the numeric keypad. + else if (key_identifier <= Rocket::Core::Input::KI_OEM_NEC_EQUAL) + { + if (key_modifier_state & Rocket::Core::Input::KM_NUMLOCK) + return keypad_map[0][key_identifier - Rocket::Core::Input::KI_NUMPAD0]; + else + return keypad_map[1][key_identifier - Rocket::Core::Input::KI_NUMPAD0]; + } + + else if (key_identifier == Rocket::Core::Input::KI_RETURN) + return '\n'; + + return 0; +} diff --git a/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/Input.h b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/Input.h new file mode 100644 index 0000000..dd2a706 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/Input.h @@ -0,0 +1,65 @@ +/* + * This source file is part of libRocket, the HTML/CSS Interface Middleware + * + * For the latest information, see http://www.librocket.com + * + * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd + * + * 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. + * + */ + +#ifndef SHELLINPUT_H +#define SHELLINPUT_H + +#include +#include + +namespace Rocket { +namespace Core { + +class Context; + +} +} + +/** + */ + +class Input +{ +public: + /// Sets the context to send input events to. + /// @param[in] context The context to send input events to. + static void SetContext(Rocket::Core::Context* context); + /// Returns the character code for a key identifer / key modifier combination. + /// @param[in] key_identifier The key to generate a character code for. + /// @param[in] key_modifier_state The configuration of the key modifiers. + /// @return The character code. + static Rocket::Core::word GetCharacterCode(Rocket::Core::Input::KeyIdentifier key_identifier, int key_modifier_state); + static Rocket::Core::Context* GetContext() + { + return context; + } + +protected: + static Rocket::Core::Context* context; +}; + +#endif diff --git a/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/InputGLFW.cpp b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/InputGLFW.cpp new file mode 100644 index 0000000..7bc6cbc --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/InputGLFW.cpp @@ -0,0 +1,282 @@ +/* + * This source file is part of libRocket, the HTML/CSS Interface Middleware + * + * For the latest information, see http://www.librocket.com + * + * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd + * + * 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 + +#include "InputGLFW.h" +#include +#include + + + +static int GetKeyModifierState(); +static void InitialiseKeymap(); + +void GLFWCALL KeyCallback( int key, int action ); +void GLFWCALL CharCallback( int character, int action ); +void GLFWCALL MouseButtonCallback( int button, int action ); +void GLFWCALL MousePosCallback( int x, int y ); +void GLFWCALL MouseWheelCallback( int pos ); + +static const int KEYMAP_SIZE = 512; +static Rocket::Core::Input::KeyIdentifier key_identifier_map[KEYMAP_SIZE]; + +bool InputGLFW::Initialise() +{ + InitialiseKeymap(); + + //init callbacks for glfw + glfwSetCharCallback( CharCallback ); + glfwSetKeyCallback( KeyCallback ); + glfwSetMouseButtonCallback( MouseButtonCallback ); + glfwSetMousePosCallback( MousePosCallback ); + glfwSetMouseWheelCallback( MouseWheelCallback ); + + return true; +} + + +void GLFWCALL KeyCallback( int key, int action ) +{ + if( 0 == Input::GetContext() ) { return; } + + if( GLFW_PRESS == action ) + { + Input::GetContext()->ProcessKeyDown(key_identifier_map[key], GetKeyModifierState()); + if( key == GLFW_KEY_TAB ) + { + Input::GetContext()->ProcessTextInput( '\t' ); + } + if( key == GLFW_KEY_ENTER ) + { + Input::GetContext()->ProcessTextInput( '\n' ); + } + } + else + { + Input::GetContext()->ProcessKeyUp(key_identifier_map[key], GetKeyModifierState()); + } + +} + +void GLFWCALL CharCallback( int character, int action ) +{ + if( 0 == Input::GetContext() ) { return; } + + if( GLFW_PRESS == action ) + { + Input::GetContext()->ProcessTextInput( character ); + } +} + +void GLFWCALL MouseButtonCallback( int button, int action ) +{ + if( 0 == Input::GetContext() ) { return; } + + if( GLFW_RELEASE == action ) + { + Input::GetContext()->ProcessMouseButtonUp( button, GetKeyModifierState()); + } + else + { + Input::GetContext()->ProcessMouseButtonDown( button, GetKeyModifierState()); + } + + +} + + +void GLFWCALL MousePosCallback( int x, int y ) +{ + if( 0 == Input::GetContext() ) { return; } + + Input::GetContext()->ProcessMouseMove(x, y, GetKeyModifierState()); +} + + +void GLFWCALL MouseWheelCallback( int pos ) +{ + if( 0 == Input::GetContext() ) { return; } + static int pos0 = 0; + Input::GetContext()->ProcessMouseWheel(pos0-pos, GetKeyModifierState()); + pos0 = pos; +} + + +static int GetKeyModifierState() +{ + int key_modifier_state = 0; + + // Query the state of all modifier keys + if( glfwGetKey( GLFW_KEY_CAPS_LOCK )) + { + key_modifier_state |= Rocket::Core::Input::KM_CAPSLOCK; + } + + if( glfwGetKey( GLFW_KEY_LSHIFT ) || glfwGetKey( GLFW_KEY_RSHIFT ) ) + { + key_modifier_state |= Rocket::Core::Input::KM_SHIFT; + } + + if( glfwGetKey( GLFW_KEY_KP_NUM_LOCK )) + { + key_modifier_state |= Rocket::Core::Input::KM_NUMLOCK; + } + + if( glfwGetKey( GLFW_KEY_LCTRL ) || glfwGetKey( GLFW_KEY_RCTRL ) ) + { + key_modifier_state |= Rocket::Core::Input::KM_CTRL; + } + + if( glfwGetKey( GLFW_KEY_LALT ) || glfwGetKey( GLFW_KEY_RALT ) ) + { + key_modifier_state |= Rocket::Core::Input::KM_ALT; + } + + return key_modifier_state; +} + +static void InitialiseKeymap() +{ + // Initialise the key map with default values. + memset(key_identifier_map, 0, sizeof(key_identifier_map)); + + // Assign individual values. + key_identifier_map['A'] = Rocket::Core::Input::KI_A; + key_identifier_map['B'] = Rocket::Core::Input::KI_B; + key_identifier_map['C'] = Rocket::Core::Input::KI_C; + key_identifier_map['D'] = Rocket::Core::Input::KI_D; + key_identifier_map['E'] = Rocket::Core::Input::KI_E; + key_identifier_map['F'] = Rocket::Core::Input::KI_F; + key_identifier_map['G'] = Rocket::Core::Input::KI_G; + key_identifier_map['H'] = Rocket::Core::Input::KI_H; + key_identifier_map['I'] = Rocket::Core::Input::KI_I; + key_identifier_map['J'] = Rocket::Core::Input::KI_J; + key_identifier_map['K'] = Rocket::Core::Input::KI_K; + key_identifier_map['L'] = Rocket::Core::Input::KI_L; + key_identifier_map['M'] = Rocket::Core::Input::KI_M; + key_identifier_map['N'] = Rocket::Core::Input::KI_N; + key_identifier_map['O'] = Rocket::Core::Input::KI_O; + key_identifier_map['P'] = Rocket::Core::Input::KI_P; + key_identifier_map['Q'] = Rocket::Core::Input::KI_Q; + key_identifier_map['R'] = Rocket::Core::Input::KI_R; + key_identifier_map['S'] = Rocket::Core::Input::KI_S; + key_identifier_map['T'] = Rocket::Core::Input::KI_T; + key_identifier_map['U'] = Rocket::Core::Input::KI_U; + key_identifier_map['V'] = Rocket::Core::Input::KI_V; + key_identifier_map['W'] = Rocket::Core::Input::KI_W; + key_identifier_map['X'] = Rocket::Core::Input::KI_X; + key_identifier_map['Y'] = Rocket::Core::Input::KI_Y; + key_identifier_map['Z'] = Rocket::Core::Input::KI_Z; + + key_identifier_map['0'] = Rocket::Core::Input::KI_0; + key_identifier_map['1'] = Rocket::Core::Input::KI_1; + key_identifier_map['2'] = Rocket::Core::Input::KI_2; + key_identifier_map['3'] = Rocket::Core::Input::KI_3; + key_identifier_map['4'] = Rocket::Core::Input::KI_4; + key_identifier_map['5'] = Rocket::Core::Input::KI_5; + key_identifier_map['6'] = Rocket::Core::Input::KI_6; + key_identifier_map['7'] = Rocket::Core::Input::KI_7; + key_identifier_map['8'] = Rocket::Core::Input::KI_8; + key_identifier_map['9'] = Rocket::Core::Input::KI_9; + + key_identifier_map[GLFW_KEY_BACKSPACE] = Rocket::Core::Input::KI_BACK; + key_identifier_map[GLFW_KEY_TAB] = Rocket::Core::Input::KI_TAB; + + key_identifier_map[GLFW_KEY_ENTER] = Rocket::Core::Input::KI_RETURN; + + key_identifier_map[GLFW_KEY_PAUSE] = Rocket::Core::Input::KI_PAUSE; + key_identifier_map[GLFW_KEY_CAPS_LOCK] = Rocket::Core::Input::KI_CAPITAL; + + key_identifier_map[GLFW_KEY_ESC] = Rocket::Core::Input::KI_ESCAPE; + + key_identifier_map[GLFW_KEY_SPACE] = Rocket::Core::Input::KI_SPACE; + key_identifier_map[GLFW_KEY_PAGEUP] = Rocket::Core::Input::KI_PRIOR; + key_identifier_map[GLFW_KEY_PAGEDOWN] = Rocket::Core::Input::KI_NEXT; + key_identifier_map[GLFW_KEY_END] = Rocket::Core::Input::KI_END; + key_identifier_map[GLFW_KEY_HOME] = Rocket::Core::Input::KI_HOME; + key_identifier_map[GLFW_KEY_LEFT] = Rocket::Core::Input::KI_LEFT; + key_identifier_map[GLFW_KEY_UP] = Rocket::Core::Input::KI_UP; + key_identifier_map[GLFW_KEY_RIGHT] = Rocket::Core::Input::KI_RIGHT; + key_identifier_map[GLFW_KEY_DOWN] = Rocket::Core::Input::KI_DOWN; + key_identifier_map[GLFW_KEY_INSERT] = Rocket::Core::Input::KI_INSERT; + key_identifier_map[GLFW_KEY_DEL] = Rocket::Core::Input::KI_DELETE; + + key_identifier_map[GLFW_KEY_LSUPER] = Rocket::Core::Input::KI_LWIN; + key_identifier_map[GLFW_KEY_RSUPER] = Rocket::Core::Input::KI_RWIN; + + key_identifier_map[GLFW_KEY_KP_0] = Rocket::Core::Input::KI_NUMPAD0; + key_identifier_map[GLFW_KEY_KP_1] = Rocket::Core::Input::KI_NUMPAD1; + key_identifier_map[GLFW_KEY_KP_2] = Rocket::Core::Input::KI_NUMPAD2; + key_identifier_map[GLFW_KEY_KP_3] = Rocket::Core::Input::KI_NUMPAD3; + key_identifier_map[GLFW_KEY_KP_4] = Rocket::Core::Input::KI_NUMPAD4; + key_identifier_map[GLFW_KEY_KP_5] = Rocket::Core::Input::KI_NUMPAD5; + key_identifier_map[GLFW_KEY_KP_6] = Rocket::Core::Input::KI_NUMPAD6; + key_identifier_map[GLFW_KEY_KP_7] = Rocket::Core::Input::KI_NUMPAD7; + key_identifier_map[GLFW_KEY_KP_8] = Rocket::Core::Input::KI_NUMPAD8; + key_identifier_map[GLFW_KEY_KP_9] = Rocket::Core::Input::KI_NUMPAD9; + key_identifier_map[GLFW_KEY_KP_MULTIPLY] = Rocket::Core::Input::KI_MULTIPLY; + key_identifier_map[GLFW_KEY_KP_ADD] = Rocket::Core::Input::KI_ADD; + key_identifier_map[GLFW_KEY_KP_DECIMAL] = Rocket::Core::Input::KI_SEPARATOR; //i.e. either '.' or ',' + key_identifier_map[GLFW_KEY_KP_SUBTRACT] = Rocket::Core::Input::KI_SUBTRACT; + key_identifier_map[GLFW_KEY_KP_DECIMAL] = Rocket::Core::Input::KI_DECIMAL; + key_identifier_map[GLFW_KEY_KP_DIVIDE] = Rocket::Core::Input::KI_DIVIDE; + key_identifier_map[GLFW_KEY_F1] = Rocket::Core::Input::KI_F1; + key_identifier_map[GLFW_KEY_F2] = Rocket::Core::Input::KI_F2; + key_identifier_map[GLFW_KEY_F3] = Rocket::Core::Input::KI_F3; + key_identifier_map[GLFW_KEY_F4] = Rocket::Core::Input::KI_F4; + key_identifier_map[GLFW_KEY_F5] = Rocket::Core::Input::KI_F5; + key_identifier_map[GLFW_KEY_F6] = Rocket::Core::Input::KI_F6; + key_identifier_map[GLFW_KEY_F7] = Rocket::Core::Input::KI_F7; + key_identifier_map[GLFW_KEY_F8] = Rocket::Core::Input::KI_F8; + key_identifier_map[GLFW_KEY_F9] = Rocket::Core::Input::KI_F9; + key_identifier_map[GLFW_KEY_F10] = Rocket::Core::Input::KI_F10; + key_identifier_map[GLFW_KEY_F11] = Rocket::Core::Input::KI_F11; + key_identifier_map[GLFW_KEY_F12] = Rocket::Core::Input::KI_F12; + key_identifier_map[GLFW_KEY_F13] = Rocket::Core::Input::KI_F13; + key_identifier_map[GLFW_KEY_F14] = Rocket::Core::Input::KI_F14; + key_identifier_map[GLFW_KEY_F15] = Rocket::Core::Input::KI_F15; + key_identifier_map[GLFW_KEY_F16] = Rocket::Core::Input::KI_F16; + key_identifier_map[GLFW_KEY_F17] = Rocket::Core::Input::KI_F17; + key_identifier_map[GLFW_KEY_F18] = Rocket::Core::Input::KI_F18; + key_identifier_map[GLFW_KEY_F19] = Rocket::Core::Input::KI_F19; + key_identifier_map[GLFW_KEY_F20] = Rocket::Core::Input::KI_F20; + key_identifier_map[GLFW_KEY_F21] = Rocket::Core::Input::KI_F21; + key_identifier_map[GLFW_KEY_F22] = Rocket::Core::Input::KI_F22; + key_identifier_map[GLFW_KEY_F23] = Rocket::Core::Input::KI_F23; + key_identifier_map[GLFW_KEY_F24] = Rocket::Core::Input::KI_F24; + + key_identifier_map[GLFW_KEY_KP_NUM_LOCK] = Rocket::Core::Input::KI_NUMLOCK; + key_identifier_map[GLFW_KEY_SCROLL_LOCK] = Rocket::Core::Input::KI_SCROLL; + + key_identifier_map[GLFW_KEY_LSHIFT] = Rocket::Core::Input::KI_LSHIFT; + key_identifier_map[GLFW_KEY_RSHIFT] = Rocket::Core::Input::KI_RSHIFT; + key_identifier_map[GLFW_KEY_LCTRL] = Rocket::Core::Input::KI_LCONTROL; + key_identifier_map[GLFW_KEY_RCTRL] = Rocket::Core::Input::KI_RCONTROL; + key_identifier_map[GLFW_KEY_LALT] = Rocket::Core::Input::KI_LMENU; + key_identifier_map[GLFW_KEY_RALT] = Rocket::Core::Input::KI_RMENU; + +} diff --git a/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/InputGLFW.h b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/InputGLFW.h new file mode 100644 index 0000000..ced668e --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/InputGLFW.h @@ -0,0 +1,51 @@ +/* + * This source file is part of libRocket, the HTML/CSS Interface Middleware + * + * For the latest information, see http://www.librocket.com + * + * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd + * + * 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 + +#ifndef ROCKETINPUTGLFW_H +#define ROCKETINPUTGLFW_H + +#include "Input.h" + + +/** + Processes Windows input events and passes them through to Rocket. Feel free to take this class and integrate it + with your project. + @author Lloyd Weehuizen + + Modified to move to GLFW by Doug Binks + */ + +class InputGLFW : public Input +{ +public: + static bool Initialise(); + +private: +}; + +#endif diff --git a/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystem.cpp b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystem.cpp new file mode 100644 index 0000000..a197294 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystem.cpp @@ -0,0 +1,46 @@ +/* + * This source file is part of libRocket, the HTML/CSS Interface Middleware + * + * For the latest information, see http://www.librocket.com + * + * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd + * + * 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 "RocketLibSystem.h" +#include + +/// Loads the default fonts from the given path. +void RocketLibSystem::LoadFonts(const char* directory) +{ + Rocket::Core::String font_names[5]; + font_names[0] = "Delicious-Roman.otf"; + font_names[1] = "Delicious-Italic.otf"; + font_names[2] = "Delicious-Bold.otf"; + font_names[3] = "Delicious-BoldItalic.otf"; + font_names[4] = "Anonymous.ttf"; + + for (int i = 0; i < sizeof(font_names) / sizeof(Rocket::Core::String); i++) + { + Rocket::Core::FontDatabase::LoadFontFace(Rocket::Core::String(directory) + font_names[i]); + } +} + diff --git a/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystem.h b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystem.h new file mode 100644 index 0000000..b3c362d --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystem.h @@ -0,0 +1,87 @@ +/* + * This source file is part of libRocket, the HTML/CSS Interface Middleware + * + * For the latest information, see http://www.librocket.com + * + * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd + * + * 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. + * + */ + +#ifndef ROCKETSHELL_H +#define ROCKETSHELL_H + +#include +#include + +#ifdef ROCKET_PLATFORM_WIN32 +#define PATH_SEPARATOR ";" +#else +#define PATH_SEPARATOR ":" +#endif + +/** + RocketLibSystem functions for creating windows, attaching OpenGL and handling input in a platform independent way. + @author Lloyd Weehuizen + */ + +class RocketLibSystem +{ +public: + /// Initialise the shell. + static bool Initialise(); + /// Shutdown the shell. + static void Shutdown(); + + /// Loads the default fonts from the given path. + static void LoadFonts(const char* directory); + + /// Open a platform specific window, optionally initialising an OpenGL context on it. + /// @param[in] title Title of the window. + /// @param[in] attach_opengl Attach and opengl context to the window. + static bool OpenWindow(const char* title, bool attach_opengl); + /// Close the active window. + static void CloseWindow(); + + /// Flips the OpenGL buffers. + static void FlipBuffers(); + + /// Run the event loop, calling the idle function every frame. + typedef void (*RocketLibSystemIdleFunction)(); + static void EventLoop(RocketLibSystemIdleFunction idle_function); + static void RequestExit(); + + /// Display an error message. + static void DisplayError(const char* fmt, ...); + + /// Get the number of seconds that have passed since shell startup. + static float GetElapsedTime(); + + static void PreRenderRocketLib(); + + static void GetViewport( int WindowSize[4] ); + +private: +}; + +#include "RocketLibSystemRenderInterfaceOpenGL.h" +#include "RocketLibSystemSystemInterface.h" + +#endif diff --git a/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemFileInterface.cpp b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemFileInterface.cpp new file mode 100644 index 0000000..09e4f72 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemFileInterface.cpp @@ -0,0 +1,74 @@ +/* + * This source file is part of libRocket, the HTML/CSS Interface Middleware + * + * For the latest information, see http://www.librocket.com + * + * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd + * + * 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 "RocketLibSystemFileInterface.h" +#include + +RocketLibSystemFileInterface::RocketLibSystemFileInterface(const Rocket::Core::String& root) : root(root) +{ +} + +RocketLibSystemFileInterface::~RocketLibSystemFileInterface() +{ +} + +// Opens a file. +Rocket::Core::FileHandle RocketLibSystemFileInterface::Open(const Rocket::Core::String& path) +{ + // Attempt to open the file relative to the application's root. + FILE* fp = fopen((root + path).CString(), "rb"); + if (fp != NULL) + return (Rocket::Core::FileHandle) fp; + + // Attempt to open the file relative to the current working directory. + fp = fopen(path.CString(), "rb"); + return (Rocket::Core::FileHandle) fp; +} + +// Closes a previously opened file. +void RocketLibSystemFileInterface::Close(Rocket::Core::FileHandle file) +{ + fclose((FILE*) file); +} + +// Reads data from a previously opened file. +size_t RocketLibSystemFileInterface::Read(void* buffer, size_t size, Rocket::Core::FileHandle file) +{ + return fread(buffer, 1, size, (FILE*) file); +} + +// Seeks to a point in a previously opened file. +bool RocketLibSystemFileInterface::Seek(Rocket::Core::FileHandle file, long offset, int origin) +{ + return fseek((FILE*) file, offset, origin) == 0; +} + +// Returns the current position of the file pointer. +size_t RocketLibSystemFileInterface::Tell(Rocket::Core::FileHandle file) +{ + return ftell((FILE*) file); +} diff --git a/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemFileInterface.h b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemFileInterface.h new file mode 100644 index 0000000..93ccef1 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemFileInterface.h @@ -0,0 +1,64 @@ +/* + * This source file is part of libRocket, the HTML/CSS Interface Middleware + * + * For the latest information, see http://www.librocket.com + * + * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd + * + * 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. + * + */ + +#ifndef SHELLFILEINTERFACE_H +#define SHELLFILEINTERFACE_H + +#include +#include + +/** + Rocket file interface for the shell examples. + @author Lloyd Weehuizen + */ + +class RocketLibSystemFileInterface : public Rocket::Core::FileInterface +{ +public: + RocketLibSystemFileInterface(const Rocket::Core::String& root); + virtual ~RocketLibSystemFileInterface(); + + /// Opens a file. + virtual Rocket::Core::FileHandle Open(const Rocket::Core::String& path); + + /// Closes a previously opened file. + virtual void Close(Rocket::Core::FileHandle file); + + /// Reads data from a previously opened file. + virtual size_t Read(void* buffer, size_t size, Rocket::Core::FileHandle file); + + /// Seeks to a point in a previously opened file. + virtual bool Seek(Rocket::Core::FileHandle file, long offset, int origin); + + /// Returns the current position of the file pointer. + virtual size_t Tell(Rocket::Core::FileHandle file); + +private: + Rocket::Core::String root; +}; + +#endif diff --git a/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemGLFW.cpp b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemGLFW.cpp new file mode 100644 index 0000000..344b3f6 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemGLFW.cpp @@ -0,0 +1,167 @@ +/* + * This source file is part of libRocket, the HTML/CSS Interface Middleware + * + * For the latest information, see http://www.librocket.com + * + * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd + * + * 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 "RocketLibSystem.h" +#include +#include "InputGLFW.h" +#include "RocketLibSystemFileInterface.h" +#include +#include + +#include "../Systems.h" +#include "../IAssetSystem.h" + +//#ifndef _WIN32 +//#include +//#endif + +void GLFWCALL WindowResize( int width, int height ); + + +static bool running = true; +static int g_WindowSize[4]; + + +static RocketLibSystemFileInterface* file_interface = NULL; + +bool RocketLibSystem::Initialise() +{ + if( GL_FALSE == glfwInit() ) + { + return false; + } + glfwSetTime(0.0); + + const char* pathToAssets = gSys->pAssetSystem->GetAssetDirectory(); + file_interface = new RocketLibSystemFileInterface(Rocket::Core::String(pathToAssets)); + + Rocket::Core::SetFileInterface(file_interface); + + return true; +} + +void RocketLibSystem::Shutdown() +{ + glfwTerminate(); + + delete file_interface; + file_interface = NULL; +} + +void RocketLibSystem::GetViewport( int WindowSize[4] ) +{ + memcpy( WindowSize, g_WindowSize, sizeof( g_WindowSize ) ); +} + +bool RocketLibSystem::OpenWindow(const char* name, bool attach_opengl) +{ + + glfwOpenWindow( 640, 768, 8, 8, 8, 8, 24, 8, GLFW_WINDOW ); + glfwSetWindowTitle( name ); + glfwSetWindowSizeCallback( WindowResize ); + glGetIntegerv( GL_VIEWPORT, g_WindowSize); + + InputGLFW::Initialise(); + + + return true; +} + +void RocketLibSystem::CloseWindow() +{ + glfwCloseWindow(); +} + +// Flips the OpenGL buffers. +void RocketLibSystem::FlipBuffers() +{ + glfwSwapBuffers(); +} + +void RocketLibSystem::EventLoop(RocketLibSystemIdleFunction idle_function) +{ + while (running) + { + if( !glfwGetWindowParam( GLFW_OPENED ) ) + { + running = false; + } + else + { + + idle_function(); + + if( !glfwGetWindowParam( GLFW_ACTIVE ) ) + { + glfwSleep( 0.1 ); + } + } + } +} + +void RocketLibSystem::RequestExit() +{ + running = false; +} + +void RocketLibSystem::DisplayError(const char* fmt, ...) +{ + //not implemented +} + +float RocketLibSystem::GetElapsedTime() +{ + return (float)glfwGetTime(); +} + +void GLFWCALL WindowResize( int width, int height ) +{ + glViewport(0, 0, width, height); + glGetIntegerv( GL_VIEWPORT, g_WindowSize); +} + + +void RocketLibSystem::PreRenderRocketLib() +{ + // Set up the GL state for rocket + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + + glDisable(GL_LIGHTING); + glDisable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + glEnable( GL_ALPHA_TEST ); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, g_WindowSize[2], g_WindowSize[3], 0, -1, 1); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + diff --git a/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemOpenGL.h b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemOpenGL.h new file mode 100644 index 0000000..0445549 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemOpenGL.h @@ -0,0 +1,48 @@ +/* + * This source file is part of libRocket, the HTML/CSS Interface Middleware + * + * For the latest information, see http://www.librocket.com + * + * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd + * + * 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. + * + */ + +#ifndef ROCKETSHELLOPENGL_H +#define ROCKETSHELLOPENGL_H + +#include + +#if defined ROCKET_PLATFORM_WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#elif defined ROCKET_PLATFORM_MACOSX +#include +#include +#include +#elif defined ROCKET_PLATFORM_UNIX +#include +#include +#include +#endif + +#endif diff --git a/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemRenderInterfaceOpenGL.cpp b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemRenderInterfaceOpenGL.cpp new file mode 100644 index 0000000..9df0867 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemRenderInterfaceOpenGL.cpp @@ -0,0 +1,210 @@ +/* + * This source file is part of libRocket, the HTML/CSS Interface Middleware + * + * For the latest information, see http://www.librocket.com + * + * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd + * + * 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 "RocketLibSystemRenderInterfaceOpenGL.h" +#include + +#define GL_CLAMP_TO_EDGE 0x812F + +RocketLibSystemRenderInterfaceOpenGL::RocketLibSystemRenderInterfaceOpenGL() +{ +} + +// Called by Rocket when it wants to render geometry that it does not wish to optimise. +void RocketLibSystemRenderInterfaceOpenGL::RenderGeometry(Rocket::Core::Vertex* vertices, int ROCKET_UNUSED(num_vertices), int* indices, int num_indices, const Rocket::Core::TextureHandle texture, const Rocket::Core::Vector2f& translation) +{ + glPushMatrix(); + glTranslatef(translation.x, translation.y, 0); + + glVertexPointer(2, GL_FLOAT, sizeof(Rocket::Core::Vertex), &vertices[0].position); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Rocket::Core::Vertex), &vertices[0].colour); + + if (texture == NULL) + { + glDisable(GL_TEXTURE_2D); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + else + { + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, (GLuint) texture); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(Rocket::Core::Vertex), &vertices[0].tex_coord); + } + + glDrawElements(GL_TRIANGLES, num_indices, GL_UNSIGNED_INT, indices); + + glPopMatrix(); +} + +// Called by Rocket when it wants to compile geometry it believes will be static for the forseeable future. +Rocket::Core::CompiledGeometryHandle RocketLibSystemRenderInterfaceOpenGL::CompileGeometry(Rocket::Core::Vertex* ROCKET_UNUSED(vertices), int ROCKET_UNUSED(num_vertices), int* ROCKET_UNUSED(indices), int ROCKET_UNUSED(num_indices), const Rocket::Core::TextureHandle ROCKET_UNUSED(texture)) +{ + return (Rocket::Core::CompiledGeometryHandle) NULL; +} + +// Called by Rocket when it wants to render application-compiled geometry. +void RocketLibSystemRenderInterfaceOpenGL::RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle ROCKET_UNUSED(geometry), const Rocket::Core::Vector2f& ROCKET_UNUSED(translation)) +{ +} + +// Called by Rocket when it wants to release application-compiled geometry. +void RocketLibSystemRenderInterfaceOpenGL::ReleaseCompiledGeometry(Rocket::Core::CompiledGeometryHandle ROCKET_UNUSED(geometry)) +{ +} + +// Called by Rocket when it wants to enable or disable scissoring to clip content. +void RocketLibSystemRenderInterfaceOpenGL::EnableScissorRegion(bool enable) +{ + if (enable) + glEnable(GL_SCISSOR_TEST); + else + glDisable(GL_SCISSOR_TEST); +} + +// Called by Rocket when it wants to change the scissor region. +void RocketLibSystemRenderInterfaceOpenGL::SetScissorRegion(int x, int y, int width, int height) +{ + int windowSize[4]; + glGetIntegerv( GL_VIEWPORT, windowSize); + glScissor(x, windowSize[3] - (y + height), width, height); +} + +// Set to byte packing, or the compiler will expand our struct, which means it won't read correctly from file +#pragma pack(1) +struct TGAHeader +{ + char idLength; + char colourMapType; + char dataType; + short int colourMapOrigin; + short int colourMapLength; + char colourMapDepth; + short int xOrigin; + short int yOrigin; + short int width; + short int height; + char bitsPerPixel; + char imageDescriptor; +}; +// Restore packing +#pragma pack() + +// Called by Rocket when a texture is required by the library. +bool RocketLibSystemRenderInterfaceOpenGL::LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source) +{ + Rocket::Core::FileInterface* file_interface = Rocket::Core::GetFileInterface(); + Rocket::Core::FileHandle file_handle = file_interface->Open(source); + if (file_handle == NULL) + return false; + + file_interface->Seek(file_handle, 0, SEEK_END); + size_t buffer_size = file_interface->Tell(file_handle); + file_interface->Seek(file_handle, 0, SEEK_SET); + + char* buffer = new char[buffer_size]; + file_interface->Read(buffer, buffer_size, file_handle); + file_interface->Close(file_handle); + + TGAHeader header; + memcpy(&header, buffer, sizeof(TGAHeader)); + + int color_mode = header.bitsPerPixel / 8; + int image_size = header.width * header.height * 4; // We always make 32bit textures + + if (header.dataType != 2) + { + Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24/32bit uncompressed TGAs are supported."); + return false; + } + + // Ensure we have at least 3 colors + if (color_mode < 3) + { + Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24 and 32bit textures are supported"); + return false; + } + + const char* image_src = buffer + sizeof(TGAHeader); + unsigned char* image_dest = new unsigned char[image_size]; + + // Targa is BGR, swap to RGB and flip Y axis + for (long y = 0; y < header.height; y++) + { + long read_index = y * header.width * color_mode; + long write_index = ((header.imageDescriptor & 32) != 0) ? read_index : (header.height - y - 1) * header.width * color_mode; + for (long x = 0; x < header.width; x++) + { + image_dest[write_index] = image_src[read_index+2]; + image_dest[write_index+1] = image_src[read_index+1]; + image_dest[write_index+2] = image_src[read_index]; + if (color_mode == 4) + image_dest[write_index+3] = image_src[read_index+3]; + else + image_dest[write_index+3] = 255; + + write_index += 4; + read_index += color_mode; + } + } + + texture_dimensions.x = header.width; + texture_dimensions.y = header.height; + + bool success = GenerateTexture(texture_handle, image_dest, texture_dimensions); + + delete [] image_dest; + delete [] buffer; + + return success; +} + +// Called by Rocket when a texture is required to be built from an internally-generated sequence of pixels. +bool RocketLibSystemRenderInterfaceOpenGL::GenerateTexture(Rocket::Core::TextureHandle& texture_handle, const Rocket::Core::byte* source, const Rocket::Core::Vector2i& source_dimensions) +{ + GLuint texture_id; + glGenTextures(1, &texture_id); + glBindTexture(GL_TEXTURE_2D, texture_id); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, source_dimensions.x, source_dimensions.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, source); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + texture_handle = (Rocket::Core::TextureHandle) texture_id; + + return true; +} + +// Called by Rocket when a loaded texture is no longer required. +void RocketLibSystemRenderInterfaceOpenGL::ReleaseTexture(Rocket::Core::TextureHandle texture_handle) +{ + glDeleteTextures(1, (GLuint*) &texture_handle); +} + diff --git a/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemRenderInterfaceOpenGL.h b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemRenderInterfaceOpenGL.h new file mode 100644 index 0000000..1e711ba --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemRenderInterfaceOpenGL.h @@ -0,0 +1,68 @@ +/* + * This source file is part of libRocket, the HTML/CSS Interface Middleware + * + * For the latest information, see http://www.librocket.com + * + * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd + * + * 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. + * + */ + +#ifndef ROCKETSHELLRENDERINTERFACE_H +#define ROCKETSHELLRENDERINTERFACE_H + +#include "Rocket/Core/RenderInterface.h" +#include "RocketLibSystemOpenGL.h" + +/** + Low level OpenGL render interface for Rocket + @author Peter Curry + */ + +class RocketLibSystemRenderInterfaceOpenGL : public Rocket::Core::RenderInterface +{ +public: + RocketLibSystemRenderInterfaceOpenGL(); + + /// Called by Rocket when it wants to render geometry that it does not wish to optimise. + virtual void RenderGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rocket::Core::TextureHandle texture, const Rocket::Core::Vector2f& translation); + + /// Called by Rocket when it wants to compile geometry it believes will be static for the forseeable future. + virtual Rocket::Core::CompiledGeometryHandle CompileGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rocket::Core::TextureHandle texture); + + /// Called by Rocket when it wants to render application-compiled geometry. + virtual void RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry, const Rocket::Core::Vector2f& translation); + /// Called by Rocket when it wants to release application-compiled geometry. + virtual void ReleaseCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry); + + /// Called by Rocket when it wants to enable or disable scissoring to clip content. + virtual void EnableScissorRegion(bool enable); + /// Called by Rocket when it wants to change the scissor region. + virtual void SetScissorRegion(int x, int y, int width, int height); + + /// Called by Rocket when a texture is required by the library. + virtual bool LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source); + /// Called by Rocket when a texture is required to be built from an internally-generated sequence of pixels. + virtual bool GenerateTexture(Rocket::Core::TextureHandle& texture_handle, const Rocket::Core::byte* source, const Rocket::Core::Vector2i& source_dimensions); + /// Called by Rocket when a loaded texture is no longer required. + virtual void ReleaseTexture(Rocket::Core::TextureHandle texture_handle); +}; + +#endif diff --git a/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemSystemInterface.cpp b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemSystemInterface.cpp new file mode 100644 index 0000000..d18c69d --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemSystemInterface.cpp @@ -0,0 +1,35 @@ +/* + * This source file is part of libRocket, the HTML/CSS Interface Middleware + * + * For the latest information, see http://www.librocket.com + * + * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd + * + * 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 "RocketLibSystemSystemInterface.h" +#include "RocketLibSystem.h" + +// Get the number of seconds elapsed since the start of the application +float RocketLibSystemSystemInterface::GetElapsedTime() +{ + return RocketLibSystem::GetElapsedTime(); +} diff --git a/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemSystemInterface.h b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemSystemInterface.h new file mode 100644 index 0000000..d62f1f7 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/RocketLibSystem/RocketLibSystemSystemInterface.h @@ -0,0 +1,50 @@ +/* + * This source file is part of libRocket, the HTML/CSS Interface Middleware + * + * For the latest information, see http://www.librocket.com + * + * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd + * + * 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. + * + */ + +#ifndef ROCKETSHELLSYSTEMINTERFACE_H +#define ROCKETSHELLSYSTEMINTERFACE_H + +#include + + +/** + A custom system interface for Rocket. This provides timing information. + @author Lloyd Weehuizen + @author modifed by Doug Binks + */ + +class RocketLibSystemSystemInterface : public Rocket::Core::SystemInterface +{ +public: + /// Get the number of seconds elapsed since the start of the application + /// @returns Seconds elapsed + virtual float GetElapsedTime(); + +private: +}; + +#endif diff --git a/3rdparty/RuntimeCompiledCpp/Systems/SystemTable.h b/3rdparty/RuntimeCompiledCpp/Systems/SystemTable.h new file mode 100644 index 0000000..23866da --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/SystemTable.h @@ -0,0 +1,56 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef SYSTEMTABLE_INCLUDED +#define SYSTEMTABLE_INCLUDED + +#include "Definitions.inl" + +class RocketLogSystem; + + +struct SystemTable +{ + IRuntimeObjectSystem * pRuntimeObjectSystem; + ITimeSystem *pTimeSystem; + ILogSystem *pLogSystem; + IEntitySystem *pEntitySystem; + IAssetSystem* pAssetSystem; + IObjectFactorySystem* pObjectFactorySystem; + IGUISystem* pGUISystem; + IFileChangeNotifier* pFileChangeNotifier; + IGame* pGame; + + // This would better live within an IRocketLibSystem, when that is written + RocketLogSystem* pRocketLogSystem; + + SystemTable() + : pTimeSystem(0) + , pLogSystem(0) + , pEntitySystem(0) + , pAssetSystem(0) + , pObjectFactorySystem(0) + , pGUISystem(0) + , pFileChangeNotifier(0) + , pRocketLogSystem(0) + , pGame(0) + {} +}; + +#endif // SYSTEMTABLE_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/Systems.cpp b/3rdparty/RuntimeCompiledCpp/Systems/Systems.cpp new file mode 100644 index 0000000..edf2648 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/Systems.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "Systems.h" + +SystemTable * gSys = 0; diff --git a/3rdparty/RuntimeCompiledCpp/Systems/Systems.h b/3rdparty/RuntimeCompiledCpp/Systems/Systems.h new file mode 100644 index 0000000..c76cecd --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/Systems.h @@ -0,0 +1,38 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef SYSTEMS_INCLUDED +#define SYSTEMS_INCLUDED + +#include "SystemTable.h" + + +// Actually creating a system table and initialising the systems can have many +// configurations, so we leave this to client code external to this static lib +// However some of the systems do need to refer to each other - the primary +// example being for logging. Hence, the client code should set this pointer +// as soon as it has created a SystemsTable instance and before initialising +// the subsystems. + +// If you want to pass around a SystemsTable without having this variable +// directly accessible, prefer to include just SystemsTable.h + +extern SystemTable * gSys; + +#endif // SYSTEMS_INCLUDED \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/Systems.vcxproj b/3rdparty/RuntimeCompiledCpp/Systems/Systems.vcxproj new file mode 100644 index 0000000..b281ea8 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/Systems.vcxproj @@ -0,0 +1,258 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {BD166836-4A63-47F6-A8A7-A535D99A5F75} + Systems + + + + StaticLibrary + true + Unicode + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + Async + false + $(SolutionDir)\External\glfw\include;$(SolutionDir)\External\libRocket\Include;%(AdditionalIncludeDirectories) + + + true + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + Async + false + $(SolutionDir)\External\glfw\include;$(SolutionDir)\External\libRocket\Include;%(AdditionalIncludeDirectories) + + + true + + + + + + + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + Async + false + _UNICODE;UNICODE;NDEBUG;%(PreprocessorDefinitions) + $(SolutionDir)\External\glfw\include;$(SolutionDir)\External\libRocket\Include;%(AdditionalIncludeDirectories) + + + true + true + true + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + Async + false + _UNICODE;UNICODE;NDEBUG;%(PreprocessorDefinitions) + $(SolutionDir)\External\glfw\include;$(SolutionDir)\External\libRocket\Include;%(AdditionalIncludeDirectories) + + + true + true + true + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/Systems.vcxproj.filters b/3rdparty/RuntimeCompiledCpp/Systems/Systems.vcxproj.filters new file mode 100644 index 0000000..483e016 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/Systems.vcxproj.filters @@ -0,0 +1,167 @@ + + + + + + + + LogSystem\FileLogSystem + + + RocketLibSystem + + + RocketLibSystem + + + RocketLibSystem + + + RocketLibSystem + + + RocketLibSystem + + + RocketLibSystem + + + LogSystem\MultiLogSystem + + + LogSystem\RocketLogSystem + + + EntitySystem + + + + + AssetSystem + + + + + + TimeSystem + + + + + + GUISystem + + + GUISystem + + + GUISystem + + + GUISystem + + + GUISystem + + + LogSystem\ThreadsafeLogSystem + + + + + RocketLibSystem + + + + + {a2f09342-ca30-415a-a4f4-5f65aed7e7d3} + + + {dbef309f-149a-4d6f-a728-5a138009a0b9} + + + {b9fee607-93d1-46b6-b21c-077b3e1b9e69} + + + {43a265e0-16a5-461f-a90a-18e85e98c4c4} + + + {b1b992aa-ab30-4d74-aeaf-b2f0bb0c1032} + + + {152394b1-4150-41bf-8641-3787dc746292} + + + {fd4b086c-b4ba-4507-93e2-840daf3e446f} + + + {9fb3956b-797a-4260-a03d-4466226ed6ff} + + + {29128767-0f84-48de-bfef-d4147561c89f} + + + {5a89aea1-71f8-4761-b0e1-f2af68a89708} + + + + + LogSystem\FileLogSystem + + + RocketLibSystem + + + RocketLibSystem + + + RocketLibSystem + + + RocketLibSystem + + + RocketLibSystem + + + LogSystem\MultiLogSystem + + + LogSystem\RocketLogSystem + + + EntitySystem + + + AssetSystem + + + TimeSystem + + + GUISystem + + + GUISystem + + + GUISystem + + + GUISystem + + + LogSystem\ThreadsafeLogSystem + + + + RocketLibSystem + + + RocketLibSystem + + + + + + \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/Systems.xcodeproj/project.pbxproj b/3rdparty/RuntimeCompiledCpp/Systems/Systems.xcodeproj/project.pbxproj new file mode 100644 index 0000000..63a2f2a --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/Systems.xcodeproj/project.pbxproj @@ -0,0 +1,494 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 911906E31620614900BE48ED /* AssetSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906A01620614900BE48ED /* AssetSystem.cpp */; }; + 911906E41620614900BE48ED /* AssetSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906A11620614900BE48ED /* AssetSystem.h */; }; + 911906E51620614900BE48ED /* EntitySystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906A41620614900BE48ED /* EntitySystem.cpp */; }; + 911906E61620614900BE48ED /* EntitySystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906A51620614900BE48ED /* EntitySystem.h */; }; + 911906E71620614900BE48ED /* GUIDocument.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906A71620614900BE48ED /* GUIDocument.cpp */; }; + 911906E81620614900BE48ED /* GUIDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906A81620614900BE48ED /* GUIDocument.h */; }; + 911906E91620614900BE48ED /* GUIElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906A91620614900BE48ED /* GUIElement.cpp */; }; + 911906EA1620614900BE48ED /* GUIElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906AA1620614900BE48ED /* GUIElement.h */; }; + 911906EB1620614900BE48ED /* GUISystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906AB1620614900BE48ED /* GUISystem.cpp */; }; + 911906EC1620614900BE48ED /* GUISystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906AC1620614900BE48ED /* GUISystem.h */; }; + 911906ED1620614900BE48ED /* IGUIInstancer.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906AD1620614900BE48ED /* IGUIInstancer.h */; }; + 911906EE1620614900BE48ED /* ReferenceCountable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906AE1620614900BE48ED /* ReferenceCountable.cpp */; }; + 911906EF1620614900BE48ED /* ReferenceCountable.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906AF1620614900BE48ED /* ReferenceCountable.h */; }; + 911906F01620614900BE48ED /* IAssetSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906B01620614900BE48ED /* IAssetSystem.h */; }; + 911906F11620614900BE48ED /* IEntity.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906B11620614900BE48ED /* IEntity.h */; }; + 911906F21620614900BE48ED /* IEntitySystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906B21620614900BE48ED /* IEntitySystem.h */; }; + 911906F31620614900BE48ED /* IGame.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906B31620614900BE48ED /* IGame.h */; }; + 911906F41620614900BE48ED /* IGUIDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906B41620614900BE48ED /* IGUIDocument.h */; }; + 911906F51620614900BE48ED /* IGUIElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906B51620614900BE48ED /* IGUIElement.h */; }; + 911906F61620614900BE48ED /* IGUISystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906B61620614900BE48ED /* IGUISystem.h */; }; + 911906F71620614900BE48ED /* ILogSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906B71620614900BE48ED /* ILogSystem.h */; }; + 911906F81620614900BE48ED /* ISystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906B81620614900BE48ED /* ISystem.h */; }; + 911906F91620614900BE48ED /* ITimeSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906B91620614900BE48ED /* ITimeSystem.h */; }; + 911906FA1620614900BE48ED /* IUpdateable.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906BA1620614900BE48ED /* IUpdateable.h */; }; + 911906FB1620614900BE48ED /* FileLogSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906BD1620614900BE48ED /* FileLogSystem.cpp */; }; + 911906FC1620614900BE48ED /* FileLogSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906BE1620614900BE48ED /* FileLogSystem.h */; }; + 911906FD1620614900BE48ED /* MultiLogSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906C01620614900BE48ED /* MultiLogSystem.cpp */; }; + 911906FE1620614900BE48ED /* MultiLogSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906C11620614900BE48ED /* MultiLogSystem.h */; }; + 911906FF1620614900BE48ED /* RocketLogSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906C31620614900BE48ED /* RocketLogSystem.cpp */; }; + 911907001620614900BE48ED /* RocketLogSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906C41620614900BE48ED /* RocketLogSystem.h */; }; + 911907011620614900BE48ED /* ThreadsafeLogSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906C61620614900BE48ED /* ThreadsafeLogSystem.h */; }; + 911907021620614900BE48ED /* ThreadsafeLogSystem_PlatformWindows.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906C71620614900BE48ED /* ThreadsafeLogSystem_PlatformWindows.cpp */; }; + 911907031620614900BE48ED /* Input.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906C91620614900BE48ED /* Input.cpp */; }; + 911907041620614900BE48ED /* Input.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906CA1620614900BE48ED /* Input.h */; }; + 9119070B1620614900BE48ED /* RocketLibSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906D11620614900BE48ED /* RocketLibSystem.cpp */; }; + 9119070C1620614900BE48ED /* RocketLibSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906D21620614900BE48ED /* RocketLibSystem.h */; }; + 9119070D1620614900BE48ED /* RocketLibSystemFileInterface.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906D31620614900BE48ED /* RocketLibSystemFileInterface.cpp */; }; + 9119070E1620614900BE48ED /* RocketLibSystemFileInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906D41620614900BE48ED /* RocketLibSystemFileInterface.h */; }; + 911907101620614900BE48ED /* RocketLibSystemOpenGL.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906D61620614900BE48ED /* RocketLibSystemOpenGL.h */; }; + 911907111620614900BE48ED /* RocketLibSystemRenderInterfaceOpenGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906D71620614900BE48ED /* RocketLibSystemRenderInterfaceOpenGL.cpp */; }; + 911907121620614900BE48ED /* RocketLibSystemRenderInterfaceOpenGL.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906D81620614900BE48ED /* RocketLibSystemRenderInterfaceOpenGL.h */; }; + 911907131620614900BE48ED /* RocketLibSystemSystemInterface.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906D91620614900BE48ED /* RocketLibSystemSystemInterface.cpp */; }; + 911907141620614900BE48ED /* RocketLibSystemSystemInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906DA1620614900BE48ED /* RocketLibSystemSystemInterface.h */; }; + 911907171620614900BE48ED /* Systems.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906DD1620614900BE48ED /* Systems.cpp */; }; + 911907181620614900BE48ED /* Systems.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906DE1620614900BE48ED /* Systems.h */; }; + 911907191620614900BE48ED /* SystemTable.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906DF1620614900BE48ED /* SystemTable.h */; }; + 9119071A1620614900BE48ED /* TimeSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911906E11620614900BE48ED /* TimeSystem.cpp */; }; + 9119071B1620614900BE48ED /* TimeSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 911906E21620614900BE48ED /* TimeSystem.h */; }; + 9170EAE71622E32E00273B92 /* InputGLFW.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9170EAE41622E32E00273B92 /* InputGLFW.cpp */; }; + 9170EAE81622E32E00273B92 /* InputGLFW.h in Headers */ = {isa = PBXBuildFile; fileRef = 9170EAE51622E32E00273B92 /* InputGLFW.h */; }; + 9170EAE91622E32E00273B92 /* RocketLibSystemGLFW.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9170EAE61622E32E00273B92 /* RocketLibSystemGLFW.cpp */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 91045332162060F40068AA25 /* libSystems.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libSystems.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 911906A01620614900BE48ED /* AssetSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AssetSystem.cpp; sourceTree = ""; }; + 911906A11620614900BE48ED /* AssetSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AssetSystem.h; sourceTree = ""; }; + 911906A21620614900BE48ED /* Definitions.inl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Definitions.inl; sourceTree = ""; }; + 911906A41620614900BE48ED /* EntitySystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EntitySystem.cpp; sourceTree = ""; }; + 911906A51620614900BE48ED /* EntitySystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EntitySystem.h; sourceTree = ""; }; + 911906A71620614900BE48ED /* GUIDocument.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GUIDocument.cpp; sourceTree = ""; }; + 911906A81620614900BE48ED /* GUIDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GUIDocument.h; sourceTree = ""; }; + 911906A91620614900BE48ED /* GUIElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GUIElement.cpp; sourceTree = ""; }; + 911906AA1620614900BE48ED /* GUIElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GUIElement.h; sourceTree = ""; }; + 911906AB1620614900BE48ED /* GUISystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GUISystem.cpp; sourceTree = ""; }; + 911906AC1620614900BE48ED /* GUISystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GUISystem.h; sourceTree = ""; }; + 911906AD1620614900BE48ED /* IGUIInstancer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGUIInstancer.h; sourceTree = ""; }; + 911906AE1620614900BE48ED /* ReferenceCountable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReferenceCountable.cpp; sourceTree = ""; }; + 911906AF1620614900BE48ED /* ReferenceCountable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReferenceCountable.h; sourceTree = ""; }; + 911906B01620614900BE48ED /* IAssetSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IAssetSystem.h; sourceTree = ""; }; + 911906B11620614900BE48ED /* IEntity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IEntity.h; sourceTree = ""; }; + 911906B21620614900BE48ED /* IEntitySystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IEntitySystem.h; sourceTree = ""; }; + 911906B31620614900BE48ED /* IGame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGame.h; sourceTree = ""; }; + 911906B41620614900BE48ED /* IGUIDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGUIDocument.h; sourceTree = ""; }; + 911906B51620614900BE48ED /* IGUIElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGUIElement.h; sourceTree = ""; }; + 911906B61620614900BE48ED /* IGUISystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGUISystem.h; sourceTree = ""; }; + 911906B71620614900BE48ED /* ILogSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ILogSystem.h; sourceTree = ""; }; + 911906B81620614900BE48ED /* ISystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ISystem.h; sourceTree = ""; }; + 911906B91620614900BE48ED /* ITimeSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ITimeSystem.h; sourceTree = ""; }; + 911906BA1620614900BE48ED /* IUpdateable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IUpdateable.h; sourceTree = ""; }; + 911906BD1620614900BE48ED /* FileLogSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileLogSystem.cpp; sourceTree = ""; }; + 911906BE1620614900BE48ED /* FileLogSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileLogSystem.h; sourceTree = ""; }; + 911906C01620614900BE48ED /* MultiLogSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MultiLogSystem.cpp; sourceTree = ""; }; + 911906C11620614900BE48ED /* MultiLogSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MultiLogSystem.h; sourceTree = ""; }; + 911906C31620614900BE48ED /* RocketLogSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RocketLogSystem.cpp; sourceTree = ""; }; + 911906C41620614900BE48ED /* RocketLogSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RocketLogSystem.h; sourceTree = ""; }; + 911906C61620614900BE48ED /* ThreadsafeLogSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadsafeLogSystem.h; sourceTree = ""; }; + 911906C71620614900BE48ED /* ThreadsafeLogSystem_PlatformWindows.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadsafeLogSystem_PlatformWindows.cpp; sourceTree = ""; }; + 911906C91620614900BE48ED /* Input.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Input.cpp; sourceTree = ""; }; + 911906CA1620614900BE48ED /* Input.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Input.h; sourceTree = ""; }; + 911906D11620614900BE48ED /* RocketLibSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RocketLibSystem.cpp; sourceTree = ""; }; + 911906D21620614900BE48ED /* RocketLibSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RocketLibSystem.h; sourceTree = ""; }; + 911906D31620614900BE48ED /* RocketLibSystemFileInterface.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RocketLibSystemFileInterface.cpp; sourceTree = ""; }; + 911906D41620614900BE48ED /* RocketLibSystemFileInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RocketLibSystemFileInterface.h; sourceTree = ""; }; + 911906D61620614900BE48ED /* RocketLibSystemOpenGL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RocketLibSystemOpenGL.h; sourceTree = ""; }; + 911906D71620614900BE48ED /* RocketLibSystemRenderInterfaceOpenGL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RocketLibSystemRenderInterfaceOpenGL.cpp; sourceTree = ""; }; + 911906D81620614900BE48ED /* RocketLibSystemRenderInterfaceOpenGL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RocketLibSystemRenderInterfaceOpenGL.h; sourceTree = ""; }; + 911906D91620614900BE48ED /* RocketLibSystemSystemInterface.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RocketLibSystemSystemInterface.cpp; sourceTree = ""; }; + 911906DA1620614900BE48ED /* RocketLibSystemSystemInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RocketLibSystemSystemInterface.h; sourceTree = ""; }; + 911906DD1620614900BE48ED /* Systems.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Systems.cpp; sourceTree = ""; }; + 911906DE1620614900BE48ED /* Systems.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Systems.h; sourceTree = ""; }; + 911906DF1620614900BE48ED /* SystemTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SystemTable.h; sourceTree = ""; }; + 911906E11620614900BE48ED /* TimeSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TimeSystem.cpp; sourceTree = ""; }; + 911906E21620614900BE48ED /* TimeSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TimeSystem.h; sourceTree = ""; }; + 9170EAE41622E32E00273B92 /* InputGLFW.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InputGLFW.cpp; sourceTree = ""; }; + 9170EAE51622E32E00273B92 /* InputGLFW.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InputGLFW.h; sourceTree = ""; }; + 9170EAE61622E32E00273B92 /* RocketLibSystemGLFW.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RocketLibSystemGLFW.cpp; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 9104532F162060F40068AA25 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 91045327162060F40068AA25 = { + isa = PBXGroup; + children = ( + 9119069F1620614900BE48ED /* AssetSystem */, + 911906A21620614900BE48ED /* Definitions.inl */, + 911906A31620614900BE48ED /* EntitySystem */, + 911906A61620614900BE48ED /* GUISystem */, + 911906B01620614900BE48ED /* IAssetSystem.h */, + 911906B11620614900BE48ED /* IEntity.h */, + 911906B21620614900BE48ED /* IEntitySystem.h */, + 911906B31620614900BE48ED /* IGame.h */, + 911906B41620614900BE48ED /* IGUIDocument.h */, + 911906B51620614900BE48ED /* IGUIElement.h */, + 911906B61620614900BE48ED /* IGUISystem.h */, + 911906B71620614900BE48ED /* ILogSystem.h */, + 911906B81620614900BE48ED /* ISystem.h */, + 911906B91620614900BE48ED /* ITimeSystem.h */, + 911906BA1620614900BE48ED /* IUpdateable.h */, + 911906BB1620614900BE48ED /* LogSystem */, + 911906C81620614900BE48ED /* RocketLibSystem */, + 911906DD1620614900BE48ED /* Systems.cpp */, + 911906DE1620614900BE48ED /* Systems.h */, + 911906DF1620614900BE48ED /* SystemTable.h */, + 911906E01620614900BE48ED /* TimeSystem */, + 91045333162060F40068AA25 /* Products */, + ); + sourceTree = ""; + }; + 91045333162060F40068AA25 /* Products */ = { + isa = PBXGroup; + children = ( + 91045332162060F40068AA25 /* libSystems.a */, + ); + name = Products; + sourceTree = ""; + }; + 9119069F1620614900BE48ED /* AssetSystem */ = { + isa = PBXGroup; + children = ( + 911906A01620614900BE48ED /* AssetSystem.cpp */, + 911906A11620614900BE48ED /* AssetSystem.h */, + ); + path = AssetSystem; + sourceTree = ""; + }; + 911906A31620614900BE48ED /* EntitySystem */ = { + isa = PBXGroup; + children = ( + 911906A41620614900BE48ED /* EntitySystem.cpp */, + 911906A51620614900BE48ED /* EntitySystem.h */, + ); + path = EntitySystem; + sourceTree = ""; + }; + 911906A61620614900BE48ED /* GUISystem */ = { + isa = PBXGroup; + children = ( + 911906A71620614900BE48ED /* GUIDocument.cpp */, + 911906A81620614900BE48ED /* GUIDocument.h */, + 911906A91620614900BE48ED /* GUIElement.cpp */, + 911906AA1620614900BE48ED /* GUIElement.h */, + 911906AB1620614900BE48ED /* GUISystem.cpp */, + 911906AC1620614900BE48ED /* GUISystem.h */, + 911906AD1620614900BE48ED /* IGUIInstancer.h */, + 911906AE1620614900BE48ED /* ReferenceCountable.cpp */, + 911906AF1620614900BE48ED /* ReferenceCountable.h */, + ); + path = GUISystem; + sourceTree = ""; + }; + 911906BB1620614900BE48ED /* LogSystem */ = { + isa = PBXGroup; + children = ( + 911906BC1620614900BE48ED /* FileLogSystem */, + 911906BF1620614900BE48ED /* MultiLogSystem */, + 911906C21620614900BE48ED /* RocketLogSystem */, + 911906C51620614900BE48ED /* ThreadsafeLogSystem */, + ); + path = LogSystem; + sourceTree = ""; + }; + 911906BC1620614900BE48ED /* FileLogSystem */ = { + isa = PBXGroup; + children = ( + 911906BD1620614900BE48ED /* FileLogSystem.cpp */, + 911906BE1620614900BE48ED /* FileLogSystem.h */, + ); + path = FileLogSystem; + sourceTree = ""; + }; + 911906BF1620614900BE48ED /* MultiLogSystem */ = { + isa = PBXGroup; + children = ( + 911906C01620614900BE48ED /* MultiLogSystem.cpp */, + 911906C11620614900BE48ED /* MultiLogSystem.h */, + ); + path = MultiLogSystem; + sourceTree = ""; + }; + 911906C21620614900BE48ED /* RocketLogSystem */ = { + isa = PBXGroup; + children = ( + 911906C31620614900BE48ED /* RocketLogSystem.cpp */, + 911906C41620614900BE48ED /* RocketLogSystem.h */, + ); + path = RocketLogSystem; + sourceTree = ""; + }; + 911906C51620614900BE48ED /* ThreadsafeLogSystem */ = { + isa = PBXGroup; + children = ( + 911906C61620614900BE48ED /* ThreadsafeLogSystem.h */, + 911906C71620614900BE48ED /* ThreadsafeLogSystem_PlatformWindows.cpp */, + ); + path = ThreadsafeLogSystem; + sourceTree = ""; + }; + 911906C81620614900BE48ED /* RocketLibSystem */ = { + isa = PBXGroup; + children = ( + 9170EAE41622E32E00273B92 /* InputGLFW.cpp */, + 9170EAE51622E32E00273B92 /* InputGLFW.h */, + 9170EAE61622E32E00273B92 /* RocketLibSystemGLFW.cpp */, + 911906C91620614900BE48ED /* Input.cpp */, + 911906CA1620614900BE48ED /* Input.h */, + 911906D11620614900BE48ED /* RocketLibSystem.cpp */, + 911906D21620614900BE48ED /* RocketLibSystem.h */, + 911906D31620614900BE48ED /* RocketLibSystemFileInterface.cpp */, + 911906D41620614900BE48ED /* RocketLibSystemFileInterface.h */, + 911906D61620614900BE48ED /* RocketLibSystemOpenGL.h */, + 911906D71620614900BE48ED /* RocketLibSystemRenderInterfaceOpenGL.cpp */, + 911906D81620614900BE48ED /* RocketLibSystemRenderInterfaceOpenGL.h */, + 911906D91620614900BE48ED /* RocketLibSystemSystemInterface.cpp */, + 911906DA1620614900BE48ED /* RocketLibSystemSystemInterface.h */, + ); + path = RocketLibSystem; + sourceTree = ""; + }; + 911906E01620614900BE48ED /* TimeSystem */ = { + isa = PBXGroup; + children = ( + 911906E11620614900BE48ED /* TimeSystem.cpp */, + 911906E21620614900BE48ED /* TimeSystem.h */, + ); + path = TimeSystem; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 91045330162060F40068AA25 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 911906E41620614900BE48ED /* AssetSystem.h in Headers */, + 911906E61620614900BE48ED /* EntitySystem.h in Headers */, + 911906E81620614900BE48ED /* GUIDocument.h in Headers */, + 911906EA1620614900BE48ED /* GUIElement.h in Headers */, + 911906EC1620614900BE48ED /* GUISystem.h in Headers */, + 911906ED1620614900BE48ED /* IGUIInstancer.h in Headers */, + 911906EF1620614900BE48ED /* ReferenceCountable.h in Headers */, + 911906F01620614900BE48ED /* IAssetSystem.h in Headers */, + 911906F11620614900BE48ED /* IEntity.h in Headers */, + 911906F21620614900BE48ED /* IEntitySystem.h in Headers */, + 911906F31620614900BE48ED /* IGame.h in Headers */, + 911906F41620614900BE48ED /* IGUIDocument.h in Headers */, + 911906F51620614900BE48ED /* IGUIElement.h in Headers */, + 911906F61620614900BE48ED /* IGUISystem.h in Headers */, + 911906F71620614900BE48ED /* ILogSystem.h in Headers */, + 911906F81620614900BE48ED /* ISystem.h in Headers */, + 911906F91620614900BE48ED /* ITimeSystem.h in Headers */, + 911906FA1620614900BE48ED /* IUpdateable.h in Headers */, + 911906FC1620614900BE48ED /* FileLogSystem.h in Headers */, + 911906FE1620614900BE48ED /* MultiLogSystem.h in Headers */, + 911907001620614900BE48ED /* RocketLogSystem.h in Headers */, + 911907011620614900BE48ED /* ThreadsafeLogSystem.h in Headers */, + 911907041620614900BE48ED /* Input.h in Headers */, + 9119070C1620614900BE48ED /* RocketLibSystem.h in Headers */, + 9119070E1620614900BE48ED /* RocketLibSystemFileInterface.h in Headers */, + 911907101620614900BE48ED /* RocketLibSystemOpenGL.h in Headers */, + 911907121620614900BE48ED /* RocketLibSystemRenderInterfaceOpenGL.h in Headers */, + 911907141620614900BE48ED /* RocketLibSystemSystemInterface.h in Headers */, + 911907181620614900BE48ED /* Systems.h in Headers */, + 911907191620614900BE48ED /* SystemTable.h in Headers */, + 9119071B1620614900BE48ED /* TimeSystem.h in Headers */, + 9170EAE81622E32E00273B92 /* InputGLFW.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 91045331162060F40068AA25 /* Systems */ = { + isa = PBXNativeTarget; + buildConfigurationList = 91045336162060F40068AA25 /* Build configuration list for PBXNativeTarget "Systems" */; + buildPhases = ( + 9104532E162060F40068AA25 /* Sources */, + 9104532F162060F40068AA25 /* Frameworks */, + 91045330162060F40068AA25 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Systems; + productName = Systems; + productReference = 91045332162060F40068AA25 /* libSystems.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 91045329162060F40068AA25 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0440; + ORGANIZATIONNAME = "Doug Binks"; + }; + buildConfigurationList = 9104532C162060F40068AA25 /* Build configuration list for PBXProject "Systems" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 91045327162060F40068AA25; + productRefGroup = 91045333162060F40068AA25 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 91045331162060F40068AA25 /* Systems */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 9104532E162060F40068AA25 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 911906E31620614900BE48ED /* AssetSystem.cpp in Sources */, + 911906E51620614900BE48ED /* EntitySystem.cpp in Sources */, + 911906E71620614900BE48ED /* GUIDocument.cpp in Sources */, + 911906E91620614900BE48ED /* GUIElement.cpp in Sources */, + 911906EB1620614900BE48ED /* GUISystem.cpp in Sources */, + 911906EE1620614900BE48ED /* ReferenceCountable.cpp in Sources */, + 911906FB1620614900BE48ED /* FileLogSystem.cpp in Sources */, + 911906FD1620614900BE48ED /* MultiLogSystem.cpp in Sources */, + 911906FF1620614900BE48ED /* RocketLogSystem.cpp in Sources */, + 911907021620614900BE48ED /* ThreadsafeLogSystem_PlatformWindows.cpp in Sources */, + 911907031620614900BE48ED /* Input.cpp in Sources */, + 9119070B1620614900BE48ED /* RocketLibSystem.cpp in Sources */, + 9119070D1620614900BE48ED /* RocketLibSystemFileInterface.cpp in Sources */, + 911907111620614900BE48ED /* RocketLibSystemRenderInterfaceOpenGL.cpp in Sources */, + 911907131620614900BE48ED /* RocketLibSystemSystemInterface.cpp in Sources */, + 911907171620614900BE48ED /* Systems.cpp in Sources */, + 9119071A1620614900BE48ED /* TimeSystem.cpp in Sources */, + 9170EAE71622E32E00273B92 /* InputGLFW.cpp in Sources */, + 9170EAE91622E32E00273B92 /* RocketLibSystemGLFW.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 91045334162060F40068AA25 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.8; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + 91045335162060F40068AA25 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.8; + SDKROOT = macosx; + }; + name = Release; + }; + 91045337162060F40068AA25 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + EXECUTABLE_PREFIX = lib; + HEADER_SEARCH_PATHS = ( + ../External/libRocket/Include, + ../External/boost/, + ../External/glfw/include, + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = ""; + }; + name = Debug; + }; + 91045338162060F40068AA25 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + EXECUTABLE_PREFIX = lib; + HEADER_SEARCH_PATHS = ( + ../External/libRocket/Include, + ../External/boost/, + ../External/glfw/include, + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = ""; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 9104532C162060F40068AA25 /* Build configuration list for PBXProject "Systems" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 91045334162060F40068AA25 /* Debug */, + 91045335162060F40068AA25 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 91045336162060F40068AA25 /* Build configuration list for PBXNativeTarget "Systems" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 91045337162060F40068AA25 /* Debug */, + 91045338162060F40068AA25 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 91045329162060F40068AA25 /* Project object */; +} diff --git a/3rdparty/RuntimeCompiledCpp/Systems/Systems.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/3rdparty/RuntimeCompiledCpp/Systems/Systems.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..a4621db --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/Systems.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/3rdparty/RuntimeCompiledCpp/Systems/TimeSystem/TimeSystem.cpp b/3rdparty/RuntimeCompiledCpp/Systems/TimeSystem/TimeSystem.cpp new file mode 100644 index 0000000..deb16b4 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/TimeSystem/TimeSystem.cpp @@ -0,0 +1,178 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "TimeSystem.h" + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include "Windows.h" // For QueryPerformanceCounter +#else +#include +#include +#endif +#include "assert.h" +#include + +/* + I'm not certain if I'm using the best datatype here for storing the time, and I suspect the divisions could be put off. + However, it should be more than accurate enough and it is all hidden behind an interface that just presents seconds as doubles. + Later, this might be worth a rewrite to be really hygenic. + Returning a 64-bit integer format would also be desirable. + There is some duplication around pausing. +*/ + +TimeSystem::TimeSystem(void) +{ + m_dSmoothFrameDuration = 0.01f; // Assume 100Hz for smoothing to start with + +#ifdef _WIN32 // Note that IIRC this can change with CPU frequency. Demoing on laptops remember! + QueryPerformanceFrequency( (LARGE_INTEGER*) &m_iPerformanceFreq ); + assert(m_iPerformanceFreq); // Consider quitting with error +#endif + Reset(); +} + +TimeSystem::~TimeSystem(void) +{} + +void TimeSystem::StartSession() +{ + assert(!m_bWithinSession); + Reset(); // Reset the universe + m_dSessionStartRaw = GetRawTime(); + m_bWithinSession = true; +} + +void TimeSystem::EndSession() +{ + assert(m_bWithinSession); + Reset(); // Reset the universe + m_bWithinSession = false; +} + +void TimeSystem::StartFrame() +{ + assert(!m_bWithinFrame); + + double dSessionTime= GetSessionTimeNow(); + + //Update last frame duration + m_dLastFrameDuration = dSessionTime - m_dFrameSessionTime; + m_dSmoothFrameDuration = (m_dSmoothFrameDuration * 0.9 + m_dLastFrameDuration * 0.1); + + + // Update total time + m_dFrameSessionTime = dSessionTime; + + //Update unpaused time + double dTotalPausedTime = m_dSessionPausedTime; // A "small" number + if (m_bPaused) + dTotalPausedTime += (m_dFrameSessionTime - m_dPausedSince); // small + (large - large) + m_dFramePlayTime = m_dFrameSessionTime - dTotalPausedTime; + + // Handle pause status + if (m_bPaused != m_bPausedNextFrame) + { + if (m_bPausedNextFrame) + { + m_dPausedSince = m_dFrameSessionTime; + } + else + { + m_dSessionPausedTime = dTotalPausedTime; + m_dPausedSince = 0.0f; // Just for clarity + } + m_bPaused = m_bPausedNextFrame; + } + + m_bWithinFrame = true; +} + + +void TimeSystem::EndFrame() +{ + assert(m_bWithinFrame); + + m_bWithinFrame = false; +} + +bool TimeSystem::IsPaused() const +{ return m_bPaused; } + +void TimeSystem::Pause(bool bPause) +{ + assert(!m_bWithinFrame); + + // This is all we do here - we can't adjust timers because in principle, we don't know when the next frame will start. + m_bPausedNextFrame = bPause; +} + +double TimeSystem::GetFramePlayTime() const +{ return m_dFramePlayTime; } + +double TimeSystem::GetFrameSessionTime() const +{ return m_dFrameSessionTime; } + +double TimeSystem::GetPlayTimeNow() const +{ + // Quite unhappy with this + double dSessionTime = GetSessionTimeNow(); + double dTotalPausedTime = m_dSessionPausedTime; // A "small" number + if (m_bPaused) + dTotalPausedTime += (dSessionTime - m_dPausedSince); // small + (large - large) + return dSessionTime - dTotalPausedTime; +} + +double TimeSystem::GetSessionTimeNow() const +{ + return GetRawTime() - m_dSessionStartRaw; +} + +double TimeSystem::GetFrameTimeNow() const +{ + return GetSessionTimeNow() - m_dFrameSessionTime; +} + +double TimeSystem::GetLastFrameDuration() const +{ return m_dLastFrameDuration; } + +double TimeSystem::GetSmoothFrameDuration() const +{ return m_dSmoothFrameDuration; } + + +double TimeSystem::GetRawTime() const +{ + + double seconds = glfwGetTime(); + + return seconds; +} + +void TimeSystem::Reset() +{ + m_dSessionStartRaw = 0.0f; + m_dFramePlayTime = 0.0f; + m_dFrameSessionTime = 0.0f; + m_dPausedSince = 0.0f; + m_dSessionPausedTime = 0.0f; + m_dLastFrameDuration = 0.0f; + // Leave the smoothed time alone + m_bWithinSession = false; + m_bWithinFrame = false; + m_bPaused = false; + m_bPausedNextFrame = false; +} \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/Systems/TimeSystem/TimeSystem.h b/3rdparty/RuntimeCompiledCpp/Systems/TimeSystem/TimeSystem.h new file mode 100644 index 0000000..c380d32 --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/TimeSystem/TimeSystem.h @@ -0,0 +1,72 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#include "../ITimeSystem.h" + +// Consider adding a subclassed version that know about logging + +class TimeSystem : public ITimeSystem +{ +public: + TimeSystem(); + ~TimeSystem(); + + // IsWithinSession + void StartSession(); + void EndSession(); + + // IsWithinFrame + void StartFrame(); + void EndFrame(); + + bool IsPaused() const; + void Pause(bool bPause); + + double GetFramePlayTime() const; + double GetFrameSessionTime() const; + + double GetPlayTimeNow() const; + double GetSessionTimeNow() const; + double GetFrameTimeNow() const; + + double GetLastFrameDuration() const; + double GetSmoothFrameDuration() const; + +private: + + void Reset(); + double GetRawTime() const; + + // All refer to the start of the current frame. The _current_ time values are obviously not worth storing. + double m_dSessionStartRaw; // The the "real" time that the session started + double m_dFramePlayTime; // How much unpaused time had elapsed when we started the frame? + double m_dFrameSessionTime; // How much total time had elapsed... + double m_dPausedSince; // + double m_dSessionPausedTime;// Accumulated paused time this session, up to the last time we unpaused. Is this too unhygenic? + double m_dLastFrameDuration; // How long did the last frame actually take? + double m_dSmoothFrameDuration; // How long do we guess this frame will take? + + bool m_bWithinSession, m_bWithinFrame; + bool m_bPaused, m_bPausedNextFrame; + +#ifdef _WIN32 + typedef __int64 INT64; + INT64 m_iPerformanceFreq; // Divisor for performance frequency values +#endif +}; diff --git a/3rdparty/RuntimeCompiledCpp/Systems/readme.txt b/3rdparty/RuntimeCompiledCpp/Systems/readme.txt new file mode 100644 index 0000000..219476d --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/Systems/readme.txt @@ -0,0 +1,12 @@ +Systems +======= + +A system is a piece of functionality that implements the simple ISystem.h interface. + +Each kind of module should have: + - an abtract interface in the Systems folder (e.g. ILogging.h) + - a folder for its implementations (e.g. Logging) + +A system can in principle have multiple interchangable implementations. +Each implementation folder should have: + - a subfolder for each concrete implementation (e.g. FileLogger) \ No newline at end of file diff --git a/3rdparty/RuntimeCompiledCpp/cmake/ProjectFiles.cmake b/3rdparty/RuntimeCompiledCpp/cmake/ProjectFiles.cmake new file mode 100644 index 0000000..5ffb3cc --- /dev/null +++ b/3rdparty/RuntimeCompiledCpp/cmake/ProjectFiles.cmake @@ -0,0 +1,64 @@ + +# +# RuntimeCompiler Source +# + +aux_source_directory(RuntimeCompiler RuntimeCompiler_SRCS) +aux_source_directory(RuntimeCompiler/SimpleFileWatcher SimpleFileWatcher_SRCS) + +if(UNIX) + list(REMOVE_ITEM RuntimeCompiler_SRCS "RuntimeCompiler/Compiler_PlatformWindows.cpp") + list(REMOVE_ITEM SimpleFileWatcher_SRCS "RuntimeCompiler/SimpleFileWatcher/FileWatcherWin32.cpp") + if(APPLE) + list(REMOVE_ITEM SimpleFileWatcher_SRCS "RuntimeCompiler/SimpleFileWatcher/FileWatcherLinux.cpp") + else() + list(REMOVE_ITEM SimpleFileWatcher_SRCS "RuntimeCompiler/SimpleFileWatcher/FileWatcherOSX.cpp") + endif() +else() + list(REMOVE_ITEM RuntimeCompiler_SRCS "RuntimeCompiler/Compiler_PlatformPosix.cpp") + list(REMOVE_ITEM SimpleFileWatcher_SRCS "RuntimeCompiler/SimpleFileWatcher/FileWatcherOSX.cpp") + list(REMOVE_ITEM SimpleFileWatcher_SRCS "RuntimeCompiler/SimpleFileWatcher/FileWatcherLinux.cpp") +endif() + +set(RuntimeCompiler_SRCS ${RuntimeCompiler_SRCS} ${SimpleFileWatcher_SRCS}) + +# +# RuntimeObjectSystem Source +# + +aux_source_directory(RuntimeObjectSystem RuntimeObjectSystem_SRCS) +aux_source_directory(RuntimeObjectSystem/ObjectFactorySystem ObjectFactorySystem_SRCS) +aux_source_directory(RuntimeObjectSystem/SimpleSerializer SimpleSerializer_SRCS) + +set(RuntimeCompiler_SRCS ${RuntimeCompiler_SRCS} ${ObjectFactorySystem_SRCS} ${SimpleSerializer_SRCS}) + +if(UNIX) + list(REMOVE_ITEM RuntimeObjectSystem_SRCS "RuntimeObjectSystem/RuntimeObjectSystem_PlatformWindows.cpp") +else() + list(REMOVE_ITEM RuntimeObjectSystem_SRCS "RuntimeObjectSystem/RuntimeObjectSystem_PlatformPosix.cpp") +endif() + +# +# Example applications +# + +if(BUILD_EXAMPLES) + # + # ConsoleExample Source + # + aux_source_directory(Examples/ConsoleExample ConsoleExample_SRCS) + # + # SimpleTest Source + # + aux_source_directory(Examples/SimpleTest SimpleTest_SRCS) + # + # Renderer Source + # + aux_source_directory(Renderer Renderer_SRCS) + # + # Systems Source + # + #aux_source_directory(Systems Systems_SRCS) + file(GLOB_RECURSE Systems_SRCS "Systems/*.cpp") +endif() + diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ccb2c0..4b0c612 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ INCLUDE_DIRECTORIES ( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src + ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty ) FIND_PACKAGE (X11 REQUIRED) @@ -61,6 +62,9 @@ SET ( protot_SRCS src/shaderc_glsl.cpp src/shaderc_hlsl.cpp + src/Scene.cc + src/SceneObject.cpp + 3rdparty/glfw/deps/glad.c ) @@ -77,6 +81,27 @@ file(GLOB glcpp-library_sources list(REMOVE_ITEM glcpp-library_sources ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/bgfx/3rdparty/glsl-optimizer/src/glsl/main.cpp) +ADD_LIBRARY (RuntimeCompiledCpp + 3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectInterfacePerModuleSource.cpp + 3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem_PlatformPosix.cpp + 3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.cpp + 3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.cpp + + 3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/ObjectFactorySystem/ObjectFactorySystem.cpp + + 3rdparty/RuntimeCompiledCpp/RuntimeObjectSystem/SimpleSerializer/SimpleSerializer.cpp + + 3rdparty/RuntimeCompiledCpp/RuntimeCompiler/BuildTool.cpp + 3rdparty/RuntimeCompiledCpp/RuntimeCompiler/Compiler_PlatformPosix.cpp + 3rdparty/RuntimeCompiledCpp/RuntimeCompiler/FileChangeNotifier.cpp + + 3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcher.cpp + 3rdparty/RuntimeCompiledCpp/RuntimeCompiler/SimpleFileWatcher/FileWatcherLinux.cpp + + 3rdparty/RuntimeCompiledCpp/Examples/ConsoleExample/StdioLogSystem.cpp + + ) + ADD_LIBRARY (glsl-optimizer ${glcpp-library_sources} @@ -118,6 +143,5 @@ TARGET_LINK_LIBRARIES ( protot bgfx bgfx_aux glsl-optimizer - gcc_s - gcc + RuntimeCompiledCpp ) diff --git a/src/Renderer.cc b/src/Renderer.cc index 36099b7..25c44b1 100644 --- a/src/Renderer.cc +++ b/src/Renderer.cc @@ -20,6 +20,10 @@ #include "math_types.h" +#include "Scene.h" + +// BGFX globals + bgfx::VertexBufferHandle cube_vbh; bgfx::IndexBufferHandle cube_ibh; bgfx::IndexBufferHandle cube_edges_ibh; @@ -461,6 +465,8 @@ class BGFXCallbacks: public bgfx::CallbackI { }; }; +Scene scene; + void Renderer::initialize(int width, int height) { this->width = width; this->height = height; @@ -528,6 +534,8 @@ void Renderer::initialize(int width, int height) { initialized = true; resize (width, height); bgfx::frame(); + + scene.init(); } void Renderer::shutdown() { @@ -597,6 +605,8 @@ void Renderer::paintGLSimple() { bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Initialization and debug text."); bgfx::dbgTextPrintf(0, 3, 0x8f, "Frame: % 7.3f[ms]", double(frameTime)*toMs); + scene.update(); + // Advance to next frame. Rendering thread will be kicked to // process submitted rendering primitives. bgfx::frame(); diff --git a/src/Scene.cc b/src/Scene.cc new file mode 100644 index 0000000..c99a7e8 --- /dev/null +++ b/src/Scene.cc @@ -0,0 +1,107 @@ +#include "Scene.h" + +// Runtime Compiled Cpp +#include "RuntimeCompiledCpp/RuntimeObjectSystem/IObjectFactorySystem.h" +#include "RuntimeCompiledCpp/RuntimeObjectSystem/ObjectInterface.h" +#include "RuntimeCompiledCpp/RuntimeCompiler/AUArray.h" + +#include "RuntimeCompiledCpp/RuntimeCompiler/BuildTool.h" +#include "RuntimeCompiledCpp/RuntimeCompiler/ICompilerLogger.h" +#include "RuntimeCompiledCpp/RuntimeCompiler/FileChangeNotifier.h" +#include "RuntimeCompiledCpp/RuntimeObjectSystem/IObjectFactorySystem.h" +#include "RuntimeCompiledCpp/RuntimeObjectSystem/ObjectFactorySystem/ObjectFactorySystem.h" +#include "RuntimeCompiledCpp/RuntimeObjectSystem/RuntimeObjectSystem.h" + +#include "RuntimeCompiledCpp/RuntimeObjectSystem/IObject.h" + +#include "rcpp/StdioLogSystem.h" +#include "rcpp/IUpdateable.h" + +// for sleep +#include +#include + + +#include + +using namespace std; + +Scene::Scene() : + mCompilerLogger(nullptr), + mRuntimeObjectSystem(nullptr), + mUpdateable(nullptr) { +} + +Scene::~Scene() { + if (mRuntimeObjectSystem != nullptr) { + mRuntimeObjectSystem->CleanObjectFiles(); + } + + if (mRuntimeObjectSystem && mRuntimeObjectSystem->GetObjectFactorySystem()) { + mRuntimeObjectSystem->GetObjectFactorySystem()->RemoveListener(this); + + // delete object via correct interface + IObject* obj = mRuntimeObjectSystem->GetObjectFactorySystem()->GetObject( mObjectId ); + delete obj; + } + + delete mRuntimeObjectSystem; + delete mCompilerLogger; +} + +bool Scene::init() { + mRuntimeObjectSystem = new RuntimeObjectSystem; + mCompilerLogger = new StdioLogSystem(); + + if (!mRuntimeObjectSystem->Initialise(mCompilerLogger, 0)) { + mRuntimeObjectSystem = nullptr; + return false; + } + + mRuntimeObjectSystem->GetObjectFactorySystem()->AddListener(this); + + // construct an object + IObjectConstructor* constructor = mRuntimeObjectSystem->GetObjectFactorySystem()->GetConstructor("SceneObject"); + if (constructor) { + IObject* obj = constructor->Construct(); + obj->GetInterface(&mUpdateable); + + if (nullptr == mUpdateable) { + delete obj; + mCompilerLogger->LogError("Error - no updateable interface found!\n"); + return false; + } + + mObjectId = obj->GetObjectId(); + } + + return true; +} + +void Scene::OnConstructorsAdded() { + if (mUpdateable) { + IObject* obj = mRuntimeObjectSystem->GetObjectFactorySystem()->GetObject(mObjectId); + obj->GetInterface(&mUpdateable); + + if (nullptr == mUpdateable) { + delete obj; + mCompilerLogger->LogError("Error - no updateable interface found!\n"); + } + } +} + +void Scene::update() { + if (mRuntimeObjectSystem->GetIsCompiledComplete()) { + mRuntimeObjectSystem->LoadCompiledModule(); + } + + if (!mRuntimeObjectSystem->GetIsCompiling()) { + static int num_updates = 0; + std::cout << "Main loop. num_updates = " << num_updates << "\n"; + + const float delta_time = 1.0f; + mRuntimeObjectSystem->GetFileChangeNotifier()->Update(delta_time); + mUpdateable->Update(delta_time); + usleep(1000 * 1000); + } +} diff --git a/src/Scene.h b/src/Scene.h new file mode 100644 index 0000000..fe1c910 --- /dev/null +++ b/src/Scene.h @@ -0,0 +1,22 @@ +#pragma once + +#include "RuntimeCompiledCpp/RuntimeObjectSystem/IObjectFactorySystem.h" +#include "RuntimeCompiledCpp/RuntimeObjectSystem/ObjectInterface.h" + +struct IUpdateable; +struct IRuntimeObjectSystem; + +struct Scene : IObjectFactoryListener { + ICompilerLogger* mCompilerLogger; + IRuntimeObjectSystem* mRuntimeObjectSystem; + + IUpdateable* mUpdateable; + ObjectId mObjectId; + + Scene(); + virtual ~Scene(); + + bool init(); + void OnConstructorsAdded(); + void update (); +}; diff --git a/src/SceneObject.cpp b/src/SceneObject.cpp new file mode 100644 index 0000000..afe2740 --- /dev/null +++ b/src/SceneObject.cpp @@ -0,0 +1,18 @@ +#include "RuntimeCompiledCpp/RuntimeObjectSystem/ObjectInterfacePerModule.h" +#include "RuntimeCompiledCpp/RuntimeObjectSystem/IObject.h" + +#include "rcpp/IUpdateable.h" +#include "rcpp/InterfaceIds.h" +#include + + +class SceneObject : public TInterface +{ +public: + virtual void Update( float deltaTime ) + { + std::cout << "Runtime Object 01 update called!\n"; + } +}; + +REGISTERCLASS(SceneObject); diff --git a/src/SceneObject.h b/src/SceneObject.h new file mode 100644 index 0000000..47e9224 --- /dev/null +++ b/src/SceneObject.h @@ -0,0 +1,18 @@ +#include "RuntimeCompiledCpp/RuntimeObjectSystem/ObjectInterfacePerModule.h" +#include "RuntimeCompiledCpp/RuntimeObjectSystem/IObject.h" + +#include "IUpdateable.h" +#include "InterfaceIds.h" +#include + + +class SceneObject : public TInterface +{ +public: + virtual void Update( float deltaTime ) + { + std::cout << "Runtime Object 01231 update called!\n"; + } +}; + +REGISTERCLASS(SceneObject); diff --git a/src/rcpp/ConsoleExample.cpp b/src/rcpp/ConsoleExample.cpp new file mode 100644 index 0000000..87e8dbf --- /dev/null +++ b/src/rcpp/ConsoleExample.cpp @@ -0,0 +1,45 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +// ConsoleExample.cpp : simple example using console command line + + +#include "ConsoleGame.h" +#include +#ifdef _WIN32 +#include +#endif + + +int main(int argc, char* argv[]) +{ + ConsoleGame game; + if( game.Init() ) + { + while( game.MainLoop() ) + { + } + } + else + { + std::cout << "\nFailed Initialisation, press a key to exit.\n"; + _getche(); + } + + std::cout << "Exiting...\n"; + return 0; +} \ No newline at end of file diff --git a/src/rcpp/ConsoleGame.cpp b/src/rcpp/ConsoleGame.cpp new file mode 100644 index 0000000..cac5c55 --- /dev/null +++ b/src/rcpp/ConsoleGame.cpp @@ -0,0 +1,175 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "ConsoleGame.h" + + +#include "../../RuntimeCompiler/AUArray.h" +#include "../../RuntimeCompiler/BuildTool.h" +#include "../../RuntimeCompiler/ICompilerLogger.h" +#include "../../RuntimeCompiler/FileChangeNotifier.h" +#include "../../RuntimeObjectSystem/IObjectFactorySystem.h" +#include "../../RuntimeObjectSystem/ObjectFactorySystem/ObjectFactorySystem.h" +#include "../../RuntimeObjectSystem/RuntimeObjectSystem.h" + +#include "StdioLogSystem.h" + +#include "../../RuntimeObjectSystem/IObject.h" +#include "IUpdateable.h" +#include "InterfaceIds.h" + +#include +#ifdef WIN32 +#include +#include +#else +#include +int _getche() +{ + int ret = getchar(); + return ret; +} +int _kbhit() +{ + std::cout << "This port needs a fix, CTRL-C to quit\n"; + return 0; +} + +int Sleep( int msecs ) +{ + return usleep( msecs * 1000); +} +#endif +#include +#include +#include +#include +#include + +// Remove windows.h define of GetObject which conflicts with EntitySystem GetObject +#if defined _WINDOWS_ && defined GetObject +#undef GetObject +#endif +using FileSystemUtils::Path; + +ConsoleGame::ConsoleGame() + : m_pCompilerLogger(0) + , m_pRuntimeObjectSystem(0) + , m_pUpdateable(0) +{ +} + +ConsoleGame::~ConsoleGame() +{ + if( m_pRuntimeObjectSystem ) + { + // clean temp object files + m_pRuntimeObjectSystem->CleanObjectFiles(); + } + + if( m_pRuntimeObjectSystem && m_pRuntimeObjectSystem->GetObjectFactorySystem() ) + { + m_pRuntimeObjectSystem->GetObjectFactorySystem()->RemoveListener(this); + + // delete object via correct interface + IObject* pObj = m_pRuntimeObjectSystem->GetObjectFactorySystem()->GetObject( m_ObjectId ); + delete pObj; + } + + delete m_pRuntimeObjectSystem; + delete m_pCompilerLogger; +} + + +bool ConsoleGame::Init() +{ + //Initialise the RuntimeObjectSystem + m_pRuntimeObjectSystem = new RuntimeObjectSystem; + m_pCompilerLogger = new StdioLogSystem(); + if( !m_pRuntimeObjectSystem->Initialise(m_pCompilerLogger, 0) ) + { + m_pRuntimeObjectSystem = 0; + return false; + } + m_pRuntimeObjectSystem->GetObjectFactorySystem()->AddListener(this); + + + // construct first object + IObjectConstructor* pCtor = m_pRuntimeObjectSystem->GetObjectFactorySystem()->GetConstructor( "RuntimeObject01" ); + if( pCtor ) + { + IObject* pObj = pCtor->Construct(); + pObj->GetInterface( &m_pUpdateable ); + if( 0 == m_pUpdateable ) + { + delete pObj; + m_pCompilerLogger->LogError("Error - no updateable interface found\n"); + return false; + } + m_ObjectId = pObj->GetObjectId(); + + } + + return true; +} + +void ConsoleGame::OnConstructorsAdded() +{ + // This could have resulted in a change of object pointer, so release old and get new one. + if( m_pUpdateable ) + { + IObject* pObj = m_pRuntimeObjectSystem->GetObjectFactorySystem()->GetObject( m_ObjectId ); + pObj->GetInterface( &m_pUpdateable ); + if( 0 == m_pUpdateable ) + { + delete pObj; + m_pCompilerLogger->LogError( "Error - no updateable interface found\n"); + } + } +} + + + +bool ConsoleGame::MainLoop() +{ + //check status of any compile + if( m_pRuntimeObjectSystem->GetIsCompiledComplete() ) + { + // load module when compile complete + m_pRuntimeObjectSystem->LoadCompiledModule(); + } + + if( !m_pRuntimeObjectSystem->GetIsCompiling() ) + { + static int numUpdates = 0; + std::cout << "\nMain Loop - press q to quit. Updates every second. Update: " << numUpdates++ << "\n"; + if( _kbhit() ) + { + int ret = _getche(); + if( 'q' == ret ) + { + return false; + } + } + const float deltaTime = 1.0f; + m_pRuntimeObjectSystem->GetFileChangeNotifier()->Update( deltaTime ); + m_pUpdateable->Update( deltaTime ); + Sleep(1000); + } + + return true; +} diff --git a/src/rcpp/ConsoleGame.h b/src/rcpp/ConsoleGame.h new file mode 100644 index 0000000..432b74d --- /dev/null +++ b/src/rcpp/ConsoleGame.h @@ -0,0 +1,64 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef CONSOLEGAME_INCLUDED +#define CONSOLEGAME_INCLUDED + +#include "../../RuntimeObjectSystem/IObjectFactorySystem.h" +#include "../../RuntimeObjectSystem/ObjectInterface.h" +#include "../../RuntimeCompiler/AUArray.h" + +#ifndef _WIN32 +int _getche(); +#endif + + +struct IUpdateable; +struct IRuntimeObjectSystem; + +class ConsoleGame : public IObjectFactoryListener +{ +public: + ConsoleGame(); + virtual ~ConsoleGame(); + + bool Init(); + bool MainLoop(); + + + // IObjectFactoryListener + + virtual void OnConstructorsAdded(); + + // ~IObjectFactoryListener + + +private: + + // Runtime Systems + ICompilerLogger* m_pCompilerLogger; + IRuntimeObjectSystem* m_pRuntimeObjectSystem; + + // Runtime object + IUpdateable* m_pUpdateable; + ObjectId m_ObjectId; + +}; + +#endif // CONSOLEGAME_INCLUDED diff --git a/src/rcpp/IUpdateable.h b/src/rcpp/IUpdateable.h new file mode 100644 index 0000000..4f5aeb1 --- /dev/null +++ b/src/rcpp/IUpdateable.h @@ -0,0 +1,30 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef IUPDATEABLE_INCLUDED +#define IUPDATEABLE_INCLUDED + +#include "RuntimeCompiledCpp/RuntimeObjectSystem/IObject.h" + +struct IUpdateable : public IObject +{ + virtual void Update( float deltaTime ) = 0; +}; + +#endif // IUPDATEABLE_INCLUDED diff --git a/src/rcpp/InterfaceIds.h b/src/rcpp/InterfaceIds.h new file mode 100644 index 0000000..bab75eb --- /dev/null +++ b/src/rcpp/InterfaceIds.h @@ -0,0 +1,41 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +//////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// InterfaceId header file. +// +// Specifys interface ids for getting hold of interfaces +// +//////////////////////////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#ifndef INTERFACEIDS_INCLUDED +#define INTERFACEIDS_INCLUDED + +#include "RuntimeCompiledCpp/RuntimeObjectSystem/IObject.h" + +enum InterfaceIDEnumConsoleExample +{ + IID_IUPDATEABLE = IID_ENDInterfaceID, + + IID_ENDInterfaceIDEnumConsoleExample +}; + + +#endif //INTERFACEIDS_INCLUDED diff --git a/src/rcpp/RuntimeObject01.cpp b/src/rcpp/RuntimeObject01.cpp new file mode 100644 index 0000000..7e602d2 --- /dev/null +++ b/src/rcpp/RuntimeObject01.cpp @@ -0,0 +1,18 @@ +#include "../../RuntimeObjectSystem/ObjectInterfacePerModule.h" + +#include "../../RuntimeObjectSystem/IObject.h" +#include "IUpdateable.h" +#include "InterfaceIds.h" +#include + + +class RuntimeObject01 : public TInterface +{ +public: + virtual void Update( float deltaTime ) + { + std::cout << "Runtime Object 01231 update called!\n"; + } +}; + +REGISTERCLASS(RuntimeObject01); diff --git a/src/rcpp/StdioLogSystem.cpp b/src/rcpp/StdioLogSystem.cpp new file mode 100644 index 0000000..b9001d2 --- /dev/null +++ b/src/rcpp/StdioLogSystem.cpp @@ -0,0 +1,62 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#include "StdioLogSystem.h" + +// Currently we create the file on first real output, and only close it on shutdown + +#include +#include +#include + +#ifdef _WIN32 + #include "Windows.h" + #pragma warning( disable : 4996 4800 ) +#endif + + +void StdioLogSystem::LogError(const char * format, ...) +{ + va_list args; + va_start(args, format); + LogInternal(format, args); +} + +void StdioLogSystem::LogWarning(const char * format, ...) +{ + va_list args; + va_start(args, format); + LogInternal(format, args); +} + +void StdioLogSystem::LogInfo(const char * format, ...) +{ + va_list args; + va_start(args, format); + LogInternal(format, args); +} +void StdioLogSystem::LogInternal(const char * format, va_list args) +{ + int result = vsnprintf(m_buff, LOGSYSTEM_MAX_BUFFER-1, format, args); + // Make sure there's a limit to the amount of rubbish we can output + m_buff[LOGSYSTEM_MAX_BUFFER-1] = '\0'; + + std::cout << m_buff; +#ifdef _WIN32 + OutputDebugStringA( m_buff ); +#endif +} diff --git a/src/rcpp/StdioLogSystem.h b/src/rcpp/StdioLogSystem.h new file mode 100644 index 0000000..596057b --- /dev/null +++ b/src/rcpp/StdioLogSystem.h @@ -0,0 +1,45 @@ +// +// Copyright (c) 2010-2011 Matthew Jack and Doug Binks +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +#pragma once + +#ifndef STDIOLOGSYSTEM_INCLUDED +#define STDIOLOGSYSTEM_INCLUDED + +#include "RuntimeCompiledCpp/RuntimeCompiler/ICompilerLogger.h" + +#include +#include + +// StdioLogSystem for compiler + +const size_t LOGSYSTEM_MAX_BUFFER = 4096; + +class StdioLogSystem : public ICompilerLogger +{ +public: + virtual void LogError(const char * format, ...); + virtual void LogWarning(const char * format, ...); + virtual void LogInfo(const char * format, ...); + +protected: + void LogInternal(const char * format, va_list args); + char m_buff[LOGSYSTEM_MAX_BUFFER]; +}; + + +#endif //STDIOLOGSYSTEM_INCLUDED