OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
StdMeshUpdate.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 #ifndef INC_StdMeshUpdate
17 #define INC_StdMeshUpdate
18 
19 // This is a helper class to fix pointers after an update of StdMeshMaterials.
20 // To update one or more materials, remove them from the MaterialManager with
21 // erase(), then add new materials, then run Update() on all StdMeshes.
22 // Afterwards, run Update on all StdMeshInstances.
23 // If Cancel() is called before any Update() call then the Update() calls
24 // will reset all materials to what they have been before they were removed
25 // from the material manager.
27 {
28  friend class StdMeshMatManager; // calls Add() for each removed material
29 public:
31 
32  void Update(StdMesh* mesh) const;
33  void Update(StdMeshInstance* instance) const; // note this is NOT recursive
34 
35  void Cancel() const;
36 
37 private:
38  void Add(const StdMeshMaterial* material);
39 
40  StdMeshMatManager& MaterialManager;
41  std::map<const StdMeshMaterial*, StdMeshMaterial> Materials;
42 };
43 
44 // This is a helper class to update the underlying StdMesh of certain mesh
45 // instances. It updated the StdMeshInstance::Mesh pointer, and tries to
46 // preserve attached meshes, however might not be able to do so in which case
47 // attached meshes are removed.
49 {
50 public:
51  StdMeshUpdate(const StdMesh& old_mesh);
52 
53  // Not recursive for attached meshes
54  void Update(StdMeshInstance* instance, const StdMesh& new_mesh) const;
55 
56  const StdMesh& GetOldMesh() const { return *OldMesh; }
57 
58 private:
59  bool UpdateAnimationNode(StdMeshInstance* instance, StdMeshInstanceAnimationNode* node) const;
60 
61  const StdMesh* OldMesh;
62 
63  std::vector<StdCopyStrBuf> BoneNamesByIndex;
64 };
65 
66 // This is a helper class to update the animation state of all mesh instances
67 // after a definition reload. It tries to keep the animation state by
68 // animation name and removes animations if that is not possible.
70 {
71 public:
72  StdMeshAnimationUpdate(const StdMeshSkeletonLoader& skeleton_loader);
73 
74  // Note that this is not recursive for attached meshes, and that the
75  // pointer to the StdMesh object must already have been fixed with
76  // a call to StdMeshUpdate::Update().
77  void Update(StdMeshInstance* instance) const;
78 
79 private:
80  bool UpdateAnimationNode(StdMeshInstance* instance, StdMeshInstanceAnimationNode* node) const;
81 
82  std::map<const StdMeshAnimation*, StdCopyStrBuf> AnimationNames;
83 };
84 
85 #endif
void Update(StdMesh *mesh) const
StdMeshUpdate(const StdMesh &old_mesh)
StdMeshMaterialUpdate(StdMeshMatManager &manager)
void Update(StdMeshInstance *instance, const StdMesh &new_mesh) const
StdMeshAnimationUpdate(const StdMeshSkeletonLoader &skeleton_loader)
const StdMesh & GetOldMesh() const
Definition: StdMeshUpdate.h:56
void Update(StdMeshInstance *instance) const