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
cmake*.cmake
openmw
Ogre.log
ogre.cfg

@ -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})

@ -3,41 +3,30 @@
#include "cell_store.hpp"
#include "render/cell.hpp"
#include "bsa/bsa_archive.hpp"
#include <Ogre.h>
#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";
}

@ -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, "");
}

@ -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; }
};
}

@ -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.

@ -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