Browse Source

Add piping down app events into fbo sources instead of registering

master
Krisjanis Rijnieks 9 years ago
parent
commit
197145bb33
  1. 5
      src/Application/Application.cpp
  2. 34
      src/MediaServer/MediaServer.cpp
  3. 4
      src/MediaServer/MediaServer.h
  4. 32
      src/Sources/FboSource.cpp
  5. 15
      src/Sources/FboSource.h

5
src/Application/Application.cpp

@ -43,6 +43,9 @@ Application::Application(){
}
void Application::setup(){
// Setup components
_mediaServer.setup();
if(!loadXmlSettings(PIMAPPER_SETTINGS_FILE)){
if(SettingsLoader::instance()->create(PIMAPPER_SETTINGS_FILE)){
bool success = loadXmlSettings(PIMAPPER_SETTINGS_FILE);
@ -69,6 +72,7 @@ void Application::setup(){
}
void Application::update(){
_mediaServer.update();
_state->update(this);
// Autosave, do it only of the mode is not presentation mode
@ -86,6 +90,7 @@ ApplicationBaseMode * Application::getState(){
}
void Application::draw(){
_mediaServer.draw();
_state->draw(this);
_info.draw();
}

34
src/MediaServer/MediaServer.cpp

@ -32,6 +32,24 @@ MediaServer::~MediaServer(){
removeWatcherListeners();
}
void MediaServer::setup(){
// We could setup sources here, but the sources are
// set up while adding them to media server. For now
// This method is here just to keep things consistent.
}
void MediaServer::update(){
for(int i = 0; i < fboSources.size(); ++i){
fboSources[i]->updateFbo();
}
}
void MediaServer::draw(){
for(int i = 0; i < fboSources.size(); ++i){
fboSources[i]->drawFbo();
}
}
int MediaServer::getNumImages(){
int numLocalImages = imageWatcher.getFilePaths().size();
int numPiImages = piImageWatcher.getFilePaths().size();
@ -156,7 +174,7 @@ BaseSource * MediaServer::loadMedia(string & path, int mediaType){
stringstream ss;
ss << "Can not load media of unknown type: " << mediaType;
ofLogFatalError("MediaServer") << ss.str();
exit(EXIT_FAILURE);
std::exit(EXIT_FAILURE);
}
return 0;
}
@ -227,7 +245,7 @@ void MediaServer::unloadImage(string & path){
stringstream failss;
failss << "Failed to remove image source: " << path;
ofLogFatalError("MediaServer") << failss.str();
exit(EXIT_FAILURE);
std::exit(EXIT_FAILURE);
}
BaseSource * MediaServer::loadVideo(string & path){
@ -298,7 +316,7 @@ void MediaServer::unloadVideo(string & path){
stringstream failss;
failss << "Failed to remove video source: " << path;
ofLogFatalError("MediaServer") << failss.str();
exit(EXIT_FAILURE);
std::exit(EXIT_FAILURE);
}
void MediaServer::unloadMedia(string & path){
@ -313,7 +331,7 @@ void MediaServer::unloadMedia(string & path){
}else{
// Oh my god, what to do!? Relax and exit.
ofLogFatalError("MediaServer") << "Attempt to unload media of unknown type";
exit(EXIT_FAILURE);
std::exit(EXIT_FAILURE);
}
}else{
ofLogNotice("MediaServer") << "Nothing to unload";
@ -341,7 +359,7 @@ BaseSource * MediaServer::getSourceByPath(string & mediaPath){
stringstream ss;
ss << "Could not find source by path: " << mediaPath;
ofLogFatalError("MediaServer") << ss.str();
exit(EXIT_FAILURE);
std::exit(EXIT_FAILURE);
}
string MediaServer::getDefaultImageDir(){
@ -361,7 +379,7 @@ string MediaServer::getDefaultMediaDir(int sourceType){
stringstream ss;
ss << "Could not get default media dir. Unknown source type: " << sourceType;
ofLogFatalError("MediaServer") << ss.str();
exit(EXIT_FAILURE);
std::exit(EXIT_FAILURE);
}
}
@ -414,7 +432,7 @@ BaseSource * MediaServer::loadFboSource(string & fboSourceName){
// else
// Not loaded, add to loaded sources and activate
// source var should be set by now
source->addAppListeners();
//source->addAppListeners();
source->referenceCount = 1;
ofLogNotice("MediaServer") << "Current " << fboSourceName << " reference count: " << source->referenceCount;
loadedSources[fboSourceName] = source;
@ -438,7 +456,7 @@ void MediaServer::unloadFboSource(string & fboSourceName){
if(source->referenceCount <= 0){
ofLogNotice("MediaServer") << fboSourceName << " reference count <= 0, removing from loaded sources";
source->referenceCount = 0;
source->removeAppListeners();
//source->removeAppListeners();
map <string, BaseSource *>::iterator it = loadedSources.find(fboSourceName);
loadedSources.erase(it);
ofLogNotice("MediaServer") << "Source count after FBO source removal: " << loadedSources.size() << endl;

4
src/MediaServer/MediaServer.h

@ -65,6 +65,10 @@ class MediaServer {
public:
MediaServer();
virtual ~MediaServer();
void setup();
void update();
void draw();
int getNumVideos();
int getNumImages();

32
src/Sources/FboSource.cpp

@ -3,7 +3,8 @@
namespace ofx {
namespace piMapper {
FboSource::FboSource() : fbo(0){
FboSource::FboSource(){
fbo = 0;
name = PIMAPPER_FBO_SOURCE_DEF_NAME;
loadable = false;
loaded = false;
@ -12,31 +13,10 @@ FboSource::FboSource() : fbo(0){
}
FboSource::~FboSource(){
removeAppListeners();
clear();
}
void FboSource::addAppListeners(){
ofLogNotice("FboSource") << "Adding app listeners";
ofAddListener(ofEvents().update, this,
&FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP);
ofAddListener(ofEvents().draw, this,
&FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP);
ofAddListener(ofEvents().exit, this,
&FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP);
}
void FboSource::removeAppListeners(){
ofLogNotice("FboSource") << "Removing app listeners";
ofRemoveListener(ofEvents().update, this,
&FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP);
ofRemoveListener(ofEvents().draw, this,
&FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP);
ofRemoveListener(ofEvents().exit, this,
&FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP);
}
void FboSource::onAppUpdate(ofEventArgs & args){
void FboSource::updateFbo(){
if(fbo == 0 || !fbo->isAllocated()){
ofLogWarning("FboSource") << "FBO not allocated";
return;
@ -44,7 +24,7 @@ void FboSource::onAppUpdate(ofEventArgs & args){
update();
}
void FboSource::onAppDraw(ofEventArgs & args){
void FboSource::drawFbo(){
if(fbo == 0 || !fbo->isAllocated()){
ofLogWarning("FboSource") << "FBO not allocated";
return;
@ -59,10 +39,6 @@ void FboSource::onAppDraw(ofEventArgs & args){
fbo->end();
}
void FboSource::onAppExit(ofEventArgs & args){
exit();
}
void FboSource::setDisableDraw(bool b){
_disableDraw = b;
}

15
src/Sources/FboSource.h

@ -18,18 +18,19 @@ class FboSource : public BaseSource {
virtual void setup(){}
virtual void update(){}
virtual void draw(){}
virtual void exit(){}
// We use this as replacement of draw internally in ofxPiMapper
// to populate the FBO texture that then can be drawn again by
// calling normal draw();
// Or maybe this should be simplified? By leaving only one draw?
// And the user would have to allocate the fbo himself?
void updateFbo();
void drawFbo();
// The only method from BaseSource to be overriden
void clear();
// App listeners
void addAppListeners();
void removeAppListeners();
void onAppSetup(ofEventArgs & args);
void onAppUpdate(ofEventArgs & args);
void onAppDraw(ofEventArgs & args);
void onAppExit(ofEventArgs & args);
void setDisableDraw(bool b); // Use in cases with external ofFbo
protected:

Loading…
Cancel
Save