OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
gamesession.h
Go to the documentation of this file.
1#pragma once
2
3#include <Tempest/Sound>
4#include <Tempest/SoundDevice>
5#include <memory>
6
7#include "game/gamescript.h"
8#include "camera.h"
9#include "gametime.h"
10
11class World;
12class WorldView;
13class Npc;
14class Serialize;
15class GSoundEffect;
16class SoundFx;
17class ParticleFx;
18class VisualFx;
20class VersionInfo;
21class GthFont;
22
23class GameSession final {
24 public:
25 GameSession()=delete;
26 GameSession(const GameSession&)=delete;
27 GameSession(std::string file);
30
31 void save(Serialize& fout, std::string_view name, const Tempest::Pixmap &screen);
32 void setupSettings();
33
34 void setWorld(std::unique_ptr<World> &&w);
35 auto clearWorld() -> std::unique_ptr<World>;
36
37 void changeWorld(std::string_view world, std::string_view wayPoint);
38 void exitSession();
39
40 auto version() const -> const VersionInfo&;
41
42 const World* world() const { return wrld.get(); }
43 World* world() { return wrld.get(); }
44
45 WorldView* view() const;
46 GameScript* script() const { return vm.get(); }
47
48 Camera& camera() { return *cam; }
49
50 auto loadSound(const Tempest::Sound& raw) -> Tempest::SoundEffect;
51 auto loadSound(const SoundFx& fx, bool& looped) -> Tempest::SoundEffect;
52
53 Npc* player();
54 void updateListenerPos(const Camera::ListenerPos& lpos);
55
56 gtime time() const { return wrldTime; }
57 void setTime(gtime t);
58 void tick(uint64_t dt);
59 uint64_t tickCount() const { return ticks; }
60
61 void setTimeMultiplyer(float t);
62
63 void updateAnimation(uint64_t dt);
64
65 auto updateDialog(const GameScript::DlgChoice &dlg, Npc &player, Npc &npc) -> std::vector<GameScript::DlgChoice>;
66 void dialogExec(const GameScript::DlgChoice &dlg, Npc &player, Npc &npc);
67
68 std::string_view messageFromSvm(std::string_view id, int voice) const;
69 std::string_view messageByName (std::string_view id) const;
70 uint32_t messageTime (std::string_view id) const;
71
73 bool isNpcInDialog(const Npc& npc) const;
74 bool isInDialog() const;
75
76 private:
77 struct ChWorld {
78 std::string zen, wp;
79 };
80
81 struct HeroStorage {
82 void save(Npc& npc);
83 void putToWorld(World &owner, std::string_view wayPoint) const;
84
85 std::vector<uint8_t> storage;
86 };
87
88 bool isWorldKnown(std::string_view name) const;
89 void initPerceptions();
90 void initScripts(bool firstTime);
91 auto implChangeWorld(std::unique_ptr<GameSession> &&game, std::string_view world, std::string_view wayPoint) -> std::unique_ptr<GameSession>;
92 auto findStorage(std::string_view name) -> const WorldStateStorage&;
93
94 Tempest::SoundDevice sound;
95
96 std::unique_ptr<Camera> cam;
97 std::unique_ptr<GameScript> vm;
98 std::unique_ptr<World> wrld;
99
100 uint64_t ticks = 0, wrldTimePart = 0;
101 uint64_t timeMul = 1000, timeMulFract = 0;
102 gtime wrldTime;
103
104 std::vector<WorldStateStorage> visitedWorlds;
105
106 ChWorld chWorld;
107 bool exitSessionFlg=false;
108
109 static const uint64_t multTime;
110 static const uint64_t divTime;
111 };
std::string_view messageFromSvm(std::string_view id, int voice) const
auto updateDialog(const GameScript::DlgChoice &dlg, Npc &player, Npc &npc) -> std::vector< GameScript::DlgChoice >
GameSession(const GameSession &)=delete
GameScript * script() const
Definition gamesession.h:46
void tick(uint64_t dt)
GameSession()=delete
auto clearWorld() -> std::unique_ptr< World >
void changeWorld(std::string_view world, std::string_view wayPoint)
World * world()
Definition gamesession.h:43
void dialogExec(const GameScript::DlgChoice &dlg, Npc &player, Npc &npc)
uint64_t tickCount() const
Definition gamesession.h:59
void setTime(gtime t)
Camera & camera()
Definition gamesession.h:48
void setTimeMultiplyer(float t)
void updateAnimation(uint64_t dt)
void exitSession()
uint32_t messageTime(std::string_view id) const
bool isNpcInDialog(const Npc &npc) const
void setupSettings()
void updateListenerPos(const Camera::ListenerPos &lpos)
bool isInDialog() const
auto version() const -> const VersionInfo &
void save(Serialize &fout, std::string_view name, const Tempest::Pixmap &screen)
AiOuputPipe * openDlgOuput(Npc &player, Npc &npc)
WorldView * view() const
void setWorld(std::unique_ptr< World > &&w)
const World * world() const
Definition gamesession.h:42
std::string_view messageByName(std::string_view id) const
gtime time() const
Definition gamesession.h:56
auto loadSound(const Tempest::Sound &raw) -> Tempest::SoundEffect
Definition npc.h:25
Definition world.h:31