Skip to content

Commit

Permalink
Merge 98d05e4 into 274b45d
Browse files Browse the repository at this point in the history
  • Loading branch information
babyccino committed Dec 16, 2017
2 parents 274b45d + 98d05e4 commit 9a5cb0e
Show file tree
Hide file tree
Showing 22 changed files with 1,459 additions and 172 deletions.
14 changes: 14 additions & 0 deletions include/radix/BaseGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
#include <radix/util/sdl/Fps.hpp>
#include <radix/GameWorld.hpp>
#include <radix/Window.hpp>
#include <radix/renderer/Renderer.hpp>
#include <radix/renderer/ScreenRenderer.hpp>
#include <radix/core/event/EventDispatcher.hpp>
#include <radix/data/map/XmlMapLoader.hpp>
#include <radix/data/map/CustomTrigger.hpp>
#include <radix/data/screen/Screen.hpp>
#include <radix/renderer/ScreenRenderer.hpp>
#include <radix/env/Config.hpp>
#include <radix/input/InputManager.hpp>

namespace radix {

Expand Down Expand Up @@ -60,6 +69,10 @@ class BaseGame {
void deferPostCycle(const std::function<void()>&);

World* getWorld();
Config& getConfig();
inline InputManager& getInputManager() {
return inputManager;
}

template<class T, typename... Args>
T& createOtherWorld(const std::string &name, Args&&... args) {
Expand Down Expand Up @@ -95,6 +108,7 @@ class BaseGame {
virtual void customTriggerHook();

Window window;
InputManager inputManager;
std::map<std::string, std::unique_ptr<World>> otherWorlds;
std::unique_ptr<World> world;
Config config;
Expand Down
95 changes: 80 additions & 15 deletions include/radix/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#include <SDL2/SDL_video.h>

#include <radix/env/Config.hpp>
#include <radix/input/InputSource.hpp>
#include <radix/Viewport.hpp>
#include <radix/env/Config.hpp>
#include <radix/core/math/Vector2i.hpp>

namespace radix {
Expand Down Expand Up @@ -90,23 +90,73 @@ class Window : public Viewport, public InputSource {
* @param key input keyboard type
* @param mod input keyboard mode
*/
void keyPressed(KeyboardKey key, KeyboardModifier mod) override;
void keyPressed(const KeyboardKey &key, const KeyboardModifier &mod) override;

/**
* @brief keyReleased handle released keyboard input
* @param key input keyboard type
* @param mod input keyboard modifier
*/
void keyReleased(KeyboardKey key, KeyboardModifier mod) override;
void keyReleased(const KeyboardKey &key, const KeyboardModifier &mod) override;

/**
* @brief isKeyDown check keyboard status
* @param key input keyboard type
* @return if key is pressed
*/
bool isKeyDown(KeyboardKey key) override;
bool isKeyDown(const KeyboardKey &key) override;
/**@} */

/**
* @name controller methods
*@{ */
/**
* @brief controllerButtonPressed handle pressed controller button input
* @param button input button type
*/
void controllerButtonPressed(const ControllerButton &button, const ControllerIndex &index) override;

/**
* @brief controllerButtonPressed handle released controller button input
* @param button input button type
*/
void controllerButtonReleased(const ControllerButton &button, const ControllerIndex &index) override;

/**
* @brief controllerButtonPressed check controller button status
* @param button input button type
* @return if button is depressed
*/
bool isControllerButtonDown(const ControllerButton &button, const ControllerIndex &index) override;

/**
* @brief getControllerAxisValue check controller axis value
* @param axis axis index
* @param index controller index
*/
float getControllerAxisValue(const ControllerAxis &axis, const ControllerIndex &index) override;
/**@} */

/**
* @brief controllerButtonPressed check mouse button status
* @param button input button type
* @return if button is depressed
*/
bool isMouseButtonDown(const int &button) override;

/**
* @brief getMouseAxisValue get mouse axis value
* @param axis x or y
*/
float getRelativeMouseAxisValue(const int &axis) override;

/**
* @brief getRelativeMouseState track mouse movement
* @param dx mouse x movement
* @param dy mouse y movement
*/
void getRelativeMouseState(int *dx, int *dy) override;

/**
* @name CharBuffer methods
* Manipulate input buffer
Expand Down Expand Up @@ -168,19 +218,25 @@ class Window : public Viewport, public InputSource {
*/
void setSdlGlAttributes();

void processMouseAxisEvents();

void processControllerStickEvents();

void processControllerTriggerEvents();

/**
* @brief processMouseButtonEvents get mouse event
* and dispatch to subscribed listeners
* @param event input mouse event
*/
void processMouseButtonEvents(SDL_Event &event);
void processMouseButtonEvents(const SDL_Event &event);

/**
* @brief processWindowEvents get window event
* and dispatch to subscribed listeners
* @param event input window event
*/
void processWindowEvents(SDL_Event &event);
void processWindowEvents(const SDL_Event &event);

/**
* @brief getOpenGlVersionString Create OpenGL version string
Expand All @@ -197,17 +253,26 @@ class Window : public Viewport, public InputSource {
void initGl();


unsigned int width; /**< main screen width */
unsigned int height; /**< main screen height */
SDL_Window *window; /**< SDL identifier for current window */
SDL_GLContext context; /**< SDL Handler for OpenGL Context */
unsigned int width; /**< main screen width */
unsigned int height; /**< main screen height */
SDL_Window *window; /**< SDL identifier for current window */
SDL_GLContext context; /**< SDL Handler for OpenGL Context */

SDL_Joystick *joystick;
SDL_GameController *controller;

std::vector<bool> keystates; /**< Keyboard pressed key status */
std::string charbuffer; /**< Text input buffer */
std::vector<bool> mouseButtonStates; /**< Mouse button pressed status */
std::vector<bool> keyStates; /**< Keyboard key pressed status */
std::vector<bool> controllerButtonStates; /**< Controller button pressed status */
std::vector<Vector2i> controllerStickStates; /**< Controller button pressed status */
std::vector<Vector2i> controllerStickMax; /**< Controller button pressed status */
std::vector<int> controllerTriggerStates; /**< Controller button pressed status */
std::string charbuffer; /**< Text input buffer */
bool lastNonZero;

static const char* DEFAULT_TITLE; /**< Default Title Name */
static const unsigned int DEFAULT_WIDTH; /**< Default Window width */
static const unsigned int DEFAULT_HEIGHT; /**< Default Window Height */
static const char* DEFAULT_TITLE; /**< Default Title Name */
static const unsigned int DEFAULT_WIDTH; /**< Default Window width */
static const unsigned int DEFAULT_HEIGHT; /**< Default Window Height */
};

} /* namespace radix */
Expand Down
8 changes: 8 additions & 0 deletions include/radix/core/math/Vector2f.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#ifndef VECTOR2F_HPP
#define VECTOR2F_HPP

#include <radix/core/math/Vector2i.hpp>

#include <string>

namespace radix {
Expand All @@ -38,6 +40,9 @@ struct Vector2f {
constexpr Vector2f(float v)
: x(v), y(v) {}

constexpr Vector2f(const Vector2i &v)
: x(v.x), y(v.y) {}

float length() const;
std::string str() const;

Expand Down Expand Up @@ -99,6 +104,9 @@ struct Vector2f {
return *this;
}

constexpr Vector2f operator/(const Vector2f& v) const {
return Vector2f(x / v.x, y / v.y);
}
constexpr Vector2f operator/=(const Vector2f& v) const {
return Vector2f(x / v.x, y / v.y);
}
Expand Down
19 changes: 19 additions & 0 deletions include/radix/core/math/Vector2i.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef VECTOR2I_HPP
#define VECTOR2I_HPP

#include <string>

namespace radix {

struct Vector2i {
union {
int x, width;
Expand All @@ -9,13 +13,28 @@ struct Vector2i {
int y, height;
};

static const Vector2i ZERO, UP;

constexpr Vector2i()
: x(0), y(0) {}
constexpr Vector2i(int x, int y)
: x(x), y(y) {}
constexpr Vector2i(int v)
: x(v), y(v) {}

std::string str() const;

constexpr bool operator==(const Vector2i &v) const {
return x == v.x && y == v.y;
}

constexpr bool operator!=(const Vector2i &v) const {
return x != v.x || y != v.y;
}

constexpr Vector2i operator-(const Vector2i& v) const {
return Vector2i(x - v.x, y - v.y);
}
};
} /* namespace radix */
#endif /* VECTOR2I_HPP */
12 changes: 11 additions & 1 deletion include/radix/entities/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include <radix/util/BulletGhostPairCallbacks.hpp>

namespace radix {

class Vector2f;

namespace entities {

class Player :
Expand All @@ -29,16 +32,23 @@ class Player :
KinematicCharacterController *controller;

Vector3f velocity, headAngle;
bool flying, noclip, frozen;
bool flying, noclip, frozen, attemptJump;
float speed;
float stepCounter;
Vector3f movement;
Vector3f headingChange;

Trigger *trigger;

Player(const CreationParams&);
~Player();

void tick(TDelta) override;
void jump();
void move(const Vector2f &move);
void moveX(const float &move);
void moveY(const float &move);
void changeHeading(const Vector2f& lookVector);

Quaternion getBaseHeadOrientation() const;
Quaternion getHeadOrientation() const;
Expand Down
75 changes: 42 additions & 33 deletions include/radix/env/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
#define RADIX_CONFIG_HPP

#include <string>
#include <vector>
#include <map>

#include <json11/json11.hpp>

#include <radix/core/diag/Logger.hpp>
#include <radix/input/Bind.hpp>

using namespace json11;

namespace radix {
Expand All @@ -20,53 +24,58 @@ class Config {
friend class ArgumentsParser;

public:
using Bindings = std::vector<std::vector<Bind>>;

Config();
void load();
bool isLoaded();
unsigned int getWidth() const { return width; }
unsigned int getHeight() const { return height; }
float getSensitivity() const { return sensitivity; }
bool isFullscreen() const { return fullscreen; }
int getAntialiasLevel() const { return antialiasing; }
int getRecursionLevel() const { return recursivePortal; }
bool hasSound() const { return sound; }
bool hasVsync() const { return vsync; }
bool isHidePortalsByClick() const { return hidePortalsByClick; }
bool isConsoleEnabled() const { return consoleEnabled; }
bool isProfilerEnabled() const { return profilerEnabled; }
bool isFlyingEnabled() const { return flyingEnabled; }
bool isDebugViewEnabled() const { return debugViewEnabled; }
bool getCursorVisibility() const { return cursorVisibility; }
bool getIgnoreGlVersion() const { return ignoreGlVersion; }
bool getGlContextEnableDebug() const { return glContextEnableDebug; }
LogLevel getLoglevel() const { return loglevel; }
std::string getMap() const { return map; }
std::string getMapPath() const { return mapPath; }
int getScreen() const { return screen; }
unsigned int getWidth() const { return width; }
unsigned int getHeight() const { return height; }
float getMouseSensitivity() const { return mouseSensitivity; }
bool isFullscreen() const { return fullscreen; }
int getAntialiasLevel() const { return antialiasing; }
int getRecursionLevel() const { return recursivePortal; }
bool hasSound() const { return sound; }
bool hasVsync() const { return vsync; }
bool isHidePortalsByClick() const { return hidePortalsByClick; }
bool isConsoleEnabled() const { return consoleEnabled; }
bool isProfilerEnabled() const { return profilerEnabled; }
bool isFlyingEnabled() const { return flyingEnabled; }
bool isDebugViewEnabled() const { return debugViewEnabled; }
bool getCursorVisibility() const { return cursorVisibility; }
bool getIgnoreGlVersion() const { return ignoreGlVersion; }
bool getGlContextEnableDebug() const { return glContextEnableDebug; }
Bindings getBindings() const { return bindings; }
LogLevel getLoglevel() const { return loglevel; }
std::string getMap() const { return map; }
std::string getMapPath() const { return mapPath; }
int getScreen() const { return screen; }

static std::string actionToString(const int &action);

private:
void loadVideoSettings(const Json &json);
void loadSoundSettings(const Json &json);
void loadMouseSettings(const Json &json);
void loadKeyboardSettings(const Json &json);
void loadControllerSettings(const Json &json);
void loadLoglevelSettings(const Json &json);
void loadDefaultBindings();

bool loaded;
unsigned int width;
unsigned int height;
float sensitivity;
float mouseSensitivity;
int antialiasing;
int recursivePortal;
bool fullscreen;
bool sound;
bool vsync;
bool hidePortalsByClick;
bool cursorVisibility;
bool ignoreGlVersion;
bool glContextEnableDebug;
bool consoleEnabled;
bool profilerEnabled;
bool flyingEnabled;
bool debugViewEnabled;
bool loaded, fullscreen, sound, vsync, flyingEnabled
, hidePortalsByClick, cursorVisibility
, ignoreGlVersion, glContextEnableDebug
, consoleEnabled, profilerEnabled, debugViewEnabled;

Bindings bindings;

static const Bindings defaultBindings;

LogLevel loglevel;
std::string map;
std::string mapPath;
Expand Down
Loading

0 comments on commit 9a5cb0e

Please sign in to comment.