bool SDLAudio::DestroyInterface(void) { /** Destroy a client interface */ SListIterator<SGZMusic*> MusicListITR = MusicList.GetIterator(); MusicListITR.Start(); while (MusicListITR.Valid()) { Mix_FreeMusic(MusicListITR.Item()->Data); MusicList.Remove(MusicListITR); MusicListITR.Forth(); } SListIterator<SGZSound*> SFXListITR = SFXList.GetIterator(); SFXListITR.Start(); while (SFXListITR.Valid()) { Mix_FreeChunk(SFXListITR.Item()->Data); SFXList.Remove(SFXListITR); SFXListITR.Forth(); } Mix_CloseAudio(); return true; }
bool SDLAudio::LoadSFXFile( std::string Filename, std::string SFXName ) { /** Check to see if we've already loaded it */ SListIterator<SGZSound*> SFXListITR = SFXList.GetIterator(); for( SFXListITR.Start(); SFXListITR.Valid(); SFXListITR.Forth() ) if((SFXListITR.Item()->Name.compare(SFXName))==0) { SGZLogger.debug("AudioMAN: SFX \"%s\" already loaded!\n", SFXName.c_str()); return false; } /** Load a sound effect to play */ SGZLogger.debug("AudioMAN: Loading SFX \"%s\" as %s\n", Filename.c_str(), SFXName.c_str()); SGZSound *Effect; Effect = new SGZSound; Effect->Name = SFXName; Effect->Data = Mix_LoadWAV(Filename.c_str()); if(Effect->Data == NULL) { SGZLogger.warn("AudioMAN: Failed to load SFX: %s\n", Filename.c_str()); delete Effect; return false; } else SFXList.Append(Effect); return true; }
bool SDLEntity2D::LoadFrame ( std::string Name, std::string TexName, std::string MaskName, int FrameDelay, int x, int y, SGZCOLOUR ColourKey ) { /// Load up a Texture into an Animation SListIterator<SGZAnimGroup2D*> AnimListITR = AnimList.GetIterator(); for( AnimListITR.Start(); AnimListITR.Valid(); AnimListITR.Forth() ) if((AnimListITR.Item()->AnimName.compare(Name))==0) { SGZAnimFrame2D *Frame = new SGZAnimFrame2D; Frame->TextureName = TexName; Frame->MaskName = "none"; Frame->delay = FrameDelay; Frame->u = x; Frame->v = y; Frame->colkey = ColourKey; AnimListITR.Item()->FrameList.Append(Frame); AnimListITR.Item()->AnimNum++; AnimListITR.Item()->FrameITR = AnimListITR.Item()->FrameList.GetIterator(); if(!SGZInterpret.accessServer()->World()->accessTextureManager()->CheckExist(TexName)) SGZLogger.warn("Texture %s has not been loaded yet.. make sure it is before calling this frame!", TexName.c_str()); return true; } SGZLogger.warn("Animation \"%s\" does not exist!\n",Name.c_str()); return false; }
bool SDLAudio::LoadMUSFile( std::string Filename, std::string MUSName ) { /** Check to see if we've already loaded it */ SListIterator<SGZMusic*> MusicListITR = MusicList.GetIterator(); for( MusicListITR.Start(); MusicListITR.Valid(); MusicListITR.Forth() ) if((MusicListITR.Item()->Name.compare(MUSName))==0) { SGZLogger.debug("AudioMAN: SFX: %s already loaded!\n", MUSName.c_str()); return false; } /** Load a music to play */ SGZLogger.debug("AudioMAN: Loading MUS: %s as %s\n", Filename.c_str(), MUSName.c_str()); SGZMusic *Music; Music = new SGZMusic; Music->Name = MUSName; Music->Data = Mix_LoadMUS(Filename.c_str()); if(Music->Data == NULL) { SGZLogger.warn("AudioMAN: Failed to load MUS: %s\n", Filename.c_str()); delete Music; return false; } else MusicList.Append(Music); return true; }
void CInterpret::CleanEvents( void ) { SListIterator<IEvent*> EventListITR = EventList.GetIterator(); for( EventListITR.Start(); EventListITR.Valid(); EventListITR.Forth() ) { if(EventListITR.Item()->handled(false)) EventList.Remove(EventListITR); } }
bool MEntity::UpdateEntities( void ) { /** Update Entities */ SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); for( EntityListITR.Start(); EntityListITR.Valid(); EntityListITR.Forth() ) EntityListITR.Item()->Update(); return true; }
bool SDLEntity2D::Update ( void ) { /// Update our beloved entity SListIterator<SGZAnimGroup2D*> AnimListITR = AnimList.GetIterator(); for( AnimListITR.Start(); AnimListITR.Valid(); AnimListITR.Forth() ) if((AnimListITR.Item()->AnimName.compare(CurrentAnim))==0) { if(AnimListITR.Item()->FrameITR.Valid()) { frame.x = (Uint16)AnimListITR.Item()->FrameITR.Item()->u; frame.y = (Uint16)AnimListITR.Item()->FrameITR.Item()->v; frame.w = (Uint16)entityWidth; frame.h = (Uint16)entityHeight; offset.x = 0; offset.y = 0; offset.w = (Uint16)entityWidth; offset.h = (Uint16)entityHeight; CurrentFrame = static_cast<SDL_Surface*>(SGZInterpret.accessServer()->World()->accessTextureManager()->GetTexture(AnimListITR.Item()->FrameITR.Item()->TextureName)); // SDL_BlitSurface(temp, &frame, TempFrame, &offset ); //CurrentFrame = rotozoomSurfaceXY (TempFrame, angle, zoomX, zoomY, 0); SDL_SetColorKey(CurrentFrame, SDL_SRCCOLORKEY, SDL_MapRGB(CurrentFrame->format, (Uint32)AnimListITR.Item()->FrameITR.Item()->colkey.r, (Uint32)AnimListITR.Item()->FrameITR.Item()->colkey.g, (Uint32)AnimListITR.Item()->FrameITR.Item()->colkey.b)); offset.w = (Uint16)entityWidth; offset.h = (Uint16)entityHeight; offset.x = (Sint16)position.x; offset.y = (Sint16)position.y; SDL_BlitSurface(CurrentFrame, &frame, SDL_GetVideoSurface(), &offset ); //SDL_FreeSurface(CurrentFrame); //SDL_FreeSurface(TempFrame); } if(AnimListITR.Item()->AnimTimer.currenttime() >= AnimListITR.Item()->FrameITR.Item()->delay) { AnimListITR.Item()->FrameITR.Forth(); AnimListITR.Item()->CurAnim++; AnimListITR.Item()->AnimTimer.reset(); } if (AnimListITR.Item()->FrameList.Size() == AnimListITR.Item()->CurAnim) { AnimListITR.Item()->CurAnim = 0; AnimListITR.Item()->FrameITR.Start(); } } return true; }
std::string SDLEntity2D::CheckVar( std::string Name ) { SListIterator<SGZVarGroup*> VarITR = VarList.GetIterator(); for( VarITR.Start(); VarITR.Valid(); VarITR.Forth() ) if((VarITR.Item()->Name.compare(Name))==0) return VarITR.Item()->Variable; return "none"; }
std::string MEntity::CheckVar ( std::string Name, std::string VarName ) { SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); for( EntityListITR.Start(); EntityListITR.Valid(); EntityListITR.Forth() ) if(EntityListITR.Item()->GetName().compare(Name)==0) return EntityListITR.Item()->CheckVar(VarName); SGZLogger.warn("Entity %s does not exist!\n", Name.c_str()); return "none"; }
void CInterpret::NextEvent( void ) { SListIterator<IEvent*> EventListITR = EventList.GetIterator(); for( EventListITR.Start(); EventListITR.Valid(); EventListITR.Forth() ) { if(EventListITR.Item()->doEvent()) EventListITR.Item()->handled(true); } CleanEvents(); }
bool MEntity::CheckExist(std::string Name) { /** Check an Entity */ SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); for( EntityListITR.Start(); EntityListITR.Valid(); EntityListITR.Forth() ) if(EntityListITR.Item()->GetName().compare(Name)==0) return true; return false; }
std::string MEntity::GetAnimation( std::string Name ) { /** Return the current X Position */ SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); for( EntityListITR.Start(); EntityListITR.Valid(); EntityListITR.Forth() ) if(EntityListITR.Item()->GetName().compare(Name)==0) return EntityListITR.Item()->GetAnimation(); SGZLogger.warn("Entity %s does not exist!\n", Name.c_str()); return "none"; }
SGZSCALER MEntity::GetDepth ( std::string Name ) { /** Return the current width */ SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); for( EntityListITR.Start(); EntityListITR.Valid(); EntityListITR.Forth() ) if(EntityListITR.Item()->GetName().compare(Name)==0) return EntityListITR.Item()->GetDepth(); SGZLogger.warn("Entity %s does not exist!\n", Name.c_str()); return 0; }
MEntity::~MEntity() { /** Destructor */ SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); EntityListITR.Start(); while (EntityListITR.Valid()) { EntityList.Remove(EntityListITR); EntityListITR.Forth(); } }
bool MEntity::MoveDeltaZ ( std::string Name, SGZVECTORVAL amount ) { SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); for( EntityListITR.Start(); EntityListITR.Valid(); EntityListITR.Forth() ) if(EntityListITR.Item()->GetName().compare(Name)==0) { EntityListITR.Item()->MoveDeltaZ( amount ); return true; } SGZLogger.warn("Entity %s does not exist!\n", Name.c_str()); return false; }
bool MEntity::DeleteAnimation( std::string Name, std::string AnimName ) { SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); for( EntityListITR.Start(); EntityListITR.Valid(); EntityListITR.Forth() ) if(EntityListITR.Item()->GetName().compare(Name)==0) { EntityListITR.Item()->DeleteAnimation( AnimName ); return true; } SGZLogger.warn("Entity %s does not exist!\n", Name.c_str()); return false; }
bool MEntity::ChangeVar ( std::string Name, std::string VarName, std::string Value ) { SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); for( EntityListITR.Start(); EntityListITR.Valid(); EntityListITR.Forth() ) if(EntityListITR.Item()->GetName().compare(Name)==0) { EntityListITR.Item()->ChangeVar(VarName, Value); return true; } SGZLogger.warn("Entity %s does not exist!\n", Name.c_str()); return false; }
bool MEntity::SetDepth ( std::string Name, SGZSCALER value ) { SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); for( EntityListITR.Start(); EntityListITR.Valid(); EntityListITR.Forth() ) if(EntityListITR.Item()->GetName().compare(Name)==0) { EntityListITR.Item()->SetDepth( value ); return false; } SGZLogger.warn("Entity %s does not exist!\n", Name.c_str()); return false; }
bool MEntity::MoveTo ( std::string Name, SGZVECTOR vector ) { /** Move to direct co-ordinates */ SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); for( EntityListITR.Start(); EntityListITR.Valid(); EntityListITR.Forth() ) if(EntityListITR.Item()->GetName().compare(Name)==0) { EntityListITR.Item()->MoveTo( vector ); return true; } SGZLogger.warn("Entity %s does not exist!\n", Name.c_str()); return false; }
bool MEntity::DelEntity(std::string Name) { /** Remove an Entity */ SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); for( EntityListITR.Start(); EntityListITR.Valid(); EntityListITR.Forth() ) if(EntityListITR.Item()->GetName().compare(Name)==0) { EntityList.Remove(EntityListITR); return true; } SGZLogger.warn("Entity %s does not exist!\n", Name.c_str()); return false; }
bool SDLEntity2D::DeleteVar( std::string Name ) { SListIterator<SGZVarGroup*> VarITR = VarList.GetIterator(); for( VarITR.Start(); VarITR.Valid(); VarITR.Forth() ) if((VarITR.Item()->Name.compare(Name))==0) { VarList.Remove(VarITR); return true; } SGZLogger.warn("Variable \"%s\" does not exist!\n",Name.c_str()); return false; }
int SDLAudio::NewestGROUP(std::string name) { /** Check to see if we've created it */ SListIterator<SGZChanGroup*> GroupListITR = GroupList.GetIterator(); for( GroupListITR.Start(); GroupListITR.Valid(); GroupListITR.Forth() ) if((GroupListITR.Item()->Name.compare(name))==0) { return Mix_GroupNewer(GroupListITR.Item()->groupNum); } SGZLogger.warn("AudioMAN: Group \"%s\" doesn't exist!\n", name.c_str()); return 0; }
bool MEntity::SetCollisionGeom ( std::string Name, int type ) { /** Set the collision type */ SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); for( EntityListITR.Start(); EntityListITR.Valid(); EntityListITR.Forth() ) if(EntityListITR.Item()->GetName().compare(Name)==0) { EntityListITR.Item()->SetCollisionGeom( type ); return true; } SGZLogger.warn("Entity %s does not exist!\n", Name.c_str()); return false; }
bool MEntity::LookTo ( std::string Name, SGZVECTOR vector ) { /** Direction to look at ( move towards ) */ SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); for( EntityListITR.Start(); EntityListITR.Valid(); EntityListITR.Forth() ) if(EntityListITR.Item()->GetName().compare(Name)==0) { EntityListITR.Item()->LookTo( vector ); return true; } SGZLogger.warn("Entity %s does not exist!\n", Name.c_str()); return false; }
bool MEntity::LoadFrame ( std::string Name, std::string AnimName, std::string TexName, std::string MaskName, int FrameDelay, int u, int v, SGZCOLOUR ColourKey ) { /** Load up a Texture into an Animation*/ SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); for( EntityListITR.Start(); EntityListITR.Valid(); EntityListITR.Forth() ) if(EntityListITR.Item()->GetName().compare(Name)==0) { EntityListITR.Item()->LoadFrame( AnimName, TexName, MaskName, FrameDelay, u, v, ColourKey ); return true; } SGZLogger.warn("Entity %s does not exist!\n", Name.c_str()); return false; }
bool MEntity::Stop ( std::string Name ) { /** Stop moving/rotating/scaling immediately */ SListIterator<IEntity*> EntityListITR = EntityList.GetIterator(); for( EntityListITR.Start(); EntityListITR.Valid(); EntityListITR.Forth() ) if(EntityListITR.Item()->GetName().compare(Name)==0) { EntityListITR.Item()->Stop( ); return true; } SGZLogger.warn("Entity %s does not exist!\n", Name.c_str()); return false; }
int SDLAudio::FadeInSFX( std::string SFXName, int time, int loops, int channel) { /** Play SFX */ SListIterator<SGZSound*> SFXListITR = SFXList.GetIterator(); for( SFXListITR.Start(); SFXListITR.Valid(); SFXListITR.Forth() ) if((SFXListITR.Item()->Name.compare(SFXName))==0) { return Mix_FadeInChannel(channel, SFXListITR.Item()->Data, loops, time); } SGZLogger.warn("AudioMAN: Can't find SFX \"%s\" to Fade In!\n", SFXName.c_str()); return -1; }
bool SDLEntity2D::ChangeVar ( std::string Name, std::string Value ) { /** Load up a Texture into an Animation*/ SListIterator<SGZVarGroup*> VarITR = VarList.GetIterator(); for( VarITR.Start(); VarITR.Valid(); VarITR.Forth() ) if((VarITR.Item()->Name.compare(Name))==0) { VarITR.Item()->Variable = Value; return true; } SGZLogger.warn("Variable \"%s\" does not exist!\n",Name.c_str()); return false; }
bool SDLAudio::GroupCHANS(int from, int to, std::string name) { /** Check to see if we've created it */ SListIterator<SGZChanGroup*> GroupListITR = GroupList.GetIterator(); for( GroupListITR.Start(); GroupListITR.Valid(); GroupListITR.Forth() ) if((GroupListITR.Item()->Name.compare(name))==0) { Mix_GroupChannels(from, to, GroupListITR.Item()->groupNum); return true; } SGZLogger.warn("AudioMAN: Group \"%s\" doesn't exist!\n", name.c_str()); return false; }
bool SDLAudio::FadeGROUP(std::string name, int time) { /** Check to see if we've created it */ SListIterator<SGZChanGroup*> GroupListITR = GroupList.GetIterator(); for( GroupListITR.Start(); GroupListITR.Valid(); GroupListITR.Forth() ) if((GroupListITR.Item()->Name.compare(name))==0) { Mix_FadeOutGroup(GroupListITR.Item()->groupNum, time); return true; } SGZLogger.warn("AudioMAN: Group \"%s\" doesn't exist!\n", name.c_str()); return false; }