diff --git a/.gitignore b/.gitignore index ec1bceda4..fa8b2285c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ CMakeCache.txt Makefile cmake*.cmake openmw +Ogre.log +ogre.cfg diff --git a/CMakeLists.txt b/CMakeLists.txt index 77d18f210..7fef2633a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,9 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/) # Local files set(BSA bsa/bsa_archive.cpp bsa/bsa_file.cpp) set(NIF nif/nif_file.cpp nifogre/ogre_nif_loader.cpp) -set(TOOLS tools/stringops.cpp) +set(TOOLS tools/stringops.cpp tools/fileops.cpp) set(MANGLE_VFS mangle/vfs/servers/ogre_vfs.cpp) +set(OGRE ogre/renderer.cpp) set(GAME game/main.cpp game/esm_store/store.cpp game/cell_store.cpp) # Platform specific @@ -26,5 +27,5 @@ include_directories("." ${OGRE_INCLUDE_DIR} ${PLATFORM_INCLUDE_DIR}) link_directories(${OGRE_LIB_DIR}) # Main executable -add_executable(openmw ${BSA} ${TOOLS} ${GAME}) +add_executable(openmw ${BSA} ${TOOLS} ${OGRE} ${GAME}) target_link_libraries(openmw ${OGRE_LIBRARIES}) diff --git a/game/main.cpp b/game/main.cpp index 5ee258664..97048e372 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -3,41 +3,30 @@ #include "cell_store.hpp" #include "render/cell.hpp" #include "bsa/bsa_archive.hpp" -#include +#include "ogre/renderer.hpp" +#include "tools/fileops.hpp" using namespace std; -// Absolute minimal OGRE setup -void ogre_setup() +void maintest() { - using namespace Ogre; + const char* esmFile = "data/Morrowind.esm"; + const char* bsaFile = "data/Morrowind.bsa"; - // Disable Ogre logging - new LogManager; - Log *log = LogManager::getSingleton().createLog(""); - log->setDebugOutputEnabled(false); +#ifdef _WIN32 + const char* plugCfg = "plugins.cfg.win32"; +#else + const char* plugCfg = "plugins.cfg.linux"; +#endif - // Set up Root. - new Root(); -} - -void main_setup(const char* bsaFile) -{ cout << "Hello, fellow traveler!\n"; cout << "Initializing OGRE\n"; - ogre_setup(); + Render::OgreRenderer ogre; + ogre.configure(!isFile("ogre.cfg"), plugCfg, false); cout << "Adding " << bsaFile << endl; addBSA(bsaFile); -} - -void maintest() -{ - const char* esmFile = "data/Morrowind.esm"; - const char* bsaFile = "data/Morrowind.bsa"; - - main_setup(bsaFile); cout << "Loading ESM " << esmFile << "\n"; ESM::ESMReader esm; @@ -49,6 +38,8 @@ void maintest() store.load(esm); cell.loadInt("Beshara", store, esm); + ogre.createWindow("OpenMW"); + cout << "\nThat's all for now!\n"; } diff --git a/ogre/renderer.cpp b/ogre/renderer.cpp index b231c46eb..d43109ff2 100644 --- a/ogre/renderer.cpp +++ b/ogre/renderer.cpp @@ -1,10 +1,18 @@ -#include "render.hpp" +#include "renderer.hpp" using namespace Ogre; +using namespace Render; + +void OgreRenderer::cleanup() +{ + if(mRoot) + delete mRoot; + mRoot = NULL; +} bool OgreRenderer::configure(bool showConfig, const std::string &pluginCfg, - bool _logging); + bool _logging) { // Set up logging first new LogManager; @@ -18,7 +26,7 @@ bool OgreRenderer::configure(bool showConfig, // Disable logging log->setDebugOutputEnabled(false); - mRoot = new Root(plugincfg, "ogre.cfg", ""); + mRoot = new Root(pluginCfg, "ogre.cfg", ""); // Show the configuration dialog and initialise the system, if the // showConfig parameter is specified. The settings are stored in @@ -32,3 +40,9 @@ bool OgreRenderer::configure(bool showConfig, return !result; } + +void OgreRenderer::createWindow(const std::string &title) +{ + // Initialize OGRE window + mWindow = mRoot->initialise(true, title, ""); +} diff --git a/ogre/renderer.hpp b/ogre/renderer.hpp index ab1654107..11eae2576 100644 --- a/ogre/renderer.hpp +++ b/ogre/renderer.hpp @@ -13,21 +13,28 @@ namespace Render class OgreRenderer { Ogre::Root *mRoot; + Ogre::RenderWindow *mWindow; bool logging; public: OgreRenderer() : mRoot(NULL) {} + ~OgreRenderer() { cleanup(); } /** Configure the renderer. This will load configuration files and set up the Root and logging classes. */ - bool configure(bool showConfig, // Show config dialog box? const std::string &pluginCfg, // plugin.cfg file bool _logging); // Enable or disable logging + /// Create a window with the given title + void createWindow(const std::string &title); + /// Kill the renderer. void cleanup(); + + Ogre::Root *getRoot() { return mRoot; } + Ogre::RenderWindow *getWindow() { return mWindow; } }; } diff --git a/old_d_version/ogre/cpp_interface.cpp b/old_d_version/ogre/cpp_interface.cpp index 5805b8736..b82f2277a 100644 --- a/old_d_version/ogre/cpp_interface.cpp +++ b/old_d_version/ogre/cpp_interface.cpp @@ -56,50 +56,7 @@ extern "C" void ogre_cleanup() mInputManager->destroyInputObject(mMouse); OIS::InputManager::destroyInputSystem(mInputManager); - // Kill OGRE - if (mRoot) - { - delete mRoot; - mRoot = 0; - } -} - -extern "C" int32_t ogre_configure( - int32_t showConfig, // Do we show the config dialogue? - char *plugincfg, // Name of 'plugin.cfg' file - int32_t debugOut) // Enable or disable logging -{ - // Set up logging first - new LogManager; - Log *log = LogManager::getSingleton().createLog("Ogre.log"); - - g_isDebug = debugOut; - if(debugOut) - // Full log detail - log->setLogDetail(LL_BOREME); - else - // Disable logging - log->setDebugOutputEnabled(false); - - mRoot = new Root(plugincfg, "ogre.cfg", ""); - - // Add the BSA archive manager - ArchiveManager::getSingleton().addArchiveFactory( &mBSAFactory ); - - ResourceGroupManager::getSingleton(). - addResourceLocation("internal", "BSA", "General"); - - // Show the configuration dialog and initialise the system, if the - // showConfig parameter is specified. The settings are stored in - // ogre.cfg. If showConfig is false, the settings are assumed to - // already exist in ogre.cfg. - int result; - if(showConfig) - result = mRoot->showConfigDialog(); - else - result = mRoot->restoreConfig(); - - return !result; + // Code killing ogre has been ported already } // Initialize window. This will create and show the actual window. diff --git a/old_d_version/plugins.cfg.linux b/plugins.cfg.linux similarity index 100% rename from old_d_version/plugins.cfg.linux rename to plugins.cfg.linux diff --git a/old_d_version/plugins.cfg.win32 b/plugins.cfg.win32 old mode 100755 new mode 100644 similarity index 100% rename from old_d_version/plugins.cfg.win32 rename to plugins.cfg.win32 diff --git a/tools/fileops.cpp b/tools/fileops.cpp new file mode 100644 index 000000000..10436e719 --- /dev/null +++ b/tools/fileops.cpp @@ -0,0 +1,32 @@ +#include "fileops.hpp" + +// Windows-specific implementation (NOT TESTED) +#ifdef _WIN32 + +#include + +bool isFile(const char *name) +{ + unsigned int stat = GetFileAttributes(name); + return (stat != 0xFFFFFFFF && + (stat & FILE_ATTRIBUTE_DIRECTORY) == 0); +} +#endif // _WIN32 + +// Linux implementations +#ifdef __linux__ + +#include +#include + +bool isFile(const char *name) +{ + // Does the file exist? + if(access(name,0) != 0) + return false; + + struct stat st; + if(stat(name, &st)) return false; + return S_ISREG(st.st_mode); +} +#endif // __linux__ diff --git a/tools/fileops.hpp b/tools/fileops.hpp new file mode 100644 index 000000000..6a5ad7c61 --- /dev/null +++ b/tools/fileops.hpp @@ -0,0 +1,7 @@ +#ifndef __FILEOPS_H_ +#define __FILEOPS_H_ + +/// Check if a given path is an existing file (not a directory) +bool isFile(const char *name); + +#endif