Example #1
0
lst_sEntry *
lst_InsertPred (
  thread_sMutex		*mp,
  lst_sEntry		*succ,		/* Insert before this element */
  lst_sEntry		*link,		/* Link to insert */
  void			*item		/* Item to insert */
)
{
  lst_sEntry		*pred;

  if (mp != NULL) sync_MutexLock(mp);

  pwr_Assert(checkInit(link));

  pred = succ->blink;
  
  pwr_Assert(check(succ));
  pwr_Assert(check(pred));
  pwr_Assert(pred->flink == succ);

  link->flink = succ;
  link->blink = succ->blink;
  succ->blink = pred->flink = link;
  if (item != NULL)
    link->item = item;

  if (mp != NULL) sync_MutexUnlock(mp);

  return pred;  
}
Example #2
0
	//may cause a performace drop...
	void Image::draw_rotated(float x, float y, float ax, float ay, float angle, float from_x, float from_y, float w, float h)
	{
		if(checkInit()==false) throw Exception("Fatal error: attempt to use GameEngine library without initialization!");

		//create a cropped surface from the original
		SDL_Surface* cropped = SDL_CreateRGBSurface(0, w, h, 32, 0, 0, 0, 0);
		srcrect.x = from_x; srcrect.y = from_y;
		srcrect.w = w; srcrect.h = h;
		SDL_BlitSurface(implementation->sdlSurface, &srcrect, cropped, null);

		//zoom the cropped fragment
		rotozoom_surface = rotozoomSurface(cropped, angle*toDegree, 1, 0);

		int w1 = implementation->sdlSurface->w,
			h1 = implementation->sdlSurface->h,
			w2 = rotozoom_surface->w,
			h2 = rotozoom_surface->h;

		int ax2 = w2/2 + (ax - w1/2)*cos(angle) - (ay - h1/2)*sin(angle);
		int ay2 = h2/2 + (ay - h1/2)*cos(angle) - (ax - w1/2)*sin(angle);

		dstrect.x = x-ax2;
		dstrect.y = y-ay2;

		//blit the rotated cropped fragment, leaving the original intact
		SDL_BlitSurface(rotozoom_surface, null, GameEngine::display->implementation->sdlDisplaySurface, &dstrect);
		SDL_FreeSurface(cropped);
		SDL_FreeSurface(rotozoom_surface);
	}
Example #3
0
lst_sEntry *
lst_InsertSucc (
  thread_sMutex		*mp,
  lst_sEntry		*pred,		/* Insert after this element */
  lst_sEntry		*link,		/* link to insert */
  void			*item		/* Item to insert */
)
{
  lst_sEntry		*succ;

  if (mp != NULL) sync_MutexLock(mp);

  pwr_Assert(checkInit(link));

  succ = pred->flink;
  
  pwr_Assert(check(succ));
  pwr_Assert(check(pred));
  pwr_Assert(succ->blink == pred);

  link->blink = pred;
  link->flink = pred->flink;
  pred->flink = succ->blink = link;
  if (item != NULL)
    link->item = item;

  if (mp != NULL) sync_MutexUnlock(mp);

  return succ;  
}
Example #4
0
bool PlaylistHandler::createPlaylist(std::string name) {
    checkInit();
    QDomNode node = root.firstChild();
    while (!node.isNull()) {
        QDomElement element = node.toElement();
        if (!element.isNull()) {
            if (element.tagName() == "Playlist") {
                if (element.attribute("name").toStdString() == name) {
                    return false;
                }
            }
        }
        node = node.nextSibling();
    }
    QDomElement thisPlaylist = doc.createElement("Playlist");
    thisPlaylist.setAttribute("name", QString::fromStdString(name));
    boost::uuids::uuid uuidobj = boost::uuids::random_generator()();
    std::stringstream ss;
    ss << uuidobj;
    QString uuid = QString::fromStdString(ss.str());
    thisPlaylist.setAttribute("id", uuid);
    root.appendChild(thisPlaylist);
    save();
    emit playlistsChanged(getPlaylists());
    return true;
}
Example #5
0
	Image::~Image()
	{
		checkInit();
		SDL_FreeSurface(this->implementation->sdlSurface);
		if(this->implementation != null) SDL_FreeSurface(this->implementation->cachedSdlSurface);
		delete implementation;
	}
Example #6
0
void PlaylistHandler::redefinePlaylist(std::string playlistName, std::vector<Song*> songs) {
    checkInit();
    QDomElement playlist = getPlaylistFromName(playlistName);
    QDomNode node = playlist.firstChild();
    std::vector<QDomElement> removeVector;
    while (!node.isNull()) {
        QDomElement element = node.toElement();
        if (!element.isNull() && element.tagName() == "Song") {
            removeVector.push_back(element);
        }
        node = node.nextSibling();
    }
    for (unsigned int i = 0; i < removeVector.size(); i++) {
        playlist.removeChild(removeVector.at(i));
    }
    for (unsigned int i = 0; i < songs.size(); i++) {
        Song* song = songs.at(i);
        QDomElement songElement = doc.createElement("Song");
        songElement.setAttribute("SongName", QString::fromStdString(song->getSongName()));
        songElement.setAttribute("ArtistName", QString::fromStdString(song->getArtistName()));
        songElement.setAttribute("AlbumName", QString::fromStdString(song->getAlbumName()));
        songElement.setAttribute("SongId", song->getSongId());
        songElement.setAttribute("ArtistId", song->getArtistId());
        songElement.setAttribute("AlbumId", song->getAlbumId());
        songElement.setAttribute("CoverArtFilename", QString::fromStdString(song->getCoverArtFilename()));
        playlist.appendChild(songElement);
    }
    save();
    emit songsChanged(playlistName, getSongs(playlistName));
}
Example #7
0
	Event* EventQueue::waitForEvent()
	{
		if(checkInit()==false) throw Exception("Fatal error: attempt to use GameEngine library without initialization!");
		Event* ev = new Event;
		SDL_WaitEvent(ev->implementation->sdlEvent);
		return ev;
	}
Example #8
0
std::vector<Song*> PlaylistHandler::getSongs(std::string playlistName) {
    checkInit();
    if (playlistName == "") {
        std::vector<Song*> emptyVector;
        return emptyVector;
    }
    QDomElement playlist = getPlaylistFromName(playlistName);
    std::vector<Song*> songVector;
    QDomNode node = playlist.firstChild();
    while (!node.isNull()) {
        QDomElement element = node.toElement();
        if (!element.isNull() && element.tagName() == "Song") {
            Song* song = new Song(this);
            song->setSongName(element.attribute("SongName").toStdString());
            song->setSongId(element.attribute("SongId").toInt());
            song->setArtistName(element.attribute("ArtistName").toStdString());
            song->setArtistId(element.attribute("ArtistId").toInt());
            song->setAlbumName(element.attribute("AlbumName").toStdString());
            song->setAlbumId(element.attribute("AlbumId").toInt());
            song->setCoverArtFilename(element.attribute("CoverArtFilename").toStdString());
            songVector.push_back(song);
        }
        node = node.nextSibling();
    }
    return songVector;
}
Example #9
0
	Image::Image(const string& filename)
	: implementation(new Implementation())
	{
		checkInit();
		this->implementation->sdlSurface = IMG_Load(filename.c_str() );
		if ( this->implementation->sdlSurface == null)
			throw AdapterException(string("Could not load image \"") + filename + "\": " + IMG_GetError());

		// attempt to use 32bit format, which are better suited to rotozoom
		if(this->implementation->sdlSurface->format->BitsPerPixel != 32)
		{
			SDL_PixelFormat format32 = *(this->implementation->sdlSurface->format);
			format32.BitsPerPixel = 32;
			SDL_Surface* surf = SDL_ConvertSurface(this->implementation->sdlSurface, &format32, 0);
			if(surf != null)  // if 32bit surf could not be obtained, move on
			{
				SDL_FreeSurface(this->implementation->sdlSurface);
				this->implementation->sdlSurface = surf;
			}
		}

		this->implementation->cachedSdlSurface = null;

		// todo make a bool flag on SDL 1.2 adapter image to toogle AA when rotozooming.
	}
Example #10
0
	Event* EventQueue::waitForEvent()
	{
		checkInit();
		Event* ev = new Event;
		al_wait_for_event(this->implementation->allegroEventQueue, ev->implementation->allegroEvent);
		return ev;
	}
Example #11
0
pwr_tBoolean
lst_IsLinked (
  thread_sMutex		*mp,
  lst_sEntry		*link
)
{
  pwr_tBoolean		is_linked;
  lst_sEntry		*pred;
  lst_sEntry		*succ;

  if (mp != NULL) sync_MutexLock(mp);

  pwr_Assert(checkInit(link));

  pred = link->blink;
  succ = link->flink;
  
  pwr_Assert(check(succ));
  pwr_Assert(check(pred));
  pwr_Assert(pred->flink == link);
  pwr_Assert(succ->blink == link);

  is_linked = link->flink != link;

  if (mp != NULL) sync_MutexUnlock(mp);

  return is_linked;
}
Example #12
0
	Image::Image(string filename)
	{
		if(checkInit()==false) throw Exception("Fatal error: attempt to use GameEngine library without initialization!");
		this->implementation = new Implementation;
		this->implementation->sdlSurface = IMG_Load(filename.c_str() );
		if ( this->implementation->sdlSurface == null)
			throw Exception("Could not load image \"" + filename + "\": " + IMG_GetError());
	}
Example #13
0
	void EventQueue::listenEvents()
	{
		checkInit();
		al_flush_event_queue(this->implementation->allegroEventQueue);
		al_register_event_source(this->implementation->allegroEventQueue, al_get_display_event_source(fgeal::display->implementation->allegroDisplay));
		al_register_event_source(this->implementation->allegroEventQueue, al_get_keyboard_event_source());
		al_register_event_source(this->implementation->allegroEventQueue, al_get_mouse_event_source());
	}
Example #14
0
	//FIXME
	void EventQueue::listenEvents()
	{
		if(checkInit()==false) throw Exception("Fatal error: attempt to use GameEngine library without initialization!");
//		al_flush_event_queue(this->implementation->allegroEventQueue);
//		al_register_event_source(this->implementation->allegroEventQueue, al_get_display_event_source(GameEngine::display->implementation->allegroDisplay));
//		al_register_event_source(this->implementation->allegroEventQueue, al_get_keyboard_event_source());
//		al_register_event_source(this->implementation->allegroEventQueue, al_get_mouse_event_source());
	}
Example #15
0
	Image::Image(int w, int h)
	: implementation(new Implementation())
	{
		checkInit();
		this->implementation->sdlSurface = SDL_CreateRGBSurface(SDL_HWSURFACE, w, h, 32, 0, 0, 0, 0);
		if ( this->implementation->sdlSurface == null)
			throw AdapterException(string("Could not load image with dimensions w=") + w + " h=" + h +" :" + IMG_GetError());
	}
char serialConfig(unsigned char * buffer, unsigned int length){
	unsigned long int i ;
	unsigned long int timer = 0;
	clearClk();
	setProgramm();
	__delay_cycles(10*CONFIG_CYCLES);	
	clearProgramm();
	__delay_cycles(5*CONFIG_CYCLES);		
	while(checkInit() > 0 && timer < 200) timer ++; // waiting for init pin to go down
	if(timer >= 200){
		 printf("Init pin not going down !");
		 setProgramm();
		 return -1;	
	}
	timer = 0;
	__delay_cycles(5*CONFIG_CYCLES);
	#ifndef MARK1
	setProgramm();
	while(checkInit() == 0 && timer < 0xFFFFFF){
		 timer ++; // waiting for init pin to go up
	}
	if(timer >= 0xFFFFFF){
		 printf("Init pin not going high ! \n");	
		 return -1;
	}
	#endif
	timer = 0;
	printf("Starting configuration ! \n");
	for(i = 0 ; i < length ; i ++){
		serialConfigWriteByte(buffer[i]);	
	}
	while(timer < 50){
		clearClk();
		__delay_cycles(CONFIG_CYCLES);
		setClk();	
		timer ++ ;
	}
	clearClk();
	clearDout();
	if(!checkDone() && timer >= 255){
		 printf("Done pin not going high ! \n");
		 return -1;	
	}
	return 1 ;
}
Example #17
0
	Event::Key::value Event::getEventKeyCode()
	{
		checkInit();
		switch(this->implementation->allegroEvent->keyboard.keycode)
		{
			case ALLEGRO_KEY_UP:		return Event::Key::ARROW_UP;
			case ALLEGRO_KEY_DOWN:		return Event::Key::ARROW_DOWN;
			case ALLEGRO_KEY_LEFT:		return Event::Key::ARROW_LEFT;
			case ALLEGRO_KEY_RIGHT:		return Event::Key::ARROW_RIGHT;

			case ALLEGRO_KEY_ENTER: 	return Event::Key::ENTER;
			case ALLEGRO_KEY_SPACE: 	return Event::Key::SPACE;
			case ALLEGRO_KEY_ESCAPE: 	return Event::Key::ESCAPE;

			case ALLEGRO_KEY_A: return Event::Key::A;
			case ALLEGRO_KEY_B: return Event::Key::B;
			case ALLEGRO_KEY_C: return Event::Key::C;
			case ALLEGRO_KEY_D: return Event::Key::D;
			case ALLEGRO_KEY_E: return Event::Key::E;
			case ALLEGRO_KEY_F: return Event::Key::F;
			case ALLEGRO_KEY_G: return Event::Key::G;
			case ALLEGRO_KEY_H: return Event::Key::H;
			case ALLEGRO_KEY_I: return Event::Key::I;
			case ALLEGRO_KEY_J: return Event::Key::J;
			case ALLEGRO_KEY_K: return Event::Key::K;
			case ALLEGRO_KEY_L: return Event::Key::L;
			case ALLEGRO_KEY_M: return Event::Key::M;
			case ALLEGRO_KEY_N: return Event::Key::N;
			case ALLEGRO_KEY_O: return Event::Key::O;
			case ALLEGRO_KEY_P: return Event::Key::P;
			case ALLEGRO_KEY_Q: return Event::Key::Q;
			case ALLEGRO_KEY_R: return Event::Key::R;
			case ALLEGRO_KEY_S: return Event::Key::S;
			case ALLEGRO_KEY_T: return Event::Key::T;
			case ALLEGRO_KEY_U: return Event::Key::U;
			case ALLEGRO_KEY_V: return Event::Key::V;
			case ALLEGRO_KEY_W: return Event::Key::W;
			case ALLEGRO_KEY_X: return Event::Key::X;
			case ALLEGRO_KEY_Y: return Event::Key::Y;
			case ALLEGRO_KEY_Z: return Event::Key::Z;

			case ALLEGRO_KEY_0: return Event::Key::_0;
			case ALLEGRO_KEY_1: return Event::Key::_1;
			case ALLEGRO_KEY_2: return Event::Key::_2;
			case ALLEGRO_KEY_3: return Event::Key::_3;
			case ALLEGRO_KEY_4: return Event::Key::_4;
			case ALLEGRO_KEY_5: return Event::Key::_5;
			case ALLEGRO_KEY_6: return Event::Key::_6;
			case ALLEGRO_KEY_7: return Event::Key::_7;
			case ALLEGRO_KEY_8: return Event::Key::_8;
			case ALLEGRO_KEY_9: return Event::Key::_9;

			//TODO map more buttons...

			default: 				return Event::Key::UNKNOWN;
		}
	}
Example #18
0
	void Image::draw(float x, float y)
	{
		if(checkInit()==false) throw Exception("Fatal error: attempt to use GameEngine library without initialization!");

		//draws all source region
		dstrect.x = x; dstrect.y = y;

		SDL_BlitSurface(this->implementation->sdlSurface, null, GameEngine::display->implementation->sdlDisplaySurface, &dstrect);
	}
Example #19
0
	void Display::clear()
	{
		if(checkInit()==false) throw Exception("Fatal error: attempt to use GameEngine library without initialization!");
		if ( SDL_FillRect(this->implementation->sdlDisplaySurface, null, 0) == -1 )
		{
			string msg = string("SDL_FillRect error! ") + SDL_GetError();
			cout << msg << endl;
			throw Exception(msg);
		}
	}
Example #20
0
	void Image::draw(float x, float y)
	{
		checkInit();
		x = round(x);
		y = round(y);

		//draws all source region
		SDL_Rect dstrect = {(Sint16) x, (Sint16) y};
		SDL_BlitSurface(this->implementation->sdlSurface, null, fgeal::display->implementation->sdlDisplaySurface, &dstrect);
	}
Example #21
0
	void Display::refresh()
	{
		if(checkInit()==false) throw Exception("Fatal error: attempt to use GameEngine library without initialization!");
		//flip surface if double-buffered, update rect if single-buffered instead
		if( SDL_Flip(this->implementation->sdlDisplaySurface) == -1 )
		{
			string message = string("Failed to swap the buffers/refresh the display: ") + SDL_GetError();
			cout << message << endl;
			throw Exception(message);
		}
	}
Example #22
0
	void Image::draw(float x, float y, float from_x, float from_y, float w, float h)
	{
		if(checkInit()==false) throw Exception("Fatal error: attempt to use GameEngine library without initialization!");

		//draws selected region
		dstrect.x = x; dstrect.y = y;
		srcrect.x = from_x; srcrect.y = from_y;
		srcrect.w = w; srcrect.h = h;

		SDL_BlitSurface(this->implementation->sdlSurface, &srcrect, GameEngine::display->implementation->sdlDisplaySurface, &dstrect);
	}
Example #23
0
	Font::Font(const string& filename, int size, bool antialiasing, bool hinting, bool kerning)
	: implementation(new Implementation)
	{
		checkInit();

		//I know, pretty odd...
		int flags = (antialiasing? 0 : ALLEGRO_TTF_MONOCHROME)	| (hinting? 0 : ALLEGRO_TTF_NO_AUTOHINT) | (kerning? 0 : ALLEGRO_TTF_NO_KERNING);
		this->implementation->allegroFont = al_load_ttf_font(filename.c_str(), size, flags);

		if(this->implementation->allegroFont == null)
			throw AdapterException("Font %s could not be loaded: Error %d", filename.c_str(), al_get_errno());
	}
Example #24
0
	Event::MouseButton::value Event::getEventMouseButton()
	{
		checkInit();
		switch(this->implementation->allegroEvent->mouse.button)
		{
			case 1:		return Event::MouseButton::LEFT;
			case 2:		return Event::MouseButton::RIGHT;
			case 3:		return Event::MouseButton::MIDDLE;

			default:	return Event::MouseButton::UNKNOWN;
		}
	}
Example #25
0
	Event::MouseButton::value Event::getEventMouseButton()
	{
		if(checkInit()==false) throw Exception("Fatal error: attempt to use GameEngine library without initialization!");
		switch(this->implementation->sdlEvent->button.button)
		{
			case SDL_BUTTON_LEFT:		return Event::MouseButton::LEFT;
			case SDL_BUTTON_MIDDLE:		return Event::MouseButton::MIDDLE;
			case SDL_BUTTON_RIGHT:		return Event::MouseButton::RIGHT;

			default:	return Event::MouseButton::UNKNOWN;
		}
	}
Example #26
0
PTYPE TSpaceGrid2D::getY(int j)
{
	
	checkInit();
	
	if(j>=0 && j<=NY)
		return j*hy + y0;
	else
	{
		printf("Error in TSpaceGrid2D::getY: Index out of bounds\n");
		exit(EXIT_FAILURE);
	}	
}
Example #27
0
std::string PlaylistHandler::getPlaylistById(std::string id) {
    checkInit();
    QDomElement playlist;
    QDomNode node = root.firstChild();
    while (!node.isNull()) {
        QDomElement element = node.toElement();
        if (!element.isNull() && element.tagName() == "Playlist" && element.attribute("id").toStdString() == id) {
            playlist = element;
        }
        node = node.nextSibling();
    }
    return playlist.attribute("name").toStdString();
}
Example #28
0
PTYPE TNodeGrid2D::get(int i, int j)
{
	
	checkInit();
	
	if(i>=0 && i<NX && j>=0 && j<NY)
		return val[INDEX2D(i,j)];
	else
	{
		printf("Error in TNodeGrid2D::get: Index out of bounds\n");
		exit(EXIT_FAILURE);
	}	
}
Example #29
0
void TNodeGrid2D::set(int i, int j, PTYPE u)
{
	
	checkInit();
	
	if(i>=0 && i<NX && j>=0 && j<NY)
		val[INDEX2D(i,j)] = u;
	else
	{
		printf("Error in TNodeGrid2D::set: Index out of bounds\n");
		exit(EXIT_FAILURE);
	}	
}
Example #30
0
void TNodeGrid2D::writeToFile()
{
	
	checkInit();
	
	ofstream file("CSV/temp.csv", ios::out);
	
	FOR(j, NY)
	{
		FOR(i, NX)
			file << val[INDEX2D(i,j)] << ", ";
		file << "\n";
	}