void ParticleSystemCore::sortParticles(DrawEnv *pEnv)
{
    //This should be called if the ParticleSystem has
    //just finished an update

	//extract camera position
	Pnt3f CameraLocation(0.0,0.0,0.0);
    pEnv->getCameraToWorld().mult(CameraLocation,CameraLocation);
    if(getSystem() != NULL && getSortingMode() != NONE && _mfSort.size() > 0)
    {
		// initialize sort funcion struct
		TheSorter = ParticleSortByViewPosition(getSystem(),CameraLocation,true);

		// get sorting order
		switch(getSortingMode())
        {
			case FRONT_TO_BACK:
				//Use the FrontToBack Comparitor, already initialized above
				break;

			case BACK_TO_FRONT:
				//Use the BackToFront Comparitor, changes sorting order
				TheSorter = ParticleSortByViewPosition(getSystem(),CameraLocation,false);
				break;
        }
		
		// particles sorted using stdlib's quicksort
		std::qsort(&_mfSort[0],_mfSort.size(), sizeof(MFUInt32::StoredType),qSortComp);
		// sort with std::sort
		//std::sort(getSort().begin(), getSort().end(), TheSorter);
    }
}
Beispiel #2
0
GHOST_EventKey* GHOST_SystemWin32::processKeyEvent(GHOST_IWindow *window, bool keyDown, WPARAM wParam, LPARAM lParam)
{
	GHOST_TKey key = ((GHOST_SystemWin32*)getSystem())->convertKey(window, wParam, lParam);
	GHOST_EventKey* event;
	if (key != GHOST_kKeyUnknown) {
		MSG keyMsg;
		char ascii = '\0';

			/* Eat any character related messages */
		if (::PeekMessage(&keyMsg, NULL, WM_CHAR, WM_SYSDEADCHAR, PM_REMOVE)) {
			ascii = (char) keyMsg.wParam;
			
		}

		event = new GHOST_EventKey(getSystem()->getMilliSeconds(), keyDown ? GHOST_kEventKeyDown: GHOST_kEventKeyUp, window, key, ascii);
		
#ifdef BF_GHOST_DEBUG
		std::cout << ascii << std::endl;
#endif
	}
	else {
		event = 0;
	}
	return event;
}
Beispiel #3
0
BaseThing::BaseThing(const PropertySystem& sys): AbstractThing(sys) {
	values.resize(getSystem().size());
	values[0] = nullptr;
	for (size_t i = 1; i < getSystem().size(); i++) {
		values[i] = getSystem()[i].def;
	}
}
Beispiel #4
0
TEST_F( System, DISABLED_timer_queue_cancel ) {
	int count=0;
	util::id::Ident id = getSystem()->registerTimer( 10000, boost::bind(&timerCallback,&count,_1) );
	ASSERT_TRUE( util::id::isValid(id) );

	getSystem()->unregisterTimer( id );
	ASSERT_TRUE( count == 0 );
}
Beispiel #5
0
void UIWindow::showAds ()
{
	if (getSystem().hasItem(PAYMENT_ADFREE)) {
		debug(LOG_CLIENT, "skip ads");
		return;
	}
	getSystem().showAds(true);
	info(LOG_CLIENT, "show ads");
}
void ParticleSystemCore::adjustVolume(Volume & volume)
{
    //The adjusted volume is dependent on the Particle System as well as the 
    //Particle Drawer
	Inherited::adjustVolume(volume);

    if(getDrawer() != NULL && getSystem() != NULL)
    {
        getDrawer()->adjustVolume(getSystem(), volume);
    }
}
Beispiel #7
0
void UIWindow::showFullscreenAds ()
{
	if (getSystem().hasItem(PAYMENT_ADFREE)) {
		debug(LOG_CLIENT, "skip ads");
		return;
	}

	if (!getSystem().showFullscreenAds())
		error(LOG_CLIENT, "failed to show the fullscreen ads");
	else
		info(LOG_CLIENT, "show fullscreen ads");
}
void ParticleSystemCore::checkAndInitializeSort(void)
{

	if(getMFSort()->size() != getSystem()->getNumParticles() && getSortingMode() != NONE)
	{	// re-init _mfSort if there is a discrepency between number of particles in each
		editMFSort()->resize(getSystem()->getNumParticles());
		//initialize _mfSort
		for(UInt32 i(0); i < getSystem()->getNumParticles(); ++i)
		{
			editSort(i) = i;
		}
	}

}
GHOST_EventButton *GHOST_SystemWin32::processButtonEvent(
        GHOST_TEventType type,
        GHOST_IWindow *window,
        GHOST_TButtonMask mask)
{
	return new GHOST_EventButton(getSystem()->getMilliSeconds(), type, window, mask);
}
Beispiel #10
0
// Invalidating a Subsystem's topology cache forces invalidation of the
// whole System's topology cache, which will in turn invalidate all the other
// Subsystem's topology caches.
void Subsystem::Guts::invalidateSubsystemTopologyCache() const {
    if (m_subsystemTopologyRealized) {
        m_subsystemTopologyRealized = false;
        if (isInSystem()) 
            getSystem().getSystemGuts().invalidateSystemTopologyCache();
    }
}
Beispiel #11
0
GHOST_EventKey* GHOST_SystemWin32::processKeyEvent(GHOST_IWindow *window, RAWINPUT const& raw)
{
	int keyDown=0;
	char vk;
	GHOST_SystemWin32 * system = (GHOST_SystemWin32 *)getSystem();
	GHOST_TKey key = system->hardKey(window, raw, &keyDown, &vk);
	GHOST_EventKey* event;
	if (key != GHOST_kKeyUnknown) {
		char ascii = '\0';

		unsigned short utf16[2]={0};
		BYTE state[256];
		GetKeyboardState((PBYTE)state);

		if(ToAsciiEx(vk, 0, state, utf16, 0, system->m_keylayout))
				WideCharToMultiByte(CP_ACP, 0x00000400, 
									(wchar_t*)utf16, 1,
									(LPSTR) &ascii, 1,
									NULL,NULL);

		event = new GHOST_EventKey(system->getMilliSeconds(), keyDown ? GHOST_kEventKeyDown: GHOST_kEventKeyUp, window, key, ascii);
		
#ifdef GHOST_DEBUG
		std::cout << ascii << std::endl;
#endif
	}
	else {
		event = 0;
	}
	return event;
}
Beispiel #12
0
//------------------------------------------------------------------------------
// onStartScanEvent() -- process the start of a scan
//------------------------------------------------------------------------------
bool Antenna::onStartScanEvent(Basic::Integer* const bar)
{
   // Pass the event to our system
   RfSystem* p = getSystem();                
   if (p != 0) p->event(SCAN_START, bar);
   return true;
}
Beispiel #13
0
long File::write (const unsigned char *buf, size_t len, const char *mode) const
{
	System.mkdir(getPath());

	SDL_RWops *rwops = SDL_RWFromFile(_rawPath.c_str(), mode);
	if (!rwops) {
		Log::info(LOG_SYSTEM, "failed to get stream for %s", _rawPath.c_str());
		return -1L;
	}

	int remaining = len;
	while (remaining) {
		const size_t written = SDL_RWwrite(rwops, buf, 1, remaining);
		if (written == 0) {
			Log::info(LOG_SYSTEM, "failed to write to stream %s", _rawPath.c_str());
			return -1L;
		}

		remaining -= written;
		buf += written;
	}

	SDL_RWclose(rwops);
	getSystem().syncFiles();

	return len;
}
bool SQLitePersister::updateCampaign (Campaign* campaign)
{
	Log::info(LOG_CAMPAIGN, "update campaign progress in database for %s", campaign->getId().c_str());
	Transaction t(*this);
	ExecutionTime e("save progress");

	activateCampaign(campaign);

	SQLiteStatement stmt;
	prepare(stmt, "INSERT OR REPLACE INTO " TABLE_GAMEMAPS " (campaignid, mapid, locked, time, finishPoints, stars, version) VALUES (?, ?, ?, ?, ?, ?, ?);");
	if (!stmt)
		return false;

	stmt.bindText(1, campaign->getId());
	stmt.bindText(7, Singleton<Application>::getInstance().getName());
	const Campaign::MapList& maps = campaign->getMaps();
	for (Campaign::MapListConstIter i = maps.begin(); i != maps.end(); ++i) {
		const CampaignMapPtr& map = *i;
		saveCampaignMapParameters(map.get(), stmt);
		stmt.step(true);
	}
	const bool savedLives = saveLives(campaign->getLives(), campaign->getId());
	if (savedLives)
		Log::info(LOG_CAMPAIGN, "updated campaign progress in database for %s", campaign->getId().c_str());

	getSystem().syncFiles();

	return savedLives;
}
void ModuleManager::syncModuleWithSystemState( IModule* module )
{
	try
	{
		switch( getSystem()->getState() )
		{
			case SystemState_Initializing:
				// module is already initialized
				break;
			case SystemState_Integrating:
			case SystemState_Integrated:
				updateModule( module, ModuleState_Integrated );
				break;
			case SystemState_IntegratingPresentation:
			case SystemState_Running:
				updateModule( module, ModuleState_PresentationIntegrated );
				break;
			default:
				assert( false );
		}
	}
	catch( std::exception& e )
	{
		module->abort();
		CORAL_THROW( ModuleLoadException, "exception raised by module '"
						<< module->getNamespace()->getFullName()
						<< "' during update: " << e.what() );
	}
}
GHOST_EventKey* GHOST_SystemWin32::processKeyEvent(GHOST_IWindow *window, RAWINPUT const& raw)
{
	int keyDown=0;
	char vk;
	GHOST_SystemWin32 * system = (GHOST_SystemWin32 *)getSystem();
	GHOST_TKey key = system->hardKey(window, raw, &keyDown, &vk);
	GHOST_EventKey* event;

	if (key != GHOST_kKeyUnknown) {
		char utf8_char[6] = {0} ;

		wchar_t utf16[2]={0};
		BYTE state[256];
		GetKeyboardState((PBYTE)state);  

		if(ToUnicodeEx(vk, 0, state, utf16, 2, 0, system->m_keylayout))
			WideCharToMultiByte(CP_UTF8, 0, 
									(wchar_t*)utf16, 1,
									(LPSTR) utf8_char, 5,
									NULL,NULL); else *utf8_char = 0;

		if(!keyDown) utf8_char[0] = '\0';
		
		event = new GHOST_EventKey(system->getMilliSeconds(), keyDown ? GHOST_kEventKeyDown: GHOST_kEventKeyUp, window, key, (*utf8_char & 0x80)?'?':*utf8_char, utf8_char);
		
#ifdef GHOST_DEBUG
		std::cout << ascii << std::endl;
#endif
	}
	else {
		event = 0;
	}
	return event;
}
Beispiel #17
0
//------------------------------------------------------------------------------
// onEndScanEvent() -- process the end of a scan
//------------------------------------------------------------------------------
bool Antenna::onEndScanEvent(Basic::Integer* const bar)
{
   // Pass the event to our sensor
   RfSystem* p = getSystem();                
   if (p != 0) p->event(SCAN_END, bar);
   return true;
}
Beispiel #18
0
void GameFramework::update( long time )
{
	g_GlobalVal.updateFrame();

	EntitySystem* entitySystem = getSystem()->getEntitySystem();
	entitySystem->update( time );
	//getGameObjectSystem()->update( time );
}
GHOST_Event* GHOST_SystemWin32::processWindowEvent(GHOST_TEventType type, GHOST_IWindow* window)
{
	GHOST_System* system = (GHOST_System*)getSystem();

	if (type == GHOST_kEventWindowActivate) {
		system->getWindowManager()->setActiveWindow(window);
	}

	return new GHOST_Event(system->getMilliSeconds(), type, window);
}
Beispiel #20
0
/*
 * A Subsystem should invoke this method during Instance stage for each 
 * triggered event it defines. It allocates a global event ID for the event, 
 * registers that ID as belonging to this Subsystem, and allocates space in the
 * State for the event trigger function.
 * 
 * @param state     the State which is being realized
 * @param eventId   on exit, the newly allocated event ID is stored here
 * @param triggerFunctionIndex  
 *      on exit, the index corresponding to the event's trigger function
 *      is stored here (this is a local, per-Subsystem, per-Stage index)
 * @param stage     the Stage at which the event will be evaluated
 */
void Subsystem::Guts::
createTriggeredEvent(const State& state, EventId& eventId, 
                     EventTriggerByStageIndex& triggerFunctionIndex, 
                     Stage stage) const 
{
    eventId = getSystem().getDefaultSubsystem()
                         .createEventId(getMySubsystemIndex(), state);
    triggerFunctionIndex = 
        state.allocateEventTrigger(getMySubsystemIndex(), stage, 1);
}
void ParticleSystemCore::fill(DrawableStatsAttachment *pStat)
{
    if(getDrawer() == NULL)
    {
        FINFO(("ParticleSystemCore::fill(DrawableStatsAttachment *): "
               "No Drawer Attached.\n"));

        return;
    }
    if(getSystem() == NULL)
    {
        FINFO(("ParticleSystemCore::fill(DrawableStatsAttachment *): "
               "No System Attached.\n"));

        return;
    }

    getDrawer()->fill(pStat, getSystem(), *getMFSort());
}
Beispiel #22
0
GHOST_EventCursor *GHOST_SystemWin32::processCursorEvent(GHOST_TEventType type, GHOST_IWindow *Iwindow)
{
	GHOST_TInt32 x_screen, y_screen;
	GHOST_SystemWin32 *system = (GHOST_SystemWin32 *) getSystem();
	GHOST_WindowWin32 *window = (GHOST_WindowWin32 *) Iwindow;
	
	system->getCursorPosition(x_screen, y_screen);

	/* TODO: CHECK IF THIS IS A TABLET EVENT */
	bool is_tablet = false;

	if (is_tablet == false && window->getCursorGrabModeIsWarp()) {
		GHOST_TInt32 x_new = x_screen;
		GHOST_TInt32 y_new = y_screen;
		GHOST_TInt32 x_accum, y_accum;
		GHOST_Rect bounds;

		/* fallback to window bounds */
		if (window->getCursorGrabBounds(bounds) == GHOST_kFailure) {
			window->getClientBounds(bounds);
		}

		/* could also clamp to screen bounds
		 * wrap with a window outside the view will fail atm  */

		bounds.wrapPoint(x_new, y_new, 2); /* offset of one incase blender is at screen bounds */

		window->getCursorGrabAccum(x_accum, y_accum);
		if (x_new != x_screen || y_new != y_screen) {
			/* when wrapping we don't need to add an event because the
			 * setCursorPosition call will cause a new event after */
			system->setCursorPosition(x_new, y_new); /* wrap */
			window->setCursorGrabAccum(x_accum + (x_screen - x_new), y_accum + (y_screen - y_new));
		}
		else {
			return new GHOST_EventCursor(system->getMilliSeconds(),
			                             GHOST_kEventCursorMove,
			                             window,
			                             x_screen + x_accum,
			                             y_screen + y_accum
			                             );
		}

	}
	else {
		return new GHOST_EventCursor(system->getMilliSeconds(),
		                             GHOST_kEventCursorMove,
		                             window,
		                             x_screen,
		                             y_screen
		                             );
	}
	return NULL;
}
 void setLengthUnit(std::string v){
   esutil::Error err( getSystem()->comm );
   if( v != "LJ" && v != "nm" && v != "A" ){
     std::stringstream msg;
     msg<<"Wrong unit length: "<< v << "  It should be string: LJ, nm or A" <<"\n";
     err.setException( msg.str() );
     err.checkException();
   }
   
   length_unit = v;
 }
void ParticleSystemCore::changed(ConstFieldMaskArg whichField, 
                                 UInt32            origin,
                                 BitVector         details)
{
    Inherited::changed(whichField, origin, details);

    if(whichField & SystemFieldMask &&
       getSystem() != NULL)
    {
        getSystem()->addParticleSystemListener(&_SystemUpdateListener);
    }
    if(((whichField & SystemFieldMask) || (whichField & ParentsFieldMask))
       && _mfParents.size() > 0)
    {
        getSystem()->setBeacon(dynamic_cast<Node*>(_mfParents.front()));
    }
    if((whichField & ParentsFieldMask)
       && _mfParents.size() > 1)
    {
        SWARNING << "ParticleSystemCore: Cannot have a single instance of"
                    "ParticleSystemCore attached to more than 1 Node." << std::cout;
    }

    if(whichField & SystemFieldMask ||
       whichField & DrawerFieldMask)
    {
        for(UInt32 i = 0; i < _mfParents.size(); i++)
        {
            _mfParents[i]->invalidateVolume();
        }
    }

    if((whichField & SystemFieldMask) || (whichField & SortFieldMask))
    {
        if(getSystem() != NULL)
        {
            if(getMFSort()->size() != getSystem()->getNumParticles())
            {
                editMFSort()->resize(getSystem()->getNumParticles());

                //initialize _mfSort
                for(UInt32 i(0); i < getSystem()->getNumParticles(); ++i)
                {
                    editSort(i) = i;
                }
            }
        }
        else
        {
            if(getMFSort()->size() != 0)
            {
                editMFSort()->clear();
            }
        }
    }
}
Beispiel #25
0
TEST_F( System, DISABLED_timer_attach ) {
	int count=0;
	util::id::Ident id = getSystem()->registerTimer( 10, boost::bind(&timerCallback,&count,_1) );
	ASSERT_TRUE( util::id::isValid(id) );
	
	{	//	Wait for timer!
		boost::unique_lock<boost::mutex> lock( impl::mutex );
		impl::wakeup.wait(lock);
	}

	ASSERT_TRUE( count == 1 );
}
Beispiel #26
0
Entity* Model::createEntity( String const& aClassname, FullID const& aFullID )
{
    if( aFullID.getSystemPath().isModel() )
    {
        THROW_EXCEPTION( BadSystemPath, "empty SystemPath" );
    }

    System* aContainerSystemPtr( getSystem( aFullID.getSystemPath() ) );
    Entity* retval( 0 );

    if ( !aContainerSystemPtr )
    {
        THROW_EXCEPTION( BadSystemPath,
                         "[" + aFullID.getSystemPath().asString()
                         + "] cannot be reached" );
    }
 
    switch( aFullID.getEntityType() )
    {
    case EntityType::VARIABLE:
        {
            retval = createVariable( aClassname );
            retval->setID( aFullID.getID() );
            aContainerSystemPtr->registerEntity(
                    static_cast< Variable* >( retval ) );
        }
        break;

    case EntityType::PROCESS:
        {
            retval = createProcess( aClassname );
            retval->setID( aFullID.getID() );
            aContainerSystemPtr->registerEntity(
                    static_cast< Process* >( retval ) );
        }
        break;

    case EntityType::SYSTEM:
        {
            retval = createSystem( aClassname );
            retval->setID( aFullID.getID() );
            aContainerSystemPtr->registerEntity(
                    static_cast< System* >( retval ) );
        }
        break;

    default:
        THROW_EXCEPTION( InvalidEntityType, "invalid EntityType specified" );
    }

    return retval;
}
bool SQLitePersister::resetState (Campaign* campaign)
{
	Transaction t(*this);
	const int lives = INITIAL_LIVES;
	if (saveLives(lives, campaign->getId()) && deleteMaps(campaign) && activateCampaign(campaign)) {
		campaign->setLives(lives);

		getSystem().syncFiles();
		return true;
	}
	Log::error(LOG_CAMPAIGN, "error reseting the state");
	return false;
}
Beispiel #28
0
GHOST_EventWheel *GHOST_SystemWin32::processWheelEvent(GHOST_IWindow *window, WPARAM wParam, LPARAM lParam)
{
	// short fwKeys = LOWORD(wParam);			// key flags
	int zDelta = (short) HIWORD(wParam);    // wheel rotation
	
	// zDelta /= WHEEL_DELTA;
	// temporary fix below: microsoft now has added more precision, making the above division not work
	if (zDelta <= 0) zDelta = -1; else zDelta = 1;
	
	// short xPos = (short) LOWORD(lParam);	// horizontal position of pointer
	// short yPos = (short) HIWORD(lParam);	// vertical position of pointer
	return new GHOST_EventWheel(getSystem()->getMilliSeconds(), window, zDelta);
}
Beispiel #29
0
GHOST_TSuccess GHOST_SystemWin32::pushDragDropEvent(GHOST_TEventType eventType, 
		GHOST_TDragnDropTypes draggedObjectType,
		GHOST_IWindow *window,
		int mouseX, int mouseY,
		void *data)
{
	GHOST_SystemWin32 *system = ((GHOST_SystemWin32 *)getSystem());
	return system->pushEvent(new GHOST_EventDragnDrop(system->getMilliSeconds(),
	                                                  eventType,
	                                                  draggedObjectType,
	                                                  window, mouseX, mouseY, data)
	                         );
}
Beispiel #30
0
boost::optional<Quantity> QuantityFactorySingleton::createQuantity(
    double value,
    const std::string& unitString) const
{
  // create return variable, and try to create unit
  OptionalQuantity result;
  UnitSystem system = getSystem(unitString);
  OptionalUnit unit = UnitFactory::instance().createUnit(unitString,system);
  if (unit) {
    result = Quantity(value,*unit);
  }
  return result;
}