Exemplo n.º 1
0
bool Bat::collisionOccured(const Character* enemy)
{
	if (Monster::collisionOccured(enemy))
	{
		EffectManager* effectManager = (EffectManager*)this->getParent()->getChildByTag(EFFECT_MANAGER_TAG);
		effectManager->createEffect(EffectManager::BAT_DIE, this->getPosition());
		return true;
	}
	return false;
}
void loop()
{
    time = millis();
    SC.Poll(time);
    // PollOffHooks returns 
    bool offHookRemote = SC.IsOffHookRemote();
    bool offHookLocal = SC.IsOffHookLocal();
    
    //bool offHookLocal = time & 2048;
    // When low power mode is enabled, notify the EM.  When the EM is done
    // with its shutdown routine, then outright kill the power.

    // Poll whether the power management low power status has changed and act
    // on it.
    if (PM.Poll(time))
    {
        if (PM.GetLowPowerStatus() == PM_LOW_POWER_MODE_ON)
        {
            EM.DisableEffects();
        } else {
            EM.EnableEffects();
        }
    }
    EM.Poll(time, offHookLocal);
    PhoneControl(offHookLocal, offHookRemote);

#ifdef WATCHDOG_ENABLED
    if ((time - watchdogTime0) > WATCHDOG_PERIOD_MS)
    {
        watchdogTime0 = time;
        PRINT("* time: ");
        PRINTLN((unsigned long) time);
    }
#endif
#ifdef BLINK_ENABLED
    if ((time - blinkTime0) > BLINK_MS)
    {
        blinkTime0 = time;
        blinkMode = !blinkMode;
        digitalWrite(BLINK_PIN, blinkMode ? HIGH : LOW);
    }    
#endif

    // Modulate Framerate a bit
    unsigned long dur = millis() - time;
    if(dur < 20)
        delay(20 - dur);
    
    // Output Random Value for WatchDog 'Duino
    digitalWrite(WATCHDOG_PULSE_PIN, ((time >> 8) & 0x1) == 1 ? HIGH : LOW);
}
Exemplo n.º 3
0
int main(int argc, char *argv[]) {
    std::cout << "Initializing Effect Master 3000..." << std::endl;

    signal(SIGINT, SignalHandler);

    EffectManager *mgr = EffectManager::getInstance();
    Environment *env = mgr->getEnvironment();
    env->loadConfig("effectmaster.conf");

    if (!createWindow("Effect Master 3000", env->getScreenWidth(), env->getScreenHeight(), env->isFullscreen()) ||
            !initOpenGL(env->getScreenWidth(), env->getScreenHeight())) {
        std::cout << "Error creating window!" << std::endl;
        exit(1);
    }

    GLenum err = glewInit();
    if (GLEW_OK != err) {/* Problem: glewInit failed, something is seriously wrong. */
      std::cout << "Error initializing GLEW: " << glewGetErrorString(err)  << std::endl;
      exit(1);
    }

    int fps = env->getFps();
    int msPerFrame = 1000/fps;
    int passedMS = msPerFrame;
    unsigned int frameStart = 0;
    int rest = 0;

    std::cout << "Initialization done!" << std::endl;

    mgr->init();

    while(!done) {
        passedMS = SDL_GetTicks() - frameStart;
        frameStart = SDL_GetTicks();
        mgr->animate(passedMS);
        mgr->draw();
        SDL_GL_SwapBuffers();
        userInput();
        rest = msPerFrame - (SDL_GetTicks() - frameStart);
        if (rest < 0 )
            rest = 0;
        SDL_Delay(rest);
    }

    std::cout << "Shutting down Effect Master 3000..." << std::endl;
    delete env;
    delete mgr;

    return 0;
}
Exemplo n.º 4
0
EffectManager* EffectManager::create()
{
    EffectManager *pRet = new EffectManager();
    if (pRet!=nullptr)
    {
        pRet->init();
        pRet->autorelease();
        return pRet;
    }
    else
    {
        delete pRet;
        pRet = NULL;
        return NULL;
    }
}
Exemplo n.º 5
0
/**
*  @brief
*    Constructor
*/
Effect::Effect(EffectManager &cManager, const String &sName) : PLCore::Resource<Effect>(sName, &cManager),
	m_pParameterManager(new ParameterManager(cManager.GetRendererContext())),
	m_nFlags(0),
	m_bBlend(false),
	m_nSelectedTechnique(-1)
{
}
Exemplo n.º 6
0
EffectManager::EffectManager(Widget *parent) :
    Widget(Rect(0, 0, GRSYS_WIDTH, GRSYS_HEIGHT), parent),
    m_isActive(false)
{
    auto event = [](Timer *timer) {
        EffectManager *self = (EffectManager*)timer->userData();
        self->timerEvent();
    };

    setFullScreenBlock(false);
    setBlockable(false);

    timer.setUserData(this);
    timer.timerEventSignal().connect( event );
    memset(&prev_img, 0, sizeof(prev_img));
    memset(&next_img, 0, sizeof(next_img));
}
void setup()
{
    state = STATE_IDLE;

    // Pin assignments

#ifdef USE_UART
    SERIAL.begin(SERIAL_RATE);
    PRINTLN("START");
#endif

    EM.AddEffectsArrays
    (
        effectsIdle,        EFFECTS_NUM_IDLE, // Effects array, length
        effectsRing,        EFFECTS_NUM_RING, 
        effectsCall,        EFFECTS_NUM_CALL,
        effectsOver,        EFFECTS_NUM_OVER
    );
    EM.SetMode(EM_MODE_IDLE);
    EM.InitHardware();
    SC.InitPins();
    PM.InitPins();

    time = millis();
   
#ifdef DEBUG
    debugState = -1;
#endif

#ifdef BLINK_ENABLED
    blinkMode = false;
    pinMode(BLINK_PIN, OUTPUT);
    blinkTime0 = time;
#endif

#ifdef WATCHDOG_ENABLED
    watchdogTime0 = time;
#endif
    //EM.InstallAnimator();
    EM.RebootPanels();

    while (!EM.RebootComplete())
    {
        PM.Poll(millis());
    }
}
Exemplo n.º 8
0
bool EventHandler::keyPressed( const KeyEvent &arg )
{
  switch (arg.key)
  {
	// Quit.
	case KC_ESCAPE:
	  _pApplication->stop();
	  break;

	// Help.
	case KC_H:
	  _pApplication->printHelp();
	  break;

	// Change current joystick.
	case KC_RIGHT:
	  _pEffectMgr->selectEffect(EffectManager::eNone);
	  _pJoystickMgr->selectJoystick(JoystickManager::eNext);
	  _pEffectMgr->checkPlayableEffects();
	  break;
	case KC_LEFT:
	  _pEffectMgr->selectEffect(EffectManager::eNone);
	  _pJoystickMgr->selectJoystick(JoystickManager::ePrevious);
	  _pEffectMgr->checkPlayableEffects();
	  break;

	// Change current effect.
	case KC_UP:
	  _pEffectMgr->selectEffect(EffectManager::eNext);
	  break;
	case KC_DOWN:
	  _pEffectMgr->selectEffect(EffectManager::ePrevious);
	  break;

	// Change current master gain.
	case KC_PGUP:
	  _pJoystickMgr->changeMasterGain(5.0); // Percent
	  break;
	case KC_PGDOWN:
	  _pJoystickMgr->changeMasterGain(-5.0); // Percent
	  break;

	// Toggle auto-center mode.
	case KC_SPACE:
	  _pJoystickMgr->changeAutoCenter();
	  break;

	default:
	  cout << "Non mapped key: " << arg.key << endl;
  }
  return true;
}
Exemplo n.º 9
0
	void printHelp()
	{
	  cout << endl
		   << "Keyboard actions :" << endl
		   << "* Escape      : Exit App" << endl
		   << "* H           : This help menu" << endl
		   << "* Right/Left  : Select next/previous joystick among the FF capable detected ones" << endl
		   << "* Up/Down     : Select next/previous effect for the selected joystick" << endl
		   << "* PgUp/PgDn   : Increase/decrease from 5% the master gain "
		   <<                  "for all the joysticks" << endl
		   << "* Space       : Toggle auto-centering on all the joysticks" << endl;
	  if (_bIsInitialized)
	  {
		cout << endl << "Implemented effects :" << endl << endl;
		_pEffectMgr->printEffects();
		cout << endl;
	  }
	}
Exemplo n.º 10
0
void CMiniSceneGraph::Draw_Internal(float fDeltaTime)
{
	PERF1("MiniSceneGraph_Draw");
	SceneState& sceneState = m_sceneState;
	m_sceneState.m_pd3dDevice = CGlobals::GetRenderDevice();
	RenderDevicePtr pd3dDevice = m_sceneState.m_pd3dDevice;

	EffectManager* pEffectManager = CGlobals::GetEffectManager();
	bool old_IsLocalLightEnabled = pEffectManager->IsLocalLightingEnabled();

	IScene * pOldScene = pEffectManager->GetScene();
	pEffectManager->SetScene(this);

	//////////////////////////////////////////////////////////////////////////
	// Set some initial states for the normal pipeline
	LinearColor fogColor = GetSunLight().ComputeFogColor();
	fogColor.r *= GetFogColorFactor().r;
	fogColor.g *= GetFogColorFactor().g;
	fogColor.b *= GetFogColorFactor().b;
	SetFogColor(fogColor);
	pEffectManager->EnableFog(IsFogEnabled());
	pEffectManager->SetD3DFogState();
#ifdef USE_DIRECTX_RENDERER
	pd3dDevice->SetMaterial((D3DMATERIAL9*)&(sceneState.GetGlobalMaterial()));
#elif defined(USE_OPENGL_RENDERER)
	if (!IsSunLightEnabled())
	{
		// sun light can not be disabled in shader, so we will fake it here. Remove this when shader support turn off global sun light. 
		GetSunLight().SetSunAmbient(LinearColor::White);
		GetSunLight().SetSunDiffuse(LinearColor::Black);
	}
#endif
	
	// disable local lights on bipeds
	if(old_IsLocalLightEnabled)
		pEffectManager->EnableLocalLighting(false);

	// end previous effects, since they may serve different IScene instance.
	pEffectManager->EndEffect();

	// copy the main scene's state
	sceneState.m_pCurrentEffect = pEffectManager->GetCurrentEffectFile();
	
	// rebuild scene state
	sceneState.dTimeDelta = fDeltaTime;
	PrepareRender(m_pCamera, &sceneState);
	
	{
		// all render code goes here

		/**
		All potentially visible scene objects in the scene state are put to three major post rendering lists for rendering.
		Each list is sorted according to object-to-camera distance. And then they will be rendered in the following order:
		- solid object list: sorted from front to back. In mesh report, it will display "F->B:%d". Their bounding boxes will be rendered as red boxes.
		- transparent object list: sorted from back to front. In mesh report, it will display "B->F:%d(%d1)".
		where %d is the total number of meshes rendered and that %d1 is the number of meshes that has been occluded during occlusion testing.
		Their bounding boxes will be rendered as blue boxes.
		- Biped list: sorted by primary asset. In mesh report, it will display "Biped:%d". Their bounding boxes will be rendered as green boxes.
		*/
		{
			// so that mesh and character that contains translucent faces are sorted and rendered later on. 
			if(!sceneState.GetFaceGroups()->IsEmpty())
			{
				sceneState.GetFaceGroups()->Clear();
			}
			sceneState.m_bEnableTranslucentFaceSorting = true;

			// object num in potentially visible set from current view point
			int nPVSCount = 0; 

			//////////////////////////////////////////////////////////////////////////
			/// Draw SkyBox 
			RenderSelection(RENDER_SKY_BOX);

			//////////////////////////////////////////////////////////////////////////
			/// draw solid object rendering list from front to back.
			if(!sceneState.listPRSolidObject.empty())
			{
				RenderSelection(RENDER_MESH_FRONT_TO_BACK);
			}

			//////////////////////////////////////////////////////////////////////////
			// draw smaller object rendering list from back to front.
			if(!sceneState.listPRSmallObject.empty())
			{
				nPVSCount = RenderSelection(RENDER_MESH_BACK_TO_FRONT);
			}
			
			//////////////////////////////////////////////////////////////////////////
			/// Draw queued bipeds
			/// we draw biped after its shadow, because we do not want biped to cast shadows on its own
			if(!sceneState.listPRBiped.empty())
			{
				RenderSelection(RENDER_CHARACTERS);
			}

			//////////////////////////////////////////////////////////////////////////
			// draw transparent object rendering list from back to front.it is rendered after ocean to prevent the ocean color over the particles. 
			if(!sceneState.listPRTransparentObject.empty())
			{
				RenderSelection(RENDER_MESH_TRANSPARENT);
			}

			//////////////////////////////////////////////////////////////////////////
			// render translucent face groups.
			if(!sceneState.GetFaceGroups()->IsEmpty())
			{
				// translucent faces are ignored. 
				RenderSelection(RENDER_TRANSLUCENT_FACE_GROUPS);
				sceneState.GetFaceGroups()->Clear();
			}

			//////////////////////////////////////////////////////////////////////////
			/// render all particle system instances after most of the scene have been rendered.
			/// it is rendered after ocean to prevent the ocean color over the particles. since all particles are z write disabled.
			{
				int nParticlesCount = RenderSelection(RENDER_PARTICLES, fDeltaTime);
			}

			//////////////////////////////////////////////////////////////////////////
			// bounding box
			if(CGlobals::GetScene()->IsShowBoundingBox())
				RenderSelection(RENDER_BOUNDINGBOX);

			//////////////////////////////////////////////////////////////////////////
			// portal 
			if(CGlobals::GetScene()->IsPortalSystemShown())
				RenderSelection(RENDER_PORTAL_SYSTEM);
		}
	}
#ifdef USE_DIRECTX_RENDERER
	if(m_pMask!=0 && pEffectManager->BeginEffect(TECH_GUI, &(m_sceneState.m_pCurrentEffect)))
	{
		/** draw the mask square in front of the screen. */
		CEffectFile* pEffectFile = CGlobals::GetEffectManager()->GetCurrentEffectFile();
		if(pEffectFile == 0)
		{
			//////////////////////////////////////////////////////////////////////////
			// fixed programming pipeline
			float sx = (float)m_nTextureWidth,sy = (float)m_nTextureHeight;

			DXUT_SCREEN_VERTEX v[10];
			v[0].x = 0;  v[0].y = sy; v[0].tu = 0;  v[0].tv = 1.0f;
			v[1].x = 0;  v[1].y = 0;  v[1].tu = 0;  v[1].tv = 0;
			v[2].x = sx; v[2].y = sy; v[2].tu = 1.f; v[2].tv = 1.f;
			v[3].x = sx; v[3].y = 0;  v[3].tu = 1.f; v[3].tv = 0;

			DWORD dwColor = LinearColor(1.f,1.f,1.f,1.f);
			int i;
			for(i=0;i<4;i++)
			{
				v[i].color = dwColor;
				v[i].z = 0;
				v[i].h = 1.0f;
			}
			//pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );		// modulate operation
			//pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG2 );
			//
			//pd3dDevice->SetRenderState( D3DRS_COLORWRITEENABLE,
			//	D3DCOLORWRITEENABLE_RED  | D3DCOLORWRITEENABLE_GREEN |
			//	D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA );

			pd3dDevice->SetRenderState( D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA );

			pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);	
			pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);
			pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_SRCALPHA);

			/*pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP,D3DTOP_SELECTARG2);
			pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1,D3DTA_TEXTURE);
			pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2,D3DTA_CURRENT);

			pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
			pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
			pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2,D3DTA_CURRENT);*/

			pd3dDevice->SetTexture(0, m_pMask->GetTexture());
			RenderDevice::DrawPrimitiveUP( pd3dDevice, RenderDevice::DRAW_PERF_TRIANGLES_MESH, D3DPT_TRIANGLESTRIP, 2, v, sizeof(DXUT_SCREEN_VERTEX) );

			/*pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP,D3DTOP_MODULATE);
			pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1,D3DTA_TEXTURE);
			pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2,D3DTA_CURRENT);

			pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
			pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
			pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2,D3DTA_CURRENT);*/

			pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
			pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

			pd3dDevice->SetRenderState( D3DRS_COLORWRITEENABLE,
					D3DCOLORWRITEENABLE_RED  | D3DCOLORWRITEENABLE_GREEN |
					D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA );
		}
	}
#endif

	// draw the head on display GUI
	RenderHeadOnDisplay();

	//////////////////////////////////////////////////////////////////////////
	// Restore state for the normal pipeline

	pEffectManager->SetScene(pOldScene);

	// enable fog
	pEffectManager->EnableFog(CGlobals::GetScene()->IsFogEnabled());

	// restore the main scene's state
	CGlobals::GetSceneState()->m_pCurrentEffect = sceneState.m_pCurrentEffect;

	if(old_IsLocalLightEnabled)
		pEffectManager->EnableLocalLighting(old_IsLocalLightEnabled);
}
Exemplo n.º 11
0
	HRESULT BMaxObject::Draw(SceneState * sceneState)
	{
		if (!m_pAnimatedMesh)
			return E_FAIL;
		if (GetPrimaryTechniqueHandle() < 0)
		{
			// try loading the asset if it has not been done before. 
			m_pAnimatedMesh->LoadAsset();
			if (m_pAnimatedMesh->IsLoaded())
			{
				SetPrimaryTechniqueHandle(m_pAnimatedMesh->GetPrimaryTechniqueHandle());
				UpdateGeometry();
			}
			return E_FAIL;
		}

		if (!CGlobals::GetEffectManager()->IsCurrentEffectValid())
		{
			return E_FAIL;
		}
		sceneState->SetCurrentSceneObject(this);

		int nIndex = (sceneState && sceneState->IsLODEnabled()) ?
			m_pAnimatedMesh->GetLodIndex(sceneState->GetCameraToCurObjectDistance()/*, GetScaling()*/) : 0;
		CParaXModel* pModel = m_pAnimatedMesh->GetModel(nIndex);
		if (pModel == NULL)
			return E_FAIL;
		
		int nRestoreSpecialTextures = -1;
		for (auto const & tex : mReplaceTextures)
		{
			if(pModel->specialTextures[tex.first] >= 0)
				pModel->replaceTextures[pModel->specialTextures[tex.first]] = tex.second;
			else
			{
				// if there is only one texture, we will force replace it even there is no special replaceable id redefined.
				if (pModel->GetObjectNum().nTextures <= 1 && nRestoreSpecialTextures<0)
				{
					nRestoreSpecialTextures = tex.first;
					pModel->specialTextures[tex.first] = tex.first;
					pModel->replaceTextures[pModel->specialTextures[tex.first]] = tex.second;
					break;
				}
			}
		}

		sceneState->SetCurrentSceneObject(this);
		SetFrameNumber(sceneState->m_nRenderCount);
		// get world transform matrix
		Matrix4 mxWorld;
		GetRenderMatrix(mxWorld);


		RenderDevicePtr pd3dDevice = sceneState->m_pd3dDevice;
		EffectManager* pEffectManager = CGlobals::GetEffectManager();
		pEffectManager->applyObjectLocalLighting(this);

		CEffectFile* pEffectFile = pEffectManager->GetCurrentEffectFile();
		CGlobals::GetWorldMatrixStack().push(mxWorld);

		ApplyBlockLighting(sceneState);

		
		CApplyObjectLevelParamBlock p(GetEffectParamBlock());

		if (pEffectFile == 0)
		{
			// TODO: Fixed Function. 
		}
		else
		{
			bool bUsePointTextureFilter = false;

			// apply block space lighting for object whose size is comparable to a single block size
			if (CheckAttribute(MESH_USE_LIGHT) && !(sceneState->IsShadowPass()))
			{
				BlockWorldClient* pBlockWorldClient = BlockWorldClient::GetInstance();
				if (pBlockWorldClient && pBlockWorldClient->IsInBlockWorld())
				{
					Vector3 vPos = GetPosition();
					vPos.y += 0.1f;
					Uint16x3 blockId_ws(0, 0, 0);
					BlockCommon::ConvertToBlockIndex(vPos.x, vPos.y, vPos.z, blockId_ws.x, blockId_ws.y, blockId_ws.z);
					DWORD dwPositionHash = blockId_ws.GetHashCode();
					uint8_t brightness[2];
					pBlockWorldClient->GetBlockMeshBrightness(blockId_ws, brightness, 2);
					// block light
					float fBlockLightness = Math::Max(pBlockWorldClient->GetLightBrightnessLinearFloat(brightness[0]), 0.1f);
					sceneState->GetCurrentLightStrength().y = fBlockLightness;
					// sun light
					float fSunLightness = Math::Max(pBlockWorldClient->GetLightBrightnessLinearFloat(brightness[1]), 0.1f);
					sceneState->GetCurrentLightStrength().x = fSunLightness;

					float fLightness = Math::Max(fBlockLightness, fSunLightness*pBlockWorldClient->GetSunIntensity());
					if (m_fLastBlockLight != fLightness)
					{
						float fMaxStep = (float)(sceneState->dTimeDelta*0.5f);
						if (dwPositionHash == m_dwLastBlockHash || m_dwLastBlockHash == 0)
							m_fLastBlockLight = fLightness;
						else
							Math::SmoothMoveFloat1(m_fLastBlockLight, fLightness, fMaxStep);

						fLightness = m_fLastBlockLight;
					}
					else
					{
						m_dwLastBlockHash = dwPositionHash;
					}
					sceneState->GetLocalMaterial().Ambient = (LinearColor(fLightness*0.7f, fLightness*0.7f, fLightness*0.7f, 1.f));
					sceneState->GetLocalMaterial().Diffuse = (LinearColor(fLightness*0.4f, fLightness*0.4f, fLightness*0.4f, 1.f));

					sceneState->EnableLocalMaterial(true);
					bUsePointTextureFilter = bUsePointTextureFilter || pBlockWorldClient->GetUsePointTextureFiltering();
				}
			}

			if (bUsePointTextureFilter)
			{
				pEffectManager->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
				pEffectManager->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
			}
			else
			{
				pEffectManager->SetSamplerState(0, D3DSAMP_MINFILTER, pEffectManager->GetDefaultSamplerState(0, D3DSAMP_MINFILTER));
				pEffectManager->SetSamplerState(0, D3DSAMP_MAGFILTER, pEffectManager->GetDefaultSamplerState(0, D3DSAMP_MAGFILTER));
			}

			// just a single standing animation is supported now and looped. 
			UpdateModel(sceneState);
			pModel->draw(sceneState, p.GetParamsBlock()); 
		}

		if (nRestoreSpecialTextures >= 0)
		{
			pModel->specialTextures[nRestoreSpecialTextures] = -1;
			pModel->replaceTextures[nRestoreSpecialTextures] = nullptr;
		}

		CGlobals::GetWorldMatrixStack().pop();
		return S_OK;
	}
Exemplo n.º 12
0
//////////////////////////////////////////////////////////////////////////////
// 뱀파이어 셀프 핸들러
//////////////////////////////////////////////////////////////////////////////
void SummonCasket::execute(Vampire* pVampire, VampireSkillSlot* pSkillSlot, CEffectID_t CEffectID)
throw(Error)
{
    __BEGIN_TRY

    //cout << "TID[" << Thread::self() << "]" << getSkillHandlerName() << " Begin" << endl;

    Assert(pVampire != NULL);
    Assert(pSkillSlot != NULL);

    //cout << "SummonCasket try.." << endl;

    try
    {
        Player* pPlayer = pVampire->getPlayer();
        Zone* pZone = pVampire->getZone();

        Assert(pPlayer != NULL);
        Assert(pZone != NULL);

        if (!pVampire->isVampire()
                && !pVampire->isMonster())
        {
            executeSkillFailNormal(pVampire, getSkillType(), NULL);
            return;
        }


        GCSkillToSelfOK1 _GCSkillToSelfOK1;
        GCSkillToSelfOK3 _GCSkillToSelfOK3;

        SkillType_t SkillType  = pSkillSlot->getSkillType();
        SkillInfo*  pSkillInfo = g_pSkillInfoManager->getSkillInfo(SkillType);

        ZoneCoord_t x = pVampire->getX();
        ZoneCoord_t y = pVampire->getY();

        // Knowledge of Summon 이 있다면 hit bonus 10
        int HitBonus = 0;
        if (pVampire->hasRankBonus(RankBonus::RANK_BONUS_KNOWLEDGE_OF_SUMMON ) )
        {
            RankBonus* pRankBonus = pVampire->getRankBonus(RankBonus::RANK_BONUS_KNOWLEDGE_OF_SUMMON);
            Assert(pRankBonus != NULL);

            HitBonus = pRankBonus->getPoint();
        }

        int  RequiredMP     = decreaseConsumeMP(pVampire, pSkillInfo);
        bool bManaCheck     = hasEnoughMana(pVampire, RequiredMP);
        bool bTimeCheck     = verifyRunTime(pSkillSlot);
        bool bRangeCheck    = checkZoneLevelToUseSkill(pVampire);
        bool bHitRoll       = HitRoll::isSuccessMagic(pVampire, pSkillInfo, pSkillSlot, HitBonus);
        bool bTileCheck     = canBurrow(pZone, x, y);
        bool bMoveModeCheck = pVampire->isWalking();
        bool bEffected      = pVampire->isFlag(Effect::EFFECT_CLASS_CASKET);

        if (bManaCheck && bTimeCheck && bRangeCheck && bHitRoll && bTileCheck && bMoveModeCheck && !bEffected)
        {
            //cout << "SummonCasket Success" << endl;

            decreaseMana(pVampire, RequiredMP, _GCSkillToSelfOK1);

            SkillInput input(pVampire);
            SkillOutput output;
            computeOutput(input, output);


            // 뱀파이어를 땅 위에서 삭제하기 이전에 기술 패킷들을 날린다.
            _GCSkillToSelfOK1.setSkillType(SkillType);
            _GCSkillToSelfOK1.setCEffectID(CEffectID);
            _GCSkillToSelfOK1.setDuration(output.Duration);

            _GCSkillToSelfOK3.setXY(x, y);
            _GCSkillToSelfOK3.setSkillType(SkillType);
            _GCSkillToSelfOK3.setDuration(output.Duration);

            pPlayer->sendPacket(&_GCSkillToSelfOK1);
            pZone->broadcastPacket(x, y, &_GCSkillToSelfOK3, pVampire);

            //---------------------------------------------------------------
            // 기존의 지속 마법 효과를 제거한다.
            //---------------------------------------------------------------
            EffectManager* pEffectManager = pVampire->getEffectManager();
            Assert(pEffectManager!=NULL);

            Effect* pCheckEffect = NULL;

            // 사용자의 level을 구한다.
            int userLevel = pVampire->getLevel();

            Effect::EffectClass effectClass;

            // EFFECT_CLASS_FLARE
            effectClass = Effect::EFFECT_CLASS_FLARE;
            pCheckEffect = pEffectManager->findEffect(effectClass);
            if (pCheckEffect!=NULL)
            {
                int level =	(dynamic_cast<EffectFlare*>(pCheckEffect))->getLevel();

                if (level < userLevel)
                {
                    pEffectManager->deleteEffect(effectClass);
                    pVampire->removeFlag(effectClass);
                }
            }

            // EFFECT_CLASS_DOOM
            effectClass = Effect::EFFECT_CLASS_DOOM;
            pCheckEffect = pEffectManager->findEffect(effectClass);
            if (pCheckEffect!=NULL)
            {
                int level =	(dynamic_cast<EffectDoom*>(pCheckEffect))->getLevel();

                if (level < userLevel)
                {
                    pEffectManager->deleteEffect(effectClass);
                    pVampire->removeFlag(effectClass);
                }
            }

            // EFFECT_CLASS_SEDUCTION
            effectClass = Effect::EFFECT_CLASS_SEDUCTION;
            pCheckEffect = pEffectManager->findEffect(effectClass);
            if (pCheckEffect!=NULL)
            {
                int level =	(dynamic_cast<EffectSeduction*>(pCheckEffect))->getLevel();

                if (level < userLevel)
                    pEffectManager->deleteEffect(effectClass);
                pVampire->removeFlag(effectClass);
            }


            //---------------------------------------------------------------
            // 이펙트 오브젝트를 생성해 붙인다.
            //---------------------------------------------------------------
            EffectSummonCasket* pEffect = new EffectSummonCasket(pVampire);
            pEffect->setDeadline(99999999);
            pEffect->setType(0);
            pVampire->addEffect(pEffect);
            pVampire->setFlag(Effect::EFFECT_CLASS_CASKET);

            // SUMMON CASKET 에 의해 변하는 능력치가 변한다.. 2002.12.13  by bezz.
            VAMPIRE_RECORD prev;

            pVampire->getVampireRecord(prev);
            pVampire->initAllStat();
            pVampire->sendRealWearingInfo();
            pVampire->sendModifyInfo(prev);

            GCAddEffect gcAddEffect;
            gcAddEffect.setObjectID(pVampire->getObjectID());
            gcAddEffect.setEffectID(Effect::EFFECT_CLASS_CASKET);
            gcAddEffect.setDuration(output.Duration);
            pZone->broadcastPacket(pVampire->getX(), pVampire->getY(), &gcAddEffect, pVampire);

            pSkillSlot->setRunTime();
        }
        else
        {
            //cout << "SummonCasket Failed" << endl;
            executeSkillFailNormal(pVampire, getSkillType(), NULL);
        }
    }
    catch(Throwable & t)
    {
        //cout << "SummonCasket Failed2" << endl;
        executeSkillFailException(pVampire, getSkillType());
    }

    //cout << "TID[" << Thread::self() << "]" << getSkillHandlerName() << " End" << endl;

    __END_CATCH

}
Exemplo n.º 13
0
void effect_End(void)
{
	g_EffectManager.getEffect().end();
	g_EffectManager.bind(0);
}
Exemplo n.º 14
0
bool effect_Begin(effect_sig signature)
{
	g_EffectManager.bind(signature);
	g_EffectManager.getEffect().begin();
	return true;
}
Exemplo n.º 15
0
namespace Engine {

/** Instantiate the global effect manager singleton */
EffectManager g_EffectManager;

bool effect_Begin(effect_sig signature)
{
	g_EffectManager.bind(signature);
	g_EffectManager.getEffect().begin();
	return true;
}

void effect_End(void)
{
	g_EffectManager.getEffect().end();
	g_EffectManager.bind(0);
}

EffectManager::EffectManager(void)
{
	clear();
}

EffectManager::~EffectManager(void)
{
	destroy();
}

void EffectManager::clear(void)
{
	currentEffect=0;
	currentSig=0;
}

void EffectManager::create(void)
{
	destroy();

	// Allocate all effects
	TRACE("Allocating all Effects");
	LinkTable temp;
	temp.insert(make_pair(effect_CLASS_Z_ONLY,						new Effect_Z_Only));
	temp.insert(make_pair(effect_CLASS_PROJECT_SHADOWS,				new Effect_Project_Shadows));
	temp.insert(make_pair(effect_CLASS_RECEIVE_SHADOWS,				new Effect_Receive_Shadows));
	temp.insert(make_pair(effect_CLASS_GOURAUD_FFP,					new Effect_Gouraud_FFP));
	temp.insert(make_pair(effect_CLASS_TEXTURE_REPLACE_FFP,			new Effect_TextureReplace_FFP));
	temp.insert(make_pair(effect_CLASS_PARTICLE_FX,					new Effect_Particle_FFP));
	temp.insert(make_pair(effect_CLASS_GUI,							new Effect_GUI_FFP));
	temp.insert(make_pair(effect_CLASS_RED,							new Effect_Red_FFP));

	// Iterate through effects and eliminate effects that are not supported
	TRACE("Determining supported Effects");
	for(LinkTable::iterator iter = temp.begin(); iter!=temp.end(); ++iter)
	{
		Effect *effect = (iter->second);
		ASSERT(effect != 0, "null Effect");

		// Do we have enough texture units to use the effect?
		if(effect->getRequiredTextureUnits() > g_MultitextureUnits)
		{
			// Discard the effect and continue
			TRACE(effect->getName() + ": Effect requires too many texture stages, discarding...");
			delete effect;
			continue;
		}
		// Do we have the extension support?
		else if(!isSupported(effect->getRequiredExtensions()))
		{
			// Discard the effect and continue
			TRACE(effect->getName() + ": Effect requires unsupported or disabled extensions, discarding...");
			//delete effect;
			continue;
		}
		// Effect is supported
		else
		{
			rawEffects.insert(make_pair(iter->first, iter->second));
		}
	}

	// Initialize all effect classes
	TRACE("Initializing the supported Effects");
	for(LinkTable::iterator iter = rawEffects.begin(); iter!=rawEffects.end(); ++iter)
	{
		(iter->second)->create();
	}

	// Then, insert those effects that are supported into the link table
	for(effect_sig i = 1; i<effect_CLASS_MAX; ++i)
	{
		Effect *effect = queryRaw(i);
		ASSERT(effect!=0, "EffectManager::create  ->  Effect was NULL");

		linkTable.insert(make_pair(i, effect));
	}

// Determine the best fit effects for the templated effect signatures

	// These are the effects we will work with to link together
	effect_sig effects[] =
	{
		effect_DEFAULT,
		effect_TEXTURE_REPLACE,
		effect_NO_TEXTURE_LIT,
		effect_TEXTURE_LIT,
		effect_GUI,
		effect_PARTICLE_FX,
		effect_TRANSPARENT,
		effect_RED
	};

	// For each effect signature:
	TRACE("Linking Effects to effect signature templates");
	for(size_t i=0; i<sizeof(effects); ++i)
	{
		priority_queue< pair<int,Effect*>, vector< pair<int,Effect*> >, less< pair<int,Effect*> > > options;

		effect_sig sig = effects[i];

		// For each effect class, determine the priority for this signature
		for(LinkTable::iterator iter = rawEffects.begin(); iter!=rawEffects.end(); ++iter)
		{
			options.push( make_pair( (iter->second)->howGood(sig), iter->second ) );
		}

		// Select the highest priority for this signature
		Effect *best = options.top().second;

		// Link to the best effect that was found for this signature
		linkTable.insert(  make_pair(sig, best)  );
	}

	// select no initial Effect
	currentEffect = 0;


	TRACE("Completed");
}

void EffectManager::destroy(void)
{
	TRACE("Destroying existing Effects");
	clear();
}

bool EffectManager::bind(effect_sig signature)
{
	if(signature==0)
	{
		currentEffect = 0;
	}
	else
	{
		// First, make sure there isn't already an active effect
		ASSERT(currentEffect==0, "there is already an active effect!");

		// What effect best matches the requested signature?
		Effect *requested = query(signature);
		ASSERT(requested != 0, "Effect was NULL, linker should have taken care of that!");

		currentEffect = requested;

		currentSig = signature;
	}

	// Indicate that we did change the Effect
	return true;
}

Effect& EffectManager::getEffect(void)
{
	ASSERT(currentEffect!=0, "There is currently no bound effect!");
	return(*currentEffect);
}

Effect* EffectManager::queryRaw(effect_sig signature)
{
	ASSERT(!rawEffects.empty(), "EffectManager::queryRaw  ->  rawEffects was empty");

	LinkTable::iterator iter = rawEffects.find(signature);

	LinkTable::iterator _end = rawEffects.end();

	if(iter != _end)
	{
		return(iter->second);
	}
	else
	{
		// Some default effect
		return(rawEffects.begin()->second);
	}
}

Effect* EffectManager::query(effect_sig signature)
{
	LinkTable::iterator iter = linkTable.find(signature);

	if(iter != linkTable.end())
	{
		return(iter->second);
	}
	else
	{
		return 0;
	}
}

bool EffectManager::isSupported(const string &str)
{
    tokenizer<> extensions(str);

	for(tokenizer<>::const_iterator iter = extensions.begin(); iter != extensions.end(); ++iter)
	{
		if(glewIsSupported((*iter).c_str())==GL_FALSE)
            return false;
	}

	return true;
}

} // namespace Engine
Exemplo n.º 16
0
void MonsterInfo::ShowCompleteMonsterInfo(MonsterData* monster)
{
    int i;
    for (i = 3; i < 30; i++)
        World.getTextManager().SetDisplayLine(i, "");

    char buf[128];

    World.getTextManager().SetDisplayLine(0, "%s", monster->monster.name.c_str());
    World.getTextManager().SetDisplayLine(1, "==========");

    World.getTextManager().SetDisplayLine(3, "");

    sprintf(buf, "Stamina: %d", monster->Stamina());
    World.getTextManager().SetDisplayLine(5, buf);

    sprintf(buf, "Skill: %d(+%d)", monster->AdjustedSkill(), monster->AdjustedSkill() - monster->Skill());
    World.getTextManager().SetDisplayLine(6, buf);

    switch (monster->GetState())
    {
    case asleep: sprintf(buf,  "State: asleep"); break;
    case sentry: sprintf(buf,  "State: sentry"); break;
    case normal: sprintf(buf,  "State: normal"); break;
    case hostile: sprintf(buf, "State: hostile"); break;
    case dead: sprintf(buf,    "State: dead"); break;
    }

    World.getTextManager().SetDisplayLine(7, buf);

    sprintf(buf, "Experience: %d", monster->experience);
    World.getTextManager().SetDisplayLine(8, buf);

    sprintf(buf, "Experience Level: %d", monster->experience_level);
    World.getTextManager().SetDisplayLine(9, buf);

    sprintf(buf, "Kills: %d", monster->Kills());
    World.getTextManager().SetDisplayLine(10, buf);

    sprintf(buf, "Dungeon Level: %d", monster->level);
    World.getTextManager().SetDisplayLine(11, buf);

    sprintf(buf, "Inventory Items %d", monster->inventory.size());
    World.getTextManager().SetDisplayLine(13, buf);

    ITEMLIST::iterator it;

    i = 15;
    for (it = monster->inventory.begin(); it != monster->inventory.end(); it++, i++)
    {

        //	if(it->equipped)
        {
            World.getTextManager().SetDisplayLine(i, "%s", it->GetName().c_str());
        }
    }
    i++;
    World.getTextManager().SetDisplayLine(i++, "Effects");

    EffectManager effectManager;

    EFFECTLIST::iterator eff;

    for (eff = monster->monster.effectList.begin(); eff != monster->monster.effectList.end(); eff++, i++)
    {
        if (eff->strength > 0)
            World.getTextManager().SetDisplayLine(i, (char*)effectManager.EffectName(eff->type).c_str());
    }

    /*EFFECTMAP_CITERATOR eff;
    for(eff=monster->monster.effectMap.begin();eff != monster->monster.effectMap.end();it++,i++)
    {
    if(eff->second > 0)
    World.getTextManager().SetDisplayLine(i,(char*)effectManager.EffectName(eff->first).c_str());

    }*/


    World.getTextManager().SetDisplayLine(39, "[x] to Exit");


}
Exemplo n.º 17
0
//////////////////////////////////////////////////////////////////////////////
// 슬레이어 셀프 핸들러
//////////////////////////////////////////////////////////////////////////////
void OpenCasket::execute(Vampire* pVampire, VampireSkillSlot* pVampireSkillSlot, CEffectID_t CEffectID)
	throw(Error)
{
	__BEGIN_TRY

	//cout << "TID[" << Thread::self() << "]" << getSkillHandlerName() << " Begin(slayerself)" << endl;

	Assert(pVampire != NULL);
	//Assert(pVampireSkillSlot != NULL);

	//cout << "Open Casket" << endl;
	try 
	{
		Player* pPlayer = pVampire->getPlayer();
		Zone* pZone = pVampire->getZone();

		Assert(pPlayer != NULL);
		Assert(pZone != NULL);

		GCSkillToSelfOK1 _GCSkillToSelfOK1;
		GCSkillToSelfOK2 _GCSkillToSelfOK2;

		SkillType_t       SkillType  = getSkillType();
		//SkillInfo*        pSkillInfo = g_pSkillInfoManager->getSkillInfo(SkillType);

		// 관 속에 들어있는 경우만 사용 가능하다.
		bool bEffected   = pVampire->isFlag(Effect::EFFECT_CLASS_CASKET);

		if (bEffected)
		{
			//cout << "Open Casket Succeed" << endl;

			// 이펙트 클래스를 만들어 붙인다.
			EffectManager* pEffectManager = pVampire->getEffectManager();
			Assert(pEffectManager!=NULL);

			Effect* pEffect = pEffectManager->findEffect(Effect::EFFECT_CLASS_CASKET);

			if (pEffect!=NULL)
			{
				pEffect->setDeadline(0);
//				pEffect->unaffect();
//				pEffectManager->deleteEffect(Effect::EFFECT_CLASS_CASKET);
//				pVampire->removeFlag(Effect::EFFECT_CLASS_CASKET);
			}

			// 패킷을 만들어 보낸다.
			_GCSkillToSelfOK1.setSkillType(SkillType);
			_GCSkillToSelfOK1.setCEffectID(CEffectID);
			_GCSkillToSelfOK1.setDuration(0);
		
			_GCSkillToSelfOK2.setObjectID(pVampire->getObjectID());
			_GCSkillToSelfOK2.setSkillType(SkillType);
			_GCSkillToSelfOK2.setDuration(0);
		
			pPlayer->sendPacket(&_GCSkillToSelfOK1);
		
			pZone->broadcastPacket(pVampire->getX(), pVampire->getY(),  &_GCSkillToSelfOK2, pVampire);

			// set Next Run Time
			//pVampireSkillSlot->setRunTime(output.Delay);
		} 
		else 
		{
			//cout << "Open Casket Failed1" << endl;
			executeSkillFailNormal(pVampire, getSkillType(), NULL);
		}
	} 
	catch (Throwable & t) 
	{
		//cout << "Open Casket Failed2" << endl;
		executeSkillFailException(pVampire, getSkillType());
	}

	//cout << "TID[" << Thread::self() << "]" << getSkillHandlerName() << " End(slayerself)" << endl;

	__END_CATCH
}
Exemplo n.º 18
0
void ActionHeal::execute (Creature * pCreature1 , Creature * pCreature2) 
	throw(Error)
{
	__BEGIN_TRY

	Assert(pCreature1 != NULL);
	Assert(pCreature2 != NULL);
	Assert(pCreature1->isNPC());
	Assert(pCreature2->isPC());

	Player* pPlayer = pCreature2->getPlayer();
	Zone*   pZone   = pCreature2->getZone();
	
	Assert(pPlayer != NULL);

	// 일단 클라이언트를 위해서 OK 패킷을 함 날린다.
	GCNPCResponse okpkt;
	okpkt.setCode(NPC_RESPONSE_HEAL);
	pPlayer->sendPacket(&okpkt);

	// 죽었거나 코마 걸려있으면 안 치료해준다.
	if (pCreature2->isDead() || pCreature2->isFlag(Effect::EFFECT_CLASS_COMA ) )
	{
		return;
	}

	// 슬레이어라면...
	if (pCreature2->isSlayer())
	{
		Slayer*             pSlayer        = dynamic_cast<Slayer*>(pCreature2);
		EffectManager*      pEffectManager = pSlayer->getEffectManager();
		GCModifyInformation modifyPkt;
		GCRemoveEffect      removePkt;
		GCStatusCurrentHP   hpPkt;

		// 먼저 HP랑 MP를 풀로 채워준다.
		if (pSlayer->getHP(ATTR_CURRENT) < pSlayer->getHP(ATTR_MAX))
		{
			pSlayer->setHP(pSlayer->getHP(ATTR_MAX), ATTR_CURRENT);
			modifyPkt.addShortData(MODIFY_CURRENT_HP, pSlayer->getHP(ATTR_CURRENT));

			hpPkt.setObjectID(pSlayer->getObjectID());
			hpPkt.setCurrentHP(pSlayer->getHP(ATTR_CURRENT));
		}
		if (pSlayer->getMP(ATTR_CURRENT) < pSlayer->getMP(ATTR_MAX))
		{
			pSlayer->setMP(pSlayer->getMP(ATTR_MAX), ATTR_CURRENT);
			modifyPkt.addShortData(MODIFY_CURRENT_MP, pSlayer->getMP(ATTR_CURRENT));
		}

		// 흡혈 이펙트를 삭제한다.
		Effect* pBloodDrainEffect = pEffectManager->findEffect(Effect::EFFECT_CLASS_BLOOD_DRAIN);
		if (pBloodDrainEffect != NULL)
		{
			// DB에서 삭제하고, 이펙트 매니저에서 삭제한다.
			pBloodDrainEffect->destroy(pSlayer->getName());
			pEffectManager->deleteEffect(pSlayer, Effect::EFFECT_CLASS_BLOOD_DRAIN);

			// 흡혈 아르바이트를 방지하기 위한 후유증 이펙트를 붙여준다.
			if (pSlayer->isFlag(Effect::EFFECT_CLASS_AFTERMATH))
			{
				Effect* pEffect = pEffectManager->findEffect(Effect::EFFECT_CLASS_AFTERMATH);
				EffectAftermath* pEffectAftermath = dynamic_cast<EffectAftermath*>(pEffect);
				pEffectAftermath->setDeadline(5*600); // 5분 동안 지속된다.
			}
			else
			{
				EffectAftermath* pEffectAftermath = new EffectAftermath(pSlayer);
				pEffectAftermath->setDeadline(5*600); // 5분 동안 지속된다.
				pEffectManager->addEffect(pEffectAftermath);
				pSlayer->setFlag(Effect::EFFECT_CLASS_AFTERMATH);
				pEffectAftermath->create(pSlayer->getName());
			}

			// 패킷에다 정보를 더한다.
			removePkt.addEffectList((EffectID_t)Effect::EFFECT_CLASS_BLOOD_DRAIN);

			// 흡혈을 치료하면 능력치가 변화하게 된다.
			SLAYER_RECORD prev;
			pSlayer->getSlayerRecord(prev);
			pSlayer->initAllStat();
			pSlayer->sendModifyInfo(prev);
			pSlayer->sendRealWearingInfo();
		}

		// 독 이펙트를 삭제한다.
		Effect* pEffectPoison = pEffectManager->findEffect(Effect::EFFECT_CLASS_POISON);
		if (pEffectPoison != NULL)
		{
			// 이펙트 매니저에서 삭제한다.
			pEffectManager->deleteEffect(pSlayer, Effect::EFFECT_CLASS_POISON);

			// 패킷에다 정보를 더한다.
			removePkt.addEffectList((EffectID_t)Effect::EFFECT_CLASS_POISON);
		}

		// 다크블루 포이즌 이펙트를 삭제한다.
		Effect* pEffectDarkBluePoison = pEffectManager->findEffect(Effect::EFFECT_CLASS_DARKBLUE_POISON);
		if (pEffectDarkBluePoison != NULL)
		{
			// 이펙트 매니저에서 삭제한다.
			pEffectManager->deleteEffect(pSlayer, Effect::EFFECT_CLASS_DARKBLUE_POISON);

			// 패킷에다 정보를 더한다.
			removePkt.addEffectList((EffectID_t)Effect::EFFECT_CLASS_DARKBLUE_POISON);
		}

		// 패킷 날려준다.
		removePkt.setObjectID(pSlayer->getObjectID());
		pPlayer->sendPacket(&modifyPkt);
		pZone->broadcastPacket(pSlayer->getX(), pSlayer->getY(), &removePkt);
		pZone->broadcastPacket(pSlayer->getX(), pSlayer->getY(), &hpPkt, pSlayer);

		//log(LOG_HEAL, pSlayer->getName(), "");
	}
	else if (pCreature2->isVampire())
	{
		Vampire*            pVampire = dynamic_cast<Vampire*>(pCreature2);
		//EffectManager*      pEffectManager = pVampire->getEffectManager();
		GCModifyInformation modifyPkt;
		GCRemoveEffect      removePkt;
		GCStatusCurrentHP   hpPkt;

		// HP 채워주고...
		if (pVampire->getHP(ATTR_CURRENT) < pVampire->getHP(ATTR_MAX))
		{
			pVampire->setHP(pVampire->getHP(ATTR_MAX), ATTR_CURRENT);
			modifyPkt.addShortData(MODIFY_CURRENT_HP, pVampire->getHP(ATTR_CURRENT));

			hpPkt.setObjectID(pVampire->getObjectID());
			hpPkt.setCurrentHP(pVampire->getHP(ATTR_CURRENT));
		}

		// 패킷 날려준다.
		removePkt.setObjectID(pVampire->getObjectID());
		pPlayer->sendPacket(&modifyPkt);
		pZone->broadcastPacket(pVampire->getX(), pVampire->getY(), &removePkt);
		pZone->broadcastPacket(pVampire->getX(), pVampire->getY(), &hpPkt, pVampire);

		//log(LOG_HEAL, pVampire->getName(), "");
	}
	else if (pCreature2->isOusters())
	{
		Ousters*             pOusters        = dynamic_cast<Ousters*>(pCreature2);
		EffectManager*      pEffectManager = pOusters->getEffectManager();
		GCModifyInformation modifyPkt;
		GCRemoveEffect      removePkt;
		GCStatusCurrentHP   hpPkt;

		// 먼저 HP랑 MP를 풀로 채워준다.
		if (pOusters->getHP(ATTR_CURRENT) < pOusters->getHP(ATTR_MAX) || pOusters->getSilverDamage() != 0 )
		{
			Silver_t prev = pOusters->getSilverDamage();

			if (prev != 0 )
			{
				pOusters->setSilverDamage(0);
				modifyPkt.addShortData(MODIFY_SILVER_DAMAGE, pOusters->getSilverDamage());
			}

			pOusters->setHP(pOusters->getHP(ATTR_MAX), ATTR_CURRENT);
			modifyPkt.addShortData(MODIFY_CURRENT_HP, pOusters->getHP(ATTR_CURRENT));

			hpPkt.setObjectID(pOusters->getObjectID());
			hpPkt.setCurrentHP(pOusters->getHP(ATTR_CURRENT));
		}
		if (pOusters->getMP(ATTR_CURRENT) < pOusters->getMP(ATTR_MAX))
		{
			pOusters->setMP(pOusters->getMP(ATTR_MAX), ATTR_CURRENT);
			modifyPkt.addShortData(MODIFY_CURRENT_MP, pOusters->getMP(ATTR_CURRENT));
		}

		// 독 이펙트를 삭제한다.
		Effect* pEffectPoison = pEffectManager->findEffect(Effect::EFFECT_CLASS_POISON);
		if (pEffectPoison != NULL)
		{
			// 이펙트 매니저에서 삭제한다.
			pEffectManager->deleteEffect(pOusters, Effect::EFFECT_CLASS_POISON);

			// 패킷에다 정보를 더한다.
			removePkt.addEffectList((EffectID_t)Effect::EFFECT_CLASS_POISON);
		}

		// 다크블루 포이즌 이펙트를 삭제한다.
		Effect* pEffectDarkBluePoison = pEffectManager->findEffect(Effect::EFFECT_CLASS_DARKBLUE_POISON);
		if (pEffectDarkBluePoison != NULL)
		{
			// 이펙트 매니저에서 삭제한다.
			pEffectManager->deleteEffect(pOusters, Effect::EFFECT_CLASS_DARKBLUE_POISON);

			// 패킷에다 정보를 더한다.
			removePkt.addEffectList((EffectID_t)Effect::EFFECT_CLASS_DARKBLUE_POISON);
		}

		// 흡혈 이펙트를 삭제한다.
		Effect* pBloodDrainEffect = pEffectManager->findEffect(Effect::EFFECT_CLASS_BLOOD_DRAIN);
		if (pBloodDrainEffect != NULL)
		{
			pBloodDrainEffect->setDeadline(0);

			// 흡혈 아르바이트를 방지하기 위한 후유증 이펙트를 붙여준다.
			if (pOusters->isFlag(Effect::EFFECT_CLASS_AFTERMATH))
			{
				Effect* pEffect = pEffectManager->findEffect(Effect::EFFECT_CLASS_AFTERMATH);
				EffectAftermath* pEffectAftermath = dynamic_cast<EffectAftermath*>(pEffect);
				pEffectAftermath->setDeadline(5*600); // 5분 동안 지속된다.
			}
			else
			{
				EffectAftermath* pEffectAftermath = new EffectAftermath(pOusters);
				pEffectAftermath->setDeadline(5*600); // 5분 동안 지속된다.
				pEffectManager->addEffect(pEffectAftermath);
				pOusters->setFlag(Effect::EFFECT_CLASS_AFTERMATH);
				pEffectAftermath->create(pOusters->getName());
			}

			// 패킷에다 정보를 더한다.
			removePkt.addEffectList((EffectID_t)Effect::EFFECT_CLASS_BLOOD_DRAIN);
		}


		// 패킷 날려준다.
		removePkt.setObjectID(pOusters->getObjectID());
		pPlayer->sendPacket(&modifyPkt);
		pZone->broadcastPacket(pOusters->getX(), pOusters->getY(), &removePkt);
		pZone->broadcastPacket(pOusters->getX(), pOusters->getY(), &hpPkt, pOusters);

		//log(LOG_HEAL, pOusters->getName(), "");

	}
	__END_CATCH
}
Exemplo n.º 19
0
        void LevelManager::run()
        {
            /* Behold, as I have been told
             * what follows below
             * is very important, you know! */
            InputManager *inputManager = InputManager::getInstance();
            TimeManager *timeManager = TimeManager::getInstance();
            VideoManager *videoManager = VideoManager::getInstance();
            EffectManager *effectManager = EffectManager::getInstance();
            SketchManager *sketchManager = SketchManager::getInstance();

            FPSLogger fps;
 
            float freq_to_update = 1000.0f / 60.0f;

            long lastUpdate = timeManager->getTicks();
            while(!inputManager->hasQuitEvent()) {

                /* Calculate the ticks that have passed. */
                long ticks = timeManager->getTicks();
                float ms = (float)(ticks - lastUpdate);
                lastUpdate = ticks;

                /* Cap FPS by sleeping a little. */
                if(ms <= freq_to_update) {
                    float wait = freq_to_update - ms;
                    timeManager->sleep(wait);
                }

                /* Update the input state. */
                inputManager->update(ms);

                /* Update the level. */
                if(level && ms > 0.0f) level->update(timeFactor * ms);

                /* Update other things. */
                effectManager->update(timeFactor * ms);
                fps.update(ms);

                /* Setup the videoManager for rendering. */
                videoManager->clear();
                videoManager->identity();

                /* Render the level first, this will also apply our camera
                 * transformation, which is good, since the effect manager
                 * wants the same transformation. */
                if(level) level->render();
                effectManager->render();
                fps.render();

                /* Flip the video buffer. */
                videoManager->flip();

                /* Update level queue. */
                if(queue) {
                    /* Remove old level. */
                    if(level)
                        delete level;

                    effectManager->clear();
                    sketchManager->clear();

                    /* Load new level. */
                    level = new Level(queueFileName);
                    queue = false;
                    timeFactor = 1.0f;

                    /* Loading the level might have taken some time, so we skip
                     * some ticks. */
                    lastUpdate = timeManager->getTicks();
                }
            }
        }
Exemplo n.º 20
0
void C3DCanvas::Draw(float fDeltaTime)
{
	CBaseObject* pActor = GetActor();
	if(!IsEnabled() || pActor==0)
		return;
	if(m_bNeedUpdate == false)
		return;

	if(!m_bInitialized)
	{
		InitDeviceObjects();
		RestoreDeviceObjects();
	}
	if(m_pCanvasSurface == 0 || m_pDepthStencilSurface==0)
		return;

	if(m_bAutoRotate)
	{
		m_camera.Rotate(0,0.3f*fDeltaTime, 0);
	}

	m_bNeedUpdate = false;
	
	EffectManager* pEffectManager = CGlobals::GetEffectManager();
	LPDIRECT3DDEVICE9 pd3dDevice = CGlobals::GetRenderDevice();

	LPDIRECT3DSURFACE9 pOldRenderTarget =  CGlobals::GetDirectXEngine().GetRenderTarget();
	CGlobals::GetDirectXEngine().SetRenderTarget(0, m_pCanvasSurface);

	// save old render origin
	Vector3 vOldRenderOrigin = CGlobals::GetScene()->GetRenderOrigin();

	// set depth surface
	LPDIRECT3DSURFACE9 pOldZBuffer = NULL;
	if(FAILED(pd3dDevice->GetDepthStencilSurface(&pOldZBuffer)))
		return;
	pd3dDevice->SetDepthStencilSurface( m_pDepthStencilSurface );

	// save old actor position
	pActor->PushParam();

	pActor->SetPosition(m_vActorPosition);
	pActor->SetFacing(m_fActorFacing);
	

	// animate the camera and push result to transformation stack
	m_camera.FrameMove(fDeltaTime);

	CGlobals::GetProjectionMatrixStack().push(*m_camera.GetProjMatrix());
	CGlobals::GetViewMatrixStack().push(*m_camera.GetViewMatrix());
	CGlobals::GetEffectManager()->UpdateD3DPipelineTransform(true,true, true);

	// clear 
	pd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, COLOR_RGBA(0, 0, 0, 0), 1.0f, 0L);

	// disable fog
	pEffectManager->EnableFog(false);

	
	if(pEffectManager->BeginEffect(pActor->GetPrimaryTechniqueHandle(), &(CGlobals::GetSceneState()->m_pCurrentEffect)))
	{
		/** draw the main stage object */
		pActor->Draw(CGlobals::GetSceneState());
		CGlobals::GetSceneState()->GetFaceGroups()->Clear();
	}
	

	if(m_pMask!=0 && pEffectManager->BeginEffect(TECH_GUI, &(CGlobals::GetSceneState()->m_pCurrentEffect)))
	{
		/** draw the mask square in front of the screen. */
		CEffectFile* pEffectFile = CGlobals::GetEffectManager()->GetCurrentEffectFile();
		if(pEffectFile == 0)
		{
			//////////////////////////////////////////////////////////////////////////
			// fixed programming pipeline
			float sx = (float)m_nTextureWidth,sy = (float)m_nTextureHeight;
			
			DXUT_SCREEN_VERTEX v[10];
			v[0].x = 0;  v[0].y = sy; v[0].tu = 0;  v[0].tv = 1.0f;
			v[1].x = 0;  v[1].y = 0;  v[1].tu = 0;  v[1].tv = 0;
			v[2].x = sx; v[2].y = sy; v[2].tu = 1.f; v[2].tv = 1.f;
			v[3].x = sx; v[3].y = 0;  v[3].tu = 1.f; v[3].tv = 0;

			DWORD dwColor = LinearColor(1.f,1.f,1.f,1.f);
			int i;
			for(i=0;i<4;i++)
			{
				v[i].color = dwColor;
				v[i].z = 0;
				v[i].h = 1.0f;
			}
			CGlobals::GetRenderDevice()->SetTexture(0, m_pMask->GetTexture());
			RenderDevice::DrawPrimitiveUP( CGlobals::GetRenderDevice(), RenderDevice::DRAW_PERF_TRIANGLES_UI, D3DPT_TRIANGLESTRIP, 2, v, sizeof(DXUT_SCREEN_VERTEX) );
		}
	}
	
	//////////////////////////////////////////////////////////////////////////
	// Restore state for the normal pipeline

	// enable fog
	pEffectManager->EnableFog(CGlobals::GetScene()->IsFogEnabled());

	// restore old actor position
	pActor->PopParam();
	
	// restore transformations
	CGlobals::GetProjectionMatrixStack().pop();
	CGlobals::GetViewMatrixStack().pop();
	CGlobals::GetEffectManager()->UpdateD3DPipelineTransform(true,true, true);

	// restore old depth surface
	pd3dDevice->SetDepthStencilSurface( pOldZBuffer);
	SAFE_RELEASE(pOldZBuffer);
	// Restore the old render target: i.e. the backbuffer
	HRESULT hr = CGlobals::GetDirectXEngine().SetRenderTarget(0, pOldRenderTarget);
	assert(hr == D3D_OK);

	// restore render origin
	CGlobals::GetScene()->RegenerateRenderOrigin(vOldRenderOrigin);

#ifdef _DEBUG
	//SaveToFile("E:\\cavas_obj.png");
#endif

}
Exemplo n.º 21
0
void MonsterInfo::ShowNormalMonsterInfo(MonsterData* monster)
{
    World.getTextManager().ClearDisplayLines();

    World.getTextManager().SetDisplayLine(0, "%s", monster->monster.name.c_str());
    World.getTextManager().SetDisplayLine(1, "==============");

    World.getTextManager().SetDisplayLine(3, "%s", World.getMonsterManager().getDescription(monster->monster).c_str());

    float max_stamina = (float)monster->monster.MaxStamina();
    float cur_stamina = (float)monster->monster.stamina;

    int state = monster->GetState();

    float wounded = (max_stamina - cur_stamina) / max_stamina * 100;
    char health[32];
    char status[32];

    if (wounded < 20)
        strcpy(health, "healthy");
    else if (wounded < 50)
        strcpy(health, "wounded");
    else if (wounded < 80)
        strcpy(health, "very wounded");
    else
        strcpy(health, "almost dead");

    if (monster->isPlayer())
        strcpy(status, "You are ready for anything.");
    else
    {
        switch (state)
        {
        case normal:	strcpy(status, "It has not seen you."); break;
        case sentry:	strcpy(status, "It appears asleep."); break;
        case hostile:	strcpy(status, "It is hostile."); break;
        case waking:	strcpy(status, "It looked annoyed."); break;
        case asleep:	strcpy(status, "It is asleep."); break;
        }
    }
    if (monster->isPlayer())
        World.getTextManager().SetDisplayLine(5, "You look %s.", health);
    else
        World.getTextManager().SetDisplayLine(5, "It looks %s.", health);

    //sprintf(buf,"%s",status);
    World.getTextManager().SetDisplayLine(6, "%s", status);

    int pSkill = World.getMonsterManager().Player()->Skill();
    int tSkill = monster->Skill();

    if (tSkill < 6) //0-5
        World.getTextManager().SetDisplayLine(7, "Experience: Low");

    else if (tSkill < 7) //6
        World.getTextManager().SetDisplayLine(7, "Experience: Average");
    else if (tSkill < 9) //6-7
        World.getTextManager().SetDisplayLine(7, "Experience: Medium");
    else if (tSkill < 11) //8-9
        World.getTextManager().SetDisplayLine(7, "Experience: High");
    else //>=10
        World.getTextManager().SetDisplayLine(7, "Experience: Very High");

    //inventory
    World.getTextManager().SetDisplayLine(9, "Equipment");
    ITEMLIST::iterator it;
    int i = 10;
    for (it = monster->inventory.begin(); it != monster->inventory.end(); it++, i++)
    {
#ifdef _DEBUG
        World.getTextManager().SetDisplayLine(i, "%s", it->GetName().c_str());
#else
        if (it->equipped)
        {
            World.getTextManager().SetDisplayLine(i, "%s", it->GetName().c_str());
        }
        else
            i--;
#endif
    }

    i++;
    if (monster->monster.effectList.size() > 0)
        World.getTextManager().SetDisplayLine(i++, "Active Effects"); i++;

    EffectManager effectManager;

    EFFECTLIST::iterator eff;

    for (eff = monster->monster.effectList.begin(); eff != monster->monster.effectList.end(); eff++, i++)
    {
        if (eff->strength > 0)
        {
            std::string eff_msg = effectManager.EffectName(eff->type);
            for (int e = 1; e < eff->strength; e++)
                eff_msg.append("!");
            World.getTextManager().SetDisplayLine(i, (char *)eff_msg.c_str());
        }
    }

    i++;
    if (monster->monster.hasResistance() > 0)
        World.getTextManager().SetDisplayLine(i++, "Resistances and vulnerabilities"); i++;

    BRANDMAP::iterator resist_it;
    for (resist_it = monster->monster.resistanceMap.begin(); resist_it != monster->monster.resistanceMap.end(); resist_it++, i++)
    {
        World.getTextManager().SetDisplayLine(i, "  %s (%d)", ResistanceBrands::GetResistanceName(resist_it->first), resist_it->second);
    }
    World.getTextManager().SetDisplayLine(39, "[x] to Return to looking.");
}
Exemplo n.º 22
0
EffectManager::EffectManager(EffectManager& other) : QObject()
{
    m_producer = other.producer();
}
Exemplo n.º 23
0
void ParaEngine::CMiniSceneGraph::Draw(float fDeltaTime)
{
	if(!IsCameraEnabled() || m_pCamera==0)
	{
		OUTPUT_LOG("warning: one can not call CMiniSceneGraph::draw() function when camera is disabled.\n");
		return;
	}

	bool bRenderToTexture = (GetRenderPipelineOrder() < PIPELINE_UI );
	
	m_sceneState.m_pd3dDevice = CGlobals::GetRenderDevice();

	if (IsDirty())
		SetDirty(false);

	if(bRenderToTexture)
	{
		if (!Begin())
			return;
		/** we will allow alpha in render target in case the device support it, if we have fog, the alpha does not take effect. */
		DWORD dwColor = 0xffffffff&(DWORD)(IsFogEnabled()? GetFogColor() : GetBackGroundColor());
		Clear(LinearColor(dwColor));
	}

	// animate the camera and push result to transformation stack
	m_pCamera->FrameMove(fDeltaTime);
	
	if(IsCameraEnabled() || CGlobals::GetWorldMatrixStack().empty())
		CGlobals::GetWorldMatrixStack().push(*CGlobals::GetIdentityMatrix());
	CGlobals::GetProjectionMatrixStack().push(*m_pCamera->GetProjMatrix());
	CGlobals::GetViewMatrixStack().push(*m_pCamera->GetViewMatrix());

	EffectManager* pEffectManager = CGlobals::GetEffectManager();
	pEffectManager->UpdateD3DPipelineTransform(true, true, true);

	// update the culling planes according to view and projection matrix on top of the global stack
	m_pCamera->UpdateFrustum(); 

	m_vRenderOrigin = CGlobals::GetScene()->GetRenderOrigin();

	{
		EffectTextureStateStack tex_state_(pEffectManager, IsUsePointTexture());
		
		/// the actual draw call is here.
		Draw_Internal(fDeltaTime);
	}
	

	//////////////////////////////////////////////////////////////////////////
	// Restore state for the normal pipeline
	if(bRenderToTexture)
	{
		DoPaint();
		End();
	}
	
	// restore transformations
	if(IsCameraEnabled())
		CGlobals::GetWorldMatrixStack().pop();
	CGlobals::GetProjectionMatrixStack().pop();
	CGlobals::GetViewMatrixStack().pop();
	CGlobals::GetEffectManager()->UpdateD3DPipelineTransform(true,true, true);

}
Exemplo n.º 24
0
	//------------------------------------------------------------------------------------
	// The works must to do after rendering the object.
	//------------------------------------------------------------------------------------
	void Bloom::Render()
	{
		if (!m_bEnable)
			return;

		gfx::Renderer*	ren = gfx::Renderer::GetSingletonPtr();
		EffectManager* emgr = EffectManager::GetSingletonPtr();

		ren->Enable(gfx::ERF_2D);
		ren->SetTextureParams(gfx::ETP_Anisotropic, 0);
		ren->SetTextureParams(gfx::ETP_Point, 6);

		m_pImage->SetUV(0.0, 0.0, 1.0, 1.0);
		m_pImage->SetSize(ren->GetWindowWidth() / 4, ren->GetWindowHeight() / 4);

		// 4X down filter
		ren->SetRenderTarget(0, emgr->GetTempRenderTarget(1));
		m_pMat->shader->m_pPixelShader = m_pPs4xDownFilter;
		ren->SetMaterial(m_pMat);
		m_pPs4xDownFilter->SetConstant(m_shPixelCoordsDownFilter, m_fPixelCoordsDownFilter, 32);
		m_pImage->m_BackImage = emgr->GetSceneTexture();
		m_pImage->Render();

		m_pImage->SetUV(0.0, 0.0, 0.25, 0.25);

		// Render bright pass in 1/4 size in render target 0
		ren->SetRenderTarget(0, emgr->GetTempRenderTarget(0));
		m_pMat->shader->m_pPixelShader = m_pPsBrightPass;
		ren->SetMaterial(m_pMat);
		m_pImage->m_BackImage = emgr->GetTempRenderTarget(1);
		m_pImage->Render();

		// Render vertical bloom in render target 1
		ren->SetRenderTarget(0, emgr->GetTempRenderTarget(1));
		m_pMat->shader->m_pPixelShader = m_pPsVerticalBloom;
		m_pPsVerticalBloom->SetConstant(m_shPixelKernel, m_fPixelKernelV, 26);
		ren->SetMaterial(m_pMat);
		m_pImage->m_BackImage = emgr->GetTempRenderTarget(0);
		m_pImage->Render();

		// Render horizontal bloom in render target 0
		ren->SetRenderTarget(0, emgr->GetTempRenderTarget(0));
		m_pMat->shader->m_pPixelShader = m_pPsVerticalBloom;
		m_pPsVerticalBloom->SetConstant(m_shPixelKernel, m_fPixelKernelH, 26);
		ren->SetMaterial(m_pMat);
		m_pImage->m_BackImage = emgr->GetTempRenderTarget(1);
		m_pImage->Render();
  
		// Render vertical bloom in render target 1
		ren->SetRenderTarget(0, emgr->GetTempRenderTarget(1));
		m_pMat->shader->m_pPixelShader = m_pPsVerticalBloom;
		m_pPsVerticalBloom->SetConstant(m_shPixelKernel, m_fPixelKernelV, 26);
		ren->SetMaterial(m_pMat);
		m_pImage->m_BackImage = emgr->GetTempRenderTarget(0);
		m_pImage->Render();
  
		// Render horizontal bloom in render target 0
		ren->SetRenderTarget(0, emgr->GetTempRenderTarget(0));
		m_pMat->shader->m_pPixelShader = m_pPsVerticalBloom;
		m_pPsVerticalBloom->SetConstant(m_shPixelKernel, m_fPixelKernelH, 26);
		ren->SetMaterial(m_pMat);
		m_pImage->m_BackImage = emgr->GetTempRenderTarget(1);
		m_pImage->Render();

		// Render result
		ren->SetRenderTarget();
		ren->Disable(gfx::ERF_DepthBuffer);
		m_pMat->shader->m_pPixelShader = m_pPsCombine;//NULL;//
		ren->SetMaterial(m_pMat);
		ren->SetTexture(emgr->GetSceneTexture(), 6);
		m_pImage->m_BackImage = emgr->GetTempRenderTarget(0);//emgr->GetSceneTexture();//
		m_pImage->SetSize(ren->GetWindowWidth(), ren->GetWindowHeight());
		ren->SetStencilBuffer(EET_Bloom, 1);

		m_pImage->Render();

		ren->Enable(gfx::ERF_DepthBuffer);
		ren->SetStencilBuffer(EET_Bloom, 2);
		ren->Disable(gfx::ERF_2D);

	} // Render
Exemplo n.º 25
0
HRESULT CGlowEffect::Render(float fGlowThreshold, float fGlowAmount, bool bUseAlpha)
{
//#ifdef _DEBUG
//	bUseAlpha = true;
//#endif
	
	HRESULT hr=S_OK;

	LPDIRECT3DDEVICE9 pd3dDevice = CGlobals::GetRenderDevice();

	// get current render target
	m_pBackBuffer = CGlobals::GetDirectXEngine().GetRenderTarget();
	if(FAILED(pd3dDevice->GetDepthStencilSurface(&m_pZBuffer)))
		return E_FAIL;
	if(!m_pBackBuffer || !m_pZBuffer)
		return E_FAIL;

	// Copy scene to lower resolution render target texture
	if( FAILED(hr = pd3dDevice->StretchRect( m_pBackBuffer, NULL, m_pRTHalfSizeSurface, NULL, D3DTEXF_LINEAR )) ) {
		OUTPUT_LOG("StretchRect() failed!\r\n");
		return hr;
	}

	EffectManager* pEffectManager =  CGlobals::GetEffectManager();
	pEffectManager->BeginEffect(TECH_FULL_SCREEN_GLOW);
	CEffectFile* pEffectFile = pEffectManager->GetCurrentEffectFile();
	
	if(pEffectFile != 0 && pEffectFile->begin(true, 0))
	{
		// full screen glow effect is completed in four steps.
		assert(pEffectFile->totalPasses() == 4);
		mesh_vertex_plain quadVertices[4] = {
			{Vector3(-1,-1,0), Vector2(0,1)},
			{ Vector3(1, -1, 0), Vector2(1, 1) },
			{ Vector3(-1, 1, 0), Vector2(0, 0) },
			{ Vector3(1, 1, 0), Vector2(1, 0) },
		};
		
		// offset the texture coordinate by half texel in order to match texel to pixel. 
		// This takes me hours to figure out. :-(
		float fhalfTexelWidth = 0.5f/m_glowtextureWidth;
		float fhalfTexelHeight = 0.5f/m_glowtextureHeight;

		for (int i=0;i<4;++i)
		{
			quadVertices[i].uv.x += fhalfTexelWidth;
			quadVertices[i].uv.y += fhalfTexelHeight;
		}

		// shader constants
		/*
#ifdef TEST_GLOW
		static int i=0;
		++i;
		if(i>30){
			fGlowAmount  = 1.0f;
			fGlowThreshold = 0.f;
			if(i>60)
				i=0;
		}
		else
		{
			fGlowAmount  = 0.f;
			fGlowThreshold = 1.0f;
		}
		
#endif*/
		/*
		pEffectFile->setParameter(CEffectFile::k_ConstVector0, (const float*)&Vector4(1/m_glowtextureWidth, 1/m_glowtextureHeight, 0.0f, 0.0f));
		LinearColor glowness = pEffectManager->GetGlowness();
		glowness.a = fGlowThreshold;
		glowness.r *= fGlowAmount;
		glowness.g *= fGlowAmount;
		glowness.b *= fGlowAmount;
		pEffectFile->setParameter(CEffectFile::k_ConstVector1, (const float*)&glowness);
		*/
	
		bUseAlpha = true;
		if(bUseAlpha)
		{
			//////////////////////////////////////////////////////////////////////////
			// make the glow source. Multiply texture alpha * RGB to get the glow sources
			pd3dDevice->SetRenderTarget( 0, m_pRTGlowSourceSurface);
			pd3dDevice->SetDepthStencilSurface( NULL );

			if(pEffectFile->BeginPass(0))
			{
				pEffectFile->setTexture(0, m_pRTHalfSizeTexture);
				LPD3DXEFFECT fx = pEffectFile->GetDXEffect();
				fx->SetFloat(fx->GetParameterByName(NULL,"glowThreshold"),fGlowThreshold);
				
				pEffectFile->CommitChanges();

				HRESULT hr = RenderDevice::DrawPrimitiveUP( pd3dDevice, RenderDevice::DRAW_PERF_TRIANGLES_MESH, D3DPT_TRIANGLESTRIP,2,quadVertices,sizeof(mesh_vertex_plain));

				pEffectFile->EndPass();
			}
		}
		
		
		//////////////////////////////////////////////////////////////////////////
		// Blur glow sources in the horizontal axis

		pd3dDevice->SetRenderTarget( 0, m_pRTBlurHorizSurface );
		pd3dDevice->SetDepthStencilSurface( NULL );
		// no need to clear alpha channel?
		// pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, 0x00, 1.0f, 0 ); 

		if(pEffectFile->BeginPass(1))
		{
			
			SetBlurEffectParameters(1.0f / m_glowtextureWidth,0,fGlowAmount,pEffectFile);	
			pEffectFile->setTexture(0, m_pRTGlowSourceTexture);
			pEffectFile->CommitChanges();

			HRESULT hr = RenderDevice::DrawPrimitiveUP( pd3dDevice, RenderDevice::DRAW_PERF_TRIANGLES_MESH, D3DPT_TRIANGLESTRIP,2,quadVertices,sizeof(mesh_vertex_plain));

			pEffectFile->EndPass();
		}

		// set texture 0 to NULL so same texture is never simultaneously a source and render target
		pEffectFile->setTexture( 0, (LPDIRECT3DTEXTURE9)NULL );

		//////////////////////////////////////////////////////////////////////////
		// Blur the horizontal blur in the vertical direction

		pd3dDevice->SetRenderTarget( 0, m_pRTBlurVertSurface );
		pd3dDevice->SetDepthStencilSurface( NULL );
		// no need to clear alpha channel?
		// pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, 0x00, 1.0f, 0 ); 

		//fGlowAmount = 2;
		if(pEffectFile->BeginPass(1))
		{
			//pEffectFile->setTexture( 1, m_pRTBlurHorizTexture );
			SetBlurEffectParameters(0,1.0f / m_glowtextureHeight,fGlowAmount,pEffectFile);	
			pEffectFile->setTexture(0, m_pRTBlurHorizTexture );  //editor here!!!
			pEffectFile->CommitChanges();

			HRESULT hr = RenderDevice::DrawPrimitiveUP( pd3dDevice, RenderDevice::DRAW_PERF_TRIANGLES_MESH, D3DPT_TRIANGLESTRIP,2,quadVertices,sizeof(mesh_vertex_plain));

			pEffectFile->EndPass();
		}

		// Set all textures to NULL to prevent RTT being bound as source and destination at the same time,
		pEffectFile->setTexture( 0,(LPDIRECT3DTEXTURE9)NULL );

		//////////////////////////////////////////////////////////////////////////
		// Add the final blur image to the back buffer

		pd3dDevice->SetRenderTarget( 0, m_pBackBuffer);
		pd3dDevice->SetDepthStencilSurface( NULL );
		// no need to clear alpha channel?
		// pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, 0x00, 1.0f, 0 ); 

		for (int i=0;i<4;++i)
		{
			quadVertices[i].uv.x -= fhalfTexelWidth * 0.5f;
			quadVertices[i].uv.y -= fhalfTexelHeight * 0.5f;
		}

		if(pEffectFile->BeginPass(3))
		{
			pEffectFile->setTexture(0, m_pRTHalfSizeTexture );
			pEffectFile->setTexture(1,m_pRTBlurVertTexture);

			Vector4 glowParam = pEffectManager->GetGlowness();
			LPD3DXEFFECT fx = pEffectFile->GetDXEffect();
			fx->SetVector(fx->GetParameterByName(NULL,"glowParams"), (const DeviceVector4*)&glowParam);

			pEffectFile->CommitChanges();

			HRESULT hr = RenderDevice::DrawPrimitiveUP( pd3dDevice, RenderDevice::DRAW_PERF_TRIANGLES_MESH, D3DPT_TRIANGLESTRIP,2,quadVertices,sizeof(mesh_vertex_plain));

			pEffectFile->EndPass();
			pEffectFile->setTexture( 0, (LPDIRECT3DTEXTURE9)NULL );
			pEffectFile->setTexture(1,(LPDIRECT3DTEXTURE9)NULL);
		}

		// restore depth stencil buffer
		pd3dDevice->SetDepthStencilSurface( m_pZBuffer );
		pEffectFile->end();
	}
	else
	{
		CGlobals::GetScene()->EnableFullScreenGlow(false);
		//Glow effect will not be load when graphics setting set to middle
		//so we just disable this warnning 
		//OUTPUT_LOG("can not set full screen glow effect error \r\n");
	}
	SAFE_RELEASE(m_pZBuffer);
	return hr;
}
Exemplo n.º 26
0
    int run()
    {
	  const unsigned int nMaxEffectUpdateCnt = _nHartBeatFreq / _nEffectUpdateFreq;
	  unsigned int nEffectUpdateCnt = 0;

	  // Initailize app. if not already done, and exit if something went wrong.
	  if (!_bIsInitialized)
		initialize();

	  if (!_bIsInitialized)
		return _nStatus;

	  try
	  {
		//Main polling loop
		while(!_bMustStop)
		{
		  // This fires off buffered events for keyboards
		  _pKeyboard->capture();

		  // This fires off buffered events for each joystick we have
		  _pJoystickMgr->captureEvents();

		  // Update currently selected effects if time has come to.
		  if (!nEffectUpdateCnt)
		  {
			_pEffectMgr->updateActiveEffects();
			nEffectUpdateCnt = nMaxEffectUpdateCnt;
		  }
		  else
			nEffectUpdateCnt--;

		  // Update state line.
		  cout << "\r" << _pJoystickMgr->toString() << " " << _pEffectMgr->toString()
			   << "                           ";

		  //Throttle down CPU usage & handle OS events
#if defined OIS_WIN32_PLATFORM
		  Sleep( (DWORD)(1000.0/_nHartBeatFreq) );
		  MSG msg;
		  while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
		  {
			TranslateMessage( &msg );
			DispatchMessage( &msg );
		  }
#elif defined OIS_LINUX_PLATFORM
		  checkX11Events();
		  usleep(1000000.0/_nHartBeatFreq);
#endif
		}
	  }
	  catch( const Exception &ex )
	  {
#if defined OIS_WIN32_PLATFORM
		MessageBox(0, ex.eText, "Exception Raised!", MB_OK);
#else
		cout << endl << "OIS Exception Caught!" << endl
			 << "\t" << ex.eText << "[Line " << ex.eLine << " in " << ex.eFile << "]" << endl;
#endif
	  }

	  terminate();

	  return _nStatus;
	}
Exemplo n.º 27
0
HRESULT ParaEngine::CLightObject::RenderMesh(SceneState * sceneState)
{
	if (!m_pAnimatedMesh)
		return E_FAIL;
	if (GetPrimaryTechniqueHandle() < 0)
	{
		// try loading the asset if it has not been done before. 
		m_pAnimatedMesh->LoadAsset();
		if (m_pAnimatedMesh->IsLoaded())
		{
			SetPrimaryTechniqueHandle(m_pAnimatedMesh->GetPrimaryTechniqueHandle());
			UpdateGeometry();
		}
		return E_FAIL;
	}

	if (!CGlobals::GetEffectManager()->IsCurrentEffectValid())
	{
		return E_FAIL;
	}

	CParaXModel* pModel = m_pAnimatedMesh->GetModel(0);
	if (pModel == NULL)
		return E_FAIL;

	sceneState->SetCurrentSceneObject(this);
	SetFrameNumber(sceneState->m_nRenderCount);
	// get world transform matrix
	Matrix4 mxWorld;
	GetRenderMatrix(mxWorld);

	RenderDevicePtr pd3dDevice = sceneState->m_pd3dDevice;
	EffectManager* pEffectManager = CGlobals::GetEffectManager();
	pEffectManager->applyObjectLocalLighting(this);

	CEffectFile* pEffectFile = pEffectManager->GetCurrentEffectFile();
	CGlobals::GetWorldMatrixStack().push(mxWorld);

	if (pEffectFile == 0)
	{
		// TODO: Fixed Function. 
	}
	else
	{
		// apply block space lighting for object whose size is comparable to a single block size
		BlockWorldClient* pBlockWorldClient = BlockWorldClient::GetInstance();
		if (pBlockWorldClient && pBlockWorldClient->IsInBlockWorld())
		{
			uint8_t brightness[2];
			Uint16x3 blockId_ws(0, 0, 0);
			Vector3 vPos = GetPosition();
			BlockCommon::ConvertToBlockIndex(vPos.x, vPos.y + 0.1f, vPos.z, blockId_ws.x, blockId_ws.y, blockId_ws.z);
			float fLightness;

			pBlockWorldClient->GetBlockMeshBrightness(blockId_ws, brightness);
			// block light
			float fBlockLightness = Math::Max(pBlockWorldClient->GetLightBrightnessFloat(brightness[0]), 0.1f);
			sceneState->GetCurrentLightStrength().y = fBlockLightness;
			// sun light
			fLightness = Math::Max(pBlockWorldClient->GetLightBrightnessFloat(brightness[1]), 0.1f);
			sceneState->GetCurrentLightStrength().x = fLightness;
			fLightness *= pBlockWorldClient->GetSunIntensity();
			fLightness = Math::Max(fLightness, fBlockLightness);
			
			sceneState->GetLocalMaterial().Ambient = (LinearColor(fLightness*0.7f, fLightness*0.7f, fLightness*0.7f, 1.f));
			sceneState->GetLocalMaterial().Diffuse = (LinearColor(fLightness*0.4f, fLightness*0.4f, fLightness*0.4f, 1.f));
			
			sceneState->EnableLocalMaterial(true);
		}

		// just a single standing animation is supported now and looped. 
		if (!m_CurrentAnim.IsValid())
			m_CurrentAnim = pModel->GetAnimIndexByID(0);
		if (m_CurrentAnim.IsValid())
		{
			int nAnimLength = std::max(1, m_CurrentAnim.nEndFrame - m_CurrentAnim.nStartFrame);
			int nToDoFrame = (m_CurrentAnim.nCurrentFrame + (int)(sceneState->dTimeDelta * 1000)) % nAnimLength;
			m_CurrentAnim.nCurrentFrame = nToDoFrame;
		}
		pModel->m_CurrentAnim = m_CurrentAnim;
		pModel->m_NextAnim.nIndex = 0;
		pModel->m_BlendingAnim.MakeInvalid();
		pModel->blendingFactor = 0;
		pModel->animate(sceneState, NULL);
		// force CParaXModel::BMAX_MODEL? 
		pModel->draw(sceneState, NULL);
	}

	CGlobals::GetWorldMatrixStack().pop();
	return S_OK;
}