Esempio n. 1
0
	void MovieGlHap::allocateVisualContext()
	{
		// Load HAP Movie
		if( HapQTQuickTimeMovieHasHapTrackPlayable( getObj()->mMovie ) )
		{
			// QT Visual Context attributes
			OSStatus err = noErr;
			QTVisualContextRef * visualContext = (QTVisualContextRef*)&getObj()->mVisualContext;
			CFDictionaryRef pixelBufferOptions = HapQTCreateCVPixelBufferOptionsDictionary();
			
			const CFStringRef keys[] = { kQTVisualContextPixelBufferAttributesKey };
			CFDictionaryRef visualContextOptions = ::CFDictionaryCreate(kCFAllocatorDefault, (const void**)&keys, (const void**)&pixelBufferOptions, sizeof(keys)/sizeof(keys[0]), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
			err = QTPixelBufferContextCreate( kCFAllocatorDefault, visualContextOptions, visualContext );
			
			::CFRelease( pixelBufferOptions );
			::CFRelease( visualContextOptions );
			
			if( err != noErr ) {
				CI_LOG_E( "HAP ERROR :: " << err << " couldnt create visual context." );
				return;
			}
			// Set the movie's visual context
			err = SetMovieVisualContext( getObj()->mMovie, *visualContext );
			if( err != noErr ) {
				CI_LOG_E( "HAP ERROR :: " << err << " SetMovieVisualContext." );
				return;
			}
		}
		
		// Get codec name
		for (long i = 1; i <= GetMovieTrackCount(getObj()->mMovie); i++) {
            Track track = GetMovieIndTrack(getObj()->mMovie, i);
            Media media = GetTrackMedia(track);
            OSType mediaType;
            GetMediaHandlerDescription(media, &mediaType, NULL, NULL);
            if (mediaType == VideoMediaType)
            {
                // Get the codec-type of this track
                ImageDescriptionHandle imageDescription = (ImageDescriptionHandle)NewHandle(0); // GetMediaSampleDescription will resize it
                GetMediaSampleDescription(media, 1, (SampleDescriptionHandle)imageDescription);
                OSType codecType = (*imageDescription)->cType;
                DisposeHandle((Handle)imageDescription);
                
                switch (codecType) {
                    case 'Hap1': mCodec = Codec::HAP; break;
                    case 'Hap5': mCodec = Codec::HAP_A; break;
                    case 'HapY': mCodec = Codec::HAP_Q; break;
                    default: mCodec = Codec::UNSUPPORTED; break;
				}
            }
        }

		// Set framerate callback
		this->setNewFrameCallback( updateMovieFPS, (void*)this );
	}
HRESULT D3DPresentEngine::PresentSwapChain(IDirect3DSwapChain9* pSwapChain, IDirect3DSurface9* pSurface)
{
	//-----------------------------------------------------------------------------
	// Copy latest D3D frame to our OpenGL/D3D shared surface...

	//pSwapChain->GetFrontBufferData(d3d_shared_surface);
	IDirect3DSurface9 *surface;
	pSwapChain->GetBackBuffer(0,D3DBACKBUFFER_TYPE_MONO,&surface);
    if (m_pDevice->StretchRect(surface,NULL,d3d_shared_surface,NULL,D3DTEXF_NONE) != D3D_OK)
	{
		CI_LOG_E("Error while copying texture to gl context");
		//printf("ciWMFVideoplayer: Error while copying texture to gl context \n");
	}
	SAFE_RELEASE(surface);

	//-----------------------------------------------------------------------------
	// Original code from the WMF EVRpresenter sample code...

	HRESULT hr = S_OK;
	
	if (m_hwnd == NULL)
    {
        return MF_E_INVALIDREQUEST;
    }
	
    hr = pSwapChain->Present(NULL, &m_rcDestRect, m_hwnd, NULL, 0);
	
    LOG_MSG_IF_FAILED(L"D3DPresentEngine::PresentSwapChain, IDirect3DSwapChain9::Present failed.", hr);
	
    return hr;
}
Esempio n. 3
0
Server::ClientConnection::ClientConnection( const TcpSessionRef &session, const ServerRef &parent )
: mSession( session ), mParent( parent ), mId( 0 ), mIsAsync( false ), mMessageMutex( new std::mutex() )
{
	mSession->connectReadEventHandler( [&]( ci::Buffer buffer ) {
		auto msgs = ci::split( TcpSession::bufferToString( buffer ), Protocol::messageDelimiter() );
		
		auto msg = ci::split( msgs[0], Protocol::dataMessageDelimiter() );
		
		if( msg[0] == Protocol::CONNECT_ASYNCHRONOUS && msg.size() == 4 ) {
			mIsAsync = true;
			mId = atoi( msg[1].c_str() );
			mName = msg[2];
			mShouldReceiveData = (msg[3] == "true");
		}
		else if( msg[0] == Protocol::CONNECT_SYNCHRONOUS && msg.size() == 3 ) {
			mIsAsync = false;
			mId = atoi( msg[1].c_str() );
			mName = msg[2];
			mShouldReceiveData = true;
		}
		else {
			CI_LOG_E("This message doesn't contain what is needed" << buffer);
		}
		// Now that we have our info let's connect the normal onRead callback
		mSession->connectReadEventHandler( &ClientConnection::onRead, this );
	});
	mSession->connectCloseEventHandler( &ClientConnection::onClose, this );
	mSession->connectErrorEventHandler( &ClientConnection::onError, this );
	mSession->connectWriteEventHandler( &ClientConnection::onWrite, this );
	
	mSession->read( Protocol::messageDelimiter() );
}
Esempio n. 4
0
void VaoImplEs::reassignImpl( Context *newContext )
{
	if( newContext == mCtx )
		return;

	mCtx = newContext;

	// generate
	glGenVertexArrays( 1, &mId );

	// assign
	glBindVertexArray( mId );

	// instantiate the VAO using the layout
	auto oldBuffer = mCtx->getBufferBinding( GL_ARRAY_BUFFER );

	for( auto attribIt = mLayout.mVertexAttribs.begin(); attribIt != mLayout.mVertexAttribs.end(); ++attribIt ) {
		if( attribIt->second.mEnabled ) {
			glEnableVertexAttribArray( attribIt->first );
			glBindBuffer( GL_ARRAY_BUFFER, attribIt->second.mArrayBufferBinding );
			if( attribIt->second.mPointerType == Vao::VertexAttrib::FLOAT )
				glVertexAttribPointer( attribIt->first, attribIt->second.mSize, attribIt->second.mType, attribIt->second.mNormalized, attribIt->second.mStride, attribIt->second.mPointer );
			else
				CI_LOG_E( "Attempt to use integer AttribPointer on ES 2. Ignoring." );
		}
	}

	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, mLayout.mElementArrayBufferBinding );
	// we need to bind this directly to prevent the gl::Context's caching from subverting our restoration of the old GL_ARRAY_BUFFER
	glBindBuffer( GL_ARRAY_BUFFER, oldBuffer );
}
Esempio n. 5
0
void SelectorBase::select( const string &label )
{
	for( size_t i = 0; i < mSegments.size(); i++ ) {
		if( mSegments[i] == label )
			select( i );
	}

	CI_LOG_E( "unknown label: " << label );
}
Esempio n. 6
0
void Connection::send( Message* m )
{
    if ( mIsConnected ) {
        mClient->write( m->getJSON( mConfig.getName() ) );
    }
	else {
        CI_LOG_E( "Send failed, not connected!" );
    }
}
Esempio n. 7
0
void Connection::send( const string &name, const string &type, const string &value )
{
    if ( mIsConnected ) {
        Message m( name, type, value );
        send( m );
    } else {
        CI_LOG_E( "Send failed, not connected!" );
    }
}
Esempio n. 8
0
uint8_t typeToBytes( GLenum type )
{
	switch( type ) {
		case GL_UNSIGNED_INT:		return sizeof(uint32_t); break;
		case GL_INT:				return sizeof(int); break;
		case GL_SAMPLER_2D:			return sizeof(int); break;
#if ! defined( CINDER_GL_ES )
		case GL_SAMPLER_1D:						return sizeof(int); break;
		case GL_SAMPLER_BUFFER_EXT:				return sizeof(int); break;
		case GL_SAMPLER_2D_RECT:				return sizeof(int); break;
		case GL_INT_SAMPLER_2D_RECT:			return sizeof(int); break;
		case GL_UNSIGNED_INT_SAMPLER_2D_RECT:	return sizeof(int); break;
#endif
#if ! defined( CINDER_GL_ES_2 )
		case GL_SAMPLER_2D_ARRAY:				return sizeof(int); break;
		case GL_SAMPLER_2D_SHADOW:				return sizeof(int); break;
		case GL_SAMPLER_2D_ARRAY_SHADOW:		return sizeof(int); break;
		case GL_SAMPLER_CUBE_SHADOW:			return sizeof(int); break;						
		case GL_INT_SAMPLER_2D:					return sizeof(int); break;
		case GL_INT_SAMPLER_3D:					return sizeof(int); break;
		case GL_INT_SAMPLER_CUBE:				return sizeof(int); break;
		case GL_INT_SAMPLER_2D_ARRAY:			return sizeof(int); break;		
		case GL_SAMPLER_3D:						return sizeof(int); break;
		case GL_UNSIGNED_INT_SAMPLER_2D:		return sizeof(int); break;
		case GL_UNSIGNED_INT_SAMPLER_3D:		return sizeof(int); break;
		case GL_UNSIGNED_INT_SAMPLER_CUBE:		return sizeof(int); break;		
		case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:	return sizeof(int); break;
#else
		case GL_SAMPLER_2D_SHADOW_EXT: return sizeof(int); break;
#endif
		case GL_SAMPLER_CUBE:		return sizeof(int); break;
		case GL_FLOAT:				return sizeof(float); break;
		case GL_BOOL:				return sizeof(bool); break;
#if ! defined( CINDER_GL_ES_2 )
		case GL_UNSIGNED_INT_VEC2:	return sizeof(glm::uvec2); break;
		case GL_UNSIGNED_INT_VEC3:	return sizeof(glm::uvec3); break;
		case GL_UNSIGNED_INT_VEC4:	return sizeof(glm::uvec4); break;
#endif
		case GL_INT_VEC2:			return sizeof(ivec2); break;
		case GL_FLOAT_VEC2:			return sizeof(vec2); break;
		case GL_BOOL_VEC2:			return sizeof(glm::bvec2); break;
		case GL_INT_VEC3:			return sizeof(ivec3); break;
		case GL_FLOAT_VEC3:			return sizeof(vec3); break;
		case GL_BOOL_VEC3:			return sizeof(glm::bvec3); break;
		case GL_INT_VEC4:			return sizeof(ivec4); break;
		case GL_FLOAT_VEC4:			return sizeof(vec4); break;
		case GL_BOOL_VEC4:			return sizeof(glm::bvec4); break;
		case GL_FLOAT_MAT2:			return sizeof(mat2); break;
		case GL_FLOAT_MAT3:			return sizeof(mat3); break;
		case GL_FLOAT_MAT4:			return sizeof(mat4); break;
		default:
			CI_LOG_E("Unknown gl type constant " << constantToString( type ));
			return 0;
		break;
	}
}
Esempio n. 9
0
void AppBase::executeLaunch()
{
	try {
		launch();
	}
	catch( std::exception &exc ) {
		CI_LOG_E( "Uncaught exception, type: " << System::demangleTypeName( typeid( exc ).name() ) << ", what : " << exc.what() );
		throw;
	}
}
Esempio n. 10
0
  int VideoDxtCreator::open(std::string outpath) {
    
    if (0 == outpath.size()) {
      CI_LOG_E("Given outpath is empty.");
      return -1;
    }

    ofs.open(outpath.c_str(), std::ios::binary | std::ios::out);
    if (!ofs.is_open()) {
      CI_LOG_E("Failed to open: " << outpath.c_str());
      return -2;
    }else{
        

        
    }

    return 0;
  }
Esempio n. 11
0
void Connection::sendRange( const string &name, int value )
{
    if ( mIsConnected ) {
        Message m( name, "range", to_string(value));
        send( m );
    }
	else {
        CI_LOG_E( "Send failed, not connected!" );
    }
}
bool D3DPresentEngine::createSharedTexture(int w, int h, int textureID)
{
	_w = w;
	_h = h;
	if (gl_handleD3D == NULL ) 	gl_handleD3D = wglDXOpenDeviceNV(m_pDevice);

	if (!gl_handleD3D)
	{
		CI_LOG_E( "Opening the shared device failed - Create SharedTexture Failed" );
		return false;
	}
	gl_name=textureID;
	HANDLE sharedHandle = NULL; //We need to create a shared handle for the ressource, otherwise the extension fails on ATI/Intel cards
	HRESULT hr = m_pDevice->CreateTexture(w,h,1,D3DUSAGE_RENDERTARGET,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&d3d_shared_texture,&sharedHandle);

	if (FAILED(hr))
	{
		CI_LOG_E( "Error creating D3DTexture" );
		return false;
	}

	if (!sharedHandle)
	{
		CI_LOG_E( "Error creating D3D shared handle" );
		return false;
	}
	
	wglDXSetResourceShareHandleNV(d3d_shared_texture,sharedHandle);

	d3d_shared_texture->GetSurfaceLevel(0,&d3d_shared_surface);
		
	gl_handle = wglDXRegisterObjectNV(gl_handleD3D, d3d_shared_texture,
		gl_name,
		GL_TEXTURE_RECTANGLE,
		WGL_ACCESS_READ_ONLY_NV);

	if (!gl_handle) 
	{
		CI_LOG_E("Opening the shared texture failed - Create SharedTexture Failed");
		return false;
	}
	return true;
}
Esempio n. 13
0
void Connection::sendBoolean( const string &name, bool value )
{
    if ( mIsConnected ) {
        string out = value ? "true" : "false";
        Message m( name, "boolean", out );
        send( m );
    }
	else {
        CI_LOG_E( "Send failed, not connected!" );
    }
}
Esempio n. 14
0
void VM::addImportDirectoryImpl( const fs::path &directory )
{
	if( ! fs::is_directory( directory ) ) {
		CI_LOG_E( "Not a directory: " << directory );
		return;
	}

	fs::path dirCanonical = fs::canonical( directory );
	auto it = find( mImportSearchDirectories.begin(), mImportSearchDirectories.end(), dirCanonical );
	if( it == mImportSearchDirectories.end() )
		mImportSearchDirectories.push_back( dirCanonical );
}
Esempio n. 15
0
void Connection::initialize()
{
	mClient.reset( new WebSocketClient() );
	// Setup callbacks:
	mUpdateConnection = app::App::get()->getSignalUpdate().connect( std::bind( &Connection::update, this ) ) ;
	//TODO: See if we can add a listener here to websocketpp cinder to automate this
	//WebSocketPP Interface
	mClient->connectOpenEventHandler( &Connection::onConnect, this );
	mClient->connectCloseEventHandler( &Connection::onDisconnect, this );
	mClient->connectFailEventHandler( [](std::string err){ CI_LOG_E(err); } );
	mClient->connectInterruptEventHandler( &Connection::onInterrupt, this );
	mClient->connectPingEventHandler( &Connection::onPing, this );
	mClient->connectMessageEventHandler( &Connection::onRead, this );
}
Esempio n. 16
0
int defaultLuabindErrorHandler( lua_State* L )
{
	// log the error message
	luabind::object msg( luabind::from_stack( L, -1 ) );
	std::ostringstream str;
	str << "lua> run-time error: " << msg;
	
	// log the callstack
	std::string traceback = luabind::call_function<std::string>( luabind::globals(L)["debug"]["traceback"] );
	str << "\n" << std::string( "lua> " ) + traceback;
	CI_LOG_E( str.str() );
	
	// return unmodified error object
	return 1;
}
Esempio n. 17
0
Surface8u RendererImpl2dGdi::copyWindowContents( const Area &area )
{
	// Warning - if you step through this code with a debugger, the image returned
	// will be of the foreground window (presumably your IDE) instead
	::RECT clientRect;
	::GetClientRect( mWnd, &clientRect );
	Area clippedArea = area.getClipBy( Area( clientRect.left, clientRect.top, clientRect.right, clientRect.bottom ) );
	::HDC hdc = ::GetDC( mWnd );
	::HDC memDC = ::CreateCompatibleDC( hdc );

	::HBITMAP copyBitmap = ::CreateCompatibleBitmap( hdc, clippedArea.getWidth(), clippedArea.getHeight() );
	if( ! copyBitmap ) {
		CI_LOG_E( "::CreateCompatibleBitmap() failed on copyWindowContents()" );
		return Surface8u();
	}

	::GdiFlush();

	// Copy the bits to our bitmap
	::HGDIOBJ oldBitmap = ::SelectObject( memDC, copyBitmap );
	if( ! ::BitBlt( memDC, 0, 0, clippedArea.getWidth(), clippedArea.getHeight(), hdc, clippedArea.x1, clippedArea.y1, SRCCOPY ) ){
		CI_LOG_E( "BitBlt() failed on copyWindowContents()" );
		return Surface8u();
	}
	::SelectObject( memDC, oldBitmap );
	
	auto tempSurface = msw::convertHBitmap( copyBitmap );
	Surface8u result( *tempSurface );

	::DeleteObject( copyBitmap );

	::ReleaseDC( NULL, hdc );
	::DeleteDC( memDC );

	return result;
}
Esempio n. 18
0
    bool VideoDxtCreator::writePixels(unsigned char* pixels,int frames){
     
        
        if(frames == 0){
            writeU32(0xCAFEBABE);
            writeU32(version);
            writeU32(w);
            writeU32(h);
            writeU32(0);

        }
        
        dxt = (unsigned char*) malloc(w * h);
        if (NULL == dxt) {
            CI_LOG_E("Failed to allocate the output buffer.");
           // return -6;
        }
        
        rygCompress(dxt, pixels, w, h, 1);
        
        if (!ofs.write((const char*)dxt, w * h)) {
            CI_LOG_E("Failed to write DXT frame.");
           // goto error;
        }
        
        free(dxt);
        dxt = NULL;

        rewriteU32(16, frames);

        
        
        
        return true;

    }
Esempio n. 19
0
void EnvironmentEs::allocateTexStorage3d( GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, bool immutable )
{
#if defined( CINDER_GL_ES_2 )
	CI_LOG_E( "allocateTexStorage3d called on unsupported platform" );
#else
  #if ! defined( CINDER_GL_ES_3 )
	// test at runtime for presence of 'glTexStorage2D' and just force mutable storage if it's not available
	// both ANGLE and iOS support EXT_texture_storage
	static auto texStorage3DFn = glTexStorage3DEXT;
  #else
	static auto texStorage3DFn = glTexStorage3D;
  #endif
	if( immutable && texStorage3DFn ) {
		texStorage3DFn( target, levels, internalFormat, width, height, depth );
	}
	else {
		GLenum dataFormat, dataType;
		TextureBase::getInternalFormatInfo( internalFormat, &dataFormat, &dataType );
		glTexImage3D( target, 0, internalFormat, width, height, depth, 0, dataFormat, dataType, nullptr );
	}
#endif
}
Esempio n. 20
0
void TreeHeartbeat::getLastEventId()
{
   try
   {
      JsonTree queryResult = queryWinChattyv2Server("getNewestEventId");

      std::string strvalue = queryResult["eventId"].getValue();

      if(strvalue.length() > 0)
      {
         m_last_event_id = fromString<uint32_t>(strvalue);
      }
      else
      {
         m_last_event_id = 0;
      }
   }
   catch(ci::Exception& exc)
   {
      CI_LOG_E("Error calling WCv2 method getNewestEventId: " << exc.what());
      m_last_event_id = 0;
   }
}
	void _stdcall OnCriticalError( HRESULT Error )
	{
		CI_LOG_E( "error: " << Error );
	}
	void _stdcall OnVoiceError( void *pBufferContext, HRESULT Error )
	{
		CI_LOG_E( "error: " << Error );
	}
Esempio n. 23
0
bool Message::valueAsBoolean() const
{
    if (mType != "boolean")
		CI_LOG_E( "This Message is not a boolean type! You'll most likely get 'false'." );
    return mValue == "true";
}
Esempio n. 24
0
  int VideoDxtCreator::create(std::string inpath,
                              int startFrame,
                              int endFrame)
  {

    char name[2048] = { 0 } ;
//    int allocated = 0;
    int channels = 0;
//    int r;
    int prev_w = 0;
    int prev_h = 0;
    int num_frames = 0;
    //    std::ofstream ofs(outpath.c_str(), std::ios::binary | std::ios::out);

//    if (VIDEO_DXT_VERSION_0_0_0 != version
//        && VIDEO_DXT_VERSION_0_0_1 != version)
//      {
//        CI_LOG_E("The version you've set is invalid. ");
//        return -1;
//      }

    /*
    if (0 == outpath.size()) {
      SX_ERROR("Given output path is invalid.");
      return -1;
    }
    */

//    if (0 == inpath.size()) {
//      CI_LOG_E("Given input path is invalid, size if 0.");
//      return -2;
//    }
//  
//    if (0 > startFrame) {
//      CI_LOG_E("Invalid start frame: " << startFrame);
//      return -4;
//    }
//
//    if (0 > endFrame || startFrame > endFrame) {
//      CI_LOG_E("Invalid endframe: " << endFrame);
//      return -5;
//    }
//
//    if (!ofs.is_open()) {
//      CI_LOG_E("Output file stream not open, did you call open()?");
//      return -6;
//    }
    

  //  CI_LOG_I("inpath: " << inpath.c_str());

    for (int i = startFrame; i <= endFrame; ++i) {

  //    sprintf(name, inpath.c_str(), i);

//      if (false == rx_file_exists(name)) {
//        CI_LOG_E("Cannot find " << name);
//        continue;
//      }
//
//      if ("png" != rx_get_file_ext(name)) {
//        CI_LOG_E("We only support png files.");
//        return -6;
//      }

//      uint64_t n = rx_hrtime();
//      r = rx_load_png(name, &pixels, w, h, channels, &allocated, RX_FLAG_LOAD_AS_RGBA);
//      if (0 >= r) {
//        SX_ERROR("Failed to load:" <<  name);
//        continue;
//      }

//      CI_LOG_I("Loaded " << w << " x " << h << ", channels: " << channels << " " << name);
//
//      if (0 != prev_w && prev_w != w) {
//        CI_LOG_E("Incorrect width, previous file had: " << prev_w << " now we have: " << w);
//        goto error;
//      }

//      if (0 == num_frames && VIDEO_DXT_VERSION_0_0_1 == version) {
//        if (0 != writeU32(0xCAFEBABE)) {
//          goto error;
//        }
//        
//        if (0 != writeU32(version)) {
//          goto error;
//        }
//        
//        if (0 != writeU32(w)) {
//          goto error;
//        }
//        
//        if (0 != writeU32(h)) {
//          goto error;
//        }
//        
//        if (0 != writeU32(0)) {
//          goto error;
//        }
//      }

      /* @todo somehow rygCompress crashes when not allocating a new buffer :/ */
      dxt = (unsigned char*) malloc(w * h);
      if (NULL == dxt) {
        CI_LOG_E("Failed to allocate the output buffer.");
        return -6;
      }
    
      rygCompress(dxt, pixels, w, h, 1);
    
      if (!ofs.write((const char*)dxt, w * h)) {
        CI_LOG_E("Failed to write DXT frame.");
        goto error;
      }

      free(dxt);
      dxt = NULL;

      if (!ofs) {
        CI_LOG_E("Failed to write dxt to output file.");
        goto error;
      }

      prev_w = w;
      prev_h = h;
      num_frames++;
    }

    if (VIDEO_DXT_VERSION_0_0_1 == version) {
      rewriteU32(16, num_frames);
    }

    if (pixels) {
      free(pixels);
      pixels = NULL;
    }

    return 0;

  error:
    if (NULL != pixels) {
      free(pixels);
      pixels = NULL;
    }

    if (NULL != dxt) {
      free(dxt);
      dxt = NULL;
    }
    
    close();

    return -666;
  }
Esempio n. 25
0
int Message::valueAsRange() const
{
    if ( mType != "range" )
		CI_LOG_E("This Message is not a range type! Results may be unpredicatable.");
    return atoi( mValue.c_str() );
}
Esempio n. 26
0
const string& Message::valueAsString() const
{
    if ( mType != "string" )
		CI_LOG_E( "This Message is not a string type! Returning raw value as string." );
    return mValue;
}
Esempio n. 27
0
void TreeHeartbeat::getNewEvents()
{
   try
   {
      JsonTree queryResult = queryWinChattyv2Server("waitForEvent?lastEventId=" + toString(m_last_event_id));

      if(queryResult.hasChild("lastEventId"))
      {
         std::string strvalue = queryResult["lastEventId"].getValue();

         if(strvalue.length() > 0)
         {
            m_last_event_id = fromString<uint32_t>(strvalue);
         }

         if(queryResult.hasChild("events"))
         {
            AppMessageRef worldTreeEventMessage = AppMessage::create(AppMessage::message_type::WORLDTREE_EVENT);

            const JsonTree& events = queryResult.getChild("events");
            for(size_t event_i = 0; event_i < events.getNumChildren(); event_i++)
            {
               const JsonTree& this_event = events.getChild(event_i);

               const JsonTree& event_data = this_event.getChild("eventData");

               strvalue = this_event["eventType"].getValue();

               if(strvalue == "newPost")
               {
                  const JsonTree& post = event_data.getChild("post");

                  worldTreeEventMessage->AsWorldTreeEvent()->m_new_posts_list.push_front(getChattyPostDataRefFromJSONPost(post));
               }
               else if(strvalue == "categoryChange")
               {

               }
               else if(strvalue == "serverMessage")
               {

               }
               else if(strvalue == "lolCountsUpdate")
               {

               }
            }

            sortChattyPostDataList(worldTreeEventMessage->AsWorldTreeEvent()->m_new_posts_list);

            if(!m_canceled)
            {
               ((LampApp*)app::App::get())->postMessage(worldTreeEventMessage);
            }
         }
      }
      else
      {
         ci::sleep(2000.0f);
      }
   }
   catch(ci::Exception& exc)
   {
      CI_LOG_E("Error calling WCv2 method waitForEvent: " << exc.what());
      ci::sleep(2000.0f);
   }
}
Esempio n. 28
0
// static
void VM::unhandledExceptionCallback( Dart_Handle error )
{
	 CI_LOG_E( Dart_GetError( error ) );
}
Esempio n. 29
0
void TreeHeartbeat::getWorldTree()
{
   getLastEventId();

   try
   {
      JsonTree queryResult = queryWinChattyv2Server("getChatty");

      if(queryResult.hasChild("threads"))
      {
         AppMessageRef worldTreeBuiltMessage = AppMessage::create(AppMessage::message_type::WORLDTREE_BUILT);

         const JsonTree& threads = queryResult.getChild("threads");
         for(size_t thread_i = 0; thread_i < threads.getNumChildren(); thread_i++)
         {
            std::list<ChattyPostDataRef> list_of_posts_in_thread;

            const JsonTree& this_thread = threads.getChild(thread_i);
            if(this_thread.hasChild("posts"))
            {
               const JsonTree& posts = this_thread.getChild("posts");
               for(size_t post_i = 0; post_i < posts.getNumChildren(); post_i++)
               {
                  const JsonTree& post = posts.getChild(post_i);
                  list_of_posts_in_thread.push_back(getChattyPostDataRefFromJSONPost(post));
               }
            }

            // sort list into tree
            chatty_post_id thread_id = fromString<uint32_t>(this_thread["threadId"].getValue());
            ChattyPostDataRef thread_tree;
            
            for(std::list<ChattyPostDataRef>::iterator it = list_of_posts_in_thread.begin();
                it != list_of_posts_in_thread.end();
                it++)
            {
               if((*it)->m_id == thread_id)
               {
                  thread_tree = *it;
                  list_of_posts_in_thread.erase(it);
                  break;
               }
            }

            if(thread_tree)
            {
               thread_tree->adoptChildren(list_of_posts_in_thread);
               CI_ASSERT(list_of_posts_in_thread.size() == 0);
            }

            thread_tree->markAsRead(false);

            // add tree to list of thread trees
            worldTreeBuiltMessage->AsWorldTreeBuilt()->m_thread_tree_list.push_back(thread_tree);
         }

         if(!m_canceled)
         {
            ((LampApp*)app::App::get())->postMessage(worldTreeBuiltMessage);
         }
      }
   }
   catch(ci::Exception& exc)
   {
      CI_LOG_E("Error calling WCv2 method getChatty: " << exc.what());
      m_last_event_id = 0;
   }
}
Esempio n. 30
0
    void Scene::initialize( const std::vector<ActorUId>& persistent_actors )
    {
        mSceneManager = EventManager::create("Scene "+mName+" Manager");
        Controller::get()->eventManager()->addListener(fastdelegate::MakeDelegate(this, &Scene::handleInitGUI), InitGUIEvent::TYPE);
        Controller::get()->eventManager()->addListener( fastdelegate::MakeDelegate(this, &Scene::handleSceneUpdate), SceneUpdateEvent::TYPE );
        Controller::get()->eventManager()->addListener( fastdelegate::MakeDelegate(this, &Scene::handleReturnActorCreate), ReturnActorCreatedEvent::TYPE );
        Controller::get()->eventManager()->addListener( fastdelegate::MakeDelegate(this, &Scene::handleScenePreDraw), ScenePreDrawEvent::TYPE );
        Controller::get()->eventManager()->addListener( fastdelegate::MakeDelegate(this, &Scene::handleSceneDraw), SceneDrawEvent::TYPE );
        Controller::get()->eventManager()->addListener( fastdelegate::MakeDelegate(this, &Scene::handleShutDown), ShutDownEvent::TYPE );
        
        if( !persistent_actors.empty() ){
            for(auto &id : persistent_actors)
            {
                auto actor_weak = ActorManager::get()->retreiveUnique(id);
                mActors.insert( std::make_pair(id, actor_weak) );
            }
        }
        
        auto init = ConfigManager::get()->retreiveActorsForScene( mName );
        
        ///call to inherited initialize for sub classes to pulll custom shit out of the config
        initialize( ConfigManager::get()->retreiveScene(mName) );
        
        try {
            
            //TODO: the problem with persistent actors is how to manage state across scenes, how to identify actors of the same type across scenes that are persistent, one solution is destroy all and reload referencing a serialized state file that is written out and read back in or something
            //for now, just sending across actors marked 'persistent' and not including them in the config for the next scene, the state has to be handled at runtime then
            
            auto & actors = init.getChildren();
            
            auto it = actors.begin();
            auto end = actors.end();
            for(;it!=end;++it){
                auto actor_name = it->getValueForKey("name");
                CI_LOG_V("found actor: "+actor_name);

                auto onInit = it->getValueForKey<bool>( "create_on_scene_init" );
                auto persistent = it->getValueForKey<bool>( "persistent" );
                
                if( persistent ){
                    //make sure its not already in there
                   if( !ec::ActorManager::get()->actorExists( ec::getHash(actor_name) ) ){
                       if( onInit ){
                           //make sure it shuld be created on scene init
                           CI_LOG_V("creating actor: "+actor_name);
                           Controller::get()->eventManager()->triggerEvent( CreateActorEvent::create( mName, actor_name) );
                       }
                    }
                }else if (onInit){
                    //make sure it shuld be created on scene init
                    CI_LOG_V("creating actor: "+actor_name);
                    Controller::get()->eventManager()->triggerEvent( CreateActorEvent::create( mName, actor_name) );

                }

                
            }
            
        } catch (const ci::JsonTree::ExcChildNotFound &e) {
            CI_LOG_E("actors not found in init");
        }
        
      
        ///POST INITIALIZE ALL ACTORS
        auto actor = mActors.begin();
        auto end = mActors.end();
        
        while( actor != end )
        {
            if(auto a = (*actor).second.lock()){
                a->postInit();
                ++actor;
            }else{
                CI_LOG_E("Actor is missing");
                ec::Controller::get()->eventManager()->triggerEvent(DestoryActorEvent::create((*actor).first));
                actor = mActors.erase(actor);
            }
        }
        
        postInit();
        
        ///run setup events;
        manager()->update();
        
    }