Skip to content

Commit

Permalink
#5231: Move ParticlesManager to core binary. Extend interface as need…
Browse files Browse the repository at this point in the history
…ed by the ParticleEditor, which is now integrated into the main UI without any host ParticleEditorModule.
  • Loading branch information
codereader committed May 19, 2020
1 parent 2947e18 commit c7978f6
Show file tree
Hide file tree
Showing 31 changed files with 146 additions and 215 deletions.
32 changes: 32 additions & 0 deletions include/iparticles.h
Expand Up @@ -54,6 +54,8 @@ class IParticleDef
*/
virtual const std::string& getFilename() const = 0;

virtual void setFilename(const std::string& filename) = 0;

/**
* Set/get the depth hack flag
*/
Expand Down Expand Up @@ -158,6 +160,13 @@ typedef std::shared_ptr<IRenderableParticle> IRenderableParticlePtr;
*/
typedef std::function< void (const IParticleDef&) > ParticleDefVisitor;

/* CONSTANTS */
namespace
{
const char* PARTICLES_DIR = "particles/";
const char* PARTICLES_EXT = "prt";
}

/// Inteface for the particles manager
class IParticlesManager :
public RegisterableModule
Expand All @@ -173,6 +182,12 @@ class IParticlesManager :
/// Return the definition object for the given named particle system
virtual IParticleDefPtr getDefByName(const std::string& name) = 0;

// Finds or creates the particle def with the given name, always returns non-NULL
virtual IParticleDefPtr findOrInsertParticleDef(const std::string& name) = 0;

// Removes the named particle definition from the storage
virtual void removeParticleDef(const std::string& name) = 0;

/**
* Create a renderable particle, which is capable of compiling the
* particle system into actual geometry usable for the backend rendersystem.
Expand All @@ -184,6 +199,23 @@ class IParticlesManager :
/// Create and return a particle node for the named particle system
virtual IParticleNodePtr createParticleNode(const std::string& name) = 0;

/**
* Writes the named particle declaration to the file it is associated with,
* replacing any existing declaration with the same name in that file.
* Any other particle declarations that happen to be declared in the same file
* will be preserved.
*
* If the associated file is stored in a PK4, a copy is written to the current
* fs_game ("mod") folder and that file is used for the save operation.
* No other particle declaration will be removed from the copied file.
*
* Note: this method does not check if the named particle system is already
* defined in a different file.
*
* throws a std::runtime_error on any failure.
*/
virtual void saveParticleDef(const std::string& particle) = 0;

/**
* \brief
* Force the particles manager to reload all particle definitions from the
Expand Down
1 change: 1 addition & 0 deletions install/menu.xml
Expand Up @@ -207,6 +207,7 @@
<menuItem name="bindEntity" caption="&amp;Bind selected entities" command="BindSelection" />
<menuItem name="animviewer" caption="MD5 Animation Viewer" command="AnimationPreview" />
<menuItem name="entityclasstree" caption="Entity Class Tree..." command="EntityClassTree" icon="icon_classname.png" />
<menuItem name="particleEditor" caption="Particle Editor..." command="ParticlesEditor" icon="particle16.png" />
</subMenu>

<subMenu name="brush" caption="B&amp;rush">
Expand Down
9 changes: 0 additions & 9 deletions radiant/Makefile.am
Expand Up @@ -134,16 +134,7 @@ darkradiant_SOURCES = main.cpp \
modelfile/picomodel/pm_terrain.c \
modelfile/picomodel/pm_ms3d.c \
modelfile/picomodel/pm_3ds.c \
particles/ParticleNode.cpp \
particles/RenderableParticle.cpp \
particles/RenderableParticleBunch.cpp \
particles/ParticlesManager.cpp \
particles/StageDef.cpp \
particles/particles.cpp \
particles/ParticleParameter.cpp \
particles/editor/ParticleEditor.cpp \
particles/RenderableParticleStage.cpp \
particles/ParticleDef.cpp \
render/OpenGLModule.cpp \
render/View.cpp \
ui/UserInterfaceModule.cpp \
Expand Down
61 changes: 0 additions & 61 deletions radiant/particles/editor/ParticleEditorModule.h

This file was deleted.

8 changes: 0 additions & 8 deletions radiant/particles/particles.cpp

This file was deleted.

4 changes: 4 additions & 0 deletions radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -33,6 +33,7 @@
#include "ui/about/AboutDialog.h"
#include "ui/eclasstree/EClassTree.h"
#include "ui/entitylist/EntityList.h"
#include "ui/particles/ParticleEditor.h"
#include "textool/TexTool.h"
#include "modelexport/ExportAsModelDialog.h"
#include "ui/filters/FilterOrthoContextMenuItem.h"
Expand Down Expand Up @@ -218,6 +219,9 @@ void UserInterfaceModule::registerUICommands()

GlobalCommandSystem().addCommand("RefreshShaders",
std::bind(&UserInterfaceModule::refreshShadersCmd, this, std::placeholders::_1));

// Add the callback event
GlobalCommandSystem().addCommand("ParticlesEditor", ParticleEditor::DisplayDialog);
}

// Static module registration
Expand Down
Expand Up @@ -24,8 +24,6 @@
#include <wx/stattext.h>
#include <wx/notebook.h>

#include "../ParticlesManager.h"

#include "os/fs.h"
#include "os/file.h"
#include "os/path.h"
Expand Down Expand Up @@ -1293,7 +1291,7 @@ void ParticleEditor::setupEditParticle()
// Generate a temporary name for this particle, and instantiate a copy
std::string temporaryParticleName = selectedName + EDIT_SUFFIX;

_currentDef = ParticlesManager::Instance().findOrInsertParticleDef(temporaryParticleName);
_currentDef = GlobalParticlesManager().findOrInsertParticleDef(temporaryParticleName);
_currentDef->setFilename(def->getFilename());

_currentDef->copyFrom(*def);
Expand All @@ -1306,7 +1304,7 @@ void ParticleEditor::releaseEditParticle()
{
if (_currentDef && string::ends_with(_currentDef->getName(), EDIT_SUFFIX))
{
ParticlesManager::Instance().removeParticleDef(_currentDef->getName());
GlobalParticlesManager().removeParticleDef(_currentDef->getName());
}

_currentDef.reset();
Expand Down Expand Up @@ -1367,7 +1365,7 @@ bool ParticleEditor::saveCurrentParticle()
// Write changes to disk, and return the result
try
{
ParticlesManager::Instance().saveParticleDef(origDef->getName());
GlobalParticlesManager().saveParticleDef(origDef->getName());
return true;
}
catch (std::runtime_error& err)
Expand Down Expand Up @@ -1469,24 +1467,24 @@ void ParticleEditor::_onNewParticle(wxCommandEvent& ev)
createAndSelectNewParticle();
}

ParticleDefPtr ParticleEditor::createAndSelectNewParticle()
IParticleDefPtr ParticleEditor::createAndSelectNewParticle()
{
std::string particleName = queryNewParticleName();

if (particleName.empty())
{
return ParticleDefPtr(); // no valid name, abort
return IParticleDefPtr(); // no valid name, abort
}

std::string destFile = queryParticleFile();

if (destFile.empty())
{
return ParticleDefPtr(); // no valid destination file
return IParticleDefPtr(); // no valid destination file
}

// Good filename, good destination file, we're set to go
ParticleDefPtr particle = ParticlesManager::Instance().findOrInsertParticleDef(particleName);
auto particle = GlobalParticlesManager().findOrInsertParticleDef(particleName);

particle->setFilename(destFile);

Expand Down Expand Up @@ -1589,7 +1587,7 @@ void ParticleEditor::_onCloneCurrentParticle(wxCommandEvent& ev)
IParticleDefPtr original = GlobalParticlesManager().getDefByName(origName);

// Create a new particle (this will already set up an edit particle, which is empty)
ParticleDefPtr newParticle = createAndSelectNewParticle();
auto newParticle = createAndSelectNewParticle();

if (!newParticle)
{
Expand Down
Expand Up @@ -9,8 +9,6 @@
#include "wxutil/WindowPosition.h"
#include "wxutil/PanedPosition.h"

#include "../ParticleDef.h"

class wxSpinCtrlDouble;
class wxSpinCtrl;
class wxSpinDoubleEvent;
Expand Down Expand Up @@ -43,7 +41,7 @@ class ParticleEditor :
wxDataViewItem _selectedStageIter;

// The particle definition we're working on
particles::ParticleDefPtr _currentDef;
particles::IParticleDefPtr _currentDef;

bool _callbacksDisabled;
bool _saveInProgress;
Expand Down Expand Up @@ -83,7 +81,7 @@ class ParticleEditor :

// Creates a particle with a new name (queried from the user), selects it and returns the particle ref
// Returns NULL if the user cancelled in some way
particles::ParticleDefPtr createAndSelectNewParticle();
particles::IParticleDefPtr createAndSelectNewParticle();

// Highlight the named particle in the treeview
void selectParticleDef(const std::string& particleDefName);
Expand Down
8 changes: 8 additions & 0 deletions radiantcore/Makefile.am
Expand Up @@ -95,6 +95,14 @@ libradiantcore_la_SOURCES = Radiant.cpp \
model/NullModelNode.cpp \
modulesystem/ModuleLoader.cpp \
modulesystem/ModuleRegistry.cpp \
particles/ParticleDef.cpp \
particles/ParticleNode.cpp \
particles/ParticleParameter.cpp \
particles/ParticlesManager.cpp \
particles/RenderableParticle.cpp \
particles/RenderableParticleBunch.cpp \
particles/RenderableParticleStage.cpp \
particles/StageDef.cpp \
rendersystem/backend/glprogram/ARBBumpProgram.cpp \
rendersystem/backend/glprogram/ARBDepthFillProgram.cpp \
rendersystem/backend/glprogram/GenericVFPProgram.cpp \
Expand Down
File renamed without changes.
Expand Up @@ -57,7 +57,7 @@ class ParticleDef
return _filename;
}

void setFilename(const std::string& filename)
void setFilename(const std::string& filename) override
{
_filename = filename;
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -24,6 +24,7 @@
#include <functional>
#include <regex>
#include "string/predicate.h"
#include "module/StaticModule.h"

namespace particles
{
Expand Down Expand Up @@ -108,7 +109,7 @@ IRenderableParticlePtr ParticlesManager::getRenderableParticle(const std::string
}
}

ParticleDefPtr ParticlesManager::findOrInsertParticleDef(const std::string& name)
IParticleDefPtr ParticlesManager::findOrInsertParticleDef(const std::string& name)
{
ensureDefsLoaded();

Expand Down Expand Up @@ -486,4 +487,6 @@ void ParticlesManager::stripParticleDefFromStream(std::istream& input,
}
}

module::StaticModule<ParticlesManager> particlesManagerModule;

} // namespace particles
Expand Up @@ -12,13 +12,6 @@
namespace particles
{

/* CONSTANTS */
namespace
{
const char* PARTICLES_DIR = "particles/";
const char* PARTICLES_EXT = "prt";
}

class ParticlesManager :
public IParticlesManager
{
Expand All @@ -42,33 +35,16 @@ class ParticlesManager :

IParticleDefPtr getDefByName(const std::string& name) override;

// Finds or creates the particle def with the given name, always returns non-NULL
ParticleDefPtr findOrInsertParticleDef(const std::string& name);
IParticleDefPtr findOrInsertParticleDef(const std::string& name) override;

// Removes the named particle definition from the storage
void removeParticleDef(const std::string& name);
void removeParticleDef(const std::string& name) override;

IRenderableParticlePtr getRenderableParticle(const std::string& name) override;
IParticleNodePtr createParticleNode(const std::string& name) override;

void reloadParticleDefs() override;

/**
* Writes the named particle declaration to the file it is associated with,
* replacing any existing declaration with the same name in that file.
* Any other particle declarations that happen to be declared in the same file
* will be preserved.
*
* If the associated file is stored in a PK4, a copy is written to the current
* fs_game ("mod") folder and that file is used for the save operation.
* No other particle declaration will be removed from the copied file.
*
* Note: this method does not check if the named particle system is already
* defined in a different file.
*
* throws a std::runtime_error on any failure.
*/
void saveParticleDef(const std::string& particle);
void saveParticleDef(const std::string& particle) override;

// RegisterableModule implementation
const std::string& getName() const override;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c7978f6

Please sign in to comment.