mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-15 06:52:34 +02:00
clang-format files in rwgame
This commit is contained in:
parent
e888d04303
commit
e39ee21ca8
@ -1,9 +1,9 @@
|
|||||||
#include "DrawUI.hpp"
|
#include "DrawUI.hpp"
|
||||||
#include <render/GameRenderer.hpp>
|
|
||||||
#include <ai/PlayerController.hpp>
|
#include <ai/PlayerController.hpp>
|
||||||
#include <objects/CharacterObject.hpp>
|
|
||||||
#include <engine/GameState.hpp>
|
#include <engine/GameState.hpp>
|
||||||
#include <items/WeaponItem.hpp>
|
#include <items/WeaponItem.hpp>
|
||||||
|
#include <objects/CharacterObject.hpp>
|
||||||
|
#include <render/GameRenderer.hpp>
|
||||||
|
|
||||||
#include <glm/gtc/constants.hpp>
|
#include <glm/gtc/constants.hpp>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@ -26,121 +26,121 @@ const float ui_mapSize = 150.f;
|
|||||||
const float ui_worldSizeMin = 200.f;
|
const float ui_worldSizeMin = 200.f;
|
||||||
const float ui_worldSizeMax = 300.f;
|
const float ui_worldSizeMax = 300.f;
|
||||||
|
|
||||||
void drawMap(ViewCamera& currentView, PlayerController* player, GameWorld* world, GameRenderer* render)
|
void drawMap(ViewCamera& currentView, PlayerController* player,
|
||||||
{
|
GameWorld* world, GameRenderer* render) {
|
||||||
MapRenderer::MapInfo map;
|
MapRenderer::MapInfo map;
|
||||||
|
|
||||||
glm::quat camRot = currentView.rotation;
|
|
||||||
|
|
||||||
map.rotation = glm::roll(camRot) - glm::half_pi<float>();
|
|
||||||
map.worldSize = ui_worldSizeMin;
|
|
||||||
map.worldSize = ui_worldSizeMax;
|
|
||||||
if( player )
|
|
||||||
{
|
|
||||||
map.worldCenter = glm::vec2(player->getCharacter()->getPosition());
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::ivec2 &vp = render->getRenderer()->getViewport();
|
glm::quat camRot = currentView.rotation;
|
||||||
|
|
||||||
glm::vec2 mapTop = glm::vec2(ui_outerMargin, vp.y - (ui_outerMargin + ui_mapSize));
|
map.rotation = glm::roll(camRot) - glm::half_pi<float>();
|
||||||
glm::vec2 mapBottom = glm::vec2(ui_outerMargin + ui_mapSize, vp.y - ui_outerMargin);
|
map.worldSize = ui_worldSizeMin;
|
||||||
|
map.worldSize = ui_worldSizeMax;
|
||||||
|
if (player) {
|
||||||
|
map.worldCenter = glm::vec2(player->getCharacter()->getPosition());
|
||||||
|
}
|
||||||
|
|
||||||
map.screenPosition = (mapTop + mapBottom)/2.f;
|
const glm::ivec2& vp = render->getRenderer()->getViewport();
|
||||||
map.screenSize = ui_mapSize * 0.95;
|
|
||||||
|
glm::vec2 mapTop =
|
||||||
render->map.draw(world, map);
|
glm::vec2(ui_outerMargin, vp.y - (ui_outerMargin + ui_mapSize));
|
||||||
|
glm::vec2 mapBottom =
|
||||||
|
glm::vec2(ui_outerMargin + ui_mapSize, vp.y - ui_outerMargin);
|
||||||
|
|
||||||
|
map.screenPosition = (mapTop + mapBottom) / 2.f;
|
||||||
|
map.screenSize = ui_mapSize * 0.95;
|
||||||
|
|
||||||
|
render->map.draw(world, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawPlayerInfo(PlayerController* player, GameWorld* world, GameRenderer* render)
|
void drawPlayerInfo(PlayerController* player, GameWorld* world,
|
||||||
{
|
GameRenderer* render) {
|
||||||
float infoTextX = render->getRenderer()->getViewport().x -
|
float infoTextX = render->getRenderer()->getViewport().x -
|
||||||
(ui_outerMargin + ui_weaponSize + ui_infoMargin);
|
(ui_outerMargin + ui_weaponSize + ui_infoMargin);
|
||||||
float infoTextY = 0.f + ui_outerMargin;
|
float infoTextY = 0.f + ui_outerMargin;
|
||||||
float iconX = render->getRenderer()->getViewport().x -
|
float iconX = render->getRenderer()->getViewport().x -
|
||||||
(ui_outerMargin + ui_weaponSize);
|
(ui_outerMargin + ui_weaponSize);
|
||||||
float iconY = ui_outerMargin;
|
float iconY = ui_outerMargin;
|
||||||
float wantedX = render->getRenderer()->getViewport().x -
|
float wantedX = render->getRenderer()->getViewport().x - (ui_outerMargin);
|
||||||
(ui_outerMargin);
|
float wantedY = ui_outerMargin + ui_weaponSize + 3.f;
|
||||||
float wantedY = ui_outerMargin + ui_weaponSize + 3.f;
|
|
||||||
|
|
||||||
TextRenderer::TextInfo ti;
|
TextRenderer::TextInfo ti;
|
||||||
ti.font = 1;
|
ti.font = 1;
|
||||||
ti.size = ui_textSize;
|
ti.size = ui_textSize;
|
||||||
ti.align = TextRenderer::TextInfo::Right;
|
ti.align = TextRenderer::TextInfo::Right;
|
||||||
|
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << std::setw(2) << std::setfill('0') << world->getHour()
|
ss << std::setw(2) << std::setfill('0') << world->getHour()
|
||||||
<< std::setw(0) << ":"
|
<< std::setw(0) << ":" << std::setw(2) << world->getMinute();
|
||||||
<< std::setw(2) << world->getMinute();
|
|
||||||
|
|
||||||
ti.text = GameStringUtil::fromString(ss.str());
|
ti.text = GameStringUtil::fromString(ss.str());
|
||||||
}
|
}
|
||||||
ti.baseColour = ui_shadowColour;
|
ti.baseColour = ui_shadowColour;
|
||||||
ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY+1.f);
|
ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY + 1.f);
|
||||||
render->text.renderText(ti);
|
render->text.renderText(ti);
|
||||||
|
|
||||||
ti.baseColour = ui_timeColour;
|
ti.baseColour = ui_timeColour;
|
||||||
ti.screenPosition = glm::vec2(infoTextX, infoTextY);
|
ti.screenPosition = glm::vec2(infoTextX, infoTextY);
|
||||||
render->text.renderText(ti);
|
render->text.renderText(ti);
|
||||||
|
|
||||||
infoTextY += ui_textHeight;
|
infoTextY += ui_textHeight;
|
||||||
|
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << std::setw(8) << std::setfill('0') << world->state->playerInfo.displayedMoney;
|
ss << std::setw(8) << std::setfill('0')
|
||||||
|
<< world->state->playerInfo.displayedMoney;
|
||||||
|
|
||||||
ti.text = GameSymbols::Money + GameStringUtil::fromString(ss.str());
|
ti.text = GameSymbols::Money + GameStringUtil::fromString(ss.str());
|
||||||
}
|
}
|
||||||
ti.baseColour = ui_shadowColour;
|
ti.baseColour = ui_shadowColour;
|
||||||
ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY+1.f);
|
ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY + 1.f);
|
||||||
render->text.renderText(ti);
|
render->text.renderText(ti);
|
||||||
|
|
||||||
ti.baseColour = ui_moneyColour;
|
ti.baseColour = ui_moneyColour;
|
||||||
ti.screenPosition = glm::vec2(infoTextX, infoTextY);
|
ti.screenPosition = glm::vec2(infoTextX, infoTextY);
|
||||||
render->text.renderText(ti);
|
render->text.renderText(ti);
|
||||||
|
|
||||||
infoTextY += ui_textHeight;
|
infoTextY += ui_textHeight;
|
||||||
|
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << std::setw(3) << std::setfill('0')
|
ss << std::setw(3) << std::setfill('0')
|
||||||
<< (int)player->getCharacter()->getCurrentState().health;
|
<< (int)player->getCharacter()->getCurrentState().health;
|
||||||
ti.text = GameSymbols::Heart + GameStringUtil::fromString(ss.str());
|
ti.text = GameSymbols::Heart + GameStringUtil::fromString(ss.str());
|
||||||
}
|
}
|
||||||
ti.baseColour = ui_shadowColour;
|
ti.baseColour = ui_shadowColour;
|
||||||
ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY+1.f);
|
ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY + 1.f);
|
||||||
render->text.renderText(ti);
|
render->text.renderText(ti);
|
||||||
|
|
||||||
ti.baseColour = ui_healthColour;
|
ti.baseColour = ui_healthColour;
|
||||||
ti.screenPosition = glm::vec2(infoTextX, infoTextY);
|
ti.screenPosition = glm::vec2(infoTextX, infoTextY);
|
||||||
render->text.renderText(ti);
|
render->text.renderText(ti);
|
||||||
|
|
||||||
if (player->getCharacter()->getCurrentState().armour > 0)
|
if (player->getCharacter()->getCurrentState().armour > 0) {
|
||||||
{
|
std::stringstream ss;
|
||||||
std::stringstream ss;
|
ss << std::setw(3) << std::setfill('0')
|
||||||
ss << std::setw(3) << std::setfill('0')
|
<< (int)player->getCharacter()->getCurrentState().armour;
|
||||||
<< (int)player->getCharacter()->getCurrentState().armour;
|
ti.text = GameSymbols::Armour + GameStringUtil::fromString(ss.str());
|
||||||
ti.text = GameSymbols::Armour + GameStringUtil::fromString(ss.str());
|
ti.baseColour = ui_shadowColour;
|
||||||
ti.baseColour = ui_shadowColour;
|
ti.screenPosition =
|
||||||
ti.screenPosition = glm::vec2(infoTextX + 1.f - ui_armourOffset, infoTextY+1.f);
|
glm::vec2(infoTextX + 1.f - ui_armourOffset, infoTextY + 1.f);
|
||||||
render->text.renderText(ti);
|
render->text.renderText(ti);
|
||||||
|
|
||||||
ti.baseColour = ui_armourColour;
|
ti.baseColour = ui_armourColour;
|
||||||
ti.screenPosition = glm::vec2(infoTextX - ui_armourOffset, infoTextY);
|
ti.screenPosition = glm::vec2(infoTextX - ui_armourOffset, infoTextY);
|
||||||
render->text.renderText(ti);
|
render->text.renderText(ti);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameString s;
|
GameString s;
|
||||||
for (size_t i = 0; i < ui_maxWantedLevel; ++i) {
|
for (size_t i = 0; i < ui_maxWantedLevel; ++i) {
|
||||||
s += GameSymbols::Star;
|
s += GameSymbols::Star;
|
||||||
}
|
}
|
||||||
ti.text = s;
|
ti.text = s;
|
||||||
ti.baseColour = ui_shadowColour;
|
ti.baseColour = ui_shadowColour;
|
||||||
ti.screenPosition = glm::vec2(wantedX + 1.f, wantedY + 1.f);
|
ti.screenPosition = glm::vec2(wantedX + 1.f, wantedY + 1.f);
|
||||||
render->text.renderText(ti);
|
render->text.renderText(ti);
|
||||||
|
|
||||||
#if 0 // Useful for debugging
|
#if 0 // Useful for debugging
|
||||||
ti.text = "ABCDEFGHIJKLMANOQRTSWXYZ\nM0123456789";
|
ti.text = "ABCDEFGHIJKLMANOQRTSWXYZ\nM0123456789";
|
||||||
ti.size = 30;
|
ti.size = 30;
|
||||||
ti.align = TextRenderer::TextInfo::Left;
|
ti.align = TextRenderer::TextInfo::Left;
|
||||||
@ -152,115 +152,110 @@ void drawPlayerInfo(PlayerController* player, GameWorld* world, GameRenderer* re
|
|||||||
render->text.renderText(ti);
|
render->text.renderText(ti);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
InventoryItem *current = player->getCharacter()->getActiveItem();
|
InventoryItem* current = player->getCharacter()->getActiveItem();
|
||||||
std::string itemTextureName = "fist";
|
std::string itemTextureName = "fist";
|
||||||
if (current) {
|
if (current) {
|
||||||
uint16_t model = current->getModelID();
|
uint16_t model = current->getModelID();
|
||||||
if (model > 0) {
|
if (model > 0) {
|
||||||
ObjectDataPtr weaponData = world
|
ObjectDataPtr weaponData =
|
||||||
->data
|
world->data->findObjectType<ObjectData>(model);
|
||||||
->findObjectType<ObjectData>(model);
|
if (weaponData != nullptr) {
|
||||||
if (weaponData != nullptr) {
|
itemTextureName = weaponData->modelName;
|
||||||
itemTextureName = weaponData->modelName;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// Urgh
|
||||||
// Urgh
|
if (itemTextureName == "colt45") {
|
||||||
if (itemTextureName == "colt45") {
|
itemTextureName = "pistol";
|
||||||
itemTextureName = "pistol";
|
}
|
||||||
}
|
|
||||||
|
|
||||||
TextureData::Handle itemTexture = render->getData()->findTexture(itemTextureName);
|
TextureData::Handle itemTexture =
|
||||||
RW_CHECK(itemTexture != nullptr, "Item has 0 texture");
|
render->getData()->findTexture(itemTextureName);
|
||||||
if (itemTexture != nullptr) {
|
RW_CHECK(itemTexture != nullptr, "Item has 0 texture");
|
||||||
RW_CHECK(itemTexture->getName() != 0, "Item has 0 texture");
|
if (itemTexture != nullptr) {
|
||||||
render->drawTexture(itemTexture.get(),
|
RW_CHECK(itemTexture->getName() != 0, "Item has 0 texture");
|
||||||
glm::vec4(iconX,
|
render->drawTexture(
|
||||||
iconY,
|
itemTexture.get(),
|
||||||
ui_weaponSize,
|
glm::vec4(iconX, iconY, ui_weaponSize, ui_weaponSize));
|
||||||
ui_weaponSize));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (current) {
|
if (current) {
|
||||||
WeaponItem* wep = static_cast<WeaponItem*>(current);
|
WeaponItem* wep = static_cast<WeaponItem*>(current);
|
||||||
if (wep->getWeaponData()->fireType != WeaponData::MELEE) {
|
if (wep->getWeaponData()->fireType != WeaponData::MELEE) {
|
||||||
const CharacterState& cs = player->getCharacter()->getCurrentState();
|
const CharacterState& cs =
|
||||||
const CharacterWeaponSlot& slotInfo = cs.weapons[cs.currentWeapon];
|
player->getCharacter()->getCurrentState();
|
||||||
ti.text = GameStringUtil::fromString(
|
const CharacterWeaponSlot& slotInfo = cs.weapons[cs.currentWeapon];
|
||||||
std::to_string(slotInfo.bulletsClip) + "-"
|
ti.text = GameStringUtil::fromString(
|
||||||
+ std::to_string(slotInfo.bulletsTotal));
|
std::to_string(slotInfo.bulletsClip) + "-" +
|
||||||
|
std::to_string(slotInfo.bulletsTotal));
|
||||||
|
|
||||||
ti.baseColour = ui_shadowColour;
|
ti.baseColour = ui_shadowColour;
|
||||||
ti.font = 2;
|
ti.font = 2;
|
||||||
ti.size = ui_ammoSize;
|
ti.size = ui_ammoSize;
|
||||||
ti.align = TextRenderer::TextInfo::Center;
|
ti.align = TextRenderer::TextInfo::Center;
|
||||||
ti.screenPosition = glm::vec2(iconX + ui_weaponSize / 2.f,
|
ti.screenPosition =
|
||||||
iconY + ui_weaponSize - ui_ammoHeight);
|
glm::vec2(iconX + ui_weaponSize / 2.f,
|
||||||
render->text.renderText(ti);
|
iconY + ui_weaponSize - ui_ammoHeight);
|
||||||
}
|
render->text.renderText(ti);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawHUD(ViewCamera& currentView, PlayerController* player, GameWorld* world, GameRenderer* render)
|
void drawHUD(ViewCamera& currentView, PlayerController* player,
|
||||||
{
|
GameWorld* world, GameRenderer* render) {
|
||||||
if(player && player->getCharacter()) {
|
if (player && player->getCharacter()) {
|
||||||
drawMap(currentView, player, world, render);
|
drawMap(currentView, player, world, render);
|
||||||
drawPlayerInfo(player, world, render);
|
drawPlayerInfo(player, world, render);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawOnScreenText(GameWorld* world, GameRenderer* renderer)
|
void drawOnScreenText(GameWorld* world, GameRenderer* renderer) {
|
||||||
{
|
const auto vp = glm::vec2(renderer->getRenderer()->getViewport());
|
||||||
const auto vp = glm::vec2(renderer->getRenderer()->getViewport());
|
|
||||||
|
|
||||||
TextRenderer::TextInfo ti;
|
|
||||||
ti.font = 2;
|
|
||||||
ti.screenPosition = glm::vec2( 10.f, 10.f );
|
|
||||||
ti.size = 20.f;
|
|
||||||
|
|
||||||
auto& alltext = world->state->text.getAllText();
|
TextRenderer::TextInfo ti;
|
||||||
|
ti.font = 2;
|
||||||
|
ti.screenPosition = glm::vec2(10.f, 10.f);
|
||||||
|
ti.size = 20.f;
|
||||||
|
|
||||||
for(auto& l : alltext)
|
auto& alltext = world->state->text.getAllText();
|
||||||
{
|
|
||||||
for (auto& t : l)
|
|
||||||
{
|
|
||||||
ti.size = t.size;
|
|
||||||
ti.font = t.font;
|
|
||||||
ti.text = t.text;
|
|
||||||
ti.wrapX = t.wrapX;
|
|
||||||
ti.screenPosition = (t.position/glm::vec2(640.f, 480.f)) * vp;
|
|
||||||
switch(t.alignment) {
|
|
||||||
case 0:
|
|
||||||
ti.align = TextRenderer::TextInfo::Left;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ti.align = TextRenderer::TextInfo::Center;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
ti.align = TextRenderer::TextInfo::Right;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for the background type
|
for (auto& l : alltext) {
|
||||||
if (t.colourBG.a == 0)
|
for (auto& t : l) {
|
||||||
{
|
ti.size = t.size;
|
||||||
glm::vec2 shadowPosition((int8_t)t.colourBG.x, (int8_t)t.colourBG.y);
|
ti.font = t.font;
|
||||||
|
ti.text = t.text;
|
||||||
|
ti.wrapX = t.wrapX;
|
||||||
|
ti.screenPosition = (t.position / glm::vec2(640.f, 480.f)) * vp;
|
||||||
|
switch (t.alignment) {
|
||||||
|
case 0:
|
||||||
|
ti.align = TextRenderer::TextInfo::Left;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
ti.align = TextRenderer::TextInfo::Center;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
ti.align = TextRenderer::TextInfo::Right;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
ti.baseColour = glm::vec3(0.f);
|
// Check for the background type
|
||||||
ti.screenPosition += shadowPosition;
|
if (t.colourBG.a == 0) {
|
||||||
ti.backgroundColour = {0, 0, 0, 0};
|
glm::vec2 shadowPosition((int8_t)t.colourBG.x,
|
||||||
|
(int8_t)t.colourBG.y);
|
||||||
|
|
||||||
renderer->text.renderText(ti, true);
|
ti.baseColour = glm::vec3(0.f);
|
||||||
|
ti.screenPosition += shadowPosition;
|
||||||
|
ti.backgroundColour = {0, 0, 0, 0};
|
||||||
|
|
||||||
ti.screenPosition -= shadowPosition;
|
renderer->text.renderText(ti, true);
|
||||||
}
|
|
||||||
else if(t.colourBG.a > 0)
|
|
||||||
{
|
|
||||||
ti.backgroundColour = t.colourBG;
|
|
||||||
}
|
|
||||||
|
|
||||||
ti.baseColour = t.colourFG;
|
ti.screenPosition -= shadowPosition;
|
||||||
renderer->text.renderText(ti);
|
} else if (t.colourBG.a > 0) {
|
||||||
}
|
ti.backgroundColour = t.colourBG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ti.baseColour = t.colourFG;
|
||||||
|
renderer->text.renderText(ti);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
class PlayerController;
|
class PlayerController;
|
||||||
|
|
||||||
void drawHUD(ViewCamera& currentView, PlayerController* player, GameWorld* world, GameRenderer* render);
|
void drawHUD(ViewCamera& currentView, PlayerController* player,
|
||||||
|
GameWorld* world, GameRenderer* render);
|
||||||
|
|
||||||
void drawOnScreenText(GameWorld* world, GameRenderer* renderer);
|
void drawOnScreenText(GameWorld* world, GameRenderer* renderer);
|
||||||
|
@ -1,100 +1,86 @@
|
|||||||
#include "GameConfig.hpp"
|
#include "GameConfig.hpp"
|
||||||
#include <rw/defines.hpp>
|
|
||||||
#include <cstring>
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <rw/defines.hpp>
|
||||||
|
|
||||||
#include <ini.h>
|
#include <ini.h>
|
||||||
|
|
||||||
const std::string kConfigDirectoryName("OpenRW");
|
const std::string kConfigDirectoryName("OpenRW");
|
||||||
|
|
||||||
GameConfig::GameConfig(const std::string& configName, const std::string& configPath)
|
GameConfig::GameConfig(const std::string& configName,
|
||||||
: m_configName(configName)
|
const std::string& configPath)
|
||||||
, m_configPath(configPath)
|
: m_configName(configName)
|
||||||
, m_valid(false)
|
, m_configPath(configPath)
|
||||||
, m_inputInvertY(false)
|
, m_valid(false)
|
||||||
{
|
, m_inputInvertY(false) {
|
||||||
if (m_configPath.empty())
|
if (m_configPath.empty()) {
|
||||||
{
|
m_configPath = getDefaultConfigPath();
|
||||||
m_configPath = getDefaultConfigPath();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Look up the path to use
|
// Look up the path to use
|
||||||
auto configFile = getConfigFile();
|
auto configFile = getConfigFile();
|
||||||
|
|
||||||
if (ini_parse(configFile.c_str(), handler, this) < 0)
|
if (ini_parse(configFile.c_str(), handler, this) < 0) {
|
||||||
{
|
m_valid = false;
|
||||||
m_valid = false;
|
} else {
|
||||||
}
|
m_valid = true;
|
||||||
else
|
}
|
||||||
{
|
|
||||||
m_valid = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GameConfig::getConfigFile()
|
std::string GameConfig::getConfigFile() {
|
||||||
{
|
return m_configPath + "/" + m_configName;
|
||||||
return m_configPath + "/" + m_configName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameConfig::isValid()
|
bool GameConfig::isValid() {
|
||||||
{
|
return m_valid;
|
||||||
return m_valid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GameConfig::getDefaultConfigPath()
|
std::string GameConfig::getDefaultConfigPath() {
|
||||||
{
|
#if defined(RW_LINUX) || defined(RW_FREEBSD) || defined(RW_NETBSD) || \
|
||||||
#if defined(RW_LINUX) || defined(RW_FREEBSD) || defined(RW_NETBSD) || defined(RW_OPENBSD)
|
defined(RW_OPENBSD)
|
||||||
char* config_home = getenv("XDG_CONFIG_HOME");
|
char* config_home = getenv("XDG_CONFIG_HOME");
|
||||||
if (config_home != nullptr) {
|
if (config_home != nullptr) {
|
||||||
return std::string(config_home) + "/" + kConfigDirectoryName;
|
return std::string(config_home) + "/" + kConfigDirectoryName;
|
||||||
}
|
}
|
||||||
char* home = getenv("HOME");
|
char* home = getenv("HOME");
|
||||||
if (home != nullptr) {
|
if (home != nullptr) {
|
||||||
return std::string(home) + "/.config/" + kConfigDirectoryName;
|
return std::string(home) + "/.config/" + kConfigDirectoryName;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(RW_OSX)
|
#elif defined(RW_OSX)
|
||||||
char* home = getenv("HOME");
|
char* home = getenv("HOME");
|
||||||
if (home)
|
if (home)
|
||||||
return std::string(home) + "/Library/Preferences/" + kConfigDirectoryName;
|
return std::string(home) + "/Library/Preferences/" +
|
||||||
|
kConfigDirectoryName;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
return ".";
|
return ".";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Well now we're stuck.
|
// Well now we're stuck.
|
||||||
RW_ERROR("No default config path found.");
|
RW_ERROR("No default config path found.");
|
||||||
return ".";
|
return ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
int GameConfig::handler(void* user,
|
int GameConfig::handler(void* user, const char* section, const char* name,
|
||||||
const char* section,
|
const char* value) {
|
||||||
const char* name,
|
auto self = static_cast<GameConfig*>(user);
|
||||||
const char* value)
|
|
||||||
{
|
|
||||||
auto self = static_cast<GameConfig*>(user);
|
|
||||||
#define MATCH(_s, _n) (strcmp(_s, section) == 0 && strcmp(_n, name) == 0)
|
#define MATCH(_s, _n) (strcmp(_s, section) == 0 && strcmp(_n, name) == 0)
|
||||||
|
|
||||||
if (MATCH("game", "path"))
|
if (MATCH("game", "path")) {
|
||||||
{
|
self->m_gamePath = value;
|
||||||
self->m_gamePath = value;
|
} else if (MATCH("game", "language")) {
|
||||||
}
|
// @todo Don't allow path seperators and relative directories
|
||||||
else if (MATCH("game", "language"))
|
self->m_gameLanguage = value;
|
||||||
{
|
} else if (MATCH("input", "invert_y")) {
|
||||||
// @todo Don't allow path seperators and relative directories
|
self->m_inputInvertY = atoi(value) > 0;
|
||||||
self->m_gameLanguage = value;
|
} else {
|
||||||
}
|
RW_MESSAGE("Unhandled config entry [" << section << "] " << name
|
||||||
else if (MATCH("input", "invert_y"))
|
<< " = " << value);
|
||||||
{
|
return 0;
|
||||||
self->m_inputInvertY = atoi(value) > 0;
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RW_MESSAGE("Unhandled config entry [" << section << "] " << name << " = " << value);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
#undef MATCH
|
#undef MATCH
|
||||||
}
|
}
|
||||||
|
@ -2,50 +2,56 @@
|
|||||||
#define RWGAME_GAMECONFIG_HPP
|
#define RWGAME_GAMECONFIG_HPP
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class GameConfig
|
class GameConfig {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief GameConfig Loads a game configuration
|
* @brief GameConfig Loads a game configuration
|
||||||
* @param configName The configuration filename to load
|
* @param configName The configuration filename to load
|
||||||
* @param configPath Where to look.
|
* @param configPath Where to look.
|
||||||
*/
|
*/
|
||||||
GameConfig(const std::string& configName, const std::string& configPath = getDefaultConfigPath());
|
GameConfig(const std::string& configName,
|
||||||
|
const std::string& configPath = getDefaultConfigPath());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief getFilePath Returns the system file path for the configuration
|
* @brief getFilePath Returns the system file path for the configuration
|
||||||
*/
|
*/
|
||||||
std::string getConfigFile();
|
std::string getConfigFile();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief isValid
|
* @brief isValid
|
||||||
* @return True if the loaded configuration is valid
|
* @return True if the loaded configuration is valid
|
||||||
*/
|
*/
|
||||||
bool isValid();
|
bool isValid();
|
||||||
|
|
||||||
const std::string& getGameDataPath() const { return m_gamePath; }
|
const std::string& getGameDataPath() const {
|
||||||
const std::string& getGameLanguage() const { return m_gameLanguage; }
|
return m_gamePath;
|
||||||
bool getInputInvertY() const { return m_inputInvertY; }
|
}
|
||||||
|
const std::string& getGameLanguage() const {
|
||||||
|
return m_gameLanguage;
|
||||||
|
}
|
||||||
|
bool getInputInvertY() const {
|
||||||
|
return m_inputInvertY;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::string getDefaultConfigPath();
|
static std::string getDefaultConfigPath();
|
||||||
static int handler(void*, const char*, const char*, const char*);
|
static int handler(void*, const char*, const char*, const char*);
|
||||||
|
|
||||||
/* Config State */
|
/* Config State */
|
||||||
std::string m_configName;
|
std::string m_configName;
|
||||||
std::string m_configPath;
|
std::string m_configPath;
|
||||||
bool m_valid;
|
bool m_valid;
|
||||||
|
|
||||||
/* Actual Configuration */
|
/* Actual Configuration */
|
||||||
|
|
||||||
/// Path to the game data
|
/// Path to the game data
|
||||||
std::string m_gamePath;
|
std::string m_gamePath;
|
||||||
|
|
||||||
/// Language for game
|
/// Language for game
|
||||||
std::string m_gameLanguage = "american";
|
std::string m_gameLanguage = "american";
|
||||||
|
|
||||||
/// Invert the y axis for camera control.
|
/// Invert the y axis for camera control.
|
||||||
bool m_inputInvertY;
|
bool m_inputInvertY;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,68 +1,57 @@
|
|||||||
#include <core/Logger.hpp>
|
|
||||||
#include "GameWindow.hpp"
|
#include "GameWindow.hpp"
|
||||||
|
#include <core/Logger.hpp>
|
||||||
|
|
||||||
GameWindow::GameWindow() :
|
GameWindow::GameWindow() : window(nullptr), glcontext(nullptr) {
|
||||||
window(nullptr), glcontext(nullptr)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameWindow::create(const std::string& title, size_t w, size_t h,
|
||||||
|
bool fullscreen) {
|
||||||
|
Uint32 style = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;
|
||||||
|
if (fullscreen) style |= SDL_WINDOW_FULLSCREEN;
|
||||||
|
|
||||||
void GameWindow::create(const std::string& title, size_t w, size_t h, bool fullscreen)
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
|
||||||
{
|
SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
Uint32 style = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
if (fullscreen)
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||||
style |= SDL_WINDOW_FULLSCREEN;
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
||||||
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED,
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
SDL_WINDOWPOS_CENTERED, w, h, style);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
if (window == nullptr) {
|
||||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
// Window creation failure is fatal
|
||||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
std::string sdlErrorStr = SDL_GetError();
|
||||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
throw std::runtime_error("SDL_CreateWindow failed: " + sdlErrorStr);
|
||||||
|
}
|
||||||
|
glcontext = SDL_GL_CreateContext(window);
|
||||||
|
if (glcontext == nullptr) {
|
||||||
|
// context creation failure is fatal
|
||||||
|
std::string sdlErrorStr = SDL_GetError();
|
||||||
|
throw std::runtime_error("SDL_GL_CreateContext failed: " + sdlErrorStr);
|
||||||
|
}
|
||||||
|
|
||||||
window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, style);
|
SDL_ShowWindow(window);
|
||||||
if (window == nullptr) {
|
|
||||||
// Window creation failure is fatal
|
|
||||||
std::string sdlErrorStr = SDL_GetError();
|
|
||||||
throw std::runtime_error("SDL_CreateWindow failed: " + sdlErrorStr);
|
|
||||||
}
|
|
||||||
glcontext = SDL_GL_CreateContext(window);
|
|
||||||
if (glcontext == nullptr) {
|
|
||||||
// context creation failure is fatal
|
|
||||||
std::string sdlErrorStr = SDL_GetError();
|
|
||||||
throw std::runtime_error("SDL_GL_CreateContext failed: " + sdlErrorStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_ShowWindow(window);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameWindow::close() {
|
||||||
|
SDL_GL_DeleteContext(glcontext);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
|
||||||
void GameWindow::close()
|
window = nullptr;
|
||||||
{
|
|
||||||
SDL_GL_DeleteContext(glcontext);
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
|
|
||||||
window = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameWindow::showCursor() {
|
||||||
void GameWindow::showCursor()
|
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||||
{
|
|
||||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameWindow::hideCursor() {
|
||||||
void GameWindow::hideCursor()
|
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||||
{
|
|
||||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::ivec2 GameWindow::getSize() const {
|
||||||
|
int x, y;
|
||||||
|
SDL_GL_GetDrawableSize(window, &x, &y);
|
||||||
|
|
||||||
glm::ivec2 GameWindow::getSize() const
|
return glm::ivec2(x, y);
|
||||||
{
|
|
||||||
int x, y;
|
|
||||||
SDL_GL_GetDrawableSize(window, &x, &y);
|
|
||||||
|
|
||||||
return glm::ivec2(x, y);
|
|
||||||
}
|
}
|
||||||
|
@ -1,38 +1,34 @@
|
|||||||
#ifndef GAMEWINDOW_HPP
|
#ifndef GAMEWINDOW_HPP
|
||||||
#define GAMEWINDOW_HPP
|
#define GAMEWINDOW_HPP
|
||||||
|
|
||||||
|
#include <glm/vec2.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#include <glm/vec2.hpp>
|
|
||||||
|
|
||||||
#include <render/GameRenderer.hpp>
|
#include <render/GameRenderer.hpp>
|
||||||
|
|
||||||
|
class GameWindow {
|
||||||
class GameWindow
|
SDL_Window* window;
|
||||||
{
|
SDL_GLContext glcontext;
|
||||||
SDL_Window* window;
|
|
||||||
SDL_GLContext glcontext;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GameWindow();
|
GameWindow();
|
||||||
|
|
||||||
void create(const std::string& title, size_t w, size_t h, bool fullscreen);
|
void create(const std::string& title, size_t w, size_t h, bool fullscreen);
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
void showCursor();
|
void showCursor();
|
||||||
void hideCursor();
|
void hideCursor();
|
||||||
|
|
||||||
glm::ivec2 getSize() const;
|
glm::ivec2 getSize() const;
|
||||||
|
|
||||||
void swap() const
|
void swap() const {
|
||||||
{
|
SDL_GL_SwapWindow(window);
|
||||||
SDL_GL_SwapWindow(window);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
bool isOpen() const
|
bool isOpen() const {
|
||||||
{
|
return !!window;
|
||||||
return !!window;
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
#ifndef _GAME_MENUSYSTEM_HPP_
|
#ifndef _GAME_MENUSYSTEM_HPP_
|
||||||
#define _GAME_MENUSYSTEM_HPP_
|
#define _GAME_MENUSYSTEM_HPP_
|
||||||
#include <string>
|
|
||||||
#include <memory>
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include <render/GameRenderer.hpp>
|
|
||||||
#include <functional>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <render/GameRenderer.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default values for menus that should match the look and feel of the original
|
* Default values for menus that should match the look and feel of the original
|
||||||
*/
|
*/
|
||||||
namespace MenuDefaults
|
namespace MenuDefaults {
|
||||||
{
|
|
||||||
constexpr int kFont = 1;
|
constexpr int kFont = 1;
|
||||||
|
|
||||||
constexpr const char* kStartGameId = "FET_SAN";
|
constexpr const char* kStartGameId = "FET_SAN";
|
||||||
@ -22,161 +21,133 @@ constexpr const char* kOptionsId = "FET_OPT";
|
|||||||
constexpr const char* kQuitGameId = "FET_QG";
|
constexpr const char* kQuitGameId = "FET_QG";
|
||||||
}
|
}
|
||||||
|
|
||||||
class Menu
|
class Menu {
|
||||||
{
|
int font;
|
||||||
int font;
|
|
||||||
public:
|
public:
|
||||||
|
Menu(int font = MenuDefaults::kFont) : font(font), activeEntry(-1) {
|
||||||
Menu(int font = MenuDefaults::kFont)
|
}
|
||||||
: font(font), activeEntry(-1) {}
|
|
||||||
|
|
||||||
struct MenuEntry
|
|
||||||
{
|
|
||||||
GameString text;
|
|
||||||
float _size;
|
|
||||||
|
|
||||||
MenuEntry(const GameString& n, float size = 30.f)
|
|
||||||
: text(n)
|
|
||||||
, _size(size)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
float getHeight() { return _size; }
|
|
||||||
|
|
||||||
virtual void draw(int font, bool active, GameRenderer* r, glm::vec2& basis)
|
|
||||||
{
|
|
||||||
TextRenderer::TextInfo ti;
|
|
||||||
ti.font = font;
|
|
||||||
ti.screenPosition = basis;
|
|
||||||
ti.text = text;
|
|
||||||
ti.size = getHeight();
|
|
||||||
if( ! active )
|
|
||||||
{
|
|
||||||
ti.baseColour = glm::u8vec3(255);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ti.baseColour = glm::u8vec3(255, 255, 0);
|
|
||||||
}
|
|
||||||
r->text.renderText(ti);
|
|
||||||
basis.y += getHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void activate(float clickX, float clickY) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Entry : public MenuEntry
|
struct MenuEntry {
|
||||||
{
|
GameString text;
|
||||||
std::function<void(void)> callback;
|
float _size;
|
||||||
|
|
||||||
Entry(const GameString& title,
|
MenuEntry(const GameString& n, float size = 30.f)
|
||||||
std::function<void(void)> cb,
|
: text(n), _size(size) {
|
||||||
float size)
|
}
|
||||||
: MenuEntry(title, size)
|
|
||||||
, callback(cb)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void activate(float clickX, float clickY)
|
float getHeight() {
|
||||||
{
|
return _size;
|
||||||
RW_UNUSED(clickX);
|
}
|
||||||
RW_UNUSED(clickY);
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static std::shared_ptr<MenuEntry> lambda(const GameString& n, std::function<void (void)> callback, float size = 30.f)
|
virtual void draw(int font, bool active, GameRenderer* r,
|
||||||
{
|
glm::vec2& basis) {
|
||||||
return std::shared_ptr<MenuEntry>(new Entry(n, callback, size));
|
TextRenderer::TextInfo ti;
|
||||||
}
|
ti.font = font;
|
||||||
|
ti.screenPosition = basis;
|
||||||
|
ti.text = text;
|
||||||
|
ti.size = getHeight();
|
||||||
|
if (!active) {
|
||||||
|
ti.baseColour = glm::u8vec3(255);
|
||||||
|
} else {
|
||||||
|
ti.baseColour = glm::u8vec3(255, 255, 0);
|
||||||
|
}
|
||||||
|
r->text.renderText(ti);
|
||||||
|
basis.y += getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
static std::shared_ptr<MenuEntry> lambda(const std::string& n, std::function<void (void)> callback, float size = 30.f)
|
virtual void activate(float clickX, float clickY) = 0;
|
||||||
{
|
};
|
||||||
return lambda(GameStringUtil::fromString(n), callback, size);
|
|
||||||
}
|
struct Entry : public MenuEntry {
|
||||||
|
std::function<void(void)> callback;
|
||||||
std::vector<std::shared_ptr<MenuEntry>> entries;
|
|
||||||
|
Entry(const GameString& title, std::function<void(void)> cb, float size)
|
||||||
/**
|
: MenuEntry(title, size), callback(cb) {
|
||||||
* Active Entry index
|
}
|
||||||
*/
|
|
||||||
int activeEntry;
|
void activate(float clickX, float clickY) {
|
||||||
|
RW_UNUSED(clickX);
|
||||||
glm::vec2 offset;
|
RW_UNUSED(clickY);
|
||||||
|
callback();
|
||||||
void addEntry(std::shared_ptr<MenuEntry> entry)
|
}
|
||||||
{
|
};
|
||||||
entries.push_back(entry);
|
|
||||||
}
|
static std::shared_ptr<MenuEntry> lambda(const GameString& n,
|
||||||
|
std::function<void(void)> callback,
|
||||||
void draw(GameRenderer* r)
|
float size = 30.f) {
|
||||||
{
|
return std::shared_ptr<MenuEntry>(new Entry(n, callback, size));
|
||||||
glm::vec2 basis(offset);
|
}
|
||||||
for(size_t i = 0;
|
|
||||||
i < entries.size();
|
static std::shared_ptr<MenuEntry> lambda(const std::string& n,
|
||||||
++i)
|
std::function<void(void)> callback,
|
||||||
{
|
float size = 30.f) {
|
||||||
bool active = false;
|
return lambda(GameStringUtil::fromString(n), callback, size);
|
||||||
if(activeEntry >= 0 && i == (unsigned) activeEntry)
|
}
|
||||||
{
|
|
||||||
active = true;
|
std::vector<std::shared_ptr<MenuEntry>> entries;
|
||||||
}
|
|
||||||
entries[i]->draw(font, active, r, basis);
|
/**
|
||||||
}
|
* Active Entry index
|
||||||
}
|
*/
|
||||||
|
int activeEntry;
|
||||||
void hover(const float x, const float y)
|
|
||||||
{
|
glm::vec2 offset;
|
||||||
glm::vec2 c(x - offset.x, y - offset.y);
|
|
||||||
for(size_t i = 0;
|
void addEntry(std::shared_ptr<MenuEntry> entry) {
|
||||||
i < entries.size();
|
entries.push_back(entry);
|
||||||
++i)
|
}
|
||||||
{
|
|
||||||
if( c.y > 0.f && c.y < entries[i]->getHeight() ) {
|
void draw(GameRenderer* r) {
|
||||||
activeEntry = i;
|
glm::vec2 basis(offset);
|
||||||
return;
|
for (size_t i = 0; i < entries.size(); ++i) {
|
||||||
}
|
bool active = false;
|
||||||
else {
|
if (activeEntry >= 0 && i == (unsigned)activeEntry) {
|
||||||
c.y -= entries[i]->getHeight();
|
active = true;
|
||||||
}
|
}
|
||||||
}
|
entries[i]->draw(font, active, r, basis);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void click(const float x, const float y)
|
|
||||||
{
|
void hover(const float x, const float y) {
|
||||||
glm::vec2 c(x - offset.x, y - offset.y);
|
glm::vec2 c(x - offset.x, y - offset.y);
|
||||||
for(auto it = entries.begin();
|
for (size_t i = 0; i < entries.size(); ++i) {
|
||||||
it != entries.end();
|
if (c.y > 0.f && c.y < entries[i]->getHeight()) {
|
||||||
++it)
|
activeEntry = i;
|
||||||
{
|
return;
|
||||||
if( c.y > 0.f && c.y < (*it)->getHeight() ) {
|
} else {
|
||||||
(*it)->activate(c.x, c.y);
|
c.y -= entries[i]->getHeight();
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
c.y -= (*it)->getHeight();
|
|
||||||
}
|
void click(const float x, const float y) {
|
||||||
}
|
glm::vec2 c(x - offset.x, y - offset.y);
|
||||||
}
|
for (auto it = entries.begin(); it != entries.end(); ++it) {
|
||||||
|
if (c.y > 0.f && c.y < (*it)->getHeight()) {
|
||||||
// Activates the menu entry at the current active index.
|
(*it)->activate(c.x, c.y);
|
||||||
void activate()
|
return;
|
||||||
{
|
} else {
|
||||||
if(activeEntry >= 0 && (unsigned) activeEntry < entries.size()) {
|
c.y -= (*it)->getHeight();
|
||||||
entries[activeEntry]->activate(0.f, 0.f);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void move(int movement)
|
// Activates the menu entry at the current active index.
|
||||||
{
|
void activate() {
|
||||||
activeEntry += movement;
|
if (activeEntry >= 0 && (unsigned)activeEntry < entries.size()) {
|
||||||
if (activeEntry >= int(entries.size())) {
|
entries[activeEntry]->activate(0.f, 0.f);
|
||||||
activeEntry = 0;
|
}
|
||||||
}
|
}
|
||||||
else if (activeEntry < 0) {
|
|
||||||
activeEntry = entries.size() - 1;
|
void move(int movement) {
|
||||||
}
|
activeEntry += movement;
|
||||||
}
|
if (activeEntry >= int(entries.size())) {
|
||||||
|
activeEntry = 0;
|
||||||
|
} else if (activeEntry < 0) {
|
||||||
|
activeEntry = entries.size() - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
1597
rwgame/RWGame.cpp
1597
rwgame/RWGame.cpp
File diff suppressed because it is too large
Load Diff
@ -1,12 +1,12 @@
|
|||||||
#ifndef _RWGAME_HPP_
|
#ifndef _RWGAME_HPP_
|
||||||
#define _RWGAME_HPP_
|
#define _RWGAME_HPP_
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <core/Logger.hpp>
|
#include <core/Logger.hpp>
|
||||||
#include <engine/GameData.hpp>
|
#include <engine/GameData.hpp>
|
||||||
#include <engine/GameWorld.hpp>
|
#include <engine/GameWorld.hpp>
|
||||||
#include <render/GameRenderer.hpp>
|
#include <render/GameRenderer.hpp>
|
||||||
#include <script/ScriptMachine.hpp>
|
#include <script/ScriptMachine.hpp>
|
||||||
#include <chrono>
|
|
||||||
#include "game.hpp"
|
#include "game.hpp"
|
||||||
|
|
||||||
#include "GameConfig.hpp"
|
#include "GameConfig.hpp"
|
||||||
@ -16,131 +16,128 @@
|
|||||||
|
|
||||||
class PlayerController;
|
class PlayerController;
|
||||||
|
|
||||||
class RWGame
|
class RWGame {
|
||||||
{
|
Logger log;
|
||||||
Logger log;
|
GameConfig config{"openrw.ini"};
|
||||||
GameConfig config {"openrw.ini"};
|
GameState* state = nullptr;
|
||||||
GameState* state = nullptr;
|
GameData* data = nullptr;
|
||||||
GameData* data = nullptr;
|
GameWorld* world = nullptr;
|
||||||
GameWorld* world = nullptr;
|
// must be allocated after Logger setup.
|
||||||
// must be allocated after Logger setup.
|
GameRenderer* renderer = nullptr;
|
||||||
GameRenderer* renderer = nullptr;
|
|
||||||
ScriptMachine* script = nullptr;
|
ScriptMachine* script = nullptr;
|
||||||
GameWindow *window = nullptr;
|
GameWindow* window = nullptr;
|
||||||
// Background worker
|
// Background worker
|
||||||
WorkContext *work = nullptr;
|
WorkContext* work = nullptr;
|
||||||
std::chrono::steady_clock clock;
|
std::chrono::steady_clock clock;
|
||||||
std::chrono::steady_clock::time_point last_clock_time;
|
std::chrono::steady_clock::time_point last_clock_time;
|
||||||
|
|
||||||
bool inFocus = true;
|
bool inFocus = true;
|
||||||
ViewCamera lastCam, nextCam;
|
ViewCamera lastCam, nextCam;
|
||||||
bool showDebugStats = false;
|
bool showDebugStats = false;
|
||||||
bool showDebugPaths = false;
|
bool showDebugPaths = false;
|
||||||
bool showDebugPhysics = false;
|
bool showDebugPhysics = false;
|
||||||
int lastDraws; /// Number of draws issued for the last frame.
|
int lastDraws; /// Number of draws issued for the last frame.
|
||||||
|
|
||||||
std::string cheatInputWindow = std::string(32, ' ');
|
std::string cheatInputWindow = std::string(32, ' ');
|
||||||
|
|
||||||
|
float accum = 0.f;
|
||||||
|
float timescale = 1.f;
|
||||||
|
|
||||||
float accum = 0.f;
|
|
||||||
float timescale = 1.f;
|
|
||||||
public:
|
public:
|
||||||
|
RWGame(int argc, char* argv[]);
|
||||||
|
~RWGame();
|
||||||
|
|
||||||
RWGame(int argc, char* argv[]);
|
int run();
|
||||||
~RWGame();
|
|
||||||
|
|
||||||
int run();
|
/**
|
||||||
|
* Initalizes a new game
|
||||||
|
*/
|
||||||
|
void newGame();
|
||||||
|
|
||||||
/**
|
GameState* getState() const {
|
||||||
* Initalizes a new game
|
return state;
|
||||||
*/
|
}
|
||||||
void newGame();
|
|
||||||
|
|
||||||
GameState* getState() const
|
GameWorld* getWorld() const {
|
||||||
{
|
return world;
|
||||||
return state;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
GameWorld* getWorld() const
|
GameData* getGameData() const {
|
||||||
{
|
return data;
|
||||||
return world;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
GameData* getGameData() const
|
GameRenderer* getRenderer() const {
|
||||||
{
|
return renderer;
|
||||||
return data;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
GameRenderer* getRenderer() const
|
GameWindow& getWindow() {
|
||||||
{
|
return *window;
|
||||||
return renderer;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
GameWindow& getWindow()
|
ScriptMachine* getScript() const {
|
||||||
{
|
return script;
|
||||||
return *window;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ScriptMachine* getScript() const
|
const GameConfig& getConfig() const {
|
||||||
{
|
return config;
|
||||||
return script;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const GameConfig& getConfig() const
|
bool hitWorldRay(glm::vec3& hit, glm::vec3& normal,
|
||||||
{
|
GameObject** object = nullptr) {
|
||||||
return config;
|
auto vc = nextCam;
|
||||||
}
|
glm::vec3 from(vc.position.x, vc.position.y, vc.position.z);
|
||||||
|
glm::vec3 tmp = vc.rotation * glm::vec3(1000.f, 0.f, 0.f);
|
||||||
|
|
||||||
bool hitWorldRay(glm::vec3 &hit, glm::vec3 &normal, GameObject** object = nullptr)
|
return hitWorldRay(from, tmp, hit, normal, object);
|
||||||
{
|
}
|
||||||
auto vc = nextCam;
|
|
||||||
glm::vec3 from(vc.position.x, vc.position.y, vc.position.z);
|
|
||||||
glm::vec3 tmp = vc.rotation * glm::vec3(1000.f, 0.f, 0.f);
|
|
||||||
|
|
||||||
return hitWorldRay(from, tmp, hit, normal, object);
|
bool hitWorldRay(const glm::vec3& start, const glm::vec3& direction,
|
||||||
}
|
glm::vec3& hit, glm::vec3& normal,
|
||||||
|
GameObject** object = nullptr) {
|
||||||
|
auto from = btVector3(start.x, start.y, start.z);
|
||||||
|
auto to = btVector3(start.x + direction.x, start.y + direction.y,
|
||||||
|
start.z + direction.z);
|
||||||
|
btCollisionWorld::ClosestRayResultCallback ray(from, to);
|
||||||
|
|
||||||
bool hitWorldRay(const glm::vec3 &start, const glm::vec3 &direction, glm::vec3 &hit, glm::vec3 &normal, GameObject **object = nullptr)
|
world->dynamicsWorld->rayTest(from, to, ray);
|
||||||
{
|
if (ray.hasHit()) {
|
||||||
auto from = btVector3(start.x, start.y, start.z);
|
hit = glm::vec3(ray.m_hitPointWorld.x(), ray.m_hitPointWorld.y(),
|
||||||
auto to = btVector3(start.x+direction.x, start.y+direction.y, start.z+direction.z);
|
ray.m_hitPointWorld.z());
|
||||||
btCollisionWorld::ClosestRayResultCallback ray(from, to);
|
normal =
|
||||||
|
glm::vec3(ray.m_hitNormalWorld.x(), ray.m_hitNormalWorld.y(),
|
||||||
|
ray.m_hitNormalWorld.z());
|
||||||
|
if (object) {
|
||||||
|
*object = static_cast<GameObject*>(
|
||||||
|
ray.m_collisionObject->getUserPointer());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
world->dynamicsWorld->rayTest(from, to, ray);
|
void startScript(const std::string& name);
|
||||||
if( ray.hasHit() )
|
|
||||||
{
|
|
||||||
hit = glm::vec3(ray.m_hitPointWorld.x(), ray.m_hitPointWorld.y(),
|
|
||||||
ray.m_hitPointWorld.z());
|
|
||||||
normal = glm::vec3(ray.m_hitNormalWorld.x(), ray.m_hitNormalWorld.y(),
|
|
||||||
ray.m_hitNormalWorld.z());
|
|
||||||
if(object) {
|
|
||||||
*object = static_cast<GameObject*>(ray.m_collisionObject->getUserPointer());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void startScript(const std::string& name);
|
|
||||||
|
|
||||||
bool hasFocus() const { return inFocus; }
|
bool hasFocus() const {
|
||||||
|
return inFocus;
|
||||||
|
}
|
||||||
|
|
||||||
void saveGame(const std::string& savename);
|
void saveGame(const std::string& savename);
|
||||||
void loadGame(const std::string& savename);
|
void loadGame(const std::string& savename);
|
||||||
|
|
||||||
/** shortcut for getWorld()->state.player->getCharacter() */
|
/** shortcut for getWorld()->state.player->getCharacter() */
|
||||||
PlayerController* getPlayer();
|
PlayerController* getPlayer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void tick(float dt);
|
void tick(float dt);
|
||||||
void render(float alpha, float dt);
|
void render(float alpha, float dt);
|
||||||
|
|
||||||
void renderDebugStats(float time, Renderer::ProfileInfo& worldRenderTime);
|
|
||||||
void renderDebugPaths(float time);
|
|
||||||
void renderProfile();
|
|
||||||
|
|
||||||
void handleCheatInput(char symbol);
|
void renderDebugStats(float time, Renderer::ProfileInfo& worldRenderTime);
|
||||||
|
void renderDebugPaths(float time);
|
||||||
|
void renderProfile();
|
||||||
|
|
||||||
void globalKeyEvent(const SDL_Event& event);
|
void handleCheatInput(char symbol);
|
||||||
|
|
||||||
|
void globalKeyEvent(const SDL_Event& event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,57 +2,53 @@
|
|||||||
#include "RWGame.hpp"
|
#include "RWGame.hpp"
|
||||||
|
|
||||||
// This serves as the "initial" camera position.
|
// This serves as the "initial" camera position.
|
||||||
ViewCamera defaultView({-250.f, -550.f, 75.f}, glm::angleAxis(glm::radians(5.f), glm::vec3(0.f, 1.f, 0.f)));
|
ViewCamera defaultView({-250.f, -550.f, 75.f},
|
||||||
|
glm::angleAxis(glm::radians(5.f),
|
||||||
|
glm::vec3(0.f, 1.f, 0.f)));
|
||||||
|
|
||||||
|
void State::handleEvent(const SDL_Event& e) {
|
||||||
|
auto m = getCurrentMenu();
|
||||||
|
if (!m) return;
|
||||||
|
|
||||||
void State::handleEvent(const SDL_Event& e)
|
switch (e.type) {
|
||||||
{
|
case SDL_MOUSEBUTTONUP:
|
||||||
auto m = getCurrentMenu();
|
if (e.button.button == SDL_BUTTON_LEFT)
|
||||||
if(!m) return;
|
m->click(e.button.x, e.button.y);
|
||||||
|
break;
|
||||||
|
|
||||||
switch(e.type) {
|
case SDL_MOUSEMOTION:
|
||||||
case SDL_MOUSEBUTTONUP:
|
m->hover(e.motion.x, e.motion.y);
|
||||||
if (e.button.button == SDL_BUTTON_LEFT)
|
break;
|
||||||
m->click(e.button.x, e.button.y);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_KEYDOWN:
|
||||||
m->hover(e.motion.x, e.motion.y);
|
switch (e.key.keysym.sym) {
|
||||||
break;
|
case SDLK_UP:
|
||||||
|
m->move(-1);
|
||||||
|
break;
|
||||||
|
|
||||||
case SDL_KEYDOWN:
|
case SDLK_DOWN:
|
||||||
switch (e.key.keysym.sym) {
|
m->move(1);
|
||||||
case SDLK_UP:
|
break;
|
||||||
m->move(-1);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDLK_DOWN:
|
case SDLK_RETURN:
|
||||||
m->move(1);
|
m->activate();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case SDLK_RETURN:
|
}
|
||||||
m->activate();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ViewCamera& State::getCamera()
|
const ViewCamera& State::getCamera() {
|
||||||
{
|
return defaultView;
|
||||||
return defaultView;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool State::shouldWorldUpdate()
|
bool State::shouldWorldUpdate() {
|
||||||
{
|
return false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GameWorld* State::getWorld()
|
GameWorld* State::getWorld() {
|
||||||
{
|
return game->getWorld();
|
||||||
return game->getWorld();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GameWindow& State::getWindow()
|
GameWindow& State::getWindow() {
|
||||||
{
|
return game->getWindow();
|
||||||
return game->getWindow();
|
|
||||||
}
|
}
|
||||||
|
188
rwgame/State.hpp
188
rwgame/State.hpp
@ -1,123 +1,111 @@
|
|||||||
#ifndef _GAME_STATE_HPP_
|
#ifndef _GAME_STATE_HPP_
|
||||||
#define _GAME_STATE_HPP_
|
#define _GAME_STATE_HPP_
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <glm/gtc/quaternion.hpp>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <render/ViewCamera.hpp>
|
#include <render/ViewCamera.hpp>
|
||||||
|
#include "GameWindow.hpp"
|
||||||
#include "MenuSystem.hpp"
|
#include "MenuSystem.hpp"
|
||||||
#include <glm/gtc/quaternion.hpp>
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#include "SDL_events.h"
|
#include "SDL_events.h"
|
||||||
#include "GameWindow.hpp"
|
|
||||||
|
|
||||||
class RWGame;
|
class RWGame;
|
||||||
class GameWorld;
|
class GameWorld;
|
||||||
|
|
||||||
struct State
|
struct State {
|
||||||
{
|
// Helper for global menu behaviour
|
||||||
// Helper for global menu behaviour
|
Menu* currentMenu;
|
||||||
Menu* currentMenu;
|
Menu* nextMenu;
|
||||||
Menu* nextMenu;
|
|
||||||
|
|
||||||
RWGame* game;
|
RWGame* game;
|
||||||
|
|
||||||
State(RWGame* game)
|
|
||||||
: currentMenu(nullptr), nextMenu(nullptr), game(game) {}
|
|
||||||
|
|
||||||
virtual void enter() = 0;
|
|
||||||
virtual void exit() = 0;
|
|
||||||
|
|
||||||
virtual void tick(float dt) = 0;
|
|
||||||
|
|
||||||
virtual void draw(GameRenderer* r)
|
|
||||||
{
|
|
||||||
if(getCurrentMenu()) {
|
|
||||||
getCurrentMenu()->draw(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~State() {
|
|
||||||
if(getCurrentMenu()) {
|
|
||||||
delete getCurrentMenu();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void enterMenu(Menu* menu)
|
|
||||||
{
|
|
||||||
nextMenu = menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
Menu* getCurrentMenu()
|
|
||||||
{
|
|
||||||
if(nextMenu) {
|
|
||||||
if(currentMenu) {
|
|
||||||
delete currentMenu;
|
|
||||||
}
|
|
||||||
currentMenu = nextMenu;
|
|
||||||
nextMenu = nullptr;
|
|
||||||
}
|
|
||||||
return currentMenu;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void handleEvent(const SDL_Event& e);
|
State(RWGame* game) : currentMenu(nullptr), nextMenu(nullptr), game(game) {
|
||||||
|
}
|
||||||
|
|
||||||
virtual const ViewCamera& getCamera();
|
virtual void enter() = 0;
|
||||||
|
virtual void exit() = 0;
|
||||||
/**
|
|
||||||
* Returns false if the game world should not should
|
|
||||||
* not update while this state is active
|
|
||||||
*/
|
|
||||||
virtual bool shouldWorldUpdate();
|
|
||||||
|
|
||||||
GameWorld* getWorld();
|
virtual void tick(float dt) = 0;
|
||||||
GameWindow& getWindow();
|
|
||||||
|
virtual void draw(GameRenderer* r) {
|
||||||
|
if (getCurrentMenu()) {
|
||||||
|
getCurrentMenu()->draw(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~State() {
|
||||||
|
if (getCurrentMenu()) {
|
||||||
|
delete getCurrentMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void enterMenu(Menu* menu) {
|
||||||
|
nextMenu = menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu* getCurrentMenu() {
|
||||||
|
if (nextMenu) {
|
||||||
|
if (currentMenu) {
|
||||||
|
delete currentMenu;
|
||||||
|
}
|
||||||
|
currentMenu = nextMenu;
|
||||||
|
nextMenu = nullptr;
|
||||||
|
}
|
||||||
|
return currentMenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void handleEvent(const SDL_Event& e);
|
||||||
|
|
||||||
|
virtual const ViewCamera& getCamera();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns false if the game world should not should
|
||||||
|
* not update while this state is active
|
||||||
|
*/
|
||||||
|
virtual bool shouldWorldUpdate();
|
||||||
|
|
||||||
|
GameWorld* getWorld();
|
||||||
|
GameWindow& getWindow();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StateManager
|
struct StateManager {
|
||||||
{
|
static StateManager& get() {
|
||||||
static StateManager& get()
|
static StateManager m;
|
||||||
{
|
return m;
|
||||||
static StateManager m;
|
}
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::deque<State*> states;
|
|
||||||
|
|
||||||
void clear()
|
std::deque<State*> states;
|
||||||
{
|
|
||||||
states.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void enter(State* state)
|
|
||||||
{
|
|
||||||
states.push_back(state);
|
|
||||||
state->enter();
|
|
||||||
}
|
|
||||||
|
|
||||||
void exec(State* state)
|
void clear() {
|
||||||
{
|
states.clear();
|
||||||
exit();
|
}
|
||||||
enter(state);
|
|
||||||
}
|
void enter(State* state) {
|
||||||
|
states.push_back(state);
|
||||||
void tick(float dt)
|
state->enter();
|
||||||
{
|
}
|
||||||
states.back()->tick(dt);
|
|
||||||
}
|
void exec(State* state) {
|
||||||
|
exit();
|
||||||
void draw(GameRenderer* r)
|
enter(state);
|
||||||
{
|
}
|
||||||
states.back()->draw(r);
|
|
||||||
}
|
void tick(float dt) {
|
||||||
|
states.back()->tick(dt);
|
||||||
void exit()
|
}
|
||||||
{
|
|
||||||
// TODO: Resole states being leaked.
|
void draw(GameRenderer* r) {
|
||||||
states.back()->exit();
|
states.back()->draw(r);
|
||||||
states.pop_back();
|
}
|
||||||
if(states.size() > 0) {
|
|
||||||
states.back()->enter();
|
void exit() {
|
||||||
}
|
// TODO: Resole states being leaked.
|
||||||
}
|
states.back()->exit();
|
||||||
|
states.pop_back();
|
||||||
|
if (states.size() > 0) {
|
||||||
|
states.back()->enter();
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,20 +1,21 @@
|
|||||||
#ifndef GAME_HPP
|
#ifndef GAME_HPP
|
||||||
#define GAME_HPP
|
#define GAME_HPP
|
||||||
|
|
||||||
#include <objects/GameObject.hpp>
|
|
||||||
#include <engine/GameWorld.hpp>
|
#include <engine/GameWorld.hpp>
|
||||||
|
#include <objects/GameObject.hpp>
|
||||||
|
|
||||||
constexpr double PiOver180 = 3.1415926535897932384626433832795028/180;
|
constexpr double PiOver180 = 3.1415926535897932384626433832795028 / 180;
|
||||||
|
|
||||||
// TODO: Move all of this stuff so it's not just lying around.
|
// TODO: Move all of this stuff so it's not just lying around.
|
||||||
|
|
||||||
bool hitWorldRay(glm::vec3& hit, glm::vec3& normal, GameObject** object = nullptr);
|
bool hitWorldRay(glm::vec3& hit, glm::vec3& normal,
|
||||||
|
GameObject** object = nullptr);
|
||||||
bool hitWorldRay(const glm::vec3& start, const glm::vec3& direction,
|
bool hitWorldRay(const glm::vec3& start, const glm::vec3& direction,
|
||||||
glm::vec3& hit, glm::vec3& normal, GameObject** object = nullptr);
|
glm::vec3& hit, glm::vec3& normal,
|
||||||
|
GameObject** object = nullptr);
|
||||||
|
|
||||||
#define GAME_TIMESTEP (1.f/30.f)
|
#define GAME_TIMESTEP (1.f / 30.f)
|
||||||
#define GAME_WINDOW_WIDTH 800
|
#define GAME_WINDOW_WIDTH 800
|
||||||
#define GAME_WINDOW_HEIGHT 600
|
#define GAME_WINDOW_HEIGHT 600
|
||||||
|
|
||||||
#endif // GAME_HPP
|
#endif // GAME_HPP
|
||||||
|
|
||||||
|
@ -1,35 +1,34 @@
|
|||||||
|
#include <iostream>
|
||||||
#include "RWGame.hpp"
|
#include "RWGame.hpp"
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[]) {
|
||||||
{
|
try {
|
||||||
try {
|
RWGame game(argc, argv);
|
||||||
RWGame game(argc, argv);
|
|
||||||
|
|
||||||
return game.run();
|
return game.run();
|
||||||
} catch (std::invalid_argument& ex) {
|
} catch (std::invalid_argument& ex) {
|
||||||
// This exception is thrown when either an invalid command line option
|
// This exception is thrown when either an invalid command line option
|
||||||
// or a --help is found. The RWGame constructor prints a usage message
|
// or a --help is found. The RWGame constructor prints a usage message
|
||||||
// in this case and then throws this exception.
|
// in this case and then throws this exception.
|
||||||
return -2;
|
return -2;
|
||||||
} catch (std::runtime_error& ex) {
|
} catch (std::runtime_error& ex) {
|
||||||
// Catch runtime_error as these are fatal issues the user may want to
|
// Catch runtime_error as these are fatal issues the user may want to
|
||||||
// know about like corrupted files or GL initialisation failure.
|
// know about like corrupted files or GL initialisation failure.
|
||||||
// Catching other types (out_of_range, bad_alloc) would just make
|
// Catching other types (out_of_range, bad_alloc) would just make
|
||||||
// debugging them more difficult.
|
// debugging them more difficult.
|
||||||
|
|
||||||
const char* kErrorTitle = "Fatal Error";
|
const char* kErrorTitle = "Fatal Error";
|
||||||
|
|
||||||
std::cerr << kErrorTitle << "\n" << ex.what() << std::endl;
|
std::cerr << kErrorTitle << "\n" << ex.what() << std::endl;
|
||||||
|
|
||||||
if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, kErrorTitle,
|
if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, kErrorTitle,
|
||||||
ex.what(), NULL) < 0) {
|
ex.what(), NULL) < 0) {
|
||||||
SDL_Log("Failed to show message box\n");
|
SDL_Log("Failed to show message box\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user