Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 29, 2009, 10:04:04 PM (15 years ago)
Author:
rgrieder
Message:

Experimental support for OGRE v1.6 "Shoggoth".
I had to write a little script that removes all the "particle_system" keywords from the particle scripts. But since we can't write to the media folder and creating unique temporary folders is quite tedious, I derived from Ogre::Archive and created a little MemoryArchive that accepts those new particle scripts and feeds them back to the Ogre::ResourceGroupManager.
Also adjusted all particle scripts for the new script compiler (i.e. just added "particle_system" everywhere).

Note: It seems that overlays don't work anymore on Windows, compiling with MinGW.

Location:
code/branches/resource2/src/core
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/resource2/src/core/CMakeLists.txt

    r5654 r5689  
    3131  Language.cc
    3232  LuaState.cc
     33  MemoryArchive.cc
    3334  ObjectListBase.cc
    3435  OrxonoxClass.cc
  • code/branches/resource2/src/core/CorePrereqs.h

    r5654 r5689  
    134134    class Loader;
    135135    class LuaState;
     136    class MemoryArchive;
     137    class MemoryArchiveFactory;
    136138    class MetaObjectList;
    137139    class MetaObjectListElement;
  • code/branches/resource2/src/core/GraphicsManager.cc

    r5682 r5689  
    2828 */
    2929
    30 /**
    31 @file
    32 @brief
    33     Implementation of an partial interface to Ogre.
    34 */
    35 
    3630#include "GraphicsManager.h"
    3731
    3832#include <fstream>
     33#include <sstream>
    3934#include <boost/filesystem.hpp>
    40 
     35#include <boost/shared_array.hpp>
     36
     37#include <OgreArchiveFactory.h>
     38#include <OgreArchiveManager.h>
    4139#include <OgreFrameListener.h>
    4240#include <OgreRoot.h>
    4341#include <OgreLogManager.h>
    44 #include <OgreException.h>
    4542#include <OgreRenderWindow.h>
    4643#include <OgreRenderSystem.h>
     
    6259#include "GameMode.h"
    6360#include "Loader.h"
     61#include "MemoryArchive.h"
    6462#include "WindowEventListener.h"
    6563#include "XMLFile.h"
     
    8886    GraphicsManager::GraphicsManager(bool bLoadRenderer)
    8987        : ogreWindowEventListener_(new OgreWindowEventListener())
     88#if OGRE_VERSION < 0x010600
     89        , memoryArchiveFactory_(new MemoryArchiveFactory())
     90#endif
    9091        , renderWindow_(0)
    9192        , viewport_(0)
     
    165166
    166167        this->loadRenderer();
     168
     169#if OGRE_VERSION < 0x010600
     170        // WORKAROUND: There is an incompatibility for particle scripts when trying
     171        // to support both Ogre 1.4 and 1.6. The hacky solution is to create
     172        // scripts for the 1.6 version and then remove the inserted "particle_system"
     173        // keyword. But we need to supply these new scripts as well, which is why
     174        // there is an extra Ogre::Archive dealing with in the memory.
     175        using namespace Ogre;
     176        ArchiveManager::getSingleton().addArchiveFactory(memoryArchiveFactory_.get());
     177        const StringVector& groups = ResourceGroupManager::getSingleton().getResourceGroups();
     178        // Travers all groups
     179        for (StringVector::const_iterator itGroup = groups.begin(); itGroup != groups.end(); ++itGroup)
     180        {
     181            FileInfoListPtr files = ResourceGroupManager::getSingleton().findResourceFileInfo(*itGroup, "*.particle");
     182            for (FileInfoList::const_iterator itFile = files->begin(); itFile != files->end(); ++itFile)
     183            {
     184                // open file
     185                Ogre::DataStreamPtr input = ResourceGroupManager::getSingleton().openResource(itFile->filename, *itGroup, false);
     186                std::stringstream output;
     187                // Parse file and replace "particle_system" with nothing
     188                while (!input->eof())
     189                {
     190                    std::string line = input->getLine();
     191                    size_t pos = line.find("particle_system");
     192                    if (pos != std::string::npos)
     193                    {
     194                        // 15 is the length of "particle_system"
     195                        line.replace(pos, 15, "");
     196                    }
     197                    output << line << std::endl;
     198                }
     199                // Add file to the memory archive
     200                shared_array<char> data(new char[output.str().size()]);
     201                // Debug optimisations
     202                const std::string outputStr = output.str();
     203                char* rawData = data.get();
     204                for (unsigned i = 0; i < outputStr.size(); ++i)
     205                    rawData[i] = outputStr[i];
     206                MemoryArchive::addFile("particle_scripts_ogre_1.4_" + *itGroup, itFile->filename, data, output.str().size());
     207            }
     208            if (!files->empty())
     209            {
     210                // Declare the files, but using a new group
     211                ResourceGroupManager::getSingleton().addResourceLocation("particle_scripts_ogre_1.4_" + *itGroup,
     212                    "Memory", "particle_scripts_ogre_1.4_" + *itGroup);
     213            }
     214        }
     215#endif
    167216
    168217        // Initialise all resources (do this AFTER the renderer has been loaded!)
  • code/branches/resource2/src/core/GraphicsManager.h

    r5670 r5689  
    9191
    9292        scoped_ptr<OgreWindowEventListener> ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h
     93#if OGRE_VERSION < 0x010600
     94        scoped_ptr<MemoryArchiveFactory>    memoryArchiveFactory_;    //!< Stores the modified particle scripts
     95#endif
    9396        scoped_ptr<Ogre::LogManager>        ogreLogger_;
    9497        scoped_ptr<Ogre::Root>              ogreRoot_;                //!< Ogre's root
Note: See TracChangeset for help on using the changeset viewer.