Skip to content

Commit

Permalink
#5532: Better parser support for videoMaps, recognising the expressio…
Browse files Browse the repository at this point in the history
…n and delivering a placeholder image.
  • Loading branch information
codereader committed Feb 26, 2021
1 parent aa2fb0b commit e55d8e6
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 9 deletions.
10 changes: 10 additions & 0 deletions include/ishaderexpression.h
Expand Up @@ -99,4 +99,14 @@ class IMapExpression
virtual std::string getExpressionString() = 0;
};

class IVideoMapExpression :
public IMapExpression
{
public:
virtual ~IVideoMapExpression() {}

// Whether the cinematic is looping
virtual bool isLooping() const = 0;
};

} // namespace
Binary file added install/bitmaps/videomap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 4 additions & 9 deletions radiantcore/shaders/ShaderTemplate.cpp
@@ -1,6 +1,7 @@
#include "ShaderTemplate.h"
#include "MapExpression.h"
#include "CameraCubeMapDecl.h"
#include "VideoMapExpression.h"

#include "itextstream.h"

Expand Down Expand Up @@ -595,15 +596,9 @@ bool ShaderTemplate::parseBlendMaps(parser::DefTokeniser& tokeniser, const std::
else if (token == "videomap")
{
_currentLayer->setMapType(ShaderLayer::MapType::VideoMap);

std::string nextToken = tokeniser.nextToken();
string::to_lower(nextToken);

if (nextToken == "loop")
{
// Skip looping keyword and ignore the videomap expression
tokeniser.skipTokens(1);
}
_currentLayer->setBindableTexture(
VideoMapExpression::CreateForTokens(tokeniser)
);
}
else if (token == "soundmap")
{
Expand Down
71 changes: 71 additions & 0 deletions radiantcore/shaders/VideoMapExpression.h
@@ -0,0 +1,71 @@
#pragma once

#include "iimage.h"
#include "imodule.h"
#include "MapExpression.h"
#include "parser/DefTokeniser.h"
#include "string/case_conv.h"

namespace shaders
{

class VideoMapExpression :
public IVideoMapExpression,
public NamedBindable
{
private:
bool _looping;
std::string _filePath;

const char* const VIDEO_MAP_PLACEHOLDER = "videomap.png";

public:
VideoMapExpression(const std::string& filePath, bool looping) :
_filePath(filePath),
_looping(looping)
{}

virtual bool isCubeMap() const override
{
return false;
}

virtual bool isLooping() const override
{
return _looping;
}

virtual std::string getExpressionString() override
{
return _filePath;
}

virtual std::string getIdentifier() const override
{
return "__videoMap__" + _filePath;
}

virtual TexturePtr bindTexture(const std::string& name) const override
{
auto bimapsPath = module::GlobalModuleRegistry().getApplicationContext().getBitmapsPath();
auto img = GlobalImageLoader().imageFromFile(bimapsPath + VIDEO_MAP_PLACEHOLDER);

return img ? img->bindTexture(name) : TexturePtr();
}

static std::shared_ptr<VideoMapExpression> CreateForTokens(parser::DefTokeniser& tokeniser)
{
auto nextToken = tokeniser.nextToken();

if (string::to_lower_copy(nextToken) == "loop")
{
return std::make_shared<VideoMapExpression>(tokeniser.nextToken(), true);
}
else
{
return std::make_shared<VideoMapExpression>(nextToken, false);
}
}
};

}
1 change: 1 addition & 0 deletions tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -1020,6 +1020,7 @@
<ClInclude Include="..\..\radiantcore\shaders\textures\GLTextureManager.h" />
<ClInclude Include="..\..\radiantcore\shaders\textures\HeightmapCreator.h" />
<ClInclude Include="..\..\radiantcore\shaders\textures\TextureManipulator.h" />
<ClInclude Include="..\..\radiantcore\shaders\VideoMapExpression.h" />
<ClInclude Include="..\..\radiantcore\skins\Doom3ModelSkin.h" />
<ClInclude Include="..\..\radiantcore\skins\Doom3SkinCache.h" />
<ClInclude Include="..\..\radiantcore\undo\Operation.h" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Expand Up @@ -2079,5 +2079,8 @@
<ClInclude Include="..\..\radiantcore\entity\AttachmentData.h">
<Filter>src\entity</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\shaders\VideoMapExpression.h">
<Filter>src\shaders</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit e55d8e6

Please sign in to comment.