Skip to content

Instantly share code, notes, and snippets.

@victorholt
Created May 2, 2017 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorholt/20eaf694071583fedf67a39c9f5c3015 to your computer and use it in GitHub Desktop.
Save victorholt/20eaf694071583fedf67a39c9f5c3015 to your computer and use it in GitHub Desktop.
FoliageComponent Header
//
// Created by Victor Holt on 5/1/2017.
//
#pragma once
#include <gs-common/PreCompiledHeadersUrho.h>
#include <gs-common/helpers/SimplePerlin.h>
#include <gs-common/helpers/Array2D.h>
#include <gs-graphics/CustomMesh.h>
using namespace Urho3D;
gs_nsstart
#define MAX_FOLIAGE_NODES 10000
class GridCell;
class SenchaThread;
class FoliageComponent : public Component
{
URHO3D_OBJECT(FoliageComponent, Component);
public:
//! Constructor.
//! \param context
FoliageComponent(Context* context);
/// Register object factory and attributes.
static void RegisterObject(Context* context);
//! Handles the Urho3D Update Event.
//! \param eventType
//! \param eventData
void HandleUpdateEvent(StringHash eventType, VariantMap& eventData);
//! Initializes the foliage component.
//! \param gridCell
//! \param name
//! \param model
//! \param maxFoliageNodes
void Initialize(GridCell* gridCell, const String& name, Model* model = nullptr, uint32_t maxFoliageNodes = MAX_FOLIAGE_NODES);
protected:
//! Saves the foliage to disk.
void Save(VectorBuffer& data);
//! Loads the foliage from disk.
void Load();
//! Unloads the foliage.
void Unload();
protected:
/// Base foliage node.
Node* foliageNode_;
/// Foilage model group.
StaticModelGroup* modelGroup_;
/// Model for building the foliage mesh.
Model* baseModel_;
/// Basic mesh for building grass.
CustomMesh* foliageMesh_;
/// Grid cell for the foliage.
GridCell* gridCell_;
/// Bounding box for the foliage.
BoundingBox boundingBox_;
/// Name used for saving the foliage.
String name_;
/// File path for the foliage.
String filePath_;
/// Checks if the foliage is loaded.
bool isLoaded_ = false;
/// Whether or not the foliage is in view.
bool isInView_ = false;
/// Whether or not the foliage is processing.
bool isProcessing_ = false;
/// Max foliage nodes that can be created.
uint32_t maxFoliageNodes_ = MAX_FOLIAGE_NODES;
/// Render distance of the foliage.
float maxRenderDistance_;
/// List of instanced nodes.
PODVector<Node*> instancedNodes_;
/// Mutex for loading foliage.
Mutex foliageLock_;
/// Loading thread.
SenchaThread* loadThread_;
/// Unloading thread.
SenchaThread* unloadThread_;
};
gs_nsend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment