From 109ec00f5f59d6502217a9c5e3b915f3a3e7022b Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 6 Jul 2014 06:04:09 +0000 Subject: [PATCH] Support more than 255 steps. --- common/camera.cpp | 106 ++++++------ common/camera.h | 22 +-- common/lc_application.cpp | 21 ++- common/lc_mainwindow.h | 2 +- common/lc_model.cpp | 10 ++ common/lc_model.h | 13 ++ common/light.cpp | 10 +- common/light.h | 4 +- common/object.cpp | 252 +++++++++++----------------- common/object.h | 16 +- common/piece.cpp | 107 ++++++++---- common/piece.h | 44 +++-- common/project.cpp | 345 +++++++++++++++++++------------------- common/project.h | 24 +-- qt/lc_qmainwindow.cpp | 24 +-- qt/lc_qmainwindow.h | 2 +- qt/lc_qpropertiestree.cpp | 8 +- qt/lc_qselectdialog.cpp | 3 +- qt/qtmain.cpp | 4 +- 19 files changed, 516 insertions(+), 501 deletions(-) diff --git a/common/camera.cpp b/common/camera.cpp index 7e10965c..7f07e529 100644 --- a/common/camera.cpp +++ b/common/camera.cpp @@ -269,7 +269,7 @@ void lcCamera::FileSave(lcFile& file) const Object::FileSave(file); - lcuint8 ch = (unsigned char)strlen(m_strName); + lcuint8 ch = (lcuint8)strlen(m_strName); file.WriteU8(ch); file.WriteBuffer(m_strName, ch); @@ -284,7 +284,7 @@ void lcCamera::FileSave(lcFile& file) const ///////////////////////////////////////////////////////////////////////////// // Camera operations -void lcCamera::Move(unsigned short nTime, bool AddKey, const lcVector3& Distance) +void lcCamera::Move(lcStep Step, bool AddKey, const lcVector3& Distance) { if (IsSimple()) AddKey = false; @@ -293,20 +293,20 @@ void lcCamera::Move(unsigned short nTime, bool AddKey, const lcVector3& Distance { mPosition += Distance; lcAlign(mOrthoTarget, mPosition, mTargetPosition); - ChangeKey(nTime, AddKey, mPosition, LC_CK_EYE); + ChangeKey(Step, AddKey, mPosition, LC_CK_EYE); } if (IsSelected(LC_CAMERA_SECTION_TARGET)) { mTargetPosition += Distance; - ChangeKey(nTime, AddKey, mTargetPosition, LC_CK_TARGET); + ChangeKey(Step, AddKey, mTargetPosition, LC_CK_TARGET); } if (IsSelected(LC_CAMERA_SECTION_UPVECTOR)) { mUpVector += Distance; mUpVector.Normalize(); - ChangeKey(nTime, AddKey, mTargetPosition, LC_CK_UP); + ChangeKey(Step, AddKey, mTargetPosition, LC_CK_UP); } lcVector3 FrontVector(mTargetPosition - mPosition); @@ -319,9 +319,9 @@ void lcCamera::Move(unsigned short nTime, bool AddKey, const lcVector3& Distance mUpVector.Normalize(); } -void lcCamera::UpdatePosition(unsigned short nTime) +void lcCamera::UpdatePosition(lcStep Step) { - CalculateKeys(nTime); + CalculateKeys(Step); lcVector3 FrontVector(mPosition - mTargetPosition); lcVector3 SideVector = lcCross(FrontVector, mUpVector); @@ -592,7 +592,7 @@ void lcCamera::BoxTest(lcObjectBoxTest& ObjectBoxTest) const } } -void lcCamera::ZoomExtents(View* view, const lcVector3& Center, const lcVector3* Points, int NumPoints, unsigned short nTime, bool bAddKey) +void lcCamera::ZoomExtents(View* view, const lcVector3& Center, const lcVector3* Points, int NumPoints, lcStep Step, bool AddKey) { int Viewport[4] = { 0, 0, view->mWidth, view->mHeight }; @@ -607,15 +607,15 @@ void lcCamera::ZoomExtents(View* view, const lcVector3& Center, const lcVector3* mOrthoTarget = mTargetPosition; if (IsSimple()) - bAddKey = false; + AddKey = false; - ChangeKey(nTime, bAddKey, mPosition, LC_CK_EYE); - ChangeKey(nTime, bAddKey, mTargetPosition, LC_CK_TARGET); + ChangeKey(Step, AddKey, mPosition, LC_CK_EYE); + ChangeKey(Step, AddKey, mTargetPosition, LC_CK_TARGET); - UpdatePosition(nTime); + UpdatePosition(Step); } -void lcCamera::ZoomRegion(const lcVector3* Points, float RatioX, float RatioY, unsigned short nTime, bool bAddKey) +void lcCamera::ZoomRegion(const lcVector3* Points, float RatioX, float RatioY, lcStep Step, bool AddKey) { // Center camera. lcVector3 Eye = mPosition; @@ -633,15 +633,15 @@ void lcCamera::ZoomRegion(const lcVector3* Points, float RatioX, float RatioY, u // Change the camera and redraw. if (IsSimple()) - bAddKey = false; + AddKey = false; - ChangeKey(nTime, bAddKey, mPosition, LC_CK_EYE); - ChangeKey(nTime, bAddKey, mTargetPosition, LC_CK_TARGET); + ChangeKey(Step, AddKey, mPosition, LC_CK_EYE); + ChangeKey(Step, AddKey, mTargetPosition, LC_CK_TARGET); - UpdatePosition(nTime); + UpdatePosition(Step); } -void lcCamera::Zoom(float Distance, unsigned short nTime, bool bAddKey) +void lcCamera::Zoom(float Distance, lcStep Step, bool AddKey) { lcVector3 FrontVector(mPosition - mTargetPosition); FrontVector.Normalize(); @@ -658,15 +658,15 @@ void lcCamera::Zoom(float Distance, unsigned short nTime, bool bAddKey) mTargetPosition += FrontVector; if (IsSimple()) - bAddKey = false; + AddKey = false; - ChangeKey(nTime, bAddKey, mPosition, LC_CK_EYE); - ChangeKey(nTime, bAddKey, mTargetPosition, LC_CK_TARGET); + ChangeKey(Step, AddKey, mPosition, LC_CK_EYE); + ChangeKey(Step, AddKey, mTargetPosition, LC_CK_TARGET); - UpdatePosition(nTime); + UpdatePosition(Step); } -void lcCamera::Pan(float DistanceX, float DistanceY, unsigned short nTime, bool bAddKey) +void lcCamera::Pan(float DistanceX, float DistanceY, lcStep Step, bool AddKey) { lcVector3 FrontVector(mPosition - mTargetPosition); lcVector3 SideVector = lcNormalize(lcCross(FrontVector, mUpVector)); @@ -677,15 +677,15 @@ void lcCamera::Pan(float DistanceX, float DistanceY, unsigned short nTime, bool mOrthoTarget += MoveVec; if (IsSimple()) - bAddKey = false; + AddKey = false; - ChangeKey(nTime, bAddKey, mPosition, LC_CK_EYE); - ChangeKey(nTime, bAddKey, mTargetPosition, LC_CK_TARGET); + ChangeKey(Step, AddKey, mPosition, LC_CK_EYE); + ChangeKey(Step, AddKey, mTargetPosition, LC_CK_TARGET); - UpdatePosition(nTime); + UpdatePosition(Step); } -void lcCamera::Orbit(float DistanceX, float DistanceY, const lcVector3& CenterPosition, unsigned short nTime, bool bAddKey) +void lcCamera::Orbit(float DistanceX, float DistanceY, const lcVector3& CenterPosition, lcStep Step, bool AddKey) { lcVector3 FrontVector(mPosition - mTargetPosition); @@ -709,16 +709,16 @@ void lcCamera::Orbit(float DistanceX, float DistanceY, const lcVector3& CenterPo mUpVector = lcMul31(mUpVector, transform); if (IsSimple()) - bAddKey = false; + AddKey = false; - ChangeKey(nTime, bAddKey, mPosition, LC_CK_EYE); - ChangeKey(nTime, bAddKey, mTargetPosition, LC_CK_TARGET); - ChangeKey(nTime, bAddKey, mUpVector, LC_CK_UP); + ChangeKey(Step, AddKey, mPosition, LC_CK_EYE); + ChangeKey(Step, AddKey, mTargetPosition, LC_CK_TARGET); + ChangeKey(Step, AddKey, mUpVector, LC_CK_UP); - UpdatePosition(nTime); + UpdatePosition(Step); } -void lcCamera::Roll(float Distance, unsigned short nTime, bool bAddKey) +void lcCamera::Roll(float Distance, lcStep Step, bool AddKey) { lcVector3 FrontVector(mPosition - mTargetPosition); lcMatrix44 Rotation = lcMatrix44FromAxisAngle(FrontVector, Distance); @@ -726,27 +726,27 @@ void lcCamera::Roll(float Distance, unsigned short nTime, bool bAddKey) mUpVector = lcMul30(mUpVector, Rotation); if (IsSimple()) - bAddKey = false; + AddKey = false; - ChangeKey(nTime, bAddKey, mUpVector, LC_CK_UP); + ChangeKey(Step, AddKey, mUpVector, LC_CK_UP); - UpdatePosition(nTime); + UpdatePosition(Step); } -void lcCamera::Center(lcVector3& point, unsigned short nTime, bool bAddKey) +void lcCamera::Center(lcVector3& point, lcStep Step, bool AddKey) { lcAlign(mTargetPosition, mPosition, point); if (IsSimple()) - bAddKey = false; + AddKey = false; - ChangeKey(nTime, bAddKey, mPosition, LC_CK_EYE); - ChangeKey(nTime, bAddKey, mTargetPosition, LC_CK_TARGET); + ChangeKey(Step, AddKey, mPosition, LC_CK_EYE); + ChangeKey(Step, AddKey, mTargetPosition, LC_CK_TARGET); - UpdatePosition(nTime); + UpdatePosition(Step); } -void lcCamera::SetViewpoint(LC_VIEWPOINT Viewpoint, unsigned short nTime, bool bAddKey) +void lcCamera::SetViewpoint(LC_VIEWPOINT Viewpoint, lcStep Step, bool AddKey) { lcVector3 Positions[] = { @@ -776,13 +776,13 @@ void lcCamera::SetViewpoint(LC_VIEWPOINT Viewpoint, unsigned short nTime, bool b mUpVector = Ups[Viewpoint]; if (IsSimple()) - bAddKey = false; + AddKey = false; - ChangeKey(nTime, bAddKey, mPosition, LC_CK_EYE); - ChangeKey(nTime, bAddKey, mTargetPosition, LC_CK_TARGET); - ChangeKey(nTime, bAddKey, mUpVector, LC_CK_UP); + ChangeKey(Step, AddKey, mPosition, LC_CK_EYE); + ChangeKey(Step, AddKey, mTargetPosition, LC_CK_TARGET); + ChangeKey(Step, AddKey, mUpVector, LC_CK_UP); - UpdatePosition(nTime); + UpdatePosition(Step); } void lcCamera::StartTiledRendering(int tw, int th, int iw, int ih, float AspectRatio) @@ -828,7 +828,7 @@ bool lcCamera::EndTile() return false; } -void lcCamera::SetFocalPoint(const lcVector3& focus, unsigned short nTime, bool bAddKey) +void lcCamera::SetFocalPoint(const lcVector3& focus, lcStep Step, bool AddKey) { if (IsOrtho()) { @@ -846,10 +846,10 @@ void lcCamera::SetFocalPoint(const lcVector3& focus, unsigned short nTime, bool } if (IsSimple()) - bAddKey = false; + AddKey = false; - ChangeKey(nTime, bAddKey, mPosition, LC_CK_EYE); - ChangeKey(nTime, bAddKey, mTargetPosition, LC_CK_TARGET); + ChangeKey(Step, AddKey, mPosition, LC_CK_EYE); + ChangeKey(Step, AddKey, mTargetPosition, LC_CK_TARGET); - UpdatePosition(nTime); + UpdatePosition(Step); } diff --git a/common/camera.h b/common/camera.h index 0c3fa4b4..55738576 100644 --- a/common/camera.h +++ b/common/camera.h @@ -252,20 +252,20 @@ public: void Select(bool bSelecting, bool bFocus, bool bMultiple); - void UpdatePosition(unsigned short nTime); + void UpdatePosition(lcStep Step); void CopyPosition(const Camera* camera); void Render(View* View); - void ZoomExtents(View* view, const lcVector3& Center, const lcVector3* Points, int NumPoints, unsigned short nTime, bool bAddKey); - void ZoomRegion(const lcVector3* Points, float RatioX, float RatioY, unsigned short nTime, bool bAddKey); - void Zoom(float Distance, unsigned short nTime, bool bAddKey); - void Pan(float DistanceX, float DistanceY, unsigned short nTime, bool bAddKey); - void Orbit(float DistanceX, float DistanceY, const lcVector3& CenterPosition, unsigned short nTime, bool bAddKey); - void Roll(float Distance, unsigned short nTime, bool bAddKey); - void Center(lcVector3& point, unsigned short nTime, bool bAddKey); - void Move(unsigned short nTime, bool AddKey, const lcVector3& Distance); - void SetViewpoint(LC_VIEWPOINT Viewpoint, unsigned short nTime, bool bAddKey); - void SetFocalPoint(const lcVector3& focus, unsigned short nTime, bool bAddKey); + void ZoomExtents(View* view, const lcVector3& Center, const lcVector3* Points, int NumPoints, lcStep Step, bool AddKey); + void ZoomRegion(const lcVector3* Points, float RatioX, float RatioY, lcStep Step, bool AddKey); + void Zoom(float Distance, lcStep Step, bool AddKey); + void Pan(float DistanceX, float DistanceY, lcStep Step, bool AddKey); + void Orbit(float DistanceX, float DistanceY, const lcVector3& CenterPosition, lcStep Step, bool AddKey); + void Roll(float Distance, lcStep Step, bool AddKey); + void Center(lcVector3& point, lcStep Step, bool AddKey); + void Move(lcStep Step, bool AddKey, const lcVector3& Distance); + void SetViewpoint(LC_VIEWPOINT Viewpoint, lcStep Step, bool AddKey); + void SetFocalPoint(const lcVector3& focus, lcStep Step, bool AddKey); void StartTiledRendering(int tw, int th, int iw, int ih, float fAspect); void GetTileInfo(int* row, int* col, int* width, int* height); diff --git a/common/lc_application.cpp b/common/lc_application.cpp index 4bba8265..60f97523 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -132,6 +132,7 @@ void lcApplication::ParseIntegerArgument(int* CurArg, int argc, char* argv[], in } else { + *Value = 0; printf("Not enough parameters for the %s argument.", argv[(*CurArg) - 1]); } } @@ -158,8 +159,8 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal bool ImageHighlight = false; int ImageWidth = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH); int ImageHeight = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT); - int ImageStart = 0; - int ImageEnd = 0; + lcStep ImageStart = 0; + lcStep ImageEnd = 0; char* ImageName = NULL; // File to open. @@ -196,11 +197,15 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal } else if ((strcmp(Param, "-f") == 0) || (strcmp(Param, "--from") == 0)) { - ParseIntegerArgument(&i, argc, argv, &ImageStart); + int Step; + ParseIntegerArgument(&i, argc, argv, &Step); + ImageStart = Step; } else if ((strcmp(Param, "-t") == 0) || (strcmp(Param, "--to") == 0)) { - ParseIntegerArgument(&i, argc, argv, &ImageEnd); + int Step; + ParseIntegerArgument(&i, argc, argv, &Step); + ImageEnd = Step; } else if (strcmp(Param, "--highlight") == 0) ImageHighlight = true; @@ -323,7 +328,7 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal if ((ImageStart == 0) && (ImageEnd == 0)) { - ImageStart = ImageEnd = mProject->GetCurrentTime(); + ImageStart = ImageEnd = mProject->GetCurrentStep(); } else if ((ImageStart == 0) && (ImageEnd != 0)) { @@ -343,14 +348,14 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal Image* images = new Image[ImageEnd - ImageStart + 1]; mProject->CreateImages(images, ImageWidth, ImageHeight, ImageStart, ImageEnd, ImageHighlight); - for (int i = 0; i <= ImageEnd - ImageStart; i++) + for (lcStep Step = 0; Step <= ImageEnd - ImageStart; Step++) { char idx[256]; String Frame; if (ImageStart != ImageEnd) { - sprintf(idx, "%02d", i+1); + sprintf(idx, "%02d", Step + 1); int Ext = FileName.ReverseFind('.'); Frame = FileName.Left(Ext) + idx + FileName.Right(FileName.GetLength() - Ext); @@ -358,7 +363,7 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal else Frame = FileName; - images[i].FileSave(Frame, ImageFormat, ImageTransparent); + images[Step].FileSave(Frame, ImageFormat, ImageTransparent); } delete []images; diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index 1c512e8d..d0d9ee90 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -60,7 +60,7 @@ class lcMainWindow : public lcBaseWindow void UpdateSelectedObjects(int Flags, int SelectedCount, Object* Focus); void UpdateAction(int NewAction); void UpdatePaste(bool Enabled); - void UpdateTime(int CurrentTime, int TotalTime); + void UpdateCurrentStep(); void SetAddKeys(bool AddKeys); void UpdateLockSnap(lcuint32 Snap); void UpdateSnap(); diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 5b9c7ac3..96375975 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -46,3 +46,13 @@ lcModel::lcModel() lcModel::~lcModel() { } + +lcStep lcModel::GetLastStep() const +{ + lcStep Step = 1; + + for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) + Step = lcMax(Step, mPieces[PieceIdx]->GetStepShow()); + + return Step; +} diff --git a/common/lc_model.h b/common/lc_model.h index 083d7007..759d6093 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -85,6 +85,11 @@ public: lcModel(); ~lcModel(); + bool IsModified() const + { + return mSavedHistory != mUndoHistory[0]; + } + const lcArray& GetPieces() const { return mPieces; @@ -105,9 +110,17 @@ public: return mGroups; } + lcStep GetLastStep() const; + lcStep GetCurrentStep() const + { + return mCurrentStep; + } + protected: lcModelProperties mProperties; + lcStep mCurrentStep; + lcArray mPieces; lcArray mCameras; lcArray mLights; diff --git a/common/light.cpp b/common/light.cpp index 3411124a..6b0974db 100644 --- a/common/light.cpp +++ b/common/light.cpp @@ -214,26 +214,26 @@ void lcLight::BoxTest(lcObjectBoxTest& ObjectBoxTest) const } } -void lcLight::Move(unsigned short nTime, bool AddKey, const lcVector3& Distance) +void lcLight::Move(lcStep Step, bool AddKey, const lcVector3& Distance) { if (IsSelected(LC_LIGHT_SECTION_POSITION)) { mPosition += Distance; - ChangeKey(nTime, AddKey, mPosition, LC_LK_POSITION); + ChangeKey(Step, AddKey, mPosition, LC_LK_POSITION); } if (IsSelected(LC_LIGHT_SECTION_TARGET)) { mTargetPosition += Distance; - ChangeKey(nTime, AddKey, mTargetPosition, LC_LK_TARGET); + ChangeKey(Step, AddKey, mTargetPosition, LC_LK_TARGET); } } -void lcLight::UpdatePosition(unsigned short nTime) +void lcLight::UpdatePosition(lcStep Step) { - CalculateKeys(nTime); + CalculateKeys(Step); if (IsPointLight()) { diff --git a/common/light.h b/common/light.h index 8b5db0b4..b97fd32c 100644 --- a/common/light.h +++ b/common/light.h @@ -203,8 +203,8 @@ public: void RenderTarget(); void RenderSphere(); - void UpdatePosition(unsigned short nTime); - void Move(unsigned short nTime, bool AddKey, const lcVector3& Distance); + void UpdatePosition(lcStep Step); + void Move(lcStep Step, bool AddKey, const lcVector3& Distance); bool Setup(int LightIndex); void CreateName(const lcArray& Lights); bool FileLoad(lcFile& file); diff --git a/common/object.cpp b/common/object.cpp index e0209301..fd735162 100644 --- a/common/object.cpp +++ b/common/object.cpp @@ -59,29 +59,30 @@ bool lcObject::FileLoad(lcFile& file) void lcObject::FileSave(lcFile& file) const { - LC_OBJECT_KEY *node; - lcuint32 n; + LC_OBJECT_KEY *node; + lcuint32 n; - file.WriteU8(LC_KEY_SAVE_VERSION); + file.WriteU8(LC_KEY_SAVE_VERSION); - for (n = 0, node = m_pInstructionKeys; node; node = node->next) - n++; - file.WriteU32(n); + for (n = 0, node = m_pInstructionKeys; node; node = node->next) + n++; + file.WriteU32(n); - for (node = m_pInstructionKeys; node; node = node->next) - { - file.WriteU16(node->time); - file.WriteFloats(node->param, 4); - file.WriteU8(node->type); - } + for (node = m_pInstructionKeys; node; node = node->next) + { + lcuint16 Step = lcMin(node->Step, 0xFFFFU); + file.WriteU16(Step); + file.WriteFloats(node->param, 4); + file.WriteU8(node->type); + } - file.WriteU32(0); + file.WriteU32(0); } // ============================================================================= // Key handling -static LC_OBJECT_KEY* AddNode(LC_OBJECT_KEY *node, unsigned short nTime, unsigned char nType) +static LC_OBJECT_KEY* AddNode(LC_OBJECT_KEY *node, lcStep Step, unsigned char nType) { LC_OBJECT_KEY* newnode = (LC_OBJECT_KEY*)malloc(sizeof(LC_OBJECT_KEY)); @@ -94,7 +95,7 @@ static LC_OBJECT_KEY* AddNode(LC_OBJECT_KEY *node, unsigned short nTime, unsigne newnode->next = NULL; newnode->type = nType; - newnode->time = nTime; + newnode->Step = Step; newnode->param[0] = newnode->param[1] = newnode->param[2] = newnode->param[3] = 0; return newnode; @@ -130,163 +131,112 @@ void lcObject::RemoveKeys() } } -void lcObject::ChangeKey(unsigned short nTime, bool bAddKey, const float *param, unsigned char nKeyType) +void lcObject::ChangeKey(lcStep Step, bool AddKey, const float *param, unsigned char nKeyType) { - LC_OBJECT_KEY *node, *poskey = NULL, *newpos = NULL; - node = m_pInstructionKeys; - - while (node) - { - if ((node->time <= nTime) && - (node->type == nKeyType)) - poskey = node; - - node = node->next; - } - - if (bAddKey) - { - if (poskey) - { - if (poskey->time != nTime) - newpos = AddNode(poskey, nTime, nKeyType); - } - else - newpos = AddNode(poskey, nTime, nKeyType); - } - - if (newpos == NULL) - newpos = poskey; - - for (int i = 0; i < m_pKeyInfo[nKeyType].size; i++) - newpos->param[i] = param[i]; -} - -void lcObject::CalculateKeys(unsigned short nTime) -{ -// LC_OBJECT_KEY *next[m_nKeyInfoCount], *prev[m_nKeyInfoCount], *node; - LC_OBJECT_KEY *next[32], *prev[32], *node; - int i, empty = m_nKeyInfoCount; - - for (i = 0; i < m_nKeyInfoCount; i++) - next[i] = NULL; - - node = m_pInstructionKeys; - - // Get the previous and next keys for each variable - while (node && empty) - { - if (node->time <= nTime) - { - prev[node->type] = node; - } - else - { - if (next[node->type] == NULL) - { - next[node->type] = node; - empty--; - } - } - - node = node->next; - } - - // TODO: USE KEY IN/OUT WEIGHTS - for (i = 0; i < m_nKeyInfoCount; i++) - { - LC_OBJECT_KEY *p = prev[i]; - - for (int j = 0; j < m_pKeyInfo[i].size; j++) - m_pKeyValues[i][j] = p->param[j]; - } -} - -void lcObject::CalculateSingleKey(unsigned short nTime, int keytype, float *value) const -{ - LC_OBJECT_KEY *prev = NULL, *node; - + LC_OBJECT_KEY *node, *poskey = NULL, *newpos = NULL; node = m_pInstructionKeys; while (node) { - if (node->type == keytype) - { - if (node->time <= nTime) - prev = node; - else - break; - } + if ((node->Step <= Step) && (node->type == nKeyType)) + poskey = node; node = node->next; } - for (int j = 0; j < m_pKeyInfo[keytype].size; j++) - value[j] = prev->param[j]; + if (AddKey) + { + if (poskey) + { + if (poskey->Step != Step) + newpos = AddNode(poskey, Step, nKeyType); + } + else + newpos = AddNode(poskey, Step, nKeyType); + } + + if (newpos == NULL) + newpos = poskey; + + for (int i = 0; i < m_pKeyInfo[nKeyType].size; i++) + newpos->param[i] = param[i]; } -void lcObject::InsertTime(unsigned short start, unsigned short time) +void lcObject::CalculateKeys(lcStep Step) { - LC_OBJECT_KEY *node, *prev = NULL; - unsigned short last; - bool end[32]; - int i; + LC_OBJECT_KEY* prev[32]; - for (i = 0; i < m_nKeyInfoCount; i++) - end[i] = false; + for (LC_OBJECT_KEY* node = m_pInstructionKeys; node; node = node->next) + if (node->Step <= Step) + prev[node->type] = node; - node = m_pInstructionKeys; - last = 255; + for (int i = 0; i < m_nKeyInfoCount; i++) + { + LC_OBJECT_KEY *p = prev[i]; - for (; node != NULL; prev = node, node = node->next) - { - // skip everything before the start time - if ((node->time < start) || (node->time == 1)) - continue; - - // there's already a key at the end, delete this one - if (end[node->type]) - { - prev->next = node->next; - free(node); - node = prev; - - continue; - } - - node->time += time; - if (node->time >= last) - { - node->time = last; - end[node->type] = true; - } - } + for (int j = 0; j < m_pKeyInfo[i].size; j++) + m_pKeyValues[i][j] = p->param[j]; + } } -void lcObject::RemoveTime(unsigned short start, unsigned short time) +void lcObject::InsertTime(lcStep Start, lcStep Time) { - LC_OBJECT_KEY *node, *prev = NULL; + LC_OBJECT_KEY *node, *prev = NULL; + bool end[32]; - node = m_pInstructionKeys; + for (int i = 0; i < m_nKeyInfoCount; i++) + end[i] = false; - for (; node != NULL; prev = node, node = node->next) - { - // skip everything before the start time - if ((node->time < start) || (node->time == 1)) - continue; + node = m_pInstructionKeys; - if (node->time < (start + time)) - { - // delete this key - prev->next = node->next; - free(node); - node = prev; + for (; node != NULL; prev = node, node = node->next) + { + // skip everything before the start time + if ((node->Step < Start) || (node->Step == 1)) + continue; - continue; - } + // there's already a key at the end, delete this one + if (end[node->type]) + { + prev->next = node->next; + free(node); + node = prev; - node->time -= time; - if (node->time < 1) - node->time = 1; - } + continue; + } + + if (node->Step >= LC_STEP_MAX - Time) + { + node->Step = LC_STEP_MAX; + end[node->type] = true; + } + else + node->Step += Time; + } +} + +void lcObject::RemoveTime(lcStep Start, lcStep Time) +{ + LC_OBJECT_KEY *node = m_pInstructionKeys, *prev = NULL; + + for (; node != NULL; prev = node, node = node->next) + { + // skip everything before the start time + if ((node->Step < Start) || (node->Step == 1)) + continue; + + if (node->Step < Start + Time) + { + // delete this key + prev->next = node->next; + free(node); + node = prev; + + continue; + } + + node->Step -= Time; + if (node->Step < 1) + node->Step = 1; + } } diff --git a/common/object.h b/common/object.h index 23eb671c..cc5922f2 100644 --- a/common/object.h +++ b/common/object.h @@ -4,6 +4,9 @@ #include "lc_math.h" #include "lc_array.h" +typedef lcuint32 lcStep; +#define LC_STEP_MAX 0xffffffff + enum lcObjectType { LC_OBJECT_PIECE, @@ -14,7 +17,7 @@ enum lcObjectType // key handling struct LC_OBJECT_KEY { - unsigned short time; + lcStep Step; float param[4]; unsigned char type; LC_OBJECT_KEY* next; @@ -87,7 +90,7 @@ public: virtual lcuint32 GetFocusSection() const = 0; virtual lcVector3 GetSectionPosition(lcuint32 Section) const = 0; - virtual void Move(unsigned short nTime, bool AddKey, const lcVector3& Distance) = 0; + virtual void Move(lcStep Step, bool AddKey, const lcVector3& Distance) = 0; virtual void RayTest(lcObjectRayTest& ObjectRayTest) const = 0; virtual void BoxTest(lcObjectBoxTest& ObjectBoxTest) const = 0; virtual const char* GetName() const = 0; @@ -97,10 +100,9 @@ protected: virtual void FileSave(lcFile& file) const; public: - void CalculateSingleKey(unsigned short nTime, int keytype, float *value) const; - void ChangeKey(unsigned short time, bool addkey, const float *param, unsigned char keytype); - virtual void InsertTime(unsigned short start, unsigned short time); - virtual void RemoveTime(unsigned short start, unsigned short time); + void ChangeKey(lcStep Step, bool AddKey, const float *param, unsigned char keytype); + virtual void InsertTime(lcStep Start, lcStep Time); + virtual void RemoveTime(lcStep Start, lcStep Time); int GetKeyTypeCount() const { @@ -119,7 +121,7 @@ public: protected: void RegisterKeys(float *values[], LC_OBJECT_KEY_INFO* info, int count); - void CalculateKeys(unsigned short nTime); + void CalculateKeys(lcStep Step); private: void RemoveKeys(); diff --git a/common/piece.cpp b/common/piece.cpp index 2a756ba0..34242204 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -34,8 +34,8 @@ lcPiece::lcPiece(PieceInfo* pPieceInfo) mState = 0; mColorIndex = 0; mColorCode = 0; - m_nStepShow = 1; - m_nStepHide = 255; + mStepShow = 1; + mStepHide = LC_STEP_MAX; memset(m_strName, 0, sizeof(m_strName)); mGroup = NULL; @@ -193,11 +193,16 @@ bool lcPiece::FileLoad(lcFile& file) file.ReadU32(&mColorCode, 1); mColorIndex = lcGetColorIndex(mColorCode); - file.ReadU8(&m_nStepShow, 1); + lcuint8 Step; + file.ReadU8(&Step, 1); + mStepShow = Step; if (version > 1) - file.ReadU8(&m_nStepHide, 1); + { + file.ReadU8(&Step, 1); + mStepHide = Step == 255 ? LC_STEP_MAX : Step; + } else - m_nStepHide = 255; + mStepHide = LC_STEP_MAX; if (version > 5) { @@ -252,8 +257,8 @@ void lcPiece::FileSave(lcFile& file) const file.WriteBuffer(mPieceInfo->m_strName, LC_PIECE_NAME_LEN); file.WriteU32(mColorCode); - file.WriteU8(m_nStepShow); - file.WriteU8(m_nStepHide); + file.WriteU8(lcMin(mStepShow, 254U)); + file.WriteU8(lcMin(mStepHide, 255U)); file.WriteU16(1); // m_nFrameShow file.WriteU16(100); // m_nFrameHide @@ -269,9 +274,9 @@ void lcPiece::FileSave(lcFile& file) const file.WriteS32(GroupIndex); } -void lcPiece::Initialize(float x, float y, float z, unsigned char nStep) +void lcPiece::Initialize(float x, float y, float z, lcStep Step) { - m_nStepShow = nStep; + mStepShow = Step; float pos[3] = { x, y, z }, rot[4] = { 0, 0, 1, 0 }; ChangeKey(1, true, pos, LC_PK_POSITION); @@ -298,26 +303,68 @@ void lcPiece::CreateName(const lcArray& Pieces) m_strName[sizeof(m_strName) - 1] = 0; } -void lcPiece::InsertTime(unsigned short start, unsigned short time) +void lcPiece::InsertTime(lcStep Start, lcStep Time) { - if (m_nStepShow >= start) - m_nStepShow = lcMin(m_nStepShow + time, 255); + if (mStepShow >= Start) + { + if (mStepShow < LC_STEP_MAX - Time) + mStepShow += Time; + else + mStepShow = LC_STEP_MAX; + } - if (m_nStepHide >= start) - m_nStepHide = lcMin(m_nStepHide + time, 255); + if (mStepHide >= Start) + { + if (mStepHide < LC_STEP_MAX - Time) + mStepHide += Time; + else + mStepHide = LC_STEP_MAX; + } - Object::InsertTime(start, time); + if (mStepShow >= mStepHide) + { + if (mStepShow != LC_STEP_MAX) + mStepHide = mStepShow + 1; + else + { + mStepShow = LC_STEP_MAX - 1; + mStepHide = LC_STEP_MAX; + } + } + + Object::InsertTime(Start, Time); } -void lcPiece::RemoveTime (unsigned short start, unsigned short time) +void lcPiece::RemoveTime(lcStep Start, lcStep Time) { - if (m_nStepShow >= start) - m_nStepShow = lcMax(m_nStepShow - time, 1); + if (mStepShow >= Start) + { + if (mStepShow > Time) + mStepShow -= Time; + else + mStepShow = 1; + } - if (m_nStepHide != 255) - m_nStepHide = lcMax(m_nStepHide - time, 1); + if (mStepHide != LC_STEP_MAX) + { + if (mStepHide > Time) + mStepHide -= Time; + else + mStepHide = 1; + } - Object::RemoveTime(start, time); + if (mStepShow >= mStepHide) + { + if (mStepShow != LC_STEP_MAX) + mStepHide = mStepShow + 1; + else + { + mStepShow = LC_STEP_MAX - 1; + mStepHide = LC_STEP_MAX; + } + } + + Object::RemoveTime(Start, Time); } void lcPiece::RayTest(lcObjectRayTest& ObjectRayTest) const @@ -402,27 +449,21 @@ void lcPiece::BoxTest(lcObjectBoxTest& ObjectBoxTest) const } } -void lcPiece::Move(unsigned short nTime, bool AddKey, const lcVector3& Distance) +void lcPiece::Move(lcStep Step, bool AddKey, const lcVector3& Distance) { mPosition += Distance; - ChangeKey(nTime, AddKey, mPosition, LC_PK_POSITION); + ChangeKey(Step, AddKey, mPosition, LC_PK_POSITION); mModelWorld.SetTranslation(mPosition); } -bool lcPiece::IsVisible(unsigned short nTime) +bool lcPiece::IsVisible(lcStep Step) { if (mState & LC_PIECE_HIDDEN) return false; - if (m_nStepShow > nTime) - return false; - - if ((m_nStepHide == 255) || (m_nStepHide > nTime)) - return true; - - return false; + return (mStepShow <= Step) && (mStepHide > Step); } void lcPiece::CompareBoundingBox(float box[6]) @@ -457,9 +498,9 @@ lcGroup* lcPiece::GetTopGroup() return mGroup ? mGroup->GetTopGroup() : NULL; } -void lcPiece::UpdatePosition(unsigned short nTime) +void lcPiece::UpdatePosition(lcStep Step) { - CalculateKeys(nTime); + CalculateKeys(Step); mModelWorld = lcMatrix44FromAxisAngle(lcVector3(mRotation[0], mRotation[1], mRotation[2]), mRotation[3] * LC_DTOR); mModelWorld.SetTranslation(mPosition); diff --git a/common/piece.h b/common/piece.h index 7701d255..7db22136 100644 --- a/common/piece.h +++ b/common/piece.h @@ -98,8 +98,8 @@ public: virtual void RayTest(lcObjectRayTest& ObjectRayTest) const; virtual void BoxTest(lcObjectBoxTest& ObjectBoxTest) const; - virtual void InsertTime(unsigned short start, unsigned short time); - virtual void RemoveTime(unsigned short start, unsigned short time); + virtual void InsertTime(lcStep Start, lcStep Time); + virtual void RemoveTime(lcStep Start, lcStep Time); bool IsHidden() { @@ -119,16 +119,16 @@ public: return m_strName; } - bool IsVisible(unsigned short nTime); - void Initialize(float x, float y, float z, unsigned char nStep); + bool IsVisible(lcStep Step); + void Initialize(float x, float y, float z, lcStep Step); void CreateName(const lcArray& Pieces); void CompareBoundingBox(float box[6]); void SetPieceInfo(PieceInfo* pPieceInfo); bool FileLoad(lcFile& file); void FileSave(lcFile& file) const; - void UpdatePosition(unsigned short nTime); - void Move(unsigned short nTime, bool AddKey, const lcVector3& Distance); + void UpdatePosition(lcStep Step); + void Move(lcStep Step, bool AddKey, const lcVector3& Distance); lcGroup* GetTopGroup(); @@ -146,14 +146,26 @@ public: { strcpy(m_strName, name); } const char* GetName() { return m_strName; } - void SetStepShow(unsigned char step) - { m_nStepShow = step; } - unsigned char GetStepShow() - { return m_nStepShow; } - void SetStepHide(unsigned char step) - { m_nStepHide = step; } - unsigned char GetStepHide() - { return (unsigned char)m_nStepHide; } + + lcStep GetStepShow() const + { + return mStepShow; + } + + lcStep GetStepHide() const + { + return mStepHide; + } + + void SetStepHide(lcStep Step) + { + mStepHide = Step; + } + + void SetStepShow(lcStep Step) + { + mStepShow = Step; + } void SetColorCode(lcuint32 ColorCode) { @@ -181,8 +193,8 @@ protected: // Atributes Group* mGroup; - lcuint8 m_nStepShow; - lcuint8 m_nStepHide; + lcStep mStepShow; + lcStep mStepHide; lcuint8 mState; char m_strName[81]; diff --git a/common/project.cpp b/common/project.cpp index ab68d701..94f77c54 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -67,7 +67,7 @@ void Project::UpdateInterface() gMainWindow->UpdatePerspective(); UpdateSelection(); - gMainWindow->UpdateTime(m_nCurStep, 255); + gMainWindow->UpdateCurrentStep(); const lcArray Views = gMainWindow->GetViews(); for (int i = 0; i < Views.GetSize(); i++) @@ -135,8 +135,8 @@ void Project::LoadDefaults(bool cameras) gMainWindow->UpdateLockSnap(m_nSnap); m_nMoveSnap = 0x0304; gMainWindow->UpdateSnap(); - m_nCurStep = 1; - gMainWindow->UpdateTime(1, 255); + mCurrentStep = 1; + gMainWindow->UpdateCurrentStep(); strcpy(m_strHeader, ""); strcpy(m_strFooter, "Page &P"); m_pTerrain->LoadDefaults(true); @@ -239,7 +239,7 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge) file->ReadS32(&i, 1); //m_nCurGroup = i; file->ReadS32(&i, 1); //m_nCurColor = i; file->ReadS32(&i, 1); //action = i; - file->ReadS32(&i, 1); m_nCurStep = i; + file->ReadS32(&i, 1); mCurrentStep = i; } if (fv > 0.8f) @@ -605,7 +605,7 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge) gMainWindow->UpdateSnap(); gMainWindow->UpdateCameraMenu(); UpdateSelection(); - gMainWindow->UpdateTime(m_nCurStep, 255); + gMainWindow->UpdateCurrentStep(); gMainWindow->UpdateAllViews(); return true; @@ -637,7 +637,7 @@ void Project::FileSave(lcFile* file, bool bUndo) i = 0;//i = m_nCurColor; file->WriteS32(&i, 1); i = 0; file->WriteS32(&i, 1); // m_nCurAction - i = m_nCurStep; file->WriteS32(&i, 1); + i = mCurrentStep; file->WriteS32(&i, 1); file->WriteU32(0);//m_nScene file->WriteS32(mPieces.GetSize()); @@ -733,8 +733,7 @@ void Project::FileSave(lcFile* file, bool bUndo) opts.transparent = false; opts.format = LC_IMAGE_GIF; - i = m_bAnimation ? m_nCurFrame : m_nCurStep; - CreateImages(image, 120, 100, i, i, false); + CreateImages(image, 120, 100, mCurrentStep, mCurrentStep, false); image[0].FileSave (*file, &opts); delete []image; } @@ -1021,7 +1020,6 @@ bool Project::DoSave(const char* FileName) if ((strcmp(ext, "dat") == 0) || (strcmp(ext, "ldr") == 0)) { - int i, steps = GetLastStep(); char buf[256]; ptr = strrchr(m_strPathName, '\\'); @@ -1032,8 +1030,7 @@ bool Project::DoSave(const char* FileName) else ptr++; - sprintf(buf, "0 Model exported from LeoCAD\r\n" - "0 Original name: %s\r\n", ptr); + sprintf(buf, "0 Model exported from LeoCAD\r\n0 Original name: %s\r\n", ptr); if (!mProperties.mAuthor.IsEmpty()) { strcat(buf, "0 Author: "); @@ -1045,13 +1042,14 @@ bool Project::DoSave(const char* FileName) const char* OldLocale = setlocale(LC_NUMERIC, "C"); - for (i = 1; i <= steps; i++) + lcStep LastStep = GetLastStep(); + for (lcStep Step = 1; Step <= LastStep; Step++) { for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) { Piece* Piece = mPieces[PieceIdx]; - if ((Piece->IsVisible(i)) && (Piece->GetStepShow() == i)) + if ((Piece->IsVisible(Step)) && (Piece->GetStepShow() == Step)) { const float* f = Piece->mModelWorld; sprintf (buf, "1 %d %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %s.DAT\r\n", @@ -1060,7 +1058,7 @@ bool Project::DoSave(const char* FileName) } } - if (i != steps) + if (Step != LastStep) file.WriteBuffer("0 STEP\r\n", 8); } file.WriteBuffer("0\r\n", 3); @@ -1220,8 +1218,8 @@ bool Project::OnOpenDocument(const char* lpszPathName) else FileReadLDraw(&file, mat, &ok, 16, &step, FileArray); - m_nCurStep = step; - gMainWindow->UpdateTime(m_nCurStep, 255); + mCurrentStep = step; + gMainWindow->UpdateCurrentStep(); gMainWindow->UpdateFocusObject(GetFocusObject()); UpdateSelection(); CalculateStep(); @@ -1460,7 +1458,7 @@ void Project::RenderScenePieces(View* view, bool DrawInterface) { Piece* Piece = mPieces[PieceIdx]; - if (!Piece->IsVisible(m_nCurStep)) + if (!Piece->IsVisible(mCurrentStep)) continue; PieceInfo* Info = Piece->mPieceInfo; @@ -1506,7 +1504,7 @@ void Project::RenderScenePieces(View* view, bool DrawInterface) { Piece* Piece = mPieces[PieceIdx]; - if (!Piece->IsVisible(m_nCurStep) || !Piece->IsSelected()) + if (!Piece->IsVisible(mCurrentStep) || !Piece->IsSelected()) continue; PieceInfo* PieceInfo = Piece->mPieceInfo; @@ -1626,7 +1624,7 @@ void Project::RenderSceneObjects(View* view) { Piece* Piece = mPieces[PieceIdx]; - if (Piece->IsVisible(m_nCurStep)) + if (Piece->IsVisible(mCurrentStep)) Piece->CompareBoundingBox(bs); } @@ -1989,11 +1987,11 @@ void Project::CalculateStep() for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) { Piece* Piece = mPieces[PieceIdx]; - Piece->UpdatePosition(m_nCurStep); + Piece->UpdatePosition(mCurrentStep); if (Piece->IsSelected()) { - if (!Piece->IsVisible(m_nCurStep)) + if (!Piece->IsVisible(mCurrentStep)) Piece->SetSelected(false); else SelectGroup(Piece->GetTopGroup(), true); @@ -2001,10 +1999,10 @@ void Project::CalculateStep() } for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++) - mCameras[CameraIdx]->UpdatePosition(m_nCurStep); + mCameras[CameraIdx]->UpdatePosition(mCurrentStep); for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++) - mLights[LightIdx]->UpdatePosition(m_nCurStep); + mLights[LightIdx]->UpdatePosition(mCurrentStep); } bool Project::RemoveSelectedObjects() @@ -2199,15 +2197,6 @@ void Project::CheckAutoSave() */ } -unsigned char Project::GetLastStep() -{ - unsigned char last = 1; - for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) - last = lcMax(last, mPieces[PieceIdx]->GetStepShow()); - - return last; -} - void Project::FindPiece(bool FindFirst, bool SearchForward) { if (mPieces.IsEmpty()) @@ -2220,7 +2209,7 @@ void Project::FindPiece(bool FindFirst, bool SearchForward) { Piece* Piece = mPieces[PieceIdx]; - if (Piece->IsFocused() && Piece->IsVisible(m_nCurStep)) + if (Piece->IsFocused() && Piece->IsVisible(mCurrentStep)) { StartIdx = PieceIdx; break; @@ -2248,7 +2237,7 @@ void Project::FindPiece(bool FindFirst, bool SearchForward) Piece* Current = mPieces[CurrentIdx]; - if (!Current->IsVisible(m_nCurStep)) + if (!Current->IsVisible(mCurrentStep)) continue; if ((!mSearchOptions.MatchInfo || Current->mPieceInfo == mSearchOptions.Info) && @@ -2274,7 +2263,7 @@ void Project::ZoomExtents(int FirstView, int LastView) { Piece* Piece = mPieces[PieceIdx]; - if (Piece->IsVisible(m_nCurStep)) + if (Piece->IsVisible(mCurrentStep)) Piece->CompareBoundingBox(bs); } @@ -2297,7 +2286,7 @@ void Project::ZoomExtents(int FirstView, int LastView) { View* view = Views[vp]; - view->mCamera->ZoomExtents(view, Center, Points, 8, m_nCurStep, gMainWindow->GetAddKeys()); + view->mCamera->ZoomExtents(view, Center, Points, 8, mCurrentStep, gMainWindow->GetAddKeys()); } gMainWindow->UpdateFocusObject(GetFocusObject()); @@ -2336,7 +2325,7 @@ void Project::GetPiecesUsed(lcArray& PiecesUsed) const } // Create a series of pictures -void Project::CreateImages(Image* images, int width, int height, unsigned short from, unsigned short to, bool hilite) +void Project::CreateImages(Image* images, int width, int height, lcStep from, lcStep to, bool hilite) { if (!GL_BeginRenderToTexture(width, height)) { @@ -2344,9 +2333,8 @@ void Project::CreateImages(Image* images, int width, int height, unsigned short return; } - unsigned short oldtime; - unsigned char* buf = (unsigned char*)malloc (width*height*3); - oldtime = m_nCurStep; + lcStep CurrentStep = mCurrentStep; + unsigned char* buf = (unsigned char*)malloc(width*height*3); View view(this); view.SetCamera(gMainWindow->GetActiveView()->mCamera, false); @@ -2359,9 +2347,9 @@ void Project::CreateImages(Image* images, int width, int height, unsigned short RenderInitialize(); - for (int i = from; i <= to; i++) + for (lcStep i = from; i <= to; i++) { - m_nCurStep = i; + mCurrentStep = i; if (hilite) { @@ -2380,14 +2368,13 @@ void Project::CreateImages(Image* images, int width, int height, unsigned short if (hilite) SelectAndFocusNone(false); - m_nCurStep = (unsigned char)oldtime; - CalculateStep(); - free (buf); + SetCurrentStep(CurrentStep); + free(buf); GL_EndRenderToTexture(); } -void Project::CreateHTMLPieceList(FILE* f, int nStep, bool bImages, const char* ext) +void Project::CreateHTMLPieceList(FILE* f, lcStep Step, bool bImages, const char* ext) { int* ColorsUsed = new int[gColorList.GetSize()]; memset(ColorsUsed, 0, sizeof(ColorsUsed[0]) * gColorList.GetSize()); @@ -2398,7 +2385,7 @@ void Project::CreateHTMLPieceList(FILE* f, int nStep, bool bImages, const char* { Piece* Piece = mPieces[PieceIdx]; - if ((Piece->GetStepShow() == nStep) || (nStep == 0)) + if ((Piece->GetStepShow() == Step) || (Step == 0)) ColorsUsed[Piece->mColorIndex]++; } @@ -2427,7 +2414,7 @@ void Project::CreateHTMLPieceList(FILE* f, int nStep, bool bImages, const char* { Piece* Piece = mPieces[PieceIdx]; - if ((Piece->mPieceInfo == pInfo) && ((Piece->GetStepShow() == nStep) || (nStep == 0))) + if ((Piece->mPieceInfo == pInfo) && ((Piece->GetStepShow() == Step) || (Step == 0))) { PiecesUsed[Piece->mColorIndex]++; Add = true; @@ -3306,8 +3293,8 @@ void Project::HandleCommand(LC_COMMANDS id) } } - Options.Start = m_nCurStep; - Options.End = m_nCurStep; + Options.Start = mCurrentStep; + Options.End = mCurrentStep; if (!gMainWindow->DoDialog(LC_DIALOG_SAVE_IMAGE, &Options)) break; @@ -3461,8 +3448,7 @@ void Project::HandleCommand(LC_COMMANDS id) FILE* f; const char *ext, *htmlext; char fn[LC_MAXPATH]; - int i; - unsigned short last = GetLastStep(); + lcStep LastStep = GetLastStep(); switch (Options.ImageFormat) { @@ -3492,13 +3478,13 @@ void Project::HandleCommand(LC_COMMANDS id) fprintf (f, "\n\nInstructions for %s\n\n
\n
\n", m_strTitle); - for (i = 1; i <= last; i++) + for (lcStep Step = 1; Step <= LastStep; Step++) { fprintf(f, "\"Step

\n", - m_strTitle, i, ext, i, Options.StepImagesWidth, Options.StepImagesHeight); + m_strTitle, Step, ext, Step, Options.StepImagesWidth, Options.StepImagesHeight); if (Options.PartsListStep) - CreateHTMLPieceList(f, i, Options.PartsListImages, ext); + CreateHTMLPieceList(f, Step, Options.PartsListImages, ext); } if (Options.PartsListEnd) @@ -3525,8 +3511,8 @@ void Project::HandleCommand(LC_COMMANDS id) fprintf(f, "\n\nInstructions for %s\n\n
\n
\n", m_strTitle); - for (i = 1; i <= last; i++) - fprintf(f, "Step %d
\n
", m_strTitle, i, htmlext, i); + for (lcStep Step = 1; Step <= LastStep; Step++) + fprintf(f, "Step %d
\n
", m_strTitle, Step, htmlext, Step); if (Options.PartsListEnd) fprintf(f, "Pieces Used
\n", m_strTitle, htmlext); @@ -3536,9 +3522,9 @@ void Project::HandleCommand(LC_COMMANDS id) } // Create each step - for (i = 1; i <= last; i++) + for (lcStep Step = 1; Step <= LastStep; Step++) { - sprintf(fn, "%s%s-%02d%s", Options.PathName, m_strTitle, i, htmlext); + sprintf(fn, "%s%s-%02d%s", Options.PathName, m_strTitle, Step, htmlext); f = fopen(fn, "wt"); if (!f) @@ -3547,22 +3533,22 @@ void Project::HandleCommand(LC_COMMANDS id) break; } - fprintf(f, "\n\n%s - Step %02d\n\n
\n
\n", m_strTitle, i); + fprintf(f, "\n\n%s - Step %02d\n\n
\n
\n", m_strTitle, Step); fprintf(f, "\"Step

\n", - m_strTitle, i, ext, i, Options.StepImagesWidth, Options.StepImagesHeight); + m_strTitle, Step, ext, Step, Options.StepImagesWidth, Options.StepImagesHeight); if (Options.PartsListStep) - CreateHTMLPieceList(f, i, Options.PartsListImages, ext); + CreateHTMLPieceList(f, Step, Options.PartsListImages, ext); fputs("
\n


", f); - if (i != 1) - fprintf(f, "Previous ", m_strTitle, i-1, htmlext); + if (Step != 1) + fprintf(f, "Previous ", m_strTitle, Step - 1, htmlext); if (Options.IndexPage) fprintf(f, "Index ", m_strTitle, htmlext); - if (i != last) - fprintf(f, "Next", m_strTitle, i+1, htmlext); + if (Step != LastStep) + fprintf(f, "Next", m_strTitle, Step + 1, htmlext); else if (Options.PartsListEnd) fprintf(f, "Pieces Used", m_strTitle, htmlext); @@ -3589,7 +3575,7 @@ void Project::HandleCommand(LC_COMMANDS id) CreateHTMLPieceList(f, 0, Options.PartsListImages, ext); fputs("
\n


", f); - fprintf(f, "Previous ", m_strTitle, i-1, htmlext); + fprintf(f, "Previous ", m_strTitle, LastStep, htmlext); if (Options.IndexPage) fprintf(f, "Index ", m_strTitle, htmlext); @@ -3600,13 +3586,13 @@ void Project::HandleCommand(LC_COMMANDS id) } // Save step pictures - Image* images = new Image[last]; - CreateImages(images, Options.StepImagesWidth, Options.StepImagesHeight, 1, last, Options.HighlightNewParts); + Image* images = new Image[LastStep]; + CreateImages(images, Options.StepImagesWidth, Options.StepImagesHeight, 1, LastStep, Options.HighlightNewParts); - for (i = 0; i < last; i++) + for (lcStep Step = 0; Step < LastStep; Step++) { - sprintf(fn, "%s%s-%02d%s", Options.PathName, m_strTitle, i+1, ext); - images[i].FileSave(fn, Options.ImageFormat, Options.TransparentImages); + sprintf(fn, "%s%s-%02d%s", Options.PathName, m_strTitle, Step + 1, ext); + images[Step].FileSave(fn, Options.ImageFormat, Options.TransparentImages); } delete []images; @@ -4131,7 +4117,7 @@ void Project::HandleCommand(LC_COMMANDS id) { lcPiece* Piece = PastedPieces[PieceIdx]; Piece->CreateName(mPieces); - Piece->SetStepShow(m_nCurStep); + Piece->SetStepShow(mCurrentStep); mPieces.Add(Piece); Piece->SetSelected(true); @@ -4231,7 +4217,7 @@ void Project::HandleCommand(LC_COMMANDS id) { Piece* Piece = mPieces[PieceIdx]; - if (Piece->IsVisible(m_nCurStep)) + if (Piece->IsVisible(mCurrentStep)) Piece->SetSelected(true); } @@ -4253,7 +4239,7 @@ void Project::HandleCommand(LC_COMMANDS id) { Piece* Piece = mPieces[PieceIdx]; - if (Piece->IsVisible(m_nCurStep)) + if (Piece->IsVisible(mCurrentStep)) Piece->SetSelected(!Piece->IsSelected()); } @@ -4370,7 +4356,7 @@ void Project::HandleCommand(LC_COMMANDS id) { lcVector3 FocusVector; GetSelectionCenter(FocusVector); - gMainWindow->GetActiveView()->mCamera->SetFocalPoint(FocusVector, m_nCurStep, gMainWindow->GetAddKeys()); + gMainWindow->GetActiveView()->mCamera->SetFocalPoint(FocusVector, mCurrentStep, gMainWindow->GetAddKeys()); gMainWindow->UpdateAllViews(); } break; @@ -4400,13 +4386,13 @@ void Project::HandleCommand(LC_COMMANDS id) GetPieceInsertPosition(Last, Pos, Rot); - pPiece->Initialize(Pos[0], Pos[1], Pos[2], m_nCurStep); + pPiece->Initialize(Pos[0], Pos[1], Pos[2], mCurrentStep); - pPiece->ChangeKey(m_nCurStep, false, Rot, LC_PK_ROTATION); - pPiece->UpdatePosition(m_nCurStep); + pPiece->ChangeKey(mCurrentStep, false, Rot, LC_PK_ROTATION); + pPiece->UpdatePosition(mCurrentStep); } else - pPiece->Initialize(0, 0, 0, m_nCurStep); + pPiece->Initialize(0, 0, 0, mCurrentStep); pPiece->SetColorIndex(gMainWindow->mColorIndex); pPiece->CreateName(mPieces); @@ -4558,14 +4544,14 @@ void Project::HandleCommand(LC_COMMANDS id) lcVector4& Position = Minifig.Matrices[i][3]; lcVector4 Rotation = lcMatrix44ToAxisAngle(Minifig.Matrices[i]); Rotation[3] *= LC_RTOD; - pPiece->Initialize(Position[0], Position[1], Position[2], m_nCurStep); + pPiece->Initialize(Position[0], Position[1], Position[2], mCurrentStep); pPiece->SetColorIndex(Minifig.Colors[i]); pPiece->CreateName(mPieces); mPieces.Add(pPiece); pPiece->SetSelected(true); pPiece->ChangeKey(1, false, Rotation, LC_PK_ROTATION); - pPiece->UpdatePosition(m_nCurStep); + pPiece->UpdatePosition(mCurrentStep); SystemPieceComboAdd(Minifig.Parts[i]->m_strDescription); } @@ -4693,7 +4679,7 @@ void Project::HandleCommand(LC_COMMANDS id) Piece* NewPiece = new Piece(pPiece->mPieceInfo); NewPieces.Add(NewPiece); - NewPiece->Initialize(Position[0] + Offset[0], Position[1] + Offset[1], Position[2] + Offset[2], m_nCurStep); + NewPiece->Initialize(Position[0] + Offset[0], Position[1] + Offset[1], Position[2] + Offset[2], mCurrentStep); NewPiece->SetColorIndex(pPiece->mColorIndex); NewPiece->ChangeKey(1, false, AxisAngle, LC_PK_ROTATION); } @@ -4705,7 +4691,7 @@ void Project::HandleCommand(LC_COMMANDS id) { Piece* Piece = NewPieces[PieceIdx]; Piece->CreateName(mPieces); - Piece->UpdatePosition(m_nCurStep); + Piece->UpdatePosition(mCurrentStep); mPieces.Add(Piece); } @@ -4940,7 +4926,7 @@ void Project::HandleCommand(LC_COMMANDS id) case LC_PIECE_SHOW_EARLIER: { - bool redraw = false; + bool Redraw = false; for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) { @@ -4948,25 +4934,27 @@ void Project::HandleCommand(LC_COMMANDS id) if (Piece->IsSelected()) { - unsigned char t = Piece->GetStepShow(); - if (t > 1) + lcStep Step = Piece->GetStepShow(); + + if (Step > 1) { - redraw = true; - Piece->SetStepShow(t-1); + Redraw = true; + Piece->SetStepShow(Step - 1); } } } - if (redraw) + if (Redraw) { CheckPoint("Modifying"); gMainWindow->UpdateAllViews(); + UpdateSelection(); } } break; case LC_PIECE_SHOW_LATER: { - bool redraw = false; + bool Redraw = false; for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) { @@ -4974,23 +4962,25 @@ void Project::HandleCommand(LC_COMMANDS id) if (Piece->IsSelected()) { - unsigned char t = Piece->GetStepShow(); - if (t < 255) - { - redraw = true; - Piece->SetStepShow(t+1); + lcStep Step = Piece->GetStepShow(); - if (t == m_nCurStep) + if (Step < LC_STEP_MAX) + { + Step++; + Redraw = true; + Piece->SetStepShow(Step); + + if (Step > mCurrentStep) Piece->SetSelected(false); } } } - if (redraw) + if (Redraw) { CheckPoint("Modifying"); gMainWindow->UpdateAllViews(); - UpdateSelection (); + UpdateSelection(); } } break; @@ -5049,57 +5039,58 @@ void Project::HandleCommand(LC_COMMANDS id) Center = lcVector3((bs[0] + bs[3]) * 0.5f, (bs[1] + bs[4]) * 0.5f, (bs[2] + bs[5]) * 0.5f); } - gMainWindow->GetActiveView()->mCamera->Center(Center, m_nCurStep, gMainWindow->GetAddKeys()); + gMainWindow->GetActiveView()->mCamera->Center(Center, mCurrentStep, gMainWindow->GetAddKeys()); gMainWindow->UpdateAllViews(); break; } case LC_VIEW_TIME_NEXT: { - m_nCurStep++; + if (mCurrentStep == LC_STEP_MAX) + break; + + mCurrentStep++; CalculateStep(); UpdateSelection(); gMainWindow->UpdateFocusObject(GetFocusObject()); gMainWindow->UpdateAllViews(); - - gMainWindow->UpdateTime(m_nCurStep, 255); + gMainWindow->UpdateCurrentStep(); } break; case LC_VIEW_TIME_PREVIOUS: { - m_nCurStep--; + if (mCurrentStep == 1) + break; + mCurrentStep--; CalculateStep(); UpdateSelection(); gMainWindow->UpdateFocusObject(GetFocusObject()); gMainWindow->UpdateAllViews(); - - gMainWindow->UpdateTime(m_nCurStep, 255); + gMainWindow->UpdateCurrentStep(); } break; case LC_VIEW_TIME_FIRST: { - m_nCurStep = 1; + mCurrentStep = 1; CalculateStep(); UpdateSelection(); gMainWindow->UpdateFocusObject(GetFocusObject()); gMainWindow->UpdateAllViews(); - - gMainWindow->UpdateTime(m_nCurStep, 255); + gMainWindow->UpdateCurrentStep(); } break; case LC_VIEW_TIME_LAST: { - m_nCurStep = GetLastStep (); + mCurrentStep = GetLastStep(); CalculateStep(); UpdateSelection(); gMainWindow->UpdateFocusObject(GetFocusObject()); gMainWindow->UpdateAllViews(); - - gMainWindow->UpdateTime(m_nCurStep, 255); + gMainWindow->UpdateCurrentStep(); } break; case LC_VIEW_TIME_INSERT: @@ -5107,16 +5098,16 @@ void Project::HandleCommand(LC_COMMANDS id) for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) { Piece* Piece = mPieces[PieceIdx]; - Piece->InsertTime(m_nCurStep, 1); - if (Piece->IsSelected() && !Piece->IsVisible(m_nCurStep)) + Piece->InsertTime(mCurrentStep, 1); + if (Piece->IsSelected() && !Piece->IsVisible(mCurrentStep)) Piece->SetSelected(false); } for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++) - mCameras[CameraIdx]->InsertTime(m_nCurStep, 1); + mCameras[CameraIdx]->InsertTime(mCurrentStep, 1); for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++) - mLights[LightIdx]->InsertTime(m_nCurStep, 1); + mLights[LightIdx]->InsertTime(mCurrentStep, 1); CheckPoint("Adding Step"); CalculateStep(); @@ -5130,16 +5121,16 @@ void Project::HandleCommand(LC_COMMANDS id) for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) { Piece* Piece = mPieces[PieceIdx]; - Piece->RemoveTime(m_nCurStep, 1); - if (Piece->IsSelected() && !Piece->IsVisible(m_nCurStep)) + Piece->RemoveTime(mCurrentStep, 1); + if (Piece->IsSelected() && !Piece->IsVisible(mCurrentStep)) Piece->SetSelected(false); } for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++) - mCameras[CameraIdx]->RemoveTime(m_nCurStep, 1); + mCameras[CameraIdx]->RemoveTime(mCurrentStep, 1); for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++) - mLights[LightIdx]->RemoveTime(m_nCurStep, 1); + mLights[LightIdx]->RemoveTime(mCurrentStep, 1); CheckPoint("Removing Step"); CalculateStep(); @@ -5150,49 +5141,49 @@ void Project::HandleCommand(LC_COMMANDS id) case LC_VIEW_VIEWPOINT_FRONT: { - gMainWindow->GetActiveView()->mCamera->SetViewpoint(LC_VIEWPOINT_FRONT, m_nCurStep, gMainWindow->GetAddKeys()); + gMainWindow->GetActiveView()->mCamera->SetViewpoint(LC_VIEWPOINT_FRONT, mCurrentStep, gMainWindow->GetAddKeys()); HandleCommand(LC_VIEW_ZOOM_EXTENTS); gMainWindow->UpdateAllViews(); } break; case LC_VIEW_VIEWPOINT_BACK: { - gMainWindow->GetActiveView()->mCamera->SetViewpoint(LC_VIEWPOINT_BACK, m_nCurStep, gMainWindow->GetAddKeys()); + gMainWindow->GetActiveView()->mCamera->SetViewpoint(LC_VIEWPOINT_BACK, mCurrentStep, gMainWindow->GetAddKeys()); HandleCommand(LC_VIEW_ZOOM_EXTENTS); gMainWindow->UpdateAllViews(); } break; case LC_VIEW_VIEWPOINT_TOP: { - gMainWindow->GetActiveView()->mCamera->SetViewpoint(LC_VIEWPOINT_TOP, m_nCurStep, gMainWindow->GetAddKeys()); + gMainWindow->GetActiveView()->mCamera->SetViewpoint(LC_VIEWPOINT_TOP, mCurrentStep, gMainWindow->GetAddKeys()); HandleCommand(LC_VIEW_ZOOM_EXTENTS); gMainWindow->UpdateAllViews(); } break; case LC_VIEW_VIEWPOINT_BOTTOM: { - gMainWindow->GetActiveView()->mCamera->SetViewpoint(LC_VIEWPOINT_BOTTOM, m_nCurStep, gMainWindow->GetAddKeys()); + gMainWindow->GetActiveView()->mCamera->SetViewpoint(LC_VIEWPOINT_BOTTOM, mCurrentStep, gMainWindow->GetAddKeys()); HandleCommand(LC_VIEW_ZOOM_EXTENTS); gMainWindow->UpdateAllViews(); } break; case LC_VIEW_VIEWPOINT_LEFT: { - gMainWindow->GetActiveView()->mCamera->SetViewpoint(LC_VIEWPOINT_LEFT, m_nCurStep, gMainWindow->GetAddKeys()); + gMainWindow->GetActiveView()->mCamera->SetViewpoint(LC_VIEWPOINT_LEFT, mCurrentStep, gMainWindow->GetAddKeys()); HandleCommand(LC_VIEW_ZOOM_EXTENTS); gMainWindow->UpdateAllViews(); } break; case LC_VIEW_VIEWPOINT_RIGHT: { - gMainWindow->GetActiveView()->mCamera->SetViewpoint(LC_VIEWPOINT_RIGHT, m_nCurStep, gMainWindow->GetAddKeys()); + gMainWindow->GetActiveView()->mCamera->SetViewpoint(LC_VIEWPOINT_RIGHT, mCurrentStep, gMainWindow->GetAddKeys()); HandleCommand(LC_VIEW_ZOOM_EXTENTS); gMainWindow->UpdateAllViews(); } break; case LC_VIEW_VIEWPOINT_HOME: { - gMainWindow->GetActiveView()->mCamera->SetViewpoint(LC_VIEWPOINT_HOME, m_nCurStep, gMainWindow->GetAddKeys()); + gMainWindow->GetActiveView()->mCamera->SetViewpoint(LC_VIEWPOINT_HOME, mCurrentStep, gMainWindow->GetAddKeys()); HandleCommand(LC_VIEW_ZOOM_EXTENTS); gMainWindow->UpdateAllViews(); } break; @@ -5684,7 +5675,7 @@ void Project::SelectGroup(Group* TopGroup, bool Select) { Piece* Piece = mPieces[PieceIdx]; - if (!Piece->IsSelected() && Piece->IsVisible(m_nCurStep) && (Piece->GetTopGroup() == TopGroup)) + if (!Piece->IsSelected() && Piece->IsVisible(mCurrentStep) && (Piece->GetTopGroup() == TopGroup)) Piece->SetSelected(Select); } } @@ -5921,7 +5912,7 @@ void Project::RayTest(lcObjectRayTest& ObjectRayTest) const { Piece* Piece = mPieces[PieceIdx]; - if (Piece->IsVisible(m_nCurStep)) + if (Piece->IsVisible(mCurrentStep)) Piece->RayTest(ObjectRayTest); } @@ -5947,7 +5938,7 @@ void Project::BoxTest(lcObjectBoxTest& ObjectBoxTest) const { Piece* Piece = mPieces[PieceIdx]; - if (Piece->IsVisible(m_nCurStep)) + if (Piece->IsVisible(mCurrentStep)) Piece->BoxTest(ObjectBoxTest); } @@ -6154,8 +6145,8 @@ bool Project::MoveSelectedObjects(lcVector3& Move, lcVector3& Remainder, bool Sn if (Piece->IsSelected()) { - Piece->Move(m_nCurStep, gMainWindow->GetAddKeys(), TransformedMove); - Piece->UpdatePosition(m_nCurStep); + Piece->Move(mCurrentStep, gMainWindow->GetAddKeys(), TransformedMove); + Piece->UpdatePosition(mCurrentStep); } } @@ -6165,8 +6156,8 @@ bool Project::MoveSelectedObjects(lcVector3& Move, lcVector3& Remainder, bool Sn if (Camera->IsSelected()) { - Camera->Move(m_nCurStep, gMainWindow->GetAddKeys(), TransformedMove); - Camera->UpdatePosition(m_nCurStep); + Camera->Move(mCurrentStep, gMainWindow->GetAddKeys(), TransformedMove); + Camera->UpdatePosition(mCurrentStep); } } @@ -6176,8 +6167,8 @@ bool Project::MoveSelectedObjects(lcVector3& Move, lcVector3& Remainder, bool Sn if (Light->IsSelected()) { - Light->Move(m_nCurStep, gMainWindow->GetAddKeys(), TransformedMove); - Light->UpdatePosition(m_nCurStep); + Light->Move(mCurrentStep, gMainWindow->GetAddKeys(), TransformedMove); + Light->UpdatePosition(mCurrentStep); } } @@ -6335,7 +6326,7 @@ bool Project::RotateSelectedObjects(lcVector3& Delta, lcVector3& Remainder, bool pos[1] = Center[1] + Distance[1]; pos[2] = Center[2] + Distance[2]; - Piece->ChangeKey(m_nCurStep, gMainWindow->GetAddKeys(), pos, LC_PK_POSITION); + Piece->ChangeKey(mCurrentStep, gMainWindow->GetAddKeys(), pos, LC_PK_POSITION); } rot[0] = NewRotation[0]; @@ -6343,8 +6334,8 @@ bool Project::RotateSelectedObjects(lcVector3& Delta, lcVector3& Remainder, bool rot[2] = NewRotation[2]; rot[3] = NewRotation[3] * LC_RTOD; - Piece->ChangeKey(m_nCurStep, gMainWindow->GetAddKeys(), rot, LC_PK_ROTATION); - Piece->UpdatePosition(m_nCurStep); + Piece->ChangeKey(mCurrentStep, gMainWindow->GetAddKeys(), rot, LC_PK_ROTATION); + Piece->UpdatePosition(mCurrentStep); } return true; @@ -6388,8 +6379,8 @@ void Project::TransformSelectedObjects(LC_TRANSFORM_TYPE Type, const lcVector3& if (pCamera->IsSelected()) { - pCamera->Move(m_nCurStep, gMainWindow->GetAddKeys(), Offset); - pCamera->UpdatePosition(m_nCurStep); + pCamera->Move(mCurrentStep, gMainWindow->GetAddKeys(), Offset); + pCamera->UpdatePosition(mCurrentStep); } } @@ -6399,8 +6390,8 @@ void Project::TransformSelectedObjects(LC_TRANSFORM_TYPE Type, const lcVector3& if (pLight->IsSelected()) { - pLight->Move(m_nCurStep, gMainWindow->GetAddKeys(), Offset); - pLight->UpdatePosition (m_nCurStep); + pLight->Move(mCurrentStep, gMainWindow->GetAddKeys(), Offset); + pLight->UpdatePosition (mCurrentStep); } } @@ -6410,8 +6401,8 @@ void Project::TransformSelectedObjects(LC_TRANSFORM_TYPE Type, const lcVector3& if (Piece->IsSelected()) { - Piece->Move(m_nCurStep, gMainWindow->GetAddKeys(), Offset); - Piece->UpdatePosition(m_nCurStep); + Piece->Move(mCurrentStep, gMainWindow->GetAddKeys(), Offset); + Piece->UpdatePosition(mCurrentStep); } } @@ -6469,8 +6460,8 @@ void Project::TransformSelectedObjects(LC_TRANSFORM_TYPE Type, const lcVector3& if (Piece->IsSelected()) { - Piece->ChangeKey(m_nCurStep, gMainWindow->GetAddKeys(), NewRotation, LC_PK_ROTATION); - Piece->UpdatePosition(m_nCurStep); + Piece->ChangeKey(mCurrentStep, gMainWindow->GetAddKeys(), NewRotation, LC_PK_ROTATION); + Piece->UpdatePosition(mCurrentStep); nSel++; } } @@ -6510,8 +6501,8 @@ void Project::ModifyObject(Object* Object, lcObjectProperty Property, void* Valu if (Part->mPosition != Position) { - Part->ChangeKey(m_nCurStep, gMainWindow->GetAddKeys(), Position, LC_PK_POSITION); - Part->UpdatePosition(m_nCurStep); + Part->ChangeKey(mCurrentStep, gMainWindow->GetAddKeys(), Position, LC_PK_POSITION); + Part->UpdatePosition(mCurrentStep); CheckPointString = "Moving"; } @@ -6524,8 +6515,8 @@ void Project::ModifyObject(Object* Object, lcObjectProperty Property, void* Valu if (Rotation != Part->mRotation) { - Part->ChangeKey(m_nCurStep, gMainWindow->GetAddKeys(), Rotation, LC_PK_ROTATION); - Part->UpdatePosition(m_nCurStep); + Part->ChangeKey(mCurrentStep, gMainWindow->GetAddKeys(), Rotation, LC_PK_ROTATION); + Part->UpdatePosition(mCurrentStep); CheckPointString = "Rotating"; } @@ -6533,13 +6524,13 @@ void Project::ModifyObject(Object* Object, lcObjectProperty Property, void* Valu case LC_PIECE_PROPERTY_SHOW: { - lcuint32 Show = *(lcuint32*)Value; + lcStep Step = *(lcStep*)Value; Piece* Part = (Piece*)Object; - if (Show != Part->GetStepShow()) + if (Step != Part->GetStepShow()) { - Part->SetStepShow(Show); - if (Part->IsSelected() && !Part->IsVisible(m_nCurStep)) + Part->SetStepShow(Step); + if (Part->IsSelected() && !Part->IsVisible(mCurrentStep)) Part->SetSelected(false); CheckPointString = "Show"; @@ -6548,12 +6539,12 @@ void Project::ModifyObject(Object* Object, lcObjectProperty Property, void* Valu case LC_PIECE_PROPERTY_HIDE: { - lcuint32 Hide = *(lcuint32*)Value; + lcStep Step = *(lcuint32*)Value; Piece* Part = (Piece*)Object; - if (Hide != Part->GetStepHide()) + if (Step != Part->GetStepHide()) { - Part->SetStepHide(Hide); + Part->SetStepHide(Step); CheckPointString = "Hide"; } @@ -6594,8 +6585,8 @@ void Project::ModifyObject(Object* Object, lcObjectProperty Property, void* Valu if (camera->mPosition != Position) { - camera->ChangeKey(m_nCurStep, gMainWindow->GetAddKeys(), Position, LC_CK_EYE); - camera->UpdatePosition(m_nCurStep); + camera->ChangeKey(mCurrentStep, gMainWindow->GetAddKeys(), Position, LC_CK_EYE); + camera->UpdatePosition(mCurrentStep); CheckPointString = "Camera"; } @@ -6608,8 +6599,8 @@ void Project::ModifyObject(Object* Object, lcObjectProperty Property, void* Valu if (camera->mTargetPosition != TargetPosition) { - camera->ChangeKey(m_nCurStep, gMainWindow->GetAddKeys(), TargetPosition, LC_CK_TARGET); - camera->UpdatePosition(m_nCurStep); + camera->ChangeKey(mCurrentStep, gMainWindow->GetAddKeys(), TargetPosition, LC_CK_TARGET); + camera->UpdatePosition(mCurrentStep); CheckPointString = "Camera"; } @@ -6622,8 +6613,8 @@ void Project::ModifyObject(Object* Object, lcObjectProperty Property, void* Valu if (camera->mUpVector != Up) { - camera->ChangeKey(m_nCurStep, gMainWindow->GetAddKeys(), Up, LC_CK_UP); - camera->UpdatePosition(m_nCurStep); + camera->ChangeKey(mCurrentStep, gMainWindow->GetAddKeys(), Up, LC_CK_UP); + camera->UpdatePosition(mCurrentStep); CheckPointString = "Camera"; } @@ -6637,7 +6628,7 @@ void Project::ModifyObject(Object* Object, lcObjectProperty Property, void* Valu if (camera->IsOrtho() != Ortho) { camera->SetOrtho(Ortho); - camera->UpdatePosition(m_nCurStep); + camera->UpdatePosition(mCurrentStep); CheckPointString = "Camera"; } @@ -6651,7 +6642,7 @@ void Project::ModifyObject(Object* Object, lcObjectProperty Property, void* Valu if (camera->m_fovy != FOV) { camera->m_fovy = FOV; - camera->UpdatePosition(m_nCurStep); + camera->UpdatePosition(mCurrentStep); CheckPointString = "Camera"; } @@ -6665,7 +6656,7 @@ void Project::ModifyObject(Object* Object, lcObjectProperty Property, void* Valu if (camera->m_zNear != Near) { camera->m_zNear= Near; - camera->UpdatePosition(m_nCurStep); + camera->UpdatePosition(mCurrentStep); CheckPointString = "Camera"; } @@ -6679,7 +6670,7 @@ void Project::ModifyObject(Object* Object, lcObjectProperty Property, void* Valu if (camera->m_zFar != Far) { camera->m_zFar = Far; - camera->UpdatePosition(m_nCurStep); + camera->UpdatePosition(mCurrentStep); CheckPointString = "Camera"; } @@ -6714,7 +6705,7 @@ void Project::ZoomActiveView(int Amount) { float ScaledAmount = 2.0f * Amount / (21 - lcGetProfileInt(LC_PROFILE_MOUSE_SENSITIVITY)); - gMainWindow->GetActiveView()->mCamera->Zoom(ScaledAmount, m_nCurStep, gMainWindow->GetAddKeys()); + gMainWindow->GetActiveView()->mCamera->Zoom(ScaledAmount, mCurrentStep, gMainWindow->GetAddKeys()); gMainWindow->UpdateFocusObject(GetFocusObject()); gMainWindow->UpdateAllViews(); } @@ -6791,10 +6782,10 @@ void Project::EndMouseTool(lcTool Tool, bool Accept) void Project::InsertPieceToolClicked(const lcVector3& Position, const lcVector4& Rotation) { lcPiece* Piece = new lcPiece(m_pCurPiece); - Piece->Initialize(Position[0], Position[1], Position[2], m_nCurStep); + Piece->Initialize(Position[0], Position[1], Position[2], mCurrentStep); Piece->SetColorIndex(gMainWindow->mColorIndex); - Piece->ChangeKey(m_nCurStep, false, Rotation, LC_PK_ROTATION); - Piece->UpdatePosition(m_nCurStep); + Piece->ChangeKey(mCurrentStep, false, Rotation, LC_PK_ROTATION); + Piece->UpdatePosition(mCurrentStep); Piece->CreateName(mPieces); mPieces.Add(Piece); @@ -6936,14 +6927,14 @@ void Project::PaintToolClicked(lcObject* Object) void Project::UpdateZoomTool(lcCamera* Camera, float Mouse) { - Camera->Zoom(Mouse - mMouseToolDistance.x, m_nCurStep, gMainWindow->GetAddKeys()); + Camera->Zoom(Mouse - mMouseToolDistance.x, mCurrentStep, gMainWindow->GetAddKeys()); mMouseToolDistance.x = Mouse; gMainWindow->UpdateAllViews(); } void Project::UpdatePanTool(lcCamera* Camera, float MouseX, float MouseY) { - Camera->Pan(MouseX - mMouseToolDistance.x, MouseY - mMouseToolDistance.y, m_nCurStep, gMainWindow->GetAddKeys()); + Camera->Pan(MouseX - mMouseToolDistance.x, MouseY - mMouseToolDistance.y, mCurrentStep, gMainWindow->GetAddKeys()); mMouseToolDistance.x = MouseX; mMouseToolDistance.y = MouseY; gMainWindow->UpdateAllViews(); @@ -6953,7 +6944,7 @@ void Project::UpdateOrbitTool(lcCamera* Camera, float MouseX, float MouseY) { lcVector3 Center; GetSelectionCenter(Center); - Camera->Orbit(MouseX - mMouseToolDistance.x, MouseY - mMouseToolDistance.y, Center, m_nCurStep, gMainWindow->GetAddKeys()); + Camera->Orbit(MouseX - mMouseToolDistance.x, MouseY - mMouseToolDistance.y, Center, mCurrentStep, gMainWindow->GetAddKeys()); mMouseToolDistance.x = MouseX; mMouseToolDistance.y = MouseY; gMainWindow->UpdateAllViews(); @@ -6961,14 +6952,14 @@ void Project::UpdateOrbitTool(lcCamera* Camera, float MouseX, float MouseY) void Project::UpdateRollTool(lcCamera* Camera, float Mouse) { - Camera->Roll(Mouse - mMouseToolDistance.x, m_nCurStep, gMainWindow->GetAddKeys()); + Camera->Roll(Mouse - mMouseToolDistance.x, mCurrentStep, gMainWindow->GetAddKeys()); mMouseToolDistance.x = Mouse; gMainWindow->UpdateAllViews(); } void Project::ZoomRegionToolClicked(lcCamera* Camera, const lcVector3* Points, float RatioX, float RatioY) { - Camera->ZoomRegion(Points, m_nCurStep, gMainWindow->GetAddKeys(), RatioX, RatioY); + Camera->ZoomRegion(Points, mCurrentStep, gMainWindow->GetAddKeys(), RatioX, RatioY); gMainWindow->UpdateFocusObject(GetFocusObject()); gMainWindow->UpdateAllViews(); diff --git a/common/project.h b/common/project.h index 38a7fdcc..e830102b 100644 --- a/common/project.h +++ b/common/project.h @@ -160,19 +160,12 @@ protected: lcVector3 mMouseToolDistance; public: - bool IsModified() const + void SetCurrentStep(lcStep Step) { - return mSavedHistory != mUndoHistory[0]; - } - - unsigned char GetLastStep(); - unsigned short GetCurrentTime () - { return m_nCurStep; } - void SetCurrentTime(unsigned short Time) - { - m_nCurStep = (unsigned char)Time; + mCurrentStep = Step; CalculateStep(); } + void SetCurrentPiece(PieceInfo* pInfo) { m_pCurPiece = pInfo; } float* GetBackgroundColor() // todo: remove @@ -182,11 +175,6 @@ public: void GetSnapIndex(int* SnapXY, int* SnapZ, int* SnapAngle) const; void GetSnapText(char* SnapXY, char* SnapZ, char* SnapAngle) const; void GetSnapDistance(float* SnapXY, float* SnapZ) const; - void GetTimeRange(int* from, int* to) - { - *from = m_nCurStep; - *to = 255; - } int GetGroupIndex(lcGroup* Group) const { @@ -207,7 +195,7 @@ public: void RenderInitialize(); void GetPiecesUsed(lcArray& PiecesUsed) const; - void CreateImages(Image* images, int width, int height, unsigned short from, unsigned short to, bool hilite); + void CreateImages(Image* images, int width, int height, lcStep from, lcStep to, bool hilite); void Render(View* view, bool bToMemory); void CheckAutoSave(); bool GetSelectionCenter(lcVector3& Center) const; @@ -260,7 +248,7 @@ protected: void RenderSceneObjects(View* view); void RenderViewports(View* view); - void CreateHTMLPieceList(FILE* f, int nStep, bool bImages, const char* ext); + void CreateHTMLPieceList(FILE* f, lcStep Step, bool bImages, const char* ext); void Export3DStudio(); void ExportPOVRay(lcFile& File); void ZoomExtents(int FirstView, int LastView); @@ -275,10 +263,8 @@ public: lcuint32 m_nSnap; protected: - // State variables int mTransformType; PieceInfo* m_pCurPiece; - unsigned char m_nCurStep; lcuint16 m_nMoveSnap; lcuint16 m_nAngleSnap; diff --git a/qt/lc_qmainwindow.cpp b/qt/lc_qmainwindow.cpp index c87fbc4d..76336497 100644 --- a/qt/lc_qmainwindow.cpp +++ b/qt/lc_qmainwindow.cpp @@ -819,7 +819,7 @@ void lcQMainWindow::print(QPrinter *printer) GL_BeginRenderToTexture(tileWidth, tileHeight); glPixelStorei(GL_PACK_ALIGNMENT, 1); - unsigned short previousTime = project->GetCurrentTime(); + lcStep previousTime = project->GetCurrentStep(); QPainter painter(printer); lcuint8 *buffer = (lcuint8*)malloc(tileWidth * tileHeight * 4); @@ -836,7 +836,7 @@ void lcQMainWindow::print(QPrinter *printer) if (printer->printerState() == QPrinter::Aborted || printer->printerState() == QPrinter::Error) return; - int currentStep = 1 + ((page - 1) * rows * columns); + lcStep currentStep = 1 + ((page - 1) * rows * columns); for (int row = 0; row < rows; row++) { @@ -845,7 +845,7 @@ void lcQMainWindow::print(QPrinter *printer) if (currentStep > project->GetLastStep()) break; - project->SetCurrentTime(currentStep); + project->SetCurrentStep(currentStep); if (stepWidth > tileWidth || stepHeight > tileHeight) { @@ -1001,7 +1001,7 @@ void lcQMainWindow::print(QPrinter *printer) free(buffer); - project->SetCurrentTime(previousTime); + project->SetCurrentStep(previousTime); GL_EndRenderToTexture(); } @@ -1135,14 +1135,18 @@ void lcQMainWindow::updatePaste(bool enabled) action->setEnabled(enabled); } -void lcQMainWindow::updateTime(int currentTime, int totalTime) +void lcQMainWindow::updateCurrentStep() { - actions[LC_VIEW_TIME_FIRST]->setEnabled(currentTime != 1); - actions[LC_VIEW_TIME_PREVIOUS]->setEnabled(currentTime > 1); - actions[LC_VIEW_TIME_NEXT]->setEnabled(currentTime < totalTime); - actions[LC_VIEW_TIME_LAST]->setEnabled(currentTime != totalTime); + Project *project = lcGetActiveProject(); + lcStep currentStep = project->GetCurrentStep(); + lcStep lastStep = project->GetLastStep(); - statusTimeLabel->setText(QString(tr(" Step %1 ")).arg(QString::number(currentTime))); + actions[LC_VIEW_TIME_FIRST]->setEnabled(currentStep != 1); + actions[LC_VIEW_TIME_PREVIOUS]->setEnabled(currentStep > 1); + actions[LC_VIEW_TIME_NEXT]->setEnabled(currentStep < LC_STEP_MAX); + actions[LC_VIEW_TIME_LAST]->setEnabled(currentStep != lastStep); + + statusTimeLabel->setText(QString(tr("Step %1")).arg(QString::number(currentStep))); } void lcQMainWindow::setAddKeys(bool addKeys) diff --git a/qt/lc_qmainwindow.h b/qt/lc_qmainwindow.h index ac501cb8..00df6993 100644 --- a/qt/lc_qmainwindow.h +++ b/qt/lc_qmainwindow.h @@ -34,7 +34,7 @@ public: void updateSelectedObjects(int flags, int selectedCount, Object* focus); void updateAction(int newAction); void updatePaste(bool enabled); - void updateTime(int currentTime, int totalTime); + void updateCurrentStep(); void setAddKeys(bool addKeys); void updateLockSnap(lcuint32 snap); void updateSnap(); diff --git a/qt/lc_qpropertiestree.cpp b/qt/lc_qpropertiestree.cpp index 4603f083..9d52a514 100644 --- a/qt/lc_qpropertiestree.cpp +++ b/qt/lc_qpropertiestree.cpp @@ -555,13 +555,13 @@ void lcQPropertiesTree::slotReturnPressed() } else if (item == partShow) { - lcuint32 value = editor->text().toUInt(); + lcStep value = editor->text().toUInt(); project->ModifyObject(focusObject, LC_PIECE_PROPERTY_SHOW, &value); } else if (item == partHide) { - lcuint32 value = editor->text().toUInt(); + lcStep value = editor->text().toUInt(); project->ModifyObject(focusObject, LC_PIECE_PROPERTY_HIDE, &value); } @@ -805,8 +805,8 @@ void lcQPropertiesTree::setPart(Object *newFocusObject) partRotationZ->setText(1, QString::number(rotation[2])); partRotationZ->setData(0, PropertyValueRole, rotation[2]); - lcuint32 show = part->GetStepShow(); - lcuint32 hide = part->GetStepHide(); + lcStep show = part->GetStepShow(); + lcStep hide = part->GetStepHide(); partShow->setText(1, QString::number(show)); partShow->setData(0, PropertyValueRole, show); diff --git a/qt/lc_qselectdialog.cpp b/qt/lc_qselectdialog.cpp index caf1c624..0343b395 100644 --- a/qt/lc_qselectdialog.cpp +++ b/qt/lc_qselectdialog.cpp @@ -166,6 +166,7 @@ void lcQSelectDialog::addChildren(QTreeWidgetItem *parentItem, Group *parentGrou } const lcArray& pieces = project->GetPieces(); + lcStep currentStep = project->GetCurrentStep(); for (int pieceIdx = 0; pieceIdx < pieces.GetSize(); pieceIdx++, numObjects++) { @@ -174,7 +175,7 @@ void lcQSelectDialog::addChildren(QTreeWidgetItem *parentItem, Group *parentGrou if (piece->GetGroup() != parentGroup) continue; - if (!piece->IsVisible(project->GetCurrentTime())) + if (!piece->IsVisible(currentStep)) continue; QTreeWidgetItem *pieceItem = new QTreeWidgetItem(parentItem, QStringList(piece->GetName())); diff --git a/qt/qtmain.cpp b/qt/qtmain.cpp index 352e6273..012bb8f9 100644 --- a/qt/qtmain.cpp +++ b/qt/qtmain.cpp @@ -500,12 +500,12 @@ void lcMainWindow::UpdatePaste(bool Enabled) window->updatePaste(Enabled); } -void lcMainWindow::UpdateTime(int CurrentTime, int TotalTime) +void lcMainWindow::UpdateCurrentStep() { lcQMainWindow* window = (lcQMainWindow*)mHandle; if (window) - window->updateTime(CurrentTime, TotalTime); + window->updateCurrentStep(); } void lcMainWindow::SetAddKeys(bool AddKeys)