Skip to content

Commit

Permalink
Merge branch 'release/v0.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdenCullen committed May 17, 2014
2 parents 64d2117 + aefb387 commit fbd5a1a
Show file tree
Hide file tree
Showing 28 changed files with 1,984 additions and 995 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Dash Logo](https://cloud.githubusercontent.com/assets/512416/2726786/6618d624-c5c2-11e3-9049-23637e5a1739.png)](https://github.com/Circular-Studios/Dash/wiki)

# [![Build Status](http://img.shields.io/travis/Circular-Studios/Dash/develop.svg?style=flat)](https://travis-ci.org/Circular-Studios/Dash) [![Docs](http://img.shields.io/badge/docs-ddoc-yellow.svg?style=flat)](http://circular-studios.github.io/Dash/docs/v0.7.0) [![Gitter Chat](http://img.shields.io/badge/chat-gitter-brightgreen.svg?style=flat)](https://gitter.im/Circular-Studios/Dash) [![Release](http://img.shields.io/github/release/Circular-Studios/Dash.svg?style=flat)](http://code.dlang.org/packages/dash)
# [![Build Status](http://img.shields.io/travis/Circular-Studios/Dash/develop.svg?style=flat)](https://travis-ci.org/Circular-Studios/Dash) [![Docs](http://img.shields.io/badge/docs-ddoc-yellow.svg?style=flat)](http://circular-studios.github.io/Dash/docs/latest) [![Gitter Chat](http://img.shields.io/badge/chat-gitter-brightgreen.svg?style=flat)](https://gitter.im/Circular-Studios/Dash) [![Release](http://img.shields.io/github/release/Circular-Studios/Dash.svg?style=flat)](http://code.dlang.org/packages/dash)

If you're reading this page, chances are you fall into one of the following categories:

Expand Down
44 changes: 39 additions & 5 deletions source/components/animation.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
module components.animation;
import core.properties;
import components.icomponent;
import components.component;
import utility;

import derelict.assimp3.assimp;
Expand All @@ -12,7 +12,7 @@ import gl3n.linalg;
/**
* Animation object which handles all animation specific to the gameobject
*/
class Animation : IComponent
class Animation : Component
{
private:
/// Asset animation that the gameobject is animating based off of
Expand All @@ -26,6 +26,11 @@ private:
/// If the gameobject should be animating
bool _animating;

/// Animation to return to if _animateOnce is true
int _returnAnimation;
/// If the animation is animating once, then returning to _returnAnimation
bool _animateOnce;

public:
/// Bone transforms for the current pose (Passed to the shader)
mixin( Property!_currBoneTransforms );
Expand All @@ -51,9 +56,15 @@ public:
// Update currentanimtime based on deltatime and animations fps
_currentAnimTime += Time.deltaTime * 24.0f;

if( _currentAnimTime >= 95.0f )
if( _currentAnimTime >= _animationData.animationSet[ _currentAnim ].duration * 24 - 1 )
{
_currentAnimTime = 0.0f;

if( _animateOnce )
{
_animateOnce = false;
_currentAnim = _returnAnimation;
}
}
}

Expand Down Expand Up @@ -84,8 +95,8 @@ public:
_currentAnimTime = 0.0f;
}
/**
* Switches the current animation
*/
* Switches the current animation
*/
void changeAnimation( int animNumber, int startAnimTime )
{
if( animNumber < _animationData.animationSet.length )
Expand All @@ -96,6 +107,21 @@ public:
else
logWarning( "Could not change to new animation, the animation did not exist." );
}
/**
* Runs an animation once, then returns
*/
void runAnimationOnce( int animNumber, int returnAnimNumber )
{
if( animNumber < _animationData.animationSet.length )
{
_animateOnce = true;
_currentAnim = animNumber;
_returnAnimation = returnAnimNumber;
_currentAnimTime = 0;
}
else
logWarning( "Could not change to new animation, the animation did not exist." );
}

/**
* Shutdown the gameobjects animation data
Expand Down Expand Up @@ -152,6 +178,14 @@ public:
addAnimationSet( animations[ ii ], 24 );
}

/**
* Returns the animation as an addible component.
*/
Animation getComponent()
{
return new Animation( this );
}

/**
* Recurse the node hierarchy, parsing it into a usable bone hierarchy
*
Expand Down
106 changes: 81 additions & 25 deletions source/components/assets.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@
* Defines the static Assets class, a static class which manages all textures, meshes, materials, and animations.
*/
module components.assets;
import components, utility;
import core.properties, components, utility;

import std.string, std.array;
import std.string, std.array, std.algorithm;

import yaml;
import derelict.freeimage.freeimage, derelict.assimp3.assimp;
AssetManager Assets;

static this()
{
Assets = new AssetManager;
}

/**
* Assets manages all assets that aren't code, GameObjects, or Prefabs.
*/
final class AssetManager
abstract final class Assets
{
static:
private:
Material[][Resource] materialResources;

package:
Mesh[string] meshes;
Texture[string] textures;
Material[string] materials;
AssetAnimation[string] animations;

public:
/// Basic quad, generally used for billboarding.
Expand All @@ -33,7 +30,7 @@ public:
/**
* Get the asset with the given type and name.
*/
final T get( T )( string name ) if( is( T == Mesh ) || is( T == Texture ) || is( T == Material ) || is( T == AssetAnimation ))
T get( T )( string name ) if( is( T == Mesh ) || is( T == Texture ) || is( T == Material ) || is( T == AssetAnimation ))
{
enum get( Type, string array ) = q{
static if( is( T == $Type ) )
Expand All @@ -60,7 +57,7 @@ public:
/**
* Load all assets in the FilePath.ResourceHome folder.
*/
final void initialize()
void initialize()
{
DerelictFI.load();

Expand All @@ -73,29 +70,31 @@ public:
// Load the unitSquare
unitSquare = new Mesh( "", aiImportFileFromMemory(
unitSquareMesh.toStringz, unitSquareMesh.length,
aiProcess_CalcTangentSpace | aiProcess_Triangulate |
aiProcess_CalcTangentSpace | aiProcess_Triangulate |
aiProcess_JoinIdenticalVertices | aiProcess_SortByPType,
"obj" ).mMeshes[0] );

foreach( file; FilePath.scanDirectory( FilePath.Resources.Meshes ) )
foreach( file; scanDirectory( Resources.Meshes ) )
{
// Load mesh
const aiScene* scene = aiImportFile( file.fullPath.toStringz,
aiProcess_CalcTangentSpace | aiProcess_Triangulate |
aiProcess_CalcTangentSpace | aiProcess_Triangulate |
aiProcess_JoinIdenticalVertices | aiProcess_SortByPType );
assert( scene, "Failed to load scene file '" ~ file.fullPath ~ "' Error: " ~ aiGetErrorString().fromStringz );

// If animation data, add animation
if( file.baseFileName in meshes )
logWarning( "Mesh ", file.baseFileName, " exsists more than once." );

// Add mesh
if( scene.mNumMeshes > 0 )
{
auto newMesh = new Mesh( file.fullPath, scene.mMeshes[ 0 ] );

if( scene.mNumAnimations > 0 )
animations[ file.baseFileName ] = new AssetAnimation( scene.mAnimations, scene.mNumAnimations, scene.mMeshes[ 0 ], scene.mRootNode );
newMesh.animationData = new AssetAnimation( scene.mAnimations, scene.mNumAnimations, scene.mMeshes[ 0 ], scene.mRootNode );

meshes[ file.baseFileName ] = new Mesh( file.fullPath, scene.mMeshes[ 0 ] );
meshes[ file.baseFileName ] = newMesh;
}
else
{
Expand All @@ -106,34 +105,71 @@ public:
aiReleaseImport( scene );
}

foreach( file; FilePath.scanDirectory( FilePath.Resources.Textures ) )
foreach( file; scanDirectory( Resources.Textures ) )
{
if( file.baseFileName in textures )
logWarning( "Texture ", file.baseFileName, " exists more than once." );

textures[ file.baseFileName ] = new Texture( file.fullPath );
}

foreach( object; loadYamlDocuments( FilePath.Resources.Materials ) )
foreach( objFile; loadYamlFiles( Resources.Materials ) )
{
Node object = objFile[ 0 ];
auto name = object[ "Name" ].as!string;

if( name in materials )
logWarning( "Material ", name, " exists more than once." );

materials[ name ] = Material.createFromYaml( object );

auto newMat = cast(Material)createYamlObject[ "Material" ]( object );
materials[ name ] = newMat;
materialResources[ objFile[ 1 ] ] ~= newMat;
}

meshes.rehash();
textures.rehash();
materials.rehash();
animations.rehash();
materialResources.rehash();
}

/**
* Refresh the assets that have changed.
*/
void refresh()
{
enum refresh( string aaName ) = q{
foreach_reverse( name; $aaName.keys )
{
auto asset = $aaName[ name ];
if( !asset.resource.exists )
{
asset.shutdown();
$aaName.remove( name );
}
else if( asset.resource.needsRefresh )
{
logDebug( "Refreshing ", name, "." );
asset.refresh();
}
}
}.replace( "$aaName", aaName );

mixin( refresh!q{meshes} );
mixin( refresh!q{textures} );

// Iterate over each file, and it's materials
refreshYamlObjects!(
node => cast(Material)createYamlObject[ "Material" ]( node ),
node => node[ "Name" ].get!string in materials,
( node, mat ) => materials[ node[ "Name" ].get!string ] = mat,
mat => materials.remove( mat.name ) )
( materialResources );
}

/**
* Unload and destroy all stored assets.
*/
final void shutdown()
void shutdown()
{
enum shutdown( string aaName, string friendlyName ) = q{
foreach_reverse( name; $aaName.keys )
Expand All @@ -149,7 +185,27 @@ public:
mixin( shutdown!( q{meshes}, "Mesh" ) );
mixin( shutdown!( q{textures}, "Texture" ) );
mixin( shutdown!( q{materials}, "Material" ) );
mixin( shutdown!( q{animations}, "Animation" ) );
}
}

abstract class Asset : Component
{
private:
bool _isUsed;
Resource _resource;

public:
/// Whether or not the material is actually used.
mixin( Property!( _isUsed, AccessModifier.Package ) );
/// The resource containing this asset.
mixin( RefGetter!_resource );

/**
* Creates asset with resource.
*/
this( Resource resource )
{
_resource = resource;
}
}

Expand Down
Loading

0 comments on commit fbd5a1a

Please sign in to comment.