Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
   Copyright (c) 2018 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   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.

 */

#ifndef _RESOURCE_H_
#define _RESOURCE_H_

#include "Core/Math/Headers/MathMatrices.h"

namespace Divide {

/// When "CreateResource" is called, the resource is in "RES_UNKNOWN" state.
/// Once it has been instantiated it will move to the "RES_CREATED" state.
/// Calling "load" on a non-created resource will fail.
/// After "load" is called, the resource is move to the "RES_LOADING" state
/// Nothing can be done to the resource when it's in "RES_LOADING" state!
/// Once loading is complete, preferably in another thread,
/// the resource state will become "RES_LOADED" and ready to be used (e.g. added
/// to the SceneGraph)
/// Calling "unload" is only available for "RES_LOADED" state resources.
/// Calling this method will set the state to "RES_LOADING"
/// Once unloading is complete, the resource will become "RES_CREATED".
/// It will still exist, but won't contain any data.
/// RES_UNKNOWN and RES_CREATED are safe to delete

enum class ResourceState : U32 {
    RES_UNKNOWN = 0,  //<The resource exists, but it's state is undefined
    RES_CREATED = 1,  //<The pointer has been created and instantiated, but no
                      //data has been loaded
    RES_LOADING = 2,  //<The resource is loading or unloading, creating or
                      //deleting data, parsing scripts, etc
    RES_LOADED  = 3,  //<The resource is loaded and available
    COUNT
};

enum class ResourceType : U32 {
    DEFAULT = 0,
    GPU_OBJECT = 1, //< Textures, Render targets, shaders, etc
    COUNT
};

class Resource;
TYPEDEF_SMART_POINTERS_FOR_CLASS(Resource);

class CachedResource;
TYPEDEF_SMART_POINTERS_FOR_CLASS(CachedResource);

class Resource : public GUIDWrapper
{
   public:
    explicit Resource(ResourceType type,
                      const stringImpl& name);
    virtual ~Resource();

    /// Name management
    const stringImpl& getName() const;
    ResourceType getType() const;
    ResourceState getState() const;

   protected:
    virtual void setState(ResourceState currentState);

   protected:
    stringImpl   _name;
    ResourceType _resourceType;
    std::atomic<ResourceState> _resourceState;
};

class CachedResource : public Resource,
                       public std::enable_shared_from_this<CachedResource>
{
    friend class ResourceCache;
    friend class ResourceLoader;
    template <typename X>
    friend class ImplResourceLoader;

public:
    explicit CachedResource(ResourceType type,
                            size_t descriptorHash,
                            const stringImpl& name);
    explicit CachedResource(ResourceType type,
                            size_t descriptorHash,
                            const stringImpl& name,
                            const stringImpl& resourceName);
    explicit CachedResource(ResourceType type,
                            size_t descriptorHash,
                            const stringImpl& name,
                            const stringImpl& resourceName,
                            const stringImpl& resourceLocation);

    virtual ~CachedResource();


    /// Loading and unloading interface
    virtual bool load(const DELEGATE_CBK<void, CachedResource_wptr>& onLoadCallback);
    virtual bool unload();
    virtual bool resourceLoadComplete();

    size_t getDescriptorHash() const;
    /// Physical file location
    const stringImpl& getResourceLocation() const;
    /// Physical file name
    const stringImpl& getResourceName() const;

    void setStateCallback(ResourceState targetState, const DELEGATE_CBK<void, Resource_wptr>& cbk);

protected:
    void setState(ResourceState currentState) override;
    void setResourceName(const stringImpl& name);
    void setResourceLocation(const stringImpl& location);

protected:
    size_t _descriptorHash;
    stringImpl   _resourceLocation;  ///< Physical file location
    stringImpl   _resourceName;      ///< Physical file name
    std::array<DELEGATE_CBK<void, Resource_wptr>, to_base(ResourceState::COUNT)> _loadingCallbacks;
    mutable SharedLock _callbackLock;
};

enum class GeometryType : U32 {
    VEGETATION,  ///< For special rendering subroutines
    PRIMITIVE,   ///< Simple objects: Boxes, Spheres etc
    GEOMETRY     ///< All other forms of geometry
};

struct FileData {
    stringImpl ItemName;
    stringImpl ModelName;
    vec3<F32> scale;
    vec3<F32> position;
    vec3<F32> orientation;
    vec3<F32> colour;
    GeometryType type;
    F32 data;  ///< general purpose
    stringImpl data2;
    stringImpl data3;
    F32 version;
    bool isUnit;
    bool castsShadows;
    bool receivesShadows;
    /// Used to determine if it's a static object or dynamic. Affects lighting,
    /// navigation, etc.
    bool staticUsage;
    /// Used to determine if the object should be added to the nav mesh
    /// generation process or not
    bool navigationUsage;
    /// Used to determine if the object should be added to physics simulations
    bool physicsUsage;
    /// If physicsUsage is true, this determines if the node can be pushed
    /// around by other actors
    /// or if it is a static(fixed in space) actor
    bool physicsStatic;
    /// Used to force a geometry level parsing for nav mesh creation instead of
    /// the default
    /// bounding-box level
    bool useHighDetailNavMesh;
};

struct TerrainInfo {
    TerrainInfo() { position.set(0, 0, 0); }
    /// "variables" contains the various strings needed for each terrain such as
    /// texture names,
    /// terrain name etc.
    hashMapImpl<U64, stringImpl> variables;
    F32 grassDensity = 1.0f;
    F32 treeDensity = 1.0f;
    F32 grassScale = 1.0f;
    F32 treeScale = 1.0f;
    vec3<F32> position;
    vec2<F32> scale;
    bool active = false;
};

TYPEDEF_SMART_POINTERS_FOR_CLASS(Resource);

};  // namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/Core/Resources/Headers/Resource.h

Diff revisions: vs.
Revision Author Commited Message
1029 Diff Diff IonutCava picture IonutCava Tue 30 Jan, 2018 17:28:39 +0000

[Ionut]
- Update copyright notices

993 Diff Diff IonutCava picture IonutCava Sun 10 Dec, 2017 20:07:57 +0000

[Ionut]
- Finished initial port of the old scene graph system to the new ECS based system.
- Finished converting 2 components to the new ECS system: Transform and RigidBody
- Fixed the “Deploy” build error with the CEGUI OpenGL renderer.
- Compilation now needs C++14 support (it’s sufficiently wide-spread now)

976 Diff Diff IonutCava picture IonutCava Sun 19 Nov, 2017 23:10:18 +0000

[Ionut]
- Texture mipmaps are now compute before bind if they need a refresh (to avoid recalculation if they’re not used)
- More work on the editor: cleanup, load/save functionality, etc
- Input scaling: Mouse position is now relative to the scene preview position in editor mode. (the scene preview rect is used to re-map X/Y absolute and relative mouse positions)

872 Diff Diff IonutCava picture IonutCava Mon 06 Mar, 2017 23:23:20 +0000

[IonutCava]
- Optimise static casts

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

863 Diff Diff IonutCava picture IonutCava Wed 15 Feb, 2017 16:27:26 +0000

[IonutCava]
- Split Resource class into Resource and CachedResource
— CachedResource is the only resource held in a ResourceCache and loaded from a ResourceDescriptor
— CachedResource is mapped by its creation descriptor’s hash value, instead of the resource name
-— Multiple cached resources can now exist with the same name if the have different properties, for example.

860 Diff Diff IonutCava picture IonutCava Mon 13 Feb, 2017 21:07:59 +0000

[IonutCava]
- Fix shared_ptr leak in resource loading callbacks

858 Diff Diff IonutCava picture IonutCava Sun 12 Feb, 2017 20:55:05 +0000

[IonutCava]
- More resource loading updates

856 Diff Diff IonutCava picture IonutCava Fri 10 Feb, 2017 17:19:06 +0000

[IonutCava]
- Attempt to improve resource creation mechanism by adding a callback for when the resource finishes loading
— This is useful for multi-threaded loading: shaders, textures, terrain, etc

836 IonutCava picture IonutCava Fri 27 Jan, 2017 14:59:56 +0000

[IonutCava]
- Update copyright notice