forked from mirror/openmw-tes3mp
Integrated OpenEngine, replaces entire components/engine/ directory.
parent
186bf8c1a1
commit
13d3f9c87e
@ -1,118 +0,0 @@
|
||||
#ifndef ENGINE_MYGUI_LAYOUT_H
|
||||
#define ENGINE_MYGUI_LAYOUT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <MyGUI.h>
|
||||
|
||||
namespace GUI
|
||||
{
|
||||
/** The Layout class is an utility class used to load MyGUI layouts
|
||||
from xml files, and to manipulate member widgets.
|
||||
*/
|
||||
class Layout
|
||||
{
|
||||
public:
|
||||
Layout(const std::string & _layout, MyGUI::WidgetPtr _parent = nullptr)
|
||||
: mMainWidget(nullptr)
|
||||
{ initialise(_layout, _parent); }
|
||||
virtual ~Layout() { shutdown(); }
|
||||
|
||||
template <typename T>
|
||||
void getWidget(T * & _widget, const std::string & _name, bool _throw = true)
|
||||
{
|
||||
_widget = nullptr;
|
||||
for (MyGUI::VectorWidgetPtr::iterator iter=mListWindowRoot.begin();
|
||||
iter!=mListWindowRoot.end(); ++iter)
|
||||
{
|
||||
MyGUI::WidgetPtr find = (*iter)->findWidget(mPrefix + _name);
|
||||
if (nullptr != find)
|
||||
{
|
||||
T * cast = find->castType<T>(false);
|
||||
if (nullptr != cast)
|
||||
_widget = cast;
|
||||
else if (_throw)
|
||||
{
|
||||
MYGUI_EXCEPT("Error cast : dest type = '" << T::getClassTypeName()
|
||||
<< "' source name = '" << find->getName()
|
||||
<< "' source type = '" << find->getTypeName() << "' in layout '" << mLayoutName << "'");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
MYGUI_ASSERT( ! _throw, "widget name '" << _name << "' in layout '" << mLayoutName << "' not found.");
|
||||
}
|
||||
|
||||
void initialise(const std::string & _layout,
|
||||
MyGUI::WidgetPtr _parent = nullptr)
|
||||
{
|
||||
const std::string MAIN_WINDOW = "_Main";
|
||||
mLayoutName = _layout;
|
||||
|
||||
if (mLayoutName.empty())
|
||||
mMainWidget = _parent;
|
||||
else
|
||||
{
|
||||
mPrefix = MyGUI::utility::toString(this, "_");
|
||||
mListWindowRoot = MyGUI::LayoutManager::getInstance().loadLayout(mLayoutName, mPrefix, _parent);
|
||||
|
||||
const std::string main_name = mPrefix + MAIN_WINDOW;
|
||||
for (MyGUI::VectorWidgetPtr::iterator iter=mListWindowRoot.begin(); iter!=mListWindowRoot.end(); ++iter)
|
||||
{
|
||||
if ((*iter)->getName() == main_name)
|
||||
{
|
||||
mMainWidget = (*iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
MYGUI_ASSERT(mMainWidget, "root widget name '" << MAIN_WINDOW << "' in layout '" << mLayoutName << "' not found.");
|
||||
}
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
MyGUI::LayoutManager::getInstance().unloadLayout(mListWindowRoot);
|
||||
mListWindowRoot.clear();
|
||||
}
|
||||
|
||||
void setCoord(int x, int y, int w, int h)
|
||||
{
|
||||
mMainWidget->setCoord(x,y,w,h);
|
||||
}
|
||||
|
||||
void setVisible(bool b)
|
||||
{
|
||||
mMainWidget->setVisible(b);
|
||||
}
|
||||
|
||||
void setText(const std::string& name, const std::string& caption)
|
||||
{
|
||||
MyGUI::WidgetPtr pt;
|
||||
getWidget(pt, name);
|
||||
pt->setCaption(caption);
|
||||
}
|
||||
|
||||
void setTextColor(const std::string& name, float r, float g, float b)
|
||||
{
|
||||
MyGUI::WidgetPtr pt;
|
||||
getWidget(pt, name);
|
||||
MyGUI::StaticText *st = dynamic_cast<MyGUI::StaticText*>(pt);
|
||||
if(st != NULL)
|
||||
st->setTextColour(MyGUI::Colour(b,g,r));
|
||||
}
|
||||
|
||||
void setImage(const std::string& name, const std::string& imgName)
|
||||
{
|
||||
MyGUI::StaticImagePtr pt;
|
||||
getWidget(pt, name);
|
||||
pt->setImageTexture(imgName);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
MyGUI::WidgetPtr mMainWidget;
|
||||
std::string mPrefix;
|
||||
std::string mLayoutName;
|
||||
MyGUI::VectorWidgetPtr mListWindowRoot;
|
||||
};
|
||||
}
|
||||
#endif
|
@ -1,43 +0,0 @@
|
||||
#include <MyGUI.h>
|
||||
#include <MyGUI_OgrePlatform.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "manager.hpp"
|
||||
|
||||
using namespace GUI;
|
||||
|
||||
void MyGUIManager::setup(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging)
|
||||
{
|
||||
assert(wnd);
|
||||
assert(mgr);
|
||||
|
||||
using namespace MyGUI;
|
||||
|
||||
// Enable/disable MyGUI logging to stdout. (Logging to MyGUI.log is
|
||||
// still enabled.) In order to do this we have to initialize the log
|
||||
// manager before the main gui system itself, otherwise the main
|
||||
// object will get the chance to spit out a few messages before we
|
||||
// can able to disable it.
|
||||
LogManager::initialise();
|
||||
LogManager::setSTDOutputEnabled(logging);
|
||||
|
||||
// Set up OGRE platform. We might make this more generic later.
|
||||
mPlatform = new OgrePlatform();
|
||||
mPlatform->initialise(wnd, mgr);
|
||||
|
||||
// Create GUI
|
||||
mGui = new Gui();
|
||||
mGui->initialise();
|
||||
}
|
||||
|
||||
void MyGUIManager::shutdown()
|
||||
{
|
||||
if(mGui) delete mGui;
|
||||
if(mPlatform)
|
||||
{
|
||||
mPlatform->shutdown();
|
||||
delete mPlatform;
|
||||
}
|
||||
mGui = NULL;
|
||||
mPlatform = NULL;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
#ifndef ENGINE_MYGUI_MANAGER_H
|
||||
#define ENGINE_MYGUI_MANAGER_H
|
||||
|
||||
namespace MyGUI
|
||||
{
|
||||
class OgrePlatform;
|
||||
class Gui;
|
||||
}
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class RenderWindow;
|
||||
class SceneManager;
|
||||
}
|
||||
|
||||
namespace GUI
|
||||
{
|
||||
class MyGUIManager
|
||||
{
|
||||
MyGUI::OgrePlatform *mPlatform;
|
||||
MyGUI::Gui *mGui;
|
||||
|
||||
public:
|
||||
MyGUIManager() : mPlatform(NULL), mGui(NULL) {}
|
||||
MyGUIManager(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging=false)
|
||||
{ setup(wnd,mgr,logging); }
|
||||
~MyGUIManager() { shutdown(); }
|
||||
|
||||
void setup(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging=false);
|
||||
void shutdown();
|
||||
};
|
||||
}
|
||||
#endif
|
@ -1,75 +0,0 @@
|
||||
#ifndef _INPUT_DISPATCHMAP_H
|
||||
#define _INPUT_DISPATCHMAP_H
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Input {
|
||||
|
||||
/**
|
||||
DispatchMap is a simple connection system that connects incomming
|
||||
signals with outgoing signals.
|
||||
|
||||
The signals can be connected one-to-one, many-to-one, one-to-many
|
||||
or many-to-many.
|
||||
|
||||
The dispatch map is completely system agnostic. It is a pure data
|
||||
structure and all signals are just integer indices. It does not
|
||||
delegate any actions, but used together with Dispatcher it can be
|
||||
used to build an event system.
|
||||
*/
|
||||
struct DispatchMap
|
||||
{
|
||||
typedef std::set<int> OutList;
|
||||
typedef std::map<int, OutList> InMap;
|
||||
|
||||
typedef OutList::iterator Oit;
|
||||
typedef InMap::iterator Iit;
|
||||
|
||||
InMap map;
|
||||
|
||||
void bind(int in, int out)
|
||||
{
|
||||
map[in].insert(out);
|
||||
}
|
||||
|
||||
void unbind(int in, int out)
|
||||
{
|
||||
Iit it = map.find(in);
|
||||
if(it != map.end())
|
||||
{
|
||||
it->second.erase(out);
|
||||
|
||||
// If there are no more elements, then remove the entire list
|
||||
if(it->second.empty())
|
||||
map.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if a given input is bound to anything
|
||||
bool isBound(int in) const
|
||||
{
|
||||
return map.find(in) != map.end();
|
||||
}
|
||||
|
||||
/**
|
||||
Get the list of outputs bound to the given input. Only call this
|
||||
on inputs that you know are bound to something.
|
||||
|
||||
The returned set is only intended for immediate iteration. Do not
|
||||
store references to it.
|
||||
*/
|
||||
const OutList &getList(int in) const
|
||||
{
|
||||
assert(isBound(in));
|
||||
InMap::const_iterator it = map.find(in);
|
||||
assert(it != map.end());
|
||||
const OutList &out = it->second;
|
||||
assert(!out.empty());
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
@ -1,44 +0,0 @@
|
||||
#ifndef _INPUT_DISPATCHER_H
|
||||
#define _INPUT_DISPATCHER_H
|
||||
|
||||
#include "dispatch_map.hpp"
|
||||
#include "func_binder.hpp"
|
||||
|
||||
namespace Input {
|
||||
|
||||
struct Dispatcher
|
||||
{
|
||||
DispatchMap map;
|
||||
FuncBinder funcs;
|
||||
|
||||
/**
|
||||
Constructor. Takes the number of actions and passes it to
|
||||
FuncBinder.
|
||||
*/
|
||||
Dispatcher(int actions) : funcs(actions) {}
|
||||
|
||||
void bind(int in, int out) { map.bind(in, out); }
|
||||
void unbind(int in, int out) { map.unbind(in, out); }
|
||||
bool isBound(int in) const { return map.isBound(in); }
|
||||
|
||||
/**
|
||||
Instigate an event. It is translated through the dispatch map and
|
||||
sent to the function bindings.
|
||||
*/
|
||||
typedef DispatchMap::OutList _O;
|
||||
void event(int index, const void* p=NULL) const
|
||||
{
|
||||
// No bindings, nothing happens
|
||||
if(!isBound(index))
|
||||
return;
|
||||
|
||||
// Get the mapped actions and execute them
|
||||
const _O &list = map.getList(index);
|
||||
_O::const_iterator it;
|
||||
for(it = list.begin(); it != list.end(); it++)
|
||||
funcs.call(*it, p);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
@ -1,104 +0,0 @@
|
||||
#ifndef _INPUT_FUNCBINDER_H
|
||||
#define _INPUT_FUNCBINDER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <boost/function.hpp>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Input {
|
||||
|
||||
/**
|
||||
An Action defines the user defined action corresponding to a
|
||||
binding.
|
||||
|
||||
The first parameter is the action index that invoked this call. You
|
||||
can assign the same function to multiple actions, and this can help
|
||||
you keep track of which action was invoked.
|
||||
|
||||
The second parameter is an optional user-defined parameter,
|
||||
represented by a void pointer. In many cases it is practical to
|
||||
point this to temporaries (stack values), so make sure not to store
|
||||
permanent references to it unless you've planning for this on the
|
||||
calling side as well.
|
||||
*/
|
||||
typedef boost::function<void(int,const void*)> Action;
|
||||
|
||||
/**
|
||||
The FuncBinder is a simple struct that binds user-defined indices
|
||||
to functions. It is useful for binding eg. keyboard events to
|
||||
specific actions in your program, but can potentially have many
|
||||
other uses as well.
|
||||
*/
|
||||
class FuncBinder
|
||||
{
|
||||
struct FuncBinding
|
||||
{
|
||||
std::string name;
|
||||
Action action;
|
||||
};
|
||||
|
||||
std::vector<FuncBinding> bindings;
|
||||
|
||||
public:
|
||||
/**
|
||||
Constructor. Initialize the struct by telling it how many action
|
||||
indices you intend to bind.
|
||||
|
||||
The indices you use should be 0 <= i < number.
|
||||
*/
|
||||
FuncBinder(int number) : bindings(number) {}
|
||||
|
||||
/**
|
||||
Bind an action to an index.
|
||||
*/
|
||||
void bind(int index, Action action, const std::string &name="")
|
||||
{
|
||||
assert(index >= 0 && index < (int)bindings.size());
|
||||
|
||||
FuncBinding &fb = bindings[index];
|
||||
fb.action = action;
|
||||
fb.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
Unbind an index, reverting a previous bind().
|
||||
*/
|
||||
void unbind(int index)
|
||||
{
|
||||
assert(index >= 0 && index < (int)bindings.size());
|
||||
|
||||
bindings[index] = FuncBinding();
|
||||
}
|
||||
|
||||
/**
|
||||
Call a specific action. Takes an optional parameter that is
|
||||
passed to the action.
|
||||
*/
|
||||
void call(int index, const void *p=NULL) const
|
||||
{
|
||||
assert(index >= 0 && index < (int)bindings.size());
|
||||
|
||||
const FuncBinding &fb = bindings[index];
|
||||
if(fb.action) fb.action(index, p);
|
||||
}
|
||||
|
||||
/// Check if a given index is bound to anything
|
||||
bool isBound(int index) const
|
||||
{
|
||||
assert(index >= 0 && index < (int)bindings.size());
|
||||
|
||||
return !bindings[index].action.empty();
|
||||
}
|
||||
|
||||
/// Return the name associated with an action (empty if not bound)
|
||||
const std::string &getName(int index) const
|
||||
{
|
||||
assert(index >= 0 && index < (int)bindings.size());
|
||||
|
||||
return bindings[index].name;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
@ -1,113 +0,0 @@
|
||||
#ifndef _INPUT_LISTENER_H
|
||||
#define _INPUT_LISTENER_H
|
||||
|
||||
#include "oismanager.hpp"
|
||||
#include "components/engine/ogre/renderer.hpp"
|
||||
#include "dispatcher.hpp"
|
||||
|
||||
#include <OgreFrameListener.h>
|
||||
#include <OgreRenderWindow.h>
|
||||
|
||||
namespace Input
|
||||
{
|
||||
struct InputListener : Ogre::FrameListener,
|
||||
OIS::KeyListener,
|
||||
OIS::MouseListener
|
||||
{
|
||||
InputListener(Render::OgreRenderer &rend,
|
||||
Input::OISManager &input,
|
||||
const Input::Dispatcher &_disp)
|
||||
: disp(_disp), doExit(false)
|
||||
{
|
||||
// Set up component pointers
|
||||
mWindow = rend.getWindow();
|
||||
mMouse = input.mouse;
|
||||
mKeyboard = input.keyboard;
|
||||
|
||||
assert(mKeyboard);
|
||||
assert(mWindow);
|
||||
|
||||
// Add ourself to the managers
|
||||
rend.getRoot() -> addFrameListener(this);
|
||||
mKeyboard -> setEventCallback(this);
|
||||
mMouse -> setEventCallback(this);
|
||||
}
|
||||
|
||||
void setCamera(Ogre::Camera *cam) { camera = cam; }
|
||||
|
||||
// Call this to exit the main loop
|
||||
void exitNow() { doExit = true; }
|
||||
|
||||
bool frameStarted(const Ogre::FrameEvent &evt)
|
||||
{
|
||||
if(mWindow->isClosed() || doExit)
|
||||
return false;
|
||||
|
||||
// Capture keyboard and mouse events
|
||||
mKeyboard->capture();
|
||||
mMouse->capture();
|
||||
|
||||
return Ogre::FrameListener::frameStarted(evt);
|
||||
}
|
||||
|
||||
bool keyPressed( const OIS::KeyEvent &arg )
|
||||
{
|
||||
// Pass the event to the dispatcher
|
||||
disp.event(arg.key, &arg);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool keyReleased( const OIS::KeyEvent &arg )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mouseMoved( const OIS::MouseEvent &arg )
|
||||
{
|
||||
using namespace Ogre;
|
||||
assert(camera);
|
||||
|
||||
// Mouse sensitivity. Should be a config option later.
|
||||
const float MS = 0.2f;
|
||||
|
||||
float x = arg.state.X.rel * MS;
|
||||
float y = arg.state.Y.rel * MS;
|
||||
|
||||
camera->yaw(Degree(-x));
|
||||
|
||||
// The camera before pitching
|
||||
Quaternion nopitch = camera->getOrientation();
|
||||
|
||||
camera->pitch(Degree(-y));
|
||||
|
||||
// Apply some failsafe measures against the camera flipping
|
||||
// upside down. Is the camera close to pointing straight up or
|
||||
// down?
|
||||
if(camera->getUp()[1] <= 0.1)
|
||||
// If so, undo the last pitch
|
||||
camera->setOrientation(nopitch);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
const Dispatcher &disp;
|
||||
Ogre::RenderWindow *mWindow;
|
||||
Ogre::Camera *camera;
|
||||
OIS::Mouse *mMouse;
|
||||
OIS::Keyboard *mKeyboard;
|
||||
bool doExit;
|
||||
};
|
||||
}
|
||||
#endif
|
@ -1,89 +0,0 @@
|
||||
#include "oismanager.hpp"
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "OgreRenderWindow.h"
|
||||
|
||||
#ifdef __APPLE_CC__
|
||||
#include <Carbon/Carbon.h>
|
||||
#endif
|
||||
|
||||
using namespace Input;
|
||||
using namespace Ogre;
|
||||
using namespace OIS;
|
||||
|
||||
using namespace std;
|
||||
|
||||
OISManager::OISManager(Render::OgreRenderer &rend, bool debug)
|
||||
{
|
||||
RenderWindow *window = rend.getWindow();
|
||||
assert(window);
|
||||
|
||||
size_t windowHnd;
|
||||
window->getCustomAttribute("WINDOW", &windowHnd);
|
||||
|
||||
std::ostringstream windowHndStr;
|
||||
ParamList pl;
|
||||
|
||||
windowHndStr << windowHnd;
|
||||
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
|
||||
|
||||
// Non-exclusive mouse and keyboard input in debug mode. Debug mode
|
||||
// isn't implemented yet though.
|
||||
if(debug)
|
||||
{
|
||||
#if defined OIS_WIN32_PLATFORM
|
||||
pl.insert(std::make_pair(std::string("w32_mouse"),
|
||||
std::string("DISCL_FOREGROUND" )));
|
||||
pl.insert(std::make_pair(std::string("w32_mouse"),
|
||||
std::string("DISCL_NONEXCLUSIVE")));
|
||||
pl.insert(std::make_pair(std::string("w32_keyboard"),
|
||||
std::string("DISCL_FOREGROUND")));
|
||||
pl.insert(std::make_pair(std::string("w32_keyboard"),
|
||||
std::string("DISCL_NONEXCLUSIVE")));
|
||||
#elif defined OIS_LINUX_PLATFORM
|
||||
pl.insert(std::make_pair(std::string("x11_mouse_grab"),
|
||||
std::string("false")));
|
||||
pl.insert(std::make_pair(std::string("x11_mouse_hide"),
|
||||
std::string("false")));
|
||||
pl.insert(std::make_pair(std::string("x11_keyboard_grab"),
|
||||
std::string("false")));
|
||||
pl.insert(std::make_pair(std::string("XAutoRepeatOn"),
|
||||
std::string("true")));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __APPLE_CC__
|
||||
// Give the application window focus to receive input events
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
SetFrontProcess(&psn);
|
||||
#endif
|
||||
|
||||
inputMgr = InputManager::createInputSystem( pl );
|
||||
|
||||
// Create all devices
|
||||
keyboard = static_cast<Keyboard*>(inputMgr->createInputObject
|
||||
( OISKeyboard, true ));
|
||||
mouse = static_cast<Mouse*>(inputMgr->createInputObject
|
||||
( OISMouse, true ));
|
||||
|
||||
// Set mouse region
|
||||
const MouseState &ms = mouse->getMouseState();
|
||||
ms.width = window->getWidth();
|
||||
ms.height = window->getHeight();
|
||||
}
|
||||
|
||||
OISManager::~OISManager()
|
||||
{
|
||||
if(inputMgr == NULL) return;
|
||||
|
||||
// Kill the input systems. This will reset input options such as key
|
||||
// repetition.
|
||||
inputMgr->destroyInputObject(keyboard);
|
||||
inputMgr->destroyInputObject(mouse);
|
||||
InputManager::destroyInputSystem(inputMgr);
|
||||
inputMgr = NULL;
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
#ifndef _INPUT_OISMANAGER_H
|
||||
#define _INPUT_OISMANAGER_H
|
||||
|
||||
#include "components/engine/ogre/renderer.hpp"
|
||||
#include <OIS/OIS.h>
|
||||
|
||||
namespace Input
|
||||
{
|
||||
struct OISManager
|
||||
{
|
||||
OIS::InputManager *inputMgr;
|
||||
OIS::Mouse *mouse;
|
||||
OIS::Keyboard *keyboard;
|
||||
|
||||
OISManager(Render::OgreRenderer &rend, bool debug);
|
||||
~OISManager();
|
||||
};
|
||||
}
|
||||
#endif
|
@ -1,51 +0,0 @@
|
||||
#ifndef _INPUT_POLLER_H
|
||||
#define _INPUT_POLLER_H
|
||||
|
||||
#include "dispatch_map.hpp"
|
||||
#include "oismanager.hpp"
|
||||
|
||||
namespace Input {
|
||||
|
||||
/** The poller is used to check (poll) for keys rather than waiting
|
||||
for events. TODO: Might make this OIS-independent later. */
|
||||
struct Poller
|
||||
{
|
||||
DispatchMap map;
|
||||
OIS::Keyboard *keyboard;
|
||||
|
||||
Poller(Input::OISManager &ois)
|
||||
{
|
||||
keyboard = ois.keyboard;
|
||||
assert(keyboard);
|
||||
}
|
||||
|
||||
/** Bind or unbind a given action with a key. The action is the first
|
||||
parameter, the key is the second.
|
||||
*/
|
||||
void bind(int in, int out) { map.bind(in, out); }
|
||||
void unbind(int in, int out) { map.unbind(in, out); }
|
||||
bool isBound(int in) const { return map.isBound(in); }
|
||||
|
||||
/// Check whether a given action button is currently pressed.
|
||||
typedef DispatchMap::OutList _O;
|
||||
bool isDown(int index) const
|
||||
{
|
||||
assert(keyboard);
|
||||
|
||||
// No bindings, no action
|
||||
if(!isBound(index))
|
||||
return false;
|
||||
|
||||
// Get all the keys bound to this action, and check them.
|
||||
const _O &list = map.getList(index);
|
||||
_O::const_iterator it;
|
||||
for(it = list.begin(); it != list.end(); it++)
|
||||
// If there's any match, we're good to go.
|
||||
if(keyboard->isKeyDown((OIS::KeyCode)*it)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
@ -1,2 +0,0 @@
|
||||
*_test
|
||||
|
@ -1,12 +0,0 @@
|
||||
GCC=g++
|
||||
|
||||
all: funcbind_test dispatch_map_test
|
||||
|
||||
funcbind_test: funcbind_test.cpp ../func_binder.hpp
|
||||
$(GCC) $< -o $@
|
||||
|
||||
dispatch_map_test: dispatch_map_test.cpp ../dispatch_map.hpp
|
||||
$(GCC) $< -o $@
|
||||
|
||||
clean:
|
||||
rm *_test
|
@ -1,54 +0,0 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include "../dispatch_map.hpp"
|
||||
|
||||
using namespace Input;
|
||||
|
||||
typedef DispatchMap::OutList OutList;
|
||||
typedef OutList::const_iterator Cit;
|
||||
|
||||
void showList(const DispatchMap::OutList &out)
|
||||
{
|
||||
for(Cit it = out.begin();
|
||||
it != out.end(); it++)
|
||||
{
|
||||
cout << " " << *it << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void showAll(DispatchMap &map)
|
||||
{
|
||||
cout << "\nPrinting everything:\n";
|
||||
for(DispatchMap::Iit it = map.map.begin();
|
||||
it != map.map.end(); it++)
|
||||
{
|
||||
cout << it->first << ":\n";
|
||||
showList(map.getList(it->first));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
cout << "Testing the dispatch map\n";
|
||||
|
||||
DispatchMap dsp;
|
||||
|
||||
dsp.bind(1,9);
|
||||
dsp.bind(2,-5);
|
||||
dsp.bind(2,9);
|
||||
dsp.bind(3,10);
|
||||
dsp.bind(3,12);
|
||||
dsp.bind(3,10);
|
||||
|
||||
showAll(dsp);
|
||||
|
||||
dsp.unbind(1,9);
|
||||
dsp.unbind(5,8);
|
||||
dsp.unbind(3,11);
|
||||
dsp.unbind(3,12);
|
||||
dsp.unbind(3,12);
|
||||
|
||||
showAll(dsp);
|
||||
return 0;
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include "../func_binder.hpp"
|
||||
|
||||
void f1(int i, const void *p)
|
||||
{
|
||||
cout << " F1 i=" << i << endl;
|
||||
|
||||
if(p)
|
||||
cout << " Got a nice gift: "
|
||||
<< *((const float*)p) << endl;
|
||||
}
|
||||
|
||||
void f2(int i, const void *p)
|
||||
{
|
||||
cout << " F2 i=" << i << endl;
|
||||
}
|
||||
|
||||
using namespace Input;
|
||||
|
||||
int main()
|
||||
{
|
||||
cout << "This will test the function binding system\n";
|
||||
|
||||
FuncBinder bnd(5);
|
||||
|
||||
bnd.bind(0, &f1, "This is action 1");
|
||||
bnd.bind(1, &f2);
|
||||
bnd.bind(2, &f1, "This is action 3");
|
||||
bnd.bind(3, &f2, "This is action 4");
|
||||
|
||||
bnd.unbind(2);
|
||||
|
||||
for(int i=0; i<5; i++)
|
||||
{
|
||||
cout << "Calling " << i << ": '" << bnd.getName(i) << "'\n";
|
||||
bnd.call(i);
|
||||
if(!bnd.isBound(i)) cout << " (not bound)\n";
|
||||
}
|
||||
|
||||
cout << "\nCalling with parameter:\n";
|
||||
float f = 3.1415;
|
||||
bnd.call(0, &f);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
Testing the dispatch map
|
||||
|
||||
Printing everything:
|
||||
1:
|
||||
9
|
||||
2:
|
||||
-5
|
||||
9
|
||||
3:
|
||||
10
|
||||
12
|
||||
|
||||
Printing everything:
|
||||
2:
|
||||
-5
|
||||
9
|
||||
3:
|
||||
10
|
@ -1,15 +0,0 @@
|
||||
This will test the function binding system
|
||||
Calling 0: 'This is action 1'
|
||||
F1 i=0
|
||||
Calling 1: ''
|
||||
F2 i=1
|
||||
Calling 2: ''
|
||||
(not bound)
|
||||
Calling 3: 'This is action 4'
|
||||
F2 i=3
|
||||
Calling 4: ''
|
||||
(not bound)
|
||||
|
||||
Calling with parameter:
|
||||
F1 i=0
|
||||
Got a nice gift: 3.1415
|
@ -1,18 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
make || exit
|
||||
|
||||
mkdir -p output
|
||||
|
||||
PROGS=*_test
|
||||
|
||||
for a in $PROGS; do
|
||||
if [ -f "output/$a.out" ]; then
|
||||
echo "Running $a:"
|
||||
./$a | diff output/$a.out -
|
||||
else
|
||||
echo "Creating $a.out"
|
||||
./$a > "output/$a.out"
|
||||
git add "output/$a.out"
|
||||
fi
|
||||
done
|
@ -1 +0,0 @@
|
||||
old
|
@ -1,80 +0,0 @@
|
||||
#include "renderer.hpp"
|
||||
|
||||
#include "OgreRoot.h"
|
||||
#include "OgreRenderWindow.h"
|
||||
#include "OgreLogManager.h"
|
||||
#include "OgreLog.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
using namespace Ogre;
|
||||
using namespace Render;
|
||||
|
||||
void OgreRenderer::cleanup()
|
||||
{
|
||||
if(mRoot)
|
||||
delete mRoot;
|
||||
mRoot = NULL;
|
||||
}
|
||||
|
||||
void OgreRenderer::screenshot(const std::string &file)
|
||||
{
|
||||
mWindow->writeContentsToFile(file);
|
||||
}
|
||||
|
||||
bool OgreRenderer::configure(bool showConfig,
|
||||
const std::string &pluginCfg,
|
||||
bool _logging)
|
||||
{
|
||||
// Set up logging first
|
||||
new LogManager;
|
||||
Log *log = LogManager::getSingleton().createLog("Ogre.log");
|
||||
logging = _logging;
|
||||
|
||||
if(logging)
|
||||
// Full log detail
|
||||
log->setLogDetail(LL_BOREME);
|
||||
else
|
||||
// Disable logging
|
||||
log->setDebugOutputEnabled(false);
|
||||
|
||||
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
|
||||
// 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;
|
||||
}
|
||||
|
||||
void OgreRenderer::createWindow(const std::string &title)
|
||||
{
|
||||
assert(mRoot);
|
||||
// Initialize OGRE window
|
||||
mWindow = mRoot->initialise(true, title, "");
|
||||
}
|
||||
|
||||
void OgreRenderer::createScene(const std::string camName, float fov, float nearClip)
|
||||
{
|
||||
assert(mRoot);
|
||||
assert(mWindow);
|
||||
// Get the SceneManager, in this case a generic one
|
||||
mScene = mRoot->createSceneManager(ST_GENERIC);
|
||||
|
||||
// Create the camera
|
||||
mCamera = mScene->createCamera(camName);
|
||||
mCamera->setNearClipDistance(nearClip);
|
||||
mCamera->setFOVy(Degree(fov));
|
||||
|
||||
// Create one viewport, entire window
|
||||
mView = mWindow->addViewport(mCamera);
|
||||
|
||||
// Alter the camera aspect ratio to match the viewport
|
||||
mCamera->setAspectRatio(Real(mView->getActualWidth()) / Real(mView->getActualHeight()));
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
#ifndef _OGRE_RENDERER_H
|
||||
#define _OGRE_RENDERER_H
|
||||
|
||||
/*
|
||||
Ogre renderer class
|
||||
*/
|
||||
|
||||
#include <OgreRoot.h>
|
||||
#include <string>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class Root;
|
||||
class RenderWindow;
|
||||
class SceneManager;
|
||||
class Camera;
|
||||
class Viewport;
|
||||
}
|
||||
|
||||
namespace Render
|
||||
{
|
||||
class OgreRenderer
|
||||
{
|
||||
Ogre::Root *mRoot;
|
||||
Ogre::RenderWindow *mWindow;
|
||||
Ogre::SceneManager *mScene;
|
||||
Ogre::Camera *mCamera;
|
||||
Ogre::Viewport *mView;
|
||||
bool logging;
|
||||
|
||||
public:
|
||||
OgreRenderer()
|
||||
: mRoot(NULL), mWindow(NULL), mScene(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);
|
||||
|
||||
/// Set up the scene manager, camera and viewport
|
||||
void createScene(const std::string camName="Camera",// Camera name
|
||||
float fov=55, // Field of view angle
|
||||
float nearClip=5 // Near clip distance
|
||||
);
|
||||
|
||||
/// Kill the renderer.
|
||||
void cleanup();
|
||||
|
||||
/// Start the main rendering loop
|
||||
void start() { mRoot->startRendering(); }
|
||||
|
||||
/// Write a screenshot to file
|
||||
void screenshot(const std::string &file);
|
||||
|
||||
/// Get the Root
|
||||
Ogre::Root *getRoot() { return mRoot; }
|
||||
|
||||
/// Get the rendering window
|
||||
Ogre::RenderWindow *getWindow() { return mWindow; }
|
||||
|
||||
/// Get the scene manager
|
||||
Ogre::SceneManager *getScene() { return mScene; }
|
||||
|
||||
/// Camera
|
||||
Ogre::Camera *getCamera() { return mCamera; }
|
||||
|
||||
/// Viewport
|
||||
Ogre::Viewport *getViewport() { return mView; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1 +1 @@
|
||||
Subproject commit 5333b8e230e285e9183b0639188283bdbc15af6c
|
||||
Subproject commit 69a56e867749944dc0e86b9ef5c54bac4339b454
|
Loading…
Reference in New Issue