Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Missing fixes] Tile Culling mechanism #954

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Expand Up @@ -230,6 +230,9 @@ set(OD_SOURCEFILES

${SRC}/camera/CameraManager.cpp
${SRC}/camera/HermiteCatmullSpline.cpp
${SRC}/camera/CullingManager.cpp
${SRC}/camera/DummyArrayClass.cpp
${SRC}/camera/SlopeWalk.cpp

${SRC}/creatureeffect/CreatureEffect.cpp
${SRC}/creatureeffect/CreatureEffectExplosion.cpp
Expand Down Expand Up @@ -382,6 +385,7 @@ set(OD_SOURCEFILES
${SRC}/utils/LogManagerOgre.cpp
${SRC}/utils/Random.cpp
${SRC}/utils/ResourceManager.cpp
${SRC}/utils/Vector3i.cpp

${SRC}/ODApplication.cpp
${SRC}/main.cpp
Expand Down
32 changes: 31 additions & 1 deletion source/camera/CameraManager.cpp
Expand Up @@ -23,13 +23,16 @@

#include "gamemap/TileContainer.h"
#include "sound/SoundEffectsManager.h"
#include "camera/CullingManager.h"
#include "utils/LogManager.h"
#include "gamemap/GameMap.h"
#include <OgreCamera.h>
#include <OgreSceneNode.h>
#include <OgreSceneManager.h>
#include <OgreViewport.h>
#include <OgreRenderWindow.h>


#include <algorithm>

//! The camera base moving speed.
Expand All @@ -48,14 +51,16 @@ const Ogre::Degree ROTATION_SPEED = Ogre::Degree(90);
//! Default orientation on the X Axis
const Ogre::Real DEFAULT_X_AXIS_VIEW = 25.0;

CameraManager::CameraManager(Ogre::SceneManager* sceneManager, TileContainer* gm, Ogre::RenderWindow* renderWindow) :
CameraManager::CameraManager(Ogre::SceneManager* sceneManager, GameMap* gm, Ogre::RenderWindow* renderWindow) :
mCullingManager(nullptr),
mCircleMode(false),
mCatmullSplineMode(false),
mFirstIter(true),
mRadius(0.0),
mCenterX(0),
mCenterY(0),
mAlpha(0.0),

mActiveCamera(nullptr),
mActiveCameraNode(nullptr),
mGameMap(gm),
Expand All @@ -73,6 +78,7 @@ CameraManager::CameraManager(Ogre::SceneManager* sceneManager, TileContainer* gm
mSceneManager(sceneManager),
mViewport(nullptr)
{
mCullingManager = new CullingManager(this);
createViewport(renderWindow);
createCamera("RTS", 0.02, 300.0);
createCameraNode("RTS");
Expand Down Expand Up @@ -568,6 +574,30 @@ void CameraManager::move(const Direction direction, double aux)
}
}

void CameraManager::startCreatureCulling()
{

mCullingManager->startCreatureCulling();
}
void CameraManager::startTileCulling()
{

mCullingManager->startTileCulling();
}


bool CameraManager::onFrameEnded()
{
mCullingManager->onFrameEnded();
return true;
}

bool CameraManager::onFrameStarted()
{
mCullingManager->onFrameStarted();
return true;
}

bool CameraManager::isCameraMovingAtAll() const
{
return (mTranslateVectorAccel.x != 0 ||
Expand Down
20 changes: 14 additions & 6 deletions source/camera/CameraManager.h
Expand Up @@ -32,6 +32,9 @@
#include <cstdint>
#include <set>

class TileContainer;
class CullingManager;
class GameMap;
class TileContainer;

// The min/max camera height in tile size
Expand All @@ -48,6 +51,7 @@ enum class ViewModes : uint16_t

class CameraManager
{
friend class CullingManager;
public:
enum Direction
{
Expand All @@ -62,7 +66,7 @@ class CameraManager
fullStop
};

CameraManager(Ogre::SceneManager* sceneManager, TileContainer* gameMap, Ogre::RenderWindow* renderWindow);
CameraManager(Ogre::SceneManager* sceneManager, GameMap* gameMap, Ogre::RenderWindow* renderWindow);
~CameraManager()
{}

Expand All @@ -86,16 +90,19 @@ class CameraManager
return mTranslateVectorAccel;
}

bool onFrameStarted()
{ return true; }
bool onFrameEnded()
{ return true; }
bool onFrameStarted();
bool onFrameEnded();

CullingManager* mCullingManager;

/*! \brief Sets the camera to a new location while still satisfying the
* constraints placed on its movement
*/
void updateCameraFrameTime(const Ogre::Real frameTime);

void startCreatureCulling();
void startTileCulling();

/*! \brief Computes a vector whose z-component is 0 and whose x-y coordinates
* are the position on the floor that the camera is pointed at.
*/
Expand Down Expand Up @@ -185,7 +192,8 @@ class CameraManager
Ogre::Camera* mActiveCamera;
Ogre::SceneNode* mActiveCameraNode;

TileContainer* mGameMap;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless empty line

GameMap* mGameMap;

//! \brief Is true when a camera is flying to a given position.
bool mCameraIsFlying;
Expand Down