Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: NoesisManager.h
- * Author: TheSHEEEP
- *
- * Created on 6. August 2013, 16:02
- */
- #ifndef NOESISMANAGER_H
- #define NOESISMANAGER_H
- #include <oolua.h>
- #include <OgreRenderQueueListener.h>
- #include <OgreRenderSystem.h>
- #include <OIS.h>
- #include <NsGui/IRenderer.h>
- #include <NsGui/FrameworkElement.h>
- namespace Ogre
- {
- class SceneManager;
- class Root;
- }
- namespace Noesis
- {
- namespace Gui
- {
- class OgreNsGuiFileSystem;
- }
- }
- class MemoryLog;
- class MouseCursor;
- class DynamicCallbackRegistry;
- class NoesisManager
- : public Ogre::RenderQueueListener
- , public Ogre::RenderSystem::Listener
- , public OIS::MouseListener
- {
- public:
- /**
- * Constructor.
- */
- NoesisManager();
- /**
- * Destructor.
- */
- virtual ~NoesisManager();
- /**
- * Will initialize the Noesis GUI manager, initializing NoesisGUI, logging, etc.
- * @param p_sceneMgr The Ogre SceneManager to use.
- * @param p_root The Ogre root.
- * @param p_logger The logger which will be used to log errors.
- * @param p_mouse The OIS Mouse.
- * @param p_width The width of the screen. In pixels.
- * @param p_height The height of the screen. In pixels.
- * @return True if the setup succeeded.
- */
- bool setup(Ogre::SceneManager* p_sceneMgr, Ogre::Root* p_root, MemoryLog* p_logger, OIS::Mouse* p_mouse, int p_width, int p_height);
- /**
- * Will shutdown the Noesis GUI.
- */
- void shutdown(void);
- /**
- * Will update the mouse position.
- * @param p_mouseEvent The event that is passed when the mouse was moved.
- * @return Should return true, I guess.
- */
- virtual bool mouseMoved(const OIS::MouseEvent& p_mouseEvent);
- /**
- * Will notify the UI of a pressed mouse button.
- * @param p_mouseEvent The event that is passed when a mouse button was pressed.
- * @param p_id The ID of the mouse button.
- * @return Should return true, I guess.
- */
- virtual bool mousePressed(const OIS::MouseEvent& p_mouseEvent, OIS::MouseButtonID p_id);
- /**
- * Will notify the UI of a released mouse button.
- * @param p_mouseEvent The event that is passed when a mouse button was released.
- * @param p_id The ID of the mouse button.
- * @return Should return true, I guess.
- */
- virtual bool mouseReleased(const OIS::MouseEvent& p_mouseEvent, OIS::MouseButtonID p_id);
- /**
- * This will render the Noesis UI content onto the screen.
- * @param p_queueGroupId The ID of the current queue group. We only render if it's RENDER_QUEUE_OVERLAY.
- * @param p_invocation ??
- * @param p_skipThisInvocation ??
- */
- void renderQueueStarted(Ogre::uint8 p_queueGroupId, const Ogre::String& p_invocation, bool& p_skipThisInvocation);
- /**
- * Called by Ogre when an event occurred.
- * @param p_eventName The name of the event. We will listen for DeviceLost and DeviceRestored.
- * @param p_parameters The parameters belonging to the event.
- */
- void eventOccurred(const Ogre::String& p_eventName, const Ogre::NameValuePairList* p_parameters);
- /**
- * This function must be called each frame before the 3D scene is rendered.
- * @param p_timeSinceLastFrame The time since the last frame, in seconds.
- */
- void doPreSceneStep(const double& p_timeSinceLastFrame);
- /**
- * This function must be called each frame after the 3D scene was rendered.
- */
- void doPostSceneStep();
- /**
- * Will bind a lua function to a Gui button with the passed name.
- * @param p_buttonName The name of the button to attach to.
- * @param p_luaFunc The lua function to bind.
- */
- void bindFunctionToButtonClick(std::string p_buttonName, OOLUA::Lua_func_ref p_luaFunc);
- /**
- * Updates the Ui depending on the jump status.
- */
- void setJumping(bool p_isJumping);
- private:
- static MemoryLog* _logger;
- /**
- * This function will be called by Noesis when an error occurs.
- * @param p_filename The name of the file where the error occurred.
- * @param p_line The line in the file where the error occured.
- * @param p_desc The description of the error (by Noesis).
- */
- static void handleNoesisError(const NsChar* p_filename, NsInt p_line, const NsChar* p_desc);
- private:
- Ogre::SceneManager* _sceneMgr;
- Ogre::Root* _root;
- OIS::Mouse* _mouse;
- MouseCursor* _mouseCursor;
- int _width;
- int _height;
- Noesis::Gui::OgreNsGuiFileSystem* _ogreFileSystem;
- Noesis::Core::Ptr<Noesis::Gui::IRenderer> _noesisGLRenderer;
- Noesis::Ptr<Noesis::Gui::FrameworkElement> _xamlRoot;
- Noesis::Gui::RenderCommands _renderCommands;
- DynamicCallbackRegistry* _callbackRegistry;
- /**
- * Handles a button click.
- * @param p_baseComp The component that caused the event.
- * @param p_args ???
- */
- void handleButtonClick(Noesis::Core::BaseComponent* p_baseComp, const Noesis::Gui::RoutedEventArgs& p_args);
- /**
- * Will tell Noesis that the device was lost.
- */
- void deviceLostCallback();
- /**
- * Will tell Noesis that the device was recovered.
- */
- void deviceResetCallback();
- private:
- struct RenderStatesStorage
- {
- bool hasState = false;
- int frameBuffer;
- float clearColors[4];
- float clearDepth;
- int clearStencil;
- unsigned char depthTest;
- unsigned char depthWrite;
- int depthFunc;
- unsigned char stencilTest;
- int stencilTestFailOp;
- int stencilTestSPDF;
- int stencilTestSPDP;
- int stencilFunc;
- int stencilRef;
- unsigned int stencilMask;
- unsigned int stencilWriteMask;
- unsigned char scissorTest;
- unsigned char cullFaceEnabled;
- int cullFaceMode;
- unsigned char blendEnabled;
- int blendEquationRGB;
- int blendEquationA;
- int blendSource;
- int blendDestination;
- unsigned char colorWriteMask[4];
- unsigned int arrayBuffer;
- unsigned int maxVertexAttribs;
- int vertexAttribsEnabled[32];
- int activeTexture;
- unsigned int elementArrayBuffer;
- unsigned int maxTextureUnits;
- int boundTexture[16];
- int currentProgram;
- int unpackAlignment;
- };
- RenderStatesStorage _rsStorage;
- /**
- * Will store the current render states.
- */
- void storeCurrentRenderStates();
- /**
- * Will restore the previously saved render states.
- */
- void restoreRenderStates();
- /**
- * Initializes all OpenGL function pointers.
- */
- void setupOpenGLFuncs();
- };
- OOLUA_PROXY_CLASS(NoesisManager)
- OOLUA_NO_TYPEDEFS
- OOLUA_ONLY_DEFAULT_CONSTRUCTOR
- OOLUA_MEM_FUNC(void, bindFunctionToButtonClick, std::string, OOLUA::Lua_func_ref)
- OOLUA_MEM_FUNC(void, setJumping, bool)
- OOLUA_CLASS_END
- #endif /* NOESISMANAGER_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement