Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
wivlaro committed Dec 15, 2024
1 parent 4efeff8 commit 910c28b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ add_executable(MagnumGameApp MagnumGameApp.cpp
MagnumGameApp.h
DebugLines.cpp
DebugLines.h
MagnumGameApp_text.cpp
MagnumGameApp_ui.cpp
MagnumGameApp_input.cpp
Tweakables.cpp
Tweakables.h
Expand Down
1 change: 0 additions & 1 deletion src/GameAssets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace MagnumGame {

using namespace Magnum::Math::Literals;


static Containers::Optional<Containers::String> findDirectory(Containers::StringView dirName) {
using namespace Corrade::Utility;

Expand Down
10 changes: 3 additions & 7 deletions src/MagnumGameApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ namespace MagnumGame {

explicit MagnumGameApp(const Arguments &arguments);

static Containers::Optional<Containers::String> findDirectory(Containers::StringView dirName);

enum ControllerKeys {
KEY_NONE = 0,
KEY_FORWARD = 1,
Expand Down Expand Up @@ -70,7 +68,6 @@ namespace MagnumGame {
void anyEvent(SDL_Event &event) override;
#endif

bool isPlaying();

GL::Framebuffer _framebuffer{NoCreate};
GL::Renderbuffer _color{NoCreate}, _objectId{NoCreate}, _depth{NoCreate};
Expand Down Expand Up @@ -100,21 +97,20 @@ namespace MagnumGame {
Containers::Pointer<Tweakables> _tweakables;

int _controllerKeysHeld;
std::unordered_map<int,Vector2> _pointerPressLocations{};
std::unordered_map<Long,Vector2> _pointerPressLocations{};

static ControllerKeys getKeyBit(Key key);
Vector2 getPlayerControlVector() const;

void updateStatusText();

bool isPlaying();
void startGame();

void setupUserInterface();

void renderTextBuffer(const Matrix3 & matrix3, const Color3& color3, const Color3& outlineColour, GL::Mesh &mesh);

UnsignedInt pickObjectIdAt(Vector2 eventPosition);

static ControllerKeys getKeyBit(Key key);
};

}
26 changes: 16 additions & 10 deletions src/MagnumGameApp_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,24 @@ namespace MagnumGame {
return keyBit;
}


Vector2 MagnumGameApp::getPlayerControlVector() const {
return {
((_controllerKeysHeld&KEY_RIGHT)?1.0f:0.0f) - ((_controllerKeysHeld&KEY_LEFT)?1.0f:0.0f),
((_controllerKeysHeld&KEY_FORWARD)?1.0f:0.0f) - ((_controllerKeysHeld&KEY_BACKWARD)?1.0f:0.0f),
};
}


void MagnumGameApp::keyPressEvent(KeyEvent &event) {
auto key = event.key();
if (_debugScreen) {
if (_debugScreen->handleKeyPress(key, event.modifiers())) {
event.setAccepted();
return;
}
if (_debugScreen && _debugScreen->handleKeyPress(key, event.modifiers())) {
event.setAccepted();
return;
}
if (_currentScreen) {
if (_currentScreen->handleKeyPress(key, event.modifiers())) {
event.setAccepted();
return;
}
if (_currentScreen && _currentScreen->handleKeyPress(key, event.modifiers())) {
event.setAccepted();
return;
}

auto keyBit = getKeyBit(key);
Expand Down Expand Up @@ -78,6 +83,7 @@ namespace MagnumGame {
auto keyBit = getKeyBit(event.key());
if (keyBit) {
_controllerKeysHeld &= ~keyBit;
event.setAccepted();
}
}

Expand Down
18 changes: 2 additions & 16 deletions src/MagnumGameApp_text.cpp → src/MagnumGameApp_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@ namespace MagnumGame {


void MagnumGameApp::setupUserInterface() {
using namespace Corrade::Utility;
auto font = _fontManager.loadAndInstantiate("StbTrueTypeFont");
assert(font);

auto fontsDir = _assets->getFontsDir();
for (auto& file : *list(fontsDir, Path::ListFlag::SkipDirectories | Path::ListFlag::SkipDotAndDotDot)) {
auto fontFileName = Path::join(fontsDir, file);
if (font->openFile(fontFileName, 80.0f)) {

_ui.emplace(std::move(font));
break;
}
if (font->openFile(Utility::Path::join(_assets->getFontsDir(), "Roboto-Regular.ttf"), 80.0f)) {
_ui.emplace(std::move(font));
}

_hudScreen.emplace();
Expand All @@ -55,13 +48,6 @@ namespace MagnumGame {
});
}

Vector2 MagnumGameApp::getPlayerControlVector() const {
return {
((_controllerKeysHeld&KEY_RIGHT)?1.0f:0.0f) - ((_controllerKeysHeld&KEY_LEFT)?1.0f:0.0f),
((_controllerKeysHeld&KEY_FORWARD)?1.0f:0.0f) - ((_controllerKeysHeld&KEY_BACKWARD)?1.0f:0.0f),
};
}

void MagnumGameApp::updateStatusText() {
std::ostringstream oss;
if (_gameState && _gameState->getPlayer()->getBody()) {
Expand Down
4 changes: 0 additions & 4 deletions src/UserInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace MagnumGame {
using namespace Corrade;
using namespace Magnum;


static inline Color4 textColour = 0xffffff_rgbf;
static inline Color4 selectedTextColour = 0xffccaa_rgbf;
static inline Color4 outlineColour = 0x111111_rgbf;
Expand Down Expand Up @@ -135,9 +134,6 @@ namespace MagnumGame {
int _selectedItemIndex{-1};
};




class UserInterface {
public:
explicit UserInterface(Containers::Pointer<Text::AbstractFont>&& font);
Expand Down

0 comments on commit 910c28b

Please sign in to comment.