1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

Added GameInstance class

- available as global GAME
- integrates LOCPLINT (CPlayerInterface)
- integrates CGI->mh (CMapHandler)
- integrates CSH (CServerHandler)
This commit is contained in:
Ivan Savenko
2025-02-11 15:23:33 +00:00
parent ffd37a8fa8
commit 156de5b17e
98 changed files with 1288 additions and 1131 deletions

View File

@ -13,6 +13,7 @@
#include "../CCallback.h"
#include "../CPlayerInterface.h"
#include "../GameEngine.h"
#include "../GameInstance.h"
#include "../mapView/mapHandler.h"
#include "../media/IMusicPlayer.h"
#include "../media/ISoundPlayer.h"
@ -83,7 +84,7 @@ void MapAudioPlayer::addObject(const CGObjectInstance * obj)
{
int3 currTile(obj->anchorPos().x - fx, obj->anchorPos().y - fy, obj->anchorPos().z);
if(LOCPLINT->cb->isInTheMap(currTile) && obj->coveringAt(currTile))
if(GAME->interface()->cb->isInTheMap(currTile) && obj->coveringAt(currTile))
objects[currTile.z][currTile.x][currTile.y].push_back(obj->id);
}
}
@ -95,7 +96,7 @@ void MapAudioPlayer::addObject(const CGObjectInstance * obj)
// visitable object - visitable tile acts as sound source
int3 currTile = obj->visitablePos();
if(LOCPLINT->cb->isInTheMap(currTile))
if(GAME->interface()->cb->isInTheMap(currTile))
objects[currTile.z][currTile.x][currTile.y].push_back(obj->id);
return;
@ -110,7 +111,7 @@ void MapAudioPlayer::addObject(const CGObjectInstance * obj)
{
int3 currTile = obj->anchorPos() + tile;
if(LOCPLINT->cb->isInTheMap(currTile))
if(GAME->interface()->cb->isInTheMap(currTile))
objects[currTile.z][currTile.x][currTile.y].push_back(obj->id);
}
return;
@ -119,9 +120,9 @@ void MapAudioPlayer::addObject(const CGObjectInstance * obj)
void MapAudioPlayer::removeObject(const CGObjectInstance * obj)
{
for(int z = 0; z < LOCPLINT->cb->getMapSize().z; z++)
for(int x = 0; x < LOCPLINT->cb->getMapSize().x; x++)
for(int y = 0; y < LOCPLINT->cb->getMapSize().y; y++)
for(int z = 0; z < GAME->interface()->cb->getMapSize().z; z++)
for(int x = 0; x < GAME->interface()->cb->getMapSize().x; x++)
for(int y = 0; y < GAME->interface()->cb->getMapSize().y; y++)
vstd::erase(objects[z][x][y], obj->id);
}
@ -131,7 +132,7 @@ std::vector<AudioPath> MapAudioPlayer::getAmbientSounds(const int3 & tile)
for(auto & objectID : objects[tile.z][tile.x][tile.y])
{
const auto & object = MAPHANDLER->getMap()->objects[objectID.getNum()];
const auto & object = GAME->map().getMap()->objects[objectID.getNum()];
assert(object);
if (!object)
@ -145,7 +146,7 @@ std::vector<AudioPath> MapAudioPlayer::getAmbientSounds(const int3 & tile)
}
}
if(MAPHANDLER->getMap()->isCoastalTile(tile))
if(GAME->map().getMap()->isCoastalTile(tile))
result.emplace_back(AudioPath::builtin("LOOPOCEA"));
return result;
@ -164,7 +165,7 @@ void MapAudioPlayer::updateAmbientSounds()
int3 pos = currentSelection->getSightCenter();
std::unordered_set<int3> tiles;
LOCPLINT->cb->getVisibleTilesInRange(tiles, pos, ENGINE->sound().ambientGetRange(), int3::DIST_CHEBYSHEV);
GAME->interface()->cb->getVisibleTilesInRange(tiles, pos, ENGINE->sound().ambientGetRange(), int3::DIST_CHEBYSHEV);
for(int3 tile : tiles)
{
int dist = pos.dist(tile, int3::DIST_CHEBYSHEV);
@ -179,7 +180,7 @@ void MapAudioPlayer::updateMusic()
{
if(audioPlaying && playerMakingTurn && currentSelection)
{
const auto * tile = LOCPLINT->cb->getTile(currentSelection->visitablePos());
const auto * tile = GAME->interface()->cb->getTile(currentSelection->visitablePos());
if (tile)
ENGINE->music().playMusicFromSet("terrain", tile->getTerrain()->getJsonKey(), true, false);
@ -201,11 +202,11 @@ void MapAudioPlayer::update()
MapAudioPlayer::MapAudioPlayer()
{
auto mapSize = LOCPLINT->cb->getMapSize();
auto mapSize = GAME->interface()->cb->getMapSize();
objects.resize(boost::extents[mapSize.z][mapSize.x][mapSize.y]);
for(const auto & obj : MAPHANDLER->getMap()->objects)
for(const auto & obj : GAME->map().getMap()->objects)
{
if (obj)
addObject(obj);