Set up OGRE window and config reading

actorid
Nicolay Korslund 15 years ago
parent dc2c9f06d0
commit 2d3a56a464

2
.gitignore vendored

@ -6,3 +6,5 @@ CMakeCache.txt
Makefile Makefile
cmake*.cmake cmake*.cmake
openmw openmw
Ogre.log
ogre.cfg

@ -9,8 +9,9 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/)
# Local files # Local files
set(BSA bsa/bsa_archive.cpp bsa/bsa_file.cpp) set(BSA bsa/bsa_archive.cpp bsa/bsa_file.cpp)
set(NIF nif/nif_file.cpp nifogre/ogre_nif_loader.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(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) set(GAME game/main.cpp game/esm_store/store.cpp game/cell_store.cpp)
# Platform specific # Platform specific
@ -26,5 +27,5 @@ include_directories("." ${OGRE_INCLUDE_DIR} ${PLATFORM_INCLUDE_DIR})
link_directories(${OGRE_LIB_DIR}) link_directories(${OGRE_LIB_DIR})
# Main executable # Main executable
add_executable(openmw ${BSA} ${TOOLS} ${GAME}) add_executable(openmw ${BSA} ${TOOLS} ${OGRE} ${GAME})
target_link_libraries(openmw ${OGRE_LIBRARIES}) target_link_libraries(openmw ${OGRE_LIBRARIES})

@ -3,41 +3,30 @@
#include "cell_store.hpp" #include "cell_store.hpp"
#include "render/cell.hpp" #include "render/cell.hpp"
#include "bsa/bsa_archive.hpp" #include "bsa/bsa_archive.hpp"
#include <Ogre.h> #include "ogre/renderer.hpp"
#include "tools/fileops.hpp"
using namespace std; using namespace std;
// Absolute minimal OGRE setup void maintest()
void ogre_setup()
{ {
using namespace Ogre; const char* esmFile = "data/Morrowind.esm";
const char* bsaFile = "data/Morrowind.bsa";
// Disable Ogre logging #ifdef _WIN32
new LogManager; const char* plugCfg = "plugins.cfg.win32";
Log *log = LogManager::getSingleton().createLog(""); #else
log->setDebugOutputEnabled(false); const char* plugCfg = "plugins.cfg.linux";
#endif
// Set up Root.
new Root();
}
void main_setup(const char* bsaFile)
{
cout << "Hello, fellow traveler!\n"; cout << "Hello, fellow traveler!\n";
cout << "Initializing OGRE\n"; cout << "Initializing OGRE\n";
ogre_setup(); Render::OgreRenderer ogre;
ogre.configure(!isFile("ogre.cfg"), plugCfg, false);
cout << "Adding " << bsaFile << endl; cout << "Adding " << bsaFile << endl;
addBSA(bsaFile); addBSA(bsaFile);
}
void maintest()
{
const char* esmFile = "data/Morrowind.esm";
const char* bsaFile = "data/Morrowind.bsa";
main_setup(bsaFile);
cout << "Loading ESM " << esmFile << "\n"; cout << "Loading ESM " << esmFile << "\n";
ESM::ESMReader esm; ESM::ESMReader esm;
@ -49,6 +38,8 @@ void maintest()
store.load(esm); store.load(esm);
cell.loadInt("Beshara", store, esm); cell.loadInt("Beshara", store, esm);
ogre.createWindow("OpenMW");
cout << "\nThat's all for now!\n"; cout << "\nThat's all for now!\n";
} }

@ -1,10 +1,18 @@
#include "render.hpp" #include "renderer.hpp"
using namespace Ogre; using namespace Ogre;
using namespace Render;
void OgreRenderer::cleanup()
{
if(mRoot)
delete mRoot;
mRoot = NULL;
}
bool OgreRenderer::configure(bool showConfig, bool OgreRenderer::configure(bool showConfig,
const std::string &pluginCfg, const std::string &pluginCfg,
bool _logging); bool _logging)
{ {
// Set up logging first // Set up logging first
new LogManager; new LogManager;
@ -18,7 +26,7 @@ bool OgreRenderer::configure(bool showConfig,
// Disable logging // Disable logging
log->setDebugOutputEnabled(false); 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 // Show the configuration dialog and initialise the system, if the
// showConfig parameter is specified. The settings are stored in // showConfig parameter is specified. The settings are stored in
@ -32,3 +40,9 @@ bool OgreRenderer::configure(bool showConfig,
return !result; return !result;
} }
void OgreRenderer::createWindow(const std::string &title)
{
// Initialize OGRE window
mWindow = mRoot->initialise(true, title, "");
}

@ -13,21 +13,28 @@ namespace Render
class OgreRenderer class OgreRenderer
{ {
Ogre::Root *mRoot; Ogre::Root *mRoot;
Ogre::RenderWindow *mWindow;
bool logging; bool logging;
public: public:
OgreRenderer() OgreRenderer()
: mRoot(NULL) {} : mRoot(NULL) {}
~OgreRenderer() { cleanup(); }
/** Configure the renderer. This will load configuration files and /** Configure the renderer. This will load configuration files and
set up the Root and logging classes. */ set up the Root and logging classes. */
bool configure(bool showConfig, // Show config dialog box? bool configure(bool showConfig, // Show config dialog box?
const std::string &pluginCfg, // plugin.cfg file const std::string &pluginCfg, // plugin.cfg file
bool _logging); // Enable or disable logging bool _logging); // Enable or disable logging
/// Create a window with the given title
void createWindow(const std::string &title);
/// Kill the renderer. /// Kill the renderer.
void cleanup(); void cleanup();
Ogre::Root *getRoot() { return mRoot; }
Ogre::RenderWindow *getWindow() { return mWindow; }
}; };
} }

@ -56,50 +56,7 @@ extern "C" void ogre_cleanup()
mInputManager->destroyInputObject(mMouse); mInputManager->destroyInputObject(mMouse);
OIS::InputManager::destroyInputSystem(mInputManager); OIS::InputManager::destroyInputSystem(mInputManager);
// Kill OGRE // Code killing ogre has been ported already
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;
} }
// Initialize window. This will create and show the actual window. // Initialize window. This will create and show the actual window.

@ -0,0 +1,32 @@
#include "fileops.hpp"
// Windows-specific implementation (NOT TESTED)
#ifdef _WIN32
#include <windows.h>
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 <sys/stat.h>
#include <unistd.h>
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__

@ -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
Loading…
Cancel
Save