Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "common/textconsole.h"
00024
00025 #include "engines/grim/debug.h"
00026 #include "engines/grim/model.h"
00027 #include "engines/grim/savegame.h"
00028 #include "engines/grim/costume/mesh_component.h"
00029 #include "engines/grim/costume/model_component.h"
00030
00031 namespace Grim {
00032
00033 MeshComponent::MeshComponent(Component *p, int parentID, const char *name, tag32 t) :
00034 Component(p, parentID, name, t), _node(nullptr) {
00035 if (sscanf(name, "mesh %d", &_num) < 1)
00036 error("Couldn't parse mesh name %s", name);
00037
00038 }
00039
00040 void MeshComponent::init() {
00041 if (_parent->isComponentType('M','M','D','L') ||
00042 _parent->isComponentType('M','O','D','L')) {
00043 ModelComponent *mc = static_cast<ModelComponent *>(_parent);
00044 _node = mc->getHierarchy() + _num;
00045 _model = mc->getModel();
00046 } else {
00047 Debug::warning(Debug::Costumes, "Parent of mesh %d was not a model", _num);
00048 _node = nullptr;
00049 _model = nullptr;
00050 }
00051 }
00052
00053 CMap *MeshComponent::cmap() {
00054 if (_parent->isComponentType('M','M','D','L') ||
00055 _parent->isComponentType('M','O','D','L')) {
00056 ModelComponent *mc = static_cast<ModelComponent *>(_parent);
00057 return mc->getCMap();
00058 }
00059 return nullptr;
00060 }
00061
00062 void MeshComponent::setKey(int val) {
00063 _node->_meshVisible = (val != 0);
00064 }
00065
00066 void MeshComponent::reset() {
00067
00068
00069
00070
00071
00072 }
00073
00074 int MeshComponent::update(uint ) {
00075 _node->setMatrix(_matrix);
00076 return 0;
00077 }
00078
00079 void MeshComponent::saveState(SaveGame *state) {
00080 state->writeBool(_node->_meshVisible);
00081 state->writeVector3d(_matrix.getPosition());
00082 }
00083
00084 void MeshComponent::restoreState(SaveGame *state) {
00085 _node->_meshVisible = state->readBool();
00086 if (state->saveMinorVersion() >= 14) {
00087 _matrix.setPosition(state->readVector3d());
00088 _node->setMatrix(_matrix);
00089 }
00090 }
00091
00092 }