osb/source/client/StarClientApplication.hpp

126 lines
3.1 KiB
C++
Raw Normal View History

#pragma once
2023-06-20 04:33:09 +00:00
#include "StarUniverseServer.hpp"
#include "StarUniverseClient.hpp"
#include "StarWorldPainter.hpp"
#include "StarGameTypes.hpp"
#include "StarMainInterface.hpp"
#include "StarMainMixer.hpp"
#include "StarTitleScreen.hpp"
#include "StarErrorScreen.hpp"
#include "StarCinematic.hpp"
#include "StarKeyBindings.hpp"
#include "StarMainApplication.hpp"
namespace Star {
2023-07-12 12:16:12 +00:00
STAR_CLASS(Input);
STAR_CLASS(Voice);
2023-06-20 04:33:09 +00:00
class ClientApplication : public Application {
protected:
virtual void startup(StringList const& cmdLineArgs) override;
virtual void shutdown() override;
virtual void applicationInit(ApplicationControllerPtr appController) override;
virtual void renderInit(RendererPtr renderer) override;
virtual void windowChanged(WindowMode windowMode, Vec2U screenSize) override;
virtual void processInput(InputEvent const& event) override;
virtual void update() override;
virtual void render() override;
virtual void getAudioData(int16_t* stream, size_t len) override;
private:
enum class MainAppState {
Quit,
Startup,
Mods,
ModsWarning,
Splash,
Error,
Title,
SinglePlayer,
MultiPlayer
};
struct PendingMultiPlayerConnection {
Variant<P2PNetworkingPeerId, HostAddressWithPort> server;
String account;
String password;
};
2024-03-19 14:53:34 +00:00
void renderReload();
2023-06-20 04:33:09 +00:00
void changeState(MainAppState newState);
void setError(String const& error);
void setError(String const& error, std::exception const& e);
void updateMods(float dt);
void updateModsWarning(float dt);
void updateSplash(float dt);
void updateError(float dt);
void updateTitle(float dt);
void updateRunning(float dt);
2023-06-20 04:33:09 +00:00
bool isActionTaken(InterfaceAction action) const;
bool isActionTakenEdge(InterfaceAction action) const;
void updateCamera(float dt);
2023-06-20 04:33:09 +00:00
RootUPtr m_root;
ThreadFunction<void> m_rootLoader;
2024-03-19 14:53:34 +00:00
CallbackListenerPtr m_reloadListener;
2023-06-20 04:33:09 +00:00
MainAppState m_state = MainAppState::Startup;
// Valid after applicationInit is called
MainMixerPtr m_mainMixer;
GuiContextPtr m_guiContext;
2023-07-01 20:34:43 +00:00
InputPtr m_input;
2023-07-12 12:16:12 +00:00
VoicePtr m_voice;
2023-06-20 04:33:09 +00:00
// Valid after renderInit is called the first time
CinematicPtr m_cinematicOverlay;
ErrorScreenPtr m_errorScreen;
// Valid if main app state >= Title
PlayerStoragePtr m_playerStorage;
StatisticsPtr m_statistics;
UniverseClientPtr m_universeClient;
TitleScreenPtr m_titleScreen;
// Valid if main app state > Title
PlayerPtr m_player;
WorldPainterPtr m_worldPainter;
WorldRenderData m_renderData;
MainInterfacePtr m_mainInterface;
// Valid if main app state == SinglePlayer
UniverseServerPtr m_universeServer;
float m_cameraXOffset = 0.0f;
float m_cameraYOffset = 0.0f;
bool m_snapBackCameraOffset = false;
int m_cameraOffsetDownTicks = 0;
Vec2F m_cameraPositionSmoother;
Vec2F m_cameraSmoothDelta;
int m_minInterfaceScale = 2;
int m_maxInterfaceScale = 3;
Vec2F m_crossoverRes;
Vec2F m_controllerLeftStick;
Vec2F m_controllerRightStick;
2023-06-20 04:33:09 +00:00
List<KeyDownEvent> m_heldKeyEvents;
List<KeyDownEvent> m_edgeKeyEvents;
Maybe<PendingMultiPlayerConnection> m_pendingMultiPlayerConnection;
Maybe<HostAddressWithPort> m_currentRemoteJoin;
};
}