Esempio n. 1
0
void SoundEngine::initSound()
{
	if( !Configuration::soundenabled )
		return;

	// This seems to be done, but since I found it in the library documentation it might be code
	// needed for a higher version of SDL_Mixer
	//int flags = MIX_INIT_OGG;
	//int initedFlags = Mix_Init( flags );
	//if ( initedFlags != flags )
	//{
	//	dawn_debug_fatal( "Could not initialize all sound modes (Mix_Init left error message \"%s\")", Mix_GetError() );
	//}

	// Chunksize is 256 since this is the smallest my system can handle.
	// Higher chunk sizes seem to make time between click and click sound noticable
	if( Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 256) == -1 )
	{
		dawn_debug_fatal( "Could not open audio (Mix_OpenAudio exited with error message \"%s\")", Mix_GetError() );
	}
	// this should be enough for the beginning, but we might need to group the channels so each group can take care of
	// and fade out old channels if more are needed.
	const int totalNumChannels = 64;
	int numChannels = Mix_AllocateChannels(totalNumChannels);
	dawn_debug_info( "Currently allocated channels for sound = %d", numChannels );
}
Esempio n. 2
0
		void finishFrame()
		{
			if ( curX == 0 && curY == 0 ) return;

			// Bind the texture object
			glBindTexture(GL_TEXTURE_2D, texID);

			// Set the texture's stretching properties
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

			glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer);

			dawn_debug_info( "texture frame finished with %d textures on it and %.2f% of space used", curTextures, float(usedSpace)/(width*height)*100);
			memset( buffer, 0, width*height*20 );

			curX=0;
			curY=0;
			maxY=0;
			curTextures = 0;
			usedSpace = 0;

			// Have OpenGL generate a texture object handle for us
			glGenTextures(1, &texID);
		}
Esempio n. 3
0
static void logChannelUsage( int curChannel )
{
	if( static_cast<size_t>(curChannel+1) > maxChannelsUsed )
	{
		maxChannelsUsed = static_cast<size_t>(curChannel+1);
		dawn_debug_info("Using a total maximum of %d channels for sound playing", maxChannelsUsed);
	}
}
Esempio n. 4
0
bool Resolution::checkResolutionAndAdjustBpp( Resolution &checkRes )
{
	Uint32 flags = SDL_OPENGL;
	if ( checkRes.fullscreen ) {
		flags |= SDL_FULLSCREEN;
	}
	int suggestedBpp = SDL_VideoModeOK( checkRes.width, checkRes.height, checkRes.bpp, flags );
	if ( suggestedBpp != checkRes.bpp )  {
		if ( suggestedBpp >= 24 ) {
			dawn_debug_info("Changing bpp to %d instead of %d for resolution %dx%d", suggestedBpp, checkRes.bpp, checkRes.width, checkRes.height );
			checkRes.bpp = suggestedBpp;
		} else {
			dawn_debug_warn("Given bpp %d for resolution %dx%d probably don't work. Will try anyway since SDL suggested small bpp value of %d.", checkRes.bpp, checkRes.width, checkRes.height, suggestedBpp );
		}
	}
	return suggestedBpp >= 24;
}
Esempio n. 5
0
void Resolution::setResolution( SDL_Surface *&screen, Resolution setRes )
{
	dawn_debug_info( "now setting resolution %dx%d, bpp: %d, fullscreen: %d", setRes.width, setRes.height, setRes.bpp, setRes.fullscreen );
	if ( screen != NULL ) {
		SDL_FreeSurface( screen );
	}

	checkResolutionAndAdjustBpp( setRes );
	
	Uint32 flags = SDL_OPENGL;
	if ( setRes.fullscreen ) {
		flags |= SDL_FULLSCREEN;
	}
	
	screen = SDL_SetVideoMode( setRes.width, setRes.height, setRes.bpp, flags );
	assert( screen != NULL );
	Configuration::screenWidth = setRes.width;
	Configuration::screenHeight = setRes.height;
	Configuration::bpp = setRes.bpp;
	Configuration::fullscreenenabled = setRes.fullscreen;
	glViewport( 0, 0, Configuration::screenWidth, Configuration::screenHeight );
}
Esempio n. 6
0
void SoundEngine::useWalkingSound( bool enabled )
{
	if ( ! Configuration::soundenabled )
		return;

	if ( !enabled && walkingChannel >= 0 ) {
		if ( ! Mix_Paused( walkingChannel ) ) {
			Mix_Pause( walkingChannel );
		}
	} else if ( enabled ) {
		if ( walkingChannel == -1 ) {
			std::string soundFile = "data/sound/walking.ogg";
			Mix_Chunk *soundSample = soundCache->getSoundFromCache( soundFile.c_str() );
			walkingChannel = Mix_PlayChannel( -1, soundSample, -1 );
			if ( walkingChannel == -1 ) {
				dawn_debug_fatal( "Could not play sound %s: %s", soundFile.c_str(), Mix_GetError() );
			}
			dawn_debug_info("using channel %d for walking sound", walkingChannel);
			logChannelUsage( walkingChannel );
		} else if ( Mix_Paused( walkingChannel ) ) {
			Mix_Resume( walkingChannel );
		}
	}
}
Esempio n. 7
0
void cameraFocusHandler::updateFocus()
{
	static float difference_x1x2 = 0.0; // Difference between x1 and x2
	static float difference_y1y2 = 0.0; // Difference between y1 and y2
	static float x_step = 0.0; // How much to increment the x axis position each run
	static float y_step = 0.0; // How much to increment the y axis position each run
	static float trajectory_angleA = 0.0; // Trajectory angle to the x-axis (tan-1(o/a))
	static bool  calculationsDone = false; // Remeber if the calculation have been done
	std::stringstream ss;

	switch (followTag) {
		case (VIEW_CNPC):
			XYCoOrdinates.first = (float)currentNPC->x_pos-(Configuration::screenWidth/2);
			XYCoOrdinates.second = (float)currentNPC->y_pos-(Configuration::screenHeight/2);
		break;

		case (VIEW_PLAYER):
			XYCoOrdinates.first = (float)currentPlayer->x_pos-(Configuration::screenWidth/2);
			XYCoOrdinates.second = (float)currentPlayer->y_pos-(Configuration::screenHeight/2);
		break;

		case (VIEW_PATH):
			if (SDL_GetTicks()+1000 >= lastMoveTime) {
				// We only want to run the step calculations in the first run of the path
				if (!calculationsDone) {
					ss << "cameraFocusHandler::updateFocus : " <<
					          "Entering path from (" << XYCoOrdinates.first <<
					          ", " << XYCoOrdinates.second << ") to (" <<
					          XYTarget.first << ", " << XYTarget.second <<
					          ") ";
					dawn_debug_info(ss.str());
					ss.str("");

					// Get the change in displacement between x1y1 to x2y2
					difference_x1x2 = (XYTarget.first - XYCoOrdinates.first);
					difference_y1y2 = (XYTarget.second - XYCoOrdinates.second);

					// Convert the change values to positives;
					if (difference_x1x2 < 0)
						difference_x1x2 *= -1;
					if (difference_y1y2 < 0)
						difference_y1y2 *= -1;

					// Calculate the angle of the trajectory from the x-axis
					trajectory_angleA = atan(difference_y1y2 / difference_x1x2);
					trajectory_angleA *= (360/(2*3.141)); // Convert to degrees from rads

					// Calculate the x component of the trajectory
					x_step = pathSpeed * cos(trajectory_angleA * (3.14159265/180));

					// Calculate the y component of the trajectory
					y_step = pathSpeed * sin(trajectory_angleA * (3.14159265/180));

					dawn_debug_info ("cameraFocusHandler::updateFocus : "
					          "Trajectory angle from the x-axis: %f", trajectory_angleA);

					dawn_debug_info ("cameraFocusHandler::updateFocus : "
					          "Trajectoy x component=%f", x_step);

					dawn_debug_info ("cameraFocusHandler::updateFocus : "
					          "Trajectoy y component=%f", y_step);

					dawn_debug_info ("cameraFocusHandler::updateFocus : X1-X2 = %f "
					           ", Y1-Y2 = %f", difference_x1x2, difference_y1y2);

					calculationsDone = true;
				}

				if (XYTarget.first > XYCoOrdinates.first)
					XYCoOrdinates.first += x_step;
				else if (XYTarget.first < XYTarget.first)
					XYCoOrdinates.first -= x_step;

				if (XYTarget.second > XYCoOrdinates.second)
					XYCoOrdinates.second += y_step;
				else if (XYTarget.second < XYCoOrdinates.second)
					XYCoOrdinates.second -= y_step;

				lastMoveTime = SDL_GetTicks();
			}

			/*
			Check if we are inside a acceptable range
			of XYTarget. -/+ 0.9 is acceptable.
			*/
			if ((+XYCoOrdinates.first < (+(XYTarget.first + x_step) + 0.9) &&
			        +XYCoOrdinates.first > (+(XYTarget.first - x_step) - 0.9)) &&
			        (+XYCoOrdinates.second < (+(XYTarget.second + y_step) + 0.9) &&
			         +XYCoOrdinates.second > (+(XYTarget.second - y_step) - 0.9))) {
				XYCoOrdinates.first = XYTarget.first;
				XYCoOrdinates.second = XYTarget.second;
				followTag = VIEW_XY;
				_inPath = false;
				calculationsDone = false;
				dawn_debug_info("cameraFocusHandler::updateFocus : "
				          "Path complete");
			}


		break;

		default:
			// Nothing needs to be done.
		break;
	}

	/*
	    My earlier version changed the focus directly, but It seemed like it might
	   be a less intuitive design than I had initially imagined. But this is where the
	   code would be.
	*/
}