MapilVoid GLSprite::DrawTexture( SharedPointer < Texture > pTexture ) { GLfloat texCoord[ 8 ] = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f }; GLfloat vertexCoord[ 8 ] = { 0.0f, 0.0f, 0.0f, static_cast < MapilFloat32 > ( pTexture->GetSize().m_Y ), static_cast < MapilFloat32 > ( pTexture->GetSize().m_X ), static_cast < MapilFloat32 > ( pTexture->GetSize().m_Y ), static_cast < MapilFloat32 > ( pTexture->GetSize().m_X ), 0.0f }; glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); // When the different texture is set, calls glBindTexture. MapilBool isNewTexture = ( !( m_pPrevTexture.GetPointer() ) || m_pPrevTexture->Get() != pTexture->Get() ); if( isNewTexture ){ glBindTexture( GL_TEXTURE_2D, 0 ); m_pPrevTexture = pTexture; glBindTexture( GL_TEXTURE_2D, pTexture->Get() ); } glVertexPointer( 2, GL_FLOAT, 0, vertexCoord ); glTexCoordPointer( 2, GL_FLOAT, 0, texCoord ); glDrawArrays( GL_QUADS, 0, 4 ); }
bool QueryCursorImpl::GetNextBatchIfNeeded(IgniteError& err) { assert(iterCalled); if (endReached || (batch && batch->Left() > 0)) return true; endReached = !IteratorHasNext(err); if (endReached) return true; JniErrorInfo jniErr; SharedPointer<InteropMemory> inMem = env.Get()->AllocateMemory(); env.Get()->Context()->TargetOutStream( javaRef, OP_GET_BATCH, inMem.Get()->PointerLong(), &jniErr); IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err); if (jniErr.code != IGNITE_JNI_ERR_SUCCESS) return false; delete batch; // Needed for exception safety. batch = 0; batch = new QueryBatch(*env.Get(), inMem); endReached = batch->IsEmpty(); return true; }
MapilVoid GLSprite::DrawString( SharedPointer < GraphicsFont > pFont, const MapilTChar* pStr, const Matrix4x4 < MapilFloat32 >& mat ) { if( !pStr ){ return; } #if defined ( API_WIN32API ) glMatrixMode( GL_MODELVIEW ); glPushMatrix(); glLoadMatrixf( mat.m_Elm1 ); ::HDC hdc = wglGetCurrentDC(); // Build string to be displayed. MapilTChar str[ 4096 ]; va_list vl; MapilInt32 len; va_start( vl, pStr ); len = _vsctprintf( pStr, vl ) + 1; if( len > sizeof( str ) ){ return; } _vstprintf( str, pStr, vl ); va_end( vl ); len = _tcslen( str ); SelectObject( hdc, reinterpret_cast < HFONT > ( pFont->Get() ) ); MapilInt32 list = glGenLists( len ); for( MapilInt32 i = 0; i < len; i++ ){ wglUseFontBitmaps( hdc, str[ i ], 1, list + i ); } //glDisable( GL_LIGHTING ); //glColor4f( colR, colG, colB, 1.0f ); glColor4f( 1.0f, 0.0f, 0.0f, 1.0f ); //glRasterPos2i( vPos.m_X, vPos.m_Y ); glRasterPos2i( 0, 0 ); for( MapilInt32 i = 0; i < len; i++ ){ glCallList( list + i ); } //glEnable( GL_LIGHTING ); glDeleteLists( list, len ); glPopMatrix(); #endif // API_WIN32API }
void QueryCursorImpl::GetAll(OutputOperation& op, IgniteError& err) { // Check whether any of iterator methods were called. if (iterCalled) { err = IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Cannot use GetAll() method because an iteration method was called."); return; } // Check whether GetAll was called before. if (getAllCalled) { err = IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Cannot use GetNext() method because GetAll() was called."); return; } // Get data. JniErrorInfo jniErr; SharedPointer<InteropMemory> inMem = env.Get()->AllocateMemory(); env.Get()->Context()->TargetOutStream(javaRef, OP_GET_ALL, inMem.Get()->PointerLong(), &jniErr); IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err); if (jniErr.code == IGNITE_JNI_ERR_SUCCESS) { getAllCalled = true; InteropInputStream in(inMem.Get()); BinaryReaderImpl reader(&in); op.ProcessOutput(reader); } }
MapilVoid GLSprite::DrawString( SharedPointer < GraphicsFont > pFont, const MapilTChar* pStr, ImageTransformationMethod method, const Vector2 < MapilFloat32 >& v, MapilUInt32 color ) { if( !pStr ){ return; } #if defined ( API_WIN32API ) ::HDC hdc = wglGetCurrentDC(); // Build string to be displayed. MapilTChar str[ 4096 ]; va_list vl; MapilInt32 len; va_start( vl, pStr ); len = _vsctprintf( pStr, vl ) + 1; if( len > sizeof( str ) ){ return; } _vstprintf( str, pStr, vl ); va_end( vl ); len = _tcslen( str ); SelectObject( hdc, reinterpret_cast < HFONT > ( pFont->Get() ) ); MapilInt32 list = glGenLists( len ); for( MapilInt32 i = 0; i < len; i++ ){ wglUseFontBitmaps( hdc, str[ i ], 1, list + i ); } //glDisable( GL_LIGHTING ); glColor4i( ( color >> 16 ) & 0xFF , ( color >> 8 ) & 0xFF, color & 0xFF, ( color >> 24 ) & 0xFF ); //glColor4f( 1.0f, 0.0f, 0.0f, 1.0f ); glRasterPos2f( v.m_X, v.m_Y ); for( MapilInt32 i = 0; i < len; i++ ){ glCallList( list + i ); } //glEnable( GL_LIGHTING ); glDeleteLists( list, len ); #endif // API_WIN32API }
bool BinaryTypeUpdaterImpl::Update(Snap* snap, IgniteError* err) { JniErrorInfo jniErr; SharedPointer<InteropMemory> mem = env.Get()->AllocateMemory(); InteropOutputStream out(mem.Get()); BinaryWriterImpl writer(&out, NULL); BinaryRawWriter rawWriter(&writer); // We always pass only one meta at a time in current implementation for simplicity. rawWriter.WriteInt32(1); rawWriter.WriteInt32(snap->GetTypeId()); rawWriter.WriteString(snap->GetTypeName()); rawWriter.WriteString(NULL); // Affinity key is not supported for now. if (snap->HasFields()) { std::map<std::string, int32_t>* fields = snap->GetFields(); rawWriter.WriteInt32(static_cast<int32_t>(fields->size())); for (std::map<std::string, int32_t>::iterator it = fields->begin(); it != fields->end(); ++it) { rawWriter.WriteString(it->first); rawWriter.WriteInt32(it->second); } } else rawWriter.WriteInt32(0); rawWriter.WriteBool(false); // Enums are not supported for now. rawWriter.WriteInt32(0); // Schema size. Compact schema footer is not yet supported. out.Synchronize(); long long res = env.Get()->Context()->TargetInStreamOutLong(javaRef, OP_METADATA, mem.Get()->PointerLong(), &jniErr); IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err); if (jniErr.code == IGNITE_JNI_ERR_SUCCESS) return res == 1; else return false; }
MapilVoid D3DSprite::DrawString( SharedPointer < GraphicsFont > pFont, const MapilTChar* pStr, ImageTransformationMethod method, const Vector2 < MapilFloat32 >& v, MapilUInt32 color ) { Assert( m_IsUsed, CURRENT_POSITION, TSTR( "The sprite isn't created yet." ), -1 ); //World coordinate transformation D3DXMATRIXA16 matWorld; D3DXMatrixTranslation( &matWorld, v.m_X, v.m_Y, 0.0f ); m_pD3DSprite->SetTransform( &matWorld ); if( FAILED( reinterpret_cast < ::LPD3DXFONT > ( pFont->Get() )->DrawText( m_pD3DSprite, pStr, //String -1, //Number of character (-1 mean that whole string will be drawn) NULL, //Region of drawing DT_LEFT | DT_NOCLIP, //Style color ) ) ) { //Character color throw MapilException( CURRENT_POSITION, TSTR( "Failed to draw." ), -1 ); } }
MapilVoid D3DSprite::DrawString( SharedPointer < GraphicsFont > pFont, const MapilTChar* pStr, const Matrix4x4 < MapilFloat32 >& mat ) { Assert( m_IsUsed, CURRENT_POSITION, TSTR( "The sprite isn't created yet." ), -1 ); //World coordinate transformation D3DXMATRIXA16 matWorld; for( MapilInt32 i = 0; i < 4; ++i ) { for( MapilInt32 j = 0; j < 4; ++j ) { matWorld.m[ i ][ j ] = mat.m_Elm[ i ][ j ]; } } m_pD3DSprite->SetTransform( &matWorld ); if( FAILED( reinterpret_cast < ::LPD3DXFONT > ( pFont->Get() )->DrawText( m_pD3DSprite, pStr, //String -1, //Number of character (-1 mean that whole string will be drawn) NULL, //Region of drawing DT_LEFT | DT_NOCLIP, //Style D3DCOLOR_XRGB( 255, 255, 255 ) ) ) ) { //Character color throw MapilException( CURRENT_POSITION, TSTR( "Failed to draw." ), -1 ); } }
Ignite Ignition::Start(const IgniteConfiguration& cfg, const char* name, IgniteError* err) { bool failed = false; SharedPointer<IgniteEnvironment> env; SharedPointer<IgniteEnvironment>* envTarget = NULL; jobject javaRef = NULL; factoryLock.Enter(); // 1. Load JVM library if needed. if (!JVM_LIB_LOADED) { bool jvmLibFound; std::string jvmLib; if (cfg.jvmLibPath) { std::string jvmLibPath = std::string(cfg.jvmLibPath); jvmLib = FindJvmLibrary(&jvmLibPath, &jvmLibFound); } else jvmLib = FindJvmLibrary(NULL, &jvmLibFound); if (!jvmLibFound) { *err = IgniteError(IgniteError::IGNITE_ERR_JVM_LIB_NOT_FOUND, "JVM library is not found (did you set JAVA_HOME environment variable?)"); failed = true; } if (!failed) { if (!LoadJvmLibrary(jvmLib)) { *err = IgniteError(IgniteError::IGNITE_ERR_JVM_LIB_LOAD_FAILED, "Failed to load JVM library."); failed = true; } } JVM_LIB_LOADED = true; } if (!failed) { // 2. Resolve IGNITE_HOME. bool homeFound; std::string home; if (cfg.igniteHome) { std::string homePath = std::string(cfg.igniteHome); home = ResolveIgniteHome(&homePath, &homeFound); } else home = ResolveIgniteHome(NULL, &homeFound); // 3. Create classpath. std::string cp; if (cfg.jvmClassPath) { std::string usrCp = cfg.jvmClassPath; cp = CreateIgniteClasspath(&usrCp, homeFound ? &home : NULL); } else cp = CreateIgniteClasspath(NULL, homeFound ? &home : NULL); if (!cp.empty()) { // 4. Start JVM if needed. JniErrorInfo jniErr; env = SharedPointer<IgniteEnvironment>(new IgniteEnvironment()); int optsLen; char** opts = CreateJvmOptions(cfg, homeFound ? &home : NULL, cp, &optsLen); envTarget = new SharedPointer<IgniteEnvironment>(env); SharedPointer<JniContext> ctx( JniContext::Create(opts, optsLen, env.Get()->GetJniHandlers(envTarget), &jniErr)); for (int i = 0; i < optsLen; i++) ReleaseChars(*(opts + i)); delete[] opts; if (!ctx.Get()) { IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err); failed = true; } // 5. Start Ignite. if (!failed) { char* springCfgPath0 = CopyChars(cfg.springCfgPath); if (!springCfgPath0) springCfgPath0 = CopyChars(DFLT_CFG); char* name0 = CopyChars(name); interop::InteropUnpooledMemory mem(16); interop::InteropOutputStream stream(&mem); stream.WriteBool(false); stream.Synchronize(); javaRef = ctx.Get()->IgnitionStart(springCfgPath0, name0, 2, mem.PointerLong(), &jniErr); ReleaseChars(springCfgPath0); ReleaseChars(name0); if (!javaRef) { IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err); failed = true; } else { // 6. Ignite is started at this point. env.Get()->Initialize(ctx); started = true; } } } else { *err = IgniteError(IgniteError::IGNITE_ERR_JVM_NO_CLASSPATH, "Java classpath is empty (did you set IGNITE_HOME environment variable?)"); failed = true; } } factoryLock.Leave(); if (failed) { if (envTarget) delete envTarget; return Ignite(); } else { IgniteImpl* impl = new IgniteImpl(env, javaRef); return Ignite(impl); } }
/** * OnStart callback. * * @param target Target environment. * @param proc Processor instance (not used for now). * @param memPtr Memory pointer. */ void IGNITE_CALL OnStart(void* target, void* proc, long long memPtr) { SharedPointer<IgniteEnvironment>* ptr = static_cast<SharedPointer<IgniteEnvironment>*>(target); ptr->Get()->OnStartCallback(memPtr); }
#define CATCH_CONFIG_MAIN #include "../../libs/catch.h" #include "../../Templates.h" using namespace Templates; TEST_CASE("SharedPointer should be allocated with nullptr", "[SharedPointer]") { SharedPointer<int> a; REQUIRE(a.Get() == nullptr); } TEST_CASE("SharedPointer should be allocated with pointer", "[SharedPointer]") { SharedPointer<int> a(new int(10)); REQUIRE(a.Get() != nullptr); REQUIRE(*a == 10); } TEST_CASE("SharedPointer should be allocated with second shared pointer with nullptr", "[SharedPointer]") { SharedPointer<int> a; SharedPointer<int> b(move(a)); REQUIRE(a.Get() == nullptr); REQUIRE(b.Get() == nullptr); } TEST_CASE("SharedPointer should be allocated with second shared pointer with pointer", "[SharedPointer]") { SharedPointer<int> a(new int(10)); SharedPointer<int> b(move(a));
MapilVoid SpriteCore::Commit( SharedPointer < Texture > texture, const ::D3DXMATRIX& worldMat ) { SpriteData sprite = { worldMat, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f }; ::LPDIRECT3DTEXTURE9 tex = reinterpret_cast < ::LPDIRECT3DTEXTURE9 > ( texture->Get() ); m_DrawList[ tex ].push_back( sprite ); }