osb/source/client/StarClientApplication.hpp
2023-06-20 14:33:09 +10:00

118 lines
2.9 KiB
C++

#ifndef STAR_CLIENT_APPLICATION_HPP
#define STAR_CLIENT_APPLICATION_HPP
#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 {
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;
};
void changeState(MainAppState newState);
void setError(String const& error);
void setError(String const& error, std::exception const& e);
void updateMods();
void updateModsWarning();
void updateSplash();
void updateError();
void updateTitle();
void updateRunning();
bool isActionTaken(InterfaceAction action) const;
bool isActionTakenEdge(InterfaceAction action) const;
void updateCamera();
RootUPtr m_root;
ThreadFunction<void> m_rootLoader;
MainAppState m_state = MainAppState::Startup;
// Valid after applicationInit is called
MainMixerPtr m_mainMixer;
GuiContextPtr m_guiContext;
// 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;
List<KeyDownEvent> m_heldKeyEvents;
List<KeyDownEvent> m_edgeKeyEvents;
Maybe<PendingMultiPlayerConnection> m_pendingMultiPlayerConnection;
Maybe<HostAddressWithPort> m_currentRemoteJoin;
};
}
#endif