1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +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

@@ -16,6 +16,7 @@
#include "../../CCallback.h"
#include "../CPlayerInterface.h"
#include "../GameInstance.h"
#include "../adventureMap/AdventureMapInterface.h"
#include "../../lib/mapObjects/CGHeroInstance.h"
@@ -24,17 +25,17 @@
static bool compareObjectBlitOrder(ObjectInstanceID left, ObjectInstanceID right)
{
//FIXME: remove mh access
return MAPHANDLER->compareObjectBlitOrder(MAPHANDLER->getMap()->objects[left.getNum()], MAPHANDLER->getMap()->objects[right.getNum()]);
return GAME->map().compareObjectBlitOrder(GAME->map().getMap()->objects[left.getNum()], GAME->map().getMap()->objects[right.getNum()]);
}
MapRendererContextState::MapRendererContextState()
{
auto mapSize = LOCPLINT->cb->getMapSize();
auto mapSize = GAME->interface()->cb->getMapSize();
objects.resize(boost::extents[mapSize.z][mapSize.x][mapSize.y]);
logGlobal->debug("Loading map objects");
for(const auto & obj : MAPHANDLER->getMap()->objects)
for(const auto & obj : GAME->map().getMap()->objects)
addObject(obj);
logGlobal->debug("Done loading map objects");
}
@@ -50,7 +51,7 @@ void MapRendererContextState::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))
{
auto & container = objects[currTile.z][currTile.x][currTile.y];
auto position = std::upper_bound(container.begin(), container.end(), obj->id, compareObjectBlitOrder);
@@ -73,7 +74,7 @@ void MapRendererContextState::addMovingObject(const CGObjectInstance * object, c
{
int3 currTile(x, y, object->anchorPos().z);
if(LOCPLINT->cb->isInTheMap(currTile))
if(GAME->interface()->cb->isInTheMap(currTile))
{
auto & container = objects[currTile.z][currTile.x][currTile.y];
@@ -86,8 +87,8 @@ void MapRendererContextState::addMovingObject(const CGObjectInstance * object, c
void MapRendererContextState::removeObject(const CGObjectInstance * object)
{
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], object->id);
}