Skip to content

Commit

Permalink
Reverted some changes made to the Ogre3D demo.
Browse files Browse the repository at this point in the history
git-svn-id: http://simplefilewatcher.googlecode.com/svn/trunk@2 d2862050-3e7c-11de-90e1-f9f1724fc9cc
  • Loading branch information
saintonfire committed May 11, 2009
1 parent e82f6f0 commit ae55776
Showing 1 changed file with 124 additions and 163 deletions.
287 changes: 124 additions & 163 deletions OgreDemo.cpp
Original file line number Diff line number Diff line change
@@ -1,78 +1,42 @@
/**
Demo app for FileWatcher. FileWatcher is a simple wrapper for the file
modification system in windows. Run the demo and then execute the batch
files in the media directory (red.bat, blue.bat, green.bat) and the
textures will automatically reload in the window.
@author James Wynn
@date 2/25/2009
*/

#include "ExampleApplication.h"
#include <FileWatcher/FileWatcher.h>
#include "ResourceGroupHelper.h"

using namespace Ogre;

// ugly globals for demo
FW::FileWatcher* gFileWatcher = 0;
/**
Demo app for FileWatcher. FileWatcher is a simple wrapper for the file
modification system in windows. Run the demo and then execute the batch
files in the media directory (red.bat, blue.bat, green.bat) and the
textures will automatically reload in the window.
@author James Wynn
@date 2/25/2009
*/

#include "ExampleApplication.h"
#include <FileWatcher/FileWatcher.h>

using namespace Ogre;

// ugly globals for demo
FW::FileWatcher* gFileWatcher = 0;
FW::WatchID gWatchID = 0;
ResourceGroupHelper* gHelper = 0;

class FWTestFrameListener : public ExampleFrameListener
{
public:
FWTestFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr)
: ExampleFrameListener(win, cam, false, false)
{
}

bool frameStarted(const FrameEvent &evt)
{
// update the file watcher every frame
gFileWatcher->update();

static float firstR = 0.0f;

if(firstR==0.0f && mKeyboard->isKeyDown(OIS::KC_T))
{
firstR = 1.0f;

// name of the resource group that we want to track
std::string resourceGroupName = "Testing";

// to receive the error messages
std::string errorMessages;

// look on the hdd the last modification time and try reload changes if needed
//gHelper->checkTimeAndReloadIfNeeded(resourceGroupName, errorMessages);
//gHelper->reloadAResourceGroupWithoutDestroyingIt(resourceGroupName);
std::vector<ResourceGroupHelper::ArchivePathAndType> paths;
paths.push_back(std::make_pair("../media","FileSystem"));
gHelper->reloadAResourceGroup(resourceGroupName, paths);
gHelper->updateOnEveryRenderable();

if(errorMessages.size()>0)
{
// you can display them in a message box, or in an overlay for example
// here I resend them to the log...
Ogre::LogManager& logMgr = Ogre::LogManager::getSingleton();
logMgr.logMessage("****************** HERE THE BAD MESSAGES : ");
logMgr.logMessage(errorMessages);
logMgr.logMessage("****************** END OF THE BAD MESSAGES *****");
}

}else if(!mKeyboard->isKeyDown(OIS::KC_R))
{
firstR = 0.0;
}

return ExampleFrameListener::frameStarted(evt);
}
};//class FWTestFrameListener


/// Processes a file action


class FWTestFrameListener : public ExampleFrameListener
{
public:
FWTestFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr)
: ExampleFrameListener(win, cam, false, false)
{
}

bool frameStarted(const FrameEvent &evt)
{
// update the file watcher every frame
gFileWatcher->update();

return ExampleFrameListener::frameStarted(evt);
}
};//class FWTestFrameListener


/// Processes a file action
class TextureReloader : public FW::FileWatchListener
{
public:
Expand All @@ -92,92 +56,89 @@ class TextureReloader : public FW::FileWatchListener
tex->reload();
}
};

class FWTestApplication : public ExampleApplication
{
protected:
Ogre::SceneNode *mNinjaNode;
Ogre::Entity *mNinjaEntity;

public:
FWTestApplication()
{
// create the file watcher object
gFileWatcher = new FW::FileWatcher();
// add a watch to the system
gWatchID = gFileWatcher->addWatch("..\\media", new TextureReloader());

// create the helper
gHelper = new ResourceGroupHelper();
}

~FWTestApplication()
{
// file watcher releases all watches on cleanup
delete gFileWatcher;
gFileWatcher = 0;
}

protected:
void createScene(void)
{
//Some normal stuff.
mSceneMgr->setAmbientLight(ColourValue(0.7,0.7,0.7));
mCamera->setPosition(Vector3(0,0,100));
mCamera->lookAt(Vector3::ZERO);
mCamera->setNearClipDistance(0.05);
mCamera->setFarClipDistance(300);
LogManager::getSingleton().setLogDetail(LL_BOREME);

//----------------------------------------------------------
// Ninja!
//----------------------------------------------------------

Vector3 pos = Vector3(0,0,0);
Quaternion rot = Quaternion::IDENTITY;

//Create Ogre stuff.
mNinjaEntity = mSceneMgr->createEntity("ogrehead", "ogrehead.mesh");
mNinjaNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("ogrehead", pos, rot);
mNinjaNode->attachObject(mNinjaEntity);
mNinjaNode->translate(0,0,0);
mNinjaNode->setScale(0.5,0.5,0.5);
}

void createFrameListener(void)
{
mFrameListener = new FWTestFrameListener(mWindow, mCamera, mSceneMgr);
mRoot->addFrameListener(mFrameListener);
}
};//class FWTestApplication



#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
// Create application object
FWTestApplication app;

try
{
app.go();
}
catch( Exception& e )
{
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.what(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
fprintf(stderr, "An exception has occurred: %s\n",
e.what());
#endif
}

return 0;
}

class FWTestApplication : public ExampleApplication
{
protected:
Ogre::SceneNode *mNinjaNode;
Ogre::Entity *mNinjaEntity;

public:
FWTestApplication()
{
// create the file watcher object
gFileWatcher = new FW::FileWatcher();
// add a watch to the system
gWatchID = gFileWatcher->addWatch("..\\media", new TextureReloader());
}

~FWTestApplication()
{
// file watcher releases all watches on cleanup
delete gFileWatcher;
gFileWatcher = 0;
}

protected:
void createScene(void)
{
//Some normal stuff.
mSceneMgr->setAmbientLight(ColourValue(0.7,0.7,0.7));
mCamera->setPosition(Vector3(0,0,100));
mCamera->lookAt(Vector3::ZERO);
mCamera->setNearClipDistance(0.05);
mCamera->setFarClipDistance(300);
LogManager::getSingleton().setLogDetail(LL_BOREME);

//----------------------------------------------------------
// Ninja!
//----------------------------------------------------------

Vector3 pos = Vector3(0,0,0);
Quaternion rot = Quaternion::IDENTITY;

//Create Ogre stuff.
mNinjaEntity = mSceneMgr->createEntity("ogrehead", "ogrehead.mesh");
mNinjaNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("ogrehead", pos, rot);
mNinjaNode->attachObject(mNinjaEntity);
mNinjaNode->translate(0,0,0);
mNinjaNode->setScale(0.5,0.5,0.5);
}

void createFrameListener(void)
{
mFrameListener = new FWTestFrameListener(mWindow, mCamera, mSceneMgr);
mRoot->addFrameListener(mFrameListener);
}
};//class FWTestApplication



#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
// Create application object
FWTestApplication app;

try
{
app.go();
}
catch( Exception& e )
{
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.what(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
fprintf(stderr, "An exception has occurred: %s\n",
e.what());
#endif
}

return 0;
}

0 comments on commit ae55776

Please sign in to comment.