Skip to content

Commit

Permalink
Implement the info file module to persist the editing timer value.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Dec 30, 2017
1 parent 215f198 commit 325accd
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 9 deletions.
2 changes: 2 additions & 0 deletions radiant/Makefile.am
Expand Up @@ -225,6 +225,8 @@ darkradiant_SOURCES = main.cpp \
patch/PatchTesselation.cpp \
map/RootNode.cpp \
map/MapPosition.cpp \
map/EditingStopwatch.cpp \
map/EditingStopwatchInfoFileModule.cpp \
map/FindMapElements.cpp \
map/infofile/InfoFileManager.cpp \
map/infofile/InfoFile.cpp \
Expand Down
21 changes: 13 additions & 8 deletions radiant/map/EditingStopwatch.cpp
Expand Up @@ -8,6 +8,7 @@
#include "imapinfofile.h"

#include "modulesystem/StaticModule.h"
#include "EditingStopwatchInfoFileModule.h"

namespace map
{
Expand Down Expand Up @@ -48,9 +49,9 @@ void EditingStopwatch::initialiseModule(const ApplicationContext& ctx)
sigc::mem_fun(*this, &EditingStopwatch::onMapEvent)
);

/*GlobalMapInfoFileManager().registerInfoFileModule(
GlobalMapInfoFileManager().registerInfoFileModule(
std::make_shared<EditingStopwatchInfoFileModule>()
);*/
);

// Register the timer when the application has come up
GlobalRadiant().signal_radiantStarted().connect(
Expand All @@ -76,8 +77,7 @@ void EditingStopwatch::onIntervalReached(wxTimerEvent& ev)
if (GlobalMainFrame().isActiveApp() && GlobalMainFrame().screenUpdatesEnabled())
{
_secondsEdited += TIMER_INTERVAL_SECS;

rMessage() << "Current timer: " << _secondsEdited << " seconds" << std::endl;
//rMessage() << "Current timer: " << _secondsEdited << " seconds" << std::endl;
}
}

Expand All @@ -91,19 +91,19 @@ void EditingStopwatch::onMapEvent(IMap::MapEvent ev)
// the new value will be set by the InfoFileModule.
case IMap::MapLoading:
stop();
setEditingTime(0);
setTotalSecondsEdited(0);
break;

// Start the clock once the map is done loading
case IMap::MapLoaded:
start();
break;

// When a map is unloaded, we reset the value to 0 again
// to prevent leaving stuff behind.
case IMap::MapUnloaded:
stop();
setEditingTime(0);
setTotalSecondsEdited(0);
break;

// We start/stop during save operations
Expand Down Expand Up @@ -132,7 +132,12 @@ void EditingStopwatch::stop()
}
}

void EditingStopwatch::setEditingTime(unsigned long newValue)
unsigned long EditingStopwatch::getTotalSecondsEdited()
{
return _secondsEdited;
}

void EditingStopwatch::setTotalSecondsEdited(unsigned long newValue)
{
_secondsEdited = newValue;
}
Expand Down
4 changes: 3 additions & 1 deletion radiant/map/EditingStopwatch.h
Expand Up @@ -39,7 +39,9 @@ class EditingStopwatch :

void start();
void stop();
void setEditingTime(unsigned long newValue);

unsigned long getTotalSecondsEdited();
void setTotalSecondsEdited(unsigned long newValue);

// Internal accessor to the module
static EditingStopwatch& GetInstanceInternal();
Expand Down
101 changes: 101 additions & 0 deletions radiant/map/EditingStopwatchInfoFileModule.cpp
@@ -0,0 +1,101 @@
#include "EditingStopwatchInfoFileModule.h"

#include "itextstream.h"
#include "EditingStopwatch.h"
#include "parser/DefTokeniser.h"

namespace map
{

namespace
{
const char* const MAP_EDIT_TIMINGS = "MapEditTimings";
const char* const TOTAL_SECONDS_EDITED = "TotalSecondsEdited";
}

std::string EditingStopwatchInfoFileModule::getName()
{
return "Map Edit Stopwatch";
}

void EditingStopwatchInfoFileModule::onInfoFileSaveStart()
{}

void EditingStopwatchInfoFileModule::onSavePrimitive(const scene::INodePtr& node, std::size_t entityNum, std::size_t primitiveNum)
{}

void EditingStopwatchInfoFileModule::onSaveEntity(const scene::INodePtr& node, std::size_t entityNum)
{}

void EditingStopwatchInfoFileModule::writeBlocks(std::ostream& stream)
{
// Block output
stream << "\t" << MAP_EDIT_TIMINGS << std::endl;

stream << "\t{" << std::endl;

unsigned long secondsEdited = EditingStopwatch::GetInstanceInternal().getTotalSecondsEdited();

// TotalSecondsEdited { 4 }
stream << "\t\t" << TOTAL_SECONDS_EDITED << " { " << secondsEdited << " }" << std::endl;

stream << "\t}" << std::endl;

rMessage() << "Map Edit Timings written." << std::endl;
}

void EditingStopwatchInfoFileModule::onInfoFileSaveFinished()
{}

void EditingStopwatchInfoFileModule::onInfoFileLoadStart()
{}

bool EditingStopwatchInfoFileModule::canParseBlock(const std::string& blockName)
{
return blockName == MAP_EDIT_TIMINGS;
}

void EditingStopwatchInfoFileModule::parseBlock(const std::string& blockName, parser::DefTokeniser& tok)
{
// The opening brace
tok.assertNextToken("{");

int blockLevel = 1;

while (tok.hasMoreTokens() && blockLevel > 0)
{
std::string token = tok.nextToken();

if (token == TOTAL_SECONDS_EDITED)
{
// TotalSecondsEdited { 4 }
tok.assertNextToken("{");

// Parse the name, replacing the &quot; placeholder with a proper quote
unsigned long secondsEdited = string::convert<unsigned long>(tok.nextToken());

tok.assertNextToken("}");

rMessage() << "[InfoFile]: Parsed map editing time." << std::endl;

// Apply the parsed value
EditingStopwatch::GetInstanceInternal().setTotalSecondsEdited(secondsEdited);
}
else if (token == "{")
{
blockLevel++;
}
else if (token == "}")
{
blockLevel--;
}
}
}

void EditingStopwatchInfoFileModule::applyInfoToScene(const scene::IMapRootNodePtr & root, const NodeIndexMap & nodeMap)
{}

void EditingStopwatchInfoFileModule::onInfoFileLoadFinished()
{}

}
16 changes: 16 additions & 0 deletions radiant/map/EditingStopwatchInfoFileModule.h
Expand Up @@ -5,11 +5,27 @@
namespace map
{

/**
* Info File Module to persist the total map editing time to the
* .darkradiant map info file.
*/
class EditingStopwatchInfoFileModule :
public IMapInfoFileModule
{
public:
std::string getName() override;

void onInfoFileSaveStart() override;
void onSavePrimitive(const scene::INodePtr & node, std::size_t entityNum, std::size_t primitiveNum) override;
void onSaveEntity(const scene::INodePtr & node, std::size_t entityNum) override;
void writeBlocks(std::ostream & stream) override;
void onInfoFileSaveFinished() override;

void onInfoFileLoadStart() override;
bool canParseBlock(const std::string & blockName) override;
void parseBlock(const std::string & blockName, parser::DefTokeniser & tok) override;
void applyInfoToScene(const scene::IMapRootNodePtr & root, const NodeIndexMap & nodeMap) override;
void onInfoFileLoadFinished() override;
};

}
1 change: 1 addition & 0 deletions tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -332,6 +332,7 @@
<ClCompile Include="..\..\radiant\map\algorithm\Models.cpp" />
<ClCompile Include="..\..\radiant\map\algorithm\Skins.cpp" />
<ClCompile Include="..\..\radiant\map\EditingStopwatch.cpp" />
<ClCompile Include="..\..\radiant\map\EditingStopwatchInfoFileModule.cpp" />
<ClCompile Include="..\..\radiant\map\infofile\InfoFile.cpp" />
<ClCompile Include="..\..\radiant\map\infofile\InfoFileExporter.cpp" />
<ClCompile Include="..\..\radiant\map\infofile\InfoFileManager.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -934,6 +934,9 @@
<ClCompile Include="..\..\radiant\map\EditingStopwatch.cpp">
<Filter>src\map</Filter>
</ClCompile>
<ClCompile Include="..\..\radiant\map\EditingStopwatchInfoFileModule.cpp">
<Filter>src\map</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiant\RadiantModule.h">
Expand Down

0 comments on commit 325accd

Please sign in to comment.