mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 13:15:32 +00:00
implemented toggleWater (twa); formatting again
This commit is contained in:
parent
2f096e131d
commit
79c2a2e465
8 changed files with 142 additions and 105 deletions
|
@ -92,19 +92,26 @@ OEngine::Render::Fader* RenderingManager::getFader()
|
|||
return mRendering.getFader();
|
||||
}
|
||||
|
||||
void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store){
|
||||
|
||||
mObjects.removeCell(store);
|
||||
void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store)
|
||||
{
|
||||
mObjects.removeCell(store);
|
||||
mActors.removeCell(store);
|
||||
|
||||
}
|
||||
void RenderingManager::removeWater (){
|
||||
|
||||
void RenderingManager::removeWater ()
|
||||
{
|
||||
if(mWater){
|
||||
delete mWater;
|
||||
mWater = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderingManager::toggleWater()
|
||||
{
|
||||
if (mWater)
|
||||
mWater->toggle();
|
||||
}
|
||||
|
||||
void RenderingManager::cellAdded (MWWorld::Ptr::CellStore *store)
|
||||
{
|
||||
mObjects.buildStaticGeometry (*store);
|
||||
|
|
|
@ -91,8 +91,10 @@ class RenderingManager: private RenderingInterface {
|
|||
void moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position);
|
||||
void scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale);
|
||||
void rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation);
|
||||
|
||||
void checkUnderwater();
|
||||
void setWaterHeight(const float height);
|
||||
void toggleWater();
|
||||
|
||||
/// \param store Cell the object was in previously (\a ptr has already been updated to the new cell).
|
||||
void moveObjectToCell (const MWWorld::Ptr& ptr, const Ogre::Vector3& position, MWWorld::Ptr::CellStore *store);
|
||||
|
|
|
@ -2,87 +2,94 @@
|
|||
|
||||
namespace MWRender
|
||||
{
|
||||
Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) : mCamera (camera), mViewport (camera->getViewport()), mSceneManager (camera->getSceneManager())
|
||||
|
||||
Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
||||
mCamera (camera), mViewport (camera->getViewport()), mSceneManager (camera->getSceneManager()),
|
||||
mIsUnderwater(false)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Water", -1);
|
||||
Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Water", -1);
|
||||
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false);
|
||||
} catch(...) {}
|
||||
|
||||
mTop = cell->water;
|
||||
|
||||
mIsUnderwater = false;
|
||||
|
||||
mWaterPlane = Ogre::Plane(Ogre::Vector3::UNIT_Y, 0);
|
||||
|
||||
Ogre::MeshManager::getSingleton().createPlane("water", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, mWaterPlane, CELL_SIZE*5, CELL_SIZE * 5, 10, 10, true, 1, 3,5, Ogre::Vector3::UNIT_Z);
|
||||
|
||||
mWater = mSceneManager->createEntity("water");
|
||||
|
||||
mWater->setMaterialName("Examples/Water0");
|
||||
|
||||
mWaterNode = mSceneManager->getRootSceneNode()->createChildSceneNode();
|
||||
mWaterNode->setPosition(0, mTop, 0);
|
||||
|
||||
if(!(cell->data.flags & cell->Interior))
|
||||
{
|
||||
mWaterNode->setPosition(getSceneNodeCoordinates(cell->data.gridX, cell->data.gridY));
|
||||
}
|
||||
mWaterNode->attachObject(mWater);
|
||||
}
|
||||
|
||||
|
||||
Water::~Water()
|
||||
{
|
||||
Ogre::MeshManager::getSingleton().remove("water");
|
||||
|
||||
mWaterNode->detachObject(mWater);
|
||||
mSceneManager->destroyEntity(mWater);
|
||||
mSceneManager->destroySceneNode(mWaterNode);
|
||||
|
||||
Ogre::CompositorManager::getSingleton().removeCompositorChain(mViewport);
|
||||
}
|
||||
|
||||
void Water::changeCell(const ESM::Cell* cell)
|
||||
{
|
||||
mTop = cell->water;
|
||||
|
||||
if(!(cell->data.flags & cell->Interior))
|
||||
mWaterNode->setPosition(getSceneNodeCoordinates(cell->data.gridX, cell->data.gridY));
|
||||
else
|
||||
setHeight(mTop);
|
||||
}
|
||||
|
||||
void Water::setHeight(const float height)
|
||||
{
|
||||
mTop = height;
|
||||
mWaterNode->setPosition(0, height, 0);
|
||||
}
|
||||
|
||||
void Water::toggle()
|
||||
{
|
||||
mWater->setVisible(!mWater->getVisible());
|
||||
}
|
||||
|
||||
void Water::checkUnderwater(float y)
|
||||
{
|
||||
if ((mIsUnderwater && y > mTop) || !mWater->isVisible())
|
||||
{
|
||||
try {
|
||||
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false);
|
||||
} catch(...) {}
|
||||
|
||||
mTop = cell->water;
|
||||
|
||||
mIsUnderwater = false;
|
||||
}
|
||||
|
||||
mWaterPlane = Ogre::Plane(Ogre::Vector3::UNIT_Y, 0);
|
||||
|
||||
Ogre::MeshManager::getSingleton().createPlane("water", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, mWaterPlane, CELL_SIZE*5, CELL_SIZE * 5, 10, 10, true, 1, 3,5, Ogre::Vector3::UNIT_Z);
|
||||
|
||||
|
||||
mWater = mSceneManager->createEntity("water");
|
||||
|
||||
mWater->setMaterialName("Examples/Water0");
|
||||
|
||||
mWaterNode = mSceneManager->getRootSceneNode()->createChildSceneNode();
|
||||
mWaterNode->setPosition(0, mTop, 0);
|
||||
|
||||
if(!(cell->data.flags & cell->Interior))
|
||||
{
|
||||
mWaterNode->setPosition(getSceneNodeCoordinates(cell->data.gridX, cell->data.gridY));
|
||||
}
|
||||
mWaterNode->attachObject(mWater);
|
||||
}
|
||||
|
||||
|
||||
Water::~Water()
|
||||
if (!mIsUnderwater && y < mTop && mWater->isVisible())
|
||||
{
|
||||
Ogre::MeshManager::getSingleton().remove("water");
|
||||
|
||||
mWaterNode->detachObject(mWater);
|
||||
mSceneManager->destroyEntity(mWater);
|
||||
mSceneManager->destroySceneNode(mWaterNode);
|
||||
|
||||
Ogre::CompositorManager::getSingleton().removeCompositorChain(mViewport);
|
||||
}
|
||||
|
||||
void Water::changeCell(const ESM::Cell* cell)
|
||||
{
|
||||
mTop = cell->water;
|
||||
|
||||
if(!(cell->data.flags & cell->Interior))
|
||||
mWaterNode->setPosition(getSceneNodeCoordinates(cell->data.gridX, cell->data.gridY));
|
||||
else
|
||||
setHeight(mTop);
|
||||
}
|
||||
|
||||
void Water::setHeight(const float height)
|
||||
{
|
||||
mTop = height;
|
||||
mWaterNode->setPosition(0, height, 0);
|
||||
}
|
||||
|
||||
|
||||
void Water::checkUnderwater(float y)
|
||||
{
|
||||
if (mIsUnderwater && y > mTop)
|
||||
{
|
||||
try {
|
||||
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false);
|
||||
} catch(...) {}
|
||||
mIsUnderwater = false;
|
||||
}
|
||||
|
||||
if (!mIsUnderwater && y < mTop)
|
||||
{
|
||||
try {
|
||||
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", true);
|
||||
} catch(...) {}
|
||||
mIsUnderwater = true;
|
||||
}
|
||||
}
|
||||
|
||||
Ogre::Vector3 Water::getSceneNodeCoordinates(int gridX, int gridY)
|
||||
{
|
||||
return Ogre::Vector3(gridX * CELL_SIZE + (CELL_SIZE / 2), mTop, -gridY * CELL_SIZE - (CELL_SIZE / 2));
|
||||
try {
|
||||
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", true);
|
||||
} catch(...) {}
|
||||
mIsUnderwater = true;
|
||||
}
|
||||
}
|
||||
|
||||
Ogre::Vector3 Water::getSceneNodeCoordinates(int gridX, int gridY)
|
||||
{
|
||||
return Ogre::Vector3(gridX * CELL_SIZE + (CELL_SIZE / 2), mTop, -gridY * CELL_SIZE - (CELL_SIZE / 2));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -7,37 +7,34 @@
|
|||
namespace MWRender {
|
||||
|
||||
/// Water rendering
|
||||
class Water : Ogre::RenderTargetListener, Ogre::Camera::Listener {
|
||||
static const int CELL_SIZE = 8192;
|
||||
Ogre::Camera *mCamera;
|
||||
Ogre::SceneManager *mSceneManager;
|
||||
Ogre::Viewport *mViewport;
|
||||
class Water : Ogre::RenderTargetListener, Ogre::Camera::Listener
|
||||
{
|
||||
static const int CELL_SIZE = 8192;
|
||||
Ogre::Camera *mCamera;
|
||||
Ogre::SceneManager *mSceneManager;
|
||||
Ogre::Viewport *mViewport;
|
||||
|
||||
|
||||
Ogre::Plane mWaterPlane;
|
||||
Ogre::SceneNode *mWaterNode;
|
||||
Ogre::Entity *mWater;
|
||||
|
||||
Ogre::Plane mWaterPlane;
|
||||
Ogre::SceneNode *mWaterNode;
|
||||
Ogre::Entity *mWater;
|
||||
bool mIsUnderwater;
|
||||
int mTop;
|
||||
|
||||
Ogre::Vector3 mOldCameraPos;
|
||||
bool mIsUnderwater;
|
||||
int mTop;
|
||||
Ogre::Vector3 getSceneNodeCoordinates(int gridX, int gridY);
|
||||
|
||||
public:
|
||||
Water (Ogre::Camera *camera, const ESM::Cell* cell);
|
||||
~Water();
|
||||
|
||||
void toggle();
|
||||
|
||||
|
||||
Ogre::Vector3 getSceneNodeCoordinates(int gridX, int gridY);
|
||||
|
||||
public:
|
||||
|
||||
Water (Ogre::Camera *camera, const ESM::Cell* cell);
|
||||
~Water();
|
||||
void checkUnderwater(float y);
|
||||
void changeCell(const ESM::Cell* cell);
|
||||
void setHeight(const float height);
|
||||
|
||||
void checkUnderwater(float y);
|
||||
void changeCell(const ESM::Cell* cell);
|
||||
void setHeight(const float height);
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -126,4 +126,5 @@ op 0x2000140: ChangeWeather
|
|||
op 0x2000141: GetWaterLevel
|
||||
op 0x2000142: SetWaterLevel
|
||||
op 0x2000143: ModWaterLevel
|
||||
opcodes 0x2000142-0x3ffffff unused
|
||||
op 0x2000144: ToggleWater, twa
|
||||
opcodes 0x2000145-0x3ffffff unused
|
||||
|
|
|
@ -175,6 +175,19 @@ namespace MWScript
|
|||
}
|
||||
};
|
||||
|
||||
class OpToggleWater : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
InterpreterContext& context =
|
||||
static_cast<InterpreterContext&> (runtime.getContext());
|
||||
|
||||
context.getWorld().toggleWater();
|
||||
}
|
||||
};
|
||||
|
||||
const int opcodeXBox = 0x200000c;
|
||||
const int opcodeOnActivate = 0x200000d;
|
||||
const int opcodeActivate = 0x2000075;
|
||||
|
@ -187,6 +200,7 @@ namespace MWScript
|
|||
const int opcodeFadeIn = 0x200013c;
|
||||
const int opcodeFadeOut = 0x200013d;
|
||||
const int opcodeFadeTo = 0x200013e;
|
||||
const int opcodeToggleWater = 0x2000144;
|
||||
|
||||
void registerExtensions (Compiler::Extensions& extensions)
|
||||
{
|
||||
|
@ -204,6 +218,8 @@ namespace MWScript
|
|||
extensions.registerInstruction ("fadein", "f", opcodeFadeIn);
|
||||
extensions.registerInstruction ("fadeout", "f", opcodeFadeOut);
|
||||
extensions.registerInstruction ("fadeto", "ff", opcodeFadeTo);
|
||||
extensions.registerInstruction ("togglewater", "", opcodeToggleWater);
|
||||
extensions.registerInstruction ("twa", "", opcodeToggleWater);
|
||||
}
|
||||
|
||||
void installOpcodes (Interpreter::Interpreter& interpreter)
|
||||
|
@ -220,6 +236,7 @@ namespace MWScript
|
|||
interpreter.installSegment5 (opcodeFadeIn, new OpFadeIn);
|
||||
interpreter.installSegment5 (opcodeFadeOut, new OpFadeOut);
|
||||
interpreter.installSegment5 (opcodeFadeTo, new OpFadeTo);
|
||||
interpreter.installSegment5 (opcodeToggleWater, new OpToggleWater);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -761,4 +761,9 @@ namespace MWWorld
|
|||
mRendering->setWaterHeight(height);
|
||||
}
|
||||
|
||||
void World::toggleWater()
|
||||
{
|
||||
mRendering->toggleWater();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -114,6 +114,7 @@ namespace MWWorld
|
|||
Ptr::CellStore *getInterior (const std::string& name);
|
||||
|
||||
void setWaterHeight(const float height);
|
||||
void toggleWater();
|
||||
|
||||
void adjustSky();
|
||||
|
||||
|
|
Loading…
Reference in a new issue