Skip to content

Commit

Permalink
Merge branch 'ockonal'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven-Hendrik Haase committed Mar 31, 2010
2 parents bc217f8 + 07c68cb commit 51e9054
Show file tree
Hide file tree
Showing 131 changed files with 12,544 additions and 1,455 deletions.
4 changes: 2 additions & 2 deletions src/action_binder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008-2009 Agop 'nullsquared' Shirinian and Sven-Hendrik 'Svenstaro' Haase
* Copyright (c) 2008-2010 Agop 'nullsquared' Shirinian and Sven-Hendrik 'Svenstaro' Haase
* This file is part of Pseudoform (Pseudoform project at http://www.pseudoform.org).
* For conditions of distribution and use, see copyright notice in COPYING
*/
Expand All @@ -19,7 +19,7 @@ namespace engine
if (r)
(*r)(misc);
else
log("invalid go() action: " + str);
log("Invalid go() action: " + str);
}

void actionBinder::bind(const string &str, const response &r)
Expand Down
80 changes: 63 additions & 17 deletions src/action_binder.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008-2009 Agop 'nullsquared' Shirinian and Sven-Hendrik 'Svenstaro' Haase
* Copyright (c) 2008-2010 Agop 'nullsquared' Shirinian and Sven-Hendrik 'Svenstaro' Haase
* This file is part of Pseudoform (Pseudoform project at http://www.pseudoform.org).
* For conditions of distribution and use, see copyright notice in COPYING
*/
Expand All @@ -17,38 +17,48 @@
#include "string.hpp"
#include "log.hpp"

/**
* @namespace engine
* @brief Consist of functions related to the game-engine
*/
namespace engine
{

namespace input
{
class input;
}

/// Action responce
typedef boost::function<void(const boost::any&)> response;
/// Response map
typedef std::map<string, response> responseMap;
/// Action map
typedef std::map<unsigned, response> actionMap;

/*
the logic for this class is a bit confusing...
what actually ends up happening is this:
1) _responses is filled with function bindings
2) _pressed, _released, or _held are filled with
lua-based bindings that in-turn call go() with
the appropriate action
*/

/**
* @class actionBinder
* @brief Connects actions with callback-functions(responses)
*
* The logic for this class is a bit confusing.
* What actually ends up happening is this:
* 1) _responses is filled with function bindings
* 2) _pressed, _released, or _held are filled with
* lua-based bindings that in-turn call go() with
* the appropriate action
*/
class actionBinder
{
protected:

/// Map for different kind of actions
actionMap _pressed, _released, _held;

/// Responses for the created actions
responseMap _responses;

/**
* @brief Get response for action
* @name str action name
*/
boost::optional<response> _response(const string &str) const
{
responseMap::const_iterator i = _responses.find(str);
Expand All @@ -58,25 +68,61 @@ namespace engine
}

public:

/**
* @brief Get response
* @param str action name
*/
void go(const string &str, const boost::any &misc);

/**
* @brief Bind press action at number `i` to the given response
* @param i action index
* @param r response to bind
*/
void bindPressed(unsigned i, const response &r) { _pressed[i] = r; }

/**
* @brief Bind release action at number `i` to the given response
* @param i action index
* @param r response to bind
*/
void bindReleased(unsigned i, const response &r) { _released[i] = r; }

/**
* @brief Bind held action at number `i` to the given response
* @param i action index
* @param r response to bind
*/
void bindHeld(unsigned i, const response &r) { _held[i] = r; }

/**
* Bind some action due to this:
* str[0] =
* '+' pressed
* '-' released
* otherwise held
* @param str action identifier
* @param r response for given action
*/
void bind(const string &str, const response &r);

/**
* @brief Unbind all actions
*/
void unbindAll();

// TODO: cooment updateHeld/Pressed/Released
void updateHeld(const input::input &in);
void updatePressed(unsigned c);
void updateReleased(unsigned c);

/**
* Destructor
*/
virtual ~actionBinder()
{
}
};

}

#endif // ACTION_BINDER_HPP_INCLUDED
31 changes: 17 additions & 14 deletions src/app_base.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008-2009 Agop 'nullsquared' Shirinian and Sven-Hendrik 'Svenstaro' Haase
* Copyright (c) 2008-2010 Agop 'nullsquared' Shirinian and Sven-Hendrik 'Svenstaro' Haase
* This file is part of Pseudoform (Pseudoform project at http://www.pseudoform.org).
* For conditions of distribution and use, see copyright notice in COPYING
*/
Expand All @@ -22,27 +22,30 @@ int appBase::run(int argc, char **argv)
using namespace engine;

engine::programOptions opts;
for (int i = 1; i < argc; ++i) // skip the first one (executable name)
for (int i = 1; i < argc; ++i) // Skip the first one (executable name)
opts.push_back(engine::string(argv[i]));

// load DATA_DIR and ROOT_DIR
// Load DATA_DIR and ROOT_DIR
configureDirs();

// we need to make sure that we have some settings to load
// We need to make sure that we have some settings to load
// TODO: Do something with default bindings. Maybe will need in chaiscript something like this
//copyFile(DATA_DIR + "scripts/bind_default.lua", DATA_DIR + "scripts/bind.lua");
copyFile(DATA_DIR + "scripts/root_default.xml", DATA_DIR + "scripts/root.xml");

// Create render application object
gfx::rootPtr root;
try
{
root.reset(new gfx::root(DATA_DIR + "scripts/root.xml", &opts));
}
catch(const std::exception &e)
{
std::cerr << "root error: " << e.what();
std::cerr << "Root error: " << e.what();
return 0xf33df00d;
}

// Create and manage input system
input::input input(root->hwnd());
input.mouseSens = 0.25;
input.resize(root->width(), root->height());
Expand All @@ -53,32 +56,32 @@ int appBase::run(int argc, char **argv)

configure(*root, input, soundSys, stateMgr, &opts);

// game loop
// Game loop
while(root->windowIsOpen())
{
// prepare window
// Prepare window
root->begin();
// capture input
// Capture input
input();

// root->begin() and input() can result in a closed window
// don't render if the window closed!
// Don't render if the window closed!
if (!root->windowIsOpen())
break;

soundSys.tick();

// tick states
// Tick states
if (!stateMgr.tick())
break;
// render states

// Render states
stateMgr.render();

// end window rendering
// Finish window rendering
root->end();

// we don't really need to time this since
// the screen shot will take at least 250 ms
// We don't need to time this since the screenshot will take at least 250 ms
if (input.keys()->isKeyDown(OIS::KC_SYSRQ))
root->screenShot();
}
Expand Down
135 changes: 95 additions & 40 deletions src/app_base.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008-2009 Agop 'nullsquared' Shirinian and Sven-Hendrik 'Svenstaro' Haase
* Copyright (c) 2008-2010 Agop 'nullsquared' Shirinian and Sven-Hendrik 'Svenstaro' Haase
* This file is part of Pseudoform (Pseudoform project at http://www.pseudoform.org).
* For conditions of distribution and use, see copyright notice in COPYING
*/
Expand All @@ -11,56 +11,111 @@

#include "types.hpp"

/**
* @namespace engine
* @brief Consist of functions related to the game-engine
*/
namespace engine
{
namespace gfx
{
class root;
}

namespace input
{
class input;
}

namespace snd
{
class system;
}
/**
* @namespace gfx
* @brief Consist of 3d render tools
*/
namespace gfx
{
/**
* @class root
* @brief Main render class, manages all Ogre stuff
*/
class root;
}

/**
* @namespace input
* @brief Consist of tools for crossing input devices
*/
namespace input
{
/**
* @class input
* @brief Manages input system
*/
class input;
}

/**
* @namespace snd
* @brief Consist of tools for playing sounds in game world
*/
namespace snd
{
/**
* @class system
* @brief Manages sound system
*/
class system;
}
}

/**
* @namespace game
* @brief Consist of tools for building game world
*/
namespace game
{
class stateManager;
/**
* @class stateManager
* @brief Manages switching between game states
* @see class state
*/
class stateManager;
}

/**
* @class appBase
* @brief Main application
*/
class appBase
{

protected:

virtual void configure(
engine::gfx::root &root,
engine::input::input &input,
engine::snd::system &soundSys,
game::stateManager &stateMgr,
engine::programOptions *opts) = 0;

public:

appBase()
{
}

virtual ~appBase()
{
}

int run(int argc, char **argv);

protected:
/**
* @brief Configure application object
*
* @param root render class
* @param input input class
* @param soundSys sound system handler
* @param stateMgr state manager handler
* @param opts program argument options
*/
virtual void configure(
engine::gfx::root &root,
engine::input::input &input,
engine::snd::system &soundSys,
game::stateManager &stateMgr,
engine::programOptions *opts) = 0;

public:
/**
* Constructor
*/
appBase() { }

/**
* Destructor
*/
virtual ~appBase() { }

/**
* @brief Begin to receive window events
* @param argc number of given arguments
* @param argv pointer to the arguments array
*/
int run(int argc, char **argv);
};

/**
* Shared pointer to the current class
*/
typedef boost::shared_ptr<appBase> appBasePtr;



#endif // APP_BASE_HPP_INCLUDED
Loading

0 comments on commit 51e9054

Please sign in to comment.