mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 10:22:52 +01:00
clang-format files in rwgame/states
This commit is contained in:
parent
e39ee21ca8
commit
a403cc87b7
@ -1,18 +1,13 @@
|
||||
#include "BenchmarkState.hpp"
|
||||
#include "RWGame.hpp"
|
||||
#include <engine/GameState.hpp>
|
||||
#include <fstream>
|
||||
#include "RWGame.hpp"
|
||||
|
||||
BenchmarkState::BenchmarkState(RWGame* game, const std::string& benchfile)
|
||||
: State(game)
|
||||
, benchfile(benchfile)
|
||||
, benchmarkTime(0.f)
|
||||
, frameCounter(0)
|
||||
{
|
||||
: State(game), benchfile(benchfile), benchmarkTime(0.f), frameCounter(0) {
|
||||
}
|
||||
|
||||
void BenchmarkState::enter()
|
||||
{
|
||||
void BenchmarkState::enter() {
|
||||
getWindow().hideCursor();
|
||||
|
||||
std::ifstream benchstream(benchfile);
|
||||
@ -20,7 +15,7 @@ void BenchmarkState::enter()
|
||||
unsigned int clockHour;
|
||||
unsigned int clockMinute;
|
||||
benchstream >> clockHour;
|
||||
benchstream.seekg(1,std::ios_base::cur);
|
||||
benchstream.seekg(1, std::ios_base::cur);
|
||||
benchstream >> clockMinute;
|
||||
|
||||
game->getWorld()->state->basic.gameHour = clockHour;
|
||||
@ -28,8 +23,7 @@ void BenchmarkState::enter()
|
||||
|
||||
float time = 0.f;
|
||||
glm::vec3 tmpPos;
|
||||
while (benchstream)
|
||||
{
|
||||
while (benchstream) {
|
||||
TrackPoint point;
|
||||
benchstream >> point.time;
|
||||
if (!benchstream) break;
|
||||
@ -61,26 +55,22 @@ void BenchmarkState::enter()
|
||||
std::cout << "Loaded " << track.size() << " points" << std::endl;
|
||||
}
|
||||
|
||||
void BenchmarkState::exit()
|
||||
{
|
||||
void BenchmarkState::exit() {
|
||||
std::cout << "Results =============\n"
|
||||
<< "Benchmark: " << benchfile << "\n"
|
||||
<< "Frames: " << frameCounter << "\n"
|
||||
<< "Duration: " << duration << " seconds\n"
|
||||
<< "Avg frametime: " << std::setprecision(3) << (duration/frameCounter)
|
||||
<< " (" << (frameCounter/duration) << " fps)" << std::endl;
|
||||
<< "Avg frametime: " << std::setprecision(3)
|
||||
<< (duration / frameCounter) << " (" << (frameCounter / duration)
|
||||
<< " fps)" << std::endl;
|
||||
}
|
||||
|
||||
void BenchmarkState::tick(float dt)
|
||||
{
|
||||
if (track.size() > 0)
|
||||
{
|
||||
void BenchmarkState::tick(float dt) {
|
||||
if (track.size() > 0) {
|
||||
TrackPoint& a = track.front();
|
||||
TrackPoint& b = track.back();
|
||||
for (TrackPoint& p : track)
|
||||
{
|
||||
if (benchmarkTime < p.time)
|
||||
{
|
||||
for (TrackPoint& p : track) {
|
||||
if (benchmarkTime < p.time) {
|
||||
b = p;
|
||||
break;
|
||||
}
|
||||
@ -89,8 +79,7 @@ void BenchmarkState::tick(float dt)
|
||||
if (benchmarkTime > duration) {
|
||||
StateManager::get().exit();
|
||||
}
|
||||
if (b.time != a.time)
|
||||
{
|
||||
if (b.time != a.time) {
|
||||
float alpha = (benchmarkTime - a.time) / (b.time - a.time);
|
||||
trackCam.position = glm::mix(a.position, b.position, alpha);
|
||||
trackCam.rotation = glm::slerp(a.angle, b.angle, alpha);
|
||||
@ -99,18 +88,15 @@ void BenchmarkState::tick(float dt)
|
||||
}
|
||||
}
|
||||
|
||||
void BenchmarkState::draw(GameRenderer* r)
|
||||
{
|
||||
void BenchmarkState::draw(GameRenderer* r) {
|
||||
frameCounter++;
|
||||
State::draw(r);
|
||||
}
|
||||
|
||||
void BenchmarkState::handleEvent(const SDL_Event& e)
|
||||
{
|
||||
void BenchmarkState::handleEvent(const SDL_Event& e) {
|
||||
State::handleEvent(e);
|
||||
}
|
||||
|
||||
const ViewCamera &BenchmarkState::getCamera()
|
||||
{
|
||||
const ViewCamera& BenchmarkState::getCamera() {
|
||||
return trackCam;
|
||||
}
|
||||
|
@ -3,8 +3,7 @@
|
||||
|
||||
#include "State.hpp"
|
||||
|
||||
class BenchmarkState : public State
|
||||
{
|
||||
class BenchmarkState : public State {
|
||||
struct TrackPoint {
|
||||
float time;
|
||||
glm::vec3 position;
|
||||
@ -19,6 +18,7 @@ class BenchmarkState : public State
|
||||
float benchmarkTime;
|
||||
float duration;
|
||||
uint32_t frameCounter;
|
||||
|
||||
public:
|
||||
BenchmarkState(RWGame* game, const std::string& benchfile);
|
||||
|
||||
|
@ -1,40 +1,36 @@
|
||||
#include "DebugState.hpp"
|
||||
#include "RWGame.hpp"
|
||||
#include <ai/PlayerController.hpp>
|
||||
#include <data/WeaponData.hpp>
|
||||
#include <engine/GameState.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
#include <items/InventoryItem.hpp>
|
||||
#include <objects/CharacterObject.hpp>
|
||||
#include <objects/InstanceObject.hpp>
|
||||
#include <objects/VehicleObject.hpp>
|
||||
#include <engine/GameState.hpp>
|
||||
#include <items/InventoryItem.hpp>
|
||||
#include <data/WeaponData.hpp>
|
||||
#include <sstream>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
#include "RWGame.hpp"
|
||||
|
||||
constexpr float kDebugEntryHeight = 14.f;
|
||||
const glm::vec2 kDebugMenuOffset = glm::vec2(10.f, 50.f);
|
||||
|
||||
static void jumpCharacter(RWGame* game, CharacterObject* player, const glm::vec3& target, bool ground = true)
|
||||
{
|
||||
static void jumpCharacter(RWGame* game, CharacterObject* player,
|
||||
const glm::vec3& target, bool ground = true) {
|
||||
glm::vec3 newPosition = target;
|
||||
if (ground) {
|
||||
newPosition = game->getWorld()->getGroundAtPosition(newPosition) + glm::vec3(0.f, 0.f, 1.f);
|
||||
newPosition = game->getWorld()->getGroundAtPosition(newPosition) +
|
||||
glm::vec3(0.f, 0.f, 1.f);
|
||||
}
|
||||
if( player )
|
||||
{
|
||||
if( player->getCurrentVehicle() )
|
||||
{
|
||||
if (player) {
|
||||
if (player->getCurrentVehicle()) {
|
||||
player->getCurrentVehicle()->setPosition(newPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
player->setPosition(newPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Menu* DebugState::createDebugMenu()
|
||||
{
|
||||
Menu* DebugState::createDebugMenu() {
|
||||
CharacterObject* player = nullptr;
|
||||
if (game->getPlayer()) {
|
||||
player = game->getPlayer()->getCharacter();
|
||||
@ -84,53 +80,62 @@ Menu* DebugState::createDebugMenu()
|
||||
}, entryHeight));
|
||||
}
|
||||
#endif
|
||||
m->addEntry(Menu::lambda("Jump to Debug Camera", [=] {
|
||||
jumpCharacter(game, player, _debugCam.position + _debugCam.rotation * glm::vec3(3.f, 0.f, 0.f), false);
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Jump to Debug Camera",
|
||||
[=] {
|
||||
jumpCharacter(game, player,
|
||||
_debugCam.position +
|
||||
_debugCam.rotation *
|
||||
glm::vec3(3.f, 0.f, 0.f),
|
||||
false);
|
||||
},
|
||||
kDebugEntryHeight));
|
||||
|
||||
m->addEntry(Menu::lambda("-Map", [=] {
|
||||
this->enterMenu(createMapMenu());
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("-Vehicles", [=] {
|
||||
this->enterMenu(createVehicleMenu());
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("-AI", [=] {
|
||||
this->enterMenu(createAIMenu());
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("-Weapons", [=] {
|
||||
this->enterMenu(createWeaponMenu());
|
||||
}, kDebugEntryHeight));
|
||||
|
||||
m->addEntry(Menu::lambda("Set Super Jump", [=] {
|
||||
player->setJumpSpeed(20.f);
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Set Normal Jump", [=] {
|
||||
player->setJumpSpeed(CharacterObject::DefaultJumpSpeed);
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Full Health", [=] {
|
||||
player->getCurrentState().health = 100.f;
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Full Armour", [=] {
|
||||
player->getCurrentState().armour = 100.f;
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Cull Here", [=] {
|
||||
game->getRenderer()->setCullOverride(true, _debugCam);
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("-Map", [=] { this->enterMenu(createMapMenu()); },
|
||||
kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("-Vehicles",
|
||||
[=] { this->enterMenu(createVehicleMenu()); },
|
||||
kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("-AI", [=] { this->enterMenu(createAIMenu()); },
|
||||
kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("-Weapons",
|
||||
[=] { this->enterMenu(createWeaponMenu()); },
|
||||
kDebugEntryHeight));
|
||||
|
||||
m->addEntry(Menu::lambda("Set Super Jump",
|
||||
[=] { player->setJumpSpeed(20.f); },
|
||||
kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda(
|
||||
"Set Normal Jump",
|
||||
[=] { player->setJumpSpeed(CharacterObject::DefaultJumpSpeed); },
|
||||
kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Full Health",
|
||||
[=] { player->getCurrentState().health = 100.f; },
|
||||
kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Full Armour",
|
||||
[=] { player->getCurrentState().armour = 100.f; },
|
||||
kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda(
|
||||
"Cull Here",
|
||||
[=] { game->getRenderer()->setCullOverride(true, _debugCam); },
|
||||
kDebugEntryHeight));
|
||||
|
||||
// Optional block if the player is in a vehicle
|
||||
auto cv = player->getCurrentVehicle();
|
||||
if(cv) {
|
||||
m->addEntry(Menu::lambda("Flip vehicle", [=] {
|
||||
cv->setRotation(cv->getRotation() * glm::quat(glm::vec3(0.f, glm::pi<float>(), 0.f)));
|
||||
}, kDebugEntryHeight));
|
||||
if (cv) {
|
||||
m->addEntry(Menu::lambda(
|
||||
"Flip vehicle",
|
||||
[=] {
|
||||
cv->setRotation(
|
||||
cv->getRotation() *
|
||||
glm::quat(glm::vec3(0.f, glm::pi<float>(), 0.f)));
|
||||
},
|
||||
kDebugEntryHeight));
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
Menu* DebugState::createMapMenu()
|
||||
{
|
||||
Menu* DebugState::createMapMenu() {
|
||||
CharacterObject* player = nullptr;
|
||||
if (game->getPlayer()) {
|
||||
player = game->getPlayer()->getCharacter();
|
||||
@ -139,102 +144,87 @@ Menu* DebugState::createMapMenu()
|
||||
Menu* m = new Menu(2);
|
||||
m->offset = kDebugMenuOffset;
|
||||
|
||||
m->addEntry(Menu::lambda("Back", [=] {
|
||||
this->enterMenu(createDebugMenu());
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Back",
|
||||
[=] { this->enterMenu(createDebugMenu()); },
|
||||
kDebugEntryHeight));
|
||||
|
||||
m->addEntry(Menu::lambda("Jump to Docks", [=] {
|
||||
jumpCharacter(game, player, glm::vec3(1390.f, -837.f, 100.f));
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Jump to Garage", [=] {
|
||||
jumpCharacter(game, player, glm::vec3(270.f, -605.f, 40.f));
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Jump to Airport", [=] {
|
||||
jumpCharacter(game, player, glm::vec3(-950.f, -980.f, 12.f));
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Jump to Hideout", [=] {
|
||||
jumpCharacter(game, player, glm::vec3(875.0, -309.0, 100.0));
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Jump to Luigi's", [=] {
|
||||
jumpCharacter(game, player, glm::vec3(902.75, -425.56, 100.0));
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Jump to Hospital", [=] {
|
||||
m->addEntry(Menu::lambda(
|
||||
"Jump to Docks",
|
||||
[=] { jumpCharacter(game, player, glm::vec3(1390.f, -837.f, 100.f)); },
|
||||
kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda(
|
||||
"Jump to Garage",
|
||||
[=] { jumpCharacter(game, player, glm::vec3(270.f, -605.f, 40.f)); },
|
||||
kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda(
|
||||
"Jump to Airport",
|
||||
[=] { jumpCharacter(game, player, glm::vec3(-950.f, -980.f, 12.f)); },
|
||||
kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda(
|
||||
"Jump to Hideout",
|
||||
[=] { jumpCharacter(game, player, glm::vec3(875.0, -309.0, 100.0)); },
|
||||
kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda(
|
||||
"Jump to Luigi's",
|
||||
[=] { jumpCharacter(game, player, glm::vec3(902.75, -425.56, 100.0)); },
|
||||
kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda(
|
||||
"Jump to Hospital",
|
||||
[=] {
|
||||
jumpCharacter(game, player, glm::vec3(1123.77, -569.15, 100.0));
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Unsolid garage doors", [=] {
|
||||
},
|
||||
kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda(
|
||||
"Unsolid garage doors",
|
||||
[=] {
|
||||
|
||||
std::vector<std::string> garageDoorModels {
|
||||
"8ballsuburbandoor",
|
||||
"amcogaragedoor",
|
||||
"bankjobdoor",
|
||||
"bombdoor",
|
||||
"crushercrush",
|
||||
"crushertop",
|
||||
"door2_garage",
|
||||
"door3_garage",
|
||||
"door4_garage",
|
||||
"door_bombshop",
|
||||
"door_col_compnd_01",
|
||||
"door_col_compnd_02",
|
||||
"door_col_compnd_03",
|
||||
"door_col_compnd_04",
|
||||
"door_col_compnd_05",
|
||||
"door_jmsgrage",
|
||||
"door_sfehousegrge",
|
||||
"double_garage_dr",
|
||||
"impex_door",
|
||||
"impexpsubgrgdoor",
|
||||
"ind_plyrwoor",
|
||||
"ind_slidedoor",
|
||||
"jamesgrge_kb",
|
||||
"leveldoor2",
|
||||
"oddjgaragdoor",
|
||||
"plysve_gragedoor",
|
||||
"SalvGarage",
|
||||
"shedgaragedoor",
|
||||
"Sub_sprayshopdoor",
|
||||
"towergaragedoor1",
|
||||
"towergaragedoor2",
|
||||
"towergaragedoor3",
|
||||
"vheistlocdoor"
|
||||
};
|
||||
std::vector<std::string> garageDoorModels{
|
||||
"8ballsuburbandoor", "amcogaragedoor",
|
||||
"bankjobdoor", "bombdoor",
|
||||
"crushercrush", "crushertop",
|
||||
"door2_garage", "door3_garage",
|
||||
"door4_garage", "door_bombshop",
|
||||
"door_col_compnd_01", "door_col_compnd_02",
|
||||
"door_col_compnd_03", "door_col_compnd_04",
|
||||
"door_col_compnd_05", "door_jmsgrage",
|
||||
"door_sfehousegrge", "double_garage_dr",
|
||||
"impex_door", "impexpsubgrgdoor",
|
||||
"ind_plyrwoor", "ind_slidedoor",
|
||||
"jamesgrge_kb", "leveldoor2",
|
||||
"oddjgaragdoor", "plysve_gragedoor",
|
||||
"SalvGarage", "shedgaragedoor",
|
||||
"Sub_sprayshopdoor", "towergaragedoor1",
|
||||
"towergaragedoor2", "towergaragedoor3",
|
||||
"vheistlocdoor"};
|
||||
|
||||
auto gw = game->getWorld();
|
||||
for(auto& i : gw->instancePool.objects) {
|
||||
for (auto& i : gw->instancePool.objects) {
|
||||
auto obj = static_cast<InstanceObject*>(i.second);
|
||||
if (std::find(garageDoorModels.begin(), garageDoorModels.end(), obj->model->name) != garageDoorModels.end()) {
|
||||
if (std::find(garageDoorModels.begin(), garageDoorModels.end(),
|
||||
obj->model->name) != garageDoorModels.end()) {
|
||||
obj->setSolid(false);
|
||||
}
|
||||
}
|
||||
}, kDebugEntryHeight));
|
||||
},
|
||||
kDebugEntryHeight));
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
Menu* DebugState::createVehicleMenu()
|
||||
{
|
||||
Menu* DebugState::createVehicleMenu() {
|
||||
Menu* m = new Menu(2);
|
||||
m->offset = kDebugMenuOffset;
|
||||
|
||||
m->addEntry(Menu::lambda("Back", [=] {
|
||||
this->enterMenu(createDebugMenu());
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Back",
|
||||
[=] { this->enterMenu(createDebugMenu()); },
|
||||
kDebugEntryHeight));
|
||||
|
||||
const std::map<std::string, int> kVehicleTypes = {
|
||||
{"Landstalker", 90},
|
||||
{"Taxi", 110},
|
||||
{"Firetruck", 97},
|
||||
{"Police", 116},
|
||||
{"Ambulance", 106},
|
||||
{"Bobcat", 112},
|
||||
{"Banshee", 119},
|
||||
{"Rhino", 122},
|
||||
{"Barracks", 123},
|
||||
{"Rumpo", 130},
|
||||
{"Columbian", 138},
|
||||
{"Dodo", 126},
|
||||
{"Speeder", 142},
|
||||
{"Yakuza", 136},
|
||||
{"Landstalker", 90}, {"Taxi", 110}, {"Firetruck", 97},
|
||||
{"Police", 116}, {"Ambulance", 106}, {"Bobcat", 112},
|
||||
{"Banshee", 119}, {"Rhino", 122}, {"Barracks", 123},
|
||||
{"Rumpo", 130}, {"Columbian", 138}, {"Dodo", 126},
|
||||
{"Speeder", 142}, {"Yakuza", 136},
|
||||
};
|
||||
|
||||
for (auto& e : kVehicleTypes) {
|
||||
@ -245,31 +235,28 @@ Menu* DebugState::createVehicleMenu()
|
||||
return m;
|
||||
}
|
||||
|
||||
Menu* DebugState::createAIMenu()
|
||||
{
|
||||
Menu* DebugState::createAIMenu() {
|
||||
Menu* m = new Menu(2);
|
||||
m->offset = kDebugMenuOffset;
|
||||
|
||||
m->addEntry(Menu::lambda("Back", [=] {
|
||||
this->enterMenu(createDebugMenu());
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Back",
|
||||
[=] { this->enterMenu(createDebugMenu()); },
|
||||
kDebugEntryHeight));
|
||||
|
||||
const std::map<std::string, int> kPedTypes = {
|
||||
{"Triad", 12},
|
||||
{"Cop", 1},
|
||||
{"SWAT", 2},
|
||||
{"FBI", 3},
|
||||
{"Fireman", 6},
|
||||
{"Construction", 74},
|
||||
{"Triad", 12}, {"Cop", 1}, {"SWAT", 2},
|
||||
{"FBI", 3}, {"Fireman", 6}, {"Construction", 74},
|
||||
};
|
||||
|
||||
for (auto& e : kPedTypes) {
|
||||
m->addEntry(Menu::lambda(e.first + " Follower", [=] {
|
||||
spawnFollower(e.second);
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda(e.first + " Follower",
|
||||
[=] { spawnFollower(e.second); },
|
||||
kDebugEntryHeight));
|
||||
}
|
||||
|
||||
m->addEntry(Menu::lambda("Kill All Peds", [=] {
|
||||
m->addEntry(Menu::lambda(
|
||||
"Kill All Peds",
|
||||
[=] {
|
||||
for (auto& p : game->getWorld()->pedestrianPool.objects) {
|
||||
if (p.second->getLifetime() == GameObject::PlayerLifetime) {
|
||||
continue;
|
||||
@ -278,52 +265,45 @@ Menu* DebugState::createAIMenu()
|
||||
p.second->getPosition(), 100.f,
|
||||
GameObject::DamageInfo::Explosion, 0.f});
|
||||
}
|
||||
}, kDebugEntryHeight));
|
||||
},
|
||||
kDebugEntryHeight));
|
||||
return m;
|
||||
}
|
||||
|
||||
Menu*DebugState::createWeaponMenu()
|
||||
{
|
||||
Menu* DebugState::createWeaponMenu() {
|
||||
Menu* m = new Menu(2);
|
||||
m->offset = kDebugMenuOffset;
|
||||
|
||||
m->addEntry(Menu::lambda("Back", [=] {
|
||||
this->enterMenu(createDebugMenu());
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(Menu::lambda("Back",
|
||||
[=] { this->enterMenu(createDebugMenu()); },
|
||||
kDebugEntryHeight));
|
||||
|
||||
for (int i = 1; i < maxInventorySlots; ++i) {
|
||||
auto item = getWorld()->getInventoryItem(i);
|
||||
auto& name = getWorld()->data->weaponData[i]->name;
|
||||
m->addEntry(Menu::lambda(name, [=] {
|
||||
giveItem(item);
|
||||
}, kDebugEntryHeight));
|
||||
m->addEntry(
|
||||
Menu::lambda(name, [=] { giveItem(item); }, kDebugEntryHeight));
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
DebugState::DebugState(RWGame* game, const glm::vec3& vp, const glm::quat& vd)
|
||||
: State(game)
|
||||
, _invertedY(game->getConfig().getInputInvertY())
|
||||
{
|
||||
: State(game), _invertedY(game->getConfig().getInputInvertY()) {
|
||||
this->enterMenu(createDebugMenu());
|
||||
|
||||
_debugCam.position = vp;
|
||||
_debugCam.rotation = vd;
|
||||
}
|
||||
|
||||
void DebugState::enter()
|
||||
{
|
||||
void DebugState::enter() {
|
||||
getWindow().showCursor();
|
||||
}
|
||||
|
||||
void DebugState::exit()
|
||||
{
|
||||
|
||||
void DebugState::exit() {
|
||||
}
|
||||
|
||||
void DebugState::tick(float dt)
|
||||
{
|
||||
void DebugState::tick(float dt) {
|
||||
/*if(debugObject) {
|
||||
auto p = debugObject->getPosition();
|
||||
ss << "Position: " << p.x << " " << p.y << " " << p.z << std::endl;
|
||||
@ -338,7 +318,8 @@ void DebugState::tick(float dt)
|
||||
for(auto itt = g->materials.begin(); itt != g->materials.end();
|
||||
++itt)
|
||||
{
|
||||
for(auto tit = itt->textures.begin(); tit != itt->textures.end();
|
||||
for(auto tit = itt->textures.begin(); tit !=
|
||||
itt->textures.end();
|
||||
++tit)
|
||||
{
|
||||
ss << " " << tit->name << std::endl;
|
||||
@ -353,15 +334,16 @@ void DebugState::tick(float dt)
|
||||
}*/
|
||||
|
||||
if (_freeLook) {
|
||||
_debugCam.rotation = glm::angleAxis(_debugLook.x, glm::vec3(0.f, 0.f, 1.f))
|
||||
* glm::angleAxis(_debugLook.y, glm::vec3(0.f, 1.f, 0.f));
|
||||
_debugCam.rotation =
|
||||
glm::angleAxis(_debugLook.x, glm::vec3(0.f, 0.f, 1.f)) *
|
||||
glm::angleAxis(_debugLook.y, glm::vec3(0.f, 1.f, 0.f));
|
||||
|
||||
_debugCam.position += _debugCam.rotation * _movement * dt * (_sonicMode ? 500.f : 50.f);
|
||||
_debugCam.position +=
|
||||
_debugCam.rotation * _movement * dt * (_sonicMode ? 500.f : 50.f);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugState::draw(GameRenderer* r)
|
||||
{
|
||||
void DebugState::draw(GameRenderer* r) {
|
||||
// Draw useful information like camera position.
|
||||
std::stringstream ss;
|
||||
ss << "Camera Position: " << glm::to_string(_debugCam.position);
|
||||
@ -369,7 +351,7 @@ void DebugState::draw(GameRenderer* r)
|
||||
TextRenderer::TextInfo ti;
|
||||
ti.text = GameStringUtil::fromString(ss.str());
|
||||
ti.font = 2;
|
||||
ti.screenPosition = glm::vec2( 10.f, 10.f );
|
||||
ti.screenPosition = glm::vec2(10.f, 10.f);
|
||||
ti.size = 15.f;
|
||||
ti.baseColour = glm::u8vec3(255);
|
||||
r->text.renderText(ti);
|
||||
@ -377,11 +359,10 @@ void DebugState::draw(GameRenderer* r)
|
||||
State::draw(r);
|
||||
}
|
||||
|
||||
void DebugState::handleEvent(const SDL_Event& event)
|
||||
{
|
||||
switch(event.type) {
|
||||
void DebugState::handleEvent(const SDL_Event& event) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
switch(event.key.keysym.sym) {
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
StateManager::get().exit();
|
||||
break;
|
||||
@ -389,13 +370,13 @@ void DebugState::handleEvent(const SDL_Event& event)
|
||||
_movement.x = 1.f;
|
||||
break;
|
||||
case SDLK_s:
|
||||
_movement.x =-1.f;
|
||||
_movement.x = -1.f;
|
||||
break;
|
||||
case SDLK_a:
|
||||
_movement.y = 1.f;
|
||||
break;
|
||||
case SDLK_d:
|
||||
_movement.y =-1.f;
|
||||
_movement.y = -1.f;
|
||||
break;
|
||||
case SDLK_f:
|
||||
_freeLook = !_freeLook;
|
||||
@ -410,13 +391,14 @@ void DebugState::handleEvent(const SDL_Event& event)
|
||||
case SDLK_LSHIFT:
|
||||
_sonicMode = true;
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
switch(event.key.keysym.sym) {
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_w:
|
||||
case SDLK_s:
|
||||
_movement.x = 0.f;
|
||||
@ -428,20 +410,20 @@ void DebugState::handleEvent(const SDL_Event& event)
|
||||
case SDLK_LSHIFT:
|
||||
_sonicMode = false;
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
if (game->hasFocus())
|
||||
{
|
||||
if (game->hasFocus()) {
|
||||
glm::ivec2 screenSize = getWindow().getSize();
|
||||
glm::vec2 mouseMove(event.motion.xrel / static_cast<float>(screenSize.x),
|
||||
glm::vec2 mouseMove(
|
||||
event.motion.xrel / static_cast<float>(screenSize.x),
|
||||
event.motion.yrel / static_cast<float>(screenSize.y));
|
||||
|
||||
if (!_invertedY)
|
||||
mouseMove.y = -mouseMove.y;
|
||||
if (!_invertedY) mouseMove.y = -mouseMove.y;
|
||||
|
||||
_debugLook.x -= mouseMove.x;
|
||||
|
||||
@ -450,23 +432,22 @@ void DebugState::handleEvent(const SDL_Event& event)
|
||||
}
|
||||
break;
|
||||
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
State::handleEvent(event);
|
||||
}
|
||||
|
||||
void DebugState::printCameraDetails()
|
||||
{
|
||||
std::cout << " " << _debugCam.position.x << " " << _debugCam.position.y << " " << _debugCam.position.z
|
||||
<< " " << _debugCam.rotation.x << " " << _debugCam.rotation.y << " " << _debugCam.rotation.z
|
||||
void DebugState::printCameraDetails() {
|
||||
std::cout << " " << _debugCam.position.x << " " << _debugCam.position.y
|
||||
<< " " << _debugCam.position.z << " " << _debugCam.rotation.x
|
||||
<< " " << _debugCam.rotation.y << " " << _debugCam.rotation.z
|
||||
<< " " << _debugCam.rotation.w << std::endl;
|
||||
}
|
||||
|
||||
void DebugState::spawnVehicle(unsigned int id)
|
||||
{
|
||||
void DebugState::spawnVehicle(unsigned int id) {
|
||||
auto ch = game->getPlayer()->getCharacter();
|
||||
if (!ch)
|
||||
return;
|
||||
if (!ch) return;
|
||||
|
||||
auto playerRot = ch->getRotation();
|
||||
auto spawnPos = ch->getPosition();
|
||||
@ -476,15 +457,15 @@ void DebugState::spawnVehicle(unsigned int id)
|
||||
getWorld()->createVehicle(id, spawnPos, spawnRot);
|
||||
}
|
||||
|
||||
void DebugState::spawnFollower(unsigned int id)
|
||||
{
|
||||
void DebugState::spawnFollower(unsigned int id) {
|
||||
auto ch = game->getPlayer()->getCharacter();
|
||||
if(! ch) return;
|
||||
if (!ch) return;
|
||||
|
||||
glm::vec3 fwd = ch->rotation * glm::vec3(0.f, 1.f, 0.f);
|
||||
|
||||
glm::vec3 hit, normal;
|
||||
if(game->hitWorldRay(ch->position + (fwd * 10.f), {0.f, 0.f, -2.f}, hit, normal)) {
|
||||
if (game->hitWorldRay(ch->position + (fwd * 10.f), {0.f, 0.f, -2.f}, hit,
|
||||
normal)) {
|
||||
auto spawnPos = hit + normal;
|
||||
auto follower = game->getWorld()->createPedestrian(id, spawnPos);
|
||||
jumpCharacter(game, follower, spawnPos);
|
||||
@ -493,8 +474,7 @@ void DebugState::spawnFollower(unsigned int id)
|
||||
}
|
||||
}
|
||||
|
||||
void DebugState::giveItem(InventoryItem* item)
|
||||
{
|
||||
void DebugState::giveItem(InventoryItem* item) {
|
||||
CharacterObject* player = nullptr;
|
||||
if (game->getPlayer()) {
|
||||
player = game->getPlayer()->getCharacter();
|
||||
@ -502,14 +482,12 @@ void DebugState::giveItem(InventoryItem* item)
|
||||
|
||||
if (player) {
|
||||
player->addToInventory(item);
|
||||
auto& wep =
|
||||
player->getCurrentState().weapons[item->getInventorySlot()];
|
||||
auto& wep = player->getCurrentState().weapons[item->getInventorySlot()];
|
||||
wep.bulletsTotal = 100;
|
||||
wep.bulletsClip = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const ViewCamera &DebugState::getCamera()
|
||||
{
|
||||
const ViewCamera& DebugState::getCamera() {
|
||||
return _debugCam;
|
||||
}
|
||||
|
@ -3,8 +3,7 @@
|
||||
|
||||
#include "State.hpp"
|
||||
|
||||
class DebugState : public State
|
||||
{
|
||||
class DebugState : public State {
|
||||
ViewCamera _debugCam;
|
||||
glm::vec3 _movement;
|
||||
glm::vec2 _debugLook;
|
||||
@ -19,7 +18,8 @@ class DebugState : public State
|
||||
Menu* createWeaponMenu();
|
||||
|
||||
public:
|
||||
DebugState(RWGame* game, const glm::vec3& vp = {}, const glm::quat& vd = {});
|
||||
DebugState(RWGame* game, const glm::vec3& vp = {},
|
||||
const glm::quat& vd = {});
|
||||
|
||||
virtual void enter();
|
||||
virtual void exit();
|
||||
|
@ -1,20 +1,20 @@
|
||||
#include "IngameState.hpp"
|
||||
#include "RWGame.hpp"
|
||||
#include "PauseState.hpp"
|
||||
#include "DebugState.hpp"
|
||||
#include "DrawUI.hpp"
|
||||
#include "PauseState.hpp"
|
||||
#include "RWGame.hpp"
|
||||
|
||||
#include <ai/PlayerController.hpp>
|
||||
#include <objects/CharacterObject.hpp>
|
||||
#include <objects/VehicleObject.hpp>
|
||||
#include <objects/ItemPickup.hpp>
|
||||
#include <dynamics/CollisionInstance.hpp>
|
||||
#include <data/Model.hpp>
|
||||
#include <items/WeaponItem.hpp>
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include <engine/GameState.hpp>
|
||||
#include <script/ScriptMachine.hpp>
|
||||
#include <dynamics/CollisionInstance.hpp>
|
||||
#include <dynamics/RaycastCallbacks.hpp>
|
||||
#include <engine/GameState.hpp>
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include <items/WeaponItem.hpp>
|
||||
#include <objects/CharacterObject.hpp>
|
||||
#include <objects/ItemPickup.hpp>
|
||||
#include <objects/VehicleObject.hpp>
|
||||
#include <script/ScriptMachine.hpp>
|
||||
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <unordered_map>
|
||||
@ -23,67 +23,68 @@ constexpr float kAutoLookTime = 2.f;
|
||||
constexpr float kAutolookMinVelocity = 0.2f;
|
||||
const float kMaxRotationRate = glm::half_pi<float>();
|
||||
const float kCameraPitchLimit = glm::quarter_pi<float>() * 0.5f;
|
||||
const float kVehicleCameraPitch = glm::half_pi<float>() - glm::quarter_pi<float>() * 0.25f;
|
||||
const float kVehicleCameraPitch =
|
||||
glm::half_pi<float>() - glm::quarter_pi<float>() * 0.25f;
|
||||
|
||||
// Hardcoded Controls SDLK_* -> GameInputState::Control
|
||||
const std::unordered_multimap<int, GameInputState::Control> kDefaultControls = {
|
||||
/* On Foot */
|
||||
{ SDLK_LCTRL, GameInputState::FireWeapon },
|
||||
{ SDLK_KP_0, GameInputState::FireWeapon },
|
||||
{ SDLK_KP_ENTER, GameInputState::NextWeapon },
|
||||
{ SDLK_KP_PERIOD, GameInputState::LastWeapon },
|
||||
{ SDLK_w, GameInputState::GoForward },
|
||||
{ SDLK_UP, GameInputState::GoForward },
|
||||
{ SDLK_s, GameInputState::GoBackwards },
|
||||
{ SDLK_DOWN, GameInputState::GoBackwards },
|
||||
{ SDLK_a, GameInputState::GoLeft },
|
||||
{ SDLK_LEFT, GameInputState::GoLeft },
|
||||
{ SDLK_d, GameInputState::GoRight },
|
||||
{ SDLK_RIGHT, GameInputState::GoRight },
|
||||
{ SDLK_PAGEUP, GameInputState::ZoomIn },
|
||||
{ SDLK_z, GameInputState::ZoomIn },
|
||||
{ SDLK_PAGEDOWN, GameInputState::ZoomOut },
|
||||
{ SDLK_x, GameInputState::ZoomOut },
|
||||
{ SDLK_f, GameInputState::EnterExitVehicle },
|
||||
{ SDLK_RETURN, GameInputState::EnterExitVehicle },
|
||||
{ SDLK_c, GameInputState::ChangeCamera },
|
||||
{ SDLK_HOME, GameInputState::ChangeCamera },
|
||||
{ SDLK_RCTRL, GameInputState::Jump },
|
||||
{ SDLK_SPACE, GameInputState::Jump },
|
||||
{ SDLK_LSHIFT, GameInputState::Sprint },
|
||||
{ SDLK_RSHIFT, GameInputState::Sprint },
|
||||
{ SDLK_LALT, GameInputState::Walk },
|
||||
{ SDLK_DELETE, GameInputState::AimWeapon },
|
||||
{ SDLK_CAPSLOCK, GameInputState::LookBehind },
|
||||
{SDLK_LCTRL, GameInputState::FireWeapon},
|
||||
{SDLK_KP_0, GameInputState::FireWeapon},
|
||||
{SDLK_KP_ENTER, GameInputState::NextWeapon},
|
||||
{SDLK_KP_PERIOD, GameInputState::LastWeapon},
|
||||
{SDLK_w, GameInputState::GoForward},
|
||||
{SDLK_UP, GameInputState::GoForward},
|
||||
{SDLK_s, GameInputState::GoBackwards},
|
||||
{SDLK_DOWN, GameInputState::GoBackwards},
|
||||
{SDLK_a, GameInputState::GoLeft},
|
||||
{SDLK_LEFT, GameInputState::GoLeft},
|
||||
{SDLK_d, GameInputState::GoRight},
|
||||
{SDLK_RIGHT, GameInputState::GoRight},
|
||||
{SDLK_PAGEUP, GameInputState::ZoomIn},
|
||||
{SDLK_z, GameInputState::ZoomIn},
|
||||
{SDLK_PAGEDOWN, GameInputState::ZoomOut},
|
||||
{SDLK_x, GameInputState::ZoomOut},
|
||||
{SDLK_f, GameInputState::EnterExitVehicle},
|
||||
{SDLK_RETURN, GameInputState::EnterExitVehicle},
|
||||
{SDLK_c, GameInputState::ChangeCamera},
|
||||
{SDLK_HOME, GameInputState::ChangeCamera},
|
||||
{SDLK_RCTRL, GameInputState::Jump},
|
||||
{SDLK_SPACE, GameInputState::Jump},
|
||||
{SDLK_LSHIFT, GameInputState::Sprint},
|
||||
{SDLK_RSHIFT, GameInputState::Sprint},
|
||||
{SDLK_LALT, GameInputState::Walk},
|
||||
{SDLK_DELETE, GameInputState::AimWeapon},
|
||||
{SDLK_CAPSLOCK, GameInputState::LookBehind},
|
||||
|
||||
/* In Vehicle */
|
||||
{ SDLK_LCTRL, GameInputState::VehicleFireWeapon },
|
||||
{ SDLK_a, GameInputState::VehicleLeft },
|
||||
{ SDLK_LEFT, GameInputState::VehicleLeft },
|
||||
{ SDLK_d, GameInputState::VehicleRight },
|
||||
{ SDLK_RIGHT, GameInputState::VehicleRight },
|
||||
{ SDLK_w, GameInputState::VehicleAccelerate },
|
||||
{ SDLK_UP, GameInputState::VehicleAccelerate },
|
||||
{ SDLK_d, GameInputState::VehicleBrake },
|
||||
{ SDLK_DOWN, GameInputState::VehicleBrake },
|
||||
{ SDLK_INSERT, GameInputState::ChangeRadio },
|
||||
{ SDLK_r, GameInputState::ChangeRadio },
|
||||
{ SDLK_LSHIFT, GameInputState::Horn },
|
||||
{ SDLK_RSHIFT, GameInputState::Horn },
|
||||
{ SDLK_KP_PLUS, GameInputState::Submission },
|
||||
{ SDLK_CAPSLOCK, GameInputState::Submission },
|
||||
{ SDLK_RCTRL, GameInputState::Handbrake },
|
||||
{ SDLK_SPACE, GameInputState::Handbrake },
|
||||
{ SDLK_KP_9, GameInputState::VehicleAimUp },
|
||||
{ SDLK_KP_2, GameInputState::VehicleAimDown },
|
||||
{ SDLK_KP_4, GameInputState::VehicleAimLeft },
|
||||
{ SDLK_KP_6, GameInputState::VehicleAimRight },
|
||||
{ SDLK_KP_9, GameInputState::VehicleDown },
|
||||
{ SDLK_KP_2, GameInputState::VehicleUp },
|
||||
{ SDLK_KP_1, GameInputState::LookLeft },
|
||||
{ SDLK_q, GameInputState::LookLeft },
|
||||
{ SDLK_KP_2, GameInputState::LookRight },
|
||||
{ SDLK_e, GameInputState::LookRight },
|
||||
{SDLK_LCTRL, GameInputState::VehicleFireWeapon},
|
||||
{SDLK_a, GameInputState::VehicleLeft},
|
||||
{SDLK_LEFT, GameInputState::VehicleLeft},
|
||||
{SDLK_d, GameInputState::VehicleRight},
|
||||
{SDLK_RIGHT, GameInputState::VehicleRight},
|
||||
{SDLK_w, GameInputState::VehicleAccelerate},
|
||||
{SDLK_UP, GameInputState::VehicleAccelerate},
|
||||
{SDLK_d, GameInputState::VehicleBrake},
|
||||
{SDLK_DOWN, GameInputState::VehicleBrake},
|
||||
{SDLK_INSERT, GameInputState::ChangeRadio},
|
||||
{SDLK_r, GameInputState::ChangeRadio},
|
||||
{SDLK_LSHIFT, GameInputState::Horn},
|
||||
{SDLK_RSHIFT, GameInputState::Horn},
|
||||
{SDLK_KP_PLUS, GameInputState::Submission},
|
||||
{SDLK_CAPSLOCK, GameInputState::Submission},
|
||||
{SDLK_RCTRL, GameInputState::Handbrake},
|
||||
{SDLK_SPACE, GameInputState::Handbrake},
|
||||
{SDLK_KP_9, GameInputState::VehicleAimUp},
|
||||
{SDLK_KP_2, GameInputState::VehicleAimDown},
|
||||
{SDLK_KP_4, GameInputState::VehicleAimLeft},
|
||||
{SDLK_KP_6, GameInputState::VehicleAimRight},
|
||||
{SDLK_KP_9, GameInputState::VehicleDown},
|
||||
{SDLK_KP_2, GameInputState::VehicleUp},
|
||||
{SDLK_KP_1, GameInputState::LookLeft},
|
||||
{SDLK_q, GameInputState::LookLeft},
|
||||
{SDLK_KP_2, GameInputState::LookRight},
|
||||
{SDLK_e, GameInputState::LookRight},
|
||||
};
|
||||
|
||||
IngameState::IngameState(RWGame* game, bool newgame, const std::string& save)
|
||||
@ -93,14 +94,12 @@ IngameState::IngameState(RWGame* game, bool newgame, const std::string& save)
|
||||
, newgame(newgame)
|
||||
, autolookTimer(0.f)
|
||||
, camMode(IngameState::CAMERA_NORMAL)
|
||||
, m_cameraAngles { 0.f, glm::half_pi<float>() }
|
||||
, m_cameraAngles{0.f, glm::half_pi<float>()}
|
||||
, m_invertedY(game->getConfig().getInputInvertY())
|
||||
, m_vehicleFreeLook(true)
|
||||
{
|
||||
, m_vehicleFreeLook(true) {
|
||||
}
|
||||
|
||||
void IngameState::startTest()
|
||||
{
|
||||
void IngameState::startTest() {
|
||||
auto playerChar = getWorld()->createPlayer({270.f, -605.f, 40.f});
|
||||
|
||||
getWorld()->state->playerObject = playerChar->getGameObjectID();
|
||||
@ -113,52 +112,47 @@ void IngameState::startTest()
|
||||
itemspawn.x += 2.5f;
|
||||
}
|
||||
|
||||
auto carPos = glm::vec3( 286.f, -591.f, 37.f );
|
||||
auto carPos = glm::vec3(286.f, -591.f, 37.f);
|
||||
auto carRot = glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 0.f, 1.f));
|
||||
//auto boatPos = glm::vec3( -1000.f, -1040.f, 5.f );
|
||||
// auto boatPos = glm::vec3( -1000.f, -1040.f, 5.f );
|
||||
int i = 0;
|
||||
for( auto& vi : getWorld()->data->objectTypes ) {
|
||||
switch( vi.first ) {
|
||||
case 140: continue;
|
||||
case 141: continue;
|
||||
for (auto& vi : getWorld()->data->objectTypes) {
|
||||
switch (vi.first) {
|
||||
case 140:
|
||||
continue;
|
||||
case 141:
|
||||
continue;
|
||||
}
|
||||
if( vi.second->class_type == ObjectInformation::_class("CARS") )
|
||||
{
|
||||
if ( i++ > 20 ) break;
|
||||
if (vi.second->class_type == ObjectInformation::_class("CARS")) {
|
||||
if (i++ > 20) break;
|
||||
auto vehicle = std::static_pointer_cast<VehicleData>(vi.second);
|
||||
|
||||
auto& sp = carPos;
|
||||
auto& sr = carRot;
|
||||
auto v = getWorld()->createVehicle(vi.first, sp, sr);
|
||||
|
||||
sp += sr * glm::vec3( 2.f + v->info->handling.dimensions.x, 0.f, 0.f);
|
||||
sp +=
|
||||
sr * glm::vec3(2.f + v->info->handling.dimensions.x, 0.f, 0.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IngameState::startGame()
|
||||
{
|
||||
void IngameState::startGame() {
|
||||
game->startScript("data/main.scm");
|
||||
game->getScript()->startThread(0);
|
||||
getWorld()->sound.playBackground( getWorld()->data->getDataPath() + "/audio/City.wav" );
|
||||
getWorld()->sound.playBackground(getWorld()->data->getDataPath() +
|
||||
"/audio/City.wav");
|
||||
}
|
||||
|
||||
void IngameState::enter()
|
||||
{
|
||||
if( ! started )
|
||||
{
|
||||
if( newgame )
|
||||
{
|
||||
if( save.empty() )
|
||||
{
|
||||
void IngameState::enter() {
|
||||
if (!started) {
|
||||
if (newgame) {
|
||||
if (save.empty()) {
|
||||
startGame();
|
||||
}
|
||||
else if( save == "test" )
|
||||
{
|
||||
} else if (save == "test") {
|
||||
startTest();
|
||||
}
|
||||
else {
|
||||
game->loadGame( save );
|
||||
} else {
|
||||
game->loadGame(save);
|
||||
}
|
||||
}
|
||||
started = true;
|
||||
@ -167,13 +161,10 @@ void IngameState::enter()
|
||||
getWindow().hideCursor();
|
||||
}
|
||||
|
||||
void IngameState::exit()
|
||||
{
|
||||
|
||||
void IngameState::exit() {
|
||||
}
|
||||
|
||||
void IngameState::tick(float dt)
|
||||
{
|
||||
void IngameState::tick(float dt) {
|
||||
auto world = getWorld();
|
||||
autolookTimer = std::max(autolookTimer - dt, 0.f);
|
||||
|
||||
@ -183,15 +174,19 @@ void IngameState::tick(float dt)
|
||||
float moneyFrequency = 1.0f / 30.0f;
|
||||
moneyTimer += dt;
|
||||
while (moneyTimer >= moneyFrequency) {
|
||||
int32_t difference = world->state->playerInfo.money - world->state->playerInfo.displayedMoney;
|
||||
int32_t difference = world->state->playerInfo.money -
|
||||
world->state->playerInfo.displayedMoney;
|
||||
|
||||
// Generates 0, 1 (difference < 100), 12 (difference < 1000), 123 (difference < 10000), .. etc.
|
||||
// Generates 0, 1 (difference < 100), 12 (difference < 1000), 123
|
||||
// (difference < 10000), .. etc.
|
||||
// Negative input will result in negative output
|
||||
auto GetIncrement = [](int32_t difference) -> int32_t {
|
||||
// @todo is this correct for difference >= 1000000000 ?
|
||||
int32_t r = 1;
|
||||
int32_t i = 2;
|
||||
if (difference == 0) { return 0; }
|
||||
if (difference == 0) {
|
||||
return 0;
|
||||
}
|
||||
while (std::abs(difference) >= 100) {
|
||||
difference /= 10;
|
||||
r = r * 10 + i;
|
||||
@ -207,11 +202,9 @@ void IngameState::tick(float dt)
|
||||
|
||||
auto player = game->getPlayer();
|
||||
const auto& input = world->state->input;
|
||||
if( player && player->isInputEnabled() )
|
||||
{
|
||||
if (player && player->isInputEnabled()) {
|
||||
float viewDistance = 4.f;
|
||||
switch( camMode )
|
||||
{
|
||||
switch (camMode) {
|
||||
case IngameState::CAMERA_CLOSE:
|
||||
viewDistance = 2.f;
|
||||
break;
|
||||
@ -230,8 +223,7 @@ void IngameState::tick(float dt)
|
||||
|
||||
auto target = world->pedestrianPool.find(world->state->cameraTarget);
|
||||
|
||||
if( target == nullptr )
|
||||
{
|
||||
if (target == nullptr) {
|
||||
target = player->getCharacter();
|
||||
}
|
||||
|
||||
@ -242,63 +234,75 @@ void IngameState::tick(float dt)
|
||||
|
||||
btCollisionObject* physTarget = player->getCharacter()->physObject;
|
||||
|
||||
auto vehicle = ( target->type() == GameObject::Character ) ? static_cast<CharacterObject*>(target)->getCurrentVehicle() : nullptr;
|
||||
if( vehicle ) {
|
||||
auto vehicle =
|
||||
(target->type() == GameObject::Character)
|
||||
? static_cast<CharacterObject*>(target)->getCurrentVehicle()
|
||||
: nullptr;
|
||||
if (vehicle) {
|
||||
auto model = vehicle->model;
|
||||
float maxDist = 0.f;
|
||||
for(auto& g : model->resource->geometries) {
|
||||
float partSize = glm::length(g->geometryBounds.center) + g->geometryBounds.radius;
|
||||
for (auto& g : model->resource->geometries) {
|
||||
float partSize = glm::length(g->geometryBounds.center) +
|
||||
g->geometryBounds.radius;
|
||||
maxDist = std::max(partSize, maxDist);
|
||||
}
|
||||
viewDistance = viewDistance + maxDist;
|
||||
targetPosition = vehicle->getPosition();
|
||||
lookTargetPosition = targetPosition;
|
||||
lookTargetPosition.z += (vehicle->info->handling.dimensions.z * 0.5f);
|
||||
lookTargetPosition.z +=
|
||||
(vehicle->info->handling.dimensions.z * 0.5f);
|
||||
targetPosition.z += (vehicle->info->handling.dimensions.z * 0.5f);
|
||||
physTarget = vehicle->collision->getBulletBody();
|
||||
|
||||
if (!m_vehicleFreeLook)
|
||||
{
|
||||
if (!m_vehicleFreeLook) {
|
||||
m_cameraAngles.y = kVehicleCameraPitch;
|
||||
}
|
||||
|
||||
// Rotate the camera to the ideal angle if the player isn't moving it
|
||||
// Rotate the camera to the ideal angle if the player isn't moving
|
||||
// it
|
||||
float velocity = vehicle->getVelocity();
|
||||
if (autolookTimer <= 0.f && glm::abs(velocity) > kAutolookMinVelocity)
|
||||
{
|
||||
auto idealYaw = -glm::roll(vehicle->getRotation()) + glm::half_pi<float>();
|
||||
if (autolookTimer <= 0.f &&
|
||||
glm::abs(velocity) > kAutolookMinVelocity) {
|
||||
auto idealYaw =
|
||||
-glm::roll(vehicle->getRotation()) + glm::half_pi<float>();
|
||||
const auto idealPitch = kVehicleCameraPitch;
|
||||
if (velocity < 0.f) {
|
||||
idealYaw = glm::mod(idealYaw - glm::pi<float>(), glm::pi<float>() * 2.f);
|
||||
idealYaw = glm::mod(idealYaw - glm::pi<float>(),
|
||||
glm::pi<float>() * 2.f);
|
||||
}
|
||||
float currentYaw = glm::mod(m_cameraAngles.x, glm::pi<float>()*2);
|
||||
float currentYaw =
|
||||
glm::mod(m_cameraAngles.x, glm::pi<float>() * 2);
|
||||
float currentPitch = m_cameraAngles.y;
|
||||
float deltaYaw = idealYaw - currentYaw;
|
||||
float deltaPitch = idealPitch - currentPitch;
|
||||
if (glm::abs(deltaYaw) > glm::pi<float>()) {
|
||||
deltaYaw -= glm::sign(deltaYaw) * glm::pi<float>()*2.f;
|
||||
deltaYaw -= glm::sign(deltaYaw) * glm::pi<float>() * 2.f;
|
||||
}
|
||||
m_cameraAngles.x += glm::sign(deltaYaw) * std::min(kMaxRotationRate * dt, glm::abs(deltaYaw));
|
||||
m_cameraAngles.y += glm::sign(deltaPitch) * std::min(kMaxRotationRate * dt, glm::abs(deltaPitch));
|
||||
m_cameraAngles.x +=
|
||||
glm::sign(deltaYaw) *
|
||||
std::min(kMaxRotationRate * dt, glm::abs(deltaYaw));
|
||||
m_cameraAngles.y +=
|
||||
glm::sign(deltaPitch) *
|
||||
std::min(kMaxRotationRate * dt, glm::abs(deltaPitch));
|
||||
}
|
||||
}
|
||||
|
||||
// Non-topdown camera can orbit
|
||||
if( camMode != IngameState::CAMERA_TOPDOWN )
|
||||
{
|
||||
if (camMode != IngameState::CAMERA_TOPDOWN) {
|
||||
bool lookleft = input.pressed(GameInputState::LookLeft);
|
||||
bool lookright = input.pressed(GameInputState::LookRight);
|
||||
if ((lookleft || lookright) && vehicle != nullptr) {
|
||||
auto rotation = vehicle->getRotation();
|
||||
if (! lookright) {
|
||||
rotation *= glm::angleAxis(glm::half_pi<float>(), glm::vec3(0.f, 0.f,-1.f));
|
||||
if (!lookright) {
|
||||
rotation *= glm::angleAxis(glm::half_pi<float>(),
|
||||
glm::vec3(0.f, 0.f, -1.f));
|
||||
} else if (!lookleft) {
|
||||
rotation *= glm::angleAxis(glm::half_pi<float>(),
|
||||
glm::vec3(0.f, 0.f, 1.f));
|
||||
}
|
||||
else if (! lookleft) {
|
||||
rotation *= glm::angleAxis(glm::half_pi<float>(), glm::vec3(0.f, 0.f, 1.f));
|
||||
}
|
||||
cameraPosition = targetPosition + rotation * glm::vec3(0.f, viewDistance, 0.f);
|
||||
}
|
||||
else {
|
||||
cameraPosition = targetPosition +
|
||||
rotation * glm::vec3(0.f, viewDistance, 0.f);
|
||||
} else {
|
||||
// Determine the "ideal" camera position for the current view
|
||||
// angles
|
||||
auto yaw =
|
||||
@ -309,9 +313,7 @@ void IngameState::tick(float dt)
|
||||
yaw * pitch * glm::vec3(0.f, 0.f, viewDistance);
|
||||
cameraPosition = targetPosition + cameraOffset;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
cameraPosition = targetPosition + glm::vec3(0.f, 0.f, viewDistance);
|
||||
}
|
||||
|
||||
@ -320,8 +322,7 @@ void IngameState::tick(float dt)
|
||||
auto camtotarget = targetPosition - cameraPosition;
|
||||
auto dir = glm::normalize(camtotarget);
|
||||
float correction = glm::length(camtotarget) - viewDistance;
|
||||
if( correction < 0.f )
|
||||
{
|
||||
if (correction < 0.f) {
|
||||
float innerDist = viewDistance * 0.1f;
|
||||
correction = glm::min(0.f, correction + innerDist);
|
||||
}
|
||||
@ -330,29 +331,28 @@ void IngameState::tick(float dt)
|
||||
auto lookdir = glm::normalize(lookTargetPosition - cameraPosition);
|
||||
// Calculate the yaw to look at the target.
|
||||
float angleYaw = glm::atan(lookdir.y, lookdir.x);
|
||||
angle = glm::quat( glm::vec3(0.f, 0.f, angleYaw) );
|
||||
angle = glm::quat(glm::vec3(0.f, 0.f, angleYaw));
|
||||
glm::vec3 movement;
|
||||
|
||||
movement.x = input[GameInputState::GoForward] - input[GameInputState::GoBackwards];
|
||||
movement.y = input[GameInputState::GoLeft] - input[GameInputState::GoRight];
|
||||
movement.x = input[GameInputState::GoForward] -
|
||||
input[GameInputState::GoBackwards];
|
||||
movement.y =
|
||||
input[GameInputState::GoLeft] - input[GameInputState::GoRight];
|
||||
/// @todo replace with correct sprint behaviour
|
||||
float speed = input.pressed(GameInputState::Sprint) ? 2.f : 1.f;
|
||||
|
||||
if( player->isInputEnabled() )
|
||||
{
|
||||
if (player->isInputEnabled()) {
|
||||
player->setRunning(!input.pressed(GameInputState::Walk));
|
||||
/// @todo find the correct behaviour for entering & exiting
|
||||
if (input.pressed(GameInputState::EnterExitVehicle)) {
|
||||
/// @todo move me
|
||||
if (player->getCharacter()->getCurrentVehicle()) {
|
||||
player->exitVehicle();
|
||||
}
|
||||
else if (!player->isCurrentActivity(
|
||||
} else if (!player->isCurrentActivity(
|
||||
Activities::EnterVehicle::ActivityName)) {
|
||||
player->enterNearestVehicle();
|
||||
}
|
||||
}
|
||||
else if (glm::length2(movement) > 0.001f) {
|
||||
} else if (glm::length2(movement) > 0.001f) {
|
||||
if (player->isCurrentActivity(
|
||||
Activities::EnterVehicle::ActivityName)) {
|
||||
// Give up entering a vehicle if we're alreadying doing so
|
||||
@ -360,41 +360,34 @@ void IngameState::tick(float dt)
|
||||
}
|
||||
}
|
||||
|
||||
if (player->getCharacter()->getCurrentVehicle())
|
||||
{
|
||||
if (player->getCharacter()->getCurrentVehicle()) {
|
||||
auto vehicle = player->getCharacter()->getCurrentVehicle();
|
||||
vehicle->setHandbraking(input.pressed(GameInputState::Handbrake));
|
||||
vehicle->setHandbraking(
|
||||
input.pressed(GameInputState::Handbrake));
|
||||
player->setMoveDirection(movement);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (input.pressed(GameInputState::Jump)) {
|
||||
player->jump();
|
||||
}
|
||||
|
||||
float length = glm::length(movement);
|
||||
float movementAngle = angleYaw - glm::half_pi<float>();
|
||||
if (length > 0.1f)
|
||||
{
|
||||
if (length > 0.1f) {
|
||||
glm::vec3 direction = glm::normalize(movement);
|
||||
movementAngle += atan2(direction.y, direction.x);
|
||||
player->setMoveDirection(glm::vec3(speed, 0.f, 0.f));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
player->setMoveDirection(glm::vec3(0.f));
|
||||
}
|
||||
player->setLookDirection({movementAngle, 0.f});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
player->setMoveDirection(glm::vec3(0.f));
|
||||
}
|
||||
|
||||
float len2d = glm::length(glm::vec2(lookdir));
|
||||
float anglePitch = glm::atan(lookdir.z, len2d);
|
||||
angle *= glm::quat( glm::vec3(0.f, -anglePitch, 0.f) );
|
||||
angle *= glm::quat(glm::vec3(0.f, -anglePitch, 0.f));
|
||||
|
||||
// Use rays to ensure target is visible from cameraPosition
|
||||
auto rayEnd = cameraPosition;
|
||||
@ -404,12 +397,14 @@ void IngameState::tick(float dt)
|
||||
ClosestNotMeRayResultCallback ray(physTarget, from, to);
|
||||
|
||||
world->dynamicsWorld->rayTest(from, to, ray);
|
||||
if( ray.hasHit() && ray.m_closestHitFraction < 1.f )
|
||||
{
|
||||
cameraPosition = glm::vec3(ray.m_hitPointWorld.x(), ray.m_hitPointWorld.y(),
|
||||
if (ray.hasHit() && ray.m_closestHitFraction < 1.f) {
|
||||
cameraPosition =
|
||||
glm::vec3(ray.m_hitPointWorld.x(), ray.m_hitPointWorld.y(),
|
||||
ray.m_hitPointWorld.z());
|
||||
cameraPosition += glm::vec3(ray.m_hitNormalWorld.x(), ray.m_hitNormalWorld.y(),
|
||||
ray.m_hitNormalWorld.z()) * 0.1f;
|
||||
cameraPosition +=
|
||||
glm::vec3(ray.m_hitNormalWorld.x(), ray.m_hitNormalWorld.y(),
|
||||
ray.m_hitNormalWorld.z()) *
|
||||
0.1f;
|
||||
}
|
||||
|
||||
_look.position = cameraPosition;
|
||||
@ -417,82 +412,81 @@ void IngameState::tick(float dt)
|
||||
}
|
||||
}
|
||||
|
||||
void IngameState::draw(GameRenderer* r)
|
||||
{
|
||||
if( !getWorld()->state->isCinematic && getWorld()->isCutsceneDone() )
|
||||
{
|
||||
void IngameState::draw(GameRenderer* r) {
|
||||
if (!getWorld()->state->isCinematic && getWorld()->isCutsceneDone()) {
|
||||
drawHUD(_look, game->getPlayer(), getWorld(), r);
|
||||
}
|
||||
|
||||
State::draw(r);
|
||||
}
|
||||
|
||||
void IngameState::handleEvent(const SDL_Event& event)
|
||||
{
|
||||
void IngameState::handleEvent(const SDL_Event& event) {
|
||||
auto player = game->getPlayer();
|
||||
|
||||
switch(event.type) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
switch(event.key.keysym.sym) {
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
StateManager::get().enter(new PauseState(game));
|
||||
break;
|
||||
case SDLK_m:
|
||||
StateManager::get().enter(new DebugState(game, _look.position, _look.rotation));
|
||||
StateManager::get().enter(
|
||||
new DebugState(game, _look.position, _look.rotation));
|
||||
break;
|
||||
case SDLK_SPACE:
|
||||
if( getWorld()->state->currentCutscene )
|
||||
{
|
||||
if (getWorld()->state->currentCutscene) {
|
||||
getWorld()->state->skipCutscene = true;
|
||||
}
|
||||
break;
|
||||
case SDLK_c:
|
||||
camMode = CameraMode((camMode+(CameraMode)1)%CAMERA_MAX);
|
||||
camMode =
|
||||
CameraMode((camMode + (CameraMode)1) % CAMERA_MAX);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
updateInputState(event);
|
||||
|
||||
if( player && player->isInputEnabled() )
|
||||
{
|
||||
if (player && player->isInputEnabled()) {
|
||||
handlePlayerInput(event);
|
||||
}
|
||||
State::handleEvent(event);
|
||||
}
|
||||
|
||||
void IngameState::handlePlayerInput(const SDL_Event& event)
|
||||
{
|
||||
void IngameState::handlePlayerInput(const SDL_Event& event) {
|
||||
auto player = game->getPlayer();
|
||||
switch(event.type) {
|
||||
|
||||
switch (event.type) {
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
switch(event.button.button) {
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT:
|
||||
player->getCharacter()->useItem(true, true);
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
switch(event.button.button) {
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT:
|
||||
player->getCharacter()->useItem(false, true);
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEWHEEL:
|
||||
player->getCharacter()->cycleInventory(event.wheel.y > 0);
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
if (game->hasFocus())
|
||||
{
|
||||
if (game->hasFocus()) {
|
||||
glm::ivec2 screenSize = getWindow().getSize();
|
||||
glm::vec2 mouseMove(event.motion.xrel / static_cast<float>(screenSize.x),
|
||||
glm::vec2 mouseMove(
|
||||
event.motion.xrel / static_cast<float>(screenSize.x),
|
||||
event.motion.yrel / static_cast<float>(screenSize.y));
|
||||
|
||||
autolookTimer = kAutoLookTime;
|
||||
@ -500,7 +494,9 @@ void IngameState::handlePlayerInput(const SDL_Event& event)
|
||||
mouseMove.y = -mouseMove.y;
|
||||
}
|
||||
m_cameraAngles += glm::vec2(mouseMove.x, mouseMove.y);
|
||||
m_cameraAngles.y = glm::clamp(m_cameraAngles.y, kCameraPitchLimit, glm::pi<float>() - kCameraPitchLimit);
|
||||
m_cameraAngles.y =
|
||||
glm::clamp(m_cameraAngles.y, kCameraPitchLimit,
|
||||
glm::pi<float>() - kCameraPitchLimit);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -508,8 +504,7 @@ void IngameState::handlePlayerInput(const SDL_Event& event)
|
||||
}
|
||||
}
|
||||
|
||||
void IngameState::updateInputState(const SDL_Event& event)
|
||||
{
|
||||
void IngameState::updateInputState(const SDL_Event& event) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP: {
|
||||
@ -525,15 +520,10 @@ void IngameState::updateInputState(const SDL_Event& event)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool IngameState::shouldWorldUpdate()
|
||||
{
|
||||
bool IngameState::shouldWorldUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
const ViewCamera &IngameState::getCamera()
|
||||
{
|
||||
const ViewCamera& IngameState::getCamera() {
|
||||
return _look;
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,10 +5,8 @@
|
||||
|
||||
class PlayerController;
|
||||
|
||||
class IngameState : public State
|
||||
{
|
||||
enum CameraMode
|
||||
{
|
||||
class IngameState : public State {
|
||||
enum CameraMode {
|
||||
CAMERA_CLOSE = 0,
|
||||
CAMERA_NORMAL = 1,
|
||||
CAMERA_FAR = 2,
|
||||
@ -41,7 +39,8 @@ public:
|
||||
* @param newgame
|
||||
* @param game An empty string, a save game to load, or the string "test".
|
||||
*/
|
||||
IngameState(RWGame* game, bool newgame = true, const std::string& save = "");
|
||||
IngameState(RWGame* game, bool newgame = true,
|
||||
const std::string& save = "");
|
||||
|
||||
void startTest();
|
||||
void startGame();
|
||||
|
@ -1,56 +1,46 @@
|
||||
#include "LoadingState.hpp"
|
||||
#include "RWGame.hpp"
|
||||
#include <render/OpenGLRenderer.hpp>
|
||||
#include "RWGame.hpp"
|
||||
|
||||
LoadingState::LoadingState(RWGame* game)
|
||||
: State(game), next(nullptr)
|
||||
{
|
||||
LoadingState::LoadingState(RWGame* game) : State(game), next(nullptr) {
|
||||
}
|
||||
|
||||
void LoadingState::enter()
|
||||
{
|
||||
void LoadingState::enter() {
|
||||
game->newGame();
|
||||
}
|
||||
|
||||
void LoadingState::exit()
|
||||
{
|
||||
|
||||
void LoadingState::exit() {
|
||||
}
|
||||
|
||||
void LoadingState::tick(float dt)
|
||||
{
|
||||
void LoadingState::tick(float dt) {
|
||||
RW_UNUSED(dt);
|
||||
|
||||
// If background work is completed, switch to the next state
|
||||
if( getWorld()->_work->isEmpty() ) {
|
||||
if (getWorld()->_work->isEmpty()) {
|
||||
StateManager::get().exec(next);
|
||||
}
|
||||
}
|
||||
|
||||
bool LoadingState::shouldWorldUpdate()
|
||||
{
|
||||
bool LoadingState::shouldWorldUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void LoadingState::setNextState(State* nextState)
|
||||
{
|
||||
void LoadingState::setNextState(State* nextState) {
|
||||
next = nextState;
|
||||
}
|
||||
|
||||
void LoadingState::handleEvent(const SDL_Event& e)
|
||||
{
|
||||
void LoadingState::handleEvent(const SDL_Event& e) {
|
||||
State::handleEvent(e);
|
||||
}
|
||||
|
||||
void LoadingState::draw(GameRenderer* r)
|
||||
{
|
||||
void LoadingState::draw(GameRenderer* r) {
|
||||
static auto kLoadingString = GameStringUtil::fromString("Loading...");
|
||||
// Display some manner of loading screen.
|
||||
TextRenderer::TextInfo ti;
|
||||
ti.text = kLoadingString;
|
||||
auto size = r->getRenderer()->getViewport();
|
||||
ti.size = 25.f;
|
||||
ti.screenPosition = glm::vec2( 50.f, size.y - ti.size - 50.f );
|
||||
ti.screenPosition = glm::vec2(50.f, size.y - ti.size - 50.f);
|
||||
ti.font = 2;
|
||||
ti.baseColour = glm::u8vec3(255);
|
||||
r->text.renderText(ti);
|
||||
|
@ -3,9 +3,9 @@
|
||||
|
||||
#include "State.hpp"
|
||||
|
||||
class LoadingState : public State
|
||||
{
|
||||
class LoadingState : public State {
|
||||
State* next;
|
||||
|
||||
public:
|
||||
LoadingState(RWGame* game);
|
||||
|
||||
|
@ -1,83 +1,88 @@
|
||||
#include "MenuState.hpp"
|
||||
#include "game.hpp"
|
||||
#include "IngameState.hpp"
|
||||
#include "game.hpp"
|
||||
|
||||
#include "RWGame.hpp"
|
||||
#include <engine/SaveGame.hpp>
|
||||
#include <rw/defines.hpp>
|
||||
#include "RWGame.hpp"
|
||||
|
||||
MenuState::MenuState(RWGame* game)
|
||||
: State(game)
|
||||
{
|
||||
MenuState::MenuState(RWGame* game) : State(game) {
|
||||
enterMainMenu();
|
||||
}
|
||||
|
||||
void MenuState::enterMainMenu()
|
||||
{
|
||||
void MenuState::enterMainMenu() {
|
||||
auto data = game->getGameData();
|
||||
auto& t = data->texts;
|
||||
|
||||
Menu *m = new Menu;
|
||||
Menu* m = new Menu;
|
||||
m->offset = glm::vec2(200.f, 200.f);
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kStartGameId), [=] { StateManager::get().enter(new IngameState(game)); }));
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kLoadGameId), [=] { enterLoadMenu(); }));
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kDebugId), [=] { StateManager::get().enter(new IngameState(game, true, "test")); }));
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kOptionsId), [] { RW_UNIMPLEMENTED("Options Menu"); }));
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kQuitGameId), [] { StateManager::get().clear(); }));
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kStartGameId), [=] {
|
||||
StateManager::get().enter(new IngameState(game));
|
||||
}));
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kLoadGameId),
|
||||
[=] { enterLoadMenu(); }));
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kDebugId), [=] {
|
||||
StateManager::get().enter(new IngameState(game, true, "test"));
|
||||
}));
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kOptionsId),
|
||||
[] { RW_UNIMPLEMENTED("Options Menu"); }));
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kQuitGameId),
|
||||
[] { StateManager::get().clear(); }));
|
||||
this->enterMenu(m);
|
||||
}
|
||||
|
||||
void MenuState::enterLoadMenu()
|
||||
{
|
||||
Menu *m = new Menu;
|
||||
void MenuState::enterLoadMenu() {
|
||||
Menu* m = new Menu;
|
||||
m->offset = glm::vec2(20.f, 30.f);
|
||||
m->addEntry(Menu::lambda("BACK", [=] { enterMainMenu(); }));
|
||||
auto saves = SaveGame::getAllSaveGameInfo();
|
||||
for(SaveGameInfo& save : saves) {
|
||||
for (SaveGameInfo& save : saves) {
|
||||
if (save.valid) {
|
||||
std::stringstream ss;
|
||||
ss << save.basicState.saveTime.year << " " << save.basicState.saveTime.month << " " << save.basicState.saveTime.day
|
||||
<< " " << save.basicState.saveTime.hour << ":" << save.basicState.saveTime.minute << " ";
|
||||
ss << save.basicState.saveTime.year << " "
|
||||
<< save.basicState.saveTime.month << " "
|
||||
<< save.basicState.saveTime.day << " "
|
||||
<< save.basicState.saveTime.hour << ":"
|
||||
<< save.basicState.saveTime.minute << " ";
|
||||
auto name = GameStringUtil::fromString(ss.str());
|
||||
name += save.basicState.saveName;
|
||||
m->addEntry(Menu::lambda(name, [=] {
|
||||
StateManager::get().enter(new IngameState(game, false));
|
||||
m->addEntry(Menu::lambda(name,
|
||||
[=] {
|
||||
StateManager::get().enter(
|
||||
new IngameState(game, false));
|
||||
game->loadGame(save.savePath);
|
||||
}, 20.f));
|
||||
}
|
||||
else {
|
||||
m->addEntry(Menu::lambda("CORRUPT", [=] { }));
|
||||
},
|
||||
20.f));
|
||||
} else {
|
||||
m->addEntry(Menu::lambda("CORRUPT", [=] {}));
|
||||
}
|
||||
}
|
||||
this->enterMenu(m);
|
||||
}
|
||||
|
||||
void MenuState::enter()
|
||||
{
|
||||
void MenuState::enter() {
|
||||
getWindow().showCursor();
|
||||
}
|
||||
|
||||
void MenuState::exit()
|
||||
{
|
||||
|
||||
void MenuState::exit() {
|
||||
}
|
||||
|
||||
void MenuState::tick(float dt)
|
||||
{
|
||||
void MenuState::tick(float dt) {
|
||||
RW_UNUSED(dt);
|
||||
}
|
||||
|
||||
void MenuState::handleEvent(const SDL_Event& e)
|
||||
{
|
||||
switch(e.type) {
|
||||
void MenuState::handleEvent(const SDL_Event& e) {
|
||||
switch (e.type) {
|
||||
case SDL_KEYUP:
|
||||
switch(e.key.keysym.sym) {
|
||||
switch (e.key.keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
StateManager::get().exit();
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
State::handleEvent(e);
|
||||
}
|
||||
|
@ -3,8 +3,7 @@
|
||||
|
||||
#include "State.hpp"
|
||||
|
||||
class MenuState : public State
|
||||
{
|
||||
class MenuState : public State {
|
||||
public:
|
||||
MenuState(RWGame* game);
|
||||
|
||||
|
@ -1,48 +1,45 @@
|
||||
#include "PauseState.hpp"
|
||||
#include "RWGame.hpp"
|
||||
#include <ai/PlayerController.hpp>
|
||||
#include <objects/CharacterObject.hpp>
|
||||
#include "RWGame.hpp"
|
||||
|
||||
PauseState::PauseState(RWGame* game)
|
||||
: State(game)
|
||||
{
|
||||
PauseState::PauseState(RWGame* game) : State(game) {
|
||||
auto data = game->getGameData();
|
||||
auto& t = data->texts;
|
||||
|
||||
Menu *m = new Menu;
|
||||
m->offset = glm::vec2( 200.f, 200.f );
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kResumeGameId), [] { StateManager::get().exit(); }));
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kOptionsId), [] { std::cout << "Options" << std::endl; }));
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kQuitGameId), [] { StateManager::get().clear(); }));
|
||||
Menu* m = new Menu;
|
||||
m->offset = glm::vec2(200.f, 200.f);
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kResumeGameId),
|
||||
[] { StateManager::get().exit(); }));
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kOptionsId),
|
||||
[] { std::cout << "Options" << std::endl; }));
|
||||
m->addEntry(Menu::lambda(t.text(MenuDefaults::kQuitGameId),
|
||||
[] { StateManager::get().clear(); }));
|
||||
this->enterMenu(m);
|
||||
}
|
||||
|
||||
void PauseState::enter()
|
||||
{
|
||||
void PauseState::enter() {
|
||||
getWorld()->setPaused(true);
|
||||
|
||||
getWindow().showCursor();
|
||||
}
|
||||
|
||||
void PauseState::exit()
|
||||
{
|
||||
void PauseState::exit() {
|
||||
getWorld()->setPaused(false);
|
||||
}
|
||||
|
||||
void PauseState::tick(float dt)
|
||||
{
|
||||
void PauseState::tick(float dt) {
|
||||
RW_UNUSED(dt);
|
||||
}
|
||||
|
||||
void PauseState::draw(GameRenderer* r)
|
||||
{
|
||||
void PauseState::draw(GameRenderer* r) {
|
||||
MapRenderer::MapInfo map;
|
||||
|
||||
auto& vp = r->getRenderer()->getViewport();
|
||||
|
||||
map.worldSize = 4000.f;
|
||||
map.clipToSize = false;
|
||||
map.screenPosition = glm::vec2(vp.x/2, vp.y/2);
|
||||
map.screenPosition = glm::vec2(vp.x / 2, vp.y / 2);
|
||||
map.screenSize = std::max(vp.x, vp.y);
|
||||
|
||||
game->getRenderer()->map.draw(getWorld(), map);
|
||||
@ -50,18 +47,19 @@ void PauseState::draw(GameRenderer* r)
|
||||
State::draw(r);
|
||||
}
|
||||
|
||||
void PauseState::handleEvent(const SDL_Event& e)
|
||||
{
|
||||
switch(e.type) {
|
||||
void PauseState::handleEvent(const SDL_Event& e) {
|
||||
switch (e.type) {
|
||||
case SDL_KEYDOWN:
|
||||
switch(e.key.keysym.sym) {
|
||||
switch (e.key.keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
StateManager::get().exit();
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
State::handleEvent(e);
|
||||
}
|
||||
|
@ -3,8 +3,7 @@
|
||||
|
||||
#include "State.hpp"
|
||||
|
||||
class PauseState : public State
|
||||
{
|
||||
class PauseState : public State {
|
||||
public:
|
||||
PauseState(RWGame* game);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user