forked from townforge/townforge
game: edit mode switch on/off speedups
This commit is contained in:
parent
fbc158483b
commit
e74bd4023e
2
external/urho3d
vendored
2
external/urho3d
vendored
@ -1 +1 @@
|
||||
Subproject commit 4bef0a0d327064830acfd745721b3ec178d5ec30
|
||||
Subproject commit 3b3459975f962407d1b88099ae0d534c155153a1
|
@ -58,6 +58,7 @@ target_link_libraries(game_util
|
||||
set(game_sources
|
||||
UTBRendererBatcher.cpp
|
||||
audio.cc
|
||||
block_model.cpp
|
||||
camera-controller.cc
|
||||
citymesh-urho3d.cc
|
||||
cloud-cover.cc
|
||||
@ -121,6 +122,7 @@ set(game_sources
|
||||
set(game_headers
|
||||
UTBRendererBatcher.h
|
||||
audio.h
|
||||
block_model.h
|
||||
caching-source-builder.h
|
||||
camera-controller.h
|
||||
citymesh-urho3d.h
|
||||
|
54
src/game/block_model.cpp
Normal file
54
src/game/block_model.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
//
|
||||
// Copyright (c) 2008-2019 the Urho3D project.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#include <Urho3D/Core/Context.h>
|
||||
#include <Urho3D/Math/Ray.h>
|
||||
#include <Urho3D/Graphics/OctreeQuery.h>
|
||||
#include "block_model.h"
|
||||
|
||||
using namespace Urho3D;
|
||||
|
||||
namespace Urho3D
|
||||
{
|
||||
extern const char* GEOMETRY_CATEGORY;
|
||||
}
|
||||
|
||||
BlockModel::BlockModel(Context* context) :
|
||||
StaticModel(context)
|
||||
{
|
||||
}
|
||||
|
||||
BlockModel::~BlockModel() = default;
|
||||
|
||||
void BlockModel::RegisterObject(Context* context)
|
||||
{
|
||||
context->RegisterFactory<BlockModel>(GEOMETRY_CATEGORY);
|
||||
}
|
||||
|
||||
void BlockModel::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results)
|
||||
{
|
||||
float distance = query.ray_.HitDistance(GetWorldBoundingBox());
|
||||
if (distance >= query.maxDistance_)
|
||||
return;
|
||||
|
||||
return StaticModel::ProcessRayQuery(query, results);
|
||||
}
|
50
src/game/block_model.h
Normal file
50
src/game/block_model.h
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// Copyright (c) 2008-2019 the Urho3D project.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Urho3D/Container/Vector.h>
|
||||
#include <Urho3D/Graphics/StaticModel.h>
|
||||
|
||||
namespace Urho3D
|
||||
{
|
||||
class Context;
|
||||
class RayOctreeQuery;
|
||||
class RayQueryResult;
|
||||
}
|
||||
|
||||
/// Static model component.
|
||||
class BlockModel : public Urho3D::StaticModel
|
||||
{
|
||||
URHO3D_OBJECT(BlockModel, StaticModel);
|
||||
|
||||
public:
|
||||
/// Construct.
|
||||
explicit BlockModel(Urho3D::Context* context);
|
||||
/// Destruct.
|
||||
~BlockModel() override;
|
||||
/// Register object factory. Drawable must be registered first.
|
||||
static void RegisterObject(Urho3D::Context* context);
|
||||
|
||||
/// Process octree raycast. May be called from a worker thread.
|
||||
void ProcessRayQuery(const Urho3D::RayOctreeQuery& query, Urho3D::PODVector<Urho3D::RayQueryResult>& results) override;
|
||||
};
|
@ -14,6 +14,7 @@
|
||||
#include "cc/cc_influence.h"
|
||||
#include "cc/cc_potential.h"
|
||||
#include "cc/cc_palette.h"
|
||||
#include "block_model.h"
|
||||
#include "citymesh-urho3d.h"
|
||||
|
||||
using namespace Urho3D;
|
||||
@ -474,7 +475,7 @@ void CityMeshSection::setHighlight(const Selection &selection, const std::shared
|
||||
auto &tile = nodes[y - vy0][x - vx0].blocks[h];
|
||||
if (!tile.node)
|
||||
continue;
|
||||
StaticModel *model = tile.node->GetComponent<StaticModel>();
|
||||
StaticModel *model = tile.node->GetComponent<BlockModel>();
|
||||
if (!model)
|
||||
continue;
|
||||
{
|
||||
@ -597,7 +598,7 @@ static StaticModel *createModel(const std::vector<float> &vertex_data, const std
|
||||
model->SetVertexBuffers(vertexBuffers, morphRangeStarts, morphRangeCounts);
|
||||
model->SetIndexBuffers(indexBuffers);
|
||||
|
||||
staticModel->SetModel(model);
|
||||
staticModel->SetModel(model, true);
|
||||
staticModel->SetMaterial(material);
|
||||
|
||||
return staticModel;
|
||||
@ -927,7 +928,7 @@ void CityMeshSection::RebuildFlags(const C &flags, bool highlight_new)
|
||||
|
||||
const bool is_new = highlight_new && h >= prevth;
|
||||
const MaterialVersion mv = is_new ? MVNew : MVNormal;
|
||||
SharedPtr<StaticModel> blockObject;
|
||||
SharedPtr<BlockModel> blockObject;
|
||||
if (!nodes[y - vy0][x - vx0].blocks[h].node)
|
||||
{
|
||||
switch (flagRenderMode)
|
||||
@ -992,7 +993,7 @@ void CityMeshSection::RebuildFlags(const C &flags, bool highlight_new)
|
||||
if (!groups[material_type])
|
||||
{
|
||||
groups[material_type] = blockNode->CreateComponent<StaticModelGroup>();
|
||||
groups[material_type]->SetModel(cache->GetResource<Model>("Models/Plane.mdl"));
|
||||
groups[material_type]->SetModel(cache->GetResource<Model>("Models/Plane.mdl"), true);
|
||||
groups[material_type]->SetMaterial(resources.materials[mv][material_type]);
|
||||
}
|
||||
if (!front_hidden) add_quad_instance(groups[material_type], blockNode, Vector3(U2F1(,x), h + 0.5f, U2F1(,y) - .5f), resources.FrontRotation);
|
||||
@ -1009,8 +1010,8 @@ void CityMeshSection::RebuildFlags(const C &flags, bool highlight_new)
|
||||
SharedPtr<Node> blockNode(parent->CreateChild("block"));
|
||||
blockNode->SetScale(1);
|
||||
blockNode->SetPosition(Vector3(U2F1(,x), h + 0.5f, U2F1(,y)));
|
||||
blockObject = blockNode->CreateComponent<StaticModel>();
|
||||
blockObject->SetModel(resources.block8Model);
|
||||
blockObject = blockNode->CreateComponent<BlockModel>();
|
||||
blockObject->SetModel(resources.block8Model, true);
|
||||
blockObject->SetMaterial(resources.materials[mv][material_type]);
|
||||
nodes[y - vy0][x - vx0].blocks[h].node = std::move(blockNode);
|
||||
break;
|
||||
@ -1029,7 +1030,7 @@ void CityMeshSection::RebuildFlags(const C &flags, bool highlight_new)
|
||||
}
|
||||
}
|
||||
else
|
||||
blockObject = nodes[y - vy0][x - vx0].blocks[h].node->GetComponent<StaticModel>();
|
||||
blockObject = nodes[y - vy0][x - vx0].blocks[h].node->GetComponent<BlockModel>();
|
||||
if (blockObject)
|
||||
blockObject->SetMaterial(resources.materials[mv][material_type]);
|
||||
nodes[y - vy0][x - vx0].blocks[h].material = material_type;
|
||||
@ -1293,7 +1294,7 @@ void CityMeshSection::Update(float timeStep, bool mark_new_block)
|
||||
{
|
||||
if (block.node)
|
||||
{
|
||||
block.node->GetComponent<StaticModel>()->SetMaterial(resources.materials[mv][block.material]);
|
||||
block.node->GetComponent<BlockModel>()->SetMaterial(resources.materials[mv][block.material]);
|
||||
}
|
||||
block.is_new = false;
|
||||
}
|
||||
@ -1339,7 +1340,7 @@ void CityMeshUrho3D::CreateGroundTiles()
|
||||
selectionNode->SetPosition(Vector3(0.0f, 0.02f * height_scale, 0.0f));
|
||||
selectionNode->SetScale(Vector3(0.0f, 0.01f, 0.0f));
|
||||
auto* selectionObject = selectionNode->CreateComponent<StaticModel>();
|
||||
selectionObject->SetModel(resources.selectionModel);
|
||||
selectionObject->SetModel(resources.selectionModel, true);
|
||||
selectionObject->SetMaterial(resources.selectedMaterial);
|
||||
selectionObject->SetCastShadows(false);
|
||||
|
||||
@ -1358,7 +1359,7 @@ void CityMeshUrho3D::CreateGroundTiles()
|
||||
cursorNode[i]->SetPosition(Vector3(0.0f, 0.0f, 0.0f));
|
||||
cursorNode[i]->SetScale(Vector3(1.0f, 1.0f, 1.0f));
|
||||
auto* cursorObject = cursorNode[i]->CreateComponent<StaticModel>();
|
||||
cursorObject->SetModel(resources.cursorModel);
|
||||
cursorObject->SetModel(resources.cursorModel, true);
|
||||
cursorObject->SetMaterial(resources.cursorMaterial[i]);
|
||||
cursorObject->SetCastShadows(false);
|
||||
}
|
||||
|
@ -56,6 +56,7 @@
|
||||
#include "horizon.h"
|
||||
#include "controls.h"
|
||||
#include "audio.h"
|
||||
#include "block_model.h"
|
||||
#include "UTBRendererBatcher.h"
|
||||
#include "ui-file-selector.h"
|
||||
#include "ui-tb-message-box.h"
|
||||
@ -565,6 +566,7 @@ void CryptoCityUrho3D::Setup(void)
|
||||
|
||||
//context_->RegisterFactory<ProcSky>();
|
||||
ProcSky::RegisterObject(context_);
|
||||
BlockModel::RegisterObject(context_);
|
||||
}
|
||||
|
||||
void CryptoCityUrho3D::Start()
|
||||
|
Loading…
Reference in New Issue
Block a user