Exemplo n.º 1
0
	unsigned char LightMap::getLightAmount(int lightX, int lightY) const
	{
		FB_ASSERT(lightX >= 0 && lightY >= 0);
		FB_ASSERT(lightX < sizeX && lightY < sizeY);

		return lightMap[lightX + lightY * sizeX];
	}
TargetDisplayWindowUpdator::~TargetDisplayWindowUpdator()
{
	FB_ASSERT( game != NULL );
	game->itemManager->setListener( NULL );
	delete window;
	window = NULL;
}
TargetDisplayWindowUpdator::TargetDisplayWindowUpdator( Game* game, TargetDisplayWindow* window ) :
    game( game ),
	currentFrame( 0 ),
	updateTargets( 20 ),
	removeUnnessary( 100 ),
	window( window ),
	risingMessages()
{
	FB_ASSERT( game != NULL );
	game->itemManager->setListener( this );
}
Exemplo n.º 4
0
		void addFadeOut(IStorm3D_BoneAnimation *a, IStorm3D_Model *m, int fadeTime, int waitTime)
		{
			FB_ASSERT(a && m && fadeTime >= 0 && waitTime >= 0);

			Info i;
			i.model = m;
			i.animation = a;
			i.fadeTime = fadeTime;
			i.waitTime = waitTime;

			fades.push_back(i);
		}
Exemplo n.º 5
0
OguiSlider::OguiSlider( OguiWindow* win, Ogui* ogui, int x, int y, int w, int h, 
		const std::string& background_norm, const std::string& background_down, const std::string& background_high,
		const std::string& foreground_norm, const std::string& foreground_down, const std::string& foreground_high, int id, float value ) :
  win( win ),
  ogui( ogui ),
  w( w ),
	h( h ),
  x( x ),
  y( y ),
  id( id ),
  value( value ),
  backgroundId( 1 ),
  foregroundId( 2 ),
  listener( NULL ),
  disabledBackground( NULL ),
  disabledForeground( NULL ),
  offset_x( 0 ),
  offset_y( 0 ),
	horizontal( true )
{
	assert( win );
	assert( ogui );
	
	background = ogui->CreateSimpleImageButton( win, x, y, w, h, 
		background_norm.empty()?NULL:background_norm.c_str(), 
		background_down.empty()?NULL:background_down.c_str(),
		background_high.empty()?NULL:background_high.c_str(), backgroundId );
	
	foreground = ogui->CreateSimpleImageButton( win, x, y, w, h, 
		foreground_norm.empty()?NULL:foreground_norm.c_str(), 
		foreground_down.empty()?NULL:foreground_down.c_str(),
		foreground_high.empty()?NULL:foreground_high.c_str(), 
		foreground_norm.empty()?NULL:foreground_norm.c_str(), foregroundId, NULL );

 
	FB_ASSERT( foreground );
	
	if( value > 1.0f ) value = 1.0f;
	if( value < 0.0f ) value = 0.0f;
		
	// foreground->SetDisabledImage( foreground_norm.c_str() );
	if(horizontal)
		foreground->SetClip( 0.0f, 0.0f, value * 100.0f, 100.0f );
	else
		foreground->SetClip( 0.0f, 100.0f - value * 100.0f, 100.0f, 100.0f );
	foreground->SetDisabled( true );
	foreground->SetListener( this );
	foreground->SetEventMask( OGUI_EMASK_PRESS | OGUI_EMASK_CLICK | OGUI_EMASK_HOLD | OGUI_EMASK_OUT );

	background->SetListener( this );
	background->SetEventMask( OGUI_EMASK_PRESS | OGUI_EMASK_CLICK | OGUI_EMASK_HOLD | OGUI_EMASK_OUT );
	
}
Exemplo n.º 6
0
void LogEntry::setRead( bool read, Game* game )
{
	if( read )
	{
		if( variableState != log_read )
		{
			FB_ASSERT( game != NULL );
			variableState = log_read;
			if( game )
				game->gameScripting->setGlobalIntVariableValue( ( variable_state_prefix + watchVariable ).c_str(), log_read );
		}
	}
	else
	{
		if( variableState != log_not_read )
		{
			FB_ASSERT( game != NULL );
			variableState = log_not_read;
			if( game )
				game->gameScripting->setGlobalIntVariableValue( ( variable_state_prefix + watchVariable ).c_str(), log_not_read );
		}
	}
}
Exemplo n.º 7
0
	void setIdle(IStorm3D_Model *model, const std::string &value, int fadeTime)
	{
		FB_ASSERT(model);

		AnimationMap::iterator it = idles.find(value);
		if(it == idles.end())
			return;

		if(fadeTime < 0)
		{
			fadeTime = idleFadeTime;
		}
		modelInfo[model].setIdle(fader, model, it->second.get(), fadeTime);
	}
Exemplo n.º 8
0
	LightMap::LightMap(ColorMap *colorMap, int sizeX, int sizeY,
		float scaledSizeX, float scaledSizeY)
	{
		this->sizeX = sizeX;
		this->sizeY = sizeY;
		this->scaledSizeX = scaledSizeX;
		this->scaledSizeY = scaledSizeY;
		this->colorMap = colorMap;

		// (what about inaccuracies in float calc?)
		FB_ASSERT(scaledSizeX / (float)sizeX == scaledSizeY / (float)sizeY);

		this->lightMap = new unsigned char[sizeX * sizeY];
		for (int y = 0; y < sizeY; y++)
		{
			for (int x = 0; x < sizeX; x++)
			{
			  COL c = colorMap->getUnmultipliedColor(float(x) / float(sizeX), float(y) / float(sizeY));
				int colAvg = ((int)(c.r*255.0f) + (int)(c.g*255.0f) + (int)(c.b*255.0f)) / 3;
				lightMap[x + y * sizeX] = colAvg;
			}
		}
	}
Exemplo n.º 9
0
	void LightMap::modifySemiDynamicLightImpl(int lightX, int lightY, int radius, bool add, float brightness)
	{
		if(!(lightX - radius >= 0 && lightY - radius >= 0
			&& lightX + radius < sizeX && lightY + radius < sizeY))
		{
			FB_ASSERT(!"LightMap::modifySemiDynamicLightImpl - position with radius goes out of bounds.");
			return;
		}

		int maxLight = int(255.0f * brightness);

		for (int ty = lightY - radius; ty < lightY + radius + 1; ty++)
		{
			for (int tx = lightX - radius; tx < lightX + radius + 1; tx++)
			{
				int dx = tx - lightX;
				int dy = ty - lightY;
				int dSq = dx * dx + dy * dy;
				if (dSq <= radius * radius)
				{
					// linear fade, 255 (at 0 distance) -> 0 (at radius distance)
					int val = lightMap[tx + ty * sizeX];
					if (add)
					{
						val += (maxLight * (radius - (int)sqrtf((float)dSq))) / radius;
						if (val > 255) val = 255;
					} else {
						val -= (maxLight * (radius - (int)sqrtf((float)dSq))) / radius;
						if (val < 0) val = 0;
					}
					lightMap[tx + ty * sizeX] = val;
				}
			}
		}

	}
Exemplo n.º 10
0
	void DevScripting::process(util::ScriptProcess *sp, 
		int command, int intData, char *stringData, ScriptLastValueType *lastValue, 
		GameScriptData *gsd, Game *game, bool *pause)
	{
		switch(command)
		{
		case GS_CMD_ERROR:
			//sp->error("DevScripting::process - Script error:");
			Logger::getInstance()->error("DevScripting::process - Script error:");
			if (stringData != NULL)
			{
				sp->error(stringData);
			} else {
				sp->error("DevScripting::process - Script error (error command has null parameter).");
			}
			break;

		case GS_CMD_RELOADSCRIPTFILE:
			if (stringData != NULL)
			{
				util::ScriptManager::getInstance()->loadScripts(stringData, NULL, true);
			} else {
				sp->error("GameScripting::process - reloadScriptFile parameter missing.");
			}
			break;

		case GS_CMD_reloadParticleEffects:
			if (game->inCombat
				&& game->gameUI->getVisualEffectManager() != NULL)
			{
				game->gameUI->getVisualEffectManager()->loadParticleEffects();
				Logger::getInstance()->info("GameScripting::process - reloadParticleEffects, particle effects reloaded (existing effects may not be affected).");
			} else {
				sp->warning("GameScripting::process - reloadParticleEffects called while in menus or no visual effect manager loaded (call ignored).");
			}
			break;

		case GS_CMD_RELOADSTRINGVALUESCRIPTFILE:
			if (gsd->stringValue != NULL)
			{
				util::ScriptManager::getInstance()->loadScripts(gsd->stringValue, NULL, true);
			} else {
				sp->error("GameScripting::process - reloadStringValueScriptFile for null string.");
			}
			break;

		case GS_CMD_SCRIPTDUMP:
			{
				Logger::getInstance()->debug("Script dump command encountered, output follows...");
				char *dump = sp->getScript()->getDebugDump(sp, false);
				if (dump != NULL)
				{
					Logger::getInstance()->debug(dump);
					delete [] dump;
				} else {
					Logger::getInstance()->debug("Null output."); 				
					assert(0);
				}
			}
			break;

		case GS_CMD_FULLSCRIPTDUMP:
			{
				Logger::getInstance()->debug("Full script dump command encountered, output follows...");
				char *dump = sp->getScript()->getDebugDump(sp, true);
				if (dump != NULL)
				{
					Logger::getInstance()->debug(dump);
					delete [] dump;
				} else {
					Logger::getInstance()->debug("Null output."); 				
					assert(0);
				}
			}
			break;


		case GS_CMD_DEVUNITSCRIPTDUMP:
			{
				Logger::getInstance()->debug("Dev unit script dump command encountered, output follows...");
					// WARNING: unsafe cast!
				util::ScriptProcess *mainsp = ((game::UnitLevelAI *)game->devUnit->getAI())->mainScriptProcess;
				char *dump = mainsp->getScript()->getDebugDump(mainsp, false);
				if (dump != NULL)
				{
					Logger::getInstance()->debug(dump);
					delete [] dump;
				} else {
					Logger::getInstance()->debug("Null output."); 				
					assert(0);
				}
			}
			break;

		case GS_CMD_DEVUNITFULLSCRIPTDUMP:
			{
				if (game->devUnit != NULL)
				{
					Logger::getInstance()->debug("Dev unit full script dump command encountered, output follows...");
					// WARNING: unsafe cast!
					util::ScriptProcess *mainsp = ((game::UnitLevelAI *)game->devUnit->getAI())->mainScriptProcess;
					char *dump = mainsp->getScript()->getDebugDump(mainsp, true);
					if (dump != NULL)
					{
						Logger::getInstance()->debug(dump);
						delete [] dump;
					} else {
						Logger::getInstance()->debug("Null output."); 				
						assert(0);
					}
				}
			}
			break;

		case GS_CMD_DEVMESSAGE:
			if (stringData != NULL)
			{
				if (SimpleOptions::getBool(DH_OPT_B_SCRIPT_DEV_MODE))
				{
					if (game->devUnit == NULL 
						|| gsd->unit == game->devUnit)
					{
						sp->warning(stringData);
					}
				}
			}
			break;

		case GS_CMD_HIDECONSOLE:
			game->gameUI->hideConsole();
			break;

		case GS_CMD_SHOWCONSOLE:
			game->gameUI->showConsole();
			break;

		case GS_CMD_DEVSIDESWAP:
			if (intData >= 0 && intData < ABS_MAX_PLAYERS)
			{
				if (SimpleOptions::getBool(DH_OPT_B_ALLOW_SIDE_SWAP)
					&& game->inCombat)
				{
					sp->debug("DevScripting::process - Swapping sides.");

					game->unitSelections[game->singlePlayerNumber]->selectAllUnits(false);
					
					game->gameUI->closeCombatWindow(game->singlePlayerNumber);
					game->singlePlayerNumber = intData;
					game->gameUI->openCombatWindow(game->singlePlayerNumber);
				}
			} else {
				sp->warning("DevScripting::process - devSideSwap parameter bad.");
			}
			break;

		case GS_CMD_DEVSIDESWAPTOVALUE:
			if (*lastValue >= 0 && *lastValue < ABS_MAX_PLAYERS)
			{
				if (SimpleOptions::getBool(DH_OPT_B_ALLOW_SIDE_SWAP)
					&& game->inCombat)
				{
					sp->debug("DevScripting::process - Swapping sides.");
					
					game->gameUI->closeCombatWindow(game->singlePlayerNumber);
					game->singlePlayerNumber = *lastValue;
					game->gameUI->openCombatWindow(game->singlePlayerNumber);
				}
			} else {
				sp->warning("DevScripting::process - devSideSwapToValue last value out of ranged.");
			}
			break;

		case GS_CMD_DEVUNIT:
			if (gsd->unit == NULL)
			{
				sp->warning("DevScripting::process - devUnit for null unit.");
				game->devUnit = NULL;
			} else {
				game->devUnit = gsd->unit;	
			}
			break;

		case GS_CMD_CLEARDEVUNIT:
			game->devUnit = NULL;
			break;

		case GS_CMD_DUMPSTATUSINFO:
			if (game->getGameScene() != NULL && game->inCombat)
			{
				char *stats = game->getGameScene()->getStorm3D()->GetPrintableStatusInfo();
				Logger::getInstance()->info(stats);
				game->getGameScene()->getStorm3D()->DeletePrintableStatusInfo(stats);
				
				Logger::getInstance()->info("Visual effects running:");
				Logger::getInstance()->info(int2str(ui::visual_effect_allocations));
			} else {
				Logger::getInstance()->warning("DevScripting::process - dumpStatusInfo cannot get info for null scene.");
			}
			break;

		case GS_CMD_dumpEffectsInfo:
			if (game->getGameScene() != NULL && game->inCombat)
			{
				Logger::getInstance()->info("Visual effects running:");
				Logger::getInstance()->info(int2str(ui::visual_effect_allocations));
				Logger::getInstance()->info("Particle spawners total amount:");
				Logger::getInstance()->info(int2str(game->particleSpawnerManager->getParticleSpawnerAmount()));
			} else {
				Logger::getInstance()->warning("DevScripting::process - dumpEffectsInfo cannot get info for null scene.");
			}
			break;

		case GS_CMD_dumpGameSceneGraph:
			{
				char *stats = game->getGameSceneGraphDump();
				Logger::getInstance()->info(stats);
				game->deleteGameSceneGraphDump(stats);
			}
			break;

		case GS_CMD_dumpPhysicsInfo:
			{
				char *stats = UnitPhysicsUpdater::getStatusInfo();
				Logger::getInstance()->info(stats);
				UnitPhysicsUpdater::deleteStatusInfo(stats);
#ifdef PHYSICS_ODE
				stats = PhysicsActorOde::getStatusInfo();
				Logger::getInstance()->info(stats);
				PhysicsActorOde::deleteStatusInfo(stats);
#endif
#ifdef PHYSICS_PHYSX
				if(game->getGamePhysics() && game->getGamePhysics()->getPhysicsLib())
				{
					std::string info = game->getGamePhysics()->getPhysicsLib()->getStatistics();
					Logger::getInstance()->info(info.c_str());
				}
#endif
			}
			break;

		case GS_CMD_RAYTRACEBLAST:
			if (game->getGameScene() != NULL && game->inCombat)
			{
				if (game->gameUI->getFirstPerson(0) != 0)
				{
					if (game->gameUI->getFirstPerson(0)->getVisualObject() != NULL)
					{
						game->gameUI->getFirstPerson(0)->getVisualObject()->setCollidable(false);
					}
					VC3 pos = game->gameUI->getFirstPerson(0)->getPosition();
					pos.y += 1.0f;
					for (float b = -2.0f; b < 1.0f; b += 0.5f)
					{
						for (float a = 0; a < 2*3.1415f; a += 0.25f)
						{
							VC3 dir = VC3(cosf(a), sinf(b / 2.0f), sinf(a));
							dir.Normalize();
							GameCollisionInfo cinfo;
							game->getGameScene()->rayTrace(pos, dir, 20, cinfo, true, false);
						}
					}
					if (game->gameUI->getFirstPerson(0)->getVisualObject() != NULL)
					{
						game->gameUI->getFirstPerson(0)->getVisualObject()->setCollidable(true);
					}
				}
			}
			break;

		case GS_CMD_DEVEXIT:
			sp->error("DevScripting::process - devExit called, making an immediate and unclean exit.");
			exit(0);
			break;

		case GS_CMD_DEVASSERT:
			if (*lastValue == 0)
			{
				sp->warning("DevScripting::process - devAssert.");
				FB_ASSERT(!"DevScripting::process - devAssert.");
			}
			break;

		case GS_CMD_DEVCRASH:
			{
#ifndef FB_TESTBUILD
				sp->warning("DevScripting::process - devCrash ignored.");
#else
				sp->warning("DevScripting::process - devCrash about to crash.");
				FB_ASSERT(!"DevScripting::process - devCrash.");
				int *crashPtr = NULL;
				int crashValue = *crashPtr;
				*lastValue = crashValue;
#endif
			}
			break;

		case GS_CMD_LISTGLOBALVARIABLES:
			{
				LinkedList *tmp = util::Script::getGlobalVariableList(false);

				while (!tmp->isEmpty())
				{
					const char *varname = (const char *)tmp->popLast();
					int varval = 0;
					util::Script::getGlobalIntVariableValue(varname, &varval);

					char *tmpbuf = new char[strlen(varname) + 32];
					strcpy(tmpbuf, varname);
					strcat(tmpbuf, " (");
					strcat(tmpbuf, int2str(varval));
					strcat(tmpbuf, ")");
					Logger::getInstance()->info(tmpbuf);
				}

				delete tmp;
			}
			break;

		case GS_CMD_reloadObjectDurabilities:
			if (gameui_physicsDamageManager != NULL)
			{
				gameui_physicsDamageManager->reloadConfiguration();
			}
			break;

		case GS_CMD_openScoreWindow:
			{
				if( game && game->gameUI )
				{
					game->gameUI->openScoreWindow( game->singlePlayerNumber );
				}
			}
			break;      
      
		case GS_CMD_openMissionSelectionWindow:
			{
				if( game && game->gameUI )
				{
					game->gameUI->openMissionSelectionWindow();
				}
			}
			break;

		case GS_CMD_dumpScriptInfo:
			Logger::getInstance()->info(util::ScriptManager::getInstance()->getStatusInfo().c_str());
			Logger::getInstance()->info("Custom script processes amount:");
			Logger::getInstance()->info(int2str(game->getCustomScriptProcessAmount()));
			break;

		case GS_CMD_devStopAllCustomScripts:
			game->stopAllCustomScriptProcesses();
			break;


#ifndef PROJECT_SHADOWGROUNDS
		case GS_CMD_missionSelectionWindowAddMissionButton:
			{
				if( game && game->gameUI && game->gameUI->getMissionSelectionWindow() )
				{
					game->gameUI->getMissionSelectionWindow()->AddMissionButton( stringData );
				}
			}
			break;
#endif

		case GS_CMD_openMainMenuWindow:
			{
				if( game && game->gameUI )
				{
					game->gameUI->openMainmenuFromGame( intData );
					// game->gameUI->getCommandWindow( game->singlePlayerNumber )->openMenu( intData );
				}
			}
			break;

		case GS_CMD_devRunSingleCommand:
			if (stringData != NULL)
			{				
				int slen = strlen(stringData);
				char *cmdName = new char[slen + 1];
				char *param = new char[slen + 1];
				int cmdNamePos = 0;
				int paramPos = 0;
				cmdName[0] = '\0';
				param[0] = '\0';
				bool trimming = true;
				bool readingCmd = false;
				bool skippingSep = false;
				bool readingParam = false;
				for (int i = 0; i < slen; i++)
				{
					if (trimming)
					{
						if (stringData[i] != ' ' && stringData[i] != '\t')
						{
							trimming = false;
							readingCmd = true;
						}
					}
					if (readingCmd)
					{
						if (stringData[i] == ' ' || stringData[i] == '\t')
						{
							readingCmd  = false;
							skippingSep = true;
						} else {
							cmdName[cmdNamePos] = stringData[i];
							cmdNamePos++;
						}
					}
					if (skippingSep)
					{
						if (stringData[i] != ' ' && stringData[i] != '\t')
						{
							skippingSep = false;
							readingParam = true;
						}
					}
					if (readingParam)
					{
						param[paramPos] = stringData[i];
						paramPos++;
					}
				}
				cmdName[cmdNamePos] = '\0';
				param[paramPos] = '\0';
				if (cmdName[0] == '\0')
				{
					sp->error("DevScripting::process - devRunSingleCommand parameter invalid.");
				} else {
					int tmpInt = *lastValue;
					int tmpInt2 = sp->getSecondaryValue();
					bool success;
					if (!readingParam)
					{
						success = game->gameScripting->runSingleSimpleStringCommand(cmdName, NULL, &tmpInt, &tmpInt2); 
					} else {
						success = game->gameScripting->runSingleSimpleStringCommand(cmdName, param, &tmpInt, &tmpInt2); 
					}
					if (!success)
					{
						sp->error("DevScripting::process - devRunSingleCommand failed.");
					}
					*lastValue = tmpInt;
					sp->setSecondaryValue(tmpInt2);
				}
				delete [] param;
				delete [] cmdName;
			} else {
				sp->error("DevScripting::process - devRunSingleCommand parameter missing.");
			}
			break;

		case GS_CMD_forceCursorVisibility:
			{
				game->gameUI->forceCursorVisibility(intData == 0 ? false : true);
			}
			break;

		case GS_CMD_dumpMemoryInfo:
			{
#ifdef FROZENBYTE_DEBUG_MEMORY
				frozenbyte::debug::dumpLeakSnapshot();
				frozenbyte::debug::markLeakSnapshot();					
#endif
			}
			break;

		case GS_CMD_devPhysicsConnectToRemoteDebugger:
#ifndef FINAL_RELEASE_BUILD
			if (stringData != NULL)
			{
				game->getGamePhysics()->getPhysicsLib()->connectToRemoteDebugger(stringData, 5425);
			} else {
				sp->error("DevScripting::process - devPhysicsConnectToRemoteDebugger parameter missing.");
			}
#else
			sp->error("DevScripting::process - devPhysicsConnectToRemoteDebugger not in build.");
#endif
			break;

		case GS_CMD_clearSelectionVisualizationForUnifiedHandle:
			if (VALIDATE_UNIFIED_HANDLE_BITS(gsd->unifiedHandle))
			{
				SelectionVisualizer::clearSelectionForUnifiedHandle(gsd->unifiedHandle);
			} else {
				sp->error("DevScripting::process - clearSelectionVisualizationForUnifiedHandle, unified handle not valid.");
			}
			break;

		case GS_CMD_setSelectionVisualizationForUnifiedHandle:
			if (VALIDATE_UNIFIED_HANDLE_BITS(gsd->unifiedHandle))
			{
				SelectionVisualizer::setSelectionForUnifiedHandle(gsd->unifiedHandle);
			} else {
				sp->error("DevScripting::process - clearSelectionVisualizationForUnifiedHandle, unified handle not valid.");
			}
			break;

		case GS_CMD_reloadChangedScriptFiles:
			{
				int reloaded = util::ScriptManager::getInstance()->reloadChangedScripts();
				if (reloaded > 0)
				{
					std::string tmp = "reloadChangedScriptFiles - Reloaded ";
					tmp += int2str(reloaded);
					tmp += " script(s).";
					Logger::getInstance()->info(tmp.c_str());
				} else {
					Logger::getInstance()->info("reloadChangedScriptFiles - No scripts were reloaded.");
				}
			}
			break;

		case GS_CMD_restartApplicationSoft:
#ifdef PROJECT_AOV
			Logger::getInstance()->info("DevScripting::process - restartApplicationSoft called.");
			game->gameUI->setQuitRequested();
			::app_soft_restart_requested = true;
#else
			Logger::getInstance()->warning("DevScripting::process - restartApplicationSoft not in build.");
#endif
			break;

		case GS_CMD_restartApplicationHard:
#ifdef PROJECT_AOV
			Logger::getInstance()->info("DevScripting::process - restartApplicationHard called.");
			game->gameUI->setQuitRequested();
			::app_hard_restart_requested = true;
#else
			Logger::getInstance()->warning("DevScripting::process - restartApplicationHard not in build.");
#endif
			break;


		default:
			sp->error("DevScripting::process - Unknown command.");
			assert(0);
		}
	}
Exemplo n.º 11
0
unsigned char AmplitudeArray::getAmplitude(int index) const
{
	if(index >= int(data.size()))
		return 0;

	FB_ASSERT(index >= 0 && index < int(data.size()));
	FB_ASSERT(maxValue);

	/*
	int sampleAhead = 30;
	int dataSize = data.size();
	if(index + sampleAhead < dataSize)
	{
		unsigned char newMax = 0;
		unsigned char newAvg = 0;

		int addAvg = 0;
		for(int i = index; i < index + sampleAhead; ++i)
		{
			unsigned char value = 0;
			if(i >= dataSize)
				value = data[dataSize - 1];
			else
				value = data[i];

			addAvg += value;
			if(value > newMax)
				newMax = value;
		}

		if(newMax < 10)
			newMax = 10;
		newAvg = unsigned char(addAvg / sampleAhead);

		//max = (3 * originalMax / 4) + (1 * newMax / 4);
		//avg = (3 * originalAvg / 4) + (1 * newAvg / 4);
		max = (3 * originalMax / 4) + (1 * newMax / 4);
		avg = (2 * originalAvg / 4) + (2 * newAvg / 4);
	}
	*/

	int sampleAhead = 10;
	int dataSize = data.size();
	if(index - sampleAhead >= 0 && index + sampleAhead < dataSize)
	{
		unsigned char newMax = 0;
		unsigned char newAvg = 0;

		int addAvg = 0;
		for(int i = index - sampleAhead; i < index + sampleAhead; ++i)
		{
			unsigned char value = 0;
			if(i >= dataSize)
				value = data[dataSize - 1];
			else
				value = data[i];

			addAvg += value;
			if(value > newMax)
				newMax = value;
		}

		if(newMax < 10)
			newMax = 10;
		newAvg = (unsigned char) (addAvg / (sampleAhead * 2));

		//max = (3 * originalMax / 4) + (1 * newMax / 4);
		//avg = (3 * originalAvg / 4) + (1 * newAvg / 4);
		maxValue = (3 * originalMax / 4) + (1 * newMax / 4);
		avgValue = (2 * originalAvg / 4) + (2 * newAvg / 4);
	}

	return (unsigned char)(255 * data[index] / maxValue);
}
Exemplo n.º 12
0
void AmplitudeArray::setSampleAmplitude(int index, unsigned char amplitude)
{
	FB_ASSERT(index >= 0 && index < int(data.size()));
	data[index] = amplitude;
}
Exemplo n.º 13
0
void AmplitudeArray::setSampleAmount(int amount)
{
	FB_ASSERT(amount >= 0);
	data.resize(amount);
}