From 4a29e8406ddcad70ec84e0ef142a9d4f270ad570 Mon Sep 17 00:00:00 2001 From: melex750 Date: Sun, 20 Mar 2016 07:48:20 -0400 Subject: [PATCH 001/125] Fix syntax and type checking for CBotListArray --- src/CBot/CBotInstr/CBotListArray.cpp | 101 +++++++++++++++++++++++---- src/CBot/CBotInstr/CBotListArray.h | 3 +- 2 files changed, 88 insertions(+), 16 deletions(-) diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp index 20a34e6e..ab25e058 100644 --- a/src/CBot/CBotInstr/CBotListArray.cpp +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -45,57 +45,111 @@ CBotListArray::~CBotListArray() } //////////////////////////////////////////////////////////////////////////////// -CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type) +CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool classItem) { CBotCStack* pStk = pStack->TokenStack(p); CBotToken* pp = p; - if (IsOfType( p, ID_NULL )) + if (IsOfType( p, ID_NULL ) || (IsOfType(p, ID_OPBLK) && IsOfType(p, ID_CLBLK))) { CBotInstr* inst = new CBotExprLitNull(); inst->SetToken(pp); return pStack->Return(inst, pStk); // ok with empty element } + p = pp; CBotListArray* inst = new CBotListArray(); + pStk->SetStartError(p->GetStart()); + if (IsOfType( p, ID_OPBLK )) { // each element takes the one after the other if (type.Eq( CBotTypArrayPointer )) { - type = type.GetTypElem(); - pStk->SetStartError(p->GetStart()); - if (nullptr == ( inst->m_expr = CBotListArray::Compile( p, pStk, type ) )) + if (p->GetType() == TokenTypVar) { - goto error; + if (!classItem) + { + inst->m_expr = CBotTwoOpExpr::Compile(p, pStk); + if (!pStk->GetTypResult().Compare(type)) // compatible type ? + { + pStk->SetError(CBotErrBadType1, p->GetStart()); + goto error; + } + } + else + { + pStk->SetError(CBotErrBadLeft, p->GetPrev()); + goto error; + } } - - while (IsOfType( p, ID_COMMA )) // other elements? + else { - pStk->SetStartError(p->GetStart()); - - CBotInstr* i = CBotListArray::Compile(p, pStk, type); - if (nullptr == i) + if (nullptr == ( inst->m_expr = CBotListArray::Compile( p, pStk, type.GetTypElem() ) )) { goto error; } - + } + while (IsOfType( p, ID_COMMA )) // other elements? + { + pStk->SetStartError(p->GetStart()); + CBotInstr* i = nullptr; + if (p->GetType() == TokenTypVar) + { + if (!classItem) + { + i = CBotTwoOpExpr::Compile(p, pStk); + if (nullptr == i || !pStk->GetTypResult().Compare(type)) // compatible type ? + { + pStk->SetError(CBotErrBadType1, p->GetStart()); + goto error; + } + } + else + { + pStk->SetError(CBotErrBadLeft, p->GetPrev()); + goto error; + } + } + else + { + i = CBotListArray::Compile(p, pStk, type.GetTypElem()); + if (nullptr == i) + { + goto error; + } + } inst->m_expr->AddNext3(i); + if ( p->GetType() == ID_COMMA ) continue; + if ( p->GetType() == ID_CLBLK ) break; + + pStk->SetError(CBotErrClosePar, p); + goto error; } } else { pStk->SetStartError(p->GetStart()); + if (classItem && IsOfType(p, TokenTypVar, ID_NEW)) // don't allow func() or var between "{ }" + { + pStk->SetError(CBotErrBadLeft, p->GetPrev()); + goto error; + } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; } CBotVar* pv = pStk->GetVar(); // result of the expression + CBotTypResult retType; + if (pv != nullptr) retType = pv->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC); - if (pv == nullptr || !TypesCompatibles( type, pv->GetTypResult())) // compatible type? + if (pv == nullptr || (type.Eq(CBotTypString) && !retType.Eq(CBotTypString)) || + (!(type.Eq(CBotTypPointer) && retType.Eq(CBotTypNullPointer)) && + !TypesCompatibles( type, pv->GetTypResult()) && + !TypeCompatible(type, retType, ID_ASS) ) ) // compatible type? { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; @@ -105,6 +159,12 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu { pStk->SetStartError(p->GetStart()); + if (classItem && IsOfType(p, TokenTypVar, ID_NEW)) // don't allow func() or var between "{ }" + { + pStk->SetError(CBotErrBadLeft, p); + goto error; + } + CBotInstr* i = CBotTwoOpExpr::Compile(p, pStk) ; if (nullptr == i) { @@ -112,13 +172,24 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu } CBotVar* pv = pStk->GetVar(); // result of the expression + CBotTypResult retType; + if (pv != nullptr) retType = pv->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC); - if (pv == nullptr || !TypesCompatibles( type, pv->GetTypResult())) // compatible type? + if (pv == nullptr || (type.Eq(CBotTypString) && !retType.Eq(CBotTypString)) || + (!(type.Eq(CBotTypPointer) && retType.Eq(CBotTypNullPointer)) && + !TypesCompatibles( type, pv->GetTypResult()) && + !TypeCompatible(type, retType, ID_ASS) ) ) // compatible type? { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; } inst->m_expr->AddNext3(i); + + if (p->GetType() == ID_COMMA) continue; + if (p->GetType() == ID_CLBLK) break; + + pStk->SetError(CBotErrClosePar, p); + goto error; } } diff --git a/src/CBot/CBotInstr/CBotListArray.h b/src/CBot/CBotInstr/CBotListArray.h index c5f800b0..5c9eafdf 100644 --- a/src/CBot/CBotInstr/CBotListArray.h +++ b/src/CBot/CBotInstr/CBotListArray.h @@ -38,9 +38,10 @@ public: * \param p * \param pStack * \param type + * \param classItem * \return */ - static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type); + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool classItem = false); /*! * \brief Execute Executes the definition of an array. From accfc9357372fd87a71723ebdc3d0210cce2a92c Mon Sep 17 00:00:00 2001 From: melex750 Date: Sun, 20 Mar 2016 07:50:42 -0400 Subject: [PATCH 002/125] Add syntax and type checking for class member vars --- src/CBot/CBotClass.cpp | 44 ++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index d5007d83..5f761453 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -19,6 +19,7 @@ #include "CBot/CBotClass.h" +#include "CBot/CBotInstr/CBotInstrUtils.h" #include "CBot/CBotInstr/CBotNew.h" #include "CBot/CBotInstr/CBotLeftExprVar.h" #include "CBot/CBotInstr/CBotTwoOpExpr.h" @@ -561,29 +562,27 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) while ( IsOfType( p, ID_OPBRK ) ) // a table? { CBotInstr* i = nullptr; - + pStack->SetStartError( p->GetStart() ); if ( p->GetType() != ID_CLBRK ) + { i = CBotExpression::Compile( p, pStack ); // expression for the value + if (i == nullptr || pStack->GetType() >= CBotTypBoolean) // must be a number + { + pStack->SetError(CBotErrBadIndex, p->GetStart()); + return false; + } + } else i = new CBotEmpty(); // special if not a formula type = CBotTypResult(CBotTypArrayPointer, type); - if (!pStack->IsOk() || !IsOfType( p, ID_CLBRK ) ) - { - pStack->SetError(CBotErrCloseIndex, p->GetStart()); - return false; - } - -/* CBotVar* pv = pStack->GetVar(); - if ( pv->GetType()>= CBotTypBoolean ) - { - pStack->SetError(CBotErrBadType1, p->GetStart()); - return false; - }*/ - if (limites == nullptr) limites = i; else limites->AddNext3(i); + + if (IsOfType(p, ID_CLBRK)) continue; + pStack->SetError(CBotErrCloseIndex, p->GetStart()); + return false; } if ( p->GetType() == ID_OPENPAR ) @@ -681,6 +680,12 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) CBotInstr* i = nullptr; if ( IsOfType(p, ID_ASS ) ) { + pStack->SetStartError(p->GetStart()); + if ( IsOfTypeList(p, TokenTypVar, ID_NEW, ID_SEP, 0) ) // no var, new, or ';' + { + pStack->SetError(CBotErrBadLeft, p->GetPrev()); + return false; + } if ( type.Eq(CBotTypArrayPointer) ) { i = CBotListArray::Compile(p, pStack, type.GetTypElem()); @@ -689,6 +694,17 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) { // it has an assignmet to calculate i = CBotTwoOpExpr::Compile(p, pStack); + + CBotTypResult retType = pStack->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC); + + if ( (type.Eq(CBotTypString) && !retType.Eq(CBotTypString)) || + (!(type.Eq(CBotTypPointer) && retType.Eq(CBotTypNullPointer)) && + !TypeCompatible( type, retType, ID_ASS)) ) + + { + pStack->SetError(CBotErrBadType1, p->GetPrev()); + return false; + } } if ( !pStack->IsOk() ) return false; } From 707ef976261b4221330f93113d6886b97381c533 Mon Sep 17 00:00:00 2001 From: melex750 Date: Sun, 20 Mar 2016 07:54:41 -0400 Subject: [PATCH 003/125] Fix syntax+type checking, base types+CBotDefArray --- src/CBot/CBotInstr/CBotDefArray.cpp | 41 ++++++++++++++++++--------- src/CBot/CBotInstr/CBotDefBoolean.cpp | 13 +++++---- src/CBot/CBotInstr/CBotDefClass.cpp | 15 +++++----- src/CBot/CBotInstr/CBotDefFloat.cpp | 13 +++++---- src/CBot/CBotInstr/CBotDefInt.cpp | 25 ++++++---------- src/CBot/CBotInstr/CBotDefString.cpp | 10 +++++-- 6 files changed, 66 insertions(+), 51 deletions(-) diff --git a/src/CBot/CBotInstr/CBotDefArray.cpp b/src/CBot/CBotInstr/CBotDefArray.cpp index 2cb05aa0..c70c8f9b 100644 --- a/src/CBot/CBotInstr/CBotDefArray.cpp +++ b/src/CBot/CBotInstr/CBotDefArray.cpp @@ -72,19 +72,26 @@ CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResul CBotInstr* i; while (IsOfType(p, ID_OPBRK)) { + pStk->SetStartError(p->GetStart()); if (p->GetType() != ID_CLBRK) - i = CBotExpression::Compile(p, pStk); // expression for the value + { + i = CBotExpression::Compile(p, pStk); // expression for the value + if (i == nullptr || pStk->GetType() >= CBotTypBoolean) // must be a number + { + pStk->SetError(CBotErrBadIndex, p->GetStart()); + goto error; + } + } else i = new CBotEmpty(); // if no special formula inst->AddNext3b(i); // construct a list type = CBotTypResult(CBotTypArrayPointer, type); - if (!pStk->IsOk() || !IsOfType(p, ID_CLBRK )) - { - pStk->SetError(CBotErrCloseIndex, p->GetStart()); - goto error; - } + if (IsOfType(p, ID_CLBRK)) continue; + + pStk->SetError(CBotErrCloseIndex, p->GetStart()); + goto error; } CBotVar* var = CBotVar::Create(*vartoken, type); // create an instance @@ -96,17 +103,23 @@ CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResul if (IsOfType(p, ID_ASS)) // with an assignment { - if ((inst->m_listass = CBotTwoOpExpr::Compile(p, pStk)) != nullptr) + pStk->SetStartError(p->GetStart()); + if ( IsOfType(p, ID_SEP) ) { - if (!pStk->GetTypResult().Compare(type)) // compatible type ? - { - pStk->SetError(CBotErrBadType1, p->GetStart()); - goto error; - } + pStk->SetError(CBotErrBadLeft, p->GetPrev()); + goto error; } - else + if ( nullptr == (inst->m_listass = CBotListArray::Compile(p, pStk, type.GetTypElem())) ) { - inst->m_listass = CBotListArray::Compile(p, pStk, type.GetTypElem()); + if (pStk->IsOk()) + { + inst->m_listass = CBotTwoOpExpr::Compile(p, pStk); + if (inst->m_listass == nullptr || !pStk->GetTypResult().Compare(type)) // compatible type ? + { + pStk->SetError(CBotErrBadType1, p->GetStart()); + goto error; + } + } } } diff --git a/src/CBot/CBotInstr/CBotDefBoolean.cpp b/src/CBot/CBotInstr/CBotDefBoolean.cpp index bcac0722..63b9d346 100644 --- a/src/CBot/CBotInstr/CBotDefBoolean.cpp +++ b/src/CBot/CBotInstr/CBotDefBoolean.cpp @@ -82,16 +82,17 @@ CBotInstr* CBotDefBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, inst = static_cast(CBotDefArray::Compile(p, pStk, CBotTypBoolean)); - if (!pStk->IsOk() ) - { - pStk->SetError(CBotErrCloseIndex, p->GetStart()); - goto error; - } goto suite; // no assignment, variable already created } if (IsOfType(p, ID_ASS)) { + pStk->SetStartError(p->GetStart()); + if ( IsOfType(p, ID_SEP) ) + { + pStk->SetError(CBotErrBadLeft, p->GetPrev()); + goto error; + } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; @@ -109,7 +110,7 @@ CBotInstr* CBotDefBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); pStack->AddVar(var); suite: - if (IsOfType(p, ID_COMMA)) + if (pStk->IsOk() && IsOfType(p, ID_COMMA)) { if (nullptr != ( inst->m_next2b = CBotDefBoolean::Compile(p, pStk, true, noskip))) { diff --git a/src/CBot/CBotInstr/CBotDefClass.cpp b/src/CBot/CBotInstr/CBotDefClass.cpp index 39ac6afa..72ec71ec 100644 --- a/src/CBot/CBotInstr/CBotDefClass.cpp +++ b/src/CBot/CBotInstr/CBotDefClass.cpp @@ -101,11 +101,6 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p inst = static_cast(CBotDefArray::Compile(p, pStk, type )); - if (!pStk->IsOk() ) - { - pStk->SetError(CBotErrCloseIndex, p->GetStart()); - goto error; - } goto suite; // no assignment, variable already created } @@ -159,6 +154,12 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p if (IsOfType(p, ID_ASS)) // with a assignment? { + pStk->SetStartError(p->GetStart()); + if ( IsOfType(p, ID_SEP) ) + { + pStk->SetError(CBotErrBadLeft, p->GetPrev()); + goto error; + } if (inst->m_hasParams) { pStk->SetError(CBotErrNoTerminator, p->GetStart()); @@ -200,7 +201,7 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p var->SetInit(CBotVar::InitType::IS_POINTER); // marks the pointer as init } suite: - if (IsOfType(p, ID_COMMA)) // several chained definitions + if (pStk->IsOk() && IsOfType(p, ID_COMMA)) // several chained definitions { if ( nullptr != ( inst->m_next = CBotDefClass::Compile(p, pStk, pClass) )) // compiles the following { @@ -208,7 +209,7 @@ suite: } } - if (IsOfType(p, ID_SEP)) // complete instruction + if (!pStk->IsOk() || IsOfType(p, ID_SEP)) // complete instruction { return pStack->Return(inst, pStk); } diff --git a/src/CBot/CBotInstr/CBotDefFloat.cpp b/src/CBot/CBotInstr/CBotDefFloat.cpp index 9a99662f..33398fa2 100644 --- a/src/CBot/CBotInstr/CBotDefFloat.cpp +++ b/src/CBot/CBotInstr/CBotDefFloat.cpp @@ -81,16 +81,17 @@ CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, b p = vartoken; inst = static_cast(CBotDefArray::Compile(p, pStk, CBotTypFloat)); - if (!pStk->IsOk() ) - { - pStk->SetError(CBotErrCloseIndex, p->GetStart()); - goto error; - } goto suite; // no assignment, variable already created } if (IsOfType(p, ID_ASS)) { + pStk->SetStartError(p->GetStart()); + if ( IsOfType(p, ID_SEP) ) + { + pStk->SetError(CBotErrBadLeft, p->GetPrev()); + goto error; + } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; @@ -108,7 +109,7 @@ CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, b (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); pStack->AddVar(var); suite: - if (IsOfType(p, ID_COMMA)) + if (pStk->IsOk() && IsOfType(p, ID_COMMA)) { if (nullptr != ( inst->m_next2b = CBotDefFloat::Compile(p, pStk, true, noskip))) { diff --git a/src/CBot/CBotInstr/CBotDefInt.cpp b/src/CBot/CBotInstr/CBotDefInt.cpp index 360eb22b..9f7dcb61 100644 --- a/src/CBot/CBotInstr/CBotDefInt.cpp +++ b/src/CBot/CBotInstr/CBotDefInt.cpp @@ -84,25 +84,18 @@ CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, boo CBotInstr* inst2 = CBotDefArray::Compile(p, pStk, CBotTypInt); - if (!pStk->IsOk() ) - { - pStk->SetError(CBotErrCloseIndex, p->GetStart()); - goto error; - } - - if (IsOfType(p, ID_COMMA)) // several definition chained - { - if (nullptr != ( inst2->m_next2b = CBotDefInt::Compile(p, pStk, true, noskip))) // compile the next one - { - return pStack->Return(inst2, pStk); - } - } inst = static_cast(inst2); goto suite; // no assignment, variable already created } if (IsOfType(p, ID_ASS)) // with an assignment? { + pStk->SetStartError(p->GetStart()); + if ( IsOfType(p, ID_SEP) ) + { + pStk->SetError(CBotErrBadLeft, p->GetPrev()); + goto error; + } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; @@ -121,15 +114,15 @@ CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, boo (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); pStack->AddVar(var); // place it on the stack } - - if (IsOfType(p, ID_COMMA)) // chained several definitions +suite: + if (pStk->IsOk() && IsOfType(p, ID_COMMA)) // chained several definitions { if (nullptr != ( inst->m_next2b = CBotDefInt::Compile(p, pStk, true, noskip))) // compile next one { return pStack->Return(inst, pStk); } } -suite: + if (noskip || IsOfType(p, ID_SEP)) // instruction is completed { return pStack->Return(inst, pStk); diff --git a/src/CBot/CBotInstr/CBotDefString.cpp b/src/CBot/CBotInstr/CBotDefString.cpp index c878a84c..b224a1c0 100644 --- a/src/CBot/CBotInstr/CBotDefString.cpp +++ b/src/CBot/CBotInstr/CBotDefString.cpp @@ -75,15 +75,21 @@ CBotInstr* CBotDefString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, if (IsOfType(p, ID_ASS)) { + pStk->SetStartError(p->GetStart()); + if ( IsOfType(p, ID_SEP) ) + { + pStk->SetError(CBotErrBadLeft, p->GetPrev()); + goto error; + } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; } -/* if (!pStk->GetTypResult().Eq(CBotTypString)) // type compatible ? + if (!pStk->GetTypResult().Eq(CBotTypString)) // type compatible ? { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; - }*/ + } } CBotVar* var = CBotVar::Create(*vartoken, CBotTypString); From 5b3da837156619fe62bfe10d9a4378c5db0cafe3 Mon Sep 17 00:00:00 2001 From: melex750 Date: Sun, 20 Mar 2016 13:27:02 -0400 Subject: [PATCH 004/125] Fix inline declaration of an array of string --- src/CBot/CBotInstr/CBotDefString.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/CBot/CBotInstr/CBotDefString.cpp b/src/CBot/CBotInstr/CBotDefString.cpp index b224a1c0..77e0119f 100644 --- a/src/CBot/CBotInstr/CBotDefString.cpp +++ b/src/CBot/CBotInstr/CBotDefString.cpp @@ -20,6 +20,7 @@ #include "CBot/CBotInstr/CBotDefString.h" #include "CBot/CBotInstr/CBotLeftExprVar.h" +#include "CBot/CBotInstr/CBotDefArray.h" #include "CBot/CBotInstr/CBotTwoOpExpr.h" #include "CBot/CBotStack.h" @@ -61,6 +62,7 @@ CBotInstr* CBotDefString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, inst->m_expr = nullptr; CBotToken* vartoken = p; + CBotVar* var = nullptr; inst->SetToken(vartoken); if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk ))) @@ -73,6 +75,19 @@ CBotInstr* CBotDefString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, goto error; } + if (IsOfType(p, ID_OPBRK)) + { + delete inst; // type is not CBotDefString + p = vartoken; // returns the variable name + + // compiles an array declaration + + CBotInstr* inst2 = CBotDefArray::Compile(p, pStk, CBotTypString); + + inst = static_cast(inst2); + goto suite; // no assignment, variable already created + } + if (IsOfType(p, ID_ASS)) { pStk->SetStartError(p->GetStart()); @@ -85,20 +100,20 @@ CBotInstr* CBotDefString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, { goto error; } - if (!pStk->GetTypResult().Eq(CBotTypString)) // type compatible ? +/* if (!pStk->GetTypResult().Eq(CBotTypString)) // type compatible ? { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; - } + }*/ } - CBotVar* var = CBotVar::Create(*vartoken, CBotTypString); + var = CBotVar::Create(*vartoken, CBotTypString); var->SetInit(inst->m_expr != nullptr ? CBotVar::InitType::DEF : CBotVar::InitType::UNDEF); var->SetUniqNum( (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); pStack->AddVar(var); - - if (IsOfType(p, ID_COMMA)) +suite: + if (pStk->IsOk() && IsOfType(p, ID_COMMA)) { if (nullptr != ( inst->m_next2b = CBotDefString::Compile(p, pStk, true, noskip))) { From 6be1f562889d62758947d825924f737036aec6ac Mon Sep 17 00:00:00 2001 From: melex750 Date: Sun, 20 Mar 2016 20:55:22 -0400 Subject: [PATCH 005/125] Add error code no expression, remove some bad code --- src/CBot/CBotClass.cpp | 6 +-- src/CBot/CBotEnums.h | 1 + src/CBot/CBotInstr/CBotDefArray.cpp | 4 +- src/CBot/CBotInstr/CBotDefBoolean.cpp | 2 +- src/CBot/CBotInstr/CBotDefClass.cpp | 2 +- src/CBot/CBotInstr/CBotDefFloat.cpp | 2 +- src/CBot/CBotInstr/CBotDefInt.cpp | 2 +- src/CBot/CBotInstr/CBotDefString.cpp | 2 +- src/CBot/CBotInstr/CBotListArray.cpp | 67 +++++---------------------- src/CBot/CBotInstr/CBotListArray.h | 2 +- src/common/restext.cpp | 1 + 11 files changed, 25 insertions(+), 66 deletions(-) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 5f761453..aca2d2b0 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -566,7 +566,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) if ( p->GetType() != ID_CLBRK ) { i = CBotExpression::Compile( p, pStack ); // expression for the value - if (i == nullptr || pStack->GetType() >= CBotTypBoolean) // must be a number + if (i == nullptr || pStack->GetType() != CBotTypInt) // must be a number { pStack->SetError(CBotErrBadIndex, p->GetStart()); return false; @@ -681,9 +681,9 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) if ( IsOfType(p, ID_ASS ) ) { pStack->SetStartError(p->GetStart()); - if ( IsOfTypeList(p, TokenTypVar, ID_NEW, ID_SEP, 0) ) // no var, new, or ';' + if ( IsOfType(p, ID_SEP) ) { - pStack->SetError(CBotErrBadLeft, p->GetPrev()); + pStack->SetError(CBotErrNoExpression, p->GetPrev()); return false; } if ( type.Eq(CBotTypArrayPointer) ) diff --git a/src/CBot/CBotEnums.h b/src/CBot/CBotEnums.h index 475648a3..24e0095b 100644 --- a/src/CBot/CBotEnums.h +++ b/src/CBot/CBotEnums.h @@ -235,6 +235,7 @@ enum CBotError : int CBotErrBadIndex = 5040, //!< wrong index type "[ false ]" CBotErrPrivate = 5041, //!< protected item CBotErrNoPublic = 5042, //!< missing word "public" + CBotErrNoExpression = 5043, //!< expression expected after = // Runtime errors CBotErrZeroDiv = 6000, //!< division by zero diff --git a/src/CBot/CBotInstr/CBotDefArray.cpp b/src/CBot/CBotInstr/CBotDefArray.cpp index c70c8f9b..473fdc8d 100644 --- a/src/CBot/CBotInstr/CBotDefArray.cpp +++ b/src/CBot/CBotInstr/CBotDefArray.cpp @@ -76,7 +76,7 @@ CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResul if (p->GetType() != ID_CLBRK) { i = CBotExpression::Compile(p, pStk); // expression for the value - if (i == nullptr || pStk->GetType() >= CBotTypBoolean) // must be a number + if (i == nullptr || pStk->GetType() != CBotTypInt) // must be a number { pStk->SetError(CBotErrBadIndex, p->GetStart()); goto error; @@ -106,7 +106,7 @@ CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResul pStk->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStk->SetError(CBotErrBadLeft, p->GetPrev()); + pStk->SetError(CBotErrNoExpression, p->GetPrev()); goto error; } if ( nullptr == (inst->m_listass = CBotListArray::Compile(p, pStk, type.GetTypElem())) ) diff --git a/src/CBot/CBotInstr/CBotDefBoolean.cpp b/src/CBot/CBotInstr/CBotDefBoolean.cpp index 63b9d346..d64a1860 100644 --- a/src/CBot/CBotInstr/CBotDefBoolean.cpp +++ b/src/CBot/CBotInstr/CBotDefBoolean.cpp @@ -90,7 +90,7 @@ CBotInstr* CBotDefBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, pStk->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStk->SetError(CBotErrBadLeft, p->GetPrev()); + pStk->SetError(CBotErrNoExpression, p->GetPrev()); goto error; } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) diff --git a/src/CBot/CBotInstr/CBotDefClass.cpp b/src/CBot/CBotInstr/CBotDefClass.cpp index 72ec71ec..ab4ea991 100644 --- a/src/CBot/CBotInstr/CBotDefClass.cpp +++ b/src/CBot/CBotInstr/CBotDefClass.cpp @@ -157,7 +157,7 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p pStk->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStk->SetError(CBotErrBadLeft, p->GetPrev()); + pStk->SetError(CBotErrNoExpression, p->GetPrev()); goto error; } if (inst->m_hasParams) diff --git a/src/CBot/CBotInstr/CBotDefFloat.cpp b/src/CBot/CBotInstr/CBotDefFloat.cpp index 33398fa2..5348a529 100644 --- a/src/CBot/CBotInstr/CBotDefFloat.cpp +++ b/src/CBot/CBotInstr/CBotDefFloat.cpp @@ -89,7 +89,7 @@ CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, b pStk->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStk->SetError(CBotErrBadLeft, p->GetPrev()); + pStk->SetError(CBotErrNoExpression, p->GetPrev()); goto error; } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) diff --git a/src/CBot/CBotInstr/CBotDefInt.cpp b/src/CBot/CBotInstr/CBotDefInt.cpp index 9f7dcb61..babd3fda 100644 --- a/src/CBot/CBotInstr/CBotDefInt.cpp +++ b/src/CBot/CBotInstr/CBotDefInt.cpp @@ -93,7 +93,7 @@ CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, boo pStk->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStk->SetError(CBotErrBadLeft, p->GetPrev()); + pStk->SetError(CBotErrNoExpression, p->GetPrev()); goto error; } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) diff --git a/src/CBot/CBotInstr/CBotDefString.cpp b/src/CBot/CBotInstr/CBotDefString.cpp index 77e0119f..cb4502d9 100644 --- a/src/CBot/CBotInstr/CBotDefString.cpp +++ b/src/CBot/CBotInstr/CBotDefString.cpp @@ -93,7 +93,7 @@ CBotInstr* CBotDefString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, pStk->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStk->SetError(CBotErrBadLeft, p->GetPrev()); + pStk->SetError(CBotErrNoExpression, p->GetPrev()); goto error; } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp index ab25e058..bc6ac28d 100644 --- a/src/CBot/CBotInstr/CBotListArray.cpp +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -45,7 +45,7 @@ CBotListArray::~CBotListArray() } //////////////////////////////////////////////////////////////////////////////// -CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool classItem) +CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type) { CBotCStack* pStk = pStack->TokenStack(p); @@ -69,58 +69,33 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu if (type.Eq( CBotTypArrayPointer )) { pStk->SetStartError(p->GetStart()); - if (p->GetType() == TokenTypVar) + if ( nullptr == (inst->m_expr = CBotListArray::Compile(p, pStk, type.GetTypElem())) ) { - if (!classItem) + if (pStk->IsOk()) { inst->m_expr = CBotTwoOpExpr::Compile(p, pStk); - if (!pStk->GetTypResult().Compare(type)) // compatible type ? + if (inst->m_expr == nullptr || !pStk->GetTypResult().Compare(type)) // compatible type ? { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; } } - else - { - pStk->SetError(CBotErrBadLeft, p->GetPrev()); - goto error; - } - } - else - { - if (nullptr == ( inst->m_expr = CBotListArray::Compile( p, pStk, type.GetTypElem() ) )) - { - goto error; - } } while (IsOfType( p, ID_COMMA )) // other elements? { pStk->SetStartError(p->GetStart()); CBotInstr* i = nullptr; - if (p->GetType() == TokenTypVar) + if ( nullptr == (i = CBotListArray::Compile(p, pStk, type.GetTypElem())) ) { - if (!classItem) + if (pStk->IsOk()) { i = CBotTwoOpExpr::Compile(p, pStk); - if (nullptr == i || !pStk->GetTypResult().Compare(type)) // compatible type ? + if (i == nullptr || !pStk->GetTypResult().Compare(type)) // compatible type ? { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; } } - else - { - pStk->SetError(CBotErrBadLeft, p->GetPrev()); - goto error; - } - } - else - { - i = CBotListArray::Compile(p, pStk, type.GetTypElem()); - if (nullptr == i) - { - goto error; - } } inst->m_expr->AddNext3(i); if ( p->GetType() == ID_COMMA ) continue; @@ -133,23 +108,15 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu else { pStk->SetStartError(p->GetStart()); - if (classItem && IsOfType(p, TokenTypVar, ID_NEW)) // don't allow func() or var between "{ }" - { - pStk->SetError(CBotErrBadLeft, p->GetPrev()); - goto error; - } + if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; } CBotVar* pv = pStk->GetVar(); // result of the expression - CBotTypResult retType; - if (pv != nullptr) retType = pv->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC); - if (pv == nullptr || (type.Eq(CBotTypString) && !retType.Eq(CBotTypString)) || - (!(type.Eq(CBotTypPointer) && retType.Eq(CBotTypNullPointer)) && - !TypesCompatibles( type, pv->GetTypResult()) && - !TypeCompatible(type, retType, ID_ASS) ) ) // compatible type? + if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) && + !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer))) ) // compatible type? { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; @@ -159,12 +126,6 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu { pStk->SetStartError(p->GetStart()); - if (classItem && IsOfType(p, TokenTypVar, ID_NEW)) // don't allow func() or var between "{ }" - { - pStk->SetError(CBotErrBadLeft, p); - goto error; - } - CBotInstr* i = CBotTwoOpExpr::Compile(p, pStk) ; if (nullptr == i) { @@ -172,13 +133,9 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu } CBotVar* pv = pStk->GetVar(); // result of the expression - CBotTypResult retType; - if (pv != nullptr) retType = pv->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC); - if (pv == nullptr || (type.Eq(CBotTypString) && !retType.Eq(CBotTypString)) || - (!(type.Eq(CBotTypPointer) && retType.Eq(CBotTypNullPointer)) && - !TypesCompatibles( type, pv->GetTypResult()) && - !TypeCompatible(type, retType, ID_ASS) ) ) // compatible type? + if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) && + !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer))) ) // compatible type? { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; diff --git a/src/CBot/CBotInstr/CBotListArray.h b/src/CBot/CBotInstr/CBotListArray.h index 5c9eafdf..329e5877 100644 --- a/src/CBot/CBotInstr/CBotListArray.h +++ b/src/CBot/CBotInstr/CBotListArray.h @@ -41,7 +41,7 @@ public: * \param classItem * \return */ - static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool classItem = false); + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type); /*! * \brief Execute Executes the definition of an array. diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 0139c1ed..9b492678 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -715,6 +715,7 @@ void InitializeRestext() stringsCbot[CBot::CBotErrBadIndex] = TR("Incorrect index type"); stringsCbot[CBot::CBotErrPrivate] = TR("Private element"); stringsCbot[CBot::CBotErrNoPublic] = TR("Public required"); + stringsCbot[CBot::CBotErrNoExpression] = TR("expression expected after ="); stringsCbot[CBot::CBotErrZeroDiv] = TR("Dividing by zero"); stringsCbot[CBot::CBotErrNotInit] = TR("Variable not initialized"); From 8b7410f803c89f5261071f28e75e7e15382b2521 Mon Sep 17 00:00:00 2001 From: melex750 Date: Mon, 21 Mar 2016 06:11:55 -0400 Subject: [PATCH 006/125] Fix class.arrays using size of one before comma --- src/CBot/CBotClass.cpp | 34 +++++++++++++++++---------- src/CBot/CBotInstr/CBotDefBoolean.cpp | 2 +- src/CBot/CBotInstr/CBotDefClass.cpp | 15 ++++++------ src/CBot/CBotInstr/CBotDefFloat.cpp | 2 +- src/CBot/CBotInstr/CBotDefInt.cpp | 2 +- src/CBot/CBotInstr/CBotDefString.cpp | 2 +- src/CBot/CBotInstr/CBotListArray.cpp | 15 ++++++------ src/CBot/CBotInstr/CBotListArray.h | 1 - 8 files changed, 41 insertions(+), 32 deletions(-) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index aca2d2b0..e701db86 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -550,6 +550,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) while (pStack->IsOk()) { + CBotTypResult type2 = CBotTypResult(type); // reset type after comma std::string pp = p->GetString(); if ( IsOfType(p, ID_NOT) ) { @@ -575,7 +576,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) else i = new CBotEmpty(); // special if not a formula - type = CBotTypResult(CBotTypArrayPointer, type); + type2 = CBotTypResult(CBotTypArrayPointer, type2); if (limites == nullptr) limites = i; else limites->AddNext3(i); @@ -671,7 +672,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) } // definition of an element - if (type.Eq(0)) + if (type2.Eq(0)) { pStack->SetError(CBotErrNoTerminator, p); return false; @@ -683,26 +684,33 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) pStack->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStack->SetError(CBotErrNoExpression, p->GetPrev()); + pStack->SetError(CBotErrNoExpression, p->GetStart()); return false; } - if ( type.Eq(CBotTypArrayPointer) ) + if ( type2.Eq(CBotTypArrayPointer) ) { - i = CBotListArray::Compile(p, pStack, type.GetTypElem()); + if ( nullptr == (i = CBotListArray::Compile(p, pStack, type2.GetTypElem())) ) + { + if (pStack->IsOk()) + { + i = CBotTwoOpExpr::Compile(p, pStack); + if (i == nullptr || !pStack->GetTypResult().Compare(type2)) + { + pStack->SetError(CBotErrBadType1, p->GetStart()); + return false; + } + } + } } else { // it has an assignmet to calculate i = CBotTwoOpExpr::Compile(p, pStack); - CBotTypResult retType = pStack->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC); - - if ( (type.Eq(CBotTypString) && !retType.Eq(CBotTypString)) || - (!(type.Eq(CBotTypPointer) && retType.Eq(CBotTypNullPointer)) && - !TypeCompatible( type, retType, ID_ASS)) ) - + if ( !(type.Eq(CBotTypPointer) && pStack->GetTypResult().Eq(CBotTypNullPointer)) && + !TypesCompatibles( type, pStack->GetTypResult()) ) { - pStack->SetError(CBotErrBadType1, p->GetPrev()); + pStack->SetError(CBotErrBadType1, p->GetStart()); return false; } } @@ -712,7 +720,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) if ( !bSecond ) { - CBotVar* pv = CBotVar::Create(pp, type); + CBotVar* pv = CBotVar::Create(pp, type2); pv -> SetStatic( bStatic ); pv -> SetPrivate( mProtect ); diff --git a/src/CBot/CBotInstr/CBotDefBoolean.cpp b/src/CBot/CBotInstr/CBotDefBoolean.cpp index d64a1860..e89bdc83 100644 --- a/src/CBot/CBotInstr/CBotDefBoolean.cpp +++ b/src/CBot/CBotInstr/CBotDefBoolean.cpp @@ -90,7 +90,7 @@ CBotInstr* CBotDefBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, pStk->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStk->SetError(CBotErrNoExpression, p->GetPrev()); + pStk->SetError(CBotErrNoExpression, p->GetStart()); goto error; } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) diff --git a/src/CBot/CBotInstr/CBotDefClass.cpp b/src/CBot/CBotInstr/CBotDefClass.cpp index ab4ea991..f7ea77a6 100644 --- a/src/CBot/CBotInstr/CBotDefClass.cpp +++ b/src/CBot/CBotInstr/CBotDefClass.cpp @@ -155,17 +155,18 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p if (IsOfType(p, ID_ASS)) // with a assignment? { pStk->SetStartError(p->GetStart()); - if ( IsOfType(p, ID_SEP) ) - { - pStk->SetError(CBotErrNoExpression, p->GetPrev()); - goto error; - } if (inst->m_hasParams) { pStk->SetError(CBotErrNoTerminator, p->GetStart()); goto error; } + if ( IsOfType(p, ID_SEP) ) + { + pStk->SetError(CBotErrNoExpression, p->GetStart()); + goto error; + } + if ( nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) ) { goto error; @@ -201,7 +202,7 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p var->SetInit(CBotVar::InitType::IS_POINTER); // marks the pointer as init } suite: - if (pStk->IsOk() && IsOfType(p, ID_COMMA)) // several chained definitions + if (pStk->IsOk() && IsOfType(p, ID_COMMA)) // several chained definitions { if ( nullptr != ( inst->m_next = CBotDefClass::Compile(p, pStk, pClass) )) // compiles the following { @@ -209,7 +210,7 @@ suite: } } - if (!pStk->IsOk() || IsOfType(p, ID_SEP)) // complete instruction + if (!pStk->IsOk() || IsOfType(p, ID_SEP)) // complete instruction { return pStack->Return(inst, pStk); } diff --git a/src/CBot/CBotInstr/CBotDefFloat.cpp b/src/CBot/CBotInstr/CBotDefFloat.cpp index 5348a529..17466581 100644 --- a/src/CBot/CBotInstr/CBotDefFloat.cpp +++ b/src/CBot/CBotInstr/CBotDefFloat.cpp @@ -89,7 +89,7 @@ CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, b pStk->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStk->SetError(CBotErrNoExpression, p->GetPrev()); + pStk->SetError(CBotErrNoExpression, p->GetStart()); goto error; } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) diff --git a/src/CBot/CBotInstr/CBotDefInt.cpp b/src/CBot/CBotInstr/CBotDefInt.cpp index babd3fda..4e946e9b 100644 --- a/src/CBot/CBotInstr/CBotDefInt.cpp +++ b/src/CBot/CBotInstr/CBotDefInt.cpp @@ -93,7 +93,7 @@ CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, boo pStk->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStk->SetError(CBotErrNoExpression, p->GetPrev()); + pStk->SetError(CBotErrNoExpression, p->GetStart()); goto error; } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) diff --git a/src/CBot/CBotInstr/CBotDefString.cpp b/src/CBot/CBotInstr/CBotDefString.cpp index cb4502d9..9bf2eebe 100644 --- a/src/CBot/CBotInstr/CBotDefString.cpp +++ b/src/CBot/CBotInstr/CBotDefString.cpp @@ -93,7 +93,7 @@ CBotInstr* CBotDefString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, pStk->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStk->SetError(CBotErrNoExpression, p->GetPrev()); + pStk->SetError(CBotErrNoExpression, p->GetStart()); goto error; } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp index bc6ac28d..559bb9d9 100644 --- a/src/CBot/CBotInstr/CBotListArray.cpp +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -61,15 +61,13 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu CBotListArray* inst = new CBotListArray(); - pStk->SetStartError(p->GetStart()); - if (IsOfType( p, ID_OPBLK )) { // each element takes the one after the other if (type.Eq( CBotTypArrayPointer )) { pStk->SetStartError(p->GetStart()); - if ( nullptr == (inst->m_expr = CBotListArray::Compile(p, pStk, type.GetTypElem())) ) + if (nullptr == ( inst->m_expr = CBotListArray::Compile( p, pStk, type.GetTypElem() ) )) { if (pStk->IsOk()) { @@ -81,11 +79,13 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu } } } + while (IsOfType( p, ID_COMMA )) // other elements? { pStk->SetStartError(p->GetStart()); + CBotInstr* i = nullptr; - if ( nullptr == (i = CBotListArray::Compile(p, pStk, type.GetTypElem())) ) + if (nullptr == ( i = CBotListArray::Compile(p, pStk, type.GetTypElem() ) )) { if (pStk->IsOk()) { @@ -97,7 +97,9 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu } } } + inst->m_expr->AddNext3(i); + if ( p->GetType() == ID_COMMA ) continue; if ( p->GetType() == ID_CLBLK ) break; @@ -108,7 +110,6 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu else { pStk->SetStartError(p->GetStart()); - if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; @@ -116,7 +117,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu CBotVar* pv = pStk->GetVar(); // result of the expression if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) && - !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer))) ) // compatible type? + !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer)) )) { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; @@ -135,7 +136,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu CBotVar* pv = pStk->GetVar(); // result of the expression if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) && - !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer))) ) // compatible type? + !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer)) )) { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; diff --git a/src/CBot/CBotInstr/CBotListArray.h b/src/CBot/CBotInstr/CBotListArray.h index 329e5877..c5f800b0 100644 --- a/src/CBot/CBotInstr/CBotListArray.h +++ b/src/CBot/CBotInstr/CBotListArray.h @@ -38,7 +38,6 @@ public: * \param p * \param pStack * \param type - * \param classItem * \return */ static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type); From 02133d0bd48a54a17a0b5d59b596c009fb512c19 Mon Sep 17 00:00:00 2001 From: melex750 Date: Mon, 21 Mar 2016 07:56:52 -0400 Subject: [PATCH 007/125] Fix method overloading --- src/CBot/CBotClass.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index e701db86..27794d7f 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -33,6 +33,7 @@ #include "CBot/CBotExternalCall.h" #include "CBot/CBotStack.h" #include "CBot/CBotCStack.h" +#include "CBot/CBotDefParam.h" #include "CBot/CBotUtils.h" #include "CBot/CBotFileUtils.h" #include "CBot/CBotCallMethode.h" @@ -604,9 +605,14 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) // return a method precompiled in pass 1 CBotFunction* pf = m_pMethod; CBotFunction* prev = nullptr; - while ( pf != nullptr ) + CBotToken* ppp = p; + CBotCStack* pStk = pStack->TokenStack(nullptr, true); + CBotDefParam* params = CBotDefParam::Compile(p, pStk ); + delete pStk; + p = ppp; + while ( pf != nullptr ) // search by name and parameters { - if (pf->GetName() == pp) break; + if (pf->GetName() == pp && pf->CheckParam( params )) break; prev = pf; pf = pf->Next(); } @@ -708,7 +714,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) i = CBotTwoOpExpr::Compile(p, pStack); if ( !(type.Eq(CBotTypPointer) && pStack->GetTypResult().Eq(CBotTypNullPointer)) && - !TypesCompatibles( type, pStack->GetTypResult()) ) + !TypesCompatibles( type2, pStack->GetTypResult()) ) { pStack->SetError(CBotErrBadType1, p->GetStart()); return false; From 640c0297ef5644d0f8cd3de3bd610439ad437d98 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 26 Mar 2016 18:34:26 +0100 Subject: [PATCH 008/125] Replaced CConfigFile::GetInstancePointer() with GetConfigFile() --- src/app/input.cpp | 20 ++++++++++---------- src/common/config_file.h | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/app/input.cpp b/src/app/input.cpp index ca7aff46..ed1fdf93 100644 --- a/src/app/input.cpp +++ b/src/app/input.cpp @@ -332,7 +332,7 @@ InputSlot CInput::FindBinding(unsigned int key) void CInput::SaveKeyBindings() { std::stringstream key; - CConfigFile::GetInstancePointer()->SetStringProperty("Keybindings", "_Version", "SDL2"); + GetConfigFile().SetStringProperty("Keybindings", "_Version", "SDL2"); for (int i = 0; i < INPUT_SLOT_MAX; i++) { InputBinding b = GetInputBinding(static_cast(i)); @@ -341,30 +341,30 @@ void CInput::SaveKeyBindings() key.str(""); key << b.primary << " " << b.secondary; - CConfigFile::GetInstancePointer()->SetStringProperty("Keybindings", m_keyTable[static_cast(i)], key.str()); + GetConfigFile().SetStringProperty("Keybindings", m_keyTable[static_cast(i)], key.str()); } for (int i = 0; i < JOY_AXIS_SLOT_MAX; i++) { JoyAxisBinding b = GetJoyAxisBinding(static_cast(i)); - CConfigFile::GetInstancePointer()->SetIntProperty("Setup", "JoystickAxisBinding"+boost::lexical_cast(i), b.axis); - CConfigFile::GetInstancePointer()->SetIntProperty("Setup", "JoystickAxisInvert"+boost::lexical_cast(i), b.invert); + GetConfigFile().SetIntProperty("Setup", "JoystickAxisBinding"+boost::lexical_cast(i), b.axis); + GetConfigFile().SetIntProperty("Setup", "JoystickAxisInvert"+boost::lexical_cast(i), b.invert); } - CConfigFile::GetInstancePointer()->SetFloatProperty("Setup", "JoystickDeadzone", GetJoystickDeadzone()); + GetConfigFile().SetFloatProperty("Setup", "JoystickDeadzone", GetJoystickDeadzone()); } void CInput::LoadKeyBindings() { std::stringstream skey; std::string keys; - if (CConfigFile::GetInstancePointer()->GetStringProperty("Keybindings", "_Version", keys) && keys == "SDL2") // Keybindings from SDL1.2 are incompatible with SDL2 !! + if (GetConfigFile().GetStringProperty("Keybindings", "_Version", keys) && keys == "SDL2") // Keybindings from SDL1.2 are incompatible with SDL2 !! { for (int i = 0; i < INPUT_SLOT_MAX; i++) { InputBinding b; - if (!CConfigFile::GetInstancePointer()->GetStringProperty("Keybindings", m_keyTable[static_cast(i)], keys)) + if (!GetConfigFile().GetStringProperty("Keybindings", m_keyTable[static_cast(i)], keys)) continue; skey.clear(); skey.str(keys); @@ -380,17 +380,17 @@ void CInput::LoadKeyBindings() { JoyAxisBinding b; - if (!CConfigFile::GetInstancePointer()->GetIntProperty("Setup", "JoystickAxisBinding"+boost::lexical_cast(i), b.axis)) + if (!GetConfigFile().GetIntProperty("Setup", "JoystickAxisBinding"+boost::lexical_cast(i), b.axis)) continue; int x = 0; - CConfigFile::GetInstancePointer()->GetIntProperty("Setup", "JoystickAxisInvert"+boost::lexical_cast(i), x); // If doesn't exist, use default (0) + GetConfigFile().GetIntProperty("Setup", "JoystickAxisInvert"+boost::lexical_cast(i), x); // If doesn't exist, use default (0) b.invert = (x != 0); SetJoyAxisBinding(static_cast(i), b); } float deadzone; - if (CConfigFile::GetInstancePointer()->GetFloatProperty("Setup", "JoystickDeadzone", deadzone)) + if (GetConfigFile().GetFloatProperty("Setup", "JoystickDeadzone", deadzone)) SetJoystickDeadzone(deadzone); } diff --git a/src/common/config_file.h b/src/common/config_file.h index 02a000c8..0ed8e19f 100644 --- a/src/common/config_file.h +++ b/src/common/config_file.h @@ -107,8 +107,8 @@ private: bool m_loaded; }; -//! Global function to get profile instance +//! Global function to get config file instance inline CConfigFile & GetConfigFile() { - return *CConfigFile::GetInstancePointer(); + return CConfigFile::GetInstance(); } From 6585ee9ae8ef7fedb3cf7fdd3d83c933be703dff Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 26 Mar 2016 18:55:39 +0100 Subject: [PATCH 009/125] Refactor some references to CRobotMain from CEngine --- src/app/app.cpp | 2 +- src/common/event.cpp | 2 ++ src/common/event.h | 4 ++++ src/graphics/engine/engine.cpp | 9 +++++--- src/graphics/engine/engine.h | 8 ++++--- src/level/robotmain.cpp | 41 ++++++++++++++-------------------- src/level/robotmain.h | 3 --- 7 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 5e91af9a..fbf6018f 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -822,7 +822,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::DeviceConfig &newConfig) m_device->ConfigChanged(m_deviceConfig); - m_engine->ResetAfterVideoConfigChanged(); + m_eventQueue->AddEvent(Event(EVENT_RESOLUTION_CHANGED)); return true; } diff --git a/src/common/event.cpp b/src/common/event.cpp index ccd7fe8a..49b5218d 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -68,6 +68,8 @@ void InitializeEventTypeTexts() EVENT_TYPE_TEXT[EVENT_UPDINTERFACE] = "EVENT_UPDINTERFACE"; + EVENT_TYPE_TEXT[EVENT_RESOLUTION_CHANGED]= "EVENT_RESOLUTION_CHANGED"; + EVENT_TYPE_TEXT[EVENT_RELOAD_TEXTURES] = "EVENT_RELOAD_TEXTURES"; EVENT_TYPE_TEXT[EVENT_WIN] = "EVENT_WIN"; EVENT_TYPE_TEXT[EVENT_LOST] = "EVENT_LOST"; diff --git a/src/common/event.h b/src/common/event.h index 50fb0c98..b4eb79fa 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -95,6 +95,10 @@ enum EventType //! Event sent on user quit request EVENT_QUIT = 20, EVENT_UPDINTERFACE = 21, + //! Event sent on resolution change + EVENT_RESOLUTION_CHANGED = 22, + //! Event sent when textures have to be reloaded + EVENT_RELOAD_TEXTURES = 23, EVENT_WIN = 30, EVENT_LOST = 31, diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index a66f8063..afc8a173 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -359,8 +359,6 @@ void CEngine::ResetAfterVideoConfigChanged() m_size = m_app->GetVideoConfig().size; m_mouseSize = Math::Point(0.04f, 0.04f * (static_cast(m_size.x) / static_cast(m_size.y))); - CRobotMain::GetInstancePointer()->ResetAfterVideoConfigChanged(); //TODO: Remove cross-reference to CRobotMain - // Update the camera projection matrix for new aspect ratio SetFocus(m_focus); @@ -373,13 +371,18 @@ void CEngine::ReloadAllTextures() FlushTextureCache(); m_text->FlushCache(); - CRobotMain::GetInstancePointer()->ReloadAllTextures(); //TODO: Remove cross-reference to CRobotMain + m_app->GetEventQueue()->AddEvent(Event(EVENT_RELOAD_TEXTURES)); UpdateGroundSpotTextures(); LoadAllTextures(); } bool CEngine::ProcessEvent(const Event &event) { + if (event.type == EVENT_RESOLUTION_CHANGED) + { + ResetAfterVideoConfigChanged(); + } + if (event.type == EVENT_KEY_DOWN) { auto data = event.GetData(); diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 5fc65a2c..bda5f782 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -655,9 +655,6 @@ public: //! Frees all resources before exit void Destroy(); - //! Resets some states and flushes textures after device was changed (e.g. resoulution changed) - void ResetAfterVideoConfigChanged(); - //! Called once per frame, the call is the entry point for rendering void Render(); @@ -1188,6 +1185,10 @@ public: void AddDisplayCrashSpheres(const std::vector& crashSpheres); protected: + //! Resets some states and flushes textures after device was changed (e.g. resoulution changed) + /** Instead of calling this directly, send EVENT_RESOLUTION_CHANGED event **/ + void ResetAfterVideoConfigChanged(); + //! Prepares the interface for 3D scene void Draw3DScene(); //! Renders shadow map @@ -1281,6 +1282,7 @@ protected: static void WriteScreenShotThread(std::unique_ptr data); //! Reloads all textures + /** This additionally sends EVENT_RELOAD_TEXTURES to reload all textures not maintained by CEngine **/ void ReloadAllTextures(); protected: diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 514d2181..9a841e6d 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -303,30 +303,6 @@ CPauseManager* CRobotMain::GetPauseManager() return m_pause.get(); } -void CRobotMain::ResetAfterVideoConfigChanged() -{ - // Recreate the interface (needed if the aspect ratio changes) - // TODO: This can sometimes cause unwanted side effects, like hidden windows reappearing. To be fixed during CEGUI refactoring. - m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE)); - CreateShortcuts(); -} - -void CRobotMain::ReloadAllTextures() -{ - if (m_phase == PHASE_SETUPds || - m_phase == PHASE_SETUPgs || - m_phase == PHASE_SETUPps || - m_phase == PHASE_SETUPcs || - m_phase == PHASE_SETUPss || - m_phase == PHASE_SIMUL || - m_phase == PHASE_WIN || - m_phase == PHASE_LOST) - { - ChangeColor(); - UpdateMap(); - } -} - std::string PhaseToString(Phase phase) { if (phase == PHASE_WELCOME1) return "PHASE_WELCOME1"; @@ -693,6 +669,23 @@ bool CRobotMain::ProcessEvent(Event &event) return EventFrame(event); } + if (event.type == EVENT_RELOAD_TEXTURES) + { + if (IsPhaseWithWorld(m_phase)) + { + ChangeColor(); + UpdateMap(); + } + } + + if (event.type == EVENT_RESOLUTION_CHANGED) + { + // Recreate the interface (needed if the aspect ratio changes) + // TODO: This can sometimes cause unwanted side effects, like hidden windows reappearing. To be fixed during CEGUI refactoring. + m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE)); + CreateShortcuts(); + } + if (event.type == EVENT_FOCUS_LOST) { GetLogger()->Trace("Window unfocused\n"); diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 991c97ce..dd409888 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -161,9 +161,6 @@ public: Ui::CDisplayText* GetDisplayText(); CPauseManager* GetPauseManager(); - void ResetAfterVideoConfigChanged(); - void ReloadAllTextures(); - void ChangePhase(Phase phase); bool ProcessEvent(Event &event); Phase GetPhase(); From 5de577400bbbe20b1e77ad1e37aa46540ddb9e9d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 26 Mar 2016 19:05:58 +0100 Subject: [PATCH 010/125] Refactor CRobotMain::ExecuteCmd() to std::string --- src/level/robotmain.cpp | 70 ++++++++++++++++++++--------------------- src/level/robotmain.h | 2 +- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 9a841e6d..ed520bac 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -1156,25 +1156,25 @@ bool CRobotMain::ProcessEvent(Event &event) //! Executes a command -void CRobotMain::ExecuteCmd(char *cmd) +void CRobotMain::ExecuteCmd(const std::string& cmd) { - if (cmd[0] == 0) return; + if (cmd.empty()) return; if (m_phase == PHASE_SIMUL) { - if (strcmp(cmd, "winmission") == 0) + if (cmd == "winmission") m_eventQueue->AddEvent(Event(EVENT_WIN)); - if (strcmp(cmd, "lostmission") == 0) + if (cmd == "lostmission") m_eventQueue->AddEvent(Event(EVENT_LOST)); - if (strcmp(cmd, "trainerpilot") == 0) + if (cmd == "trainerpilot") { m_trainerPilot = !m_trainerPilot; return; } - if (strcmp(cmd, "fly") == 0) + if (cmd == "fly") { m_researchDone[0] |= RESEARCH_FLY; @@ -1182,7 +1182,7 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } - if (strcmp(cmd, "allresearch") == 0) + if (cmd == "allresearch") { m_researchDone[0] = -1; // all research are done @@ -1190,7 +1190,7 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } - if (strcmp(cmd, "allbuildings") == 0) + if (cmd == "allbuildings") { m_build = -1; // all buildings are available @@ -1198,7 +1198,7 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } - if (strcmp(cmd, "all") == 0) + if (cmd == "all") { m_researchDone[0] = -1; // all research are done m_build = -1; // all buildings are available @@ -1207,13 +1207,13 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } - if (strcmp(cmd, "nolimit") == 0) + if (cmd == "nolimit") { m_terrain->SetFlyingMaxHeight(280.0f); return; } - if (strcmp(cmd, "controller") == 0) + if (cmd == "controller") { if (m_controller != nullptr) { @@ -1231,7 +1231,7 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } - if (strcmp(cmd, "photo1") == 0) + if (cmd == "photo1") { if (m_freePhotoPause == nullptr) { @@ -1247,7 +1247,7 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } - if (strcmp(cmd, "photo2") == 0) + if (cmd == "photo2") { if (m_freePhotoPause == nullptr) { @@ -1269,26 +1269,26 @@ void CRobotMain::ExecuteCmd(char *cmd) } int camtype; - if (sscanf(cmd, "camtype %d", &camtype) > 0) + if (sscanf(cmd.c_str(), "camtype %d", &camtype) > 0) { m_camera->SetType(static_cast(camtype)); return; } float camspeed; - if (sscanf(cmd, "camspeed %f", &camspeed) > 0) + if (sscanf(cmd.c_str(), "camspeed %f", &camspeed) > 0) { m_camera->SetCameraSpeed(camspeed); return; } - if (strcmp(cmd, "freecam") == 0) + if (cmd == "freecam") { m_camera->SetType(Gfx::CAM_TYPE_FREE); return; } - if (strcmp(cmd, "noclip") == 0) + if (cmd == "noclip") { CObject* object = GetSelect(); if (object != nullptr) @@ -1296,7 +1296,7 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } - if (strcmp(cmd, "clip") == 0) + if (cmd == "clip") { CObject* object = GetSelect(); if (object != nullptr) @@ -1304,7 +1304,7 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } - if (strcmp(cmd, "addhusky") == 0) + if (cmd == "addhusky") { CObject* object = GetSelect(); if (object != nullptr && object->Implements(ObjectInterfaceType::Shielded)) @@ -1312,7 +1312,7 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } - if (strcmp(cmd, "addfreezer") == 0) + if (cmd == "addfreezer") { CObject* object = GetSelect(); if (object != nullptr && object->Implements(ObjectInterfaceType::JetFlying)) @@ -1320,7 +1320,7 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } - if (strcmp(cmd, "\155\157\157") == 0) + if (cmd == "\155\157\157") { // VGhpcyBpcyBlYXN0ZXItZWdnIGFuZCBzbyBpdCBzaG91bGQgYmUgb2JmdXNjYXRlZCEgRG8gbm90 // IGNsZWFuLXVwIHRoaXMgY29kZSEK @@ -1334,7 +1334,7 @@ void CRobotMain::ExecuteCmd(char *cmd) GetLogger()->Info(" \x20\x20 \x7C\x7C\x20\x20\x20\x20 ||\n"); } - if (strcmp(cmd, "fullpower") == 0) + if (cmd == "fullpower") { CObject* object = GetSelect(); if (object != nullptr) @@ -1355,7 +1355,7 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } - if (strcmp(cmd, "fullenergy") == 0) + if (cmd == "fullenergy") { CObject* object = GetSelect(); @@ -1371,7 +1371,7 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } - if (strcmp(cmd, "fullshield") == 0) + if (cmd == "fullshield") { CObject* object = GetSelect(); if (object != nullptr && object->Implements(ObjectInterfaceType::Shielded)) @@ -1379,7 +1379,7 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } - if (strcmp(cmd, "fullrange") == 0) + if (cmd == "fullrange") { CObject* object = GetSelect(); if (object != nullptr) @@ -1389,19 +1389,19 @@ void CRobotMain::ExecuteCmd(char *cmd) } return; } - if (strcmp(cmd, "debugcrashon") == 0) + if (cmd == "debugcrashon") { m_debugCrashSpheres = true; return; } - if (strcmp(cmd, "debugcrashoff") == 0) + if (cmd == "debugcrashoff") { m_debugCrashSpheres = false; return; } } - if (strcmp(cmd, "debugmode") == 0) + if (cmd == "debugmode") { if (m_app->IsDebugModeActive(DEBUG_ALL)) { @@ -1414,46 +1414,46 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } - if (strcmp(cmd, "showstat") == 0) + if (cmd == "showstat") { m_engine->SetShowStats(!m_engine->GetShowStats()); return; } - if (strcmp(cmd, "invui") == 0) + if (cmd == "invui") { m_engine->SetRenderInterface(!m_engine->GetRenderInterface()); return; } - if (strcmp(cmd, "selectinsect") == 0) + if (cmd == "selectinsect") { m_selectInsect = !m_selectInsect; return; } - if (strcmp(cmd, "showsoluce") == 0) + if (cmd == "showsoluce") { m_showSoluce = !m_showSoluce; m_ui->ShowSoluceUpdate(); return; } - if (strcmp(cmd, "allmission") == 0) + if (cmd == "allmission") { m_showAll = !m_showAll; m_ui->AllMissionUpdate(); return; } - if (strcmp(cmd, "invradar") == 0) + if (cmd == "invradar") { m_cheatRadar = !m_cheatRadar; return; } float speed; - if (sscanf(cmd, "speed %f", &speed) > 0) + if (sscanf(cmd.c_str(), "speed %f", &speed) > 0) { SetSpeed(speed); UpdateSpeedLabel(); diff --git a/src/level/robotmain.h b/src/level/robotmain.h index dd409888..0ed3e0bd 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -392,7 +392,7 @@ protected: void StartDisplayVisit(EventType event); void FrameVisit(float rTime); void StopDisplayVisit(); - void ExecuteCmd(char *cmd); + void ExecuteCmd(const std::string& cmd); void UpdateSpeedLabel(); int AutosaveRotate(bool freeOne); From adf20f58d41565780fda4194fa926aa1a9358524 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 26 Mar 2016 19:49:24 +0100 Subject: [PATCH 011/125] Removed unused members of CNullDevice --- src/graphics/core/nulldevice.cpp | 3 --- src/graphics/core/nulldevice.h | 11 ----------- 2 files changed, 14 deletions(-) diff --git a/src/graphics/core/nulldevice.cpp b/src/graphics/core/nulldevice.cpp index 5ab4ec08..ad483ede 100644 --- a/src/graphics/core/nulldevice.cpp +++ b/src/graphics/core/nulldevice.cpp @@ -27,9 +27,6 @@ namespace Gfx CNullDevice::CNullDevice() { - m_matrix = Math::Matrix(); - m_material = Material(); - m_light = Light(); } CNullDevice::~CNullDevice() diff --git a/src/graphics/core/nulldevice.h b/src/graphics/core/nulldevice.h index 68f2effc..3a78ea83 100644 --- a/src/graphics/core/nulldevice.h +++ b/src/graphics/core/nulldevice.h @@ -17,11 +17,6 @@ * along with this program. If not, see http://gnu.org/licenses */ -/** - * \file graphics/core/device.h - * \brief Abstract graphics device - CDevice class and related structs/enums - */ - #pragma once #include "graphics/core/device.h" @@ -38,7 +33,6 @@ namespace Gfx /** * \class CNullDevice * \brief Device implementation that doesn't render anything - * */ class CNullDevice : public CDevice { @@ -160,11 +154,6 @@ public: int GetMaxTextureSize() override; bool IsFramebufferSupported() override; - -private: - Math::Matrix m_matrix; - Material m_material; - Light m_light; }; From d2ac1afcf04f28fced52799fe42892ef1bfd6ebd Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 27 Mar 2016 13:34:26 +0200 Subject: [PATCH 012/125] Changed reference colors using when recoloring textures to constants --- src/level/robotmain.cpp | 65 +++++++++++++++++------------------------ src/level/robotmain.h | 4 --- 2 files changed, 26 insertions(+), 43 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index ed520bac..1234224f 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -116,6 +116,12 @@ const float UNIT = 4.0f; // default for g_unit float g_unit; // conversion factor +// Reference colors used when recoloring textures, see ChangeColor() +const Gfx::Color COLOR_REF_BOT = Gfx::Color( 10.0f/256.0f, 166.0f/256.0f, 254.0f/256.0f); // blue +const Gfx::Color COLOR_REF_ALIEN = Gfx::Color(135.0f/256.0f, 170.0f/256.0f, 13.0f/256.0f); // green +const Gfx::Color COLOR_REF_GREEN = Gfx::Color(135.0f/256.0f, 170.0f/256.0f, 13.0f/256.0f); // green +const Gfx::Color COLOR_REF_WATER = Gfx::Color( 25.0f/256.0f, 255.0f/256.0f, 240.0f/256.0f); // cyan + template<> CRobotMain* CSingleton::m_instance = nullptr; @@ -2823,30 +2829,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_controller = nullptr; - m_colorRefBot.r = 10.0f/256.0f; - m_colorRefBot.g = 166.0f/256.0f; - m_colorRefBot.b = 254.0f/256.0f; // blue - m_colorRefBot.a = 0.0f; m_colorNewBot.clear(); - m_colorNewBot[0] = m_colorRefBot; - - m_colorRefAlien.r = 135.0f/256.0f; - m_colorRefAlien.g = 170.0f/256.0f; - m_colorRefAlien.b = 13.0f/256.0f; // green - m_colorRefAlien.a = 0.0f; - m_colorNewAlien = m_colorRefAlien; - - m_colorRefGreen.r = 135.0f/256.0f; - m_colorRefGreen.g = 170.0f/256.0f; - m_colorRefGreen.b = 13.0f/256.0f; // green - m_colorRefGreen.a = 0.0f; - m_colorNewGreen = m_colorRefGreen; - - m_colorRefWater.r = 25.0f/256.0f; - m_colorRefWater.g = 255.0f/256.0f; - m_colorRefWater.b = 240.0f/256.0f; // cyan - m_colorRefWater.a = 0.0f; - m_colorNewWater = m_colorRefWater; + m_colorNewBot[0] = COLOR_REF_BOT; + m_colorNewAlien = COLOR_REF_ALIEN; + m_colorNewGreen = COLOR_REF_GREEN; + m_colorNewWater = COLOR_REF_WATER; m_engine->SetAmbientColor(Gfx::Color(0.5f, 0.5f, 0.5f, 0.5f), 0); m_engine->SetAmbientColor(Gfx::Color(0.5f, 0.5f, 0.5f, 0.5f), 1); @@ -3249,7 +3236,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) line->GetParam("level")->AsFloat(100.0f)*g_unit, line->GetParam("glint")->AsFloat(1.0f), pos); - m_colorNewWater = line->GetParam("color")->AsColor(m_colorRefWater); + m_colorNewWater = line->GetParam("color")->AsColor(COLOR_REF_WATER); m_colorShiftWater = line->GetParam("brightness")->AsFloat(0.0f); continue; } @@ -3951,26 +3938,26 @@ void CRobotMain::ChangeColor() // VehicleColor - for(auto it : m_colorNewBot) + for (auto it : m_colorNewBot) { int team = it.first; Gfx::Color newColor = it.second; std::string teamStr = StrUtils::ToString(team); if(team == 0) teamStr = ""; - m_engine->ChangeTextureColor("textures/objects/base1.png"+teamStr, "textures/objects/base1.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); - m_engine->ChangeTextureColor("textures/objects/convert.png"+teamStr, "textures/objects/convert.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); - m_engine->ChangeTextureColor("textures/objects/derrick.png"+teamStr, "textures/objects/derrick.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); - m_engine->ChangeTextureColor("textures/objects/factory.png"+teamStr, "textures/objects/factory.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); - m_engine->ChangeTextureColor("textures/objects/lemt.png"+teamStr, "textures/objects/lemt.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); - m_engine->ChangeTextureColor("textures/objects/roller.png"+teamStr, "textures/objects/roller.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); - m_engine->ChangeTextureColor("textures/objects/search.png"+teamStr, "textures/objects/search.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); + m_engine->ChangeTextureColor("textures/objects/base1.png"+teamStr, "textures/objects/base1.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); + m_engine->ChangeTextureColor("textures/objects/convert.png"+teamStr, "textures/objects/convert.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); + m_engine->ChangeTextureColor("textures/objects/derrick.png"+teamStr, "textures/objects/derrick.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); + m_engine->ChangeTextureColor("textures/objects/factory.png"+teamStr, "textures/objects/factory.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); + m_engine->ChangeTextureColor("textures/objects/lemt.png"+teamStr, "textures/objects/lemt.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); + m_engine->ChangeTextureColor("textures/objects/roller.png"+teamStr, "textures/objects/roller.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); + m_engine->ChangeTextureColor("textures/objects/search.png"+teamStr, "textures/objects/search.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, nullptr, 0, true); exclu[0] = Math::Point( 0.0f/256.0f, 160.0f/256.0f); exclu[1] = Math::Point(256.0f/256.0f, 256.0f/256.0f); // pencils exclu[2] = Math::Point(0.0f, 0.0f); exclu[3] = Math::Point(0.0f, 0.0f); // terminator - m_engine->ChangeTextureColor("textures/objects/drawer.png"+teamStr, "textures/objects/drawer.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true); + m_engine->ChangeTextureColor("textures/objects/drawer.png"+teamStr, "textures/objects/drawer.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true); exclu[0] = Math::Point(237.0f/256.0f, 176.0f/256.0f); exclu[1] = Math::Point(256.0f/256.0f, 220.0f/256.0f); // blue canister @@ -3978,7 +3965,7 @@ void CRobotMain::ChangeColor() exclu[3] = Math::Point(130.0f/256.0f, 214.0f/256.0f); // safe location exclu[4] = Math::Point(0.0f, 0.0f); exclu[5] = Math::Point(0.0f, 0.0f); // terminator - m_engine->ChangeTextureColor("textures/objects/subm.png"+teamStr, "textures/objects/subm.png", m_colorRefBot, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true); + m_engine->ChangeTextureColor("textures/objects/subm.png"+teamStr, "textures/objects/subm.png", COLOR_REF_BOT, newColor, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true); } // AlienColor @@ -3987,23 +3974,23 @@ void CRobotMain::ChangeColor() exclu[1] = Math::Point(256.0f/256.0f, 256.0f/256.0f); // SatCom exclu[2] = Math::Point(0.0f, 0.0f); exclu[3] = Math::Point(0.0f, 0.0f); // terminator - m_engine->ChangeTextureColor("textures/objects/ant.png", m_colorRefAlien, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti, exclu); - m_engine->ChangeTextureColor("textures/objects/mother.png", m_colorRefAlien, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti); + m_engine->ChangeTextureColor("textures/objects/ant.png", COLOR_REF_ALIEN, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti, exclu); + m_engine->ChangeTextureColor("textures/objects/mother.png", COLOR_REF_ALIEN, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti); // GreeneryColor - m_engine->ChangeTextureColor("textures/objects/plant.png", m_colorRefGreen, m_colorNewGreen, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti); + m_engine->ChangeTextureColor("textures/objects/plant.png", COLOR_REF_GREEN, m_colorNewGreen, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti); // water color // PARTIPLOUF0 and PARTIDROP : ts = Math::Point(0.500f, 0.500f); ti = Math::Point(0.875f, 0.750f); - m_engine->ChangeTextureColor("textures/effect00.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, nullptr, m_colorShiftWater, true); + m_engine->ChangeTextureColor("textures/effect00.png", COLOR_REF_WATER, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, nullptr, m_colorShiftWater, true); // PARTIFLIC : ts = Math::Point(0.00f, 0.75f); ti = Math::Point(0.25f, 1.00f); - m_engine->ChangeTextureColor("textures/effect02.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, nullptr, m_colorShiftWater, true); + m_engine->ChangeTextureColor("textures/effect02.png", COLOR_REF_WATER, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, nullptr, m_colorShiftWater, true); } //! Calculates the distance to the nearest object diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 0ed3e0bd..079add3e 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -559,13 +559,9 @@ protected: ShowLimit m_showLimit[MAXSHOWLIMIT]; - Gfx::Color m_colorRefBot; std::map m_colorNewBot; - Gfx::Color m_colorRefAlien; Gfx::Color m_colorNewAlien; - Gfx::Color m_colorRefGreen; Gfx::Color m_colorNewGreen; - Gfx::Color m_colorRefWater; Gfx::Color m_colorNewWater; float m_colorShiftWater = 0.0f; From 7fe65067ee06c414e56499c01e65666db176c957 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 27 Mar 2016 13:46:48 +0200 Subject: [PATCH 013/125] Fixed exit after single mission mode --- src/level/robotmain.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 1234224f..1d51b59d 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -231,8 +231,6 @@ CRobotMain::CRobotMain() m_globalMagnifyDamage = 1.0f; - m_exitAfterMission = false; - m_autosave = true; m_autosaveInterval = 5; m_autosaveSlots = 3; @@ -366,6 +364,13 @@ void CRobotMain::ChangePhase(Phase phase) bool resetWorld = false; if ((IsPhaseWithWorld(m_phase) || IsPhaseWithWorld(phase)) && !IsInSimulationConfigPhase(m_phase) && !IsInSimulationConfigPhase(phase)) { + if (IsPhaseWithWorld(m_phase) && !IsPhaseWithWorld(phase) && m_exitAfterMission) + { + GetLogger()->Info("Mission finished in single mission mode, exiting\n"); + m_eventQueue->AddEvent(Event(EVENT_QUIT)); + return; + } + GetLogger()->Info("Reseting world on phase change...\n"); resetWorld = true; } @@ -5105,8 +5110,6 @@ Error CRobotMain::CheckEndMission(bool frame) m_missionTimerEnabled = m_missionTimerStarted = false; m_winDelay = m_endTakeWinDelay; // wins in two seconds m_lostDelay = 0.0f; - if (m_exitAfterMission) - m_eventQueue->AddEvent(Event(EVENT_QUIT)); m_displayText->SetEnable(false); } m_missionResult = ERR_OK; @@ -5139,8 +5142,6 @@ Error CRobotMain::CheckEndMission(bool frame) } m_missionTimerEnabled = m_missionTimerStarted = false; m_displayText->SetEnable(false); - if (m_exitAfterMission) - m_eventQueue->AddEvent(Event(EVENT_QUIT)); return INFO_LOSTq; } @@ -5154,8 +5155,6 @@ Error CRobotMain::CheckEndMission(bool frame) } m_missionTimerEnabled = m_missionTimerStarted = false; m_displayText->SetEnable(false); - if (m_exitAfterMission) - m_eventQueue->AddEvent(Event(EVENT_QUIT)); return INFO_LOST; } @@ -5167,8 +5166,6 @@ Error CRobotMain::CheckEndMission(bool frame) m_lostDelay = 0.0f; m_missionTimerEnabled = m_missionTimerStarted = false; m_displayText->SetEnable(false); - if (m_exitAfterMission) - m_eventQueue->AddEvent(Event(EVENT_QUIT)); return ERR_OK; // mission ended } @@ -5194,8 +5191,6 @@ Error CRobotMain::CheckEndMission(bool frame) m_winDelay = m_endTakeWinDelay; // wins in two seconds m_lostDelay = 0.0f; } - if (m_exitAfterMission) - m_eventQueue->AddEvent(Event(EVENT_QUIT)); m_displayText->SetEnable(false); return ERR_OK; // mission ended } From 45c93f58ec75e5fd5d4a93c2240961fc0174778f Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 27 Mar 2016 14:19:48 +0200 Subject: [PATCH 014/125] Fixed Houston lights when object is rotated --- src/object/auto/autohouston.cpp | 64 ++++++++++++++++----------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/src/object/auto/autohouston.cpp b/src/object/auto/autohouston.cpp index a73b2705..9ace4085 100644 --- a/src/object/auto/autohouston.cpp +++ b/src/object/auto/autohouston.cpp @@ -18,6 +18,7 @@ */ +#include #include "object/auto/autohouston.h" #include "object/old_object.h" @@ -30,23 +31,19 @@ CAutoHouston::CAutoHouston(COldObject* object) : CAuto(object) { - Math::Vector pos; - int i; - - for ( i=0 ; iGetPosition(); m_lens[0].type = Gfx::PARTISELR; m_lens[1].type = Gfx::PARTISELR; m_lens[2].type = Gfx::PARTISELR; m_lens[3].type = Gfx::PARTISELR; - m_lens[0].pos = pos+Math::Vector(0.0f+13.0f, 34.0f, 30.0f ); - m_lens[1].pos = pos+Math::Vector(0.0f-13.0f, 34.0f, 30.0f ); - m_lens[2].pos = pos+Math::Vector(0.0f , 34.0f, 30.0f+13.0f); - m_lens[3].pos = pos+Math::Vector(0.0f , 34.0f, 30.0f-13.0f); + m_lens[0].pos = Math::Vector(0.0f+13.0f, 34.0f, 30.0f ); + m_lens[1].pos = Math::Vector(0.0f-13.0f, 34.0f, 30.0f ); + m_lens[2].pos = Math::Vector(0.0f , 34.0f, 30.0f+13.0f); + m_lens[3].pos = Math::Vector(0.0f , 34.0f, 30.0f-13.0f); m_lens[0].dim = 4.0f; m_lens[1].dim = 4.0f; m_lens[2].dim = 4.0f; @@ -60,49 +57,50 @@ CAutoHouston::CAutoHouston(COldObject* object) : CAuto(object) m_lens[2].off = 0.4f; m_lens[3].off = 0.4f; + int i = 4; + // Part under the radar. - i = 4; m_lens[i].type = Gfx::PARTISELR; - m_lens[i].pos = pos+Math::Vector(-7.0f, 9.9f, 40.1f); + m_lens[i].pos = Math::Vector(-7.0f, 9.9f, 40.1f); m_lens[i].dim = 1.8f; m_lens[i].total = 0.4f; m_lens[i].off = 0.2f; i ++; m_lens[i].type = Gfx::PARTISELY; - m_lens[i].pos = pos+Math::Vector(-7.0f, 7.2f, 34.8f); + m_lens[i].pos = Math::Vector(-7.0f, 7.2f, 34.8f); m_lens[i].dim = 0.4f; m_lens[i].total = 0.7f; m_lens[i].off = 0.3f; i ++; m_lens[i].type = Gfx::PARTISELY; - m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 34.3f); + m_lens[i].pos = Math::Vector(-7.0f, 6.5f, 34.3f); m_lens[i].dim = 0.4f; m_lens[i].total = 0.7f; m_lens[i].off = 0.3f; i ++; m_lens[i].type = Gfx::PARTISELR; - m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 33.4f); + m_lens[i].pos = Math::Vector(-7.0f, 6.5f, 33.4f); m_lens[i].dim = 0.4f; m_lens[i].total = 0.0f; m_lens[i].off = 0.0f; i ++; m_lens[i].type = Gfx::PARTISELR; - m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 33.0f); + m_lens[i].pos = Math::Vector(-7.0f, 6.5f, 33.0f); m_lens[i].dim = 0.4f; m_lens[i].total = 1.0f; m_lens[i].off = 0.5f; i ++; m_lens[i].type = Gfx::PARTISELY; - m_lens[i].pos = pos+Math::Vector(-7.0f, 8.5f, 14.0f); + m_lens[i].pos = Math::Vector(-7.0f, 8.5f, 14.0f); m_lens[i].dim = 1.2f; m_lens[i].total = 0.8f; m_lens[i].off = 0.2f; i ++; m_lens[i].type = Gfx::PARTISELR; - m_lens[i].pos = pos+Math::Vector(4.0f, 6.0f, 8.6f); + m_lens[i].pos = Math::Vector(4.0f, 6.0f, 8.6f); m_lens[i].dim = 1.0f; m_lens[i].total = 0.9f; m_lens[i].off = 0.7f; @@ -110,53 +108,53 @@ CAutoHouston::CAutoHouston(COldObject* object) : CAuto(object) // Part with three windows. m_lens[i].type = Gfx::PARTISELR; - m_lens[i].pos = pos+Math::Vector(-7.0f, 9.9f, -19.9f); + m_lens[i].pos = Math::Vector(-7.0f, 9.9f, -19.9f); m_lens[i].dim = 1.0f; m_lens[i].total = 0.6f; m_lens[i].off = 0.3f; i ++; m_lens[i].type = Gfx::PARTISELY; - m_lens[i].pos = pos+Math::Vector(-7.0f, 7.2f, 34.8f-60.0f); + m_lens[i].pos = Math::Vector(-7.0f, 7.2f, 34.8f-60.0f); m_lens[i].dim = 0.4f; m_lens[i].total = 0.7f; m_lens[i].off = 0.3f; i ++; m_lens[i].type = Gfx::PARTISELY; - m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 34.3f-60.0f); + m_lens[i].pos = Math::Vector(-7.0f, 6.5f, 34.3f-60.0f); m_lens[i].dim = 0.4f; m_lens[i].total = 0.0f; m_lens[i].off = 0.0f; i ++; m_lens[i].type = Gfx::PARTISELR; - m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 33.4f-60.0f); + m_lens[i].pos = Math::Vector(-7.0f, 6.5f, 33.4f-60.0f); m_lens[i].dim = 0.4f; m_lens[i].total = 0.6f; m_lens[i].off = 0.4f; i ++; m_lens[i].type = Gfx::PARTISELR; - m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 33.0f-60.0f); + m_lens[i].pos = Math::Vector(-7.0f, 6.5f, 33.0f-60.0f); m_lens[i].dim = 0.4f; m_lens[i].total = 0.8f; m_lens[i].off = 0.2f; i ++; m_lens[i].type = Gfx::PARTISELY; - m_lens[i].pos = pos+Math::Vector(-6.5f, 13.5f, -37.0f); + m_lens[i].pos = Math::Vector(-6.5f, 13.5f, -37.0f); m_lens[i].dim = 1.0f; m_lens[i].total = 0.0f; m_lens[i].off = 0.0f; i ++; m_lens[i].type = Gfx::PARTISELY; - m_lens[i].pos = pos+Math::Vector(-7.0f, 12.2f, -39.8f); + m_lens[i].pos = Math::Vector(-7.0f, 12.2f, -39.8f); m_lens[i].dim = 1.8f; m_lens[i].total = 1.5f; m_lens[i].off = 0.5f; i ++; m_lens[i].type = Gfx::PARTISELY; - m_lens[i].pos = pos+Math::Vector(-7.0f, 8.5f, -47.0f); + m_lens[i].pos = Math::Vector(-7.0f, 8.5f, -47.0f); m_lens[i].dim = 0.6f; m_lens[i].total = 0.7f; m_lens[i].off = 0.5f; @@ -204,15 +202,11 @@ void CAutoHouston::Start(int param) bool CAutoHouston::EventProcess(const Event &event) { - Math::Vector speed; - Math::Point dim; - float angle; - int i; - CAuto::EventProcess(event); if ( m_engine->GetPause() ) return true; + float angle; angle = -m_time*1.0f; m_object->SetPartRotationY(1, angle); // rotates the radar angle = sinf(m_time*4.0f)*0.3f; @@ -223,8 +217,7 @@ bool CAutoHouston::EventProcess(const Event &event) m_progress += event.rTime*m_speed; // Flashes the keys. - speed = Math::Vector(0.0f, 0.0f, 0.0f); - for ( i=0 ; iCreateParticle(m_lens[i].pos, speed, dim, m_lens[i].type, 1.0f, 0.0f, 0.0f); + + Math::Vector pos = m_lens[i].pos; + Math::RotatePoint(Math::Vector(0.0f, 0.0f, 0.0f), -m_object->GetRotationY(), 0.0f, pos); + + m_lens[i].parti = m_particle->CreateParticle(m_object->GetPosition()+pos, Math::Vector(0.0f, 0.0f, 0.0f), dim, m_lens[i].type, 1.0f, 0.0f, 0.0f); } } } From 4af02c86f8c398c28faa2c7dfadec56ac00f59e7 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 28 Mar 2016 13:51:39 +0200 Subject: [PATCH 015/125] Debug menu --- src/CMakeLists.txt | 1 + src/common/event.h | 25 +- src/graphics/engine/engine.cpp | 50 ++-- src/graphics/engine/engine.h | 8 +- src/graphics/engine/lightning.cpp | 59 +++-- src/graphics/engine/lightning.h | 3 + src/graphics/engine/particle.cpp | 8 - src/graphics/engine/particle.h | 3 - src/level/robotmain.cpp | 49 ++-- src/level/robotmain.h | 6 + src/ui/controls/target.cpp | 3 +- src/ui/debug_menu.cpp | 400 ++++++++++++++++++++++++++++++ src/ui/debug_menu.h | 70 ++++++ 13 files changed, 607 insertions(+), 78 deletions(-) create mode 100644 src/ui/debug_menu.cpp create mode 100644 src/ui/debug_menu.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f0012b1f..38d21f0f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -218,6 +218,7 @@ set(BASE_SOURCES script/scriptfunc.cpp sound/sound.cpp sound/sound_type.cpp + ui/debug_menu.cpp ui/displayinfo.cpp ui/displaytext.cpp ui/object_interface.cpp diff --git a/src/common/event.h b/src/common/event.h index b4eb79fa..d1b851c9 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -149,7 +149,7 @@ enum EventType EVENT_WINDOW4 = 84, //!< CDisplayInfo EVENT_WINDOW5 = 85, //!< all menu windows EVENT_WINDOW6 = 86, //!< code battle interface - EVENT_WINDOW7 = 87, //!< (unused) + EVENT_WINDOW7 = 87, //!< debug interface EVENT_WINDOW8 = 88, //!< (unused) EVENT_WINDOW9 = 89, //!< CMainDialog and CStudio file selector @@ -380,6 +380,29 @@ enum EventType EVENT_CMD = 800, EVENT_SPEED = 801, + EVENT_DBG_STATS = 850, + EVENT_DBG_SPAWN_OBJ = 851, + EVENT_DBG_TELEPORT = 852, + EVENT_DBG_LIGHTNING = 853, + EVENT_DBG_CRASHSPHERES = 854, + EVENT_DBG_LIGHTS = 855, + EVENT_DBG_LIGHTS_DUMP = 856, + + EVENT_SPAWN_CANCEL = 860, + EVENT_SPAWN_ME = 861, + EVENT_SPAWN_WHEELEDGRABBER = 862, + EVENT_SPAWN_WHEELEDSHOOTER = 863, + EVENT_SPAWN_PHAZERSHOOTER = 864, + EVENT_SPAWN_BOTFACTORY = 865, + EVENT_SPAWN_CONVERTER = 866, + EVENT_SPAWN_DERRICK = 867, + EVENT_SPAWN_POWERSTATION= 868, + EVENT_SPAWN_TITANIUM = 869, + EVENT_SPAWN_TITANIUMORE = 870, + EVENT_SPAWN_URANIUMORE = 871, + EVENT_SPAWN_POWERCELL = 872, + EVENT_SPAWN_NUCLEARCELL = 873, + EVENT_HYPER_PREV = 900, EVENT_HYPER_NEXT = 901, EVENT_HYPER_HOME = 902, diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index afc8a173..4ab66f3d 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -392,18 +392,6 @@ bool CEngine::ProcessEvent(const Event &event) m_showStats = !m_showStats; return false; } - - if (data->key == KEY(F11)) - { - m_debugLights = !m_debugLights; - return false; - } - - if (data->key == KEY(F10)) - { - m_debugDumpLights = true; - return false; - } } // By default, pass on all events @@ -1753,17 +1741,18 @@ bool CEngine::DetectBBox(int objRank, Math::Point mouse) mouse.y <= max.y ); } -int CEngine::DetectObject(Math::Point mouse) +int CEngine::DetectObject(Math::Point mouse, Math::Vector& targetPos, bool terrain) { float min = 1000000.0f; int nearest = -1; + Math::Vector pos; for (int objRank = 0; objRank < static_cast( m_objects.size() ); objRank++) { if (! m_objects[objRank].used) continue; - if (m_objects[objRank].type == ENG_OBJTYPE_TERRAIN) + if (m_objects[objRank].type == ENG_OBJTYPE_TERRAIN && !terrain) continue; if (! DetectBBox(objRank, mouse)) @@ -1792,10 +1781,11 @@ int CEngine::DetectObject(Math::Point mouse) for (int i = 0; i < static_cast( p3.vertices.size() ); i += 3) { float dist = 0.0f; - if (DetectTriangle(mouse, &p3.vertices[i], objRank, dist) && dist < min) + if (DetectTriangle(mouse, &p3.vertices[i], objRank, dist, pos) && dist < min) { min = dist; nearest = objRank; + targetPos = pos; } } } @@ -1804,10 +1794,11 @@ int CEngine::DetectObject(Math::Point mouse) for (int i = 0; i < static_cast( p3.vertices.size() ) - 2; i += 1) { float dist = 0.0f; - if (DetectTriangle(mouse, &p3.vertices[i], objRank, dist) && dist < min) + if (DetectTriangle(mouse, &p3.vertices[i], objRank, dist, pos) && dist < min) { min = dist; nearest = objRank; + targetPos = pos; } } } @@ -1818,7 +1809,7 @@ int CEngine::DetectObject(Math::Point mouse) return nearest; } -bool CEngine::DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRank, float& dist) +bool CEngine::DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRank, float& dist, Math::Vector& pos) { assert(objRank >= 0 && objRank < static_cast(m_objects.size())); @@ -1865,6 +1856,16 @@ bool CEngine::DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRan if (! Math::IsInsideTriangle(a, b, c, mouse)) return false; + Math::Vector a2 = Math::Transform(m_objects[objRank].transform, triangle[0].coord); + Math::Vector b2 = Math::Transform(m_objects[objRank].transform, triangle[1].coord); + Math::Vector c2 = Math::Transform(m_objects[objRank].transform, triangle[2].coord); + Math::Vector e = Math::Transform(m_matView.Inverse(), Math::Vector(0.0f, 0.0f, -1.0f)); + Math::Vector f = Math::Transform(m_matView.Inverse(), Math::Vector( + (mouse.x*2.0f-1.0f)*m_matProj.Inverse().Get(1,1), + (mouse.y*2.0f-1.0f)*m_matProj.Inverse().Get(2,2), + 0.0f)); + Math::Intersect(a2, b2, c2, e, f, pos); + dist = (p2D[0].z + p2D[1].z + p2D[2].z) / 3.0f; return true; } @@ -5078,4 +5079,19 @@ void CEngine::SetStaticMeshTransparency(int meshHandle, float value) SetObjectTransparency(objRank, value); } +void CEngine::SetDebugLights(bool debugLights) +{ + m_debugLights = debugLights; +} + +bool CEngine::GetDebugLights() +{ + return m_debugLights; +} + +void CEngine::DebugDumpLights() +{ + m_debugDumpLights = true; +} + } // namespace Gfx diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index bda5f782..ba1b1718 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -841,7 +841,7 @@ public: //! Detects the target object that is selected with the mouse /** Returns the rank of the object or -1. */ - int DetectObject(Math::Point mouse); + int DetectObject(Math::Point mouse, Math::Vector& targetPos, bool terrain = false); //! Creates a shadow for the given object void CreateShadowSpot(int objRank); @@ -1184,6 +1184,10 @@ public: void ClearDisplayCrashSpheres(); void AddDisplayCrashSpheres(const std::vector& crashSpheres); + void SetDebugLights(bool debugLights); + bool GetDebugLights(); + void DebugDumpLights(); + protected: //! Resets some states and flushes textures after device was changed (e.g. resoulution changed) /** Instead of calling this directly, send EVENT_RESOLUTION_CHANGED event **/ @@ -1250,7 +1254,7 @@ protected: bool GetBBox2D(int objRank, Math::Point& min, Math::Point& max); //! Detects whether the mouse is in a triangle. - bool DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRank, float& dist); + bool DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRank, float& dist, Math::Vector& pos); //! Transforms a 3D point (x, y, z) in 2D space (x, y, -) of the window /** The coordinated p2D.z gives the distance. */ diff --git a/src/graphics/engine/lightning.cpp b/src/graphics/engine/lightning.cpp index 88b9d33b..18192fe5 100644 --- a/src/graphics/engine/lightning.cpp +++ b/src/graphics/engine/lightning.cpp @@ -82,16 +82,24 @@ bool CLightning::EventProcess(const Event &event) bool CLightning::EventFrame(const Event &event) { + if (m_terrain == nullptr) + m_terrain = CRobotMain::GetInstancePointer()->GetTerrain(); + + if (m_camera == nullptr) + m_camera = CRobotMain::GetInstancePointer()->GetCamera(); + + if (m_sound == nullptr) + m_sound = CApplication::GetInstancePointer()->GetSound(); + if (m_engine->GetPause()) return true; if (CRobotMain::GetInstancePointer()->GetMovieLock()) return true; m_progress += event.rTime*m_speed; - if (m_phase == LightningPhase::Wait) + if (m_phase == LightningPhase::Wait && m_lightningExists) { if (m_progress >= 1.0f) { - m_pos.x = (Math::Rand()-0.5f)*(3200.0f-200.0f); m_pos.z = (Math::Rand()-0.5f)*(3200.0f-200.0f); m_pos.y = 0.0f; @@ -127,21 +135,7 @@ bool CLightning::EventFrame(const Event &event) } } - Math::Vector eye = m_engine->GetEyePt(); - float dist = Math::Distance(m_pos, eye); - float deep = m_engine->GetDeepView(); - - if (dist < deep) - { - Math::Vector pos = eye+((m_pos-eye)*0.2f); // like so close! - m_sound->Play(SOUND_BLITZ, pos); - - m_camera->StartOver(CAM_OVER_EFFECT_LIGHTNING, m_pos, 1.0f); - - m_phase = LightningPhase::Flash; - m_progress = 0.0f; - m_speed = 1.0f; - } + StrikeAtPos(m_pos); } } @@ -193,15 +187,6 @@ bool CLightning::Create(float sleep, float delay, float magnetic) m_progress = 0.0f; m_speed = 1.0f / m_sleep; - if (m_terrain == nullptr) - m_terrain = CRobotMain::GetInstancePointer()->GetTerrain(); - - if (m_camera == nullptr) - m_camera = CRobotMain::GetInstancePointer()->GetCamera(); - - if (m_sound == nullptr) - m_sound = CApplication::GetInstancePointer()->GetSound(); - return false; } @@ -233,7 +218,6 @@ bool CLightning::SetStatus(float sleep, float delay, float magnetic, float progr void CLightning::Draw() { - if (!m_lightningExists) return; if (m_phase != LightningPhase::Flash) return; CDevice* device = m_engine->GetDevice(); @@ -368,4 +352,25 @@ CObject* CLightning::SearchObject(Math::Vector pos) } +void CLightning::StrikeAtPos(Math::Vector pos) +{ + m_pos = pos; + + Math::Vector eye = m_engine->GetEyePt(); + float dist = Math::Distance(m_pos, eye); + float deep = m_engine->GetDeepView(); + + if (dist < deep) + { + Math::Vector pos = eye+((m_pos-eye)*0.2f); // like so close! + m_sound->Play(SOUND_BLITZ, pos); + + m_camera->StartOver(CAM_OVER_EFFECT_LIGHTNING, m_pos, 1.0f); + + m_phase = LightningPhase::Flash; + m_progress = 0.0f; + m_speed = 1.0f; + } +} + } // namespace Gfx diff --git a/src/graphics/engine/lightning.h b/src/graphics/engine/lightning.h index 57cc6f58..505a7cf6 100644 --- a/src/graphics/engine/lightning.h +++ b/src/graphics/engine/lightning.h @@ -75,6 +75,9 @@ public: //! Draws lightning void Draw(); + //! Shoots lightning strike at given position + void StrikeAtPos(Math::Vector pos); + protected: //! Updates lightning bool EventFrame(const Event &event); diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index 80e593b3..69b27e37 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -3724,12 +3724,4 @@ Color CParticle::GetFogColor(Math::Vector pos) return result; } -bool CParticle::WriteWheelTrace(const char *filename, int width, int height, - Math::Vector dl, Math::Vector ur) -{ - // TODO: stub! - GetLogger()->Trace("CParticle::WriteWheelTrace(): stub!\n"); - return true; -} - } // namespace Gfx diff --git a/src/graphics/engine/particle.h b/src/graphics/engine/particle.h index 676a21b4..5279009a 100644 --- a/src/graphics/engine/particle.h +++ b/src/graphics/engine/particle.h @@ -291,9 +291,6 @@ public: //! Draws all the particles void DrawParticle(int sheet); - //! Writes a file containing all the tire tracks - bool WriteWheelTrace(const char *filename, int width, int height, Math::Vector dl, Math::Vector ur); - protected: //! Removes a particle of given rank void DeleteRank(int rank); diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 1d51b59d..c410e31c 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -86,6 +86,7 @@ #include "sound/sound.h" +#include "ui/debug_menu.h" #include "ui/displayinfo.h" #include "ui/displaytext.h" #include "ui/maindialog.h" @@ -162,6 +163,8 @@ CRobotMain::CRobotMain() m_modelManager.get(), m_particle); + m_debugMenu = MakeUnique(this, m_engine, m_objMan.get(), m_sound); + m_time = 0.0f; m_gameTime = 0.0f; m_gameTimeAbsolute = 0.0f; @@ -650,6 +653,12 @@ Phase CRobotMain::GetPhase() bool CRobotMain::ProcessEvent(Event &event) { if (!m_ui->EventProcess(event)) return false; + if (m_phase == PHASE_SIMUL) + { + if (!m_editFull) + m_camera->EventProcess(event); + } + if (!m_debugMenu->EventProcess(event)) return false; if (event.type == EVENT_FRAME) { @@ -763,6 +772,15 @@ bool CRobotMain::ProcessEvent(Event &event) } return false; } + + if (IsPhaseWithWorld(m_phase)) + { + if (data->key == KEY(F11)) + { + m_debugMenu->ToggleInterface(); + return false; + } + } } if (event.type == EVENT_KEY_DOWN && @@ -830,9 +848,6 @@ bool CRobotMain::ProcessEvent(Event &event) // Simulation phase of the game if (m_phase == PHASE_SIMUL) { - if (!m_editFull) - m_camera->EventProcess(event); - switch (event.type) { case EVENT_KEY_DOWN: @@ -841,11 +856,6 @@ bool CRobotMain::ProcessEvent(Event &event) KeyCamera(event.type, data->slot); HiliteClear(); - if (data->key == KEY(F11)) - { - m_particle->WriteWheelTrace("Savegame/t.png", 256, 256, Math::Vector(16.0f, 0.0f, -368.0f), Math::Vector(140.0f, 0.0f, -248.0f)); - return false; - } if (m_editLock) // current edition? { if (data->slot == INPUT_SLOT_HELP) @@ -1400,16 +1410,6 @@ void CRobotMain::ExecuteCmd(const std::string& cmd) } return; } - if (cmd == "debugcrashon") - { - m_debugCrashSpheres = true; - return; - } - if (cmd == "debugcrashoff") - { - m_debugCrashSpheres = false; - return; - } } if (cmd == "debugmode") @@ -1993,7 +1993,8 @@ CObject* CRobotMain::GetSelect() //! Detects the object aimed by the mouse CObject* CRobotMain::DetectObject(Math::Point pos) { - int objRank = m_engine->DetectObject(pos); + Math::Vector p; + int objRank = m_engine->DetectObject(pos, p); for (CObject* obj : m_objMan->GetAllObjects()) { @@ -6007,3 +6008,13 @@ void CRobotMain::UpdateDebugCrashSpheres() } } } + +void CRobotMain::SetDebugCrashSpheres(bool draw) +{ + m_debugCrashSpheres = draw; +} + +bool CRobotMain::GetDebugCrashSpheres() +{ + return m_debugCrashSpheres; +} diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 079add3e..deea9e82 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -113,6 +113,7 @@ class CMainMap; class CInterface; class CDisplayText; class CDisplayInfo; +class CDebugMenu; } struct NewScriptName @@ -361,6 +362,10 @@ public: bool IsSelectable(CObject* obj); + void SetDebugCrashSpheres(bool draw); + + bool GetDebugCrashSpheres(); + protected: bool EventFrame(const Event &event); bool EventObject(const Event &event); @@ -432,6 +437,7 @@ protected: std::unique_ptr m_interface; std::unique_ptr m_displayInfo; std::unique_ptr m_displayText; + std::unique_ptr m_debugMenu; std::unique_ptr m_settings; //! Progress of loaded player diff --git a/src/ui/controls/target.cpp b/src/ui/controls/target.cpp index b42116fc..9ba4f4e0 100644 --- a/src/ui/controls/target.cpp +++ b/src/ui/controls/target.cpp @@ -135,7 +135,8 @@ bool CTarget::GetTooltip(Math::Point pos, std::string &name) CObject* CTarget::DetectFriendObject(Math::Point pos) { - int objRank = m_engine->DetectObject(pos); + Math::Vector p; + int objRank = m_engine->DetectObject(pos, p); for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { diff --git a/src/ui/debug_menu.cpp b/src/ui/debug_menu.cpp new file mode 100644 index 00000000..2c98371f --- /dev/null +++ b/src/ui/debug_menu.cpp @@ -0,0 +1,400 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + +#include "ui/debug_menu.h" + +#include "common/event.h" + +#include "graphics/engine/lightning.h" +#include "graphics/engine/terrain.h" + +#include "level/robotmain.h" + +#include "object/object_create_params.h" +#include "object/object_manager.h" +#include "object/object.h" + +#include "ui/controls/interface.h" +#include "ui/controls/window.h" +#include "ui/controls/check.h" +#include "ui/controls/button.h" + +namespace Ui +{ + +CDebugMenu::CDebugMenu(CRobotMain* main, Gfx::CEngine* engine, CObjectManager* objMan, CSoundInterface* sound) +{ + m_main = main; + m_interface = m_main->GetInterface(); + m_engine = engine; + m_objMan = objMan; + m_sound = sound; +} + +CDebugMenu::~CDebugMenu() +{ + +} + +void CDebugMenu::ToggleInterface() +{ + if (m_interface->SearchControl(EVENT_WINDOW7) == nullptr) + CreateInterface(); + else + DestroyInterface(); +} + +const Math::Point dim = Math::Point(33.0f/640.0f, 33.0f/480.0f); +const float ox = 3.0f/640.0f, oy = 3.0f/480.0f; +const float sx = 33.0f/640.0f, sy = 33.0f/480.0f; + +void CDebugMenu::CreateInterface() +{ + CWindow* pw = m_interface->CreateWindows(Math::Point(), Math::Point(), 0, EVENT_WINDOW7); + Math::Point pos, ddim; + CCheck* pc; + CButton* pb; + + ddim.x = 4*dim.x+4*ox; + ddim.y = 222.0f/480.0f; + pos.x = 1.0f-ddim.x; + pos.y = oy+sy*3.0f; + pw->CreateGroup(pos, ddim, 6, EVENT_WINDOW7); + + ddim.x = ddim.x - 4*ox; + ddim.y = dim.y*0.5f; + pos.x += 2*ox; + pos.y = oy+sy*9.0f; + pb = pw->CreateButton(pos, ddim, -1, EVENT_DBG_SPAWN_OBJ); + pb->SetName("Spawn object"); + pos.y -= ddim.y; + pb = pw->CreateButton(pos, ddim, -1, EVENT_DBG_TELEPORT); + pb->SetName("Teleport"); + pos.y -= ddim.y; + pb = pw->CreateButton(pos, ddim, -1, EVENT_DBG_LIGHTNING); + pb->SetName("Lightning"); + pos.y -= 0.048f; + pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_STATS); + pc->SetName("Display stats"); + pos.y -= 0.048f; + pos.y -= 0.048f; + pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_CRASHSPHERES); + pc->SetName("Render crash spheres"); + pos.y -= 0.048f; + pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_LIGHTS); + pc->SetName("Render dynamic lights"); + pos.y -= 0.048f; + pb = pw->CreateButton(pos, ddim, -1, EVENT_DBG_LIGHTS_DUMP); + pb->SetName("Dump lights to log"); + + UpdateInterface(); +} + +void CDebugMenu::CreateSpawnInterface() +{ + CWindow* pw = m_interface->CreateWindows(Math::Point(), Math::Point(), 0, EVENT_WINDOW7); + Math::Point pos, ddim; + CButton* pb; + + ddim.x = 4*dim.x+4*ox; + ddim.y = 222.0f/480.0f; + pos.x = 1.0f-ddim.x; + pos.y = oy+sy*3.0f; + pw->CreateGroup(pos, ddim, 6, EVENT_WINDOW7); + + ddim.x = ddim.x - 4*ox; + ddim.y = dim.y*0.5f; + pos.x += 2*ox; + pos.y = oy+sy*9.0f; + pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_CANCEL); + pb->SetName("Cancel"); + + pos.y -= dim.y; + pw->CreateButton(pos, dim, 128+8, EVENT_SPAWN_ME); + pos.x += dim.x; + pw->CreateButton(pos, dim, 128+9, EVENT_SPAWN_WHEELEDGRABBER); + pos.x += dim.x; + pw->CreateButton(pos, dim, 128+15, EVENT_SPAWN_WHEELEDSHOOTER); + pos.x += dim.x; + pw->CreateButton(pos, dim, 128+19, EVENT_SPAWN_PHAZERSHOOTER); + pos.x -= 3*dim.x; + pos.y -= dim.y; + pw->CreateButton(pos, dim, 128+32, EVENT_SPAWN_BOTFACTORY); + pos.x += dim.x; + pw->CreateButton(pos, dim, 128+34, EVENT_SPAWN_CONVERTER); + pos.x += dim.x; + pw->CreateButton(pos, dim, 128+33, EVENT_SPAWN_DERRICK); + pos.x += dim.x; + pw->CreateButton(pos, dim, 128+36, EVENT_SPAWN_POWERSTATION); + pos.x -= 3*dim.x; + pos.y -= ddim.y; + pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_TITANIUM); + pb->SetName("Titanium"); + pos.y -= ddim.y; + pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_TITANIUMORE); + pb->SetName("TitaniumOre"); + pos.y -= ddim.y; + pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_URANIUMORE); + pb->SetName("UraniumOre"); + pos.y -= ddim.y; + pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_POWERCELL); + pb->SetName("PowerCell"); + pos.y -= ddim.y; + pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_NUCLEARCELL); + pb->SetName("NuclearCell"); +} + +const std::map SPAWN_TYPES = { + {EVENT_SPAWN_ME, OBJECT_HUMAN}, + {EVENT_SPAWN_WHEELEDGRABBER, OBJECT_MOBILEwa}, + {EVENT_SPAWN_WHEELEDSHOOTER, OBJECT_MOBILEwc}, + {EVENT_SPAWN_PHAZERSHOOTER, OBJECT_MOBILErc}, + {EVENT_SPAWN_BOTFACTORY, OBJECT_FACTORY}, + {EVENT_SPAWN_CONVERTER, OBJECT_CONVERT}, + {EVENT_SPAWN_DERRICK, OBJECT_DERRICK}, + {EVENT_SPAWN_POWERSTATION, OBJECT_STATION}, + {EVENT_SPAWN_TITANIUM, OBJECT_METAL}, + {EVENT_SPAWN_TITANIUMORE, OBJECT_STONE}, + {EVENT_SPAWN_URANIUMORE, OBJECT_URANIUM}, + {EVENT_SPAWN_POWERCELL, OBJECT_POWER}, + {EVENT_SPAWN_NUCLEARCELL, OBJECT_ATOMIC}, +}; + +void CDebugMenu::UpdateInterface() +{ + CCheck* pc; + CButton* pb; + + CWindow* pw = static_cast(m_interface->SearchControl(EVENT_WINDOW7)); + if (pw == nullptr) return; + + + pb = static_cast(pw->SearchControl(EVENT_DBG_LIGHTNING)); + if (pb != nullptr) + { + pb->SetName(m_lightningActive ? "Disable lightning" : "Lightning"); + } + + pb = static_cast(pw->SearchControl(EVENT_DBG_TELEPORT)); + if (pb != nullptr) + { + pb->SetName(m_teleportActive ? "Abort teleport" : "Teleport"); + } + + pc = static_cast(pw->SearchControl(EVENT_DBG_STATS)); + if (pc != nullptr) + { + pc->SetState(STATE_CHECK, m_engine->GetShowStats()); + } + + pc = static_cast(pw->SearchControl(EVENT_DBG_CRASHSPHERES)); + if (pc != nullptr) + { + pc->SetState(STATE_CHECK, m_main->GetDebugCrashSpheres()); + } + + pc = static_cast(pw->SearchControl(EVENT_DBG_LIGHTS)); + if (pc != nullptr) + { + pc->SetState(STATE_CHECK, m_engine->GetDebugLights()); + } + + for (const auto& it : SPAWN_TYPES) + { + pb = static_cast(pw->SearchControl(it.first)); + if (pb != nullptr) + { + pb->SetState(STATE_ENABLE, it.second != m_spawningType); + } + } +} + +void CDebugMenu::DestroyInterface() +{ + m_interface->DeleteControl(EVENT_WINDOW7); + m_spawningType = OBJECT_NULL; +} + +bool CDebugMenu::EventProcess(const Event &event) +{ + switch (event.type) + { + case EVENT_DBG_STATS: + m_engine->SetShowStats(!m_engine->GetShowStats()); + UpdateInterface(); + break; + + case EVENT_DBG_SPAWN_OBJ: + DestroyInterface(); + CreateSpawnInterface(); + break; + + case EVENT_DBG_TELEPORT: + if (!m_teleportActive) + { + if (m_main->GetSelect() != nullptr) + m_teleportActive = true; + else + m_sound->Play(SOUND_CLICK); + } + else + { + m_teleportActive = false; + } + UpdateInterface(); + break; + + case EVENT_DBG_LIGHTNING: + m_lightningActive = !m_lightningActive; + UpdateInterface(); + break; + + case EVENT_DBG_CRASHSPHERES: + m_main->SetDebugCrashSpheres(!m_main->GetDebugCrashSpheres()); + UpdateInterface(); + break; + + case EVENT_DBG_LIGHTS: + m_engine->SetDebugLights(!m_engine->GetDebugLights()); + UpdateInterface(); + break; + + case EVENT_DBG_LIGHTS_DUMP: + m_engine->DebugDumpLights(); + break; + + + case EVENT_SPAWN_CANCEL: + DestroyInterface(); + CreateInterface(); + break; + + case EVENT_SPAWN_ME: + case EVENT_SPAWN_WHEELEDGRABBER: + case EVENT_SPAWN_WHEELEDSHOOTER: + case EVENT_SPAWN_PHAZERSHOOTER: + case EVENT_SPAWN_BOTFACTORY: + case EVENT_SPAWN_CONVERTER: + case EVENT_SPAWN_DERRICK: + case EVENT_SPAWN_POWERSTATION: + case EVENT_SPAWN_TITANIUM: + case EVENT_SPAWN_TITANIUMORE: + case EVENT_SPAWN_URANIUMORE: + case EVENT_SPAWN_POWERCELL: + case EVENT_SPAWN_NUCLEARCELL: + m_spawningType = SPAWN_TYPES.at(event.type); + UpdateInterface(); + break; + + case EVENT_MOUSE_BUTTON_DOWN: + if (event.GetData()->button == MOUSE_BUTTON_LEFT) + { + if (m_lightningActive) + { + return !HandleLightning(event.mousePos); + } + + if (m_teleportActive) + { + return !HandleTeleport(event.mousePos); + } + + if (m_spawningType != OBJECT_NULL) + { + return !HandleSpawnObject(m_spawningType, event.mousePos); + } + } + break; + + case EVENT_MOUSE_MOVE: + if (m_spawningType != OBJECT_NULL || m_teleportActive || m_lightningActive) + { + return false; + } + break; + + + default: + break; + } + return true; +} + +bool CDebugMenu::HandleSpawnObject(ObjectType type, Math::Point mousePos) +{ + Math::Vector pos; + if (m_engine->DetectObject(mousePos, pos, true) == -1) + { + m_sound->Play(SOUND_CLICK, 1.0f, 0.5f); + return false; + } + + ObjectCreateParams params; + params.pos = pos; + params.type = type; + params.power = 100.0f; + m_objMan->CreateObject(params); + + // Update shortcuts in the upper-left corner + m_main->CreateShortcuts(); + + m_sound->Play(SOUND_RADAR, 2.0f, 1.5f); + + return true; +} + +bool CDebugMenu::HandleLightning(Math::Point mousePos) +{ + Math::Vector pos; + if (m_engine->DetectObject(mousePos, pos, true) == -1) + { + m_sound->Play(SOUND_CLICK, 1.0f, 0.5f); + return false; + } + + m_engine->GetLightning()->StrikeAtPos(pos); + + return true; +} + +bool CDebugMenu::HandleTeleport(Math::Point mousePos) +{ + CObject* select = m_main->GetSelect(); + + Math::Vector pos; + if (m_engine->DetectObject(mousePos, pos, true) == -1 || !m_engine->GetTerrain()->AdjustToFloor(pos) || select == nullptr) + { + m_sound->Play(SOUND_CLICK, 1.0f, 0.5f); + m_teleportActive = false; + UpdateInterface(); + return false; + } + + select->SetPosition(pos); + + m_sound->Play(SOUND_BUILD, 4.0f, 0.75f); + m_sound->Play(SOUND_BUILD, pos, 4.0f, 0.75f); + + m_teleportActive = false; + UpdateInterface(); + + return true; +} + +} \ No newline at end of file diff --git a/src/ui/debug_menu.h b/src/ui/debug_menu.h new file mode 100644 index 00000000..2fb4b9de --- /dev/null +++ b/src/ui/debug_menu.h @@ -0,0 +1,70 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + +#pragma once + +#include +#include +#include "object/object_type.h" + +class CRobotMain; +class CObjectManager; +struct Event; + +namespace Gfx +{ +class CEngine; +} + +namespace Ui +{ +class CInterface; + +class CDebugMenu +{ +public: + CDebugMenu(CRobotMain* main, Gfx::CEngine* engine, CObjectManager* objMan, CSoundInterface* sound); + virtual ~CDebugMenu(); + + void ToggleInterface(); + bool EventProcess(const Event& event); + +protected: + void CreateInterface(); + void CreateSpawnInterface(); + void UpdateInterface(); + void DestroyInterface(); + + bool HandleSpawnObject(ObjectType type, Math::Point mousePos); + bool HandleLightning(Math::Point mousePos); + bool HandleTeleport(Math::Point mousePos); + +protected: + CRobotMain* m_main; + CInterface* m_interface; + Gfx::CEngine* m_engine; + CObjectManager* m_objMan; + CSoundInterface* m_sound; + + ObjectType m_spawningType = OBJECT_NULL; + bool m_lightningActive = false; + bool m_teleportActive = false; +}; + +} From e4f9360e63fcd7ee66dc942a927b0ac799d1d3e2 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 28 Mar 2016 17:57:41 +0200 Subject: [PATCH 016/125] Resources debug mode --- src/common/event.h | 7 ++++--- src/graphics/engine/engine.cpp | 37 ++++++++++++++++++++++++++++++++- src/graphics/engine/engine.h | 4 ++++ src/graphics/engine/terrain.cpp | 36 +++++++++++++++++++------------- src/graphics/engine/terrain.h | 2 ++ src/ui/debug_menu.cpp | 15 +++++++++++++ 6 files changed, 82 insertions(+), 19 deletions(-) diff --git a/src/common/event.h b/src/common/event.h index d1b851c9..c5fe1f5c 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -384,9 +384,10 @@ enum EventType EVENT_DBG_SPAWN_OBJ = 851, EVENT_DBG_TELEPORT = 852, EVENT_DBG_LIGHTNING = 853, - EVENT_DBG_CRASHSPHERES = 854, - EVENT_DBG_LIGHTS = 855, - EVENT_DBG_LIGHTS_DUMP = 856, + EVENT_DBG_RESOURCES = 854, + EVENT_DBG_CRASHSPHERES = 855, + EVENT_DBG_LIGHTS = 856, + EVENT_DBG_LIGHTS_DUMP = 857, EVENT_SPAWN_CANCEL = 860, EVENT_SPAWN_ME = 861, diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 4ab66f3d..e3e3431e 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -3971,7 +3971,7 @@ void CEngine::UpdateGroundSpotTextures() set = true; } - if (clear || set) + if (clear || set || m_debugResources) { CImage shadowImg(Math::IntPoint(256, 256)); shadowImg.Fill(Gfx::IntColor(255, 255, 255, 255)); @@ -4131,6 +4131,29 @@ void CEngine::UpdateGroundSpotTextures() } } + if (m_debugResources) + { + for (float x = min.x; x < max.x; x += 1.0f) + { + for (float y = min.y; y < max.y; y += 1.0f) + { + Math::Vector pos( + x / 4.0f / 254.0f * 3200.0f - 1600.0f, + 0.0f, + y / 4.0f / 254.0f * 3200.0f - 1600.0f + ); + TerrainRes res = m_terrain->GetResource(pos); + Math::IntPoint p(x-min.x, y-min.y); + if (res == TR_NULL) + { + shadowImg.SetPixel(p, Gfx::Color(0.5f, 0.5f, 0.5f)); + continue; + } + shadowImg.SetPixelInt(p, ResourceToColor(res)); + } + } + } + std::stringstream str; str << "textures/shadow" << std::setfill('0') << std::setw(2) << s << ".png"; std::string texName = str.str(); @@ -5094,4 +5117,16 @@ void CEngine::DebugDumpLights() m_debugDumpLights = true; } +void CEngine::SetDebugResources(bool debugResources) +{ + m_debugResources = debugResources; + m_firstGroundSpot = true; // Force a refresh of ground spot textures + UpdateGroundSpotTextures(); +} + +bool CEngine::GetDebugResources() +{ + return m_debugResources; +} + } // namespace Gfx diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index ba1b1718..f95bdf33 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -1188,6 +1188,9 @@ public: bool GetDebugLights(); void DebugDumpLights(); + void SetDebugResources(bool debugResources); + bool GetDebugResources(); + protected: //! Resets some states and flushes textures after device was changed (e.g. resoulution changed) /** Instead of calling this directly, send EVENT_RESOLUTION_CHANGED event **/ @@ -1478,6 +1481,7 @@ protected: bool m_debugLights; bool m_debugDumpLights; bool m_debugCrashSpheres = false; + bool m_debugResources = false; std::string m_timerText; diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index 8475a8a4..7ff24172 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -192,6 +192,22 @@ void CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point } +// values from original bitmap palette +const std::map RESOURCE_PALETTE = { + {TR_STONE, Gfx::IntColor(255, 0, 0)}, + {TR_URANIUM, Gfx::IntColor(255, 255, 0)}, + {TR_POWER, Gfx::IntColor( 0, 255, 0)}, + {TR_KEY_A, Gfx::IntColor( 0, 204, 0)}, + {TR_KEY_B, Gfx::IntColor( 51, 204, 0)}, + {TR_KEY_C, Gfx::IntColor(102, 204, 0)}, + {TR_KEY_D, Gfx::IntColor(153, 204, 0)} +}; + +Gfx::IntColor ResourceToColor(TerrainRes res) +{ + return RESOURCE_PALETTE.at(res); +} + /** * The image must be 24 bits/pixel and grayscale and dx x dy in size * with dx = dy = (mosaic*brick)+1 */ @@ -224,21 +240,11 @@ bool CTerrain::LoadResources(const std::string& fileName) Gfx::IntColor pixel = img.GetPixelInt(Math::IntPoint(x, size - y - 1)); TerrainRes res = TR_NULL; - // values from original bitmap palette - if (pixel.r == 255 && pixel.g == 0 && pixel.b == 0) - res = TR_STONE; - else if (pixel.r == 255 && pixel.g == 255 && pixel.b == 0) - res = TR_URANIUM; - else if (pixel.r == 0 && pixel.g == 255 && pixel.b == 0) - res = TR_POWER; - else if (pixel.r == 0 && pixel.g == 204 && pixel.b == 0) - res = TR_KEY_A; - else if (pixel.r == 51 && pixel.g == 204 && pixel.b == 0) - res = TR_KEY_B; - else if (pixel.r == 102 && pixel.g == 204 && pixel.b == 0) - res = TR_KEY_C; - else if (pixel.r == 153 && pixel.g == 204 && pixel.b == 0) - res = TR_KEY_D; + for (const auto& it : RESOURCE_PALETTE) + { + if (pixel.r == it.second.r && pixel.g == it.second.g && pixel.b == it.second.b) + res = it.first; + } m_resources[x+size*y] = static_cast(res); } diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h index 7f66f726..9a86b584 100644 --- a/src/graphics/engine/terrain.h +++ b/src/graphics/engine/terrain.h @@ -69,6 +69,8 @@ enum TerrainRes TR_KEY_D = 7 //@} }; +//! Converts TerrainRes to color +Gfx::IntColor ResourceToColor(TerrainRes res); /** * \class CTerrain diff --git a/src/ui/debug_menu.cpp b/src/ui/debug_menu.cpp index 2c98371f..7d8ae152 100644 --- a/src/ui/debug_menu.cpp +++ b/src/ui/debug_menu.cpp @@ -94,6 +94,9 @@ void CDebugMenu::CreateInterface() pc->SetName("Display stats"); pos.y -= 0.048f; pos.y -= 0.048f; + pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_RESOURCES); + pc->SetName("Underground resources"); + pos.y -= 0.048f; pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_CRASHSPHERES); pc->SetName("Render crash spheres"); pos.y -= 0.048f; @@ -124,6 +127,7 @@ void CDebugMenu::CreateSpawnInterface() pos.y = oy+sy*9.0f; pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_CANCEL); pb->SetName("Cancel"); + pos.y -= ddim.y; pos.y -= dim.y; pw->CreateButton(pos, dim, 128+8, EVENT_SPAWN_ME); @@ -203,6 +207,12 @@ void CDebugMenu::UpdateInterface() pc->SetState(STATE_CHECK, m_engine->GetShowStats()); } + pc = static_cast(pw->SearchControl(EVENT_DBG_RESOURCES)); + if (pc != nullptr) + { + pc->SetState(STATE_CHECK, m_engine->GetDebugResources()); + } + pc = static_cast(pw->SearchControl(EVENT_DBG_CRASHSPHERES)); if (pc != nullptr) { @@ -265,6 +275,11 @@ bool CDebugMenu::EventProcess(const Event &event) UpdateInterface(); break; + case EVENT_DBG_RESOURCES: + m_engine->SetDebugResources(!m_engine->GetDebugResources()); + UpdateInterface(); + break; + case EVENT_DBG_CRASHSPHERES: m_main->SetDebugCrashSpheres(!m_main->GetDebugCrashSpheres()); UpdateInterface(); From d38ddcbc4199fe624f9b6689127363ee7bb5693d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 28 Mar 2016 20:25:07 +0200 Subject: [PATCH 017/125] goto() path debugger --- src/common/event.h | 7 ++++--- src/graphics/engine/engine.cpp | 30 ++++++++++++++++++++++++++++++ src/graphics/engine/engine.h | 6 ++++++ src/object/task/taskgoto.cpp | 33 ++++++++++++++++++++++++++++++++- src/ui/debug_menu.cpp | 14 ++++++++++++++ 5 files changed, 86 insertions(+), 4 deletions(-) diff --git a/src/common/event.h b/src/common/event.h index c5fe1f5c..d3f22b0c 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -385,9 +385,10 @@ enum EventType EVENT_DBG_TELEPORT = 852, EVENT_DBG_LIGHTNING = 853, EVENT_DBG_RESOURCES = 854, - EVENT_DBG_CRASHSPHERES = 855, - EVENT_DBG_LIGHTS = 856, - EVENT_DBG_LIGHTS_DUMP = 857, + EVENT_DBG_GOTO = 855, + EVENT_DBG_CRASHSPHERES = 856, + EVENT_DBG_LIGHTS = 857, + EVENT_DBG_LIGHTS_DUMP = 858, EVENT_SPAWN_CANCEL = 860, EVENT_SPAWN_ME = 861, diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index e3e3431e..7d00e874 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -3378,6 +3378,21 @@ void CEngine::Draw3DScene() if (m_debugCrashSpheres) DrawCrashSpheres(); + if (m_debugGoto) + { + Math::Matrix worldMatrix; + worldMatrix.LoadIdentity(); + m_device->SetTransform(TRANSFORM_WORLD, worldMatrix); + + SetState(ENG_RSTATE_OPAQUE_COLOR); + + for (const auto& line : m_displayGoto) + { + m_device->DrawPrimitive(PRIMITIVE_LINE_STRIP, line.data(), line.size()); + } + } + m_displayGoto.clear(); + m_app->StartPerformanceCounter(PCNT_RENDER_PARTICLE); m_particle->DrawParticle(SH_WORLD); // draws the particles of the 3D world m_app->StopPerformanceCounter(PCNT_RENDER_PARTICLE); @@ -5129,4 +5144,19 @@ bool CEngine::GetDebugResources() return m_debugResources; } +void CEngine::SetDebugGoto(bool debugGoto) +{ + m_debugGoto = debugGoto; +} + +bool CEngine::GetDebugGoto() +{ + return m_debugGoto; +} + +void CEngine::AddDebugGotoLine(std::vector line) +{ + m_displayGoto.push_back(line); +} + } // namespace Gfx diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index f95bdf33..04757fc7 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -1191,6 +1191,10 @@ public: void SetDebugResources(bool debugResources); bool GetDebugResources(); + void SetDebugGoto(bool debugGoto); + bool GetDebugGoto(); + void AddDebugGotoLine(std::vector line); + protected: //! Resets some states and flushes textures after device was changed (e.g. resoulution changed) /** Instead of calling this directly, send EVENT_RESOLUTION_CHANGED event **/ @@ -1482,12 +1486,14 @@ protected: bool m_debugDumpLights; bool m_debugCrashSpheres = false; bool m_debugResources = false; + bool m_debugGoto = false; std::string m_timerText; std::unordered_map m_staticMeshBaseObjects; std::vector m_displayCrashSpheres; + std::vector> m_displayGoto; //! Pause the animation updates bool m_pause = false; diff --git a/src/object/task/taskgoto.cpp b/src/object/task/taskgoto.cpp index d7e36cd7..7a6c754e 100644 --- a/src/object/task/taskgoto.cpp +++ b/src/object/task/taskgoto.cpp @@ -77,9 +77,38 @@ bool CTaskGoto::EventProcess(const Event &event) float a, g, dist, linSpeed, cirSpeed, h, hh, factor, dir; Error ret; - if ( m_engine->GetPause() ) return true; if ( event.type != EVENT_FRAME ) return true; + if (m_engine->GetDebugGoto()) + { + auto AdjustPoint = [&](Math::Vector p) -> Math::Vector + { + m_terrain->AdjustToFloor(p); + p.y += 2.0f; + return p; + }; + + std::vector debugLine; + if (m_bmTotal > 0) + { + Gfx::Color color = Gfx::Color(0.0f, 1.0f, 0.0f); + for (int i = 0; i < m_bmTotal; i++) + { + if (i > m_bmIndex-1) + color = Gfx::Color(1.0f, 0.0f, 0.0f); + debugLine.push_back(Gfx::VertexCol(AdjustPoint(m_bmPoints[i]), color)); + } + m_engine->AddDebugGotoLine(debugLine); + debugLine.clear(); + } + Gfx::Color color = Gfx::Color(0.0f, 0.0f, 1.0f); + debugLine.push_back(Gfx::VertexCol(m_object->GetPosition(), color)); + debugLine.push_back(Gfx::VertexCol(AdjustPoint(m_bmTotal > 0 && m_bmIndex <= m_bmTotal && m_phase != TGP_BEAMSEARCH ? m_bmPoints[m_bmIndex] : m_goal), color)); + m_engine->AddDebugGotoLine(debugLine); + } + + if ( m_engine->GetPause() ) return true; + // Momentarily stationary object (ant on the back)? CBaseAlien* alien = dynamic_cast(m_object); if ( alien != nullptr && alien->GetFixed() ) @@ -1616,6 +1645,8 @@ Error CTaskGoto::BeamExplore(const Math::Vector &prevPos, const Math::Vector &cu iLar = 0; if ( i >= MAXPOINTS ) return ERR_GOTO_ITER; // too many recursions + m_bmTotal = i; + if ( m_bmIter[i] == -1 ) { m_bmIter[i] = 0; diff --git a/src/ui/debug_menu.cpp b/src/ui/debug_menu.cpp index 7d8ae152..88e62c10 100644 --- a/src/ui/debug_menu.cpp +++ b/src/ui/debug_menu.cpp @@ -97,6 +97,9 @@ void CDebugMenu::CreateInterface() pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_RESOURCES); pc->SetName("Underground resources"); pos.y -= 0.048f; + pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_GOTO); + pc->SetName("Render goto() path"); + pos.y -= 0.048f; pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_CRASHSPHERES); pc->SetName("Render crash spheres"); pos.y -= 0.048f; @@ -213,6 +216,12 @@ void CDebugMenu::UpdateInterface() pc->SetState(STATE_CHECK, m_engine->GetDebugResources()); } + pc = static_cast(pw->SearchControl(EVENT_DBG_GOTO)); + if (pc != nullptr) + { + pc->SetState(STATE_CHECK, m_engine->GetDebugGoto()); + } + pc = static_cast(pw->SearchControl(EVENT_DBG_CRASHSPHERES)); if (pc != nullptr) { @@ -280,6 +289,11 @@ bool CDebugMenu::EventProcess(const Event &event) UpdateInterface(); break; + case EVENT_DBG_GOTO: + m_engine->SetDebugGoto(!m_engine->GetDebugGoto()); + UpdateInterface(); + break; + case EVENT_DBG_CRASHSPHERES: m_main->SetDebugCrashSpheres(!m_main->GetDebugCrashSpheres()); UpdateInterface(); From e24d77bde87b20b8a4d02e8c0871d8c6748d3bc2 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 28 Mar 2016 21:42:25 +0200 Subject: [PATCH 018/125] goto() bitmap debugger --- src/graphics/engine/engine.cpp | 27 ++++++++++++++++++++++++++- src/graphics/engine/engine.h | 2 ++ src/object/task/taskgoto.cpp | 33 +++++++++++++++++++++++++++++++++ src/object/task/taskgoto.h | 1 + 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 7d00e874..5b2fc6e5 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -3986,7 +3986,7 @@ void CEngine::UpdateGroundSpotTextures() set = true; } - if (clear || set || m_debugResources) + if (clear || set || m_debugResources || m_displayGotoImage != nullptr) { CImage shadowImg(Math::IntPoint(256, 256)); shadowImg.Fill(Gfx::IntColor(255, 255, 255, 255)); @@ -4169,6 +4169,20 @@ void CEngine::UpdateGroundSpotTextures() } } + if (m_displayGotoImage != nullptr) + { + Math::IntPoint size = m_displayGotoImage->GetSize(); + for (float x = min.x; x < max.x; x += 1.0f) + { + for (float y = min.y; y < max.y; y += 1.0f) + { + int px = x / 4.0f / 254.0f * size.x; + int py = y / 4.0f / 254.0f * size.y; + shadowImg.SetPixelInt(Math::IntPoint(x-min.x, y-min.y), m_displayGotoImage->GetPixelInt(Math::IntPoint(px, py))); + } + } + } + std::stringstream str; str << "textures/shadow" << std::setfill('0') << std::setw(2) << s << ".png"; std::string texName = str.str(); @@ -5147,6 +5161,10 @@ bool CEngine::GetDebugResources() void CEngine::SetDebugGoto(bool debugGoto) { m_debugGoto = debugGoto; + if (!m_debugGoto) + { + m_displayGotoImage.reset(); + } } bool CEngine::GetDebugGoto() @@ -5159,4 +5177,11 @@ void CEngine::AddDebugGotoLine(std::vector line) m_displayGoto.push_back(line); } +void CEngine::SetDebugGotoBitmap(std::unique_ptr debugImage) +{ + m_displayGotoImage = std::move(debugImage); + m_firstGroundSpot = true; // Force ground spot texture reload + UpdateGroundSpotTextures(); +} + } // namespace Gfx diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 04757fc7..a64b8c3c 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -1194,6 +1194,7 @@ public: void SetDebugGoto(bool debugGoto); bool GetDebugGoto(); void AddDebugGotoLine(std::vector line); + void SetDebugGotoBitmap(std::unique_ptr debugImage); protected: //! Resets some states and flushes textures after device was changed (e.g. resoulution changed) @@ -1494,6 +1495,7 @@ protected: std::vector m_displayCrashSpheres; std::vector> m_displayGoto; + std::unique_ptr m_displayGotoImage; //! Pause the animation updates bool m_pause = false; diff --git a/src/object/task/taskgoto.cpp b/src/object/task/taskgoto.cpp index 7a6c754e..de37d1a1 100644 --- a/src/object/task/taskgoto.cpp +++ b/src/object/task/taskgoto.cpp @@ -22,6 +22,7 @@ #include "common/event.h" #include "common/global.h" +#include "common/image.h" #include "common/make_unique.h" #include "graphics/engine/terrain.h" @@ -65,6 +66,9 @@ CTaskGoto::CTaskGoto(COldObject* object) : CForegroundTask(object) CTaskGoto::~CTaskGoto() { BitmapClose(); + + if (m_engine->GetDebugGoto() && m_object->GetSelect()) + m_engine->SetDebugGotoBitmap(std::move(nullptr)); } @@ -105,6 +109,31 @@ bool CTaskGoto::EventProcess(const Event &event) debugLine.push_back(Gfx::VertexCol(m_object->GetPosition(), color)); debugLine.push_back(Gfx::VertexCol(AdjustPoint(m_bmTotal > 0 && m_bmIndex <= m_bmTotal && m_phase != TGP_BEAMSEARCH ? m_bmPoints[m_bmIndex] : m_goal), color)); m_engine->AddDebugGotoLine(debugLine); + + if (m_object->GetSelect() && m_bmChanged) + { + if (m_bmArray != nullptr) + { + std::unique_ptr debugImage = MakeUnique(Math::IntPoint(m_bmSize, m_bmSize)); + debugImage->Fill(Gfx::IntColor(255, 255, 255, 255)); + for (int x = 0; x < m_bmSize; x++) + { + for (int y = 0; y < m_bmSize; y++) + { + bool a = BitmapTestDot(0, x, y); + bool b = BitmapTestDot(1, x, y); + if (a || b) + { + Gfx::Color c = Gfx::Color(0.0f, 0.0f, 0.0f, 1.0f); + if (b) c = Gfx::Color(0.0f, 0.0f, 1.0f, 1.0f); + debugImage->SetPixel(Math::IntPoint(x, y), c); + } + } + } + m_engine->SetDebugGotoBitmap(std::move(debugImage)); + } + m_bmChanged = false; + } } if ( m_engine->GetPause() ) return true; @@ -2001,6 +2030,7 @@ bool CTaskGoto::BitmapOpen() m_bmSize = static_cast(3200.0f/BM_DIM_STEP); m_bmArray = MakeUniqueArray(m_bmSize*m_bmSize/8*2); + m_bmChanged = true; m_bmOffset = m_bmSize/2; m_bmLine = m_bmSize/8; @@ -2018,6 +2048,7 @@ bool CTaskGoto::BitmapOpen() bool CTaskGoto::BitmapClose() { m_bmArray.reset(); + m_bmChanged = true; return true; } @@ -2074,6 +2105,7 @@ void CTaskGoto::BitmapSetDot(int rank, int x, int y) y < 0 || y >= m_bmSize ) return; m_bmArray[rank*m_bmLine*m_bmSize + m_bmLine*y + x/8] |= (1<= m_bmSize ) return; m_bmArray[rank*m_bmLine*m_bmSize + m_bmLine*y + x/8] &= ~(1< Date: Mon, 28 Mar 2016 23:04:24 +0200 Subject: [PATCH 019/125] Changed CParticle::CheckChannel log message --- src/graphics/engine/particle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index 69b27e37..e9aa0ab4 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -647,13 +647,13 @@ bool CParticle::CheckChannel(int &channel) if (!m_particle[channel].used) { - GetLogger()->Error("CheckChannel used=false !\n"); + GetLogger()->Error("CParticle::CheckChannel used=false !\n"); return false; } if (m_particle[channel].uniqueStamp != uniqueStamp) { - GetLogger()->Error("CheckChannel uniqueStamp !\n"); + GetLogger()->Error("CParticle::CheckChannel uniqueStamp !\n"); return false; } From 1c5f47703bca1ae3d4f2f6df77706bdd482c1ab9 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 29 Mar 2016 16:08:20 +0200 Subject: [PATCH 020/125] Post-release 0.1.7-alpha --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f4510bb..9de7ae93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,9 +16,9 @@ set(COLOBOT_VERSION_MINOR 1) set(COLOBOT_VERSION_REVISION 7) # Used on official releases -set(COLOBOT_VERSION_RELEASE_CODENAME "-alpha") +#set(COLOBOT_VERSION_RELEASE_CODENAME "-alpha") # Used on unreleased, development builds -#set(COLOBOT_VERSION_UNRELEASED "+alpha") +set(COLOBOT_VERSION_UNRELEASED "+alpha") # Append git characteristics to version if(DEFINED COLOBOT_VERSION_UNRELEASED) From 2ea453f484c75c9146296d904785c42e775fbe65 Mon Sep 17 00:00:00 2001 From: Krzysztof Dermont Date: Tue, 29 Mar 2016 21:36:33 +0200 Subject: [PATCH 021/125] Change SatCom button size in main menu Change button size as proposed in issue #722 --- src/ui/screen/screen_main_menu.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ui/screen/screen_main_menu.cpp b/src/ui/screen/screen_main_menu.cpp index fa016a3d..ea8a29c2 100644 --- a/src/ui/screen/screen_main_menu.cpp +++ b/src/ui/screen/screen_main_menu.cpp @@ -163,9 +163,11 @@ void CScreenMainMenu::CreateInterface() pl->SetFontSize(Gfx::FONT_SIZE_SMALL); // SatCom button - pos.x = ox+sx*4.4f; - pos.y = oy+sy*4.4f; - pb = pw->CreateButton(pos, dim, 128+60, EVENT_INTERFACE_SATCOM); + pos.x = ox+sx*4.3f; + pos.y = oy+sy*4.3f; + ddim.x = dim.x*1.2f; + ddim.y = dim.y*1.2f; + pb = pw->CreateButton(pos, ddim, 128+60, EVENT_INTERFACE_SATCOM); pb->SetState(STATE_SHADOW); SetBackground("textures/interface/interface.png"); From 8ccad5b954e9a11a0ccf4ffad8e12aa7023706c3 Mon Sep 17 00:00:00 2001 From: Krzysztof Dermont Date: Tue, 29 Mar 2016 22:29:24 +0200 Subject: [PATCH 022/125] Deactive pause before jumping to next visit When pause was active setting new pause resulted in strange behavior. This should fix issue #736. --- src/level/robotmain.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index c410e31c..9506fcaf 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -1631,6 +1631,12 @@ void CRobotMain::StartDisplayVisit(EventType event) { if (m_editLock) return; + if (m_visitPause) + { + m_pause->DeactivatePause(m_visitPause); + m_visitPause = nullptr; + } + Ui::CWindow* pw = static_cast(m_interface->SearchControl(EVENT_WINDOW2)); if (pw == nullptr) return; From a06035ecb8e49884d38d0d7a2da295cde1813d49 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Wed, 30 Mar 2016 13:40:26 +0200 Subject: [PATCH 023/125] Fix occured/occurred spelling error --- src/CBot/CBotProgram.h | 4 ++-- src/CBot/CBotStack.h | 2 +- src/app/signal_handlers.cpp | 4 ++-- src/graphics/opengl/gl21device.cpp | 2 +- src/graphics/opengl/gl33device.cpp | 2 +- src/graphics/opengl/gldevice.cpp | 2 +- src/graphics/opengl/glutil.cpp | 8 ++++---- src/level/robotmain.cpp | 10 +++++----- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/CBot/CBotProgram.h b/src/CBot/CBotProgram.h index 2b477bda..9f5cdc00 100644 --- a/src/CBot/CBotProgram.h +++ b/src/CBot/CBotProgram.h @@ -143,7 +143,7 @@ public: * \param[out] code Error code * \param[out] start Starting position in the code string of this error * \param[out] end Ending position in the code string of this error - * \return false if no error has occured + * \return false if no error has occurred */ bool GetError(CBotError& code, int& start, int& end); @@ -153,7 +153,7 @@ public: * \param[out] start Starting position in the code string of this error * \param[out] end Ending position in the code string of this error * \param[out] pProg Program that caused the error (TODO: This always returns "this"... what?) - * \return false if no error has occured + * \return false if no error has occurred */ bool GetError(CBotError& code, int& start, int& end, CBotProgram*& pProg); diff --git a/src/CBot/CBotStack.h b/src/CBot/CBotStack.h index 1d7c7884..6cd8e567 100644 --- a/src/CBot/CBotStack.h +++ b/src/CBot/CBotStack.h @@ -105,7 +105,7 @@ public: /** * \brief Check if there was an error - * \return false if an error occured + * \return false if an error occurred * \see GetError() */ bool IsOk() diff --git a/src/app/signal_handlers.cpp b/src/app/signal_handlers.cpp index 1f29dc61..87dbb4ac 100644 --- a/src/app/signal_handlers.cpp +++ b/src/app/signal_handlers.cpp @@ -124,7 +124,7 @@ void CSignalHandlers::ReportError(const std::string& errorMessage) } std::stringstream msg; - msg << "Unhandled exception occured!" << std::endl; + msg << "Unhandled exception occurred!" << std::endl; msg << "==============================" << std::endl; msg << errorMessage << std::endl; msg << "==============================" << std::endl; @@ -162,7 +162,7 @@ void CSignalHandlers::ReportError(const std::string& errorMessage) std::cerr << std::endl << msg.str() << std::endl; - m_systemUtils->SystemDialog(SDT_ERROR, "Unhandled exception occured!", msg.str()); + m_systemUtils->SystemDialog(SDT_ERROR, "Unhandled exception occurred!", msg.str()); if (canSave && !triedSaving) { diff --git a/src/graphics/opengl/gl21device.cpp b/src/graphics/opengl/gl21device.cpp index 6f7051e3..f5fb7741 100644 --- a/src/graphics/opengl/gl21device.cpp +++ b/src/graphics/opengl/gl21device.cpp @@ -174,7 +174,7 @@ bool CGL21Device::Create() if (!InitializeGLEW()) { - m_errorMessage = "An error occured while initializing GLEW."; + m_errorMessage = "An error occurred while initializing GLEW."; return false; } diff --git a/src/graphics/opengl/gl33device.cpp b/src/graphics/opengl/gl33device.cpp index d02ff77a..c0c1e124 100644 --- a/src/graphics/opengl/gl33device.cpp +++ b/src/graphics/opengl/gl33device.cpp @@ -173,7 +173,7 @@ bool CGL33Device::Create() if (!InitializeGLEW()) { - m_errorMessage = "An error occured while initializing GLEW."; + m_errorMessage = "An error occurred while initializing GLEW."; return false; } diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 95a96fea..423520d6 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -169,7 +169,7 @@ bool CGLDevice::Create() if (!InitializeGLEW()) { - m_errorMessage = "An error occured while initializing GLEW."; + m_errorMessage = "An error occurred while initializing GLEW."; return false; } diff --git a/src/graphics/opengl/glutil.cpp b/src/graphics/opengl/glutil.cpp index 95c1f24f..04ad80a9 100644 --- a/src/graphics/opengl/glutil.cpp +++ b/src/graphics/opengl/glutil.cpp @@ -480,8 +480,8 @@ GLint LoadShader(GLint type, const char* filename) auto message = MakeUniqueArray(len + 1); glGetShaderInfoLog(shader, len + 1, nullptr, message.get()); - GetLogger()->Error("Shader compilation error occured!\n%s\n", message.get()); - lastShaderError = std::string("Shader compilation error occured!\n\n") + std::string(message.get()); + GetLogger()->Error("Shader compilation error occurred!\n%s\n", message.get()); + lastShaderError = std::string("Shader compilation error occurred!\n\n") + std::string(message.get()); glDeleteShader(shader); return 0; @@ -513,8 +513,8 @@ GLint LinkProgram(int count, GLint shaders[]) auto message = MakeUniqueArray(len + 1); glGetProgramInfoLog(program, len + 1, nullptr, message.get()); - GetLogger()->Error("Shader program linking error occured!\n%s\n", message.get()); - lastShaderError = std::string("Shader program linking error occured!\n\n") + std::string(message.get()); + GetLogger()->Error("Shader program linking error occurred!\n%s\n", message.get()); + lastShaderError = std::string("Shader program linking error occurred!\n\n") + std::string(message.get()); glDeleteProgram(program); diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 9506fcaf..d7f71be2 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -563,7 +563,7 @@ void CRobotMain::ChangePhase(Phase phase) } catch (const std::runtime_error& e) { - LevelLoadingError("An error occured while trying to load a level", e); + LevelLoadingError("An error occurred while trying to load a level", e); } } @@ -606,7 +606,7 @@ void CRobotMain::ChangePhase(Phase phase) } catch (const std::runtime_error& e) { - LevelLoadingError("An error occured while trying to load win scene", e); + LevelLoadingError("An error occurred while trying to load win scene", e); } } } @@ -636,7 +636,7 @@ void CRobotMain::ChangePhase(Phase phase) } catch (const std::runtime_error& e) { - LevelLoadingError("An error occured while trying to load lost scene", e); + LevelLoadingError("An error occurred while trying to load lost scene", e); } } } @@ -2781,7 +2781,7 @@ void CRobotMain::ScenePerso() } catch (const std::runtime_error& e) { - LevelLoadingError("An error occured while trying to load apperance scene", e, PHASE_PLAYER_SELECT); + LevelLoadingError("An error occurred while trying to load apperance scene", e, PHASE_PLAYER_SELECT); } m_engine->SetDrawWorld(false); // does not draw anything on the interface @@ -4986,7 +4986,7 @@ void CRobotMain::ResetCreate() } catch (const std::runtime_error& e) { - LevelLoadingError("An error occured while trying to reset scene", e); + LevelLoadingError("An error occurred while trying to reset scene", e); } } From 761c85468fa3a7571861667d05beee7b0bb9468e Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Wed, 30 Mar 2016 13:51:37 +0200 Subject: [PATCH 024/125] Add Keywords key in desktop file See: - https://wiki.gnome.org/Initiatives/GnomeGoals/DesktopFileKeywords - https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s05.html --- desktop/colobot.ini | 2 +- desktop/create_desktop_file.sh | 2 +- desktop/po/colobot-desktop.pot | 8 +++++++- desktop/po/fr.po | 10 ++++++++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/desktop/colobot.ini b/desktop/colobot.ini index 27193df7..0cba2158 100644 --- a/desktop/colobot.ini +++ b/desktop/colobot.ini @@ -1,4 +1,4 @@ Name="Colobot" GenericName="Game to learn programming" Comment="Colonize with bots" - +Keywords="robots;3d;space;astronaut;java;c++" diff --git a/desktop/create_desktop_file.sh b/desktop/create_desktop_file.sh index 8f3d15b6..a41299f3 100755 --- a/desktop/create_desktop_file.sh +++ b/desktop/create_desktop_file.sh @@ -10,7 +10,7 @@ cat colobot.desktop.in linguas=$([ ! -d lang ] || ( cd lang ; ls)); -for type in Name GenericName Comment; do +for type in Name GenericName Comment Keywords; do egrep "^$type=" $fname | sed -e "s/^$type=\"\(.*\)\"$/$type=\1/g" for l in $linguas; do egrep "^$type=" lang/$l/$fname | sed -e "s/^$type=\"\(.*\)\"$/$type[$l]=\1/g" diff --git a/desktop/po/colobot-desktop.pot b/desktop/po/colobot-desktop.pot index 4fbbee34..52e6e1a8 100644 --- a/desktop/po/colobot-desktop.pot +++ b/desktop/po/colobot-desktop.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2016-03-25 19:24+0100\n" +"POT-Creation-Date: 2016-03-30 13:45+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -34,6 +34,12 @@ msgstr "" msgid "Colonize with bots" msgstr "" +#. type: Keywords= +#: colobot.ini:4 +#, no-wrap +msgid "robots;3d;space;astronaut;java;c++" +msgstr "" + #. type: =head1 #: colobot.pod:3 msgid "NAME" diff --git a/desktop/po/fr.po b/desktop/po/fr.po index 01b73ce3..5032271f 100644 --- a/desktop/po/fr.po +++ b/desktop/po/fr.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: colobot 0.1.7\n" -"POT-Creation-Date: 2016-03-25 19:24+0100\n" -"PO-Revision-Date: 2016-03-25 21:13+0100\n" +"POT-Creation-Date: 2016-03-30 13:45+0200\n" +"PO-Revision-Date: 2016-03-30 13:49+0100\n" "Last-Translator: Didier Raboud \n" "Language: fr\n" "MIME-Version: 1.0\n" @@ -34,6 +34,12 @@ msgstr "Apprentissage de la programmation par le jeu" msgid "Colonize with bots" msgstr "Colonise avec des roBots" +#. type: Keywords= +#: colobot.ini:4 +#, no-wrap +msgid "robots;3d;space;astronaut;java;c++" +msgstr "robots;3d;espace;astronaute;cosmonaute;java;c++" + #. type: =head1 #: colobot.pod:3 msgid "NAME" From 39b364fa778f049c798b97d12967e4e1cab88c30 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 30 Mar 2016 22:22:22 +0200 Subject: [PATCH 025/125] Fixed compilation with disabled sound support, closes #748 --- src/app/app.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/app.cpp b/src/app/app.cpp index 19a48306..4a509219 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -42,6 +42,7 @@ #include "object/object_manager.h" +#include "sound/sound.h" #ifdef OPENAL_SOUND #include "sound/oalsound/alsound.h" #endif From 831276f37892fba73865be4e668d9dae68e1b3f2 Mon Sep 17 00:00:00 2001 From: Smok94 Date: Sat, 2 Apr 2016 13:13:42 +0200 Subject: [PATCH 026/125] Appearance customization face butons fix *face buttons 2 and 4 swaped. *default hair colors now fit to buttons look *changing face changes hair color do default Fixes two first issues mentioned in the #724 --- src/common/restext.cpp | 4 +-- src/level/player_profile.cpp | 55 +++++++++++++++++++++++------- src/level/player_profile.h | 1 + src/ui/screen/screen_apperance.cpp | 5 +-- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/common/restext.cpp b/src/common/restext.cpp index c1cd857f..1ef49306 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -283,9 +283,9 @@ void InitializeRestext() stringsEvent[EVENT_INTERFACE_PCGb] = TR("Green"); stringsEvent[EVENT_INTERFACE_PCBb] = TR("Blue"); stringsEvent[EVENT_INTERFACE_PFACE1] = TR("\\Face 1"); - stringsEvent[EVENT_INTERFACE_PFACE2] = TR("\\Face 4"); + stringsEvent[EVENT_INTERFACE_PFACE2] = TR("\\Face 2"); stringsEvent[EVENT_INTERFACE_PFACE3] = TR("\\Face 3"); - stringsEvent[EVENT_INTERFACE_PFACE4] = TR("\\Face 2"); + stringsEvent[EVENT_INTERFACE_PFACE4] = TR("\\Face 4"); stringsEvent[EVENT_INTERFACE_PGLASS0] = TR("\\No eyeglasses"); stringsEvent[EVENT_INTERFACE_PGLASS1] = TR("\\Eyeglasses 1"); stringsEvent[EVENT_INTERFACE_PGLASS2] = TR("\\Eyeglasses 2"); diff --git a/src/level/player_profile.cpp b/src/level/player_profile.cpp index a34bfb50..7eba33c9 100644 --- a/src/level/player_profile.cpp +++ b/src/level/player_profile.cpp @@ -38,9 +38,9 @@ void PlayerApperance::DefPerso() this->colorCombi.r = 206.0f/256.0f; this->colorCombi.g = 206.0f/256.0f; this->colorCombi.b = 204.0f/256.0f; // ~white - this->colorBand.r = 255.0f/256.0f; - this->colorBand.g = 132.0f/256.0f; - this->colorBand.b = 1.0f/256.0f; // orange + this->colorBand.r = 255.0f / 256.0f; + this->colorBand.g = 132.0f / 256.0f; + this->colorBand.b = 1.0f / 256.0f; // orange if ( this->face == 0 ) // normal ? { @@ -52,23 +52,23 @@ void PlayerApperance::DefPerso() if ( this->face == 1 ) // bald ? { this->glasses = 0; - this->colorHair.r = 83.0f/256.0f; - this->colorHair.g = 64.0f/256.0f; - this->colorHair.b = 51.0f/256.0f; // brown + this->colorHair.r = 74.0f / 256.0f; + this->colorHair.g = 58.0f / 256.0f; + this->colorHair.b = 46.0f / 256.0f; // brown } if ( this->face == 2 ) // carlos ? { this->glasses = 1; - this->colorHair.r = 85.0f/256.0f; - this->colorHair.g = 48.0f/256.0f; + this->colorHair.r = 70.0f / 256.0f; + this->colorHair.g = 40.0f / 256.0f; this->colorHair.b = 9.0f/256.0f; // brown } - if ( this->face == 3 ) // blond ? + if ( this->face == 3 ) // blond ? -> ginger ? { this->glasses = 4; - this->colorHair.r = 255.0f/256.0f; - this->colorHair.g = 255.0f/256.0f; - this->colorHair.b = 181.0f/256.0f; // yellow + this->colorHair.r = 74.0f / 256.0f; + this->colorHair.g = 16.0f / 256.0f; + this->colorHair.b = 0.0f / 256.0f; // yellow, changed to ginger } this->colorHair.a = 0.0f; @@ -76,6 +76,37 @@ void PlayerApperance::DefPerso() this->colorBand.a = 0.0f; } +void PlayerApperance::DefHairColor() + { + if (this->face == 0) // normal ? + { + this->colorHair.r = 90.0f / 256.0f; + this->colorHair.g = 95.0f / 256.0f; + this->colorHair.b = 85.0f / 256.0f; // black + } + if (this->face == 1) // bald ? + { + this->colorHair.r = 74.0f / 256.0f; + this->colorHair.g = 58.0f / 256.0f; + this->colorHair.b = 46.0f / 256.0f; // brown + } + if (this->face == 2) // carlos ? + { + this->colorHair.r = 70.0f / 256.0f; + this->colorHair.g = 40.0f / 256.0f; + this->colorHair.b = 9.0f / 256.0f; // brown + } + if (this->face == 3) // blond ? -> ginger ? + { + this->colorHair.r = 74.0f / 256.0f; + this->colorHair.g = 16.0f / 256.0f; + this->colorHair.b = 0.0f / 256.0f; // yellow, changed to ginger + } + + this->colorHair.a = 0.0f; + } + + CPlayerProfile::CPlayerProfile(std::string playerName) { m_playerName = playerName; diff --git a/src/level/player_profile.h b/src/level/player_profile.h index 63bbfd74..fc198cbe 100644 --- a/src/level/player_profile.h +++ b/src/level/player_profile.h @@ -42,6 +42,7 @@ struct PlayerApperance Gfx::Color colorBand; // strips color void DefPerso(); + void DefHairColor(); }; struct SavedScene diff --git a/src/ui/screen/screen_apperance.cpp b/src/ui/screen/screen_apperance.cpp index 82c92266..9ae82c97 100644 --- a/src/ui/screen/screen_apperance.cpp +++ b/src/ui/screen/screen_apperance.cpp @@ -164,13 +164,13 @@ void CScreenApperance::CreateInterface() pb = pw->CreateButton(pos, ddim, 43, EVENT_INTERFACE_PFACE1); pb->SetState(STATE_SHADOW); pos.x += 50.0f/640.0f; - pb = pw->CreateButton(pos, ddim, 46, EVENT_INTERFACE_PFACE4); + pb = pw->CreateButton(pos, ddim, 44, EVENT_INTERFACE_PFACE2); pb->SetState(STATE_SHADOW); pos.x += 50.0f/640.0f; pb = pw->CreateButton(pos, ddim, 45, EVENT_INTERFACE_PFACE3); pb->SetState(STATE_SHADOW); pos.x += 50.0f/640.0f; - pb = pw->CreateButton(pos, ddim, 44, EVENT_INTERFACE_PFACE2); + pb = pw->CreateButton(pos, ddim, 46, EVENT_INTERFACE_PFACE4); pb->SetState(STATE_SHADOW); // Glasses @@ -349,6 +349,7 @@ bool CScreenApperance::EventProcess(const Event &event) case EVENT_INTERFACE_PFACE3: case EVENT_INTERFACE_PFACE4: apperance.face = event.type-EVENT_INTERFACE_PFACE1; + apperance.DefHairColor(); UpdatePerso(); m_main->ScenePerso(); break; From 6afdb7b6c898c861fd6b6f30a69c7bd7fa267ebd Mon Sep 17 00:00:00 2001 From: Smok94 Date: Sat, 2 Apr 2016 14:43:40 +0200 Subject: [PATCH 027/125] First person camera unlocked for Me and Tech *unlocked camaera button for Me and Tech *unlocked first ferson view for Me and Tech *Me and Tech have no "camera view" effect like robots in first person mode #156 --- src/level/robotmain.cpp | 4 ++- src/ui/object_interface.cpp | 49 ++++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index d7f71be2..274118b7 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -2270,7 +2270,9 @@ void CRobotMain::ChangeCamera() ObjectType oType = obj->GetType(); Gfx::CameraType type = controllableObj->GetCameraType(); - if ( oType != OBJECT_MOBILEfa && + if ( oType != OBJECT_HUMAN && + oType != OBJECT_TECH && + oType != OBJECT_MOBILEfa && oType != OBJECT_MOBILEta && oType != OBJECT_MOBILEwa && oType != OBJECT_MOBILEia && diff --git a/src/ui/object_interface.cpp b/src/ui/object_interface.cpp index 81a68006..c2ed098f 100644 --- a/src/ui/object_interface.cpp +++ b/src/ui/object_interface.cpp @@ -1302,8 +1302,9 @@ bool CObjectInterface::CreateInterface(bool bSelect) pw->CreateButton(pos, ddim, 19, EVENT_OBJECT_HELP); } - if ( type != OBJECT_HUMAN && - type != OBJECT_TECH && +//camera button no more disabled for humans + if ( //type != OBJECT_HUMAN && + //type != OBJECT_TECH && !m_object->GetCameraLock() ) { //? if ( m_main->GetShowMap() ) @@ -1396,29 +1397,33 @@ bool CObjectInterface::CreateInterface(bool bSelect) pt->ClearState(STATE_GLINT); } - ddim.x = 64.0f/640.0f; - ddim.y = 64.0f/480.0f; - pos.x = 30.0f/640.0f; - pos.y = 430.0f/480.0f-ddim.y; - pw->CreateGroup(pos, ddim, 13, EVENT_OBJECT_CORNERul); + if (type != OBJECT_HUMAN && + type != OBJECT_TECH) + { + ddim.x = 64.0f / 640.0f; + ddim.y = 64.0f / 480.0f; + pos.x = 30.0f / 640.0f; + pos.y = 430.0f / 480.0f - ddim.y; + pw->CreateGroup(pos, ddim, 13, EVENT_OBJECT_CORNERul); - ddim.x = 64.0f/640.0f; - ddim.y = 64.0f/480.0f; - pos.x = 610.0f/640.0f-ddim.x; - pos.y = 430.0f/480.0f-ddim.y; - pw->CreateGroup(pos, ddim, 14, EVENT_OBJECT_CORNERur); + ddim.x = 64.0f / 640.0f; + ddim.y = 64.0f / 480.0f; + pos.x = 610.0f / 640.0f - ddim.x; + pos.y = 430.0f / 480.0f - ddim.y; + pw->CreateGroup(pos, ddim, 14, EVENT_OBJECT_CORNERur); - ddim.x = 64.0f/640.0f; - ddim.y = 64.0f/480.0f; - pos.x = 30.0f/640.0f; - pos.y = 110.0f/480.0f; - pw->CreateGroup(pos, ddim, 15, EVENT_OBJECT_CORNERdl); + ddim.x = 64.0f / 640.0f; + ddim.y = 64.0f / 480.0f; + pos.x = 30.0f / 640.0f; + pos.y = 110.0f / 480.0f; + pw->CreateGroup(pos, ddim, 15, EVENT_OBJECT_CORNERdl); - ddim.x = 64.0f/640.0f; - ddim.y = 64.0f/480.0f; - pos.x = 610.0f/640.0f-ddim.x; - pos.y = 110.0f/480.0f; - pw->CreateGroup(pos, ddim, 16, EVENT_OBJECT_CORNERdr); + ddim.x = 64.0f / 640.0f; + ddim.y = 64.0f / 480.0f; + pos.x = 610.0f / 640.0f - ddim.x; + pos.y = 110.0f / 480.0f; + pw->CreateGroup(pos, ddim, 16, EVENT_OBJECT_CORNERdr); + } UpdateInterface(); m_lastUpdateTime = 0.0f; From b5438c3ae4c09705a04974814cfd7b3fcf6cec00 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 3 Apr 2016 11:34:08 +1200 Subject: [PATCH 028/125] Fix CMake warning when compiling on OSX --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c5edf93c..72e22179 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,8 @@ elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") # Platform-dependent implementation of system.h set(SYSTEM_CPP_MODULE "system_macosx.cpp") + # To avoid CMake warning + set(CMAKE_MACOSX_RPATH 1) else() message(STATUS "Build for other system") set(PLATFORM_WINDOWS 0) From 89389e82e8a6d999092497c68172c7d633a0fa88 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 3 Apr 2016 15:18:46 +1200 Subject: [PATCH 029/125] Fix desktop SVG icon not resizing properly Workaround for librsvg bug --- desktop/CMakeLists.txt | 32 ++++++++++++++++++-------------- desktop/colobot.svg | 1 + 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/desktop/CMakeLists.txt b/desktop/CMakeLists.txt index 93113adc..a452167b 100644 --- a/desktop/CMakeLists.txt +++ b/desktop/CMakeLists.txt @@ -1,30 +1,34 @@ cmake_minimum_required(VERSION 2.8) -set(COLOBOT_ICON_FILE colobot.svg) +set(COLOBOT_ICON_FILE ${CMAKE_CURRENT_SOURCE_DIR}/colobot.svg) # Render SVG icon in various sizes find_program(RSVG_CONVERT rsvg-convert) -if(RSVG_CONVERT AND (PLATFORM_GNU OR PLATFORM_MACOSX)) - add_custom_target(png-icons ALL) - foreach(PNGSIZE 512 256 128 48 32 16) +find_program(XMLSTARLET xmlstarlet) +if(RSVG_CONVERT AND XMLSTARLET AND (PLATFORM_GNU OR PLATFORM_MACOSX)) + add_custom_target(png-icons ALL DEPENDS ${COLOBOT_ICON_FILE}) + + foreach(PNG_SIZE 512 256 128 48 32 16) + # Using xmlstarlet to edit SVG file is a workaround for rsvg-convert bug (see: https://bugzilla.gnome.org/show_bug.cgi?id=762115) add_custom_command( - OUTPUT ${PNGSIZE}/colobot.png - COMMAND mkdir -p ${PNGSIZE} - COMMAND ${RSVG_CONVERT} -w ${PNGSIZE} -h ${PNGSIZE} ${CMAKE_CURRENT_SOURCE_DIR}/${COLOBOT_ICON_FILE} > ${PNGSIZE}/colobot.png + OUTPUT ${PNG_SIZE}/colobot.png + COMMAND mkdir -p ${PNG_SIZE} + COMMAND ${XMLSTARLET} ed -u /*/@width -v ${PNG_SIZE} -u /*/@height -v ${PNG_SIZE} ${COLOBOT_ICON_FILE} > ${PNG_SIZE}/colobot.svg + COMMAND ${RSVG_CONVERT} ${PNG_SIZE}/colobot.svg -o ${PNG_SIZE}/colobot.png ) - add_custom_target(png-icon-${PNGSIZE} ALL DEPENDS ${PNGSIZE}/colobot.png) - add_dependencies(png-icons png-icon-${PNGSIZE}) + add_custom_target(png-icon-${PNG_SIZE} ALL DEPENDS ${PNG_SIZE}/colobot.png) + add_dependencies(png-icons png-icon-${PNG_SIZE}) if(PLATFORM_GNU) install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGSIZE}/colobot.png - DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/${PNGSIZE}x${PNGSIZE}/apps/ + FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNG_SIZE}/colobot.png + DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/${PNG_SIZE}x${PNG_SIZE}/apps/ ) endif() # Prepare the ICNS icon generation - list(APPEND ICNS_SRCS "${PNGSIZE}/colobot.png") + list(APPEND ICNS_SRCS "${PNG_SIZE}/colobot.png") endforeach() - + # Pack icon for Mac OS find_program(PNG2ICNS png2icns) if(PNG2ICNS AND PLATFORM_MACOSX) @@ -54,7 +58,7 @@ if(PLATFORM_GNU) # Install Icon install( - FILES ${CMAKE_CURRENT_SOURCE_DIR}/${COLOBOT_ICON_FILE} + FILES ${COLOBOT_ICON_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps/ ) diff --git a/desktop/colobot.svg b/desktop/colobot.svg index c514d6ba..cb3ca353 100644 --- a/desktop/colobot.svg +++ b/desktop/colobot.svg @@ -12,6 +12,7 @@ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="32" height="32" + viewBox="0 0 32 32" id="svg2" version="1.1" inkscape:version="0.48.4 r9939" From 3a3653d47e2a0d2ee75ccfd50fab99d036a41374 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 3 Apr 2016 15:30:23 +1200 Subject: [PATCH 030/125] Add warning messages if tool programs are not found --- desktop/CMakeLists.txt | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/desktop/CMakeLists.txt b/desktop/CMakeLists.txt index a452167b..b4e6a853 100644 --- a/desktop/CMakeLists.txt +++ b/desktop/CMakeLists.txt @@ -4,7 +4,15 @@ set(COLOBOT_ICON_FILE ${CMAKE_CURRENT_SOURCE_DIR}/colobot.svg) # Render SVG icon in various sizes find_program(RSVG_CONVERT rsvg-convert) +if(NOT RSVG_CONVERT) + message(WARNING "rsvg-cnvert not found; desktop icons will not be generated") +endif() + find_program(XMLSTARLET xmlstarlet) +if(NOT XMLSTARLET) + message(WARNING "xmlstarlet not found; desktop icons will not be generated") +endif() + if(RSVG_CONVERT AND XMLSTARLET AND (PLATFORM_GNU OR PLATFORM_MACOSX)) add_custom_target(png-icons ALL DEPENDS ${COLOBOT_ICON_FILE}) @@ -30,13 +38,19 @@ if(RSVG_CONVERT AND XMLSTARLET AND (PLATFORM_GNU OR PLATFORM_MACOSX)) endforeach() # Pack icon for Mac OS - find_program(PNG2ICNS png2icns) - if(PNG2ICNS AND PLATFORM_MACOSX) - add_custom_command(OUTPUT Colobot.icns - COMMAND ${PNG2ICNS} Colobot.icns ${ICNS_SRCS} - DEPENDS png-icons - ) - add_custom_target(icns-icon ALL DEPENDS Colobot.icns) + if(PLATFORM_MACOSX) + find_program(PNG2ICNS png2icns) + if(NOT PNG2ICNS) + message(WARNING "png2icns not found; icns file will not be generated") + endif() + + if(PNG2ICNS) + add_custom_command(OUTPUT Colobot.icns + COMMAND ${PNG2ICNS} Colobot.icns ${ICNS_SRCS} + DEPENDS png-icons + ) + add_custom_target(icns-icon ALL DEPENDS Colobot.icns) + endif() endif() endif() @@ -64,6 +78,10 @@ if(PLATFORM_GNU) # Translate translatable material find_program(PO4A po4a) + if(NOT PO4A) + message(WARNING "po4a not found; desktop and manpage files will not be translated") + endif() + if(PO4A) add_custom_target(desktop_po4a COMMAND ${PO4A} po4a.cfg @@ -74,6 +92,10 @@ if(PLATFORM_GNU) # Create manpage from pod-formatted file find_program(POD2MAN pod2man) + if(NOT POD2MAN) + message(WARNING "pod2man not found; manpage will not be generated") + endif() + if(POD2MAN) set(COLOBOT_MANPAGE_SECTION 6) From 72f966b1184eec4fee04260cd2fedb544e80ee6a Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 3 Apr 2016 16:45:13 +1200 Subject: [PATCH 031/125] Fix for #738 Add one-pixel boundary and fix texture coordinates for font characters This should finally fix the issue of pixelated text --- src/graphics/engine/text.cpp | 15 ++++++++------- src/graphics/engine/text.h | 1 - 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index c1317f1e..7ecf204c 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -944,10 +944,11 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P Math::Point p1(pos.x, pos.y); Math::Point p2(pos.x + charInterfaceSize.x, pos.y + charInterfaceSize.y); - Math::Point texCoord1(static_cast(tex.charPos.x) / FONT_TEXTURE_SIZE.x, - static_cast(tex.charPos.y) / FONT_TEXTURE_SIZE.y); - Math::Point texCoord2(static_cast(tex.charPos.x + tex.charSize.x) / FONT_TEXTURE_SIZE.x, - static_cast(tex.charPos.y + tex.charSize.y) / FONT_TEXTURE_SIZE.y); + const float halfPixelMargin = 0.5f; + Math::Point texCoord1(static_cast(tex.charPos.x + halfPixelMargin) / FONT_TEXTURE_SIZE.x, + static_cast(tex.charPos.y + halfPixelMargin) / FONT_TEXTURE_SIZE.y); + Math::Point texCoord2(static_cast(tex.charPos.x + tex.charSize.x + halfPixelMargin) / FONT_TEXTURE_SIZE.x, + static_cast(tex.charPos.y + tex.charSize.y + halfPixelMargin) / FONT_TEXTURE_SIZE.y); Math::Vector n(0.0f, 0.0f, -1.0f); // normal Vertex quad[4] = @@ -1061,8 +1062,9 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font) return texture; } - Math::IntPoint tileSize(Math::NextPowerOfTwo(textSurface->w), - Math::NextPowerOfTwo(textSurface->h)); + const int pixelMargin = 1; + Math::IntPoint tileSize(Math::NextPowerOfTwo(textSurface->w) + pixelMargin, + Math::NextPowerOfTwo(textSurface->h) + pixelMargin); FontTexture* fontTexture = GetOrCreateFontTexture(tileSize); @@ -1075,7 +1077,6 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font) texture.id = fontTexture->id; texture.charPos = GetNextTilePos(*fontTexture); texture.charSize = Math::IntPoint(textSurface->w, textSurface->h); - texture.tileSize = tileSize; ImageData imageData; imageData.surface = textSurface; diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index 962c755f..6ee0a862 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -193,7 +193,6 @@ struct CharTexture unsigned int id = 0; Math::IntPoint charPos; Math::IntPoint charSize; - Math::IntPoint tileSize; }; // Definition is private - in text.cpp From 9639dc5f96db7079099de638aa38885b549554d4 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 3 Apr 2016 22:25:41 +1200 Subject: [PATCH 032/125] Fix typo --- desktop/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop/CMakeLists.txt b/desktop/CMakeLists.txt index b4e6a853..dcca3b77 100644 --- a/desktop/CMakeLists.txt +++ b/desktop/CMakeLists.txt @@ -5,7 +5,7 @@ set(COLOBOT_ICON_FILE ${CMAKE_CURRENT_SOURCE_DIR}/colobot.svg) # Render SVG icon in various sizes find_program(RSVG_CONVERT rsvg-convert) if(NOT RSVG_CONVERT) - message(WARNING "rsvg-cnvert not found; desktop icons will not be generated") + message(WARNING "rsvg-convert not found; desktop icons will not be generated") endif() find_program(XMLSTARLET xmlstarlet) From 98dd9f90c8fec2129b5dcc59f56c3741315a9659 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 3 Apr 2016 13:06:39 +0200 Subject: [PATCH 033/125] Fixed code style warnings --- src/object/auto/autohouston.cpp | 4 ++-- src/ui/debug_menu.cpp | 9 +++++---- src/ui/debug_menu.h | 5 +++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/object/auto/autohouston.cpp b/src/object/auto/autohouston.cpp index 9ace4085..2853be89 100644 --- a/src/object/auto/autohouston.cpp +++ b/src/object/auto/autohouston.cpp @@ -17,10 +17,10 @@ * along with this program. If not, see http://gnu.org/licenses */ - -#include #include "object/auto/autohouston.h" +#include "math/geometry.h" + #include "object/old_object.h" #include "ui/controls/interface.h" diff --git a/src/ui/debug_menu.cpp b/src/ui/debug_menu.cpp index 88e62c10..92390386 100644 --- a/src/ui/debug_menu.cpp +++ b/src/ui/debug_menu.cpp @@ -26,9 +26,10 @@ #include "level/robotmain.h" -#include "object/object_create_params.h" -#include "object/object_manager.h" #include "object/object.h" +#include "object/object_manager.h" + +#include "sound/sound.h" #include "ui/controls/interface.h" #include "ui/controls/window.h" @@ -62,7 +63,7 @@ void CDebugMenu::ToggleInterface() const Math::Point dim = Math::Point(33.0f/640.0f, 33.0f/480.0f); const float ox = 3.0f/640.0f, oy = 3.0f/480.0f; -const float sx = 33.0f/640.0f, sy = 33.0f/480.0f; +const float /*sx = 33.0f/640.0f,*/ sy = 33.0f/480.0f; void CDebugMenu::CreateInterface() { @@ -426,4 +427,4 @@ bool CDebugMenu::HandleTeleport(Math::Point mousePos) return true; } -} \ No newline at end of file +} diff --git a/src/ui/debug_menu.h b/src/ui/debug_menu.h index 2fb4b9de..a45623ac 100644 --- a/src/ui/debug_menu.h +++ b/src/ui/debug_menu.h @@ -19,12 +19,13 @@ #pragma once -#include -#include +#include "math/point.h" + #include "object/object_type.h" class CRobotMain; class CObjectManager; +class CSoundInterface; struct Event; namespace Gfx From c0780f938e2fd73eb3a2ba22da936e2a796450fc Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 3 Apr 2016 13:19:51 +0200 Subject: [PATCH 034/125] One more code style fix --- src/ui/debug_menu.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/debug_menu.cpp b/src/ui/debug_menu.cpp index 92390386..10aa9397 100644 --- a/src/ui/debug_menu.cpp +++ b/src/ui/debug_menu.cpp @@ -31,10 +31,10 @@ #include "sound/sound.h" +#include "ui/controls/button.h" +#include "ui/controls/check.h" #include "ui/controls/interface.h" #include "ui/controls/window.h" -#include "ui/controls/check.h" -#include "ui/controls/button.h" namespace Ui { From 1960b373f1a3124053339e2febbc7990ef92cf7f Mon Sep 17 00:00:00 2001 From: KarolTrzeszczkowski Date: Sun, 3 Apr 2016 12:45:50 +0200 Subject: [PATCH 035/125] Solves #700 It turns out, that tower is not over powered in code battle mode. It never hits flying enemy robot. --- src/object/auto/autotower.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/object/auto/autotower.cpp b/src/object/auto/autotower.cpp index 23d8f2c0..ad436af7 100644 --- a/src/object/auto/autotower.cpp +++ b/src/object/auto/autotower.cpp @@ -271,12 +271,16 @@ CObject* CAutoTower::SearchTarget(Math::Vector &impact) CObject* best = nullptr; for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { + int oTeam=obj->GetTeam(); + int myTeam=m_object->GetTeam(); ObjectType oType = obj->GetType(); if ( oType != OBJECT_MOTHER && oType != OBJECT_ANT && oType != OBJECT_SPIDER && oType != OBJECT_BEE && - oType != OBJECT_WORM ) continue; + oType != OBJECT_WORM && + (oTeam == myTeam || + oTeam == 0) ) continue; if ( !obj->GetDetectable() ) continue; // inactive? From 15702ec856cc83d98dd8c8cb67c7ed1624eb1c86 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 3 Apr 2016 20:29:55 +0200 Subject: [PATCH 036/125] Fixed indentation --- src/level/player_profile.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/level/player_profile.cpp b/src/level/player_profile.cpp index 7eba33c9..d3603f1c 100644 --- a/src/level/player_profile.cpp +++ b/src/level/player_profile.cpp @@ -77,35 +77,35 @@ void PlayerApperance::DefPerso() } void PlayerApperance::DefHairColor() - { +{ if (this->face == 0) // normal ? - { + { this->colorHair.r = 90.0f / 256.0f; this->colorHair.g = 95.0f / 256.0f; this->colorHair.b = 85.0f / 256.0f; // black - } + } if (this->face == 1) // bald ? - { + { this->colorHair.r = 74.0f / 256.0f; this->colorHair.g = 58.0f / 256.0f; this->colorHair.b = 46.0f / 256.0f; // brown - } + } if (this->face == 2) // carlos ? - { + { this->colorHair.r = 70.0f / 256.0f; this->colorHair.g = 40.0f / 256.0f; this->colorHair.b = 9.0f / 256.0f; // brown - } + } if (this->face == 3) // blond ? -> ginger ? - { + { this->colorHair.r = 74.0f / 256.0f; this->colorHair.g = 16.0f / 256.0f; this->colorHair.b = 0.0f / 256.0f; // yellow, changed to ginger - } - - this->colorHair.a = 0.0f; } + this->colorHair.a = 0.0f; +} + CPlayerProfile::CPlayerProfile(std::string playerName) { From 059a54668948bdb7473fb69d7d8b7bfd0b7337f0 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 3 Apr 2016 21:09:41 +0200 Subject: [PATCH 037/125] Reenabled unit tests that started working after 14721001e5ad8a7d4a3c893d0343125eddc20ddc --- test/unit/CBot/CBot_test.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/unit/CBot/CBot_test.cpp b/test/unit/CBot/CBot_test.cpp index cd684a86..b4e1bbb6 100644 --- a/test/unit/CBot/CBot_test.cpp +++ b/test/unit/CBot/CBot_test.cpp @@ -814,8 +814,7 @@ TEST_F(CBotUT, DISABLED_ClassDestructorNaming) ); } -// TODO: This doesn't work -TEST_F(CBotUT, DISABLED_ClassMethodOverloading) +TEST_F(CBotUT, ClassMethodOverloading) { ExecuteTest( "public class TestClass {\n" @@ -955,8 +954,7 @@ TEST_F(CBotUT, DISABLED_StringAsArray) ); } -// TODO: doesn't work, see discussion in #737 -TEST_F(CBotUT, DISABLED_ArraysOfStrings) +TEST_F(CBotUT, ArraysOfStrings) { ExecuteTest( "extern void ArraysOfStrings()\n" From 09a586936bf9bc5d3e7b2e4415e5ab2f535ceefb Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 3 Apr 2016 22:23:12 +0200 Subject: [PATCH 038/125] Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 90654ddf..17b8846a 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 90654ddfedb385d90d10db702264aa3c69c6afad +Subproject commit 17b8846ac97a26de006c456fe645724199155403 From c94ebb45e79851ec3a4253381448959ffe1907b6 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 4 Apr 2016 22:28:08 +0200 Subject: [PATCH 039/125] Moved pathman from common/ to app/ --- src/CMakeLists.txt | 2 +- src/app/app.cpp | 2 +- src/{common => app}/pathman.cpp | 2 +- src/{common => app}/pathman.h | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename src/{common => app}/pathman.cpp (99%) rename src/{common => app}/pathman.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 38d21f0f..482de23b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -78,6 +78,7 @@ set(BASE_SOURCES app/app.cpp app/controller.cpp app/input.cpp + app/pathman.cpp app/pausemanager.cpp app/signal_handlers.cpp app/system.cpp @@ -90,7 +91,6 @@ set(BASE_SOURCES common/language.cpp common/logger.cpp common/misc.cpp - common/pathman.cpp common/regex_utils.cpp common/resources/inputstream.cpp common/resources/inputstreambuffer.cpp diff --git a/src/app/app.cpp b/src/app/app.cpp index 4a509219..43135502 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -21,6 +21,7 @@ #include "app/controller.h" #include "app/input.h" +#include "app/pathman.h" #include "app/system.h" #include "common/config_file.h" @@ -28,7 +29,6 @@ #include "common/key.h" #include "common/logger.h" #include "common/make_unique.h" -#include "common/pathman.h" #include "common/stringutils.h" #include "common/version.h" diff --git a/src/common/pathman.cpp b/src/app/pathman.cpp similarity index 99% rename from src/common/pathman.cpp rename to src/app/pathman.cpp index 44e2d345..2e32ddf0 100644 --- a/src/common/pathman.cpp +++ b/src/app/pathman.cpp @@ -18,7 +18,7 @@ */ -#include "common/pathman.h" +#include "app/pathman.h" #include "common/config.h" diff --git a/src/common/pathman.h b/src/app/pathman.h similarity index 100% rename from src/common/pathman.h rename to src/app/pathman.h From 61440392d22816d87d57311a705981e5d0095458 Mon Sep 17 00:00:00 2001 From: melex750 Date: Tue, 5 Apr 2016 14:00:15 -0400 Subject: [PATCH 040/125] Fix initializing static array in class definition issue #32 --- src/CBot/CBotClass.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 27794d7f..1995dd9c 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -739,8 +739,15 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) if ( pv->IsStatic() && pv->m_InitExpr != nullptr ) { CBotStack* pile = CBotStack::AllocateStack(); // independent stack - while(pile->IsOk() && !pv->m_InitExpr->Execute(pile)); // evaluates the expression without timer - pv->SetVal( pile->GetVar() ) ; + if ( type2.Eq(CBotTypArrayPointer) ) + { + while(pile->IsOk() && !pv->m_InitExpr->Execute(pile, pv)); + } + else + { + while(pile->IsOk() && !pv->m_InitExpr->Execute(pile)); // evaluates the expression without timer + pv->SetVal( pile->GetVar() ) ; + } pile->Delete(); } } From 748f0034bd613f587607be9e761cca0347d06059 Mon Sep 17 00:00:00 2001 From: melex750 Date: Tue, 5 Apr 2016 14:28:36 -0400 Subject: [PATCH 041/125] Fix array in a class not working with sizeof()... ...when no assignment is made in the definition. It should pass this unit test now: TEST_F(CBotUT, DISABLED_ArraysInClasses) --- src/CBot/CBotClass.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 1995dd9c..70c72ef5 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -22,6 +22,7 @@ #include "CBot/CBotInstr/CBotInstrUtils.h" #include "CBot/CBotInstr/CBotNew.h" #include "CBot/CBotInstr/CBotLeftExprVar.h" +#include "CBot/CBotInstr/CBotExprLitNull.h" #include "CBot/CBotInstr/CBotTwoOpExpr.h" #include "CBot/CBotInstr/CBotFunction.h" #include "CBot/CBotInstr/CBotExpression.h" @@ -722,6 +723,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) } if ( !pStack->IsOk() ) return false; } + else if ( type2.Eq(CBotTypArrayPointer) ) i = new CBotExprLitNull(); if ( !bSecond ) From 71a77c77f6d94c84b0aaf02772ea7d7d104b6cf9 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 6 Apr 2016 22:21:41 +1200 Subject: [PATCH 042/125] Hack to finally fix #738 Text rendering is now done in window coordinates corresponding to window pixels to avoid floating-point rounding errors that show up as rendering artifacts --- src/graphics/engine/engine.cpp | 31 ++++++-- src/graphics/engine/engine.h | 3 + src/graphics/engine/text.cpp | 130 +++++++++++++++++++++++---------- src/graphics/engine/text.h | 10 ++- 4 files changed, 127 insertions(+), 47 deletions(-) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 5b2fc6e5..8b0b40e5 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -3789,9 +3789,7 @@ void CEngine::DrawInterface() m_device->SetRenderState(RENDER_STATE_LIGHTING, false); m_device->SetRenderState(RENDER_STATE_FOG, false); - m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); - m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); - m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); + SetInterfaceCoordinates(); // Force new state to disable lighting m_interfaceMode = true; @@ -3890,9 +3888,7 @@ void CEngine::DrawInterface() m_device->SetRenderMode(RENDER_MODE_INTERFACE); - m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); - m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); - m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); + SetInterfaceCoordinates(); } // Draw foreground color @@ -5184,4 +5180,27 @@ void CEngine::SetDebugGotoBitmap(std::unique_ptr debugImage) UpdateGroundSpotTextures(); } +void CEngine::SetInterfaceCoordinates() +{ + m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); + m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); + m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); +} + +void CEngine::SetWindowCoordinates() +{ + Math::Matrix matWorldWindow; + matWorldWindow.LoadIdentity(); + + Math::Matrix matViewWindow; + matViewWindow.LoadIdentity(); + + Math::Matrix matProjWindow; + Math::LoadOrthoProjectionMatrix(matProjWindow, 0.0f, m_size.x, m_size.y, 0.0f, -1.0f, 1.0f); + + m_device->SetTransform(TRANSFORM_VIEW, matViewWindow); + m_device->SetTransform(TRANSFORM_PROJECTION, matProjWindow); + m_device->SetTransform(TRANSFORM_WORLD, matWorldWindow); +} + } // namespace Gfx diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index a64b8c3c..1f5cfe8f 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -1196,6 +1196,9 @@ public: void AddDebugGotoLine(std::vector line); void SetDebugGotoBitmap(std::unique_ptr debugImage); + void SetWindowCoordinates(); + void SetInterfaceCoordinates(); + protected: //! Resets some states and flushes textures after device was changed (e.g. resoulution changed) /** Instead of calling this directly, send EVENT_RESOLUTION_CHANGED event **/ diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 7ecf204c..0af5723a 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -214,7 +214,9 @@ void CText::DrawText(const std::string &text, std::vector::iterato pos.x -= sw; } - DrawString(text, format, end, size, pos, width, eol, color); + Math::IntPoint intPos = m_engine->InterfaceToWindowCoords(pos); + int intWidth = width * m_engine->GetWindowSize().x; + DrawString(text, format, end, size, intPos, intWidth, eol, color); } void CText::DrawText(const std::string &text, FontType font, @@ -236,7 +238,9 @@ void CText::DrawText(const std::string &text, FontType font, pos.x -= sw; } - DrawString(text, font, size, pos, width, eol, color); + Math::IntPoint intPos = m_engine->InterfaceToWindowCoords(pos); + int intWidth = width * m_engine->GetWindowSize().x; + DrawString(text, font, size, intPos, intWidth, eol, color); } void CText::SizeText(const std::string &text, std::vector::iterator format, @@ -322,6 +326,14 @@ float CText::GetHeight(FontType font, float size) return ifSize.y; } +int CText::GetHeightInt(FontType font, float size) +{ + assert(font != FONT_BUTTON); + + CachedFont* cf = GetOrOpenFont(font, size); + assert(cf != nullptr); + return TTF_FontHeight(cf->font); +} float CText::GetStringWidth(const std::string &text, std::vector::iterator format, @@ -416,6 +428,46 @@ float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset) return charSize.x * width; } +int CText::GetCharWidthInt(UTF8Char ch, FontType font, float size, float offset) +{ + if (font == FONT_BUTTON) + { + Math::IntPoint windowSize = m_engine->GetWindowSize(); + int height = GetHeightInt(FONT_COLOBOT, size); + int width = height*(static_cast(windowSize.y)/windowSize.x); + return width; + } + + int width = 1; + if (ch.c1 < 32 && ch.c1 >= 0) + { + if (ch.c1 == '\t') + width = m_tabSize; + + // TODO: tab sizing at intervals? + + ch.c1 = ':'; + } + + CachedFont* cf = GetOrOpenFont(font, size); + assert(cf != nullptr); + + Math::IntPoint charSize; + auto it = cf->cache.find(ch); + if (it != cf->cache.end()) + { + charSize = (*it).second.charSize; + } + else + { + std::string text; + text.append({ch.c1, ch.c2, ch.c3}); + TTF_SizeUTF8(cf->font, text.c_str(), &charSize.x, &charSize.y); + } + + return charSize.x * width; +} + int CText::Justify(const std::string &text, std::vector::iterator format, std::vector::iterator end, @@ -636,11 +688,11 @@ UTF8Char CText::TranslateSpecialChar(int specialChar) void CText::DrawString(const std::string &text, std::vector::iterator format, std::vector::iterator end, - float size, Math::Point pos, float width, int eol, Color color) + float size, Math::IntPoint pos, int width, int eol, Color color) { m_engine->SetState(ENG_RSTATE_TEXT); - float start = pos.x; + int start = pos.x; unsigned int fmtIndex = 0; @@ -654,12 +706,12 @@ void CText::DrawString(const std::string &text, std::vector::itera UTF8Char ch = *it; - float offset = pos.x - start; - float cw = GetCharWidth(ch, font, size, offset); + int offset = pos.x - start; + int cw = GetCharWidthInt(ch, font, size, offset); if (offset + cw > width) // exceeds the maximum width? { ch = TranslateSpecialChar(CHAR_SKIP_RIGHT); - cw = GetCharWidth(ch, font, size, offset); + cw = GetCharWidthInt(ch, font, size, offset); pos.x = start + width - cw; color = Color(1.0f, 0.0f, 0.0f); DrawCharAndAdjustPos(ch, font, size, pos, color); @@ -700,9 +752,9 @@ void CText::DrawString(const std::string &text, std::vector::itera } else { - Math::Point charSize; - charSize.x = GetCharWidth(ch, font, size, offset); - charSize.y = GetHeight(font, size); + Math::IntPoint charSize; + charSize.x = GetCharWidthInt(ch, font, size, offset); + charSize.y = GetHeightInt(font, size); DrawHighlight(hl, pos, charSize); } } @@ -788,7 +840,7 @@ void CText::StringToUTFCharList(const std::string &text, std::vector & } void CText::DrawString(const std::string &text, FontType font, - float size, Math::Point pos, float width, int eol, Color color) + float size, Math::IntPoint pos, int width, int eol, Color color) { assert(font != FONT_BUTTON); @@ -802,7 +854,7 @@ void CText::DrawString(const std::string &text, FontType font, } } -void CText::DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size) +void CText::DrawHighlight(FontHighlight hl, Math::IntPoint pos, Math::IntPoint size) { // Gradient colors Color grad[4]; @@ -827,9 +879,9 @@ void CText::DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size) Math::IntPoint vsize = m_engine->GetWindowSize(); float h = 0.0f; if (vsize.y <= 768.0f) // 1024x768 or less? - h = 1.01f / vsize.y; // 1 pixel + h = 1.01f; // 1 pixel else // more than 1024x768? - h = 2.0f / vsize.y; // 2 pixels + h = 2.0f; // 2 pixels Math::Point p1, p2; p1.x = pos.x; @@ -856,22 +908,24 @@ void CText::DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size) VertexCol(Math::Vector(p2.x, p2.y, 0.0f), grad[1]) }; + m_engine->SetWindowCoordinates(); m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4); + m_engine->SetInterfaceCoordinates(); m_engine->AddStatisticTriangle(2); m_device->SetTextureEnabled(0, true); } -void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::Point &pos, Color color) +void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::IntPoint &pos, Color color) { - if(font == FONT_BUTTON) + if (font == FONT_BUTTON) { Math::IntPoint windowSize = m_engine->GetWindowSize(); - float height = GetHeight(FONT_COLOBOT, size); - float width = height*(static_cast(windowSize.y)/windowSize.x); + int height = GetHeightInt(FONT_COLOBOT, size); + int width = height * (static_cast(windowSize.y)/windowSize.x); - Math::Point p1(pos.x, pos.y); - Math::Point p2(pos.x + width, pos.y + height); + Math::IntPoint p1(pos.x, pos.y - height); + Math::IntPoint p2(pos.x + width, pos.y); Math::Vector n(0.0f, 0.0f, -1.0f); // normal @@ -909,13 +963,15 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P Vertex quad[4] = { - Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x, uv2.y)), - Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x, uv1.y)), - Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x, uv2.y)), - Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x, uv1.y)) + Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x, uv2.y)), + Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x, uv1.y)), + Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x, uv2.y)), + Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x, uv1.y)) }; + m_engine->SetWindowCoordinates(); m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4, color); + m_engine->SetInterfaceCoordinates(); m_engine->AddStatisticTriangle(2); pos.x += width; @@ -939,31 +995,31 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P CharTexture tex = GetCharTexture(ch, font, size); - Math::Point charInterfaceSize = m_engine->WindowToInterfaceSize(tex.charSize); - - Math::Point p1(pos.x, pos.y); - Math::Point p2(pos.x + charInterfaceSize.x, pos.y + charInterfaceSize.y); + Math::Point p1(pos.x, pos.y - tex.charSize.y); + Math::Point p2(pos.x + tex.charSize.x, pos.y); const float halfPixelMargin = 0.5f; Math::Point texCoord1(static_cast(tex.charPos.x + halfPixelMargin) / FONT_TEXTURE_SIZE.x, static_cast(tex.charPos.y + halfPixelMargin) / FONT_TEXTURE_SIZE.y); - Math::Point texCoord2(static_cast(tex.charPos.x + tex.charSize.x + halfPixelMargin) / FONT_TEXTURE_SIZE.x, - static_cast(tex.charPos.y + tex.charSize.y + halfPixelMargin) / FONT_TEXTURE_SIZE.y); + Math::Point texCoord2(static_cast(tex.charPos.x + tex.charSize.x - halfPixelMargin) / FONT_TEXTURE_SIZE.x, + static_cast(tex.charPos.y + tex.charSize.y - halfPixelMargin) / FONT_TEXTURE_SIZE.y); Math::Vector n(0.0f, 0.0f, -1.0f); // normal Vertex quad[4] = { - Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(texCoord1.x, texCoord2.y)), - Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(texCoord1.x, texCoord1.y)), - Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(texCoord2.x, texCoord2.y)), - Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(texCoord2.x, texCoord1.y)) + Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(texCoord1.x, texCoord2.y)), + Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(texCoord1.x, texCoord1.y)), + Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(texCoord2.x, texCoord2.y)), + Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(texCoord2.x, texCoord1.y)) }; m_device->SetTexture(0, tex.id); + m_engine->SetWindowCoordinates(); m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4, color); + m_engine->SetInterfaceCoordinates(); m_engine->AddStatisticTriangle(2); - pos.x += charInterfaceSize.x * width; + pos.x += tex.charSize.x * width; } } @@ -1063,8 +1119,8 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font) } const int pixelMargin = 1; - Math::IntPoint tileSize(Math::NextPowerOfTwo(textSurface->w) + pixelMargin, - Math::NextPowerOfTwo(textSurface->h) + pixelMargin); + Math::IntPoint tileSize(Math::Max(16, Math::NextPowerOfTwo(textSurface->w)) + pixelMargin, + Math::Max(16, Math::NextPowerOfTwo(textSurface->h)) + pixelMargin); FontTexture* fontTexture = GetOrCreateFontTexture(tileSize); diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index 6ee0a862..909dada5 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -281,6 +281,7 @@ public: float GetDescent(FontType font, float size); //! Returns the height font metric float GetHeight(FontType font, float size); + int GetHeightInt(FontType font, float size); //! Returns width of string (multi-format) TEST_VIRTUAL float GetStringWidth(const std::string& text, @@ -290,6 +291,7 @@ public: TEST_VIRTUAL float GetStringWidth(std::string text, FontType font, float size); //! Returns width of single character TEST_VIRTUAL float GetCharWidth(UTF8Char ch, FontType font, float size, float offset); + int GetCharWidthInt(UTF8Char ch, FontType font, float size, float offset); //! Justifies a line of text (multi-format) int Justify(const std::string &text, std::vector::iterator format, @@ -319,11 +321,11 @@ protected: void DrawString(const std::string &text, std::vector::iterator format, std::vector::iterator end, - float size, Math::Point pos, float width, int eol, Color color); + float size, Math::IntPoint pos, int width, int eol, Color color); void DrawString(const std::string &text, FontType font, - float size, Math::Point pos, float width, int eol, Color color); - void DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size); - void DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::Point &pos, Color color); + float size, Math::IntPoint pos, int width, int eol, Color color); + void DrawHighlight(FontHighlight hl, Math::IntPoint pos, Math::IntPoint size); + void DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::IntPoint &pos, Color color); void StringToUTFCharList(const std::string &text, std::vector &chars); void StringToUTFCharList(const std::string &text, std::vector &chars, std::vector::iterator format, std::vector::iterator end); From 0d12dedd90ab3826220f80c6408dd75f5f9f4381 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 7 Apr 2016 20:21:35 +0200 Subject: [PATCH 043/125] Fixed failed assertion when non-damageable objects get fall damage (closes #764) --- src/physics/physics.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index e4013bb9..8fcc08c3 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -1577,10 +1577,13 @@ bool CPhysics::EventFrame(const Event &event) if ( m_bLand && m_fallingHeight != 0.0f ) // if fell { - float force = (m_fallingHeight - m_object->GetPosition().y) * m_fallDamageFraction; - if (m_object->DamageObject(DamageType::Fall, force)) + if (m_object->Implements(ObjectInterfaceType::Damageable)) { - return false; // ugly hack, but works for 0.1.6 release :/ + float force = (m_fallingHeight - m_object->GetPosition().y) * m_fallDamageFraction; + if (m_object->DamageObject(DamageType::Fall, force)) + { + return false; // ugly hack, but works for 0.1.6 release :/ + } } m_fallingHeight = 0.0f; } From ac950978a9042b73533694a389e5723400283282 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 7 Apr 2016 20:30:25 +0200 Subject: [PATCH 044/125] Fixed AlienWorm collisions (#740) --- src/object/object.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/object/object.cpp b/src/object/object.cpp index 44466012..6685dd3d 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -114,7 +114,8 @@ std::vector CObject::GetAllCrashSpheres() bool CObject::CanCollideWith(CObject* other) { ObjectType otherType = other->GetType(); - if (m_type == OBJECT_WORM) return otherType == OBJECT_WORM; + if (m_type == OBJECT_WORM) return false; + if (otherType == OBJECT_WORM) return false; if (m_type == OBJECT_MOTHER) { if (otherType == OBJECT_ANT) return false; From efc5431da2a68af6c7f14973893075fc78cf01a4 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 7 Apr 2016 21:28:16 +0200 Subject: [PATCH 045/125] Enabled ArraysInClasses test after 1941020993d740c7dc90762a9dbf788916729e63 --- test/unit/CBot/CBot_test.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/unit/CBot/CBot_test.cpp b/test/unit/CBot/CBot_test.cpp index b4e1bbb6..63c3e918 100644 --- a/test/unit/CBot/CBot_test.cpp +++ b/test/unit/CBot/CBot_test.cpp @@ -524,8 +524,7 @@ TEST_F(CBotUT, Arrays) ); } -// TODO: BAD! WRONG! NOOOOO!!! :< -TEST_F(CBotUT, DISABLED_ArraysInClasses) +TEST_F(CBotUT, ArraysInClasses) { ExecuteTest( "public class TestClass {\n" @@ -533,9 +532,9 @@ TEST_F(CBotUT, DISABLED_ArraysInClasses) " private int test2[5];\n" " \n" " public void TestClass() {\n" - " ASSERT(sizeof(test) == 0);\n" // TODO: NOT INITIALIZED - " ASSERT(sizeof(this.test) == 0);\n" // TODO: NOT INITIALIZED - " ASSERT(test == null);\n" // TODO: Again, not sure // TODO: NOT INITIALIZED + " ASSERT(sizeof(test) == 0);\n" + " ASSERT(sizeof(this.test) == 0);\n" + " ASSERT(test == null);\n" // TODO: Again, not sure " test[0] = 5;\n" " this.test[1] = 5;\n" " ASSERT(sizeof(test) == 2);\n" From c6c01c332fd2a60beea1c6179af065c2007ed852 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 8 Apr 2016 21:23:11 +1200 Subject: [PATCH 046/125] Fix displaying of text highlights (#738) --- src/graphics/engine/text.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 0af5723a..4fcf4acc 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -885,27 +885,23 @@ void CText::DrawHighlight(FontHighlight hl, Math::IntPoint pos, Math::IntPoint s Math::Point p1, p2; p1.x = pos.x; + p1.y = pos.y - size.y; p2.x = pos.x + size.x; + p2.y = pos.y; if (hl == FONT_HIGHLIGHT_LINK) { - p1.y = pos.y; - p2.y = pos.y + h; // just emphasized - } - else - { - p1.y = pos.y; - p2.y = pos.y + size.y; + p1.y = pos.y - h; // just emphasized } m_device->SetTextureEnabled(0, false); VertexCol quad[] = { - VertexCol(Math::Vector(p1.x, p1.y, 0.0f), grad[3]), - VertexCol(Math::Vector(p1.x, p2.y, 0.0f), grad[0]), - VertexCol(Math::Vector(p2.x, p1.y, 0.0f), grad[2]), - VertexCol(Math::Vector(p2.x, p2.y, 0.0f), grad[1]) + VertexCol(Math::Vector(p1.x, p2.y, 0.0f), grad[3]), + VertexCol(Math::Vector(p1.x, p1.y, 0.0f), grad[0]), + VertexCol(Math::Vector(p2.x, p2.y, 0.0f), grad[2]), + VertexCol(Math::Vector(p2.x, p1.y, 0.0f), grad[1]) }; m_engine->SetWindowCoordinates(); From ae4e875729e6d2fddbf3a75349427d3c08a33dbf Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 8 Apr 2016 18:28:35 +0200 Subject: [PATCH 047/125] Do not store exact object part positions This seems to be unnecessary, as the animation update code should set those on its own. Needs some more testing though. --- src/level/robotmain.cpp | 55 ++-------------------------------- src/object/task/taskshield.cpp | 13 +++++++- 2 files changed, 14 insertions(+), 54 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 274118b7..4fa11f3a 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -4529,33 +4529,6 @@ void CRobotMain::IOWriteObject(CLevelParserLine* line, CObject* obj, const std:: if (obj->Implements(ObjectInterfaceType::Old)) { - COldObject* oldObj = dynamic_cast(obj); - - for (int i = 1; i < OBJECTMAXPART; i++) - { - if (oldObj->GetObjectRank(i) == -1) continue; - - Math::Vector pos = oldObj->GetPartPosition(i); - if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f) - { - pos /= g_unit; - line->AddParam("p" + boost::lexical_cast(i), MakeUnique(pos)); - } - - Math::Vector rot = oldObj->GetPartRotation(i); - if (rot.x != 0.0f || rot.y != 0.0f || rot.z != 0.0f) - { - rot /= (Math::PI/180.0f); - line->AddParam("a" + boost::lexical_cast(i), MakeUnique(rot)); - } - - Math::Vector scale = oldObj->GetPartScale(i); - if (scale.x != 1.0f || scale.y != 1.0f || scale.z != 1.0f) - { - line->AddParam("z" + boost::lexical_cast(i), MakeUnique(scale)); - } - } - line->AddParam("option", MakeUnique(obj->GetOption())); } @@ -4576,7 +4549,7 @@ void CRobotMain::IOWriteObject(CLevelParserLine* line, CObject* obj, const std:: if (obj->Implements(ObjectInterfaceType::ProgramStorage)) { CProgramStorageObject* programStorage = dynamic_cast(obj); - if(programStorage->GetProgramStorageIndex() >= 0) + if (programStorage->GetProgramStorageIndex() >= 0) { programStorage->SaveAllProgramsForSavedScene(line, programDir); } @@ -4772,32 +4745,8 @@ CObject* CRobotMain::IOReadObject(CLevelParserLine *line, const std::string& pro if (obj->Implements(ObjectInterfaceType::Old)) { COldObject* oldObj = dynamic_cast(obj); - oldObj->SetPosition(line->GetParam("pos")->AsPoint() * g_unit); oldObj->SetRotation(line->GetParam("angle")->AsPoint() * Math::DEG_TO_RAD); - - for (int i = 1; i < OBJECTMAXPART; i++) - { - if (oldObj->GetObjectRank(i) == -1) continue; - - Math::Vector pos = line->GetParam(std::string("p")+boost::lexical_cast(i))->AsPoint(Math::Vector()); - if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f) - { - oldObj->SetPartPosition(i, pos*g_unit); - } - - Math::Vector dir = line->GetParam(std::string("a")+boost::lexical_cast(i))->AsPoint(Math::Vector()); - if (dir.x != 0.0f || dir.y != 0.0f || dir.z != 0.0f) - { - oldObj->SetPartRotation(i, dir*(Math::PI/180.0f)); - } - - Math::Vector zoom = line->GetParam(std::string("z")+boost::lexical_cast(i))->AsPoint(Math::Vector()); - if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f) - { - oldObj->SetPartScale(i, zoom); - } - } } if (obj->GetType() == OBJECT_BASE) m_base = obj; @@ -4815,7 +4764,7 @@ CObject* CRobotMain::IOReadObject(CLevelParserLine *line, const std::string& pro if (obj->Implements(ObjectInterfaceType::ProgramStorage)) { CProgramStorageObject* programStorage = dynamic_cast(obj); - if (!line->GetParam("programStorageIndex")->IsDefined()) // Backwards combatibility + if (!line->GetParam("programStorageIndex")->IsDefined()) // Backwards compatibility programStorage->SetProgramStorageIndex(objRank); programStorage->LoadAllProgramsForSavedScene(line, programDir); } diff --git a/src/object/task/taskshield.cpp b/src/object/task/taskshield.cpp index 7f2baa08..09e1da40 100644 --- a/src/object/task/taskshield.cpp +++ b/src/object/task/taskshield.cpp @@ -258,10 +258,21 @@ Error CTaskShield::Start(TaskShieldMode mode, float delay) if ( mode == TSM_START ) { + Math::Vector pos; Math::Point dim; + pos.x = 7.0f; + pos.y = 4.5f+3.0f; + pos.z = 0.0f; + m_object->SetPartPosition(2, pos); + + pos.x = 0.0f; + pos.y = 1.0f+3.0f; + pos.z = 0.0f; + m_object->SetPartPosition(3, pos); + Math::Matrix* mat = m_object->GetWorldMatrix(0); - Math::Vector pos = Math::Vector(7.0f, 15.0f, 0.0f); + pos = Math::Vector(7.0f, 15.0f, 0.0f); pos = Transform(*mat, pos); // sphere position m_shieldPos = pos; From 4c8da2c5036fc8a9ab0123b7f0a29a2a15eb260d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 8 Apr 2016 20:56:09 +0200 Subject: [PATCH 048/125] LevelController improvements; minor EndMissionTake cleanup * using LevelController script in the level doesn't forcefully disable EndMissionTake and AudioChange anymore * cleaned up some code related to processing EndMissionTake commands --- src/level/robotmain.cpp | 220 ++++++++++++++++++----------------- src/level/robotmain.h | 9 +- src/level/scene_conditions.h | 1 + src/script/scriptfunc.cpp | 2 +- 4 files changed, 123 insertions(+), 109 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 274118b7..b3c34de1 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -1236,19 +1236,22 @@ void CRobotMain::ExecuteCmd(const std::string& cmd) if (cmd == "controller") { - if (m_controller != nullptr) + if (m_controller == nullptr) { - // Don't use SelectObject because it checks if the object is selectable - if (m_camera->GetType() == Gfx::CAM_TYPE_VISIT) - StopDisplayVisit(); - - CObject* prev = DeselectAll(); - if (prev != nullptr && prev != m_controller) - PushToSelectionHistory(prev); - - SelectOneObject(m_controller, true); - m_short->UpdateShortcuts(); + GetLogger()->Error("No LevelController on the map to select\n"); + return; } + + // Don't use SelectObject because it checks if the object is selectable + if (m_camera->GetType() == Gfx::CAM_TYPE_VISIT) + StopDisplayVisit(); + + CObject* prev = DeselectAll(); + if (prev != nullptr && prev != m_controller) + PushToSelectionHistory(prev); + + SelectOneObject(m_controller, true); + m_short->UpdateShortcuts(); return; } @@ -2831,6 +2834,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_endingLostRank = 0; m_audioChange.clear(); m_endTake.clear(); + m_endTakeImmediat = false; m_endTakeResearch = 0; m_endTakeWinDelay = 2.0f; m_endTakeLostDelay = 2.0f; @@ -2870,6 +2874,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_teamNames.clear(); m_missionResult = ERR_MISSION_NOTERM; + m_missionResultFromScript = false; } //NOTE: Reset timer always, even when only resetting object positions @@ -2999,7 +3004,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) continue; } - if (line->GetCommand() == "AudioChange" && !resetObject && m_controller == nullptr) + if (line->GetCommand() == "AudioChange" && !resetObject) { auto audioChange = MakeUnique(); audioChange->Read(line.get()); @@ -3009,7 +3014,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) continue; } - if (line->GetCommand() == "Audio" && !resetObject && m_controller == nullptr) + if (line->GetCommand() == "Audio" && !resetObject) { if (line->GetParam("track")->IsDefined()) { @@ -3410,6 +3415,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (line->GetCommand() == "LevelController" && m_sceneReadPath.empty()) { + if (m_controller != nullptr) + { + throw CLevelParserException("There can be only one LevelController in the level"); + } + m_controller = m_objMan->CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, OBJECT_CONTROLLER); assert(m_controller->Implements(ObjectInterfaceType::Programmable)); assert(m_controller->Implements(ObjectInterfaceType::ProgramStorage)); @@ -3625,26 +3635,28 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) continue; } - if (line->GetCommand() == "EndMissionTake" && !resetObject && m_controller == nullptr) + if (line->GetCommand() == "EndMissionTake" && !resetObject) { auto endTake = MakeUnique(); endTake->Read(line.get()); + if (endTake->immediat) + m_endTakeImmediat = true; m_endTake.push_back(std::move(endTake)); continue; } - if (line->GetCommand() == "EndMissionDelay" && !resetObject && m_controller == nullptr) + if (line->GetCommand() == "EndMissionDelay" && !resetObject) { m_endTakeWinDelay = line->GetParam("win")->AsFloat(2.0f); m_endTakeLostDelay = line->GetParam("lost")->AsFloat(2.0f); continue; } - if (line->GetCommand() == "EndMissionResearch" && !resetObject && m_controller == nullptr) //TODO: Is this used anywhere? + if (line->GetCommand() == "EndMissionResearch" && !resetObject) // This is not used in any original Colobot levels, but we'll keep it for userlevel creators { m_endTakeResearch |= line->GetParam("type")->AsResearchFlag(); continue; } - if (line->GetCommand() == "ObligatoryToken" && !resetObject) //NOTE: This was used only in CeeBot, maybe we should add this to some Colobot exercises? + if (line->GetCommand() == "ObligatoryToken" && !resetObject) // NOTE: This was used only in CeeBot, maybe we should add this to some Colobot exercises? { int i = m_obligatoryTotal; if (i < 100) //TODO: remove the limit @@ -3655,7 +3667,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) continue; } - if (line->GetCommand() == "ProhibitedToken" && !resetObject) //NOTE: This was used only in CeeBot, maybe we should add this to some Colobot exercises? + if (line->GetCommand() == "ProhibitedToken" && !resetObject) // NOTE: This was used only in CeeBot, maybe we should add this to some Colobot exercises? { int i = m_prohibitedTotal; if (i < 100) //TODO: remove the limit @@ -5008,17 +5020,16 @@ void CRobotMain::UpdateAudio(bool frame) } } -void CRobotMain::SetEndMission(Error result, float delay) +//! Set mission result from LevelController script +void CRobotMain::SetMissionResultFromScript(Error result, float delay) { - if (m_controller != nullptr) - { - m_endTakeWinDelay = delay; - m_endTakeLostDelay = delay; - m_missionResult = result; - } + m_endTakeWinDelay = delay; + m_endTakeLostDelay = delay; + m_missionResult = result; + m_missionResultFromScript = true; } -Error CRobotMain::CheckEndMissionForGroup(std::vector& endTakes) +Error CRobotMain::ProcessEndMissionTakeForGroup(std::vector& endTakes) { Error finalResult = ERR_OK; bool hasWinningConditions = false; @@ -5045,104 +5056,101 @@ Error CRobotMain::CheckEndMissionForGroup(std::vector& endT return finalResult; } -//! Checks if the mission is over -Error CRobotMain::CheckEndMission(bool frame) +Error CRobotMain::ProcessEndMissionTake() { - bool isImmediat = false; - // Process EndMissionTake, unless we are using MissionController - if (m_controller == nullptr) + // Sort end conditions by teams + std::map> teams; + for (std::unique_ptr& endTake : m_endTake) + teams[endTake->winTeam].push_back(endTake.get()); + + int teamCount = 0; + bool usesTeamConditions = false; + for (auto it : teams) { - // Sort end conditions by teams - std::map> teams; - for (std::unique_ptr& endTake : m_endTake) - { - teams[endTake->winTeam].push_back(endTake.get()); - if(endTake->immediat) - isImmediat = true; - } + int team = it.first; + if (team == 0) continue; + usesTeamConditions = true; + if (!m_objMan->TeamExists(team)) continue; + teamCount++; + } - int teamCount = 0; - bool usesTeamConditions = false; - for (auto it : teams) - { - int team = it.first; - if(team == 0) continue; - usesTeamConditions = true; - if(!m_objMan->TeamExists(team)) continue; - teamCount++; - } + if (!usesTeamConditions) + { + m_missionResult = ProcessEndMissionTakeForGroup(teams[0]); + } + else + { + // Special handling for teams + m_missionResult = ERR_MISSION_NOTERM; - if (!usesTeamConditions) + if (teamCount == 0) { - m_missionResult = CheckEndMissionForGroup(teams[0]); + GetLogger()->Info("All teams died, mission ended with failure\n"); + m_missionResult = INFO_LOST; } else { - // Special handling for teams - m_missionResult = ERR_MISSION_NOTERM; + for (auto it : teams) + { + int team = it.first; + if (team == 0) continue; + if (!m_objMan->TeamExists(team)) continue; - if (teamCount == 0) - { - GetLogger()->Info("All teams died, mission ended with failure\n"); - m_missionResult = INFO_LOST; - } - else - { - for (auto it : teams) + Error result = ProcessEndMissionTakeForGroup(it.second); + if (result == INFO_LOST || result == INFO_LOSTq) { - int team = it.first; - if (team == 0) continue; - if (!m_objMan->TeamExists(team)) continue; + GetLogger()->Info("Team %d lost\n", team); + m_displayText->DisplayText(("<<< Team "+boost::lexical_cast(team)+" lost! >>>").c_str(), Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 10.0f, Ui::TT_ERROR); - Error result = CheckEndMissionForGroup(it.second); - if (result == INFO_LOST || result == INFO_LOSTq) - { - GetLogger()->Info("Team %d lost\n", team); - m_displayText->DisplayText(("<<< Team "+boost::lexical_cast(team)+" lost! >>>").c_str(), Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 10.0f, Ui::TT_ERROR); - - m_displayText->SetEnable(false); // To prevent "bot destroyed" messages - m_objMan->DestroyTeam(team); - m_displayText->SetEnable(true); - } - else if(result == ERR_OK) - { - if (m_winDelay == 0.0f) - { - GetLogger()->Info("Team %d won\n", team); - - m_displayText->DisplayText(("<<< Team "+boost::lexical_cast(team)+" won the game >>>").c_str(), Math::Vector(0.0f,0.0f,0.0f)); - if (m_missionTimerEnabled && m_missionTimerStarted) - { - GetLogger()->Info("Mission time: %s\n", TimeFormat(m_missionTimer).c_str()); - m_displayText->DisplayText(("Time: " + TimeFormat(m_missionTimer)).c_str(), Math::Vector(0.0f,0.0f,0.0f)); - } - m_missionTimerEnabled = m_missionTimerStarted = false; - m_winDelay = m_endTakeWinDelay; // wins in two seconds - m_lostDelay = 0.0f; - m_displayText->SetEnable(false); - } - m_missionResult = ERR_OK; - return ERR_OK; - } + m_displayText->SetEnable(false); // To prevent "bot destroyed" messages + m_objMan->DestroyTeam(team); + m_displayText->SetEnable(true); } - } - } - - if (m_missionResult != INFO_LOST && m_missionResult != INFO_LOSTq) - { - if (m_endTakeResearch != 0) - { - if (m_endTakeResearch != (m_endTakeResearch&m_researchDone[0])) + else if (result == ERR_OK) { - m_missionResult = ERR_MISSION_NOTERM; + if (m_winDelay == 0.0f) + { + GetLogger()->Info("Team %d won\n", team); + + m_displayText->DisplayText(("<<< Team "+boost::lexical_cast(team)+" won the game >>>").c_str(), Math::Vector(0.0f,0.0f,0.0f)); + if (m_missionTimerEnabled && m_missionTimerStarted) + { + GetLogger()->Info("Mission time: %s\n", TimeFormat(m_missionTimer).c_str()); + m_displayText->DisplayText(("Time: " + TimeFormat(m_missionTimer)).c_str(), Math::Vector(0.0f,0.0f,0.0f)); + } + m_missionTimerEnabled = m_missionTimerStarted = false; + m_winDelay = m_endTakeWinDelay; // wins in two seconds + m_lostDelay = 0.0f; + m_displayText->SetEnable(false); + } + m_missionResult = ERR_OK; + return ERR_OK; } } } } + if (m_missionResult != INFO_LOST && m_missionResult != INFO_LOSTq) + { + if (m_endTakeResearch != 0) + { + if (m_endTakeResearch != (m_endTakeResearch&m_researchDone[0])) + { + m_missionResult = ERR_MISSION_NOTERM; + } + } + } +} + +//! Checks if the mission is over +Error CRobotMain::CheckEndMission(bool frame) +{ + // Process EndMissionTake, unless we are using LevelController script for processing ending conditions + if (!m_missionResultFromScript) ProcessEndMissionTake(); + // Take action depending on m_missionResult - if(m_missionResult == INFO_LOSTq) + if (m_missionResult == INFO_LOSTq) { if (m_lostDelay == 0.0f) { @@ -5154,7 +5162,7 @@ Error CRobotMain::CheckEndMission(bool frame) return INFO_LOSTq; } - if(m_missionResult == INFO_LOST) + if (m_missionResult == INFO_LOST) { if (m_lostDelay == 0.0f) { @@ -5180,7 +5188,7 @@ Error CRobotMain::CheckEndMission(bool frame) if (frame) { - if(m_base != nullptr && !isImmediat) + if (m_base != nullptr && !m_endTakeImmediat) { assert(m_base->Implements(ObjectInterfaceType::Controllable)); if(dynamic_cast(m_base)->GetSelectable()) diff --git a/src/level/robotmain.h b/src/level/robotmain.h index deea9e82..4f78df3d 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -195,9 +195,10 @@ public: void ResetObject(); void UpdateAudio(bool frame); - void SetEndMission(Error result, float delay); + void SetMissionResultFromScript(Error result, float delay); Error CheckEndMission(bool frame); - Error CheckEndMissionForGroup(std::vector& endTakes); + Error ProcessEndMissionTake(); + Error ProcessEndMissionTakeForGroup(std::vector& endTakes); int GetObligatoryToken(); char* GetObligatoryToken(int i); int IsObligatoryToken(const char* token); @@ -543,6 +544,8 @@ protected: ActivePause* m_visitPause = nullptr; std::vector> m_endTake; + //! If true, the mission ends immediately after completing the requirements without requiring SpaceShip takeoff + bool m_endTakeImmediat = false; long m_endTakeResearch = 0; float m_endTakeWinDelay = 0.0f; float m_endTakeLostDelay = 0.0f; @@ -562,6 +565,8 @@ protected: std::map m_researchDone; Error m_missionResult = ERR_OK; + //! true if m_missionResult has been set by LevelController script, this disables normal EndMissionTake processing + bool m_missionResultFromScript = false; ShowLimit m_showLimit[MAXSHOWLIMIT]; diff --git a/src/level/scene_conditions.h b/src/level/scene_conditions.h index 33a65088..258cc7ef 100644 --- a/src/level/scene_conditions.h +++ b/src/level/scene_conditions.h @@ -77,6 +77,7 @@ public: int lost = -1; // lost if <= + //! If this is true, the mission ends as soon as this requirement is met, without having to complete the others bool immediat = false; //! Read from line in scene file diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp index d072c79a..e4da1f16 100644 --- a/src/script/scriptfunc.cpp +++ b/src/script/scriptfunc.cpp @@ -204,7 +204,7 @@ bool CScriptFunctions::rEndMission(CBotVar* var, CBotVar* result, int& exception delay = var->GetValFloat(); - CRobotMain::GetInstancePointer()->SetEndMission(ended, delay); + CRobotMain::GetInstancePointer()->SetMissionResultFromScript(ended, delay); return true; } From ed58e7e012b61d1b24c445ab058080afd786ca4d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 8 Apr 2016 21:16:03 +0200 Subject: [PATCH 049/125] Fix compile warning --- src/level/robotmain.cpp | 3 ++- src/level/robotmain.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index b3c34de1..848804f7 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -5056,7 +5056,8 @@ Error CRobotMain::ProcessEndMissionTakeForGroup(std::vector return finalResult; } -Error CRobotMain::ProcessEndMissionTake() +//! Process EndMissionTake commands, result is stored in m_missionResult +void CRobotMain::ProcessEndMissionTake() { // Sort end conditions by teams std::map> teams; diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 4f78df3d..d3294b3e 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -197,7 +197,7 @@ public: void UpdateAudio(bool frame); void SetMissionResultFromScript(Error result, float delay); Error CheckEndMission(bool frame); - Error ProcessEndMissionTake(); + void ProcessEndMissionTake(); Error ProcessEndMissionTakeForGroup(std::vector& endTakes); int GetObligatoryToken(); char* GetObligatoryToken(int i); From 3e4fbe93a6c37ecfbe2a2c3b7202905a105c4191 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 8 Apr 2016 21:18:45 +0200 Subject: [PATCH 050/125] This time really fixed compile errors --- src/level/robotmain.cpp | 11 +++++++++-- src/level/robotmain.h | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 848804f7..07b64bbc 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -5057,7 +5057,8 @@ Error CRobotMain::ProcessEndMissionTakeForGroup(std::vector } //! Process EndMissionTake commands, result is stored in m_missionResult -void CRobotMain::ProcessEndMissionTake() +//! If return value is different than ERR_MISSION_NOTERM, assume the mission is finished and pass on the result +Error CRobotMain::ProcessEndMissionTake() { // Sort end conditions by teams std::map> teams; @@ -5141,13 +5142,19 @@ void CRobotMain::ProcessEndMissionTake() } } } + + return ERR_MISSION_NOTERM; } //! Checks if the mission is over Error CRobotMain::CheckEndMission(bool frame) { // Process EndMissionTake, unless we are using LevelController script for processing ending conditions - if (!m_missionResultFromScript) ProcessEndMissionTake(); + if (!m_missionResultFromScript) + { + Error result = ProcessEndMissionTake(); + if (result != ERR_MISSION_NOTERM) return result; + } // Take action depending on m_missionResult diff --git a/src/level/robotmain.h b/src/level/robotmain.h index d3294b3e..4f78df3d 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -197,7 +197,7 @@ public: void UpdateAudio(bool frame); void SetMissionResultFromScript(Error result, float delay); Error CheckEndMission(bool frame); - void ProcessEndMissionTake(); + Error ProcessEndMissionTake(); Error ProcessEndMissionTakeForGroup(std::vector& endTakes); int GetObligatoryToken(); char* GetObligatoryToken(int i); From 7f38aca7660f5ba80a259537d9bee7c0cecdb3f1 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 8 Apr 2016 22:15:54 +0200 Subject: [PATCH 051/125] Improvements to ObligatoryToken/ProhibitedToken Now you can specify exactly how many times given instruction can occur --- po/colobot.pot | 12 ++++--- po/de.po | 24 +++++++++----- po/fr.po | 24 +++++++++----- po/pl.po | 24 +++++++++----- po/ru.po | 24 +++++++++----- src/common/restext.cpp | 4 +-- src/level/robotmain.cpp | 69 ++++++++++++++--------------------------- src/level/robotmain.h | 16 +++++----- src/script/script.cpp | 58 ++++++++++++++++++---------------- src/script/script.h | 3 +- 10 files changed, 143 insertions(+), 115 deletions(-) diff --git a/po/colobot.pot b/po/colobot.pot index 1c4e61ef..442beb45 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -611,13 +611,13 @@ msgstr "" msgid "\\Face 1" msgstr "" -msgid "\\Face 4" +msgid "\\Face 2" msgstr "" msgid "\\Face 3" msgstr "" -msgid "\\Face 2" +msgid "\\Face 4" msgstr "" msgid "\\No eyeglasses" @@ -1519,10 +1519,11 @@ msgid "Unable to control enemy objects" msgstr "" #, c-format -msgid "\"%s\" missing in this exercise" +msgid "You have to use \"%s\" at least %d times in this exercise (used: %d)" msgstr "" -msgid "Do not use in this exercise" +#, c-format +msgid "You have to use \"%s\" at most %d times in this exercise (used: %d)" msgstr "" msgid "Inappropriate bot" @@ -1738,6 +1739,9 @@ msgstr "" msgid "Public required" msgstr "" +msgid "expression expected after =" +msgstr "" + msgid "Dividing by zero" msgstr "" diff --git a/po/de.po b/po/de.po index d008dfa3..300d209c 100644 --- a/po/de.po +++ b/po/de.po @@ -61,10 +61,6 @@ msgstr "Es fehlt eine offene eckige Klammer \" [ \"" msgid "\" ] \" missing" msgstr "Es fehlt eine geschlossene eckige Klammer \" ] \"" -#, c-format -msgid "\"%s\" missing in this exercise" -msgstr "Es fehlt \"%s\" in Ihrem Programm" - msgid "..behind" msgstr "..hinten" @@ -491,9 +487,6 @@ msgstr "Bildschirm\\Driver und Bildschirmauflösung" msgid "Dividing by zero" msgstr "Teilung durch Null" -msgid "Do not use in this exercise" -msgstr "In dieser Übung verboten" - msgid "Do you really want to destroy the selected building?" msgstr "Wollen Sie das angewählte Gebäude wirklich zerstören ?" @@ -1715,6 +1708,14 @@ msgstr "Sie können unter Wasser nichts tragen" msgid "You found a usable object" msgstr "Sie haben ein brauchbares Objekt gefunden" +#, c-format +msgid "You have to use \"%s\" at least %d times in this exercise (used: %d)" +msgstr "" + +#, c-format +msgid "You have to use \"%s\" at most %d times in this exercise (used: %d)" +msgstr "" + msgid "You must get on the spaceship to take off " msgstr "Gehen Sie an Bord, bevor Sie abheben" @@ -1821,6 +1822,9 @@ msgstr "" msgid "epsitec.com" msgstr "www.epsitec.com" +msgid "expression expected after =" +msgstr "" + #~ msgid " " #~ msgstr " " @@ -1830,6 +1834,9 @@ msgstr "www.epsitec.com" #~ msgid " Missions on this level:" #~ msgstr " Missionen des Userlevels:" +#~ msgid "\"%s\" missing in this exercise" +#~ msgstr "Es fehlt \"%s\" in Ihrem Programm" + #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "3D-Geräusche\\Orten der Geräusche im Raum" @@ -1863,6 +1870,9 @@ msgstr "www.epsitec.com" #~ msgid "Developed by :" #~ msgstr "Entwickelt von:" +#~ msgid "Do not use in this exercise" +#~ msgstr "In dieser Übung verboten" + #, fuzzy #~ msgid "Do you want to quit Colobot: Gold Edition?" #~ msgstr "Wollen Sie COLOBOT schließen ?" diff --git a/po/fr.po b/po/fr.po index 5db35d47..a57ce326 100644 --- a/po/fr.po +++ b/po/fr.po @@ -54,10 +54,6 @@ msgstr "\" [ \" attendu" msgid "\" ] \" missing" msgstr "\" ] \" attendu" -#, c-format -msgid "\"%s\" missing in this exercise" -msgstr "Il manque \"%s\" dans le programme" - msgid "..behind" msgstr "..derrière" @@ -486,9 +482,6 @@ msgstr "Affichage\\Pilote et résolution d'affichage" msgid "Dividing by zero" msgstr "Division par zéro" -msgid "Do not use in this exercise" -msgstr "Interdit dans cet exercice" - msgid "Do you really want to destroy the selected building?" msgstr "Voulez-vous vraiment détruire le bâtiment sélectionné ?" @@ -1701,6 +1694,14 @@ msgstr "Vous ne pouvez pas transporter un objet sous l'eau" msgid "You found a usable object" msgstr "Vous avez trouvé un objet utilisable" +#, c-format +msgid "You have to use \"%s\" at least %d times in this exercise (used: %d)" +msgstr "" + +#, c-format +msgid "You have to use \"%s\" at most %d times in this exercise (used: %d)" +msgstr "" + msgid "You must get on the spaceship to take off " msgstr "Vous devez embarquer pour pouvoir décoller" @@ -1806,6 +1807,9 @@ msgstr "colobot.info" msgid "epsitec.com" msgstr "epsitec.com" +msgid "expression expected after =" +msgstr "" + #~ msgid " " #~ msgstr " " @@ -1815,6 +1819,9 @@ msgstr "epsitec.com" #~ msgid " Missions on this level:" #~ msgstr " Missions du niveau :" +#~ msgid "\"%s\" missing in this exercise" +#~ msgstr "Il manque \"%s\" dans le programme" + #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "Bruitages 3D\\Positionnement sonore dans l'espace" @@ -1848,6 +1855,9 @@ msgstr "epsitec.com" #~ msgid "Developed by :" #~ msgstr "Développé par :" +#~ msgid "Do not use in this exercise" +#~ msgstr "Interdit dans cet exercice" + #, fuzzy #~ msgid "Do you want to quit Colobot: Gold Edition?" #~ msgstr "Voulez-vous quitter COLOBOT ?" diff --git a/po/pl.po b/po/pl.po index b4f079c2..5bc0a58d 100644 --- a/po/pl.po +++ b/po/pl.po @@ -60,10 +60,6 @@ msgstr "Oczekiwane \" [ \"" msgid "\" ] \" missing" msgstr "Brak \" ] \"" -#, c-format -msgid "\"%s\" missing in this exercise" -msgstr "Brakuje \"%s\" w tym ćwiczeniu" - msgid "..behind" msgstr "..za" @@ -492,9 +488,6 @@ msgstr "Urządzenie\\Ustawienia sterownika i rozdzielczości" msgid "Dividing by zero" msgstr "Dzielenie przez zero" -msgid "Do not use in this exercise" -msgstr "Do not use in this exercise" - msgid "Do you really want to destroy the selected building?" msgstr "Czy na pewno chcesz zniszczyć zaznaczony budynek?" @@ -1709,6 +1702,14 @@ msgstr "Nie możesz przenosić przedmiotów pod wodą" msgid "You found a usable object" msgstr "Znaleziono użyteczny przedmiot" +#, c-format +msgid "You have to use \"%s\" at least %d times in this exercise (used: %d)" +msgstr "Musisz użyć \"%s\" przynajmniej %d razy w tym ćwiczeniu (użyto: %d)" + +#, c-format +msgid "You have to use \"%s\" at most %d times in this exercise (used: %d)" +msgstr "Musisz użyć \"%s\" najwyżej %d razy w tym ćwiczeniu (użyto: %d)" + msgid "You must get on the spaceship to take off " msgstr "Musisz być na statku kosmicznym aby nim odlecieć" @@ -1814,9 +1815,15 @@ msgstr "colobot.info" msgid "epsitec.com" msgstr "epsitec.com" +msgid "expression expected after =" +msgstr "" + #~ msgid " Drivers:" #~ msgstr " Sterowniki:" +#~ msgid "\"%s\" missing in this exercise" +#~ msgstr "Brakuje \"%s\" w tym ćwiczeniu" + #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "Dźwięk 3D\\Przestrzenne pozycjonowanie dźwięków" @@ -1844,6 +1851,9 @@ msgstr "epsitec.com" #~ msgid "Details\\Visual quality of 3D objects" #~ msgstr "Szczegóły\\Jakość wizualna obiektów 3D" +#~ msgid "Do not use in this exercise" +#~ msgstr "Do not use in this exercise" + #~ msgid "Do you want to quit Colobot: Gold Edition?" #~ msgstr "Czy na pewno chcesz opuścić grę Colobot: Gold Edition?" diff --git a/po/ru.po b/po/ru.po index 16f252e3..25bb06a3 100644 --- a/po/ru.po +++ b/po/ru.po @@ -59,10 +59,6 @@ msgstr "Ожидалось \" [ \"" msgid "\" ] \" missing" msgstr "Отсутствует \"]\" " -#, c-format -msgid "\"%s\" missing in this exercise" -msgstr "\"%s\" отсутствует в этом упражнении" - msgid "..behind" msgstr "Сзади" @@ -484,9 +480,6 @@ msgstr "Устройство\\Драйвер и настройки разреш msgid "Dividing by zero" msgstr "Деление на ноль (запрещено!)" -msgid "Do not use in this exercise" -msgstr "Не используй в этом упражнении" - msgid "Do you really want to destroy the selected building?" msgstr "Вы действительно хотите уничтожить выбранное здание?" @@ -1706,6 +1699,14 @@ msgstr "Вы не можете нести объекты под водой" msgid "You found a usable object" msgstr "Вы нашли рабочий объект" +#, c-format +msgid "You have to use \"%s\" at least %d times in this exercise (used: %d)" +msgstr "" + +#, c-format +msgid "You have to use \"%s\" at most %d times in this exercise (used: %d)" +msgstr "" + msgid "You must get on the spaceship to take off " msgstr "Вы должны быть на борту корабля, чтобы взлететь" @@ -1812,6 +1813,9 @@ msgstr "" msgid "epsitec.com" msgstr "www.epsitec.com" +msgid "expression expected after =" +msgstr "" + #~ msgid " " #~ msgstr " " @@ -1821,6 +1825,9 @@ msgstr "www.epsitec.com" #~ msgid " Missions on this level:" #~ msgstr " Миссии на этом уровне:" +#~ msgid "\"%s\" missing in this exercise" +#~ msgstr "\"%s\" отсутствует в этом упражнении" + #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "3D-звук\\Стерео звук" @@ -1854,6 +1861,9 @@ msgstr "www.epsitec.com" #~ msgid "Developed by :" #~ msgstr "Разработка :" +#~ msgid "Do not use in this exercise" +#~ msgstr "Не используй в этом упражнении" + #, fuzzy #~ msgid "Do you want to quit Colobot: Gold Edition?" #~ msgstr "Вы хотите закрыть COLOBOT?" diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 96e51e0d..966f9939 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -632,8 +632,8 @@ void InitializeRestext() stringsErr[ERR_DELETEMOBILE] = TR("Bot destroyed"); stringsErr[ERR_DELETEBUILDING] = TR("Building destroyed"); stringsErr[ERR_ENEMY_OBJECT] = TR("Unable to control enemy objects"); - stringsErr[ERR_OBLIGATORYTOKEN] = TR("\"%s\" missing in this exercise"); - stringsErr[ERR_PROHIBITEDTOKEN] = TR("Do not use in this exercise"); + stringsErr[ERR_OBLIGATORYTOKEN] = TR("You have to use \"%s\" at least %d times in this exercise (used: %d)"); + stringsErr[ERR_PROHIBITEDTOKEN] = TR("You have to use \"%s\" at most %d times in this exercise (used: %d)"); stringsErr[ERR_WRONG_BOT] = TR("Inappropriate bot"); stringsErr[INFO_BUILD] = TR("Building completed"); diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 07b64bbc..b59cc1f3 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -2839,8 +2839,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_endTakeWinDelay = 2.0f; m_endTakeLostDelay = 2.0f; m_globalMagnifyDamage = 1.0f; - m_obligatoryTotal = 0; - m_prohibitedTotal = 0; + m_obligatoryTokens.clear(); m_mapShow = true; m_mapImage = false; m_mapFilename[0] = 0; @@ -3656,25 +3655,32 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) continue; } - if (line->GetCommand() == "ObligatoryToken" && !resetObject) // NOTE: This was used only in CeeBot, maybe we should add this to some Colobot exercises? + if (line->GetCommand() == "ObligatoryToken" && !resetObject) { - int i = m_obligatoryTotal; - if (i < 100) //TODO: remove the limit + std::string token = line->GetParam("text")->AsString(); + if (!line->GetParam("min")->IsDefined() && !line->GetParam("max")->IsDefined()) + GetLogger()->Warn("ObligatoryToken without specifying min/max is provided only for backwards compatibility - instead, do this: ObligatoryToken text=\"%s\" min=1\n", token.c_str()); + if (m_obligatoryTokens.count(token)) + throw CLevelParserException("Incorrect ObligatoryToken specification - you cannot define a token twice"); + + m_obligatoryTokens[token].min = line->GetParam("min")->AsInt(line->GetParam("max")->IsDefined() ? -1 : 1); // BACKWARDS COMPATIBILITY: if neither min or max are defined, default to min=1 + m_obligatoryTokens[token].max = line->GetParam("max")->AsInt(-1); + if (m_obligatoryTokens[token].min >= 0 && m_obligatoryTokens[token].max >= 0 && m_obligatoryTokens[token].min > m_obligatoryTokens[token].max) { - strcpy(m_obligatoryToken[i], line->GetParam("text")->AsString().c_str()); - m_obligatoryTotal ++; + throw CLevelParserException("Incorrect ObligatoryToken specification - min cannot be greater than max"); } continue; } - if (line->GetCommand() == "ProhibitedToken" && !resetObject) // NOTE: This was used only in CeeBot, maybe we should add this to some Colobot exercises? + if (line->GetCommand() == "ProhibitedToken" && !resetObject) // NOTE: Kept only for backwards compatibility { - int i = m_prohibitedTotal; - if (i < 100) //TODO: remove the limit - { - strcpy(m_prohibitedToken[i], line->GetParam("text")->AsString().c_str()); - m_prohibitedTotal ++; - } + std::string token = line->GetParam("text")->AsString(); + GetLogger()->Warn("ProhibitedToken is only provided for backwards compatibility - instead, do this: ObligatoryToken text=\"%s\" max=0\n", token.c_str()); + if (m_obligatoryTokens.count(token)) + throw CLevelParserException("Incorrect ObligatoryToken specification - you cannot define a token twice"); + + m_obligatoryTokens[token].min = -1; + m_obligatoryTokens[token].max = 0; continue; } @@ -5227,41 +5233,12 @@ Error CRobotMain::CheckEndMission(bool frame) } -//! Returns the number of instructions required -int CRobotMain::GetObligatoryToken() +//! Returns the list instructions required in CBot program in level +const std::map& CRobotMain::GetObligatoryTokenList() { - return m_obligatoryTotal; + return m_obligatoryTokens; } -//! Returns the name of a required instruction -char* CRobotMain::GetObligatoryToken(int i) -{ - return m_obligatoryToken[i]; -} - -//! Checks if an instruction is part of the obligatory list -int CRobotMain::IsObligatoryToken(const char* token) -{ - for (int i = 0; i < m_obligatoryTotal; i++) - { - if (strcmp(token, m_obligatoryToken[i]) == 0) - return i; - } - return -1; -} - -//! Checks if an instruction is not part of the banned list -bool CRobotMain::IsProhibitedToken(const char* token) -{ - for (int i = 0; i < m_prohibitedTotal; i++) - { - if (strcmp(token, m_prohibitedToken[i]) == 0) - return false; - } - return true; -} - - //! Indicates whether it is possible to control a driving robot bool CRobotMain::GetTrainerPilot() { diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 4f78df3d..3247813d 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -141,6 +141,12 @@ struct ShowLimit float time = 0.0f; }; +struct MinMax +{ + int min = -1; + int max = -1; +}; + const int SATCOM_HUSTON = 0; const int SATCOM_SAT = 1; @@ -199,10 +205,7 @@ public: Error CheckEndMission(bool frame); Error ProcessEndMissionTake(); Error ProcessEndMissionTakeForGroup(std::vector& endTakes); - int GetObligatoryToken(); - char* GetObligatoryToken(int i); - int IsObligatoryToken(const char* token); - bool IsProhibitedToken(const char* token); + const std::map& GetObligatoryTokenList(); void UpdateMap(); bool GetShowMap(); @@ -552,10 +555,7 @@ protected: std::vector> m_audioChange; - int m_obligatoryTotal = 0; - char m_obligatoryToken[100][20] = {}; - int m_prohibitedTotal = 0; - char m_prohibitedToken[100][20] = {}; + std::map m_obligatoryTokens; //! Enabled buildings int m_build = 0; diff --git a/src/script/script.cpp b/src/script/script.cpp index 3beac76e..924081da 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -161,46 +161,52 @@ bool CScript::CheckToken() m_error = CBot::CBotNoErr; m_title[0] = 0; m_mainFunction[0] = 0; - m_token[0] = 0; + m_token.clear(); m_bCompile = false; - std::vector used(m_main->GetObligatoryToken(), false); + std::map used; + std::map cursor1; + std::map cursor2; auto tokens = CBot::CBotToken::CompileTokens(m_script.get()); CBot::CBotToken* bt = tokens.get(); while ( bt != nullptr ) { std::string token = bt->GetString(); - int cursor1 = bt->GetStart(); - int cursor2 = bt->GetEnd(); - int i = m_main->IsObligatoryToken(token.c_str()); - if ( i != -1 ) - { - used[i] = true; // token used - } + // Store only the last occurrence of the token + cursor1[token] = bt->GetStart(); + cursor2[token] = bt->GetEnd(); - if ( !m_main->IsProhibitedToken(token.c_str()) ) - { - m_error = static_cast(ERR_PROHIBITEDTOKEN); - m_cursor1 = cursor1; - m_cursor2 = cursor2; - strcpy(m_title, ""); - m_mainFunction[0] = 0; - return false; - } + used[token]++; bt = bt->GetNext(); } - // At least once every obligatory instruction? - for (unsigned int i = 0; i < used.size(); i++) + for (const auto& it : m_main->GetObligatoryTokenList()) { - if (!used[i]) // token not used? + Error error = ERR_OK; + int allowed = 0; + if (it.second.max >= 0 && used[it.first] > it.second.max) { - strcpy(m_token, m_main->GetObligatoryToken(i)); - m_error = static_cast(ERR_OBLIGATORYTOKEN); - strcpy(m_title, ""); + error = ERR_PROHIBITEDTOKEN; + allowed = it.second.max; + m_cursor1 = cursor1[it.first]; + m_cursor2 = cursor2[it.first]; + } + if (it.second.min >= 0 && used[it.first] < it.second.min) + { + error = ERR_OBLIGATORYTOKEN; + allowed = it.second.min; + } + + if (error != ERR_OK) + { + m_token = it.first; + m_tokenUsed = used[it.first]; + m_tokenAllowed = allowed; + m_error = static_cast(error); + strcpy(m_title, ""); m_mainFunction[0] = 0; return false; } @@ -788,11 +794,11 @@ void CScript::GetError(std::string& error) } else { - if ( m_error == static_cast(ERR_OBLIGATORYTOKEN) ) + if ( m_error == static_cast(ERR_OBLIGATORYTOKEN) || m_error == static_cast(ERR_PROHIBITEDTOKEN) ) { std::string s; GetResource(RES_ERR, m_error, s); - error = StrUtils::Format(s.c_str(), m_token); + error = StrUtils::Format(s.c_str(), m_token.c_str(), m_tokenAllowed, m_tokenUsed); } else if ( m_error < 1000 ) { diff --git a/src/script/script.h b/src/script/script.h index 50f279ef..a1141714 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -122,7 +122,8 @@ protected: char m_title[50] = {}; // script title char m_mainFunction[50] = {}; char m_filename[50] = {}; // file name - char m_token[50] = {}; // missing instruction + std::string m_token = ""; // missing instruction + int m_tokenUsed = 0, m_tokenAllowed = 0; CBot::CBotError m_error = CBot::CBotNoErr; // error (0=ok) int m_cursor1 = 0; int m_cursor2 = 0; From bd9184bd92d60986eabe298f2b4479a52f2d2219 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 8 Apr 2016 22:27:42 +0200 Subject: [PATCH 052/125] Refactored part of CScript to std::string --- src/script/script.cpp | 62 +++++++++++++------------------------ src/script/script.h | 12 +++---- src/ui/object_interface.cpp | 14 ++++----- 3 files changed, 33 insertions(+), 55 deletions(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index 924081da..4f7bf323 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -70,11 +70,8 @@ CScript::CScript(COldObject* object) m_bRun = false; m_bStepMode = false; m_bCompile = false; - m_title[0] = 0; - m_mainFunction[0] = 0; m_cursor1 = 0; m_cursor2 = 0; - m_filename[0] = 0; } // Object's destructor. @@ -159,8 +156,8 @@ bool CScript::CheckToken() if ( !m_object->GetCheckToken() ) return true; m_error = CBot::CBotNoErr; - m_title[0] = 0; - m_mainFunction[0] = 0; + m_title.clear(); + m_mainFunction.clear(); m_token.clear(); m_bCompile = false; @@ -206,8 +203,8 @@ bool CScript::CheckToken() m_tokenUsed = used[it.first]; m_tokenAllowed = allowed; m_error = static_cast(error); - strcpy(m_title, ""); - m_mainFunction[0] = 0; + m_title = ""; + m_mainFunction.clear(); return false; } } @@ -220,14 +217,13 @@ bool CScript::CheckToken() bool CScript::Compile() { std::vector functionList; - int i; std::string p; m_error = CBot::CBotNoErr; m_cursor1 = 0; m_cursor2 = 0; - m_title[0] = 0; - m_mainFunction[0] = 0; + m_title.clear(); + m_mainFunction.clear(); m_bCompile = false; if ( IsEmpty() ) // program exist? @@ -245,33 +241,17 @@ bool CScript::Compile() { if (functionList.empty()) { - strcpy(m_title, ""); - m_mainFunction[0] = 0; + m_title = ""; + m_mainFunction.clear(); } else { - p = functionList[0]; - i = 0; - bool titleDone = false; - while ( true ) + m_mainFunction = functionList[0]; + m_title = m_mainFunction; + if (m_title.length() >= 20) { - if ( p[i] == 0 || p[i] == '(' ) break; - if ( i >= 20 && !titleDone ) - { - m_title[i+0] = '.'; - m_title[i+1] = '.'; - m_title[i+2] = '.'; - m_title[i+3] = 0; - titleDone = true; - } - if(!titleDone) - m_title[i] = p[i]; - m_mainFunction[i] = p[i]; - i ++; + m_title = m_title.substr(0, 20)+"..."; } - if(!titleDone) - m_title[i] = 0; - m_mainFunction[i] = p[i]; } m_bCompile = true; return true; @@ -289,8 +269,8 @@ bool CScript::Compile() { m_cursor1 = m_cursor2 = 0; } - strcpy(m_title, ""); - m_mainFunction[0] = 0; + m_title = ""; + m_mainFunction.clear(); return false; } } @@ -298,9 +278,9 @@ bool CScript::Compile() // Returns the title of the script. -void CScript::GetTitle(char* buffer) +const std::string& CScript::GetTitle() { - strcpy(buffer, m_title); + return m_title; } @@ -323,9 +303,9 @@ bool CScript::Run() { if (m_botProg == nullptr) return false; if ( m_script == nullptr || m_len == 0 ) return false; - if ( m_mainFunction[0] == 0 ) return false; + if ( m_mainFunction.empty() ) return false; - if ( !m_botProg->Start(m_mainFunction) ) return false; + if ( !m_botProg->Start(m_mainFunction.c_str()) ) return false; m_bRun = true; m_bContinue = false; @@ -1024,12 +1004,12 @@ bool CScript::Compare(CScript* other) // Management of the file name when the script is saved. -void CScript::SetFilename(char *filename) +void CScript::SetFilename(const std::string& filename) { - strcpy(m_filename, filename); + m_filename = filename; } -char* CScript::GetFilename() +const std::string& CScript::GetFilename() { return m_filename; } diff --git a/src/script/script.h b/src/script/script.h index a1141714..deed0c6b 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -66,7 +66,7 @@ public: bool GetScript(Ui::CEdit* edit); bool GetCompile(); - void GetTitle(char* buffer); + const std::string& GetTitle(); void SetStepMode(bool bStep); bool GetStepMode(); @@ -92,8 +92,8 @@ public: bool WriteStack(FILE *file); bool Compare(CScript* other); - void SetFilename(char *filename); - char* GetFilename(); + void SetFilename(const std::string &filename); + const std::string& GetFilename(); protected: bool IsEmpty(); @@ -119,9 +119,9 @@ protected: bool m_bStepMode = false; // step by step bool m_bContinue = false; // external function to continue bool m_bCompile = false; // compilation ok? - char m_title[50] = {}; // script title - char m_mainFunction[50] = {}; - char m_filename[50] = {}; // file name + std::string m_title = ""; // script title + std::string m_mainFunction = ""; + std::string m_filename = ""; // file name std::string m_token = ""; // missing instruction int m_tokenUsed = 0, m_tokenAllowed = 0; CBot::CBotError m_error = CBot::CBotNoErr; // error (0=ok) diff --git a/src/ui/object_interface.cpp b/src/ui/object_interface.cpp index c2ed098f..aa52678a 100644 --- a/src/ui/object_interface.cpp +++ b/src/ui/object_interface.cpp @@ -1623,7 +1623,6 @@ void CObjectInterface::UpdateInterface() CSlider* ps; CColor* pc; bool bFly, bRun; - char title[100]; if ( !m_object->GetSelect() ) return; @@ -1793,8 +1792,8 @@ void CObjectInterface::UpdateInterface() { if (m_programStorage->GetProgram(m_selScript)->runnable) { - m_programStorage->GetProgram(m_selScript)->script->GetTitle(title); - if ( title[0] != 0 ) + std::string title = m_programStorage->GetProgram(m_selScript)->script->GetTitle(); + if ( !title.empty() ) { bRun = true; } @@ -1943,7 +1942,6 @@ void CObjectInterface::UpdateScript(CWindow *pw) { CList* pl; char name[100]; - char title[100]; pl = static_cast< CList* >(pw->SearchControl(EVENT_OBJECT_PROGLIST)); if ( pl == nullptr ) return; @@ -1953,16 +1951,16 @@ void CObjectInterface::UpdateScript(CWindow *pw) { sprintf(name, "%d", i+1); - m_programStorage->GetProgram(i)->script->GetTitle(title); - if ( title[0] != 0 ) + std::string title = m_programStorage->GetProgram(i)->script->GetTitle(); + if ( !title.empty() ) { if(!m_programStorage->GetProgram(i)->readOnly) { - sprintf(name, "%d: %s", i+1, title); + sprintf(name, "%d: %s", i+1, title.c_str()); } else { - sprintf(name, "*%d: %s", i+1, title); + sprintf(name, "*%d: %s", i+1, title.c_str()); } } From 14e2910f83098e44f5d17036f090033b6d2b2b3a Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 9 Apr 2016 16:28:11 +0200 Subject: [PATCH 053/125] Proper plural form translations for ObligatoryToken --- cmake/FindGettext.cmake | 218 ---------------------------------------- po/CMakeLists.txt | 35 ++++++- po/colobot.pot | 38 +++---- po/de.po | 54 +++++----- po/fr.po | 83 ++++++--------- po/pl.po | 97 +++++++----------- po/ru.po | 57 +++++------ src/common/restext.cpp | 2 - src/script/script.cpp | 26 ++++- 9 files changed, 187 insertions(+), 423 deletions(-) delete mode 100644 cmake/FindGettext.cmake diff --git a/cmake/FindGettext.cmake b/cmake/FindGettext.cmake deleted file mode 100644 index ca1150e4..00000000 --- a/cmake/FindGettext.cmake +++ /dev/null @@ -1,218 +0,0 @@ -## -# Patched version of original CMake module -# Added variable GETTEXT_INSTALL_PREFIX to optionally override installation path of resulting translations -## - -# - Find GNU gettext tools -# This module looks for the GNU gettext tools. This module defines the -# following values: -# GETTEXT_MSGMERGE_EXECUTABLE: the full path to the msgmerge tool. -# GETTEXT_MSGFMT_EXECUTABLE: the full path to the msgfmt tool. -# GETTEXT_FOUND: True if gettext has been found. -# GETTEXT_VERSION_STRING: the version of gettext found (since CMake 2.8.8) -# -# Additionally it provides the following macros: -# GETTEXT_CREATE_TRANSLATIONS ( outputFile [ALL] file1 ... fileN ) -# This will create a target "translations" which will convert the -# given input po files into the binary output mo file. If the -# ALL option is used, the translations will also be created when -# building the default target. -# GETTEXT_PROCESS_POT( [ALL] [INSTALL_DESTINATION ] LANGUAGES ... ) -# Process the given pot file to mo files. -# If INSTALL_DESTINATION is given then automatically install rules will be created, -# the language subdirectory will be taken into account (by default use share/locale/). -# If ALL is specified, the pot file is processed when building the all traget. -# It creates a custom target "potfile". -# GETTEXT_PROCESS_PO_FILES( [ALL] [INSTALL_DESTINATION ] PO_FILES ... ) -# Process the given po files to mo files for the given language. -# If INSTALL_DESTINATION is given then automatically install rules will be created, -# the language subdirectory will be taken into account (by default use share/locale/). -# If ALL is specified, the po files are processed when building the all traget. -# It creates a custom target "pofiles". - -#============================================================================= -# Copyright 2007-2009 Kitware, Inc. -# Copyright 2007 Alexander Neundorf -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -find_program(GETTEXT_MSGMERGE_EXECUTABLE msgmerge) - -find_program(GETTEXT_MSGFMT_EXECUTABLE msgfmt) - -if(GETTEXT_MSGMERGE_EXECUTABLE) - execute_process(COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --version - OUTPUT_VARIABLE gettext_version - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - if (gettext_version MATCHES "^msgmerge \\(.*\\) [0-9]") - string(REGEX REPLACE "^msgmerge \\([^\\)]*\\) ([0-9\\.]+[^ \n]*).*" "\\1" GETTEXT_VERSION_STRING "${gettext_version}") - endif() - unset(gettext_version) -endif() - -set(GETTEXT_INSTALL_PREFIX share/locale) - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Gettext - REQUIRED_VARS GETTEXT_MSGMERGE_EXECUTABLE GETTEXT_MSGFMT_EXECUTABLE - VERSION_VAR GETTEXT_VERSION_STRING) - -include(CMakeParseArguments) - -function(_GETTEXT_GET_UNIQUE_TARGET_NAME _name _unique_name) - set(propertyName "_GETTEXT_UNIQUE_COUNTER_${_name}") - get_property(currentCounter GLOBAL PROPERTY "${propertyName}") - if(NOT currentCounter) - set(currentCounter 1) - endif() - set(${_unique_name} "${_name}_${currentCounter}" PARENT_SCOPE) - math(EXPR currentCounter "${currentCounter} + 1") - set_property(GLOBAL PROPERTY ${propertyName} ${currentCounter} ) -endfunction() - -macro(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg) - # make it a real variable, so we can modify it here - set(_firstPoFile "${_firstPoFileArg}") - - set(_gmoFiles) - get_filename_component(_potName ${_potFile} NAME) - string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" _potBasename ${_potName}) - get_filename_component(_absPotFile ${_potFile} ABSOLUTE) - - set(_addToAll) - if(${_firstPoFile} STREQUAL "ALL") - set(_addToAll "ALL") - set(_firstPoFile) - endif() - - foreach (_currentPoFile ${_firstPoFile} ${ARGN}) - get_filename_component(_absFile ${_currentPoFile} ABSOLUTE) - get_filename_component(_abs_PATH ${_absFile} PATH) - get_filename_component(_lang ${_absFile} NAME_WE) - set(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo) - - add_custom_command( - OUTPUT ${_gmoFile} - COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${_absFile} ${_absPotFile} - COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_absFile} - DEPENDS ${_absPotFile} ${_absFile} - ) - - install(FILES ${_gmoFile} DESTINATION ${GETTEXT_INSTALL_PREFIX}/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo) - set(_gmoFiles ${_gmoFiles} ${_gmoFile}) - - endforeach () - - if(NOT TARGET translations) - add_custom_target(translations) - endif() - - _GETTEXT_GET_UNIQUE_TARGET_NAME(translations uniqueTargetName) - - add_custom_target(${uniqueTargetName} ${_addToAll} DEPENDS ${_gmoFiles}) - - add_dependencies(translations ${uniqueTargetName}) - -endmacro() - - -function(GETTEXT_PROCESS_POT_FILE _potFile) - set(_gmoFiles) - set(_options ALL) - set(_oneValueArgs INSTALL_DESTINATION) - set(_multiValueArgs LANGUAGES) - - CMAKE_PARSE_ARGUMENTS(_parsedArguments "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN}) - - get_filename_component(_potName ${_potFile} NAME) - string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" _potBasename ${_potName}) - get_filename_component(_absPotFile ${_potFile} ABSOLUTE) - - foreach (_lang ${_parsedArguments_LANGUAGES}) - set(_poFile "${CMAKE_CURRENT_BINARY_DIR}/${_lang}.po") - set(_gmoFile "${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo") - - add_custom_command( - OUTPUT "${_poFile}" - COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${_poFile} ${_absPotFile} - DEPENDS ${_absPotFile} - ) - - add_custom_command( - OUTPUT "${_gmoFile}" - COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_poFile} - DEPENDS ${_absPotFile} ${_poFile} - ) - - if(_parsedArguments_INSTALL_DESTINATION) - install(FILES ${_gmoFile} DESTINATION ${_parsedArguments_INSTALL_DESTINATION}/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo) - endif() - list(APPEND _gmoFiles ${_gmoFile}) - endforeach () - - if(NOT TARGET potfiles) - add_custom_target(potfiles) - endif() - - _GETTEXT_GET_UNIQUE_TARGET_NAME( potfiles uniqueTargetName) - - if(_parsedArguments_ALL) - add_custom_target(${uniqueTargetName} ALL DEPENDS ${_gmoFiles}) - else() - add_custom_target(${uniqueTargetName} DEPENDS ${_gmoFiles}) - endif() - - add_dependencies(potfiles ${uniqueTargetName}) - -endfunction() - - -function(GETTEXT_PROCESS_PO_FILES _lang) - set(_options ALL) - set(_oneValueArgs INSTALL_DESTINATION) - set(_multiValueArgs PO_FILES) - set(_gmoFiles) - - CMAKE_PARSE_ARGUMENTS(_parsedArguments "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN}) - - foreach(_current_PO_FILE ${_parsedArguments_PO_FILES}) - get_filename_component(_name ${_current_PO_FILE} NAME) - string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" _basename ${_name}) - set(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.gmo) - add_custom_command(OUTPUT ${_gmoFile} - COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_current_PO_FILE} - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - DEPENDS ${_current_PO_FILE} - ) - - if(_parsedArguments_INSTALL_DESTINATION) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.gmo DESTINATION ${_parsedArguments_INSTALL_DESTINATION}/${_lang}/LC_MESSAGES/ RENAME ${_basename}.mo) - endif() - list(APPEND _gmoFiles ${_gmoFile}) - endforeach() - - - if(NOT TARGET pofiles) - add_custom_target(pofiles) - endif() - - _GETTEXT_GET_UNIQUE_TARGET_NAME( pofiles uniqueTargetName) - - if(_parsedArguments_ALL) - add_custom_target(${uniqueTargetName} ALL DEPENDS ${_gmoFiles}) - else() - add_custom_target(${uniqueTargetName} DEPENDS ${_gmoFiles}) - endif() - - add_dependencies(pofiles ${uniqueTargetName}) - -endfunction() diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt index 3550e7c3..6a5d7073 100644 --- a/po/CMakeLists.txt +++ b/po/CMakeLists.txt @@ -4,11 +4,14 @@ find_package(Gettext REQUIRED) set(_potFile colobot.pot) +# Extract translations + find_program(XGETTEXT_CMD xgettext) add_custom_command(OUTPUT ${_potFile} - COMMAND ${XGETTEXT_CMD} ${colobot_SOURCE_DIR}/src/app/app.cpp --output=${_potFile} - COMMAND ${XGETTEXT_CMD} ${colobot_SOURCE_DIR}/src/common/restext.cpp --output=${_potFile} --join-existing --keyword=TR --no-location + COMMAND ${XGETTEXT_CMD} ${colobot_SOURCE_DIR}/src/app/app.cpp --output=${_potFile} --no-wrap + COMMAND ${XGETTEXT_CMD} ${colobot_SOURCE_DIR}/src/common/restext.cpp --output=${_potFile} --no-wrap --join-existing --no-location --keyword=TR + COMMAND ${XGETTEXT_CMD} ${colobot_SOURCE_DIR}/src/script/script.cpp --output=${_potFile} --no-wrap --join-existing --no-location COMMAND sed -i -e "s|^\\(\"POT-Creation-Date:\\).*$|\\1 DATE\\\\n\"|" ${_potFile} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} @@ -18,6 +21,30 @@ add_custom_command(OUTPUT ${_potFile} add_custom_target(update-pot DEPENDS ${_potFile}) +# Generate translations + file(GLOB _poFiles *.po) -set(GETTEXT_INSTALL_PREFIX ${COLOBOT_INSTALL_I18N_DIR}) -gettext_create_translations(${_potFile} ALL ${_poFiles}) + +set(_gmoFiles) +get_filename_component(_potName ${_potFile} NAME) +string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" _potBasename ${_potName}) +get_filename_component(_absPotFile ${_potFile} ABSOLUTE) + +foreach (_currentPoFile ${_poFiles}) + get_filename_component(_absFile ${_currentPoFile} ABSOLUTE) + get_filename_component(_abs_PATH ${_absFile} PATH) + get_filename_component(_lang ${_absFile} NAME_WE) + set(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo) + + add_custom_command( + OUTPUT ${_gmoFile} + COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --no-wrap --update --backup=none -s ${_absFile} ${_absPotFile} + COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} --check-format -o ${_gmoFile} ${_absFile} + DEPENDS ${_absPotFile} ${_absFile} + ) + + install(FILES ${_gmoFile} DESTINATION ${COLOBOT_INSTALL_I18N_DIR}/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo) + set(_gmoFiles ${_gmoFiles} ${_gmoFile}) +endforeach() + +add_custom_target(translations ALL DEPENDS ${_gmoFiles}) diff --git a/po/colobot.pot b/po/colobot.pot index 442beb45..b39e7ad2 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -16,6 +16,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" msgid "Colobot rules!" msgstr "" @@ -370,9 +371,7 @@ msgstr "" msgid "Film sequences\\Films before and after the missions" msgstr "" -msgid "" -"Camera border scrolling\\Scrolling when the mouse touches right or left " -"border" +msgid "Camera border scrolling\\Scrolling when the mouse touches right or left border" msgstr "" msgid "Mouse inversion X\\Inversion of the scrolling direction on the X axis" @@ -459,8 +458,7 @@ msgstr "" msgid "Previous object\\Selects the previous object" msgstr "" -msgid "" -"Standard action\\Standard action of the bot (take/grab, shoot, sniff, etc)" +msgid "Standard action\\Standard action of the bot (take/grab, shoot, sniff, etc)" msgstr "" msgid "Camera closer\\Moves the camera forward" @@ -541,8 +539,7 @@ msgstr "" msgid "Normal\\Normal sound volume" msgstr "" -msgid "" -"Access to solution\\Shows the solution (detailed instructions for missions)" +msgid "Access to solution\\Shows the solution (detailed instructions for missions)" msgstr "" msgid "Invert\\Invert values on this axis" @@ -1505,8 +1502,7 @@ msgstr "" msgid "Inappropriate object" msgstr "" -msgid "" -"The mission is not accomplished yet (press \\key help; for more details)" +msgid "The mission is not accomplished yet (press \\key help; for more details)" msgstr "" msgid "Bot destroyed" @@ -1518,14 +1514,6 @@ msgstr "" msgid "Unable to control enemy objects" msgstr "" -#, c-format -msgid "You have to use \"%s\" at least %d times in this exercise (used: %d)" -msgstr "" - -#, c-format -msgid "You have to use \"%s\" at most %d times in this exercise (used: %d)" -msgstr "" - msgid "Inappropriate bot" msgstr "" @@ -1792,3 +1780,19 @@ msgstr "" msgid "Button %1" msgstr "" + +#, c-format +msgid "You have to use \"%1$s\" at least once in this exercise (used: %2$d)" +msgid_plural "You have to use \"%1$s\" at least %3$d times in this exercise (used: %2$d)" +msgstr[0] "" +msgstr[1] "" + +#, c-format +msgid "You cannot use \"%s\" in this exercise (used: %d)" +msgstr "" + +#, c-format +msgid "You have to use \"%1$s\" at most once in this exercise (used: %2$d)" +msgid_plural "You have to use \"%1$s\" at most %3$d times in this exercise (used: %2$d)" +msgstr[0] "" +msgstr[1] "" diff --git a/po/de.po b/po/de.po index 300d209c..972066e6 100644 --- a/po/de.po +++ b/po/de.po @@ -86,9 +86,7 @@ msgid "<<< Well done; mission accomplished >>>" msgstr "<<< Bravo, Mission vollendet >>>" msgid "A label must be followed by \"for\"; \"while\"; \"do\" or \"switch\"" -msgstr "" -"Ein Label kann nur vor den Anweisungen \"for\", \"while\", \"do\" oder " -"\"switch\" vorkommen" +msgstr "Ein Label kann nur vor den Anweisungen \"for\", \"while\", \"do\" oder \"switch\" vorkommen" msgid "A variable can not be declared twice" msgstr "Eine Variable wird zum zweiten Mal deklariert" @@ -99,13 +97,11 @@ msgstr "Abbrechen\\Mission abbrechen" msgid "Access beyond array limit" msgstr "Zugriff im Array außerhalb der Grenzen" -msgid "" -"Access to solution\\Shows the solution (detailed instructions for missions)" +msgid "Access to solution\\Shows the solution (detailed instructions for missions)" msgstr "Zeigt die Lösung\\Zeigt nach 3mal Scheitern die Lösung" msgid "Access to solutions\\Show program \"4: Solution\" in the exercises" -msgstr "" -"Lösung zugänglich\\Die Lösung ist im Programmslot \"4: Lösung\" zugänglich" +msgstr "Lösung zugänglich\\Die Lösung ist im Programmslot \"4: Lösung\" zugänglich" msgid "Add new program" msgstr "" @@ -328,11 +324,8 @@ msgid "Camera back\\Moves the camera backward" msgstr "Kamera weiter\\Bewegung der Kamera rückwärts" #, fuzzy -msgid "" -"Camera border scrolling\\Scrolling when the mouse touches right or left " -"border" -msgstr "" -"Kameradrehung mit der Maus\\Die Kamera dreht wenn die Maus den Rand erreicht" +msgid "Camera border scrolling\\Scrolling when the mouse touches right or left border" +msgstr "Kameradrehung mit der Maus\\Die Kamera dreht wenn die Maus den Rand erreicht" msgid "Camera closer\\Moves the camera forward" msgstr "Kamera näher\\Bewegung der Kamera vorwärts" @@ -1418,8 +1411,7 @@ msgstr "Spinne tödlich verwundet" msgid "Stack overflow" msgstr "Stack overflow" -msgid "" -"Standard action\\Standard action of the bot (take/grab, shoot, sniff, etc)" +msgid "Standard action\\Standard action of the bot (take/grab, shoot, sniff, etc)" msgstr "Standardhandlung\\Führt die Standardhandlung des Roboters aus" msgid "Standard controls\\Standard key functions" @@ -1483,11 +1475,8 @@ msgstr "Der Ausdruck muss einen boolschen Wert ergeben" msgid "The function returned no value " msgstr "Die Funktion hat kein Ergebnis zurückgegeben" -msgid "" -"The mission is not accomplished yet (press \\key help; for more details)" -msgstr "" -"Mission noch nicht beendet (Drücken Sie auf \\key help; für weitere " -"Informationen)" +msgid "The mission is not accomplished yet (press \\key help; for more details)" +msgstr "Mission noch nicht beendet (Drücken Sie auf \\key help; für weitere Informationen)" msgid "The types of the two operands are incompatible " msgstr "Die zwei Operanden sind nicht kompatibel" @@ -1705,16 +1694,24 @@ msgstr "Sie können keinen radioaktiven Gegenstand tragen" msgid "You can not carry an object under water" msgstr "Sie können unter Wasser nichts tragen" +#, fuzzy, c-format +msgid "You cannot use \"%s\" in this exercise (used: %d)" +msgstr "In dieser Übung verboten" + msgid "You found a usable object" msgstr "Sie haben ein brauchbares Objekt gefunden" -#, c-format -msgid "You have to use \"%s\" at least %d times in this exercise (used: %d)" -msgstr "" +#, fuzzy, c-format +msgid "You have to use \"%1$s\" at least once in this exercise (used: %2$d)" +msgid_plural "You have to use \"%1$s\" at least %3$d times in this exercise (used: %2$d)" +msgstr[0] "In dieser Übung verboten" +msgstr[1] "In dieser Übung verboten" -#, c-format -msgid "You have to use \"%s\" at most %d times in this exercise (used: %d)" -msgstr "" +#, fuzzy, c-format +msgid "You have to use \"%1$s\" at most once in this exercise (used: %2$d)" +msgid_plural "You have to use \"%1$s\" at most %3$d times in this exercise (used: %2$d)" +msgstr[0] "In dieser Übung verboten" +msgstr[1] "In dieser Übung verboten" msgid "You must get on the spaceship to take off " msgstr "Gehen Sie an Bord, bevor Sie abheben" @@ -1870,9 +1867,6 @@ msgstr "" #~ msgid "Developed by :" #~ msgstr "Entwickelt von:" -#~ msgid "Do not use in this exercise" -#~ msgstr "In dieser Übung verboten" - #, fuzzy #~ msgid "Do you want to quit Colobot: Gold Edition?" #~ msgstr "Wollen Sie COLOBOT schließen ?" @@ -1931,9 +1925,7 @@ msgstr "" #~ msgid "Textures\\Quality of textures " #~ msgstr "Qualität der Texturen\\Qualität der Anzeige" -#~ msgid "" -#~ "The list is only available if a \\l;radar station\\u object\\radar; is " -#~ "working.\n" +#~ msgid "The list is only available if a \\l;radar station\\u object\\radar; is working.\n" #~ msgstr "Die Liste ist ohne \\l;Radar\\u object\\radar; nicht verfügbar.\n" #~ msgid "Use a joystick\\Joystick or keyboard" diff --git a/po/fr.po b/po/fr.po index a57ce326..6822fa0e 100644 --- a/po/fr.po +++ b/po/fr.po @@ -79,9 +79,7 @@ msgid "<<< Well done; mission accomplished >>>" msgstr "<<< Bravo; mission terminée >>>" msgid "A label must be followed by \"for\"; \"while\"; \"do\" or \"switch\"" -msgstr "" -"Un label ne peut se placer que devant un \"for\"; un \"while\"; un \"do\" ou " -"un \"switch\"" +msgstr "Un label ne peut se placer que devant un \"for\"; un \"while\"; un \"do\" ou un \"switch\"" msgid "A variable can not be declared twice" msgstr "Redéfinition d'une variable" @@ -92,8 +90,7 @@ msgstr "Abandonner\\Abandonner la mission en cours" msgid "Access beyond array limit" msgstr "Accès hors du tableau" -msgid "" -"Access to solution\\Shows the solution (detailed instructions for missions)" +msgid "Access to solution\\Shows the solution (detailed instructions for missions)" msgstr "Accès à la solution\\Donne la solution" msgid "Access to solutions\\Show program \"4: Solution\" in the exercises" @@ -148,9 +145,7 @@ msgid "Automatic indent\\When program editing" msgstr "Indentation automatique\\Pendant l'édition d'un programme" msgid "Autosave interval\\How often your game will autosave" -msgstr "" -"Intervalle d'auto-sauvegarde\\À quels intervalles les parties vont-t-elles " -"êtres sauvegardées automatiquement" +msgstr "Intervalle d'auto-sauvegarde\\À quels intervalles les parties vont-t-elles êtres sauvegardées automatiquement" msgid "Autosave slots\\How many autosave slots you'll have" msgstr "Nombre d'auto-sauvegardes\\Combien d'auto-sauvegarde seront conservées" @@ -320,20 +315,14 @@ msgstr "Caméra plus loin" msgid "Camera back\\Moves the camera backward" msgstr "Caméra plus loin\\Recule la caméra" -msgid "" -"Camera border scrolling\\Scrolling when the mouse touches right or left " -"border" -msgstr "" -"Défilement dans les bords\\Défilement lorsque la souris touche les bords " -"gauche ou droite" +msgid "Camera border scrolling\\Scrolling when the mouse touches right or left border" +msgstr "Défilement dans les bords\\Défilement lorsque la souris touche les bords gauche ou droite" msgid "Camera closer\\Moves the camera forward" msgstr "Caméra plus proche\\Avance la caméra" msgid "Camera down\\Decrease camera angle while visiting message origin" -msgstr "" -"Caméra plus basse\\Réduit l'angle de caméra lors de la vue de l'origine des " -"messages" +msgstr "Caméra plus basse\\Réduit l'angle de caméra lors de la vue de l'origine des messages" msgid "Camera nearest" msgstr "Caméra plus proche" @@ -345,9 +334,7 @@ msgid "Camera to right" msgstr "Caméra à droite" msgid "Camera up\\Increase camera angle while visiting message origin" -msgstr "" -"Caméra plus haute\\Augmente l'angle de caméra lors de la vue de l'origine " -"des messages" +msgstr "Caméra plus haute\\Augmente l'angle de caméra lors de la vue de l'origine des messages" msgid "Can not produce not researched object" msgstr "Impossible de créer un objet n'ayant pas été recherché" @@ -401,8 +388,7 @@ msgid "Code battles" msgstr "Batailles de code" msgid "Code battles\\Program your robot to be the best of them all!" -msgstr "" -"Batailles de code\\Programmez votre robot pour être le meilleur entre tous!" +msgstr "Batailles de code\\Programmez votre robot pour être le meilleur entre tous!" msgid "Colobot rules!" msgstr "Colobot est super!" @@ -851,12 +837,10 @@ msgid "Missions\\Select mission" msgstr "Missions\\La grande aventure" msgid "Mouse inversion X\\Inversion of the scrolling direction on the X axis" -msgstr "" -"Inversion souris X\\Inversion de la rotation lorsque la souris touche un bord" +msgstr "Inversion souris X\\Inversion de la rotation lorsque la souris touche un bord" msgid "Mouse inversion Y\\Inversion of the scrolling direction on the Y axis" -msgstr "" -"Inversion souris Y\\Inversion de la rotation lorsque la souris touche un bord" +msgstr "Inversion souris Y\\Inversion de la rotation lorsque la souris touche un bord" msgid "Move selected program down" msgstr "Déplace le programme sélectionné vers le bas" @@ -1306,9 +1290,7 @@ msgid "Semicolon terminator missing" msgstr "Terminateur point-virgule non trouvé" msgid "Shadow resolution\\Higher means better range and quality, but slower" -msgstr "" -"Résolution des ombres\\Plus grand implique une meilleure qulité et " -"amplitude, mais plus lent" +msgstr "Résolution des ombres\\Plus grand implique une meilleure qulité et amplitude, mais plus lent" msgid "Shield level" msgstr "Niveau du bouclier" @@ -1403,8 +1385,7 @@ msgstr "Araignée mortellement touchée" msgid "Stack overflow" msgstr "Débordement de la pile" -msgid "" -"Standard action\\Standard action of the bot (take/grab, shoot, sniff, etc)" +msgid "Standard action\\Standard action of the bot (take/grab, shoot, sniff, etc)" msgstr "Action standard\\Action du bouton avec le cadre rouge" msgid "Standard controls\\Standard key functions" @@ -1467,10 +1448,8 @@ msgstr "L'expression doit ętre un boolean" msgid "The function returned no value " msgstr "La fonction n'a pas retourné de résultat" -msgid "" -"The mission is not accomplished yet (press \\key help; for more details)" -msgstr "" -"La misssion n'est pas terminée (appuyez sur \\key help; pour plus de détails)" +msgid "The mission is not accomplished yet (press \\key help; for more details)" +msgstr "La misssion n'est pas terminée (appuyez sur \\key help; pour plus de détails)" msgid "The types of the two operands are incompatible " msgstr "Les deux opérandes ne sont pas de types compatibles" @@ -1491,9 +1470,7 @@ msgid "This label does not exist" msgstr "Cette étiquette n'existe pas" msgid "This menu is for userlevels from mods, but you didn't install any" -msgstr "" -"Ce menu donne accès aux niveaux spéciaux (importés ou personnalisés), mais " -"aucun n'est installé." +msgstr "Ce menu donne accès aux niveaux spéciaux (importés ou personnalisés), mais aucun n'est installé." msgid "This object is not a member of a class" msgstr "L'objet n'est pas une instance d'une classe" @@ -1682,8 +1659,7 @@ msgid "Yes" msgstr "Oui" msgid "You can fly with the keys (\\key gup;) and (\\key gdown;)" -msgstr "" -"Il est possible de voler avec les touches (\\key gup;) et (\\key gdown;)" +msgstr "Il est possible de voler avec les touches (\\key gup;) et (\\key gdown;)" msgid "You can not carry a radioactive object" msgstr "Vous ne pouvez pas transporter un objet radioactif" @@ -1691,16 +1667,24 @@ msgstr "Vous ne pouvez pas transporter un objet radioactif" msgid "You can not carry an object under water" msgstr "Vous ne pouvez pas transporter un objet sous l'eau" +#, fuzzy, c-format +msgid "You cannot use \"%s\" in this exercise (used: %d)" +msgstr "Interdit dans cet exercice" + msgid "You found a usable object" msgstr "Vous avez trouvé un objet utilisable" -#, c-format -msgid "You have to use \"%s\" at least %d times in this exercise (used: %d)" -msgstr "" +#, fuzzy, c-format +msgid "You have to use \"%1$s\" at least once in this exercise (used: %2$d)" +msgid_plural "You have to use \"%1$s\" at least %3$d times in this exercise (used: %2$d)" +msgstr[0] "Interdit dans cet exercice" +msgstr[1] "Interdit dans cet exercice" -#, c-format -msgid "You have to use \"%s\" at most %d times in this exercise (used: %d)" -msgstr "" +#, fuzzy, c-format +msgid "You have to use \"%1$s\" at most once in this exercise (used: %2$d)" +msgid_plural "You have to use \"%1$s\" at most %3$d times in this exercise (used: %2$d)" +msgstr[0] "Interdit dans cet exercice" +msgstr[1] "Interdit dans cet exercice" msgid "You must get on the spaceship to take off " msgstr "Vous devez embarquer pour pouvoir décoller" @@ -1855,9 +1839,6 @@ msgstr "" #~ msgid "Developed by :" #~ msgstr "Développé par :" -#~ msgid "Do not use in this exercise" -#~ msgstr "Interdit dans cet exercice" - #, fuzzy #~ msgid "Do you want to quit Colobot: Gold Edition?" #~ msgstr "Voulez-vous quitter COLOBOT ?" @@ -1919,9 +1900,7 @@ msgstr "" #~ msgid "Textures\\Quality of textures " #~ msgstr "Qualité des textures\\Qualité des images" -#~ msgid "" -#~ "The list is only available if a \\l;radar station\\u object\\radar; is " -#~ "working.\n" +#~ msgid "The list is only available if a \\l;radar station\\u object\\radar; is working.\n" #~ msgstr "Liste non disponible sans \\l;radar\\u object\\radar;.\n" #~ msgid "Use a joystick\\Joystick or keyboard" diff --git a/po/pl.po b/po/pl.po index 5bc0a58d..89cc2368 100644 --- a/po/pl.po +++ b/po/pl.po @@ -14,12 +14,9 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 " -"|| n%100>=20) ? 1 : 2);\n" -"X-Generator: Pootle 2.5.1.1\n" +"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" "X-Language: pl_PL\n" "X-Source-Language: en_US\n" -"X-POOTLE-MTIME: 1405002617.000000\n" msgid " Challenges in the chapter:" msgstr " Wyzwania w tym rozdziale:" @@ -96,11 +93,8 @@ msgstr "Przerwij\\Przerywa bieżącą misję" msgid "Access beyond array limit" msgstr "Dostęp poza tablicę" -msgid "" -"Access to solution\\Shows the solution (detailed instructions for missions)" -msgstr "" -"Dostęp do rozwiązania\\Pokazuje rozwiązanie (szczegółowe instrukcje " -"dotyczące misji)" +msgid "Access to solution\\Shows the solution (detailed instructions for missions)" +msgstr "Dostęp do rozwiązania\\Pokazuje rozwiązanie (szczegółowe instrukcje dotyczące misji)" msgid "Access to solutions\\Show program \"4: Solution\" in the exercises" msgstr "Accčs aux solutions\\Programme \"4: Solution\" dans les exercices" @@ -154,14 +148,10 @@ msgid "Automatic indent\\When program editing" msgstr "Automatyczne wcięcia\\Automatyczne wcięcia podczas edycji programu" msgid "Autosave interval\\How often your game will autosave" -msgstr "" -"Częstotliwość autozapisu\\Jak często gra będzie automatycznie zapisywać twój " -"postęp" +msgstr "Częstotliwość autozapisu\\Jak często gra będzie automatycznie zapisywać twój postęp" msgid "Autosave slots\\How many autosave slots you'll have" -msgstr "" -"Sloty autozapisów\\Określa ile slotów na automatyczne zapisy będzie " -"dostępnych" +msgstr "Sloty autozapisów\\Określa ile slotów na automatyczne zapisy będzie dostępnych" msgid "Autosave\\Enables autosave" msgstr "Autozapis\\Włącza automatyczny zapis" @@ -182,9 +172,7 @@ msgid "Bad argument for \"new\"" msgstr "Zły argument dla funkcji \"new\"" msgid "Big indent\\Indent 2 or 4 spaces per level defined by braces" -msgstr "" -"Duże wcięcie\\2 lub 4 spacje wcięcia na każdy poziom zdefiniowany przez " -"klamry" +msgstr "Duże wcięcie\\2 lub 4 spacje wcięcia na każdy poziom zdefiniowany przez klamry" msgid "Black box" msgstr "Czarna skrzynka" @@ -330,12 +318,8 @@ msgstr "Camera awayest" msgid "Camera back\\Moves the camera backward" msgstr "Kamera dalej\\Oddala kamerę" -msgid "" -"Camera border scrolling\\Scrolling when the mouse touches right or left " -"border" -msgstr "" -"Przewijanie kamery przy krawędzi\\Ekran jest przewijany gdy mysz dotknie " -"prawej lub lewej jego krawędzi" +msgid "Camera border scrolling\\Scrolling when the mouse touches right or left border" +msgstr "Przewijanie kamery przy krawędzi\\Ekran jest przewijany gdy mysz dotknie prawej lub lewej jego krawędzi" msgid "Camera closer\\Moves the camera forward" msgstr "Kamera bliżej\\Przybliża kamerę" @@ -407,8 +391,7 @@ msgid "Code battles" msgstr "Programobitwy" msgid "Code battles\\Program your robot to be the best of them all!" -msgstr "" -"Programobitwy\\Zaprogramuj swego robota by był najlepszy ze wszystkich!" +msgstr "Programobitwy\\Zaprogramuj swego robota by był najlepszy ze wszystkich!" msgid "Colobot rules!" msgstr "Colobot rządzi!" @@ -683,8 +666,7 @@ msgid "Help balloons\\Explain the function of the buttons" msgstr "Dymki pomocy\\Wyjaśnia funkcje przycisków" msgid "Highest\\Highest graphic quality (lowest frame rate)" -msgstr "" -"Najwyższa\\Maksymalna jakość grafiki (najniższa częstotliwość odświeżania)" +msgstr "Najwyższa\\Maksymalna jakość grafiki (najniższa częstotliwość odświeżania)" msgid "Home" msgstr "Początek" @@ -831,8 +813,7 @@ msgid "Loading terrain" msgstr "Wczytywanie terenu" msgid "Lowest\\Minimum graphic quality (highest frame rate)" -msgstr "" -"Najniższa\\Minimalna jakość grafiki (najwyższa częstotliwość odświeżania)" +msgstr "Najniższa\\Minimalna jakość grafiki (najwyższa częstotliwość odświeżania)" msgid "Lunar Roving Vehicle" msgstr "Pojazd Księżycowy" @@ -1033,8 +1014,7 @@ msgid "Organic matter" msgstr "Materia organiczna" msgid "Origin of last message\\Shows where the last message was sent from" -msgstr "" -"Miejsce nadania wiadomości\\Pokazuje skąd została wysłana ostatnia wiadomość" +msgstr "Miejsce nadania wiadomości\\Pokazuje skąd została wysłana ostatnia wiadomość" msgid "Original game developed by:" msgstr "Twórcy oryginalnej gry:" @@ -1118,8 +1098,7 @@ msgid "Practice bot" msgstr "Robot treningowy" msgid "Press \\key help; to read instructions on your SatCom" -msgstr "" -"Naciśnij klawisz \\key help; aby wyświetlić rozkazy na przekaźniku SatCom" +msgstr "Naciśnij klawisz \\key help; aby wyświetlić rozkazy na przekaźniku SatCom" msgid "Previous" msgstr "Poprzedni" @@ -1314,9 +1293,7 @@ msgid "Semicolon terminator missing" msgstr "Brak średnika na końcu wiersza" msgid "Shadow resolution\\Higher means better range and quality, but slower" -msgstr "" -"Rozdzielczość cieni\\Wyższa wartość oznacza wyższy zasięg i jakość, ale jest " -"wolniejsza" +msgstr "Rozdzielczość cieni\\Wyższa wartość oznacza wyższy zasięg i jakość, ale jest wolniejsza" msgid "Shield level" msgstr "Poziom osłony" @@ -1411,11 +1388,8 @@ msgstr "Pająk śmiertelnie raniony" msgid "Stack overflow" msgstr "Przepełnienie stosu" -msgid "" -"Standard action\\Standard action of the bot (take/grab, shoot, sniff, etc)" -msgstr "" -"Standardowa akcja\\Standardowa akcja robota (podnieś/upuść, strzelaj, " -"szukaj, itp.)" +msgid "Standard action\\Standard action of the bot (take/grab, shoot, sniff, etc)" +msgstr "Standardowa akcja\\Standardowa akcja robota (podnieś/upuść, strzelaj, szukaj, itp.)" msgid "Standard controls\\Standard key functions" msgstr "Standardowa kontrola\\Standardowe klawisze funkcyjne" @@ -1477,8 +1451,7 @@ msgstr "Wyrażenie musi zwrócić wartość logiczną" msgid "The function returned no value " msgstr "Funkcja nie zwróciła żadnej wartości " -msgid "" -"The mission is not accomplished yet (press \\key help; for more details)" +msgid "The mission is not accomplished yet (press \\key help; for more details)" msgstr "Misja nie jest wypełniona (naciśnij \\key help; aby uzyskać szczegóły)" msgid "The types of the two operands are incompatible " @@ -1500,9 +1473,7 @@ msgid "This label does not exist" msgstr "Taka etykieta nie istnieje" msgid "This menu is for userlevels from mods, but you didn't install any" -msgstr "" -"To menu jest przeznaczone na poziomy użytkownika z modyfikacji, ale żadne " -"nie są zainstalowane" +msgstr "To menu jest przeznaczone na poziomy użytkownika z modyfikacji, ale żadne nie są zainstalowane" msgid "This object is not a member of a class" msgstr "Ten obiekt nie jest członkiem klasy" @@ -1699,16 +1670,26 @@ msgstr "Nie możesz przenosić przedmiotów radioaktywnych" msgid "You can not carry an object under water" msgstr "Nie możesz przenosić przedmiotów pod wodą" +#, c-format +msgid "You cannot use \"%s\" in this exercise (used: %d)" +msgstr "Nie możesz użyć \"%s\" w tym ćwiczeniu (użyto: %d)" + msgid "You found a usable object" msgstr "Znaleziono użyteczny przedmiot" #, c-format -msgid "You have to use \"%s\" at least %d times in this exercise (used: %d)" -msgstr "Musisz użyć \"%s\" przynajmniej %d razy w tym ćwiczeniu (użyto: %d)" +msgid "You have to use \"%1$s\" at least once in this exercise (used: %2$d)" +msgid_plural "You have to use \"%1$s\" at least %3$d times in this exercise (used: %2$d)" +msgstr[0] "Musisz użyć \"%1$s\" przynajmniej raz w tym ćwiczeniu (użyto: %2$d)" +msgstr[1] "Musisz użyć \"%1$s\" przynajmniej %3$d razy w tym ćwiczeniu (użyto: %2$d)" +msgstr[2] "Musisz użyć \"%1$s\" przynajmniej %3$d razy w tym ćwiczeniu (użyto: %2$d)" #, c-format -msgid "You have to use \"%s\" at most %d times in this exercise (used: %d)" -msgstr "Musisz użyć \"%s\" najwyżej %d razy w tym ćwiczeniu (użyto: %d)" +msgid "You have to use \"%1$s\" at most once in this exercise (used: %2$d)" +msgid_plural "You have to use \"%1$s\" at most %3$d times in this exercise (used: %2$d)" +msgstr[0] "Możesz użyć \"%1$s\" najwyżej raz w tym ćwiczeniu (użyto: %2$d)" +msgstr[1] "Możesz użyć \"%1$s\" najwyżej %3$d razy w tym ćwiczeniu (użyto: %2$d)" +msgstr[2] "Możesz użyć \"%1$s\" najwyżej %3$d razy w tym ćwiczeniu (użyto: %2$d)" msgid "You must get on the spaceship to take off " msgstr "Musisz być na statku kosmicznym aby nim odlecieć" @@ -1867,8 +1848,7 @@ msgstr "" #~ msgstr "Nieodpowiedni teren" #~ msgid "Key word help\\More detailed help about key words" -#~ msgstr "" -#~ "Pomoc dot. słów kluczowych\\Dokładniejsza pomoc na temat słów kluczowych" +#~ msgstr "Pomoc dot. słów kluczowych\\Dokładniejsza pomoc na temat słów kluczowych" #~ msgid "Loading programs" #~ msgstr "Wczytywanie programów" @@ -1886,8 +1866,7 @@ msgstr "" #~ msgstr "Wciąż za mało energii" #~ msgid "Num of decorative objects\\Number of purely ornamental objects" -#~ msgstr "" -#~ "Ilość elementów dekoracyjnych \\Ilość elementów czysto dekoracyjnych" +#~ msgstr "Ilość elementów dekoracyjnych \\Ilość elementów czysto dekoracyjnych" #~ msgid "Object not found" #~ msgstr "Obiekt nieznany" @@ -1913,12 +1892,8 @@ msgstr "" #~ msgid "Textures\\Quality of textures " #~ msgstr "Tekstury\\Jakość tekstur " -#~ msgid "" -#~ "The list is only available if a \\l;radar station\\u object\\radar; is " -#~ "working.\n" -#~ msgstr "" -#~ "Lista jest dostępna jedynie gdy działa \\l;stacja radarowa\\u object" -#~ "\\radar;.\n" +#~ msgid "The list is only available if a \\l;radar station\\u object\\radar; is working.\n" +#~ msgstr "Lista jest dostępna jedynie gdy działa \\l;stacja radarowa\\u object\\radar;.\n" #~ msgid "Use a joystick\\Joystick or keyboard" #~ msgstr "Używaj joysticka\\Joystick lub klawiatura" diff --git a/po/ru.po b/po/ru.po index 25bb06a3..31d91d65 100644 --- a/po/ru.po +++ b/po/ru.po @@ -95,8 +95,7 @@ msgstr "Выход\\Прервать текущую миссию" msgid "Access beyond array limit" msgstr "Доступ к массиву за предел" -msgid "" -"Access to solution\\Shows the solution (detailed instructions for missions)" +msgid "Access to solution\\Shows the solution (detailed instructions for missions)" msgstr "Доступ к решению\\Показывает решение (подробные инструкции для миссий)" msgid "Access to solutions\\Show program \"4: Solution\" in the exercises" @@ -323,9 +322,7 @@ msgid "Camera back\\Moves the camera backward" msgstr "Отдалить камеру\\Перемещение камеры назад" #, fuzzy -msgid "" -"Camera border scrolling\\Scrolling when the mouse touches right or left " -"border" +msgid "Camera border scrolling\\Scrolling when the mouse touches right or left border" msgstr "Прокрутка\\Прокрутка, когда указатель мыши касается граней экрана" msgid "Camera closer\\Moves the camera forward" @@ -1027,9 +1024,7 @@ msgid "Organic matter" msgstr "Органическое вещество" msgid "Origin of last message\\Shows where the last message was sent from" -msgstr "" -"Источник сообщения\\Показывает место, откуда было отправлено последнеее " -"сообщение" +msgstr "Источник сообщения\\Показывает место, откуда было отправлено последнеее сообщение" msgid "Original game developed by:" msgstr "Оригинальная игра была разработана:" @@ -1156,8 +1151,7 @@ msgid "Programming help (\\key prog;)" msgstr "Помощь в программировании (\\key prog;)" msgid "Programming help\\Gives more detailed help with programming" -msgstr "" -"Помощь в программировании\\Дает более детальную помощь в программировании" +msgstr "Помощь в программировании\\Дает более детальную помощь в программировании" msgid "Programs dispatched by Houston" msgstr "Программы переданные с Хьюстона" @@ -1408,11 +1402,8 @@ msgstr "Паук смертельно ранен" msgid "Stack overflow" msgstr "Переполнение стека" -msgid "" -"Standard action\\Standard action of the bot (take/grab, shoot, sniff, etc)" -msgstr "" -"Стандартное действие\\Стандартное действие бота (брать/взять, стрелять, " -"искать и т.д.)" +msgid "Standard action\\Standard action of the bot (take/grab, shoot, sniff, etc)" +msgstr "Стандартное действие\\Стандартное действие бота (брать/взять, стрелять, искать и т.д.)" msgid "Standard controls\\Standard key functions" msgstr "Стандартное управление\\Сделать управление по умолчанию" @@ -1475,10 +1466,8 @@ msgstr "Выражение должно возвращать логическо msgid "The function returned no value " msgstr "Функция не возвратила значения" -msgid "" -"The mission is not accomplished yet (press \\key help; for more details)" -msgstr "" -"Миссия еще не выполнена (нажмите \\key help; для более подробной информации)" +msgid "The mission is not accomplished yet (press \\key help; for more details)" +msgstr "Миссия еще не выполнена (нажмите \\key help; для более подробной информации)" msgid "The types of the two operands are incompatible " msgstr "Типы операндов несовместимы" @@ -1696,16 +1685,24 @@ msgstr "Вы не можете нести радиоактивные объек msgid "You can not carry an object under water" msgstr "Вы не можете нести объекты под водой" +#, fuzzy, c-format +msgid "You cannot use \"%s\" in this exercise (used: %d)" +msgstr "Не используй в этом упражнении" + msgid "You found a usable object" msgstr "Вы нашли рабочий объект" -#, c-format -msgid "You have to use \"%s\" at least %d times in this exercise (used: %d)" -msgstr "" +#, fuzzy, c-format +msgid "You have to use \"%1$s\" at least once in this exercise (used: %2$d)" +msgid_plural "You have to use \"%1$s\" at least %3$d times in this exercise (used: %2$d)" +msgstr[0] "Не используй в этом упражнении" +msgstr[1] "Не используй в этом упражнении" -#, c-format -msgid "You have to use \"%s\" at most %d times in this exercise (used: %d)" -msgstr "" +#, fuzzy, c-format +msgid "You have to use \"%1$s\" at most once in this exercise (used: %2$d)" +msgid_plural "You have to use \"%1$s\" at most %3$d times in this exercise (used: %2$d)" +msgstr[0] "Не используй в этом упражнении" +msgstr[1] "Не используй в этом упражнении" msgid "You must get on the spaceship to take off " msgstr "Вы должны быть на борту корабля, чтобы взлететь" @@ -1861,9 +1858,6 @@ msgstr "" #~ msgid "Developed by :" #~ msgstr "Разработка :" -#~ msgid "Do not use in this exercise" -#~ msgstr "Не используй в этом упражнении" - #, fuzzy #~ msgid "Do you want to quit Colobot: Gold Edition?" #~ msgstr "Вы хотите закрыть COLOBOT?" @@ -1922,11 +1916,8 @@ msgstr "" #~ msgid "Textures\\Quality of textures " #~ msgstr "Текстуры\\Качество текстур " -#~ msgid "" -#~ "The list is only available if a \\l;radar station\\u object\\radar; is " -#~ "working.\n" -#~ msgstr "" -#~ "Список доступен только если \\l;radar station\\u object\\radar; работают\n" +#~ msgid "The list is only available if a \\l;radar station\\u object\\radar; is working.\n" +#~ msgstr "Список доступен только если \\l;radar station\\u object\\radar; работают\n" #~ msgid "Use a joystick\\Joystick or keyboard" #~ msgstr "Использовать джойстик\\Джойстик или клавиатура" diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 966f9939..2016464f 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -632,8 +632,6 @@ void InitializeRestext() stringsErr[ERR_DELETEMOBILE] = TR("Bot destroyed"); stringsErr[ERR_DELETEBUILDING] = TR("Building destroyed"); stringsErr[ERR_ENEMY_OBJECT] = TR("Unable to control enemy objects"); - stringsErr[ERR_OBLIGATORYTOKEN] = TR("You have to use \"%s\" at least %d times in this exercise (used: %d)"); - stringsErr[ERR_PROHIBITEDTOKEN] = TR("You have to use \"%s\" at most %d times in this exercise (used: %d)"); stringsErr[ERR_WRONG_BOT] = TR("Inappropriate bot"); stringsErr[INFO_BUILD] = TR("Building completed"); diff --git a/src/script/script.cpp b/src/script/script.cpp index 4f7bf323..ff4c04d2 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -44,6 +44,7 @@ #include "ui/controls/interface.h" #include "ui/controls/list.h" +#include const int CBOT_IPF = 100; // CBOT: default number of instructions / frame @@ -774,13 +775,28 @@ void CScript::GetError(std::string& error) } else { - if ( m_error == static_cast(ERR_OBLIGATORYTOKEN) || m_error == static_cast(ERR_PROHIBITEDTOKEN) ) + if (m_error == static_cast(ERR_OBLIGATORYTOKEN)) { - std::string s; - GetResource(RES_ERR, m_error, s); - error = StrUtils::Format(s.c_str(), m_token.c_str(), m_tokenAllowed, m_tokenUsed); + error = StrUtils::Format(ngettext( + "You have to use \"%1$s\" at least once in this exercise (used: %2$d)", + "You have to use \"%1$s\" at least %3$d times in this exercise (used: %2$d)", + m_tokenAllowed), m_token.c_str(), m_tokenUsed, m_tokenAllowed); } - else if ( m_error < 1000 ) + else if (m_error == static_cast(ERR_PROHIBITEDTOKEN)) + { + if (m_tokenAllowed == 0) + { + error = StrUtils::Format(gettext("You cannot use \"%s\" in this exercise (used: %d)"), m_token.c_str(), m_tokenUsed); + } + else + { + error = StrUtils::Format(ngettext( + "You have to use \"%1$s\" at most once in this exercise (used: %2$d)", + "You have to use \"%1$s\" at most %3$d times in this exercise (used: %2$d)", + m_tokenAllowed), m_token.c_str(), m_tokenUsed, m_tokenAllowed); + } + } + else if (m_error < 1000) { GetResource(RES_ERR, m_error, error); } From 139592bc00534dabe4709b1baf5be6aa260edee7 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 9 Apr 2016 18:23:57 +0200 Subject: [PATCH 054/125] Proper l10n for date/time --- src/app/app.cpp | 8 +++-- src/common/misc.cpp | 54 -------------------------------- src/common/misc.h | 4 --- src/level/parser/parserparam.cpp | 4 +++ src/level/parser/parserparam.h | 1 + src/level/robotmain.cpp | 5 +-- src/ui/screen/screen_io.cpp | 2 +- src/ui/studio.cpp | 11 ++++--- 8 files changed, 21 insertions(+), 68 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 43135502..5cc047a5 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -1813,9 +1813,13 @@ void CApplication::SetLanguage(Language language) char* defaultLocale = setlocale(LC_ALL, ""); // Load system locale GetLogger()->Debug("Default system locale: %s\n", defaultLocale); + if (!locale.empty()) // Override system locale? + { + setlocale(LC_ALL, locale.c_str()); + } setlocale(LC_NUMERIC, "C"); // Force numeric locale to "C" (fixes decimal point problems) - char* systemLocale = setlocale(LC_ALL, nullptr); // Get current locale configuration - GetLogger()->Debug("Setting locale: %s\n", systemLocale); + std::string systemLocale = setlocale(LC_ALL, nullptr); // Get current locale configuration + GetLogger()->Debug("Setting locale: %s\n", systemLocale.c_str()); // Update C++ locale try { diff --git a/src/common/misc.cpp b/src/common/misc.cpp index e96f58ed..578b4a61 100644 --- a/src/common/misc.cpp +++ b/src/common/misc.cpp @@ -186,55 +186,6 @@ char GetToLower(char letter) return tolower(letter); } - -// Converting time to string. - -void TimeToAscii(time_t time, char *buffer) -{ - struct tm when; - int year; - - when = *localtime(&time); - year = when.tm_year+1900; - if ( year < 2000 ) year -= 1900; - else year -= 2000; - char format[10]; - int hour; - - hour = when.tm_hour; // 0..23 - if ( hour < 12 ) // morning? - { - strcpy(format, "am"); - } - else // afternoon? - { - strcpy(format, "pm"); - hour -= 12; // 0..11 - } - if ( hour == 0 ) hour = 12; - - sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d %s", - when.tm_mon+1, when.tm_mday, year, - hour, when.tm_min, format); -} - -// Converting time to string. - -void TimeToAsciiClean(time_t time, char *buffer) -{ - struct tm when; - int year; - - when = *localtime(&time); - year = when.tm_year+1900; - if ( year < 2000 ) year -= 1900; - else year -= 2000; - - sprintf(buffer, "%.2d%.2d%.2d%.2d%.2d", - year, when.tm_mon+1, when.tm_mday, - when.tm_hour, when.tm_min); -} - std::string TimeFormat(float time) { int minutes = floor(time/60); @@ -254,8 +205,3 @@ void AddExt(char* filename, const char* ext) if ( strchr(filename, '.') != nullptr ) return; // already an extension? strcat(filename, ext); } - -int GetCurrentTimestamp() -{ - return std::chrono::seconds(std::time(nullptr)).count(); -} diff --git a/src/common/misc.h b/src/common/misc.h index d2927815..4177f3da 100644 --- a/src/common/misc.h +++ b/src/common/misc.h @@ -31,10 +31,6 @@ extern char GetNoAccent(char letter); extern char GetToUpper(char letter); extern char GetToLower(char letter); -extern void TimeToAscii(time_t time, char *buffer); -extern void TimeToAsciiClean(time_t time, char *buffer); extern std::string TimeFormat(float time); extern void AddExt(char* filename, const char* ext); - -extern int GetCurrentTimestamp(); diff --git a/src/level/parser/parserparam.cpp b/src/level/parser/parserparam.cpp index 317d388b..82e6e494 100644 --- a/src/level/parser/parserparam.cpp +++ b/src/level/parser/parserparam.cpp @@ -50,6 +50,10 @@ CLevelParserParam::CLevelParserParam(int value) : m_value(boost::lexical_cast(value)) {} +CLevelParserParam::CLevelParserParam(long value) + : m_value(boost::lexical_cast(value)) +{} + CLevelParserParam::CLevelParserParam(float value) : m_value(boost::lexical_cast(value)) {} diff --git a/src/level/parser/parserparam.h b/src/level/parser/parserparam.h index f620d845..55a2f444 100644 --- a/src/level/parser/parserparam.h +++ b/src/level/parser/parserparam.h @@ -54,6 +54,7 @@ public: //! Create param with given value //@{ CLevelParserParam(int value); + CLevelParserParam(long value); CLevelParserParam(float value); CLevelParserParam(std::string value); CLevelParserParam(bool value); diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index b59cc1f3..e2afb5b7 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -4646,7 +4646,7 @@ bool CRobotMain::IOWriteScene(std::string filename, std::string filecbot, std::s line = MakeUnique("Created"); - line->AddParam("date", MakeUnique(GetCurrentTimestamp())); + line->AddParam("date", MakeUnique(time(nullptr))); levelParser.AddLine(std::move(line)); line = MakeUnique("Mission"); @@ -5700,7 +5700,8 @@ void CRobotMain::Autosave() std::string dir = m_playerProfile->GetSaveFile("autosave" + boost::lexical_cast(id)); char timestr[100]; - TimeToAscii(time(nullptr), timestr); + time_t now = time(nullptr); + strftime(timestr, 99, "%x %X", localtime(&now)); std::string info = std::string("[AUTOSAVE] ")+timestr; m_playerProfile->SaveScene(dir, info); diff --git a/src/ui/screen/screen_io.cpp b/src/ui/screen/screen_io.cpp index 749a6540..19fc79d1 100644 --- a/src/ui/screen/screen_io.cpp +++ b/src/ui/screen/screen_io.cpp @@ -81,7 +81,7 @@ void CScreenIO::IOReadName() } time(&now); - TimeToAsciiClean(now, line); + strftime(line, 99, "%y%m%d%H%M", localtime(&now)); sprintf(name, "%s - %s %d", line, resume.c_str(), m_main->GetLevelRank()); pe->SetText(name); diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index 1b7da4ec..ff34ea4b 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -1282,9 +1282,9 @@ void CStudio::AdjustDialog() { pli->SetPos(ppos); pli->SetDim(ddim); - pli->SetTabs(0, ddim.x-(50.0f+130.0f+16.0f)/640.0f); + pli->SetTabs(0, ddim.x-(50.0f+140.0f+16.0f)/640.0f); pli->SetTabs(1, 50.0f/640.0f, Gfx::TEXT_ALIGN_RIGHT); - pli->SetTabs(2, 130.0f/640.0f); + pli->SetTabs(2, 140.0f/640.0f); //? pli->ShowSelect(); } @@ -1575,7 +1575,7 @@ void CStudio::UpdateDialogList() CWindow* pw; CList* pl; int i = 0; - char time[100]; + char timestr[100]; pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9)); if ( pw == nullptr ) return; @@ -1590,8 +1590,9 @@ void CStudio::UpdateDialogList() for (auto& prog : programs) { std::ostringstream temp; - TimeToAscii(CResourceManager::GetLastModificationTime(SearchDirectory(false) + prog), time); - temp << prog << '\t' << CResourceManager::GetFileSize(SearchDirectory(false) + prog) << " \t" << time; + time_t now = CResourceManager::GetLastModificationTime(SearchDirectory(false) + prog); + strftime(timestr, 99, "%x %X", localtime(&now)); + temp << prog << '\t' << CResourceManager::GetFileSize(SearchDirectory(false) + prog) << " \t" << timestr; pl->SetItemName(i++, temp.str().c_str()); } } From 04d7c343ef20bbf2d634cdd4cd8f923b1d772ab4 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 9 Apr 2016 18:46:12 +0200 Subject: [PATCH 055/125] Removed misc.cpp / misc.h --- src/CMakeLists.txt | 1 - src/common/misc.cpp | 207 ------------------------- src/common/misc.h | 36 ----- src/level/robotmain.cpp | 11 +- src/object/auto/autolabo.cpp | 1 - src/ui/controls/button.cpp | 1 - src/ui/controls/check.cpp | 1 - src/ui/controls/color.cpp | 1 - src/ui/controls/edit.cpp | 17 +- src/ui/controls/editvalue.cpp | 1 - src/ui/controls/group.cpp | 1 - src/ui/controls/image.cpp | 1 - src/ui/controls/scroll.cpp | 1 - src/ui/controls/shortcut.cpp | 1 - src/ui/controls/slider.cpp | 1 - src/ui/displayinfo.cpp | 1 - src/ui/screen/screen_io.cpp | 1 - src/ui/screen/screen_player_select.cpp | 25 --- src/ui/studio.cpp | 11 +- 19 files changed, 17 insertions(+), 303 deletions(-) delete mode 100644 src/common/misc.cpp delete mode 100644 src/common/misc.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 482de23b..d397fb20 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -90,7 +90,6 @@ set(BASE_SOURCES common/key.cpp common/language.cpp common/logger.cpp - common/misc.cpp common/regex_utils.cpp common/resources/inputstream.cpp common/resources/inputstreambuffer.cpp diff --git a/src/common/misc.cpp b/src/common/misc.cpp deleted file mode 100644 index 578b4a61..00000000 --- a/src/common/misc.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsitec.ch; http://colobot.info; http://github.com/colobot - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://gnu.org/licenses - */ - - -#include "common/misc.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -// Returns a non-accented letter. - -char GetNoAccent(char letter) -{ - /* - if ( letter < 0 ) - { - if ( letter == '�' || - letter == '�' || - letter == '�' || - letter == '�' || - letter == '�' ) return 'a'; - - if ( letter == '�' || - letter == '�' || - letter == '�' || - letter == '�' ) return 'e'; - - if ( letter == '�' || - letter == '�' || - letter == '�' || - letter == '�' ) return 'i'; - - if ( letter == '�' || - letter == '�' || - letter == '�' || - letter == '�' || - letter == '�' ) return 'o'; - - if ( letter == '�' || - letter == '�' || - letter == '�' || - letter == '�' ) return 'u'; - - if ( letter == '�' ) return 'c'; - - if ( letter == '�' ) return 'n'; - - if ( letter == '�' || - letter == '�' || - letter == '�' || - letter == '�' || - letter == '�' ) return 'A'; - - if ( letter == '�' || - letter == '�' || - letter == '�' || - letter == '�' ) return 'E'; - - if ( letter == '�' || - letter == '�' || - letter == '�' || - letter == '�' ) return 'I'; - - if ( letter == '�' || - letter == '�' || - letter == '�' || - letter == '�' || - letter == '�' ) return 'O'; - - if ( letter == '�' || - letter == '�' || - letter == '�' || - letter == '�' ) return 'U'; - - if ( letter == '�' ) return 'C'; - - if ( letter == '�' ) return 'N'; - }*/ - - return letter; -} - -// Returns an uppercase letter. - -char GetToUpper(char letter) -{ - /*if ( letter < 0 ) - { - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - - if ( letter == '�' ) return '�'; - - if ( letter == '�' ) return '�'; - }*/ - - return toupper(letter); -} - -// Returns a lowercase letter. - -char GetToLower(char letter) -{ - /*if ( letter < 0 ) - { - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - if ( letter == '�' ) return '�'; - - if ( letter == '�' ) return '�'; - - if ( letter == '�' ) return '�'; - }*/ - - return tolower(letter); -} - -std::string TimeFormat(float time) -{ - int minutes = floor(time/60); - double time2 = fmod(time, 60); - double seconds; - double fraction = modf(time2, &seconds)*100; - std::ostringstream sstream; - sstream << std::setfill('0') << std::setw(2) << minutes << ":" << std::setfill('0') << std::setw(2) << floor(seconds) << "." << std::setfill('0') << std::setw(2) << floor(fraction); - return sstream.str(); -} - - -// Adds an extension to file, if doesn't already one. - -void AddExt(char* filename, const char* ext) -{ - if ( strchr(filename, '.') != nullptr ) return; // already an extension? - strcat(filename, ext); -} diff --git a/src/common/misc.h b/src/common/misc.h deleted file mode 100644 index 4177f3da..00000000 --- a/src/common/misc.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsitec.ch; http://colobot.info; http://github.com/colobot - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://gnu.org/licenses - */ - - -#pragma once - - -#include -#include - - -// TODO: rewrite/refactor or remove - -extern char GetNoAccent(char letter); -extern char GetToUpper(char letter); -extern char GetToLower(char letter); - -extern std::string TimeFormat(float time); - -extern void AddExt(char* filename, const char* ext); diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index e2afb5b7..ff3ae3bc 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -29,7 +29,6 @@ #include "common/event.h" #include "common/logger.h" #include "common/make_unique.h" -#include "common/misc.h" #include "common/restext.h" #include "common/settings.h" #include "common/stringutils.h" @@ -2420,6 +2419,16 @@ void CRobotMain::AbortMovie() } +std::string TimeFormat(float time) +{ + int minutes = static_cast(floor(time/60)); + double time2 = fmod(time, 60); + double seconds; + double fraction = modf(time2, &seconds)*100; + std::ostringstream sstream; + sstream << std::setfill('0') << std::setw(2) << minutes << ":" << std::setfill('0') << std::setw(2) << floor(seconds) << "." << std::setfill('0') << std::setw(2) << floor(fraction); + return sstream.str(); +} //! Updates the text information void CRobotMain::UpdateInfoText() diff --git a/src/object/auto/autolabo.cpp b/src/object/auto/autolabo.cpp index 45375ba8..0fb087d5 100644 --- a/src/object/auto/autolabo.cpp +++ b/src/object/auto/autolabo.cpp @@ -21,7 +21,6 @@ #include "object/auto/autolabo.h" #include "common/make_unique.h" -#include "common/misc.h" #include "level/robotmain.h" diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp index 37d1ad2c..ece43a8d 100644 --- a/src/ui/controls/button.cpp +++ b/src/ui/controls/button.cpp @@ -21,7 +21,6 @@ #include "ui/controls/button.h" #include "common/event.h" -#include "common/misc.h" #include "common/restext.h" #include "graphics/engine/engine.h" diff --git a/src/ui/controls/check.cpp b/src/ui/controls/check.cpp index 80262433..b1b70b41 100644 --- a/src/ui/controls/check.cpp +++ b/src/ui/controls/check.cpp @@ -21,7 +21,6 @@ #include "ui/controls/check.h" #include "common/event.h" -#include "common/misc.h" #include "common/restext.h" #include "graphics/engine/engine.h" diff --git a/src/ui/controls/color.cpp b/src/ui/controls/color.cpp index b92598b3..2aec2a92 100644 --- a/src/ui/controls/color.cpp +++ b/src/ui/controls/color.cpp @@ -21,7 +21,6 @@ #include "ui/controls/color.h" #include "common/event.h" -#include "common/misc.h" #include "common/restext.h" #include "graphics/core/device.h" diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index 9cf9d330..c881aa71 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -27,7 +27,6 @@ #include "common/logger.h" #include "common/make_unique.h" -#include "common/misc.h" #include "common/resources/inputstream.h" #include "common/resources/outputstream.h" @@ -73,15 +72,9 @@ bool IsSpace(int character) //! Indicates whether a character is part of a word. -bool IsWord(int character) +bool IsWord(char c) { - char c; - - c = tolower(GetNoAccent(character)); - - return ( (c >= 'a' && c <= 'z') || - (c >= '0' && c <= '9') || - c == '_' ); + return ( isalnum(c) || c == '_'); } //! Indicates whether a character is a word separator. @@ -2920,13 +2913,13 @@ bool CEdit::MinMaj(bool bMaj) c1 = m_cursor1; c2 = m_cursor2; - if ( c1 > c2 ) Math::Swap(c1, c2); // alwyas c1 <= c2 + if ( c1 > c2 ) Math::Swap(c1, c2); // always c1 <= c2 for ( i=c1 ; i(m_text[i]); - if ( bMaj ) character = GetToUpper(character); - else character = GetToLower(character); + if ( bMaj ) character = toupper(character); + else character = tolower(character); m_text[i] = character; } diff --git a/src/ui/controls/editvalue.cpp b/src/ui/controls/editvalue.cpp index d8e2af7f..cb3d5bb8 100644 --- a/src/ui/controls/editvalue.cpp +++ b/src/ui/controls/editvalue.cpp @@ -22,7 +22,6 @@ #include "common/event.h" #include "common/make_unique.h" -#include "common/misc.h" #include "level/robotmain.h" diff --git a/src/ui/controls/group.cpp b/src/ui/controls/group.cpp index b45b99dd..0f7c8c90 100644 --- a/src/ui/controls/group.cpp +++ b/src/ui/controls/group.cpp @@ -21,7 +21,6 @@ #include "ui/controls/group.h" #include "common/event.h" -#include "common/misc.h" #include "common/restext.h" #include "graphics/engine/engine.h" diff --git a/src/ui/controls/image.cpp b/src/ui/controls/image.cpp index 41b7a1e3..ea365b7f 100644 --- a/src/ui/controls/image.cpp +++ b/src/ui/controls/image.cpp @@ -21,7 +21,6 @@ #include "ui/controls/image.h" #include "common/event.h" -#include "common/misc.h" #include "common/restext.h" #include "graphics/engine/engine.h" diff --git a/src/ui/controls/scroll.cpp b/src/ui/controls/scroll.cpp index e0205893..256a67b6 100644 --- a/src/ui/controls/scroll.cpp +++ b/src/ui/controls/scroll.cpp @@ -22,7 +22,6 @@ #include "common/event.h" #include "common/make_unique.h" -#include "common/misc.h" #include "graphics/engine/engine.h" diff --git a/src/ui/controls/shortcut.cpp b/src/ui/controls/shortcut.cpp index 480da375..ef4f5439 100644 --- a/src/ui/controls/shortcut.cpp +++ b/src/ui/controls/shortcut.cpp @@ -21,7 +21,6 @@ #include "ui/controls/shortcut.h" #include "common/event.h" -#include "common/misc.h" #include "graphics/core/device.h" diff --git a/src/ui/controls/slider.cpp b/src/ui/controls/slider.cpp index eecb4724..6a851782 100644 --- a/src/ui/controls/slider.cpp +++ b/src/ui/controls/slider.cpp @@ -21,7 +21,6 @@ #include "ui/controls/slider.h" #include "common/event.h" -#include "common/misc.h" #include "common/stringutils.h" #include "graphics/engine/engine.h" diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index 0b9c1bd8..325a16aa 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -23,7 +23,6 @@ #include "app/app.h" #include "app/pausemanager.h" -#include "common/misc.h" #include "common/restext.h" #include "common/settings.h" #include "common/stringutils.h" diff --git a/src/ui/screen/screen_io.cpp b/src/ui/screen/screen_io.cpp index 19fc79d1..52e62ee2 100644 --- a/src/ui/screen/screen_io.cpp +++ b/src/ui/screen/screen_io.cpp @@ -20,7 +20,6 @@ #include "ui/screen/screen_io.h" #include "common/logger.h" -#include "common/misc.h" #include "common/restext.h" #include "common/stringutils.h" diff --git a/src/ui/screen/screen_player_select.cpp b/src/ui/screen/screen_player_select.cpp index f4f30c9a..9c707d70 100644 --- a/src/ui/screen/screen_player_select.cpp +++ b/src/ui/screen/screen_player_select.cpp @@ -22,7 +22,6 @@ #include "app/app.h" #include "common/logger.h" -#include "common/misc.h" #include "common/stringutils.h" #include "level/player_profile.h" @@ -388,30 +387,6 @@ bool CScreenPlayerSelect::NameCreate() return false; } - len = strlen(name); - j = 0; - for ( i=0 ; i= '0' && c <= '9') || - (c >= 'a' && c <= 'z') || - c == ' ' || - c == '-' || - c == '_' || - c == '.' || - c == ',' || - c == '\'' ) - { - name[j++] = name[i]; - } - } - name[j] = 0; - if ( j == 0 ) - { - m_sound->Play(SOUND_TZOING); - return false; - } - m_main->SelectPlayer(name); m_main->GetPlayerProfile()->Create(); diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index ff34ea4b..b07b6315 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -25,7 +25,6 @@ #include "common/event.h" #include "common/logger.h" -#include "common/misc.h" #include "common/settings.h" #include "common/resources/resourcemanager.h" @@ -425,15 +424,9 @@ bool CStudio::EventFrame(const Event &event) // Indicates whether a character is part of a word. -bool IsToken(int character) +bool IsToken(char c) { - char c; - - c = tolower(GetNoAccent(character)); - - return ( (c >= 'a' && c <= 'z') || - (c >= '0' && c <= '9') || - c == '_' ); + return ( isalnum(c) || c == '_' ); } // Seeks if the cursor is on a keyword. From e75ed79fb5cb65431f5826a544164bba542035cf Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 9 Apr 2016 18:47:26 +0200 Subject: [PATCH 056/125] Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 17b8846a..229394cd 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 17b8846ac97a26de006c456fe645724199155403 +Subproject commit 229394cda28955dfa6ec554c58365d11c647f55c From 32af7f45df055a3504559ca5bb2b13461d89d808 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 9 Apr 2016 18:52:15 +0200 Subject: [PATCH 057/125] Fixed missing #includes --- src/level/robotmain.cpp | 1 + src/ui/studio.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index ff3ae3bc..e1fb2392 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -107,6 +107,7 @@ #include #include +#include #include diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index b07b6315..483d89b7 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -62,6 +62,7 @@ #include "ui/controls/window.h" #include +#include namespace Ui From 4de9d25f048441e3d4b64245f53e56a09779634e Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 9 Apr 2016 18:58:34 +0200 Subject: [PATCH 058/125] Man, those compile errors... --- src/app/app.cpp | 2 +- src/level/parser/parserparam.cpp | 4 ---- src/level/parser/parserparam.h | 1 - src/level/robotmain.cpp | 2 +- src/ui/screen/screen_player_select.cpp | 4 +--- 5 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 5cc047a5..c1439ff1 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -1823,7 +1823,7 @@ void CApplication::SetLanguage(Language language) // Update C++ locale try { - std::locale::global(std::locale(systemLocale)); + std::locale::global(std::locale(systemLocale.c_str())); } catch (...) { diff --git a/src/level/parser/parserparam.cpp b/src/level/parser/parserparam.cpp index 82e6e494..317d388b 100644 --- a/src/level/parser/parserparam.cpp +++ b/src/level/parser/parserparam.cpp @@ -50,10 +50,6 @@ CLevelParserParam::CLevelParserParam(int value) : m_value(boost::lexical_cast(value)) {} -CLevelParserParam::CLevelParserParam(long value) - : m_value(boost::lexical_cast(value)) -{} - CLevelParserParam::CLevelParserParam(float value) : m_value(boost::lexical_cast(value)) {} diff --git a/src/level/parser/parserparam.h b/src/level/parser/parserparam.h index 55a2f444..f620d845 100644 --- a/src/level/parser/parserparam.h +++ b/src/level/parser/parserparam.h @@ -54,7 +54,6 @@ public: //! Create param with given value //@{ CLevelParserParam(int value); - CLevelParserParam(long value); CLevelParserParam(float value); CLevelParserParam(std::string value); CLevelParserParam(bool value); diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index e1fb2392..9104f3b2 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -4656,7 +4656,7 @@ bool CRobotMain::IOWriteScene(std::string filename, std::string filecbot, std::s line = MakeUnique("Created"); - line->AddParam("date", MakeUnique(time(nullptr))); + line->AddParam("date", MakeUnique(static_cast(time(nullptr)))); levelParser.AddLine(std::move(line)); line = MakeUnique("Mission"); diff --git a/src/ui/screen/screen_player_select.cpp b/src/ui/screen/screen_player_select.cpp index 9c707d70..678f8286 100644 --- a/src/ui/screen/screen_player_select.cpp +++ b/src/ui/screen/screen_player_select.cpp @@ -370,9 +370,6 @@ bool CScreenPlayerSelect::NameCreate() { CWindow* pw; CEdit* pe; - char name[100]; - char c; - int len, i, j; GetLogger()->Info("Creating new player\n"); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); @@ -380,6 +377,7 @@ bool CScreenPlayerSelect::NameCreate() pe = static_cast(pw->SearchControl(EVENT_INTERFACE_NEDIT)); if ( pe == nullptr ) return false; + char name[100]; pe->GetText(name, 100); if ( name[0] == 0 ) { From dd8a324f9b87710280cd4ec2aeaeb6e7e7630917 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 10 Apr 2016 13:27:56 +0200 Subject: [PATCH 059/125] Fixed crash when loading level with incorrect object type --- src/level/parser/parserparam.cpp | 2 +- src/level/parser/parserparam.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/level/parser/parserparam.cpp b/src/level/parser/parserparam.cpp index 317d388b..fb3c82f7 100644 --- a/src/level/parser/parserparam.cpp +++ b/src/level/parser/parserparam.cpp @@ -530,7 +530,7 @@ ObjectType CLevelParserParam::ToObjectType(std::string value) if (value == "Me" ) return OBJECT_HUMAN; if (value == "Tech" ) return OBJECT_TECH; if (value == "MissionController" ) return OBJECT_CONTROLLER; - return static_cast(boost::lexical_cast(value)); + return static_cast(Cast(value, "object")); } const std::string CLevelParserParam::FromObjectType(ObjectType value) diff --git a/src/level/parser/parserparam.h b/src/level/parser/parserparam.h index f620d845..c72be4f0 100644 --- a/src/level/parser/parserparam.h +++ b/src/level/parser/parserparam.h @@ -123,7 +123,6 @@ public: bool IsDefined(); static const std::string FromObjectType(ObjectType value); - static ObjectType ToObjectType(std::string value); private: void ParseArray(); @@ -133,6 +132,7 @@ private: template T Cast(std::string requestedType); std::string ToPath(std::string path, const std::string defaultDir); + ObjectType ToObjectType(std::string value); DriveType ToDriveType(std::string value); ToolType ToToolType(std::string value); Gfx::WaterType ToWaterType(std::string value); From 952a5423fd598413fcae08e4f21a77c0e020e706 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 10 Apr 2016 13:53:34 +0200 Subject: [PATCH 060/125] Fixed non-power-of-2 images in SatCom (closes #634); fixed not unloading textures on SatCom close --- src/ui/controls/edit.cpp | 42 ++++++++++++++++++++++------------------ src/ui/controls/edit.h | 1 - 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index c881aa71..0cb3763b 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -1127,25 +1127,41 @@ void CEdit::Draw() // Draw an image part. +std::string PrepareImageFilename(std::string name) +{ + std::string filename; + filename = name + ".png"; + filename = InjectLevelPathsForCurrentLevel(filename, "icons"); + boost::replace_all(filename, "\\", "/"); // TODO: Fix this in files + return filename; +} + void CEdit::DrawImage(Math::Point pos, std::string name, float width, float offset, float height, int nbLine) { Math::Point uv1, uv2, dim; float dp; - std::string filename; - filename = name + ".png"; - filename = InjectLevelPathsForCurrentLevel(filename, "icons"); - boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files - - m_engine->SetTexture(filename); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); + Gfx::TextureCreateParams params; + params.format = Gfx::TEX_IMG_AUTO; + params.filter = Gfx::TEX_FILTER_BILINEAR; + params.padToNearestPowerOfTwo = true; + Gfx::Texture tex = m_engine->LoadTexture(PrepareImageFilename(name), params); + + m_engine->SetTexture(tex); + uv1.x = 0.0f; uv2.x = 1.0f; uv1.y = offset; uv2.y = offset+height; + uv1.x *= static_cast(tex.originalSize.x) / static_cast(tex.size.x); + uv2.x *= static_cast(tex.originalSize.x) / static_cast(tex.size.x); + uv1.y *= static_cast(tex.originalSize.y) / static_cast(tex.size.y); + uv2.y *= static_cast(tex.originalSize.y) / static_cast(tex.size.y); + dp = 0.5f/256.0f; uv1.x += dp; uv1.y += dp; @@ -1415,21 +1431,10 @@ void CEdit::FreeImage() { for (auto& image : m_image) { - m_engine->DeleteTexture(image.name + ".png"); + m_engine->DeleteTexture(PrepareImageFilename(image.name)); } } -// Reads the texture of an image. - -void CEdit::LoadImage(std::string name) -{ - std::string filename; - filename = name + ".png"; - filename = InjectLevelPathsForCurrentLevel(filename, "icons"); - boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files - m_engine->LoadTexture(filename); -} - // Read from a text file. bool CEdit::ReadText(std::string filename, int addSize) @@ -1632,7 +1637,6 @@ bool CEdit::ReadText(std::string filename, int addSize) iWidth = static_cast(GetValueParam(buffer.data()+i+7, 1)); iWidth *= m_engine->GetText()->GetHeight(Gfx::FONT_COLOBOT, Gfx::FONT_SIZE_SMALL); iLines = GetValueParam(buffer.data()+i+7, 2); - LoadImage(std::string(iName)); // A part of image per line of text. for ( iCount=0 ; iCount Date: Tue, 19 Apr 2016 10:36:06 -0400 Subject: [PATCH 061/125] Fix checking parameters in CBotFunction --- src/CBot/CBotInstr/CBotFunction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index 4c016d3b..4c15a416 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -840,8 +840,8 @@ bool CBotFunction::CheckParam(CBotDefParam* pParam) CBotDefParam* pp = m_param; while ( pp != nullptr && pParam != nullptr ) { - CBotTypResult type1 = pp->GetType(); - CBotTypResult type2 = pParam->GetType(); + CBotTypResult type1 = pp->GetTypResult(); + CBotTypResult type2 = pParam->GetTypResult(); if ( !type1.Compare(type2) ) return false; pp = pp->GetNext(); pParam = pParam->GetNext(); From 7c551dc39ddcdc42ee4a11250d57a59ef446f4c9 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 19 Apr 2016 21:09:41 +0200 Subject: [PATCH 062/125] Added unit tests for #768 --- test/unit/CBot/CBot_test.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/unit/CBot/CBot_test.cpp b/test/unit/CBot/CBot_test.cpp index 63c3e918..f130666f 100644 --- a/test/unit/CBot/CBot_test.cpp +++ b/test/unit/CBot/CBot_test.cpp @@ -647,6 +647,18 @@ TEST_F(CBotUT, FunctionRedefined) "}\n", CBotErrRedefFunc ); + + ExecuteTest( + "int func(int[] test)\n" + "{\n" + " return 1;\n" + "}\n" + "int func(int[] test)\n" + "{\n" + " return 2;\n" + "}\n", + CBotErrRedefFunc + ); } // TODO: Doesn't work @@ -845,6 +857,18 @@ TEST_F(CBotUT, ClassMethodRedefined) "}\n", CBotErrRedefFunc ); + + ExecuteTest( + "public class TestClass {\n" + " public int test(int[] test) {\n" + " return 1;\n" + " }\n" + " public int test(int[] test) {\n" + " return 2;\n" + " }\n" + "}\n", + CBotErrRedefFunc + ); } // TODO: Not only doesn't work but segfaults From c00a7fd13241272106e6a4f78977a8d766b0e86e Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 22 Apr 2016 19:20:31 +0200 Subject: [PATCH 063/125] Do not zoom while scrolling lists, closes #769 --- src/ui/controls/edit.cpp | 2 +- src/ui/controls/editvalue.cpp | 1 + src/ui/controls/list.cpp | 2 +- src/ui/controls/scroll.cpp | 1 + src/ui/controls/slider.cpp | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index 0cb3763b..c46d5b0b 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -248,7 +248,7 @@ bool CEdit::EventProcess(const Event &event) { auto data = event.GetData(); Scroll(m_lineFirst - data->y, true); - return true; + return false; } CControl::EventProcess(event); diff --git a/src/ui/controls/editvalue.cpp b/src/ui/controls/editvalue.cpp index cb3d5bb8..21bb3d46 100644 --- a/src/ui/controls/editvalue.cpp +++ b/src/ui/controls/editvalue.cpp @@ -190,6 +190,7 @@ bool CEditValue::EventProcess(const Event &event) if ( value > m_maxValue ) value = m_maxValue; SetValue(value, true); HiliteValue(event); + return false; } return true; diff --git a/src/ui/controls/list.cpp b/src/ui/controls/list.cpp index dc4de23e..88d36d94 100644 --- a/src/ui/controls/list.cpp +++ b/src/ui/controls/list.cpp @@ -288,7 +288,7 @@ bool CList::EventProcess(const Event &event) UpdateScroll(); UpdateButton(); - return true; + return false; } CControl::EventProcess(event); diff --git a/src/ui/controls/scroll.cpp b/src/ui/controls/scroll.cpp index 256a67b6..e47e561f 100644 --- a/src/ui/controls/scroll.cpp +++ b/src/ui/controls/scroll.cpp @@ -291,6 +291,7 @@ bool CScroll::EventProcess(const Event &event) m_event->AddEvent(Event(m_buttonDown->GetEventType())); } } + return false; } return true; diff --git a/src/ui/controls/slider.cpp b/src/ui/controls/slider.cpp index 6a851782..a4926005 100644 --- a/src/ui/controls/slider.cpp +++ b/src/ui/controls/slider.cpp @@ -356,6 +356,7 @@ bool CSlider::EventProcess(const Event &event) m_event->AddEvent(Event(m_buttonRight->GetEventType())); } } + return false; } return true; From 9870cfe8a882af9318b00635a16bc55bc876875e Mon Sep 17 00:00:00 2001 From: tomangelo2 Date: Mon, 2 May 2016 01:27:07 +0200 Subject: [PATCH 064/125] Clamp FogStart value to 0 if negative Should fix issue #766 --- src/graphics/engine/engine.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 8b0b40e5..aeb6dcb2 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -2733,7 +2733,10 @@ float CEngine::GetDeepView(int rank) void CEngine::SetFogStart(float start, int rank) { - m_fogStart[rank] = start; + if (start < 0.0f) + m_fogStart[rank] = 0.0f; + else + m_fogStart[rank] = start; } float CEngine::GetFogStart(int rank) From 734e6e97c06df98bb6c7584aa26b4ff26d20a39a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Przyby=C5=82?= Date: Mon, 2 May 2016 12:14:18 +0200 Subject: [PATCH 065/125] Group source files for IDE projects in CMake Merge pull request #773 from MrSimbax/msvc-project-org-cmake --- CMakeLists.txt | 5 + src/CBot/CMakeLists.txt | 98 ++++++- src/CMakeLists.txt | 636 ++++++++++++++++++++++++++++------------ 3 files changed, 538 insertions(+), 201 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 72e22179..dd412fb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,7 @@ if("${CMAKE_SYSTEM_NAME}" MATCHES "Windows") # Platform-dependent implementation of system.h set(SYSTEM_CPP_MODULE "system_windows.cpp") + set(SYSTEM_H_MODULE "system_windows.h") elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") message(STATUS "Build for Linux system") set(PLATFORM_WINDOWS 0) @@ -74,6 +75,7 @@ elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") # Platform-dependent implementation of system.h set(SYSTEM_CPP_MODULE "system_linux.cpp") + set(SYSTEM_H_MODULE "system_linux.h") elseif("${CMAKE_SYSTEM_NAME}" MATCHES "kFreeBSD" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "GNU") message(STATUS "Build for kFreeBSD system") set(PLATFORM_WINDOWS 0) @@ -84,6 +86,7 @@ elseif("${CMAKE_SYSTEM_NAME}" MATCHES "kFreeBSD" OR "${CMAKE_SYSTEM_NAME}" STREQ # Platform-dependent implementation of system.h set(SYSTEM_CPP_MODULE "system_other.cpp") + set(SYSTEM_H_MODULE "system_other.h") elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") message(STATUS "Build for Mac OSX system") set(PLATFORM_WINDOWS 0) @@ -94,6 +97,7 @@ elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") # Platform-dependent implementation of system.h set(SYSTEM_CPP_MODULE "system_macosx.cpp") + set(SYSTEM_H_MODULE "system_macosx.h") # To avoid CMake warning set(CMAKE_MACOSX_RPATH 1) else() @@ -106,6 +110,7 @@ else() # Platform-dependent implementation of system.h set(SYSTEM_CPP_MODULE "system_other.cpp") + set(SYSTEM_H_MODULE "system_other.h") endif() diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 1f17e6bb..dbd3d02e 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -1,75 +1,148 @@ set(SOURCES - CBotCallMethode.cpp - CBotClass.cpp + CBot.h CBotCStack.cpp + CBotCStack.h + CBotCallMethode.cpp + CBotCallMethode.h + CBotClass.cpp + CBotClass.h CBotDebug.cpp + CBotDebug.h CBotDefParam.cpp + CBotDefParam.h + CBotDefines.h + CBotEnums.h CBotExternalCall.cpp + CBotExternalCall.h CBotFileUtils.cpp - CBotProgram.cpp - CBotStack.cpp - CBotToken.cpp - CBotTypResult.cpp - CBotUtils.cpp + CBotFileUtils.h CBotInstr/CBotBlock.cpp + CBotInstr/CBotBlock.h CBotInstr/CBotBoolExpr.cpp + CBotInstr/CBotBoolExpr.h CBotInstr/CBotBreak.cpp + CBotInstr/CBotBreak.h CBotInstr/CBotCase.cpp + CBotInstr/CBotCase.h CBotInstr/CBotCatch.cpp + CBotInstr/CBotCatch.h CBotInstr/CBotCondition.cpp + CBotInstr/CBotCondition.h CBotInstr/CBotDefArray.cpp + CBotInstr/CBotDefArray.h CBotInstr/CBotDefBoolean.cpp + CBotInstr/CBotDefBoolean.h CBotInstr/CBotDefClass.cpp + CBotInstr/CBotDefClass.h CBotInstr/CBotDefFloat.cpp + CBotInstr/CBotDefFloat.h CBotInstr/CBotDefInt.cpp + CBotInstr/CBotDefInt.h CBotInstr/CBotDefString.cpp + CBotInstr/CBotDefString.h CBotInstr/CBotDo.cpp + CBotInstr/CBotDo.h CBotInstr/CBotEmpty.cpp - CBotInstr/CBotExpression.cpp + CBotInstr/CBotEmpty.h CBotInstr/CBotExprLitBool.cpp + CBotInstr/CBotExprLitBool.h CBotInstr/CBotExprLitNan.cpp + CBotInstr/CBotExprLitNan.h CBotInstr/CBotExprLitNull.cpp + CBotInstr/CBotExprLitNull.h CBotInstr/CBotExprLitNum.cpp + CBotInstr/CBotExprLitNum.h CBotInstr/CBotExprLitString.cpp + CBotInstr/CBotExprLitString.h CBotInstr/CBotExprUnaire.cpp + CBotInstr/CBotExprUnaire.h CBotInstr/CBotExprVar.cpp + CBotInstr/CBotExprVar.h + CBotInstr/CBotExpression.cpp + CBotInstr/CBotExpression.h CBotInstr/CBotFieldExpr.cpp + CBotInstr/CBotFieldExpr.h CBotInstr/CBotFor.cpp + CBotInstr/CBotFor.h CBotInstr/CBotFunction.cpp + CBotInstr/CBotFunction.h CBotInstr/CBotIf.cpp + CBotInstr/CBotIf.h CBotInstr/CBotIndexExpr.cpp - CBotInstr/CBotInstrCall.cpp + CBotInstr/CBotIndexExpr.h CBotInstr/CBotInstr.cpp + CBotInstr/CBotInstr.h + CBotInstr/CBotInstrCall.cpp + CBotInstr/CBotInstrCall.h CBotInstr/CBotInstrMethode.cpp + CBotInstr/CBotInstrMethode.h CBotInstr/CBotInstrUtils.cpp + CBotInstr/CBotInstrUtils.h CBotInstr/CBotLeftExpr.cpp + CBotInstr/CBotLeftExpr.h CBotInstr/CBotLeftExprVar.cpp + CBotInstr/CBotLeftExprVar.h CBotInstr/CBotListArray.cpp + CBotInstr/CBotListArray.h CBotInstr/CBotListExpression.cpp + CBotInstr/CBotListExpression.h CBotInstr/CBotListInstr.cpp + CBotInstr/CBotListInstr.h CBotInstr/CBotLogicExpr.cpp + CBotInstr/CBotLogicExpr.h CBotInstr/CBotNew.cpp + CBotInstr/CBotNew.h CBotInstr/CBotParExpr.cpp + CBotInstr/CBotParExpr.h CBotInstr/CBotPostIncExpr.cpp + CBotInstr/CBotPostIncExpr.h CBotInstr/CBotPreIncExpr.cpp + CBotInstr/CBotPreIncExpr.h CBotInstr/CBotReturn.cpp + CBotInstr/CBotReturn.h CBotInstr/CBotSwitch.cpp + CBotInstr/CBotSwitch.h CBotInstr/CBotThrow.cpp + CBotInstr/CBotThrow.h CBotInstr/CBotTry.cpp + CBotInstr/CBotTry.h CBotInstr/CBotTwoOpExpr.cpp + CBotInstr/CBotTwoOpExpr.h CBotInstr/CBotWhile.cpp - CBotVar/CBotVarArray.cpp - CBotVar/CBotVarBoolean.cpp - CBotVar/CBotVarClass.cpp + CBotInstr/CBotWhile.h + CBotProgram.cpp + CBotProgram.h + CBotStack.cpp + CBotStack.h + CBotToken.cpp + CBotToken.h + CBotTypResult.cpp + CBotTypResult.h + CBotUtils.cpp + CBotUtils.h CBotVar/CBotVar.cpp + CBotVar/CBotVar.h + CBotVar/CBotVarArray.cpp + CBotVar/CBotVarArray.h + CBotVar/CBotVarBoolean.cpp + CBotVar/CBotVarBoolean.h + CBotVar/CBotVarClass.cpp + CBotVar/CBotVarClass.h CBotVar/CBotVarFloat.cpp + CBotVar/CBotVarFloat.h CBotVar/CBotVarInt.cpp + CBotVar/CBotVarInt.h CBotVar/CBotVarPointer.cpp + CBotVar/CBotVarPointer.h CBotVar/CBotVarString.cpp + CBotVar/CBotVarString.h stdlib/Compilation.cpp + stdlib/Compilation.h stdlib/FileFunctions.cpp stdlib/MathFunctions.cpp stdlib/StringFunctions.cpp + stdlib/stdlib.h + stdlib/stdlib_public.h ) # Includes @@ -90,3 +163,4 @@ else() RUNTIME DESTINATION ${COLOBOT_INSTALL_BIN_DIR}) endif() +group_sources("${SOURCES}" "Source Files") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d397fb20..f619cac7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,15 @@ set(CMAKE_CXX_FLAGS "${COLOBOT_CXX_FLAGS} ${MXE_CFLAGS}") set(CMAKE_CXX_FLAGS_RELEASE ${COLOBOT_CXX_FLAGS_RELEASE}) set(CMAKE_CXX_FLAGS_DEBUG ${COLOBOT_CXX_FLAGS_DEBUG}) +# Groups source files for IDE project +macro(group_sources SOURCES GROUP_ROOT) + foreach(SOURCE_FILE ${SOURCES}) + get_filename_component(GROUP "${SOURCE_FILE}" PATH) + string(REPLACE "/" "\\" GROUP "${GROUP}") + set(GROUP "${GROUP_ROOT}\\${GROUP}") + source_group("${GROUP}" FILES "${SOURCE_FILE}") + endforeach() +endmacro() # Subdirectories @@ -64,6 +73,10 @@ if(OPENAL_SOUND) sound/oalsound/buffer.cpp sound/oalsound/channel.cpp sound/oalsound/check.cpp + sound/oalsound/alsound.h + sound/oalsound/buffer.h + sound/oalsound/channel.h + sound/oalsound/check.h ) endif() @@ -75,195 +88,439 @@ endif() # Source files set(BASE_SOURCES - app/app.cpp - app/controller.cpp - app/input.cpp - app/pathman.cpp - app/pausemanager.cpp - app/signal_handlers.cpp - app/system.cpp - app/${SYSTEM_CPP_MODULE} - app/system_other.cpp - common/config_file.cpp - common/event.cpp - common/image.cpp - common/key.cpp - common/language.cpp - common/logger.cpp - common/regex_utils.cpp - common/resources/inputstream.cpp - common/resources/inputstreambuffer.cpp - common/resources/outputstream.cpp - common/resources/outputstreambuffer.cpp - common/resources/resourcemanager.cpp - common/resources/sdl_file_wrapper.cpp - common/resources/sdl_memory_wrapper.cpp - common/resources/sndfile_wrapper.cpp - common/restext.cpp - common/settings.cpp - common/stringutils.cpp - graphics/core/color.cpp - graphics/core/framebuffer.cpp - graphics/core/nulldevice.cpp - graphics/engine/camera.cpp - graphics/engine/cloud.cpp - graphics/engine/engine.cpp - graphics/engine/lightman.cpp - graphics/engine/lightning.cpp - graphics/engine/oldmodelmanager.cpp - graphics/engine/particle.cpp - graphics/engine/planet.cpp - graphics/engine/pyro.cpp - graphics/engine/pyro_manager.cpp - graphics/engine/terrain.cpp - graphics/engine/text.cpp - graphics/engine/water.cpp - graphics/opengl/gl21device.cpp - graphics/opengl/gl33device.cpp - graphics/opengl/gldevice.cpp - graphics/opengl/glframebuffer.cpp - graphics/opengl/glutil.cpp - graphics/model/model.cpp - graphics/model/model_input.cpp - graphics/model/model_manager.cpp - graphics/model/model_mesh.cpp - graphics/model/model_output.cpp - level/level_category.cpp - level/mainmovie.cpp - level/player_profile.cpp - level/robotmain.cpp - level/scene_conditions.cpp - level/parser/parser.cpp - level/parser/parserexceptions.cpp - level/parser/parserline.cpp - level/parser/parserparam.cpp - object/auto/auto.cpp - object/auto/autobase.cpp - object/auto/autoconvert.cpp - object/auto/autoderrick.cpp - object/auto/autodestroyer.cpp - object/auto/autoegg.cpp - object/auto/autopowerplant.cpp - object/auto/autofactory.cpp - object/auto/autoflag.cpp - object/auto/autohouston.cpp - object/auto/autojostle.cpp - object/auto/autokid.cpp - object/auto/autolabo.cpp - object/auto/automush.cpp - object/auto/autonest.cpp - object/auto/autonuclearplant.cpp - object/auto/autopowercaptor.cpp - object/auto/autoportico.cpp - object/auto/autoradar.cpp - object/auto/autorepair.cpp - object/auto/autoresearch.cpp - object/auto/autoroot.cpp - object/auto/autovault.cpp - object/auto/autopowerstation.cpp - object/auto/autotower.cpp - object/drive_type.cpp - object/interface/trace_drawing_object.cpp - object/implementation/power_container_impl.cpp - object/implementation/programmable_impl.cpp - object/implementation/program_storage_impl.cpp - object/implementation/task_executor_impl.cpp - object/motion/motion.cpp - object/motion/motionant.cpp - object/motion/motionbee.cpp - object/motion/motionlevelcontroller.cpp - object/motion/motionhuman.cpp - object/motion/motionqueen.cpp - object/motion/motionspider.cpp - object/motion/motiontoto.cpp - object/motion/motionvehicle.cpp - object/motion/motionworm.cpp - object/object.cpp - object/object_factory.cpp - object/object_manager.cpp - object/old_object.cpp - object/old_object_interface.cpp - object/task/task.cpp - object/task/taskadvance.cpp - object/task/taskbuild.cpp - object/task/taskdeletemark.cpp - object/task/taskfire.cpp - object/task/taskfireant.cpp - object/task/taskflag.cpp - object/task/taskgoto.cpp - object/task/taskgungoal.cpp - object/task/taskinfo.cpp - object/task/taskmanip.cpp - object/task/taskpen.cpp - object/task/taskrecover.cpp - object/task/tasksearch.cpp - object/task/taskshield.cpp - object/task/taskspiderexplo.cpp - object/task/tasktake.cpp - object/task/taskterraform.cpp - object/task/taskturn.cpp - object/task/taskwait.cpp - object/tool_type.cpp - object/subclass/base_alien.cpp - object/subclass/base_building.cpp - object/subclass/base_robot.cpp - object/subclass/base_vehicle.cpp - object/subclass/exchange_post.cpp - object/subclass/shielder.cpp - object/subclass/static_object.cpp - physics/physics.cpp - script/cbottoken.cpp - script/script.cpp - script/scriptfunc.cpp - sound/sound.cpp - sound/sound_type.cpp - ui/debug_menu.cpp - ui/displayinfo.cpp - ui/displaytext.cpp - ui/object_interface.cpp - ui/maindialog.cpp - ui/mainmap.cpp - ui/mainshort.cpp - ui/mainui.cpp - ui/studio.cpp - ui/controls/button.cpp - ui/controls/check.cpp - ui/controls/color.cpp - ui/controls/control.cpp - ui/controls/edit.cpp - ui/controls/editvalue.cpp - ui/controls/enumslider.cpp - ui/controls/gauge.cpp - ui/controls/group.cpp - ui/controls/image.cpp - ui/controls/interface.cpp - ui/controls/key.cpp - ui/controls/label.cpp - ui/controls/list.cpp - ui/controls/map.cpp - ui/controls/scroll.cpp - ui/controls/shortcut.cpp - ui/controls/slider.cpp - ui/controls/target.cpp - ui/controls/window.cpp - ui/screen/screen.cpp - ui/screen/screen_apperance.cpp - ui/screen/screen_io.cpp - ui/screen/screen_io_read.cpp - ui/screen/screen_io_write.cpp - ui/screen/screen_level_list.cpp - ui/screen/screen_loading.cpp - ui/screen/screen_main_menu.cpp - ui/screen/screen_player_select.cpp - ui/screen/screen_quit.cpp - ui/screen/screen_setup.cpp - ui/screen/screen_setup_controls.cpp - ui/screen/screen_setup_display.cpp - ui/screen/screen_setup_game.cpp - ui/screen/screen_setup_graphics.cpp - ui/screen/screen_setup_sound.cpp - ui/screen/screen_welcome.cpp ${OPENAL_SRC} + app/${SYSTEM_CPP_MODULE} + app/${SYSTEM_H_MODULE} + app/app.cpp + app/app.h + app/controller.cpp + app/controller.h + app/input.cpp + app/input.h + app/pathman.cpp + app/pathman.h + app/pausemanager.cpp + app/pausemanager.h + app/signal_handlers.cpp + app/signal_handlers.h + app/system.cpp + app/system.h + app/system_other.cpp + app/system_other.h + common/config_file.cpp + common/config_file.h + common/error.h + common/event.cpp + common/event.h + common/global.h + common/image.cpp + common/image.h + common/ioutils.h + common/key.cpp + common/key.h + common/language.cpp + common/language.h + common/logger.cpp + common/logger.h + common/make_unique.h + common/regex_utils.cpp + common/regex_utils.h + common/resources/inputstream.cpp + common/resources/inputstream.h + common/resources/inputstreambuffer.cpp + common/resources/inputstreambuffer.h + common/resources/outputstream.cpp + common/resources/outputstream.h + common/resources/outputstreambuffer.cpp + common/resources/outputstreambuffer.h + common/resources/resourcemanager.cpp + common/resources/resourcemanager.h + common/resources/sdl_file_wrapper.cpp + common/resources/sdl_file_wrapper.h + common/resources/sdl_memory_wrapper.cpp + common/resources/sdl_memory_wrapper.h + common/resources/sndfile_wrapper.cpp + common/resources/sndfile_wrapper.h + common/restext.cpp + common/restext.h + common/settings.cpp + common/settings.h + common/singleton.h + common/stringutils.cpp + common/stringutils.h + common/thread/resource_owning_thread.h + common/thread/sdl_cond_wrapper.h + common/thread/sdl_mutex_wrapper.h + graphics/core/color.cpp + graphics/core/color.h + graphics/core/device.h + graphics/core/framebuffer.cpp + graphics/core/framebuffer.h + graphics/core/light.h + graphics/core/material.h + graphics/core/nulldevice.cpp + graphics/core/nulldevice.h + graphics/core/texture.h + graphics/core/vertex.h + graphics/engine/camera.cpp + graphics/engine/camera.h + graphics/engine/cloud.cpp + graphics/engine/cloud.h + graphics/engine/engine.cpp + graphics/engine/engine.h + graphics/engine/lightman.cpp + graphics/engine/lightman.h + graphics/engine/lightning.cpp + graphics/engine/lightning.h + graphics/engine/oldmodelmanager.cpp + graphics/engine/oldmodelmanager.h + graphics/engine/particle.cpp + graphics/engine/particle.h + graphics/engine/planet.cpp + graphics/engine/planet.h + graphics/engine/pyro.cpp + graphics/engine/pyro.h + graphics/engine/pyro_manager.cpp + graphics/engine/pyro_manager.h + graphics/engine/pyro_type.h + graphics/engine/terrain.cpp + graphics/engine/terrain.h + graphics/engine/text.cpp + graphics/engine/text.h + graphics/engine/water.cpp + graphics/engine/water.h + graphics/model/model.cpp + graphics/model/model.h + graphics/model/model_crash_sphere.h + graphics/model/model_format.h + graphics/model/model_input.cpp + graphics/model/model_input.h + graphics/model/model_io_exception.h + graphics/model/model_io_structs.h + graphics/model/model_manager.cpp + graphics/model/model_manager.h + graphics/model/model_mesh.cpp + graphics/model/model_mesh.h + graphics/model/model_output.cpp + graphics/model/model_output.h + graphics/model/model_shadow_spot.h + graphics/model/model_triangle.h + graphics/opengl/gl21device.cpp + graphics/opengl/gl21device.h + graphics/opengl/gl33device.cpp + graphics/opengl/gl33device.h + graphics/opengl/gldevice.cpp + graphics/opengl/gldevice.h + graphics/opengl/glframebuffer.cpp + graphics/opengl/glframebuffer.h + graphics/opengl/glutil.cpp + graphics/opengl/glutil.h + level/build_type.h + level/level_category.cpp + level/level_category.h + level/mainmovie.cpp + level/mainmovie.h + level/parser/parser.cpp + level/parser/parser.h + level/parser/parserexceptions.cpp + level/parser/parserexceptions.h + level/parser/parserline.cpp + level/parser/parserline.h + level/parser/parserparam.cpp + level/parser/parserparam.h + level/player_profile.cpp + level/player_profile.h + level/research_type.h + level/robotmain.cpp + level/robotmain.h + level/scene_conditions.cpp + level/scene_conditions.h + math/all.h + math/const.h + math/func.h + math/geometry.h + math/intpoint.h + math/matrix.h + math/point.h + math/sphere.h + math/vector.h + object/auto/auto.cpp + object/auto/auto.h + object/auto/autobase.cpp + object/auto/autobase.h + object/auto/autoconvert.cpp + object/auto/autoconvert.h + object/auto/autoderrick.cpp + object/auto/autoderrick.h + object/auto/autodestroyer.cpp + object/auto/autodestroyer.h + object/auto/autoegg.cpp + object/auto/autoegg.h + object/auto/autofactory.cpp + object/auto/autofactory.h + object/auto/autoflag.cpp + object/auto/autoflag.h + object/auto/autohouston.cpp + object/auto/autohouston.h + object/auto/autojostle.cpp + object/auto/autojostle.h + object/auto/autokid.cpp + object/auto/autokid.h + object/auto/autolabo.cpp + object/auto/autolabo.h + object/auto/automush.cpp + object/auto/automush.h + object/auto/autonest.cpp + object/auto/autonest.h + object/auto/autonuclearplant.cpp + object/auto/autonuclearplant.h + object/auto/autoportico.cpp + object/auto/autoportico.h + object/auto/autopowercaptor.cpp + object/auto/autopowercaptor.h + object/auto/autopowerplant.cpp + object/auto/autopowerplant.h + object/auto/autopowerstation.cpp + object/auto/autopowerstation.h + object/auto/autoradar.cpp + object/auto/autoradar.h + object/auto/autorepair.cpp + object/auto/autorepair.h + object/auto/autoresearch.cpp + object/auto/autoresearch.h + object/auto/autoroot.cpp + object/auto/autoroot.h + object/auto/autotower.cpp + object/auto/autotower.h + object/auto/autovault.cpp + object/auto/autovault.h + object/crash_sphere.h + object/drive_type.cpp + object/drive_type.h + object/implementation/power_container_impl.cpp + object/implementation/power_container_impl.h + object/implementation/program_storage_impl.cpp + object/implementation/program_storage_impl.h + object/implementation/programmable_impl.cpp + object/implementation/programmable_impl.h + object/implementation/task_executor_impl.cpp + object/implementation/task_executor_impl.h + object/interface/carrier_object.h + object/interface/controllable_object.h + object/interface/damageable_object.h + object/interface/destroyable_object.h + object/interface/flying_object.h + object/interface/fragile_object.h + object/interface/interactive_object.h + object/interface/jet_flying_object.h + object/interface/jostleable_object.h + object/interface/movable_object.h + object/interface/power_container_object.h + object/interface/powered_object.h + object/interface/program_storage_object.h + object/interface/programmable_object.h + object/interface/ranged_object.h + object/interface/shielded_auto_regen_object.h + object/interface/shielded_object.h + object/interface/task_executor_object.h + object/interface/trace_drawing_object.cpp + object/interface/trace_drawing_object.h + object/interface/transportable_object.h + object/mission_type.h + object/motion/motion.cpp + object/motion/motion.h + object/motion/motionant.cpp + object/motion/motionant.h + object/motion/motionbee.cpp + object/motion/motionbee.h + object/motion/motionhuman.cpp + object/motion/motionhuman.h + object/motion/motionlevelcontroller.cpp + object/motion/motionlevelcontroller.h + object/motion/motionqueen.cpp + object/motion/motionqueen.h + object/motion/motionspider.cpp + object/motion/motionspider.h + object/motion/motiontoto.cpp + object/motion/motiontoto.h + object/motion/motionvehicle.cpp + object/motion/motionvehicle.h + object/motion/motionworm.cpp + object/motion/motionworm.h + object/object.cpp + object/object.h + object/object_create_exception.h + object/object_create_params.h + object/object_factory.cpp + object/object_factory.h + object/object_interface_type.h + object/object_manager.cpp + object/object_manager.h + object/object_type.h + object/old_object.cpp + object/old_object.h + object/old_object_interface.cpp + object/old_object_interface.h + object/subclass/base_alien.cpp + object/subclass/base_alien.h + object/subclass/base_building.cpp + object/subclass/base_building.h + object/subclass/base_robot.cpp + object/subclass/base_robot.h + object/subclass/base_vehicle.cpp + object/subclass/base_vehicle.h + object/subclass/exchange_post.cpp + object/subclass/exchange_post.h + object/subclass/shielder.cpp + object/subclass/shielder.h + object/subclass/static_object.cpp + object/subclass/static_object.h + object/task/task.cpp + object/task/task.h + object/task/taskadvance.cpp + object/task/taskadvance.h + object/task/taskbuild.cpp + object/task/taskbuild.h + object/task/taskdeletemark.cpp + object/task/taskdeletemark.h + object/task/taskfire.cpp + object/task/taskfire.h + object/task/taskfireant.cpp + object/task/taskfireant.h + object/task/taskflag.cpp + object/task/taskflag.h + object/task/taskgoto.cpp + object/task/taskgoto.h + object/task/taskgungoal.cpp + object/task/taskgungoal.h + object/task/taskinfo.cpp + object/task/taskinfo.h + object/task/taskmanip.cpp + object/task/taskmanip.h + object/task/taskpen.cpp + object/task/taskpen.h + object/task/taskrecover.cpp + object/task/taskrecover.h + object/task/tasksearch.cpp + object/task/tasksearch.h + object/task/taskshield.cpp + object/task/taskshield.h + object/task/taskspiderexplo.cpp + object/task/taskspiderexplo.h + object/task/tasktake.cpp + object/task/tasktake.h + object/task/taskterraform.cpp + object/task/taskterraform.h + object/task/taskturn.cpp + object/task/taskturn.h + object/task/taskwait.cpp + object/task/taskwait.h + object/tool_type.cpp + object/tool_type.h + physics/physics.cpp + physics/physics.h + script/cbottoken.cpp + script/cbottoken.h + script/script.cpp + script/script.h + script/scriptfunc.cpp + script/scriptfunc.h + sound/sound.cpp + sound/sound.h + sound/sound_type.cpp + sound/sound_type.h + ui/controls/button.cpp + ui/controls/button.h + ui/controls/check.cpp + ui/controls/check.h + ui/controls/color.cpp + ui/controls/color.h + ui/controls/control.cpp + ui/controls/control.h + ui/controls/edit.cpp + ui/controls/edit.h + ui/controls/editvalue.cpp + ui/controls/editvalue.h + ui/controls/enumslider.cpp + ui/controls/enumslider.h + ui/controls/gauge.cpp + ui/controls/gauge.h + ui/controls/group.cpp + ui/controls/group.h + ui/controls/image.cpp + ui/controls/image.h + ui/controls/interface.cpp + ui/controls/interface.h + ui/controls/key.cpp + ui/controls/key.h + ui/controls/label.cpp + ui/controls/label.h + ui/controls/list.cpp + ui/controls/list.h + ui/controls/map.cpp + ui/controls/map.h + ui/controls/scroll.cpp + ui/controls/scroll.h + ui/controls/shortcut.cpp + ui/controls/shortcut.h + ui/controls/slider.cpp + ui/controls/slider.h + ui/controls/target.cpp + ui/controls/target.h + ui/controls/window.cpp + ui/controls/window.h + ui/debug_menu.cpp + ui/debug_menu.h + ui/displayinfo.cpp + ui/displayinfo.h + ui/displaytext.cpp + ui/displaytext.h + ui/maindialog.cpp + ui/maindialog.h + ui/mainmap.cpp + ui/mainmap.h + ui/mainshort.cpp + ui/mainshort.h + ui/mainui.cpp + ui/mainui.h + ui/object_interface.cpp + ui/object_interface.h + ui/screen/screen.cpp + ui/screen/screen.h + ui/screen/screen_apperance.cpp + ui/screen/screen_apperance.h + ui/screen/screen_io.cpp + ui/screen/screen_io.h + ui/screen/screen_io_read.cpp + ui/screen/screen_io_read.h + ui/screen/screen_io_write.cpp + ui/screen/screen_io_write.h + ui/screen/screen_level_list.cpp + ui/screen/screen_level_list.h + ui/screen/screen_loading.cpp + ui/screen/screen_loading.h + ui/screen/screen_main_menu.cpp + ui/screen/screen_main_menu.h + ui/screen/screen_player_select.cpp + ui/screen/screen_player_select.h + ui/screen/screen_quit.cpp + ui/screen/screen_quit.h + ui/screen/screen_setup.cpp + ui/screen/screen_setup.h + ui/screen/screen_setup_controls.cpp + ui/screen/screen_setup_controls.h + ui/screen/screen_setup_display.cpp + ui/screen/screen_setup_display.h + ui/screen/screen_setup_game.cpp + ui/screen/screen_setup_game.h + ui/screen/screen_setup_graphics.cpp + ui/screen/screen_setup_graphics.h + ui/screen/screen_setup_sound.cpp + ui/screen/screen_setup_sound.h + ui/screen/screen_welcome.cpp + ui/screen/screen_welcome.h + ui/studio.cpp + ui/studio.h ) set(MAIN_SOURCES @@ -271,7 +528,6 @@ set(MAIN_SOURCES ${RES_FILES} ) - # Libraries set(LIBS CBot @@ -341,3 +597,5 @@ endif() if(COLOBOT_LINT_BUILD) add_fake_header_sources("src") endif() + +group_sources("${BASE_SOURCES}" "Source Files") From ebca89d9200e7ff649ee11e7ba071824ae80dd31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Wed, 11 May 2016 13:47:08 +0200 Subject: [PATCH 066/125] Removed texture coordinate generation This feature was only needed by GL14 device to implement shadow mapping and is not supported by shader-based devices. Shadow mapping has been rewritten, so this feature is no longer needed. --- src/graphics/core/device.h | 3 --- src/graphics/core/nulldevice.cpp | 4 --- src/graphics/core/nulldevice.h | 1 - src/graphics/opengl/gl21device.cpp | 42 ------------------------------ src/graphics/opengl/gl21device.h | 1 - src/graphics/opengl/gl33device.cpp | 5 ---- src/graphics/opengl/gl33device.h | 1 - src/graphics/opengl/gldevice.cpp | 40 ---------------------------- src/graphics/opengl/gldevice.h | 1 - 9 files changed, 98 deletions(-) diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 2b5f4a60..b4e897db 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -413,9 +413,6 @@ public: //! Sets only the texture wrap modes (for faster than thru stage params) virtual void SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT) = 0; - //! Sets the texture coordinate generation mode for given texture unit - virtual void SetTextureCoordGeneration(int index, TextureGenerationParams ¶ms) = 0; - //! Renders primitive composed of vertices with single texture virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount, Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) = 0; diff --git a/src/graphics/core/nulldevice.cpp b/src/graphics/core/nulldevice.cpp index ad483ede..aba9f800 100644 --- a/src/graphics/core/nulldevice.cpp +++ b/src/graphics/core/nulldevice.cpp @@ -154,10 +154,6 @@ void CNullDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode { } -void CNullDevice::SetTextureCoordGeneration(int index, TextureGenerationParams ¶ms) -{ -} - void CNullDevice::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount, Color color) { diff --git a/src/graphics/core/nulldevice.h b/src/graphics/core/nulldevice.h index 3a78ea83..5721d920 100644 --- a/src/graphics/core/nulldevice.h +++ b/src/graphics/core/nulldevice.h @@ -80,7 +80,6 @@ public: void SetTextureStageParams(int index, const TextureStageParams ¶ms) override; void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT) override; - void SetTextureCoordGeneration(int index, TextureGenerationParams ¶ms) override; void DrawPrimitive(PrimitiveType type, const Vertex* vertices, int vertexCount, Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override; void DrawPrimitive(PrimitiveType type, const VertexTex2* vertices, int vertexCount, Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override; diff --git a/src/graphics/opengl/gl21device.cpp b/src/graphics/opengl/gl21device.cpp index f5fb7741..e1a96dbe 100644 --- a/src/graphics/opengl/gl21device.cpp +++ b/src/graphics/opengl/gl21device.cpp @@ -1058,48 +1058,6 @@ void CGL21Device::SetTextureStageParams(int index, const TextureStageParams &par UpdateTextureParams(index); } -void CGL21Device::SetTextureCoordGeneration(int index, TextureGenerationParams ¶ms) -{ - /* - glActiveTexture(GL_TEXTURE0 + index); - - for (int i = 0; i < 4; i++) - { - GLuint texCoordGen = TranslateTextureCoordinateGen(i); - GLuint texCoord = TranslateTextureCoordinate(i); - - switch (params.coords[i].mode) - { - case TEX_GEN_NONE: - glDisable(texCoordGen); - break; - case TEX_GEN_OBJECT_LINEAR: - glEnable(texCoordGen); - glTexGeni(texCoord, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGenfv(texCoord, GL_OBJECT_PLANE, params.coords[i].plane); - break; - case TEX_GEN_EYE_LINEAR: - glEnable(texCoordGen); - glTexGeni(texCoord, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); - glTexGenfv(texCoord, GL_EYE_PLANE, params.coords[i].plane); - break; - case TEX_GEN_SPHERE_MAP: - glEnable(texCoordGen); - glTexGeni(texCoord, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); - break; - case TEX_GEN_NORMAL_MAP: - glEnable(texCoordGen); - glTexGeni(texCoord, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP); - break; - case TEX_GEN_REFLECTION_MAP: - glEnable(texCoordGen); - glTexGeni(texCoord, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); - break; - } - } - // */ -} - void CGL21Device::UpdateTextureParams(int index) { assert(index >= 0 && index < static_cast( m_currentTextures.size() )); diff --git a/src/graphics/opengl/gl21device.h b/src/graphics/opengl/gl21device.h index 83627bfc..9b073e31 100644 --- a/src/graphics/opengl/gl21device.h +++ b/src/graphics/opengl/gl21device.h @@ -99,7 +99,6 @@ public: void SetTextureStageParams(int index, const TextureStageParams ¶ms) override; void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT) override; - void SetTextureCoordGeneration(int index, TextureGenerationParams ¶ms) override; virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount, Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override; diff --git a/src/graphics/opengl/gl33device.cpp b/src/graphics/opengl/gl33device.cpp index c0c1e124..df67e5c1 100644 --- a/src/graphics/opengl/gl33device.cpp +++ b/src/graphics/opengl/gl33device.cpp @@ -1009,11 +1009,6 @@ void CGL33Device::SetTextureStageParams(int index, const TextureStageParams &par UpdateTextureParams(index); } -void CGL33Device::SetTextureCoordGeneration(int index, TextureGenerationParams ¶ms) -{ - -} - void CGL33Device::UpdateTextureParams(int index) { assert(index >= 0 && index < static_cast( m_currentTextures.size() )); diff --git a/src/graphics/opengl/gl33device.h b/src/graphics/opengl/gl33device.h index 317c7b13..a47fb999 100644 --- a/src/graphics/opengl/gl33device.h +++ b/src/graphics/opengl/gl33device.h @@ -114,7 +114,6 @@ public: void SetTextureStageParams(int index, const TextureStageParams ¶ms) override; void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT) override; - void SetTextureCoordGeneration(int index, TextureGenerationParams ¶ms) override; virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount, Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override; diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 423520d6..e28b6c2a 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -992,46 +992,6 @@ void CGLDevice::SetTextureStageParams(int index, const TextureStageParams ¶m UpdateTextureParams(index); } -void CGLDevice::SetTextureCoordGeneration(int index, TextureGenerationParams ¶ms) -{ - glActiveTexture(GL_TEXTURE0 + m_remap[index]); - - for (int i = 0; i < 4; i++) - { - GLuint texCoordGen = TranslateTextureCoordinateGen(i); - GLuint texCoord = TranslateTextureCoordinate(i); - - switch (params.coords[i].mode) - { - case TEX_GEN_NONE: - glDisable(texCoordGen); - break; - case TEX_GEN_OBJECT_LINEAR: - glEnable(texCoordGen); - glTexGeni(texCoord, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGenfv(texCoord, GL_OBJECT_PLANE, params.coords[i].plane); - break; - case TEX_GEN_EYE_LINEAR: - glEnable(texCoordGen); - glTexGeni(texCoord, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); - glTexGenfv(texCoord, GL_EYE_PLANE, params.coords[i].plane); - break; - case TEX_GEN_SPHERE_MAP: - glEnable(texCoordGen); - glTexGeni(texCoord, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); - break; - case TEX_GEN_NORMAL_MAP: - glEnable(texCoordGen); - glTexGeni(texCoord, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP); - break; - case TEX_GEN_REFLECTION_MAP: - glEnable(texCoordGen); - glTexGeni(texCoord, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); - break; - } - } -} - void CGLDevice::UpdateTextureParams(int index) { assert(index >= 0 && index < static_cast(m_currentTextures.size())); diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index baaaa3b8..33973f14 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -118,7 +118,6 @@ public: void SetTextureStageParams(int index, const TextureStageParams ¶ms) override; void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT) override; - void SetTextureCoordGeneration(int index, TextureGenerationParams ¶ms) override; virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount, Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override; From 8922bb5e848be9dae6a272fa5a68057682c2661d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Wed, 11 May 2016 14:50:18 +0200 Subject: [PATCH 067/125] Renamed CGLDevice to CGL14Device --- src/CMakeLists.txt | 4 +- .../opengl/{gldevice.cpp => gl14device.cpp} | 152 +++++++++--------- .../opengl/{gldevice.h => gl14device.h} | 14 +- src/graphics/opengl/glutil.cpp | 10 +- 4 files changed, 90 insertions(+), 90 deletions(-) rename src/graphics/opengl/{gldevice.cpp => gl14device.cpp} (93%) rename src/graphics/opengl/{gldevice.h => gl14device.h} (97%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f619cac7..bc6f12ad 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -205,12 +205,12 @@ set(BASE_SOURCES graphics/model/model_output.h graphics/model/model_shadow_spot.h graphics/model/model_triangle.h + graphics/opengl/gl14device.cpp + graphics/opengl/gl14device.h graphics/opengl/gl21device.cpp graphics/opengl/gl21device.h graphics/opengl/gl33device.cpp graphics/opengl/gl33device.h - graphics/opengl/gldevice.cpp - graphics/opengl/gldevice.h graphics/opengl/glframebuffer.cpp graphics/opengl/glframebuffer.h graphics/opengl/glutil.cpp diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gl14device.cpp similarity index 93% rename from src/graphics/opengl/gldevice.cpp rename to src/graphics/opengl/gl14device.cpp index e28b6c2a..7b93aaff 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gl14device.cpp @@ -18,7 +18,7 @@ */ -#include "graphics/opengl/gldevice.h" +#include "graphics/opengl/gl14device.h" #include "common/config.h" @@ -43,22 +43,22 @@ namespace Gfx { -CGLDevice::CGLDevice(const DeviceConfig &config) +CGL14Device::CGL14Device(const DeviceConfig &config) : m_config(config) {} -CGLDevice::~CGLDevice() +CGL14Device::~CGL14Device() { } -void CGLDevice::DebugHook() +void CGL14Device::DebugHook() { /* This function is only called here, so it can be used * as a breakpoint when debugging using gDEBugger */ glColor3i(0, 0, 0); } -void CGLDevice::DebugLights() +void CGL14Device::DebugLights() { Gfx::ColorHSV color(0.0, 1.0, 1.0); @@ -158,12 +158,12 @@ void CGLDevice::DebugLights() UpdateModelviewMatrix(); } -std::string CGLDevice::GetName() +std::string CGL14Device::GetName() { return std::string("OpenGL 1.4"); } -bool CGLDevice::Create() +bool CGL14Device::Create() { GetLogger()->Info("Creating CDevice - OpenGL 1.4\n"); @@ -382,7 +382,7 @@ bool CGLDevice::Create() return true; } -void CGLDevice::Destroy() +void CGL14Device::Destroy() { // delete framebuffers for (auto& framebuffer : m_framebuffers) @@ -404,7 +404,7 @@ void CGLDevice::Destroy() m_textureStageParams.clear(); } -void CGLDevice::ConfigChanged(const DeviceConfig& newConfig) +void CGL14Device::ConfigChanged(const DeviceConfig& newConfig) { m_config = newConfig; @@ -423,7 +423,7 @@ void CGLDevice::ConfigChanged(const DeviceConfig& newConfig) m_framebuffers["default"] = MakeUnique(framebufferParams); } -void CGLDevice::BeginScene() +void CGL14Device::BeginScene() { Clear(); @@ -433,7 +433,7 @@ void CGLDevice::BeginScene() UpdateModelviewMatrix(); } -void CGLDevice::EndScene() +void CGL14Device::EndScene() { #ifdef DEV_BUILD int count = ClearGLErrors(); @@ -443,18 +443,18 @@ void CGLDevice::EndScene() #endif } -void CGLDevice::Clear() +void CGL14Device::Clear() { glDepthMask(GL_TRUE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } -void CGLDevice::SetRenderMode(RenderMode mode) +void CGL14Device::SetRenderMode(RenderMode mode) { // nothing is done } -void CGLDevice::SetTransform(TransformType type, const Math::Matrix &matrix) +void CGL14Device::SetTransform(TransformType type, const Math::Matrix &matrix) { if (type == TRANSFORM_WORLD) { @@ -492,7 +492,7 @@ void CGLDevice::SetTransform(TransformType type, const Math::Matrix &matrix) } } -void CGLDevice::UpdateModelviewMatrix() +void CGL14Device::UpdateModelviewMatrix() { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -507,7 +507,7 @@ void CGLDevice::UpdateModelviewMatrix() } } -void CGLDevice::SetMaterial(const Material &material) +void CGL14Device::SetMaterial(const Material &material) { m_material = material; @@ -516,12 +516,12 @@ void CGLDevice::SetMaterial(const Material &material) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, m_material.specular.Array()); } -int CGLDevice::GetMaxLightCount() +int CGL14Device::GetMaxLightCount() { return m_lights.size(); } -void CGLDevice::SetLight(int index, const Light &light) +void CGL14Device::SetLight(int index, const Light &light) { assert(index >= 0); assert(index < static_cast( m_lights.size() )); @@ -550,7 +550,7 @@ void CGLDevice::SetLight(int index, const Light &light) UpdateLightPosition(index); } -void CGLDevice::UpdateLightPosition(int index) +void CGL14Device::UpdateLightPosition(int index) { assert(index >= 0); assert(index < static_cast( m_lights.size() )); @@ -594,7 +594,7 @@ void CGLDevice::UpdateLightPosition(int index) glPopMatrix(); } -void CGLDevice::UpdateLightPositions() +void CGL14Device::UpdateLightPositions() { glMatrixMode(GL_MODELVIEW); glPushMatrix(); @@ -653,7 +653,7 @@ void CGLDevice::UpdateLightPositions() glPopMatrix(); } -void CGLDevice::SetLightEnabled(int index, bool enabled) +void CGL14Device::SetLightEnabled(int index, bool enabled) { assert(index >= 0); assert(index < static_cast( m_lights.size() )); @@ -669,7 +669,7 @@ void CGLDevice::SetLightEnabled(int index, bool enabled) /** If image is invalid, returns invalid texture. Otherwise, returns pointer to new Texture struct. This struct must not be deleted in other way than through DeleteTexture() */ -Texture CGLDevice::CreateTexture(CImage *image, const TextureCreateParams ¶ms) +Texture CGL14Device::CreateTexture(CImage *image, const TextureCreateParams ¶ms) { ImageData *data = image->GetData(); if (data == nullptr) @@ -689,7 +689,7 @@ Texture CGLDevice::CreateTexture(CImage *image, const TextureCreateParams ¶m return tex; } -Texture CGLDevice::CreateTexture(ImageData *data, const TextureCreateParams ¶ms) +Texture CGL14Device::CreateTexture(ImageData *data, const TextureCreateParams ¶ms) { Texture result; @@ -778,7 +778,7 @@ Texture CGLDevice::CreateTexture(ImageData *data, const TextureCreateParams &par return result; } -Texture CGLDevice::CreateDepthTexture(int width, int height, int depth) +Texture CGL14Device::CreateDepthTexture(int width, int height, int depth) { Texture result; @@ -852,7 +852,7 @@ Texture CGLDevice::CreateDepthTexture(int width, int height, int depth) return result; } -void CGLDevice::UpdateTexture(const Texture& texture, Math::IntPoint offset, ImageData* data, TexImgFormat format) +void CGL14Device::UpdateTexture(const Texture& texture, Math::IntPoint offset, ImageData* data, TexImgFormat format) { // Use & enable 1st texture stage glActiveTexture(GL_TEXTURE0 + m_remap[0]); @@ -872,7 +872,7 @@ void CGLDevice::UpdateTexture(const Texture& texture, Math::IntPoint offset, Ima SDL_FreeSurface(texData.convertedSurface); } -void CGLDevice::DestroyTexture(const Texture &texture) +void CGL14Device::DestroyTexture(const Texture &texture) { // Unbind the texture if in use anywhere for (int index = 0; index < static_cast( m_currentTextures.size() ); ++index) @@ -889,7 +889,7 @@ void CGLDevice::DestroyTexture(const Texture &texture) } } -void CGLDevice::DestroyAllTextures() +void CGL14Device::DestroyAllTextures() { // Unbind all texture stages for (int index = 0; index < static_cast( m_currentTextures.size() ); ++index) @@ -914,7 +914,7 @@ void CGLDevice::DestroyAllTextures() glBindTexture(GL_TEXTURE_2D, m_currentTextures[0].id); } -int CGLDevice::GetMaxTextureStageCount() +int CGL14Device::GetMaxTextureStageCount() { return m_currentTextures.size(); } @@ -923,7 +923,7 @@ int CGLDevice::GetMaxTextureStageCount() If \a texture is invalid, unbinds the given texture. If valid, binds the texture and enables the given texture stage. The setting is remembered, even if texturing is disabled at the moment. */ -void CGLDevice::SetTexture(int index, const Texture &texture) +void CGL14Device::SetTexture(int index, const Texture &texture) { assert(index >= 0 && index < static_cast( m_currentTextures.size() )); @@ -942,7 +942,7 @@ void CGLDevice::SetTexture(int index, const Texture &texture) UpdateTextureParams(index); } -void CGLDevice::SetTexture(int index, unsigned int textureId) +void CGL14Device::SetTexture(int index, unsigned int textureId) { assert(index >= 0 && index < static_cast(m_currentTextures.size())); @@ -959,7 +959,7 @@ void CGLDevice::SetTexture(int index, unsigned int textureId) UpdateTextureParams(index); } -void CGLDevice::SetTextureEnabled(int index, bool enabled) +void CGL14Device::SetTextureEnabled(int index, bool enabled) { assert(index >= 0 && index < static_cast(m_currentTextures.size())); @@ -982,7 +982,7 @@ void CGLDevice::SetTextureEnabled(int index, bool enabled) Sets the texture parameters for the given texture stage. If the given texture was not set (bound) yet, nothing happens. The settings are remembered, even if texturing is disabled at the moment. */ -void CGLDevice::SetTextureStageParams(int index, const TextureStageParams ¶ms) +void CGL14Device::SetTextureStageParams(int index, const TextureStageParams ¶ms) { assert(index >= 0 && index < static_cast(m_currentTextures.size())); @@ -992,7 +992,7 @@ void CGLDevice::SetTextureStageParams(int index, const TextureStageParams ¶m UpdateTextureParams(index); } -void CGLDevice::UpdateTextureParams(int index) +void CGL14Device::UpdateTextureParams(int index) { assert(index >= 0 && index < static_cast(m_currentTextures.size())); @@ -1157,7 +1157,7 @@ after_tex_color: after_tex_operations: ; } -void CGLDevice::EnableShadows() +void CGL14Device::EnableShadows() { // already enabled if (m_shadowMapping) return; @@ -1252,7 +1252,7 @@ void CGLDevice::EnableShadows() m_shadowMapping = true; } -void CGLDevice::DisableShadows() +void CGL14Device::DisableShadows() { // already disabled if (!m_shadowMapping) return; @@ -1276,7 +1276,7 @@ void CGLDevice::DisableShadows() m_shadowMapping = false; } -void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT) +void CGL14Device::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT) { assert(index >= 0 && index < static_cast( m_currentTextures.size() )); @@ -1307,7 +1307,7 @@ void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wr else assert(false); } -void CGLDevice::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount, +void CGL14Device::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount, Color color) { Vertex* vs = const_cast(vertices); @@ -1331,7 +1331,7 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int ve glDisableClientState(GL_TEXTURE_COORD_ARRAY); // GL_TEXTURE0 } -void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount, +void CGL14Device::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount, Color color) { VertexTex2* vs = const_cast(vertices); @@ -1363,7 +1363,7 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, in glDisableClientState(GL_TEXTURE_COORD_ARRAY); } -void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount) +void CGL14Device::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount) { VertexCol* vs = const_cast(vertices); @@ -1379,7 +1379,7 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int glDisableClientState(GL_COLOR_ARRAY); } -void CGLDevice::DrawPrimitives(PrimitiveType type, const Vertex *vertices, +void CGL14Device::DrawPrimitives(PrimitiveType type, const Vertex *vertices, int first[], int count[], int drawCount, Color color) { Vertex* vs = const_cast(vertices); @@ -1413,7 +1413,7 @@ void CGLDevice::DrawPrimitives(PrimitiveType type, const Vertex *vertices, glDisableClientState(GL_TEXTURE_COORD_ARRAY); // GL_TEXTURE0 } -void CGLDevice::DrawPrimitives(PrimitiveType type, const VertexTex2 *vertices, +void CGL14Device::DrawPrimitives(PrimitiveType type, const VertexTex2 *vertices, int first[], int count[], int drawCount, Color color) { VertexTex2* vs = const_cast(vertices); @@ -1454,7 +1454,7 @@ void CGLDevice::DrawPrimitives(PrimitiveType type, const VertexTex2 *vertices, glDisableClientState(GL_TEXTURE_COORD_ARRAY); } -void CGLDevice::DrawPrimitives(PrimitiveType type, const VertexCol *vertices, +void CGL14Device::DrawPrimitives(PrimitiveType type, const VertexCol *vertices, int first[], int count[], int drawCount) { VertexCol* vs = const_cast(vertices); @@ -1481,7 +1481,7 @@ void CGLDevice::DrawPrimitives(PrimitiveType type, const VertexCol *vertices, glDisableClientState(GL_COLOR_ARRAY); } -unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) +unsigned int CGL14Device::CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) { unsigned int id = 0; if (m_vertexBufferType != VBT_DISPLAY_LIST) @@ -1525,7 +1525,7 @@ unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Ve return id; } -unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) +unsigned int CGL14Device::CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) { unsigned int id = 0; if (m_vertexBufferType != VBT_DISPLAY_LIST) @@ -1569,7 +1569,7 @@ unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Ve return id; } -unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) +unsigned int CGL14Device::CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) { unsigned int id = 0; if (m_vertexBufferType != VBT_DISPLAY_LIST) @@ -1613,7 +1613,7 @@ unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Ve return id; } -void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) +void CGL14Device::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) { if (m_vertexBufferType != VBT_DISPLAY_LIST) { @@ -1649,7 +1649,7 @@ void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiv } } -void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) +void CGL14Device::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) { if (m_vertexBufferType != VBT_DISPLAY_LIST) { @@ -1685,7 +1685,7 @@ void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiv } } -void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) +void CGL14Device::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) { if (m_vertexBufferType != VBT_DISPLAY_LIST) { @@ -1721,7 +1721,7 @@ void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiv } } -void CGLDevice::DrawStaticBuffer(unsigned int bufferId) +void CGL14Device::DrawStaticBuffer(unsigned int bufferId) { if (m_vertexBufferType != VBT_DISPLAY_LIST) { @@ -1806,7 +1806,7 @@ void CGLDevice::DrawStaticBuffer(unsigned int bufferId) } } -void CGLDevice::DestroyStaticBuffer(unsigned int bufferId) +void CGL14Device::DestroyStaticBuffer(unsigned int bufferId) { if (m_vertexBufferType != VBT_DISPLAY_LIST) { @@ -1829,7 +1829,7 @@ void CGLDevice::DestroyStaticBuffer(unsigned int bufferId) /* Based on libwine's implementation */ -int CGLDevice::ComputeSphereVisibility(const Math::Vector ¢er, float radius) +int CGL14Device::ComputeSphereVisibility(const Math::Vector ¢er, float radius) { if (m_combinedMatrixOutdated) { @@ -1908,12 +1908,12 @@ int CGLDevice::ComputeSphereVisibility(const Math::Vector ¢er, float radius) return result; } -void CGLDevice::SetViewport(int x, int y, int width, int height) +void CGL14Device::SetViewport(int x, int y, int width, int height) { glViewport(x, y, width, height); } -void CGLDevice::SetRenderState(RenderState state, bool enabled) +void CGL14Device::SetRenderState(RenderState state, bool enabled) { if (state == RENDER_STATE_DEPTH_WRITE) { @@ -1965,42 +1965,42 @@ void CGLDevice::SetRenderState(RenderState state, bool enabled) glDisable(flag); } -void CGLDevice::SetColorMask(bool red, bool green, bool blue, bool alpha) +void CGL14Device::SetColorMask(bool red, bool green, bool blue, bool alpha) { glColorMask(red, green, blue, alpha); } -void CGLDevice::SetDepthTestFunc(CompFunc func) +void CGL14Device::SetDepthTestFunc(CompFunc func) { glDepthFunc(TranslateGfxCompFunc(func)); } -void CGLDevice::SetDepthBias(float factor, float units) +void CGL14Device::SetDepthBias(float factor, float units) { glPolygonOffset(factor, units); } -void CGLDevice::SetAlphaTestFunc(CompFunc func, float refValue) +void CGL14Device::SetAlphaTestFunc(CompFunc func, float refValue) { glAlphaFunc(TranslateGfxCompFunc(func), refValue); } -void CGLDevice::SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) +void CGL14Device::SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) { glBlendFunc(TranslateGfxBlendFunc(srcBlend), TranslateGfxBlendFunc(dstBlend)); } -void CGLDevice::SetClearColor(const Color &color) +void CGL14Device::SetClearColor(const Color &color) { glClearColor(color.r, color.g, color.b, color.a); } -void CGLDevice::SetGlobalAmbient(const Color &color) +void CGL14Device::SetGlobalAmbient(const Color &color) { glLightModelfv(GL_LIGHT_MODEL_AMBIENT, color.Array()); } -void CGLDevice::SetFogParams(FogMode mode, const Color &color, float start, float end, float density) +void CGL14Device::SetFogParams(FogMode mode, const Color &color, float start, float end, float density) { if (mode == FOG_LINEAR) glFogi(GL_FOG_MODE, GL_LINEAR); else if (mode == FOG_EXP) glFogi(GL_FOG_MODE, GL_EXP); @@ -2013,7 +2013,7 @@ void CGLDevice::SetFogParams(FogMode mode, const Color &color, float start, floa glFogfv(GL_FOG_COLOR, color.Array()); } -void CGLDevice::SetCullMode(CullMode mode) +void CGL14Device::SetCullMode(CullMode mode) { // Cull clockwise back faces, so front face is the opposite // (assuming GL_CULL_FACE is GL_BACK) @@ -2022,19 +2022,19 @@ void CGLDevice::SetCullMode(CullMode mode) else assert(false); } -void CGLDevice::SetShadeModel(ShadeModel model) +void CGL14Device::SetShadeModel(ShadeModel model) { if (model == SHADE_FLAT) glShadeModel(GL_FLAT); else if (model == SHADE_SMOOTH) glShadeModel(GL_SMOOTH); else assert(false); } -void CGLDevice::SetShadowColor(float value) +void CGL14Device::SetShadowColor(float value) { // doesn't do anything because it can't } -void CGLDevice::SetFillMode(FillMode mode) +void CGL14Device::SetFillMode(FillMode mode) { if (mode == FILL_POINT) glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); else if (mode == FILL_LINES) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); @@ -2042,7 +2042,7 @@ void CGLDevice::SetFillMode(FillMode mode) else assert(false); } -void CGLDevice::CopyFramebufferToTexture(Texture& texture, int xOffset, int yOffset, int x, int y, int width, int height) +void CGL14Device::CopyFramebufferToTexture(Texture& texture, int xOffset, int yOffset, int x, int y, int width, int height) { if (texture.id == 0) return; @@ -2056,12 +2056,12 @@ void CGLDevice::CopyFramebufferToTexture(Texture& texture, int xOffset, int yOff glBindTexture(GL_TEXTURE_2D, m_currentTextures[0].id); } -std::unique_ptr CGLDevice::GetFrameBufferPixels() const +std::unique_ptr CGL14Device::GetFrameBufferPixels() const { return GetGLFrameBufferPixels(m_config.size); } -CFramebuffer* CGLDevice::GetFramebuffer(std::string name) +CFramebuffer* CGL14Device::GetFramebuffer(std::string name) { auto it = m_framebuffers.find(name); if (it == m_framebuffers.end()) @@ -2070,7 +2070,7 @@ CFramebuffer* CGLDevice::GetFramebuffer(std::string name) return it->second.get(); } -CFramebuffer* CGLDevice::CreateFramebuffer(std::string name, const FramebufferParams& params) +CFramebuffer* CGL14Device::CreateFramebuffer(std::string name, const FramebufferParams& params) { // existing framebuffer was found if (m_framebuffers.find(name) != m_framebuffers.end()) @@ -2094,7 +2094,7 @@ CFramebuffer* CGLDevice::CreateFramebuffer(std::string name, const FramebufferPa return framebufferPtr; } -void CGLDevice::DeleteFramebuffer(std::string name) +void CGL14Device::DeleteFramebuffer(std::string name) { // can't delete default framebuffer if (name == "default") return; @@ -2107,32 +2107,32 @@ void CGLDevice::DeleteFramebuffer(std::string name) } } -bool CGLDevice::IsAnisotropySupported() +bool CGL14Device::IsAnisotropySupported() { return m_capabilities.anisotropySupported; } -int CGLDevice::GetMaxAnisotropyLevel() +int CGL14Device::GetMaxAnisotropyLevel() { return m_capabilities.maxAnisotropy; } -int CGLDevice::GetMaxSamples() +int CGL14Device::GetMaxSamples() { return m_capabilities.maxSamples; } -bool CGLDevice::IsShadowMappingSupported() +bool CGL14Device::IsShadowMappingSupported() { return m_capabilities.shadowMappingSupported; } -int CGLDevice::GetMaxTextureSize() +int CGL14Device::GetMaxTextureSize() { return m_capabilities.maxTextureSize; } -bool CGLDevice::IsFramebufferSupported() +bool CGL14Device::IsFramebufferSupported() { return m_capabilities.framebufferSupported; } diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gl14device.h similarity index 97% rename from src/graphics/opengl/gldevice.h rename to src/graphics/opengl/gl14device.h index 33973f14..96190394 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gl14device.h @@ -18,8 +18,8 @@ */ /** - * \file graphics/opengl/gldevice.h - * \brief OpenGL implementation - CGLDevice class + * \file graphics/opengl/gl14device.h + * \brief OpenGL implementation - CGL14Device class */ #pragma once @@ -62,21 +62,21 @@ enum ShadowMappingSupport }; /** - \class CGLDevice + \class CGL14Device \brief Implementation of CDevice interface in OpenGL Provides the concrete implementation of 3D device in OpenGL. This class should be initialized (by calling Initialize() ) only after setting the video mode by CApplication, once the OpenGL context is defined. - Because of that, CGLDeviceConfig is outside the CDevice class and must be set + Because of that, CGL14DeviceConfig is outside the CDevice class and must be set in CApplication. */ -class CGLDevice : public CDevice +class CGL14Device : public CDevice { public: - CGLDevice(const DeviceConfig &config); - virtual ~CGLDevice(); + CGL14Device(const DeviceConfig &config); + virtual ~CGL14Device(); void DebugHook() override; void DebugLights() override; diff --git a/src/graphics/opengl/glutil.cpp b/src/graphics/opengl/glutil.cpp index 04ad80a9..bd6ae886 100644 --- a/src/graphics/opengl/glutil.cpp +++ b/src/graphics/opengl/glutil.cpp @@ -23,9 +23,9 @@ #include "common/logger.h" #include "common/make_unique.h" +#include "graphics/opengl/gl14device.h" #include "graphics/opengl/gl21device.h" #include "graphics/opengl/gl33device.h" -#include "graphics/opengl/gldevice.h" #include #include @@ -71,9 +71,9 @@ FramebufferSupport DetectFramebufferSupport() std::unique_ptr CreateDevice(const DeviceConfig &config, const std::string& name) { - if (name == "default") return MakeUnique(config); - else if (name == "opengl") return MakeUnique(config); - else if (name == "gl14") return MakeUnique(config); + if (name == "default") return MakeUnique(config); + else if (name == "opengl") return MakeUnique(config); + else if (name == "gl14") return MakeUnique(config); else if (name == "gl21") return MakeUnique(config); else if (name == "gl33") return MakeUnique(config); else if (name == "auto") @@ -82,7 +82,7 @@ std::unique_ptr CreateDevice(const DeviceConfig &config, const std::str if (version >= 33) return MakeUnique(config); else if (version >= 21) return MakeUnique(config); - else return MakeUnique(config); + else return MakeUnique(config); } return nullptr; From 213fd6b203c82156fef49e8d77e1a4c719e53a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Sat, 21 May 2016 14:27:35 +0200 Subject: [PATCH 068/125] Added blur effect when the game is paused (issue #656) Might be unstable, needs more testing. To enable, add PauseBlur=1 to [Experimental] section in colobot.ini --- src/common/settings.cpp | 4 + src/graphics/engine/engine.cpp | 175 ++++++++++++++++++++++++++++++++- src/graphics/engine/engine.h | 17 ++++ src/level/robotmain.cpp | 4 + src/math/func.h | 9 ++ 5 files changed, 206 insertions(+), 3 deletions(-) diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 2b67ef1d..10039848 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -112,6 +112,7 @@ void CSettings::SaveSettings() // Experimental settings GetConfigFile().SetBoolProperty("Experimental", "TerrainShadows", engine->GetTerrainShadows()); + GetConfigFile().SetBoolProperty("Experimental", "PauseBlur", engine->GetPauseBlur()); CInput::GetInstancePointer()->SaveKeyBindings(); @@ -270,6 +271,9 @@ void CSettings::LoadSettings() if (GetConfigFile().GetBoolProperty("Experimental", "TerrainShadows", bValue)) engine->SetTerrainShadows(bValue); + if (GetConfigFile().GetBoolProperty("Experimental", "PauseBlur", bValue)) + engine->SetPauseBlur(bValue); + CInput::GetInstancePointer()->LoadKeyBindings(); diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index aeb6dcb2..b7d0e563 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -59,6 +59,7 @@ #include "ui/controls/interface.h" #include +#include #include template<> Gfx::CEngine* CSingleton::m_instance = nullptr; @@ -148,6 +149,7 @@ CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils) m_editIndentMode = true; m_editIndentValue = 4; m_tracePrecision = 1.0f; + m_pauseBlur = false; m_updateGeometry = false; @@ -3028,6 +3030,16 @@ EngineMouseType CEngine::GetMouseType() return m_mouseType; } +void CEngine::SetPauseBlur(bool enable) +{ + m_pauseBlur = enable; +} + +bool CEngine::GetPauseBlur() +{ + return m_pauseBlur; +} + const Math::Matrix& CEngine::GetMatView() { return m_matView; @@ -3066,6 +3078,10 @@ void CEngine::UpdateMatProj() void CEngine::ApplyChange() { SetFocus(m_focus); + + // recapture 3D scene + if (m_worldCaptured) + m_captureWorld = true; } void CEngine::ClearDisplayCrashSpheres() @@ -3137,8 +3153,8 @@ void CEngine::Render() UseMSAA(true); - DrawBackground(); // draws the background - + if (!m_worldCaptured) + DrawBackground(); // draws the background if (m_drawWorld) Draw3DScene(); @@ -3155,6 +3171,33 @@ void CEngine::Render() void CEngine::Draw3DScene() { + // use currently captured scene for world + if (m_worldCaptured) + { + Math::Matrix identity; + + m_device->SetTransform(TRANSFORM_PROJECTION, identity); + m_device->SetTransform(TRANSFORM_VIEW, identity); + m_device->SetTransform(TRANSFORM_WORLD, identity); + + Vertex vertices[4]; + + vertices[0] = Vertex(Math::Vector(-1.0f, -1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(0.0f, 0.0f)); + vertices[1] = Vertex(Math::Vector( 1.0f, -1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(1.0f, 0.0f)); + vertices[2] = Vertex(Math::Vector(-1.0f, 1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(0.0f, 1.0f)); + vertices[3] = Vertex(Math::Vector( 1.0f, 1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(1.0f, 1.0f)); + + m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false); + + m_device->SetTexture(TEXTURE_PRIMARY, m_capturedWorldTexture); + m_device->SetTextureEnabled(TEXTURE_PRIMARY, true); + m_device->SetTextureEnabled(TEXTURE_SECONDARY, false); + + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertices, 4); + + return; + } + m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false); UpdateGroundSpotTextures(); @@ -3237,7 +3280,6 @@ void CEngine::Draw3DScene() if (!m_shadowMapping) DrawShadowSpots(); - m_app->StopPerformanceCounter(PCNT_RENDER_TERRAIN); // Draw other objects @@ -3407,6 +3449,117 @@ void CEngine::Draw3DScene() DrawForegroundImage(); // draws the foreground if (! m_overFront) DrawOverColor(); // draws the foreground color + + // marked to capture currently rendered world + if (m_captureWorld) + { + // destroy existing texture + if (m_capturedWorldTexture.Valid()) + { + m_device->DestroyTexture(m_capturedWorldTexture); + m_capturedWorldTexture = Texture(); + } + + // obtain pixels from screen + int width = m_size.x; + int height = m_size.y; + + auto pixels = m_device->GetFrameBufferPixels(); + unsigned char* data = reinterpret_cast(pixels->GetPixelsData()); + + // calculate 2nd mipmap + int newWidth = width / 4; + int newHeight = height / 4; + std::unique_ptr mipmap(new unsigned char[4 * newWidth * newHeight]); + + for (int x = 0; x < newWidth; x++) + { + for (int y = 0; y < newHeight; y++) + { + float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + int index = 4 * ((4 * x + i) + width * (4 * y + j)); + + for (int k = 0; k < 4; k++) + color[k] += data[index + k]; + } + } + + int index = 4 * (x + newWidth * y); + + for (int k = 0; k < 4; k++) + { + mipmap[index + k] = static_cast(color[k] * (1.0f / 16.0f)); + } + } + } + + // calculate Gaussian blur + std::unique_ptr blured(new unsigned char[4 * newWidth * newHeight]); + + float matrix[7][7] = + { + { 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f }, + { 0.00002292f, 0.00078634f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f }, + { 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f }, + { 0.00038771f, 0.01330373f, 0.11098164f, 0.22508352f, 0.11098164f, 0.01330373f, 0.00038771f }, + { 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f }, + { 0.00002292f, 0.00078633f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f }, + { 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f } + }; + + for (int x = 0; x < newWidth; x++) + { + for (int y = 0; y < newHeight; y++) + { + float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + + for (int i = -3; i <= 3; i++) + { + for (int j = -3; j <= 3; j++) + { + int xp = Math::Clamp(x + i, 0, newWidth - 1); + int yp = Math::Clamp(y + j, 0, newHeight - 1); + + float weight = matrix[i + 3][j + 3]; + + int index = 4 * (newWidth * yp + xp); + + for (int k = 0; k < 4; k++) + color[k] += weight * mipmap[index + k]; + } + } + + int index = 4 * (newWidth * y + x); + + for (int k = 0; k < 4; k++) + { + float value = Math::Clamp(color[k], 0.0f, 255.0f); + blured[index + k] = static_cast(value); + } + } + } + + // create SDL surface and final texture + ImageData image; + image.surface = SDL_CreateRGBSurfaceFrom(blured.get(), newWidth, newHeight, 32, 0, 0, 0, 0, 0xFF000000); + + TextureCreateParams params; + params.filter = TEX_FILTER_BILINEAR; + params.format = TEX_IMG_RGBA; + params.mipmap = false; + + m_capturedWorldTexture = m_device->CreateTexture(&image, params); + + SDL_FreeSurface(image.surface); + + m_captureWorld = false; + m_worldCaptured = true; + } } void CEngine::DrawCrashSpheres() @@ -5190,6 +5343,22 @@ void CEngine::SetInterfaceCoordinates() m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); } +void CEngine::EnablePauseBlur() +{ + if (!m_pauseBlur) return; + + m_captureWorld = true; + m_worldCaptured = false; +} + +void CEngine::DisablePauseBlur() +{ + if (!m_pauseBlur) return; + + m_captureWorld = false; + m_worldCaptured = false; +} + void CEngine::SetWindowCoordinates() { Math::Matrix matWorldWindow; diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 1f5cfe8f..8fb195a2 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -1162,6 +1162,12 @@ public: EngineMouseType GetMouseType(); //@} + //@{ + //! Management of pause blur + void SetPauseBlur(bool enable); + bool GetPauseBlur(); + //@} + //! Returns the view matrix const Math::Matrix& GetMatView(); //! Returns the camera center point @@ -1199,6 +1205,9 @@ public: void SetWindowCoordinates(); void SetInterfaceCoordinates(); + void EnablePauseBlur(); + void DisablePauseBlur(); + protected: //! Resets some states and flushes textures after device was changed (e.g. resoulution changed) /** Instead of calling this directly, send EVENT_RESOLUTION_CHANGED event **/ @@ -1408,6 +1417,7 @@ protected: float m_terrainVision; bool m_backForce; float m_tracePrecision; + bool m_pauseBlur; bool m_dirty; bool m_fog; @@ -1502,6 +1512,13 @@ protected: //! Pause the animation updates bool m_pause = false; + + //! true means that current 3D scene was captured and is not to be rendered again + bool m_worldCaptured = false; + //! true means that currently rendered world is to be captured + bool m_captureWorld = false; + //! Texture with captured 3D world + Texture m_capturedWorldTexture; }; diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index e6caa127..e41a0605 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -1601,6 +1601,8 @@ void CRobotMain::StartSuspend() m_suspendInitCamera = m_camera->GetType(); m_camera->SetType(Gfx::CAM_TYPE_DIALOG); + + m_engine->EnablePauseBlur(); } //! End of dialogue during the game @@ -1619,6 +1621,8 @@ void CRobotMain::StopSuspend() m_displayText->HideText(false); m_camera->SetType(m_suspendInitCamera); + + m_engine->DisablePauseBlur(); } diff --git a/src/math/func.h b/src/math/func.h index 66ee974e..b206c89a 100644 --- a/src/math/func.h +++ b/src/math/func.h @@ -93,6 +93,15 @@ inline float Max(float a, float b, float c, float d, float e) return Math::Max( Math::Max(a, b), Math::Max(c, d), e ); } +//! Clamps the value to a range specified by min and max +template +inline T Clamp(T value, T min, T max) +{ + if (value < min) return min; + else if (value > max) return max; + else return value; +} + //! Returns the normalized value (0 .. 1) inline float Norm(float a) { From 59c106f7a7c0024e00e15fa2332601721f39064d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 21 May 2016 18:58:35 +0200 Subject: [PATCH 069/125] Fixed pause blur image not updating correctly on resolution change --- src/graphics/engine/engine.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index b7d0e563..5e773dc6 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -362,7 +362,7 @@ void CEngine::ResetAfterVideoConfigChanged() m_mouseSize = Math::Point(0.04f, 0.04f * (static_cast(m_size.x) / static_cast(m_size.y))); // Update the camera projection matrix for new aspect ratio - SetFocus(m_focus); + ApplyChange(); // This needs to be recreated on resolution change m_device->DeleteFramebuffer("multisample"); @@ -3081,7 +3081,10 @@ void CEngine::ApplyChange() // recapture 3D scene if (m_worldCaptured) + { m_captureWorld = true; + m_worldCaptured = false; + } } void CEngine::ClearDisplayCrashSpheres() From cdd719cc470c359ea134a0f7f0fa38db726138fe Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 21 May 2016 19:05:18 +0200 Subject: [PATCH 070/125] Made clipping distance settings apply immediately --- src/ui/screen/screen_setup.cpp | 2 -- src/ui/screen/screen_setup_graphics.cpp | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ui/screen/screen_setup.cpp b/src/ui/screen/screen_setup.cpp index 4d5c5978..7f20eabe 100644 --- a/src/ui/screen/screen_setup.cpp +++ b/src/ui/screen/screen_setup.cpp @@ -153,7 +153,6 @@ bool CScreenSetup::EventProcess(const Event &event) (event.type == EVENT_KEY_DOWN && event.GetData()->key == KEY(ESCAPE)) ) { m_settings->SaveSettings(); - m_engine->ApplyChange(); m_main->ChangePhase(PHASE_MAIN_MENU); return false; } @@ -194,7 +193,6 @@ bool CScreenSetup::EventProcess(const Event &event) (event.type == EVENT_KEY_DOWN && event.GetData()->key == KEY(ESCAPE)) ) { m_settings->SaveSettings(); - m_engine->ApplyChange(); m_interface->DeleteControl(EVENT_WINDOW5); m_main->ChangePhase(PHASE_SIMUL); m_main->StopSuspend(); diff --git a/src/ui/screen/screen_setup_graphics.cpp b/src/ui/screen/screen_setup_graphics.cpp index 83713b70..93467540 100644 --- a/src/ui/screen/screen_setup_graphics.cpp +++ b/src/ui/screen/screen_setup_graphics.cpp @@ -248,8 +248,12 @@ bool CScreenSetupGraphics::EventProcess(const Event &event) switch( event.type ) { case EVENT_INTERFACE_PARTI: + ChangeSetupButtons(); + break; + case EVENT_INTERFACE_CLIP: ChangeSetupButtons(); + m_engine->ApplyChange(); break; case EVENT_INTERFACE_DIRTY: From c19f97bc24c2c5532db84fd2ba6664fba22f8838 Mon Sep 17 00:00:00 2001 From: melex750 Date: Tue, 24 May 2016 10:09:44 -0400 Subject: [PATCH 071/125] Fix RestoreState to assign IDs to instance vars --- src/CBot/CBotStack.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 746976b0..3170fb72 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -805,6 +805,8 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) CBotToken token(name, std::string()); + bool isClass = false; + switch (w) { case CBotTypInt: @@ -826,6 +828,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) // returns an intrinsic object or element of an array case CBotTypIntrinsic: + isClass = true; case CBotTypArrayBody: { CBotTypResult r; @@ -843,6 +846,17 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) if ( !RestoreState(pf, (static_cast(pNew))->m_pVar)) return false; pNew->SetIdent(id); + if (isClass && p == nullptr) // set id for each item in this instance + { + CBotVar* pVars = pNew->GetItemList(); + long itemId = 1; + while (pVars != nullptr) + { + pVars->m_ident = itemId++; + pVars = pVars->GetNext(); + } + } + if ( p != nullptr ) { delete pNew; From 6491ce0aa5b1139fc8c55e9bc56d999790b187aa Mon Sep 17 00:00:00 2001 From: melex750 Date: Tue, 24 May 2016 10:30:20 -0400 Subject: [PATCH 072/125] Fix passing "this" as an argument to a method --- src/CBot/CBotInstr/CBotInstrMethode.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp index 52a58cca..e0d08a99 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.cpp +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -119,7 +119,7 @@ bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre pThis->SetName("this"); pThis->SetUniqNum(-2); - pile1->AddVar(pThis); + pile1->SetVar(pThis); pile1->IncState(); } int i = 0; @@ -144,7 +144,7 @@ bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre ppVars[i] = nullptr; CBotClass* pClass = CBotClass::Find(m_className); - CBotVar* pThis = pile1->FindVar(-2, false); + CBotVar* pThis = pile1->GetVar(); CBotVar* pResult = nullptr; if (m_typRes.GetType() > 0) pResult = CBotVar::Create("", m_typRes); if (m_typRes.Eq(CBotTypClass)) @@ -174,7 +174,10 @@ void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, bool bMain) CBotStack* pile2 = pile1->RestoreStack(); // and for the parameters coming if (pile2 == nullptr) return; - CBotVar* pThis = pile1->FindVar("this"); + CBotVar* pThis = pile1->GetVar(); + + assert(pThis != nullptr); // see fix for issues #256 & #436 + pThis->SetUniqNum(-2); int i = 0; @@ -226,7 +229,7 @@ bool CBotInstrMethode::Execute(CBotStack* &pj) // Test.Action (Test = Other); // Action must act on the value before test = Other! pThis->SetName("this"); - pile1->AddVar(pThis); + pile1->SetVar(pThis); pile1->IncState(); } int i = 0; @@ -250,7 +253,7 @@ bool CBotInstrMethode::Execute(CBotStack* &pj) ppVars[i] = nullptr; CBotClass* pClass = CBotClass::Find(m_className); - CBotVar* pThis = pile1->FindVar("this"); + CBotVar* pThis = pile1->GetVar(); CBotVar* pResult = nullptr; if (m_typRes.GetType()>0) pResult = CBotVar::Create("", m_typRes); if (m_typRes.Eq(CBotTypClass)) From 620620fa615fba839c809d89e3e3ac5efb5f9976 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 27 May 2016 11:39:33 +0200 Subject: [PATCH 073/125] Reenabled working tests after fc7e6214714c0c959fe00f200dcd30653107bbc0 --- test/unit/CBot/CBot_test.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/test/unit/CBot/CBot_test.cpp b/test/unit/CBot/CBot_test.cpp index f130666f..129d7972 100644 --- a/test/unit/CBot/CBot_test.cpp +++ b/test/unit/CBot/CBot_test.cpp @@ -909,8 +909,7 @@ TEST_F(CBotUT, DISABLED_PublicClasses) ); } -// TODO: This needs to be fixed -TEST_F(CBotUT, DISABLED_WeirdThisEarlyContextSwitch_Issue436) +TEST_F(CBotUT, ThisEarlyContextSwitch_Issue436) { ExecuteTest( "public class Something {\n" @@ -1091,3 +1090,28 @@ TEST_F(CBotUT, TestArrayFunctionReturn) "}\n" ); } + +TEST_F(CBotUT, AccessMembersInParameters_Issue256) +{ + ExecuteTest( + "public class Test1 {\n" + " int x = 1337;\n" + "}\n" + "public class Test2 {\n" + " public bool test(int a) {\n" + " return a == 1337;\n" + " }\n" + "}\n" + "public class Test3 {\n" + " public Test1 test1 = new Test1();\n" + " public Test2 test2 = new Test2();\n" + " public void test() {\n" + " ASSERT(test2.test(test1.x));\n" + " }\n" + "}\n" + "extern void AccessMembersInParameters() {\n" + " Test3 t();\n" + " t.test();\n" + "}\n" + ); +} From 261b26c8e9b2f81a4028d1264379b2da00b87cf0 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 27 May 2016 18:30:56 +0200 Subject: [PATCH 074/125] Added Jenkinsfile --- Jenkinsfile | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..a0431a69 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,49 @@ +node('master') { + stage 'Pull changes' + checkout scm + + stage 'Build Windows' + sh 'mkdir -p build/windows' + dir('build/windows') { + sh ''' + cmake \ + -DCMAKE_INSTALL_PREFIX=/install \ + -DCMAKE_TOOLCHAIN_FILE=/opt/mxe/usr/i686-w64-mingw32.static/share/cmake/mxe-conf.cmake \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDEV_BUILD=1 -DPORTABLE=1 -DTOOLS=1 -DTESTS=0 ../.. + make + rm -rf install + DESTDIR=. make install + ''' + } + sh 'rm -f windows-debug.zip' + zip zipFile: 'windows-debug.zip', archive: true, dir: 'build/windows/install' + + stage 'Build Linux' + sh 'mkdir -p build/linux' + dir('build/linux') { + sh ''' + cmake \ + -DCMAKE_INSTALL_PREFIX=/install -DCOLOBOT_INSTALL_BIN_DIR=/install -DCOLOBOT_INSTALL_LIB_DIR=/install -DCOLOBOT_INSTALL_DATA_DIR=/install/data -DCOLOBOT_INSTALL_I18N_DIR=/install/lang \ + -DBOOST_STATIC=ON -DGLEW_STATIC=ON -DGLEW_LIBRARY=/usr/lib64/libGLEW.a \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDEV_BUILD=1 -DPORTABLE=1 -DTOOLS=1 -DTESTS=1 -DDESKTOP=0 ../.. + make + rm -rf install + DESTDIR=. make install + ''' + } + sh 'rm -f linux-debug.zip' + zip zipFile: 'linux-debug.zip', archive: true, dir: 'build/linux/install' + + stage 'Doxygen' + dir('build/linux') { + sh 'make doc' + } + publishHTML target: [$class: 'HtmlPublisherTarget', reportName: 'Doxygen', reportDir: 'build/linux/doc/html', reportFiles: 'index.html'] + + stage 'Run tests' + dir('build/linux') { + sh './colobot_ut --gtest_output=xml:gtestresults.xml || true' + } + step([$class: 'XUnitBuilder', testTimeMargin: '3000', thresholdMode: 1, thresholds: [[$class: 'FailedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '0'], [$class: 'SkippedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '']], tools: [[$class: 'GoogleTestType', deleteOutputFiles: true, failIfNotNew: true, pattern: 'build/linux/gtestresults.xml', skipNoTestFiles: false, stopProcessingIfError: true]]]) +} + From bd72086704a6b61222a9708b848875585d84ae4e Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 27 May 2016 22:38:44 +0200 Subject: [PATCH 075/125] Unified all camera inputs Until now each camera type had separate code for handling camera input, and some new features were missing in some of them. The camera controls are as follows: * RMB+mouse and numpad keys - horizontal/vertical rotation * mouse wheel and +/- keys - zoom (in free camera - move eye up/down) * CTRL or MMB + horizontal controls - pan left/right * CTRL or MMB + zoom controls - move lookat up/down (free camera only) --- po/colobot.pot | 6 - po/de.po | 6 - po/fr.po | 12 +- po/pl.po | 12 +- po/ru.po | 6 - src/app/input.cpp | 30 +--- src/app/input.h | 8 - src/common/key.h | 2 - src/common/restext.cpp | 2 - src/graphics/engine/camera.cpp | 266 ++++++++++----------------------- src/graphics/engine/camera.h | 21 +-- 11 files changed, 109 insertions(+), 262 deletions(-) diff --git a/po/colobot.pot b/po/colobot.pot index b39e7ad2..08625b6f 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -506,12 +506,6 @@ msgstr "" msgid "Speed 6.0x\\Sextuple speed" msgstr "" -msgid "Camera up\\Increase camera angle while visiting message origin" -msgstr "" - -msgid "Camera down\\Decrease camera angle while visiting message origin" -msgstr "" - msgid "Pause\\Pause the game without opening menu" msgstr "" diff --git a/po/de.po b/po/de.po index 972066e6..c49e5cf0 100644 --- a/po/de.po +++ b/po/de.po @@ -330,9 +330,6 @@ msgstr "Kameradrehung mit der Maus\\Die Kamera dreht wenn die Maus den Rand erre msgid "Camera closer\\Moves the camera forward" msgstr "Kamera näher\\Bewegung der Kamera vorwärts" -msgid "Camera down\\Decrease camera angle while visiting message origin" -msgstr "" - msgid "Camera nearest" msgstr "Kamera näher" @@ -342,9 +339,6 @@ msgstr "Kamera links" msgid "Camera to right" msgstr "Kamera rechts" -msgid "Camera up\\Increase camera angle while visiting message origin" -msgstr "" - msgid "Can not produce not researched object" msgstr "Das erforschte Objekt kann nicht produziert werden" diff --git a/po/fr.po b/po/fr.po index 6822fa0e..880f1d02 100644 --- a/po/fr.po +++ b/po/fr.po @@ -321,9 +321,6 @@ msgstr "Défilement dans les bords\\Défilement lorsque la souris touche les bor msgid "Camera closer\\Moves the camera forward" msgstr "Caméra plus proche\\Avance la caméra" -msgid "Camera down\\Decrease camera angle while visiting message origin" -msgstr "Caméra plus basse\\Réduit l'angle de caméra lors de la vue de l'origine des messages" - msgid "Camera nearest" msgstr "Caméra plus proche" @@ -333,9 +330,6 @@ msgstr "Caméra à gauche" msgid "Camera to right" msgstr "Caméra à droite" -msgid "Camera up\\Increase camera angle while visiting message origin" -msgstr "Caméra plus haute\\Augmente l'angle de caméra lors de la vue de l'origine des messages" - msgid "Can not produce not researched object" msgstr "Impossible de créer un objet n'ayant pas été recherché" @@ -1815,6 +1809,12 @@ msgstr "" #~ msgid "COLOBOT" #~ msgstr "COLOBOT" +#~ msgid "Camera down\\Decrease camera angle while visiting message origin" +#~ msgstr "Caméra plus basse\\Réduit l'angle de caméra lors de la vue de l'origine des messages" + +#~ msgid "Camera up\\Increase camera angle while visiting message origin" +#~ msgstr "Caméra plus haute\\Augmente l'angle de caméra lors de la vue de l'origine des messages" + #~ msgid "Can not create this; there are too many objects" #~ msgstr "Création impossible; il y a trop d'objets" diff --git a/po/pl.po b/po/pl.po index 89cc2368..67967286 100644 --- a/po/pl.po +++ b/po/pl.po @@ -324,9 +324,6 @@ msgstr "Przewijanie kamery przy krawędzi\\Ekran jest przewijany gdy mysz dotkni msgid "Camera closer\\Moves the camera forward" msgstr "Kamera bliżej\\Przybliża kamerę" -msgid "Camera down\\Decrease camera angle while visiting message origin" -msgstr "Kamera w dół\\Opuść kamerę podczas sprawdzania źródła wiadomości" - msgid "Camera nearest" msgstr "Camera nearest" @@ -336,9 +333,6 @@ msgstr "Camera to left" msgid "Camera to right" msgstr "Camera to right" -msgid "Camera up\\Increase camera angle while visiting message origin" -msgstr "Kamera w górę\\Podnieś kamerę podczas sprawdzania źródła wiadomości" - msgid "Can not produce not researched object" msgstr "Nie można wyprodukować nie wynalezionego obiektu" @@ -1811,6 +1805,12 @@ msgstr "" #~ msgid "Building too close" #~ msgstr "Budynek za blisko" +#~ msgid "Camera down\\Decrease camera angle while visiting message origin" +#~ msgstr "Kamera w dół\\Opuść kamerę podczas sprawdzania źródła wiadomości" + +#~ msgid "Camera up\\Increase camera angle while visiting message origin" +#~ msgstr "Kamera w górę\\Podnieś kamerę podczas sprawdzania źródła wiadomości" + #~ msgid "Can not create this; there are too many objects" #~ msgstr "Nie można tego utworzyć, za dużo obiektów" diff --git a/po/ru.po b/po/ru.po index 31d91d65..563ba006 100644 --- a/po/ru.po +++ b/po/ru.po @@ -328,9 +328,6 @@ msgstr "Прокрутка\\Прокрутка, когда указатель м msgid "Camera closer\\Moves the camera forward" msgstr "Приблизать камеру\\Перемещение камеры вперед" -msgid "Camera down\\Decrease camera angle while visiting message origin" -msgstr "" - msgid "Camera nearest" msgstr "Приблизить камеру" @@ -340,9 +337,6 @@ msgstr "Камеру влево" msgid "Camera to right" msgstr "Камеру вправо" -msgid "Camera up\\Increase camera angle while visiting message origin" -msgstr "" - msgid "Can not produce not researched object" msgstr "" diff --git a/src/app/input.cpp b/src/app/input.cpp index ed1fdf93..0a049157 100644 --- a/src/app/input.cpp +++ b/src/app/input.cpp @@ -30,6 +30,7 @@ #include #include +#include template<> CInput* CSingleton::m_instance = nullptr; @@ -63,13 +64,10 @@ CInput::CInput() { INPUT_SLOT_SPEED30, "speed30" }, { INPUT_SLOT_SPEED40, "speed40" }, { INPUT_SLOT_SPEED60, "speed60" }, - { INPUT_SLOT_CAMERA_UP, "camup" }, - { INPUT_SLOT_CAMERA_DOWN, "camdown" }, { INPUT_SLOT_PAUSE, "pause" }, { INPUT_SLOT_CMDLINE, "cmdline" }, }; - m_kmodState = 0; m_mousePos = Math::Point(); m_mouseButtonsState = 0; std::fill_n(m_keyPresses, static_cast(INPUT_SLOT_MAX), false); @@ -80,13 +78,6 @@ CInput::CInput() void CInput::EventProcess(Event& event) { - if (event.type == EVENT_KEY_DOWN || - event.type == EVENT_KEY_UP) - { - // Use the occasion to update kmods - m_kmodState = event.kmodState; - } - // Use the occasion to update mouse button state if (event.type == EVENT_MOUSE_BUTTON_DOWN) { @@ -107,7 +98,7 @@ void CInput::EventProcess(Event& event) data->slot = FindBinding(data->key); } - event.kmodState = m_kmodState; + event.kmodState = SDL_GetModState(); event.mousePos = m_mousePos; event.mouseButtonsState = m_mouseButtonsState; @@ -134,8 +125,6 @@ void CInput::EventProcess(Event& event) if (data->slot == INPUT_SLOT_GUP ) m_keyMotion.z = 1.0f; if (data->slot == INPUT_SLOT_GDOWN) m_keyMotion.z = -1.0f; - if (data->slot == INPUT_SLOT_CAMERA_UP ) m_cameraKeyMotion.z = 1.0f; - if (data->slot == INPUT_SLOT_CAMERA_DOWN) m_cameraKeyMotion.z = -1.0f; if (data->key == KEY(KP_4) ) m_cameraKeyMotion.x = -1.0f; if (data->key == KEY(KP_6) ) m_cameraKeyMotion.x = 1.0f; if (data->key == KEY(KP_8) ) m_cameraKeyMotion.y = 1.0f; @@ -152,8 +141,6 @@ void CInput::EventProcess(Event& event) if (data->slot == INPUT_SLOT_GUP ) m_keyMotion.z = 0.0f; if (data->slot == INPUT_SLOT_GDOWN) m_keyMotion.z = 0.0f; - if (data->slot == INPUT_SLOT_CAMERA_UP ) m_cameraKeyMotion.z = 0.0f; - if (data->slot == INPUT_SLOT_CAMERA_DOWN) m_cameraKeyMotion.z = 0.0f; if (data->key == KEY(KP_4) ) m_cameraKeyMotion.x = 0.0f; if (data->key == KEY(KP_6) ) m_cameraKeyMotion.x = 0.0f; if (data->key == KEY(KP_8) ) m_cameraKeyMotion.y = 0.0f; @@ -194,16 +181,6 @@ void CInput::MouseMove(Math::IntPoint pos) m_mousePos = Gfx::CEngine::GetInstancePointer()->WindowToInterfaceCoords(pos); } -int CInput::GetKmods() const -{ - return m_kmodState; -} - -bool CInput::GetKmodState(int kmod) const -{ - return (m_kmodState & kmod) != 0; -} - bool CInput::GetKeyState(InputSlot key) const { return m_keyPresses[key]; @@ -217,7 +194,6 @@ bool CInput::GetMouseButtonState(int index) const void CInput::ResetKeyStates() { GetLogger()->Trace("Reset key states\n"); - m_kmodState = 0; m_keyMotion = Math::Vector(0.0f, 0.0f, 0.0f); m_joyMotion = Math::Vector(0.0f, 0.0f, 0.0f); m_cameraKeyMotion = Math::Vector(0.0f, 0.0f, 0.0f); @@ -272,8 +248,6 @@ void CInput::SetDefaultInputBindings() m_inputBindings[INPUT_SLOT_SPEED30].primary = KEY(F7); m_inputBindings[INPUT_SLOT_SPEED40].primary = KEY(F8); m_inputBindings[INPUT_SLOT_SPEED60].primary = KEY(F9); - m_inputBindings[INPUT_SLOT_CAMERA_UP].primary = KEY(PAGEUP); - m_inputBindings[INPUT_SLOT_CAMERA_DOWN].primary = KEY(PAGEDOWN); m_inputBindings[INPUT_SLOT_PAUSE].primary = KEY(PAUSE); m_inputBindings[INPUT_SLOT_PAUSE].secondary = KEY(p); m_inputBindings[INPUT_SLOT_CMDLINE].primary = KEY(BACKQUOTE); diff --git a/src/app/input.h b/src/app/input.h index e9203880..d58bf2fb 100644 --- a/src/app/input.h +++ b/src/app/input.h @@ -81,12 +81,6 @@ public: void MouseMove(Math::IntPoint pos); - //! Returns the current key modifiers - int GetKmods() const; - - //! Returns whether the given kmod is active - bool GetKmodState(int kmod) const; - //! Returns whether the key is pressed bool GetKeyState(InputSlot key) const; @@ -140,8 +134,6 @@ public: //@} private: - //! Current state of key modifiers (bitmask of SDLMod) - unsigned int m_kmodState; //! Current state of keys bool m_keyPresses[INPUT_SLOT_MAX]; diff --git a/src/common/key.h b/src/common/key.h index 4f089ec6..d618c459 100644 --- a/src/common/key.h +++ b/src/common/key.h @@ -102,8 +102,6 @@ enum InputSlot INPUT_SLOT_SPEED30, INPUT_SLOT_SPEED40, INPUT_SLOT_SPEED60, - INPUT_SLOT_CAMERA_UP, - INPUT_SLOT_CAMERA_DOWN, INPUT_SLOT_PAUSE, INPUT_SLOT_CMDLINE, diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 2016464f..24d515d3 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -235,8 +235,6 @@ void InitializeRestext() stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_SPEED30] = TR("Speed 3.0x\\Triple speed"); stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_SPEED40] = TR("Speed 4.0x\\Quadruple speed"); stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_SPEED60] = TR("Speed 6.0x\\Sextuple speed"); - stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_CAMERA_UP] = TR("Camera up\\Increase camera angle while visiting message origin"); - stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_CAMERA_DOWN] = TR("Camera down\\Decrease camera angle while visiting message origin"); stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_PAUSE] = TR("Pause\\Pause the game without opening menu"); stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_CMDLINE] = TR("Cheat console\\Show cheat console"); diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index 53613b6a..b713bc67 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -102,7 +102,7 @@ CCamera::CCamera() m_eyePt = Math::Vector(0.0f, 0.0f, 0.0f); m_directionH = 0.0f; m_directionV = 0.0f; - m_heightEye = 20.0f; + m_heightEye = 40.0f; m_heightLookat = 0.0f; m_speed = 2.0f; @@ -122,8 +122,6 @@ CCamera::CCamera() m_visitType = CAM_TYPE_NULL; m_visitDirectionV = 0.0f; - m_editHeight = 40.0f; - m_remotePan = 0.0f; m_centeringPhase = CAM_PHASE_NULL; @@ -1145,34 +1143,7 @@ bool CCamera::EventMouseMove(const Event &event) void CCamera::EventMouseWheel(const Event &event) { auto dir = event.GetData()->y; - - if (m_type == CAM_TYPE_BACK) - { - m_backDist -= 8.0f*dir; - if (m_backDist < m_backMin) - m_backDist = m_backMin; - if (m_backDist > 200.0f) - m_backDist = 200.0f; - } - - if ( m_type == CAM_TYPE_FIX || - m_type == CAM_TYPE_PLANE ) - { - m_fixDist -= 8.0f*dir; - if (m_fixDist < 10.0f) - m_fixDist = 10.0f; - if (m_fixDist > 200.0f) - m_fixDist = 200.0f; - } - - if ( m_type == CAM_TYPE_VISIT ) - { - m_visitDist -= 8.0f*dir; - if (m_visitDist < 20.0f) - m_visitDist = 20.0f; - if (m_visitDist > 200.0f) - m_visitDist = 200.0f; - } + m_mouseWheelDelta -= dir; } void CCamera::EventMouseButton(const Event &event) @@ -1202,11 +1173,9 @@ bool CCamera::EventFrame(const Event &event) EffectFrame(event); OverFrame(event); - if (m_type == CAM_TYPE_FREE) - return EventFrameFree(event); - - if (m_type == CAM_TYPE_EDIT) - return EventFrameEdit(event); + if (m_type == CAM_TYPE_FREE || + m_type == CAM_TYPE_EDIT) + return EventFrameFree(event, m_type != CAM_TYPE_EDIT); if (m_type == CAM_TYPE_DIALOG) return EventFrameDialog(event); @@ -1236,57 +1205,36 @@ bool CCamera::EventFrame(const Event &event) return true; } -bool CCamera::EventFrameFree(const Event &event) +bool CCamera::EventFrameFree(const Event &event, bool keysAllowed) { - Math::Vector cameraInput = event.cameraInput; - if (m_cameraObj == nullptr) - { - cameraInput = Math::Clamp(cameraInput + event.motionInput, Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector(1.0f, 1.0f, 1.0f)); - } + Math::Vector cameraMove = CalculateCameraMovement(event, keysAllowed); float factor = m_heightEye * 0.5f + 30.0f; + bool secondary = event.kmodState & KEY_MOD(CTRL) || event.mouseButtonsState & MOUSE_BUTTON_MIDDLE; - m_directionH -= m_mouseDelta.x * 2*Math::PI; - m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDelta.y * factor * m_speed); - m_mouseDelta.LoadZero(); + // Forward/Backward + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, -cameraMove.y * factor * 2); - // Up/Down - m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, cameraInput.y * event.rTime * factor * m_speed); - - // Left/Right - if ( event.kmodState & KEY_MOD(CTRL) ) + // Left/Right (pan or rotate) + if (secondary) { - if ( cameraInput.x < 0.0f ) - m_eyePt = Math::LookatPoint(m_eyePt, m_directionH + Math::PI / 2.0f, m_directionV, -cameraInput.x * event.rTime * factor * m_speed); - if ( cameraInput.x > 0.0f ) - m_eyePt = Math::LookatPoint(m_eyePt, m_directionH - Math::PI / 2.0f, m_directionV, cameraInput.x * event.rTime * factor * m_speed); + if (cameraMove.x < 0.0f) + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH + Math::PI / 2.0f, m_directionV, -cameraMove.x * factor); + if (cameraMove.x > 0.0f) + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH - Math::PI / 2.0f, m_directionV, cameraMove.x * factor); } else { - m_directionH -= cameraInput.x * event.rTime * 0.7f * m_speed; + m_directionH -= cameraMove.x; } - // PageUp/PageDown - if ( m_input->GetKeyState(INPUT_SLOT_AWAY) ) - { - if (m_heightEye < 500.0f) - m_heightEye += event.rTime * factor * m_speed; - } - if ( m_input->GetKeyState(INPUT_SLOT_NEAR) ) - { - if (m_heightEye > -2.0f) - m_heightEye -= event.rTime * factor * m_speed; - } + // Up/Down (eye or lookat point) + if (secondary) + m_heightLookat -= cameraMove.z; + else + m_heightEye -= cameraMove.z; - - if ( m_input->GetKeyState(INPUT_SLOT_CAMERA_UP) ) - { - m_heightLookat += event.rTime * factor * m_speed; - } - if ( m_input->GetKeyState(INPUT_SLOT_CAMERA_DOWN) ) - { - m_heightLookat -= event.rTime * factor * m_speed; - } + m_heightEye = Math::Clamp(m_heightEye, -2.0f, 500.0f); m_terrain->AdjustToBounds(m_eyePt, 10.0f); @@ -1314,44 +1262,6 @@ bool CCamera::EventFrameFree(const Event &event) return true; } -bool CCamera::EventFrameEdit(const Event &event) -{ - float factor = m_editHeight * 0.5f + 30.0f; - - m_directionH -= m_mouseDelta.x * 0.7f * 2*Math::PI; - m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDelta.y * factor * m_speed); - - m_fixDirectionH += m_mouseDelta.x * 2*Math::PI; - m_fixDirectionH = Math::NormAngle(m_fixDirectionH); - - m_mouseDelta.LoadZero(); - - m_terrain->AdjustToBounds(m_eyePt, 10.0f); - - if (m_terrain->AdjustToFloor(m_eyePt, false)) - { - m_eyePt.y += m_editHeight; - - Math::Vector pos = m_eyePt; - if (m_terrain->AdjustToFloor(pos, false)) - { - pos.y += 2.0f; - if (m_eyePt.y < pos.y) - m_eyePt.y = pos.y; - } - - } - - Math::Vector lookatPt = Math::LookatPoint( m_eyePt, m_directionH, m_directionV, 50.0f ); - - if ( m_terrain->AdjustToFloor(lookatPt, true)) - lookatPt.y += m_heightLookat; - - SetViewTime(m_eyePt, lookatPt, event.rTime); - - return true; -} - bool CCamera::EventFrameDialog(const Event &event) { return true; @@ -1359,29 +1269,15 @@ bool CCamera::EventFrameDialog(const Event &event) bool CCamera::EventFrameBack(const Event &event) { - ObjectType type; - if (m_cameraObj == nullptr) - type = OBJECT_NULL; - else - type = m_cameraObj->GetType(); + Math::Vector cameraMove = CalculateCameraMovement(event); + m_addDirectionH += cameraMove.x; + m_addDirectionV += cameraMove.y; + m_backDist += cameraMove.z; - // +/-. - if (m_input->GetKeyState(INPUT_SLOT_NEAR)) - { - m_backDist -= event.rTime * 30.0f * m_speed; - if (m_backDist < m_backMin) m_backDist = m_backMin; - } - if (m_input->GetKeyState(INPUT_SLOT_AWAY)) - { - m_backDist += event.rTime * 30.0f * m_speed; - if (m_backDist > 200.0f) m_backDist = 200.0f; - } - - m_addDirectionH -= m_mouseDelta.x * 2*Math::PI; m_addDirectionH = Math::NormAngle(m_addDirectionH); - if (m_mouseDelta.Length() > 0) - AbortCentering(); // special stops framing - m_mouseDelta.LoadZero(); + m_addDirectionV = Math::NormAngle(m_addDirectionV); + + m_backDist = Math::Clamp(m_backDist, m_backMin, 200.0f); // Increase the special framework float centeringH = 0.0f; @@ -1423,6 +1319,8 @@ bool CCamera::EventFrameBack(const Event &event) if (m_cameraObj != nullptr) { + ObjectType type = m_cameraObj->GetType(); + Math::Vector lookatPt = m_cameraObj->GetPosition(); if (type == OBJECT_BASE ) lookatPt.y += 40.0f; else if (type == OBJECT_HUMAN) lookatPt.y += 1.0f; @@ -1502,30 +1400,16 @@ bool CCamera::EventFrameBack(const Event &event) bool CCamera::EventFrameFix(const Event &event) { - // +/-. - if (m_input->GetKeyState(INPUT_SLOT_NEAR)) - { - m_fixDist -= event.rTime * 30.0f * m_speed; - if (m_fixDist < 10.0f) m_fixDist = 10.0f; - } - if (m_input->GetKeyState(INPUT_SLOT_AWAY)) - { - m_fixDist += event.rTime * 30.0f * m_speed; - if (m_fixDist > 200.0f) m_fixDist = 200.0f; - } + Math::Vector cameraMove = CalculateCameraMovement(event); + m_fixDirectionH += cameraMove.x; + m_fixDirectionV += cameraMove.y; + m_fixDist += cameraMove.z; - m_fixDirectionH -= m_mouseDelta.x * 2*Math::PI; - if (m_mouseDelta.Length() > 0) - AbortCentering(); // special stops framing - m_mouseDelta.LoadZero(); - - // Left/Right - m_fixDirectionH += event.cameraInput.x * event.rTime * 0.7f * m_speed; m_fixDirectionH = Math::NormAngle(m_fixDirectionH); + m_fixDirectionV = Math::NormAngle(m_fixDirectionV); - // Up/Down - m_fixDirectionV -= event.cameraInput.y * event.rTime * 0.7f * m_speed; - m_fixDirectionV = Math::Min(Math::Max(m_fixDirectionV, -0.5*Math::PI), 0.25*Math::PI); + m_fixDirectionV = Math::Clamp(m_fixDirectionV, -0.5f*Math::PI, 0.25f*Math::PI); + m_fixDist = Math::Clamp(m_fixDist, 10.0f, 200.0f); if (m_cameraObj != nullptr) { @@ -1551,8 +1435,9 @@ bool CCamera::EventFrameFix(const Event &event) bool CCamera::EventFrameExplo(const Event &event) { - m_directionH -= m_mouseDelta.x * 2*Math::PI; - m_mouseDelta.LoadZero(); + Math::Vector cameraMove = CalculateCameraMovement(event); + m_directionH += cameraMove.x; + m_directionH = Math::NormAngle(m_directionH); m_terrain->AdjustToBounds(m_eyePt, 10.0f); @@ -1609,34 +1494,15 @@ bool CCamera::EventFrameVisit(const Event &event) { m_visitTime += event.rTime; - // +/-. - if (m_input->GetKeyState(INPUT_SLOT_NEAR)) - { - m_visitDist -= event.rTime * 50.0f * m_speed; - if (m_visitDist < 20.0f) m_visitDist = 20.0f; - } - if (m_input->GetKeyState(INPUT_SLOT_AWAY)) - { - m_visitDist += event.rTime * 50.0f * m_speed; - if (m_visitDist > 200.0f) m_visitDist = 200.0f; - } + Math::Vector cameraMove = CalculateCameraMovement(event); - // PageUp/Down. - if (m_input->GetKeyState(INPUT_SLOT_CAMERA_UP)) - { - m_visitDirectionV -= event.rTime * 1.0f * m_speed; - if (m_visitDirectionV < -Math::PI * 0.40f) m_visitDirectionV = -Math::PI * 0.40f; - } - if (m_input->GetKeyState(INPUT_SLOT_CAMERA_DOWN)) - { - m_visitDirectionV += event.rTime * 1.0f * m_speed; - if (m_visitDirectionV > 0.0f ) m_visitDirectionV = 0.0f; - } + // ZoomIn/ZoomOut + m_visitDist += cameraMove.z; + m_visitDist = Math::Clamp(m_visitDist, 20.0f, 200.0f); - m_visitDist -= m_mouseDelta.y * 100.0f * m_speed; - m_mouseDelta.LoadZero(); - if (m_visitDist < 20.0f) m_visitDist = 20.0f; - if (m_visitDist > 200.0f) m_visitDist = 200.0f; + // Up/Down + m_visitDirectionV += cameraMove.y; + m_visitDirectionV = Math::Clamp(m_visitDirectionV, -Math::PI * 0.40f, 0.0f); float angleH = (m_visitTime / 10.0f) * (Math::PI * 2.0f); float angleV = m_visitDirectionV; @@ -1726,4 +1592,38 @@ void CCamera::SetCameraSpeed(float speed) m_speed = speed; } +Math::Vector CCamera::CalculateCameraMovement(const Event &event, bool keysAllowed) +{ + Math::Vector delta; + + delta.x += m_mouseDelta.x * 2*Math::PI; + delta.y -= m_mouseDelta.y * Math::PI; + m_mouseDelta.LoadZero(); + + delta.z += m_mouseWheelDelta * 8.0f; + m_mouseWheelDelta = 0.0f; + + if (keysAllowed) + { + delta.x += event.cameraInput.x * event.rTime * 0.5f * m_speed; + delta.y -= event.cameraInput.y * event.rTime * 0.5f * m_speed; + + if (m_cameraObj == nullptr) + { + delta.x += event.motionInput.x * event.rTime * 0.5f * m_speed; + delta.y -= event.motionInput.y * event.rTime * 0.5f * m_speed; + } + + if (m_input->GetKeyState(INPUT_SLOT_NEAR)) + delta.z -= event.rTime * 20.0f * m_speed; + if (m_input->GetKeyState(INPUT_SLOT_AWAY)) + delta.z += event.rTime * 20.0f * m_speed; + } + + if (delta.Length() > 0) + AbortCentering(); // special stops framing + + return delta; +} + } diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index f00332a0..8d7386f5 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -144,11 +144,11 @@ public: CObject* GetControllingObject(); //! Change the type of camera - void SetType(CameraType type); - CameraType GetType(); + void SetType(CameraType type); + CameraType GetType(); //! Management of the smoothing mode - void SetSmooth(CameraSmooth type); + void SetSmooth(CameraSmooth type); CameraSmooth GetSmooth(); //! Management of the setback distance @@ -223,9 +223,7 @@ protected: //! Changes the camera according to the time elapsed bool EventFrame(const Event &event); //! Moves the point of view - bool EventFrameFree(const Event &event); - //! Moves the point of view - bool EventFrameEdit(const Event &event); + bool EventFrameFree(const Event &event, bool keysAllowed); //! Moves the point of view bool EventFrameDialog(const Event &event); //! Moves the point of view @@ -264,6 +262,13 @@ protected: //! Advanced overlay effect in the foreground void OverFrame(const Event &event); + /** + * \brief Calculate camera movement (from user inputs) to apply + * \return Math::Vector where x, y represent respectively horizontal and vertical angle change in radians and z represents zoom (distance change) + * \remarks Should not be called more often than once every EVENT_FRAME + **/ + Math::Vector CalculateCameraMovement(const Event &event, bool keysAllowed = true); + protected: CEngine* m_engine; CRobotMain* m_main; @@ -339,15 +344,13 @@ protected: //! CAM_TYPE_VISIT: direction float m_visitDirectionV; - //! CAM_TYPE_EDIT: height - float m_editHeight; - float m_remotePan; //! Last known mouse position, used to calculate change since last frame Math::Point m_mousePos = Math::Point(0.5f, 0.5f); Math::Point m_mouseDelta = Math::Point(0.0f, 0.0f); Math::Point m_mouseDeltaEdge = Math::Point(0.0f, 0.0f); + float m_mouseWheelDelta = 0.0f; CenteringPhase m_centeringPhase; float m_centeringAngleH; From 250047579f3e23071507e461cf616c366125693b Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 27 May 2016 23:37:36 +0200 Subject: [PATCH 076/125] Allow using custom paths for win/lost scenes --- data | 2 +- src/level/level_category.cpp | 4 -- src/level/level_category.h | 5 --- src/level/robotmain.cpp | 64 ++++++++++++++++++++--------- src/level/robotmain.h | 6 ++- src/ui/screen/screen_level_list.cpp | 10 ----- src/ui/screen/screen_level_list.h | 1 - 7 files changed, 49 insertions(+), 43 deletions(-) diff --git a/data b/data index 229394cd..cbd7b5b4 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 229394cda28955dfa6ec554c58365d11c647f55c +Subproject commit cbd7b5b46a2098b8d88a96370cc8d9aeb05a71f7 diff --git a/src/level/level_category.cpp b/src/level/level_category.cpp index e2eab7df..c9274550 100644 --- a/src/level/level_category.cpp +++ b/src/level/level_category.cpp @@ -30,10 +30,6 @@ const std::map CATEGORY_DIR_MAP = { { LevelCategory::Challenges, "challenges" }, { LevelCategory::CodeBattles, "battles" }, { LevelCategory::CustomLevels, "custom" }, - - { LevelCategory::Win, "win" }, - { LevelCategory::Lost, "lost" }, - { LevelCategory::Perso, "perso" }, }; std::string GetLevelCategoryDir(LevelCategory category) diff --git a/src/level/level_category.h b/src/level/level_category.h index 1db6bccb..4001b674 100644 --- a/src/level/level_category.h +++ b/src/level/level_category.h @@ -30,11 +30,6 @@ enum class LevelCategory CodeBattles, CustomLevels, Max, - - // These are special types not runnable by the user - Win, - Lost, - Perso, }; std::string GetLevelCategoryDir(LevelCategory category); diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index e41a0605..2990ceb4 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -228,8 +228,6 @@ CRobotMain::CRobotMain() m_tooltipName.clear(); m_tooltipTime = 0.0f; - m_endingWinRank = 0; - m_endingLostRank = 0; m_winTerminate = false; m_globalMagnifyDamage = 1.0f; @@ -570,14 +568,14 @@ void CRobotMain::ChangePhase(Phase phase) if (m_phase == PHASE_WIN) { m_sound->StopAll(); - if (m_endingWinRank == -1) + if (m_endingWin.empty()) { ChangePhase(PHASE_LEVEL_LIST); } else { - m_winTerminate = (m_endingWinRank == 904); - SetLevel(LevelCategory::Win, 0, m_endingWinRank); + m_winTerminate = (m_endingWin.substr(m_endingWin.find_last_of("/")+1) == "win904.txt"); + m_levelFile = m_endingWin; try { CreateScene(false, true, false); // sets scene @@ -614,14 +612,14 @@ void CRobotMain::ChangePhase(Phase phase) if (m_phase == PHASE_LOST) { m_sound->StopAll(); - if (m_endingLostRank == -1) + if (m_endingLost.empty()) { ChangePhase(PHASE_LEVEL_LIST); } else { m_winTerminate = false; - SetLevel(LevelCategory::Lost, 0, m_endingLostRank); + m_levelFile = m_endingLost; try { CreateScene(false, true, false); // sets scene @@ -2793,7 +2791,7 @@ void CRobotMain::ScenePerso() m_lightMan->FlushLights(); m_particle->FlushParticle(); - SetLevel(LevelCategory::Perso, 0, 0); + m_levelFile = "levels/other/perso000.txt"; try { CreateScene(false, true, false); // sets scene @@ -2844,8 +2842,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_displayText->SetEnable(true); m_immediatSatCom = false; m_lockedSatCom = false; - m_endingWinRank = 0; - m_endingLostRank = 0; + m_endingWin = ""; + m_endingLost = ""; m_audioChange.clear(); m_endTake.clear(); m_endTakeImmediat = false; @@ -2890,7 +2888,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_missionResultFromScript = false; } - //NOTE: Reset timer always, even when only resetting object positions + // NOTE: Reset timer always, even when only resetting object positions m_missionTimerEnabled = false; m_missionTimerStarted = false; m_missionTimer = 0.0f; @@ -2905,7 +2903,9 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) try { m_ui->GetLoadingScreen()->SetProgress(0.05f, RT_LOADING_PROCESSING); - CLevelParser levelParser(m_levelCategory, m_levelChap, m_levelRank); + GetLogger()->Info("Loading level: %s\n", m_levelFile.c_str()); + CLevelParser levelParser(m_levelFile); + levelParser.SetLevelPaths(m_levelCategory, m_levelChap, m_levelRank); levelParser.Load(); int numObjects = levelParser.CountLines("CreateObject"); m_ui->GetLoadingScreen()->SetProgress(0.1f, RT_LOADING_LEVEL_SETTINGS); @@ -2913,11 +2913,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) int rankObj = 0; CObject* sel = nullptr; - /* - * NOTE: Moving frequently used lines to the top - * may speed up loading - */ - for (auto& line : levelParser.GetLines()) { if (line->GetCommand() == "Title" && !resetObject) @@ -2979,9 +2974,36 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (line->GetCommand() == "EndingFile" && !resetObject) { - // NOTE: The old default was 0, but I think -1 is more correct - 0 means "ending file 000", while -1 means "no ending file" - m_endingWinRank = line->GetParam("win")->AsInt(-1); - m_endingLostRank = line->GetParam("lost")->AsInt(-1); + auto Process = [&](const std::string& type) -> std::string + { + if (line->GetParam(type)->IsDefined()) + { + try + { + int rank = boost::lexical_cast(line->GetParam(type)->GetValue()); + if (rank >= 0) + { + GetLogger()->Warn("This level is using deprecated way of defining %1$s scene. Please change the %1$s= parameter in EndingFile from %2$d to \"levels/other/%1$s%2$03d.txt\".\n", type.c_str(), rank); + std::stringstream ss; + ss << "levels/other/" << type << std::setfill('0') << std::setw(3) << rank << ".txt"; + return ss.str(); + } + else + { + GetLogger()->Warn("This level is using deprecated way of defining %1$s scene. Please remove the %1$s= parameter in EndingFile.\n", type.c_str()); + return ""; + } + + } + catch (boost::bad_lexical_cast &e) + { + return line->GetParam(type)->AsPath("levels"); + } + } + return ""; + }; + m_endingWin = Process("win"); + m_endingLost = Process("lost"); continue; } @@ -5288,9 +5310,11 @@ float CRobotMain::GetPersoAngle() void CRobotMain::SetLevel(LevelCategory cat, int chap, int rank) { + GetLogger()->Debug("Change level to %s %d %d\n", GetLevelCategoryDir(cat).c_str(), chap, rank); m_levelCategory = cat; m_levelChap = chap; m_levelRank = rank; + m_levelFile = CLevelParser::BuildScenePath(m_levelCategory, m_levelChap, m_levelRank); } LevelCategory CRobotMain::GetLevelCategory() diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 3247813d..505b5b9a 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -458,6 +458,8 @@ protected: LevelCategory m_levelCategory; int m_levelChap = 0; int m_levelRank = 0; + //! if set, loads this file instead of building from category/chap/rank + std::string m_levelFile = ""; std::string m_sceneReadPath; float m_winDelay = 0.0f; @@ -517,8 +519,8 @@ protected: std::string m_scriptName = ""; std::string m_scriptFile = ""; - int m_endingWinRank = 0; - int m_endingLostRank = 0; + std::string m_endingWin = ""; + std::string m_endingLost = ""; bool m_winTerminate = false; float m_globalMagnifyDamage = 0.0f; diff --git a/src/ui/screen/screen_level_list.cpp b/src/ui/screen/screen_level_list.cpp index ee91369d..38110358 100644 --- a/src/ui/screen/screen_level_list.cpp +++ b/src/ui/screen/screen_level_list.cpp @@ -47,7 +47,6 @@ namespace Ui CScreenLevelList::CScreenLevelList(CMainDialog* mainDialog) : m_dialog(mainDialog), m_category{}, - m_listCategory{}, m_sceneSoluce{false}, m_maxList{0}, m_accessChap{0} @@ -57,15 +56,6 @@ CScreenLevelList::CScreenLevelList(CMainDialog* mainDialog) void CScreenLevelList::SetLevelCategory(LevelCategory category) { m_category = category; - - if ( static_cast(m_category) >= static_cast(LevelCategory::Max) ) - { - m_category = m_listCategory; - } - else - { - m_listCategory = m_category; - } } void CScreenLevelList::CreateInterface() diff --git a/src/ui/screen/screen_level_list.h b/src/ui/screen/screen_level_list.h index 2073e546..b27f88c1 100644 --- a/src/ui/screen/screen_level_list.h +++ b/src/ui/screen/screen_level_list.h @@ -63,7 +63,6 @@ protected: Ui::CMainDialog* m_dialog; LevelCategory m_category; - LevelCategory m_listCategory; bool m_sceneSoluce; From 5ab99429d4551a9e6cdfbe8349386a3aeec47360 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 May 2016 00:00:08 +0200 Subject: [PATCH 077/125] Fixed FIX camera up/down movement --- src/graphics/engine/camera.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index b713bc67..e0cfaa79 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -1406,7 +1406,6 @@ bool CCamera::EventFrameFix(const Event &event) m_fixDist += cameraMove.z; m_fixDirectionH = Math::NormAngle(m_fixDirectionH); - m_fixDirectionV = Math::NormAngle(m_fixDirectionV); m_fixDirectionV = Math::Clamp(m_fixDirectionV, -0.5f*Math::PI, 0.25f*Math::PI); m_fixDist = Math::Clamp(m_fixDist, 10.0f, 200.0f); From 99a831a03be068dd0c40ee3a7ca162cdcfb5e85d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 May 2016 00:26:56 +0200 Subject: [PATCH 078/125] Fixed CParticle::CheckChannel "errors" Not really errors, but I fixed them anyway --- src/graphics/engine/particle.cpp | 56 +++++++++++++++----------------- src/graphics/engine/particle.h | 13 +++++--- src/object/old_object.cpp | 6 ++-- src/object/old_object.h | 6 ++-- 4 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index e9aa0ab4..2642b74e 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -581,7 +581,7 @@ int CParticle::CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim if (!m_track[i].used) // free? { int rank = channel; - if (!CheckChannel(rank)) return -1; + GetRankFromChannel(rank); m_particle[rank].trackRank = i; m_track[i].used = true; @@ -636,27 +636,26 @@ void CParticle::CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, -/** Adapts the channel so it can be used as an offset in m_particle */ -bool CParticle::CheckChannel(int &channel) +void CParticle::GetRankFromChannel(int &channel) { int uniqueStamp = (channel>>16)&0xffff; channel &= 0xffff; - if (channel < 0) return false; - if (channel >= MAXPARTICULE*MAXPARTITYPE) return false; + assert(channel >= 0 && channel < MAXPARTICULE*MAXPARTITYPE); - if (!m_particle[channel].used) - { - GetLogger()->Error("CParticle::CheckChannel used=false !\n"); - return false; - } + if (!m_particle[channel].used) assert(!!"Tried to access invalid particle channel (used=false) !\n"); + if (m_particle[channel].uniqueStamp != uniqueStamp) assert(!!"Tried to access invalid particle channel (uniqueStamp changed) !\n"); +} - if (m_particle[channel].uniqueStamp != uniqueStamp) - { - GetLogger()->Error("CParticle::CheckChannel uniqueStamp !\n"); - return false; - } +bool CParticle::ParticleExists(int channel) +{ + int uniqueStamp = (channel>>16)&0xffff; + channel &= 0xffff; + assert(channel >= 0 && channel < MAXPARTICULE*MAXPARTITYPE); + + if (!m_particle[channel].used) return false; + if (m_particle[channel].uniqueStamp != uniqueStamp) return false; return true; } @@ -685,7 +684,7 @@ void CParticle::DeleteParticle(ParticleType type) void CParticle::DeleteParticle(int channel) { - if (!CheckChannel(channel)) return; + GetRankFromChannel(channel); if (m_totalInterface[channel/MAXPARTICULE][m_particle[channel].sheet] > 0 ) m_totalInterface[channel/MAXPARTICULE][m_particle[channel].sheet]--; @@ -699,50 +698,50 @@ void CParticle::DeleteParticle(int channel) void CParticle::SetObjectLink(int channel, CObject *object) { - if (!CheckChannel(channel)) return; + GetRankFromChannel(channel); m_particle[channel].objLink = object; } void CParticle::SetObjectFather(int channel, CObject *object) { - if (!CheckChannel(channel)) return; + GetRankFromChannel(channel); m_particle[channel].objFather = object; } void CParticle::SetPosition(int channel, Math::Vector pos) { - if (!CheckChannel(channel)) return; + GetRankFromChannel(channel); m_particle[channel].pos = pos; } void CParticle::SetDimension(int channel, Math::Point dim) { - if (!CheckChannel(channel)) return; + GetRankFromChannel(channel); m_particle[channel].dim = dim; } void CParticle::SetZoom(int channel, float zoom) { - if (!CheckChannel(channel)) return; + GetRankFromChannel(channel); m_particle[channel].zoom = zoom; } void CParticle::SetAngle(int channel, float angle) { - if (!CheckChannel(channel)) return; + GetRankFromChannel(channel); m_particle[channel].angle = angle; } void CParticle::SetIntensity(int channel, float intensity) { - if (!CheckChannel(channel)) return; + GetRankFromChannel(channel); m_particle[channel].intensity = intensity; } void CParticle::SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom, float angle, float intensity) { - if (!CheckChannel(channel)) return; + GetRankFromChannel(channel); m_particle[channel].pos = pos; m_particle[channel].dim = dim; m_particle[channel].zoom = zoom; @@ -752,17 +751,16 @@ void CParticle::SetParam(int channel, Math::Vector pos, Math::Point dim, float z void CParticle::SetPhase(int channel, ParticlePhase phase, float duration) { - if (!CheckChannel(channel)) return; + GetRankFromChannel(channel); m_particle[channel].phase = phase; m_particle[channel].duration = duration; m_particle[channel].phaseTime = m_particle[channel].time; } -bool CParticle::GetPosition(int channel, Math::Vector &pos) +Math::Vector CParticle::GetPosition(int channel) { - if (!CheckChannel(channel)) return false; - pos = m_particle[channel].pos; - return true; + GetRankFromChannel(channel); + return m_particle[channel].pos; } void CParticle::SetFrameUpdate(int sheet, bool update) diff --git a/src/graphics/engine/particle.h b/src/graphics/engine/particle.h index 5279009a..55ef7baa 100644 --- a/src/graphics/engine/particle.h +++ b/src/graphics/engine/particle.h @@ -162,9 +162,9 @@ enum ParticlePhase struct Particle { - bool used = false; // TRUE -> particle used + bool used = false; //!< true if this channel is used, false if not bool ray = false; // TRUE -> ray with goal - unsigned short uniqueStamp = 0; // unique mark + unsigned short uniqueStamp = 0; //!< unique marker added to particle channel ID to make sure this is still the same particle short sheet = 0; // sheet (0..n) ParticleType type = {}; // type PARTI* ParticlePhase phase = {}; // phase PARPH* @@ -279,7 +279,7 @@ public: void SetPhase(int channel, ParticlePhase phase, float duration); //! Returns the position of the particle - bool GetPosition(int channel, Math::Vector &pos); + Math::Vector GetPosition(int channel); //! Returns the color if you're in the fog or black if you're not Color GetFogColor(Math::Vector pos); @@ -291,11 +291,14 @@ public: //! Draws all the particles void DrawParticle(int sheet); + //! Checks if given particle channel still exists + bool ParticleExists(int channel); + protected: //! Removes a particle of given rank void DeleteRank(int rank); - //! Check a channel number - bool CheckChannel(int &channel); + //! Adapts the channel so it can be used as an offset in m_particle + void GetRankFromChannel(int &channel); //! Draws a triangular particle void DrawParticleTriangle(int i); //! Draw a normal particle diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index cfc2e11b..7c2682d8 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -2187,15 +2187,17 @@ void COldObject::PartiFrame(float rTime) channel = m_objectPart[i].masterParti; if ( channel == -1 ) continue; - if ( !m_particle->GetPosition(channel, pos) ) + if ( !m_particle->ParticleExists(channel) ) { m_objectPart[i].masterParti = -1; // particle no longer exists! continue; } + pos = m_particle->GetPosition(channel); + SetPartPosition(i, pos); - // Each song spins differently. + // Each part rotates differently switch( i%5 ) { case 0: factor = Math::Vector( 0.5f, 0.3f, 0.6f); break; diff --git a/src/object/old_object.h b/src/object/old_object.h index 44a49e2d..5ba5c7eb 100644 --- a/src/object/old_object.h +++ b/src/object/old_object.h @@ -55,9 +55,9 @@ const int OBJECTMAXPART = 40; struct ObjectPart { bool bUsed = false; - int object = -1; // number of the object in CEngine - int parentPart = -1; // number of father part - int masterParti = -1; // master canal of the particle + int object = -1; //!< identifier of the object in Gfx::CEngine + int parentPart = -1; //!< identifier of parent part + int masterParti = -1; //!< particle channel this part is connected to after explosion Math::Vector position; Math::Vector angle; Math::Vector zoom; From aa159bc9b07d7f0dd776ec5a5a398f5e40a12c71 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 May 2016 00:43:14 +0200 Subject: [PATCH 079/125] Don't scale mouse cursor with resolution --- src/graphics/engine/engine.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 5e773dc6..d8666731 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -177,7 +177,7 @@ CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils) m_mice[ENG_MOUSE_SCROLLU] = EngineMouse(28, 29, 45, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 9.0f, 2.0f)); m_mice[ENG_MOUSE_SCROLLD] = EngineMouse(30, 31, 46, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 9.0f, 17.0f)); - m_mouseSize = Math::Point(0.04f, 0.04f * (800.0f / 600.0f)); + m_mouseSize = Math::Point(48.f/m_size.x, 48.f/m_size.x * (800.f/600.f)); m_mouseType = ENG_MOUSE_NORM; m_fpsCounter = 0; @@ -280,7 +280,7 @@ void CEngine::SetTerrain(CTerrain* terrain) bool CEngine::Create() { m_size = m_app->GetVideoConfig().size; - m_mouseSize = Math::Point(0.04f, 0.04f * (static_cast(m_size.x) / static_cast(m_size.y))); + m_mouseSize = Math::Point(48.f/m_size.x, 48.f/m_size.x * (static_cast(m_size.x) / static_cast(m_size.y))); // Use the setters to set defaults, because they automatically disable what is not supported SetShadowMapping(m_shadowMapping); @@ -359,7 +359,7 @@ void CEngine::Destroy() void CEngine::ResetAfterVideoConfigChanged() { m_size = m_app->GetVideoConfig().size; - m_mouseSize = Math::Point(0.04f, 0.04f * (static_cast(m_size.x) / static_cast(m_size.y))); + m_mouseSize = Math::Point(48.f/m_size.x, 48.f/m_size.x * (static_cast(m_size.x) / static_cast(m_size.y))); // Update the camera projection matrix for new aspect ratio ApplyChange(); From 2bebd0e87fafc382471d5a2cdc2f7d775c80ae6f Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 May 2016 10:46:26 +0200 Subject: [PATCH 080/125] Jenkinsfile: don't add runtime information on install in linux builds --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index a0431a69..9ec312b2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -23,7 +23,7 @@ node('master') { dir('build/linux') { sh ''' cmake \ - -DCMAKE_INSTALL_PREFIX=/install -DCOLOBOT_INSTALL_BIN_DIR=/install -DCOLOBOT_INSTALL_LIB_DIR=/install -DCOLOBOT_INSTALL_DATA_DIR=/install/data -DCOLOBOT_INSTALL_I18N_DIR=/install/lang \ + -DCMAKE_INSTALL_PREFIX=/install -DCOLOBOT_INSTALL_BIN_DIR=/install -DCOLOBOT_INSTALL_LIB_DIR=/install -DCOLOBOT_INSTALL_DATA_DIR=/install/data -DCOLOBOT_INSTALL_I18N_DIR=/install/lang -DCMAKE_SKIP_INSTALL_RPATH=ON \ -DBOOST_STATIC=ON -DGLEW_STATIC=ON -DGLEW_LIBRARY=/usr/lib64/libGLEW.a \ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDEV_BUILD=1 -DPORTABLE=1 -DTOOLS=1 -DTESTS=1 -DDESKTOP=0 ../.. make From 9feea63086d61ea57a25c36f13eff534ba3841b8 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 May 2016 11:09:12 +0200 Subject: [PATCH 081/125] Jenkinsfile: change RPATH to current directory --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 9ec312b2..926f4e2e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,6 +29,7 @@ node('master') { make rm -rf install DESTDIR=. make install + patchelf --set-rpath '.' install/colobot ''' } sh 'rm -f linux-debug.zip' From 942f746a21608f44f068ac92a777ccce4d1f2b3f Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 May 2016 12:50:32 +0200 Subject: [PATCH 082/125] Removed CAM_TYPE_DIALOG --- src/app/pausemanager.h | 1 + src/graphics/engine/camera.cpp | 16 ++++++++-------- src/graphics/engine/camera.h | 10 ++++++---- src/level/robotmain.cpp | 12 ++++-------- src/level/robotmain.h | 1 - src/ui/mainui.cpp | 2 +- 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/app/pausemanager.h b/src/app/pausemanager.h index 478d1156..d76baf87 100644 --- a/src/app/pausemanager.h +++ b/src/app/pausemanager.h @@ -40,6 +40,7 @@ enum PauseType PAUSE_PHOTO = (1<<2), //!< photo mode, TODO: remove PAUSE_OBJECT_UPDATES = (1<<3), //!< do not send events to objects PAUSE_MUTE_SOUND = (1<<4), //!< mute sound + PAUSE_CAMERA = (1<<5), //!< freeze camera }; inline PauseType& operator|=(PauseType& a, const PauseType& b) { diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index e0cfaa79..96c4f00d 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -1163,6 +1163,9 @@ void CCamera::EventMouseButton(const Event &event) bool CCamera::EventFrame(const Event &event) { + if (m_freeze) + return true; + Math::Point newDelta = m_mouseDeltaEdge * m_speed * event.rTime; if (m_cameraInvertX) newDelta.x = -newDelta.x; @@ -1177,9 +1180,6 @@ bool CCamera::EventFrame(const Event &event) m_type == CAM_TYPE_EDIT) return EventFrameFree(event, m_type != CAM_TYPE_EDIT); - if (m_type == CAM_TYPE_DIALOG) - return EventFrameDialog(event); - if (m_type == CAM_TYPE_BACK) return EventFrameBack(event); @@ -1262,11 +1262,6 @@ bool CCamera::EventFrameFree(const Event &event, bool keysAllowed) return true; } -bool CCamera::EventFrameDialog(const Event &event) -{ - return true; -} - bool CCamera::EventFrameBack(const Event &event) { Math::Vector cameraMove = CalculateCameraMovement(event); @@ -1625,4 +1620,9 @@ Math::Vector CCamera::CalculateCameraMovement(const Event &event, bool keysAllow return delta; } +void CCamera::SetFreeze(bool freeze) +{ + m_freeze = freeze; +} + } diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index 8d7386f5..ff4d62e7 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -63,8 +63,6 @@ enum CameraType CAM_TYPE_INFO = 8, //! Visit instead of an error CAM_TYPE_VISIT = 9, - //! Camera for dialog - CAM_TYPE_DIALOG = 10, //! Static camera height CAM_TYPE_PLANE = 11, }; @@ -211,6 +209,9 @@ public: void SetCameraInvertY(bool invert); bool GetCameraInvertY(); + //! Temporarily freeze camera movement + void SetFreeze(bool freeze); + void SetCameraSpeed(float speed); protected: @@ -225,8 +226,6 @@ protected: //! Moves the point of view bool EventFrameFree(const Event &event, bool keysAllowed); //! Moves the point of view - bool EventFrameDialog(const Event &event); - //! Moves the point of view bool EventFrameBack(const Event &event); //! Moves the point of view bool EventFrameFix(const Event &event); @@ -389,6 +388,9 @@ protected: bool m_cameraInvertX; //! Y inversion in the edges? bool m_cameraInvertY; + + //! Is camera frozen? + bool m_freeze = false; }; diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 2990ceb4..9abd54a2 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -456,7 +456,7 @@ void CRobotMain::ChangePhase(Phase phase) FlushNewScriptName(); m_sound->SetListener(Math::Vector(0.0f, 0.0f, 0.0f), Math::Vector(0.0f, 0.0f, 1.0f)); m_sound->StopAll(); - m_camera->SetType(Gfx::CAM_TYPE_DIALOG); + m_camera->SetType(Gfx::CAM_TYPE_NULL); m_movie->Flush(); m_movieInfoIndex = -1; m_cameraPan = 0.0f; @@ -1589,7 +1589,7 @@ void CRobotMain::StartSuspend() { m_sound->MuteAll(true); ClearInterface(); - m_suspend = m_pause->ActivatePause(PAUSE_ENGINE|PAUSE_HIDE_SHORTCUTS|PAUSE_MUTE_SOUND); + m_suspend = m_pause->ActivatePause(PAUSE_ENGINE|PAUSE_HIDE_SHORTCUTS|PAUSE_MUTE_SOUND|PAUSE_CAMERA); m_engine->SetOverFront(false); // over flat behind CreateShortcuts(); @@ -1597,9 +1597,6 @@ void CRobotMain::StartSuspend() m_infoObject = DeselectAll(); // removes the control buttons m_displayText->HideText(true); - m_suspendInitCamera = m_camera->GetType(); - m_camera->SetType(Gfx::CAM_TYPE_DIALOG); - m_engine->EnablePauseBlur(); } @@ -1618,8 +1615,6 @@ void CRobotMain::StopSuspend() m_map->ShowMap(m_mapShow); m_displayText->HideText(false); - m_camera->SetType(m_suspendInitCamera); - m_engine->DisablePauseBlur(); } @@ -4975,7 +4970,7 @@ void CRobotMain::ResetCreate() m_particle->FlushParticle(); m_terrain->FlushBuildingLevel(); - m_camera->SetType(Gfx::CAM_TYPE_DIALOG); + m_camera->SetType(Gfx::CAM_TYPE_NULL); try { @@ -5500,6 +5495,7 @@ void CRobotMain::StartMusic() void CRobotMain::UpdatePause(PauseType pause) { m_engine->SetPause(pause & PAUSE_ENGINE); + m_camera->SetFreeze(pause & PAUSE_CAMERA); m_sound->MuteAll(pause & PAUSE_MUTE_SOUND); CreateShortcuts(); if (pause != PAUSE_NONE) HiliteClear(); diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 505b5b9a..8c6b53e0 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -506,7 +506,6 @@ protected: char m_mapFilename[100] = {}; ActivePause* m_suspend = nullptr; - Gfx::CameraType m_suspendInitCamera = Gfx::CAM_TYPE_NULL; Math::Point m_tooltipPos; std::string m_tooltipName; diff --git a/src/ui/mainui.cpp b/src/ui/mainui.cpp index 2a60dae6..f373d692 100644 --- a/src/ui/mainui.cpp +++ b/src/ui/mainui.cpp @@ -148,7 +148,7 @@ CScreenSetup* CMainUserInterface::GetSetupScreen(Phase phase) void CMainUserInterface::ChangePhase(Phase phase) { - m_main->GetCamera()->SetType(Gfx::CAM_TYPE_DIALOG); + m_main->GetCamera()->SetType(Gfx::CAM_TYPE_NULL); m_engine->SetOverFront(false); m_engine->SetOverColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::ENG_RSTATE_TCOLOR_BLACK); // TODO: color ok? From ebc2e6e26cc13ac2dd347257710c9049f15b17be Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 May 2016 13:50:41 +0200 Subject: [PATCH 083/125] Added camera joystick bindings (#653) --- src/app/input.cpp | 27 +++- src/app/input.h | 2 + src/common/event.cpp | 8 +- src/common/event.h | 38 +++-- src/common/key.h | 3 + src/common/restext.cpp | 3 + src/graphics/engine/camera.cpp | 2 + src/ui/screen/screen_setup_controls.cpp | 193 +++++++++--------------- 8 files changed, 140 insertions(+), 136 deletions(-) diff --git a/src/app/input.cpp b/src/app/input.cpp index 0a049157..62bad06f 100644 --- a/src/app/input.cpp +++ b/src/app/input.cpp @@ -170,10 +170,31 @@ void CInput::EventProcess(Event& event) if (GetJoyAxisBinding(JOY_AXIS_SLOT_Z).invert) m_joyMotion.z *= -1.0f; } + + if (data->axis == GetJoyAxisBinding(JOY_AXIS_SLOT_CAM_X).axis) + { + m_joyMotionCam.x = -Math::Neutral(data->value / 32768.0f, m_joystickDeadzone); + if (GetJoyAxisBinding(JOY_AXIS_SLOT_CAM_X).invert) + m_joyMotionCam.x *= -1.0f; + } + + if (data->axis == GetJoyAxisBinding(JOY_AXIS_SLOT_CAM_Y).axis) + { + m_joyMotionCam.y = -Math::Neutral(data->value / 32768.0f, m_joystickDeadzone); + if (GetJoyAxisBinding(JOY_AXIS_SLOT_CAM_Y).invert) + m_joyMotionCam.y *= -1.0f; + } + + if (data->axis == GetJoyAxisBinding(JOY_AXIS_SLOT_CAM_Z).axis) + { + m_joyMotionCam.z = -Math::Neutral(data->value / 32768.0f, m_joystickDeadzone); + if (GetJoyAxisBinding(JOY_AXIS_SLOT_CAM_Z).invert) + m_joyMotionCam.z *= -1.0f; + } } event.motionInput = Math::Clamp(m_joyMotion + m_keyMotion, Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector(1.0f, 1.0f, 1.0f)); - event.cameraInput = m_cameraKeyMotion; + event.cameraInput = Math::Clamp(m_joyMotionCam + m_cameraKeyMotion, Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector(1.0f, 1.0f, 1.0f)); } void CInput::MouseMove(Math::IntPoint pos) @@ -197,6 +218,7 @@ void CInput::ResetKeyStates() m_keyMotion = Math::Vector(0.0f, 0.0f, 0.0f); m_joyMotion = Math::Vector(0.0f, 0.0f, 0.0f); m_cameraKeyMotion = Math::Vector(0.0f, 0.0f, 0.0f); + m_joyMotionCam = Math::Vector(0.0f, 0.0f, 0.0f); for(int i=0; iGetKeyState(INPUT_SLOT_NEAR)) diff --git a/src/ui/screen/screen_setup_controls.cpp b/src/ui/screen/screen_setup_controls.cpp index bdb2c5c8..7aa39ebe 100644 --- a/src/ui/screen/screen_setup_controls.cpp +++ b/src/ui/screen/screen_setup_controls.cpp @@ -103,63 +103,40 @@ void CScreenSetupControls::CreateInterface() ddim.x = 160.0f/640.0f; ddim.y = 80.0f/480.0f; pos.x = 400.0f/640.0f; - pos.y = 213.0f/480.0f; + pos.y = 273.0f/480.0f; pli = pw->CreateList(pos, ddim, 0, EVENT_INTERFACE_JOYSTICK); pli->SetState(STATE_SHADOW); ddim.x = dim.x*1.5f; ddim.y = 18.0f/480.0f; - pos.y = 180.0f/480.0f; + pos.y = 240.0f/480.0f; - pos.y -= 5.0f/480.0f; - pos.x = 390.0f/640.0f; - pw->CreateLabel(pos, ddim, 0, EVENT_LABEL0, "X:"); - pos.y += 5.0f/480.0f; - pos.x = 422.0f/640.0f; - pev = pw->CreateEditValue(pos, ddim, 0, EVENT_INTERFACE_JOYSTICK_X); - pev->SetState(STATE_SHADOW); - pev->SetType(EVT_INT); - pev->SetMinValue(0); - pev->SetMaxValue(2); - pev->SetStepValue(1); - pev->SetValue(0); - pos.x = 480.0f/640.0f; - pc = pw->CreateCheck(pos, ddim, 0, EVENT_INTERFACE_JOYSTICK_X_INVERT); - pc->SetState(STATE_SHADOW); - - pos.y -= 20.0f/480.0f; - pos.x = 390.0f/640.0f; - pos.y -= 5.0f/480.0f; - pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, "Y:"); - pos.y += 5.0f/480.0f; - pos.x = 422.0f/640.0f; - pev = pw->CreateEditValue(pos, ddim, 0, EVENT_INTERFACE_JOYSTICK_Y); - pev->SetState(STATE_SHADOW); - pev->SetType(EVT_INT); - pev->SetMinValue(0); - pev->SetMaxValue(2); - pev->SetStepValue(1); - pev->SetValue(1); - pos.x = 480.0f/640.0f; - pc = pw->CreateCheck(pos, ddim, 0, EVENT_INTERFACE_JOYSTICK_Y_INVERT); - pc->SetState(STATE_SHADOW); - - pos.y -= 20.0f/480.0f; - pos.x = 390.0f/640.0f; - pos.y -= 5.0f/480.0f; - pw->CreateLabel(pos, ddim, 0, EVENT_LABEL2, "Z:"); - pos.y += 5.0f/480.0f; - pos.x = 422.0f/640.0f; - pev = pw->CreateEditValue(pos, ddim, 0, EVENT_INTERFACE_JOYSTICK_Z); - pev->SetState(STATE_SHADOW); - pev->SetType(EVT_INT); - pev->SetMinValue(0); - pev->SetMaxValue(2); - pev->SetStepValue(1); - pev->SetValue(2); - pos.x = 480.0f/640.0f; - pc = pw->CreateCheck(pos, ddim, 0, EVENT_INTERFACE_JOYSTICK_Z_INVERT); - pc->SetState(STATE_SHADOW); + auto CreateJoystickControls = [&](const std::string& label, EventType bindingControl, EventType invertControl) + { + pos.y -= 20.0f/480.0f; + pos.x = 390.0f/640.0f; + pos.y -= 5.0f/480.0f; + pw->CreateLabel(pos, ddim, 0, EVENT_LABEL0, label); + pos.y += 5.0f/480.0f; + pos.x = 442.0f/640.0f; + pev = pw->CreateEditValue(pos, ddim, 0, bindingControl); + pev->SetState(STATE_SHADOW); + pev->SetType(EVT_INT); + pev->SetMinValue(-1); + pev->SetMaxValue(2); + pev->SetStepValue(1); + pev->SetValue(1); + pos.x = 500.0f/640.0f; + pc = pw->CreateCheck(pos, ddim, 0, invertControl); + pc->SetState(STATE_SHADOW); + }; + pos.y += 15.0f/480.0f; + CreateJoystickControls("X:", EVENT_INTERFACE_JOYSTICK_X, EVENT_INTERFACE_JOYSTICK_X_INVERT); + CreateJoystickControls("Y:", EVENT_INTERFACE_JOYSTICK_Y, EVENT_INTERFACE_JOYSTICK_Y_INVERT); + CreateJoystickControls("Z:", EVENT_INTERFACE_JOYSTICK_Z, EVENT_INTERFACE_JOYSTICK_Z_INVERT); + CreateJoystickControls("CamX:", EVENT_INTERFACE_JOYSTICK_CAM_X, EVENT_INTERFACE_JOYSTICK_CAM_X_INVERT); + CreateJoystickControls("CamY:", EVENT_INTERFACE_JOYSTICK_CAM_Y, EVENT_INTERFACE_JOYSTICK_CAM_Y_INVERT); + CreateJoystickControls("CamZ:", EVENT_INTERFACE_JOYSTICK_CAM_Z, EVENT_INTERFACE_JOYSTICK_CAM_Z_INVERT); pos.y -= 25.0f/480.0f; pos.x = 420.0f/640.0f; @@ -203,6 +180,9 @@ bool CScreenSetupControls::EventProcess(const Event &event) case EVENT_INTERFACE_JOYSTICK_X_INVERT: case EVENT_INTERFACE_JOYSTICK_Y_INVERT: case EVENT_INTERFACE_JOYSTICK_Z_INVERT: + case EVENT_INTERFACE_JOYSTICK_CAM_X_INVERT: + case EVENT_INTERFACE_JOYSTICK_CAM_Y_INVERT: + case EVENT_INTERFACE_JOYSTICK_CAM_Z_INVERT: ToggleJoystickInvert(event.type); ChangeSetupButtons(); UpdateSetupButtons(); @@ -212,6 +192,9 @@ bool CScreenSetupControls::EventProcess(const Event &event) case EVENT_INTERFACE_JOYSTICK_X: case EVENT_INTERFACE_JOYSTICK_Y: case EVENT_INTERFACE_JOYSTICK_Z: + case EVENT_INTERFACE_JOYSTICK_CAM_X: + case EVENT_INTERFACE_JOYSTICK_CAM_Y: + case EVENT_INTERFACE_JOYSTICK_CAM_Z: case EVENT_INTERFACE_JOYSTICK_DEADZONE: ChangeSetupButtons(); UpdateSetupButtons(); @@ -254,42 +237,28 @@ void CScreenSetupControls::ChangeSetupButtons() } } - if (nullptr != (pev = static_cast(pw->SearchControl(EVENT_INTERFACE_JOYSTICK_X)))) + auto HandleJoystickControls = [&](JoyAxisSlot joyAxis, EventType bindingControl, EventType invertControl) { - JoyAxisBinding binding = m_input->GetJoyAxisBinding(JOY_AXIS_SLOT_X); - binding.axis = static_cast(round(pev->GetValue())); - m_input->SetJoyAxisBinding(JOY_AXIS_SLOT_X, binding); - } - if (nullptr != (pc = static_cast(pw->SearchControl(EVENT_INTERFACE_JOYSTICK_X_INVERT)))) - { - JoyAxisBinding binding = m_input->GetJoyAxisBinding(JOY_AXIS_SLOT_X); - binding.invert = pc->TestState(STATE_CHECK); - m_input->SetJoyAxisBinding(JOY_AXIS_SLOT_X, binding); - } - if (nullptr != (pev = static_cast(pw->SearchControl(EVENT_INTERFACE_JOYSTICK_Y)))) - { - JoyAxisBinding binding = m_input->GetJoyAxisBinding(JOY_AXIS_SLOT_Y); - binding.axis = static_cast(round(pev->GetValue())); - m_input->SetJoyAxisBinding(JOY_AXIS_SLOT_Y, binding); - } - if (nullptr != (pc = static_cast(pw->SearchControl(EVENT_INTERFACE_JOYSTICK_Y_INVERT)))) - { - JoyAxisBinding binding = m_input->GetJoyAxisBinding(JOY_AXIS_SLOT_Y); - binding.invert = pc->TestState(STATE_CHECK); - m_input->SetJoyAxisBinding(JOY_AXIS_SLOT_Y, binding); - } - if (nullptr != (pev = static_cast(pw->SearchControl(EVENT_INTERFACE_JOYSTICK_Z)))) - { - JoyAxisBinding binding = m_input->GetJoyAxisBinding(JOY_AXIS_SLOT_Z); - binding.axis = static_cast(round(pev->GetValue())); - m_input->SetJoyAxisBinding(JOY_AXIS_SLOT_Z, binding); - } - if (nullptr != (pc = static_cast(pw->SearchControl(EVENT_INTERFACE_JOYSTICK_Z_INVERT)))) - { - JoyAxisBinding binding = m_input->GetJoyAxisBinding(JOY_AXIS_SLOT_Z); - binding.invert = pc->TestState(STATE_CHECK); - m_input->SetJoyAxisBinding(JOY_AXIS_SLOT_Z, binding); - } + if (nullptr != (pev = static_cast(pw->SearchControl(bindingControl)))) + { + JoyAxisBinding binding = m_input->GetJoyAxisBinding(joyAxis); + binding.axis = static_cast(round(pev->GetValue())); + m_input->SetJoyAxisBinding(joyAxis, binding); + } + if (nullptr != (pc = static_cast(pw->SearchControl(invertControl)))) + { + JoyAxisBinding binding = m_input->GetJoyAxisBinding(joyAxis); + binding.invert = pc->TestState(STATE_CHECK); + m_input->SetJoyAxisBinding(joyAxis, binding); + } + }; + HandleJoystickControls(JOY_AXIS_SLOT_X, EVENT_INTERFACE_JOYSTICK_X, EVENT_INTERFACE_JOYSTICK_X_INVERT); + HandleJoystickControls(JOY_AXIS_SLOT_Y, EVENT_INTERFACE_JOYSTICK_Y, EVENT_INTERFACE_JOYSTICK_Y_INVERT); + HandleJoystickControls(JOY_AXIS_SLOT_Z, EVENT_INTERFACE_JOYSTICK_Z, EVENT_INTERFACE_JOYSTICK_Z_INVERT); + HandleJoystickControls(JOY_AXIS_SLOT_CAM_X, EVENT_INTERFACE_JOYSTICK_CAM_X, EVENT_INTERFACE_JOYSTICK_CAM_X_INVERT); + HandleJoystickControls(JOY_AXIS_SLOT_CAM_Y, EVENT_INTERFACE_JOYSTICK_CAM_Y, EVENT_INTERFACE_JOYSTICK_CAM_Y_INVERT); + HandleJoystickControls(JOY_AXIS_SLOT_CAM_Z, EVENT_INTERFACE_JOYSTICK_CAM_Z, EVENT_INTERFACE_JOYSTICK_CAM_Z_INVERT); + if (nullptr != (pev = static_cast(pw->SearchControl(EVENT_INTERFACE_JOYSTICK_DEADZONE)))) { m_input->SetJoystickDeadzone(pev->GetValue()); @@ -332,39 +301,27 @@ void CScreenSetupControls::UpdateSetupButtons() pli->SetSelect(m_app->GetJoystickEnabled() ? m_app->GetJoystick().index + 1 : 0); } - if (nullptr != (pev = static_cast(pw->SearchControl(EVENT_INTERFACE_JOYSTICK_X)))) + auto HandleJoystickControls = [&](JoyAxisSlot joyAxis, EventType bindingControl, EventType invertControl) { - pev->SetState(STATE_ENABLE, m_app->GetJoystickEnabled()); - pev->SetMaxValue(m_app->GetJoystick().axisCount-1); - pev->SetValue(m_input->GetJoyAxisBinding(JOY_AXIS_SLOT_X).axis); - } - if (nullptr != (pc = static_cast(pw->SearchControl(EVENT_INTERFACE_JOYSTICK_X_INVERT)))) - { - pc->SetState(STATE_ENABLE, m_app->GetJoystickEnabled()); - pc->SetState(STATE_CHECK, m_input->GetJoyAxisBinding(JOY_AXIS_SLOT_X).invert); - } - if (nullptr != (pev = static_cast(pw->SearchControl(EVENT_INTERFACE_JOYSTICK_Y)))) - { - pev->SetState(STATE_ENABLE, m_app->GetJoystickEnabled()); - pev->SetMaxValue(m_app->GetJoystick().axisCount-1); - pev->SetValue(m_input->GetJoyAxisBinding(JOY_AXIS_SLOT_Y).axis); - } - if (nullptr != (pc = static_cast(pw->SearchControl(EVENT_INTERFACE_JOYSTICK_Y_INVERT)))) - { - pc->SetState(STATE_ENABLE, m_app->GetJoystickEnabled()); - pc->SetState(STATE_CHECK, m_input->GetJoyAxisBinding(JOY_AXIS_SLOT_Y).invert); - } - if (nullptr != (pev = static_cast(pw->SearchControl(EVENT_INTERFACE_JOYSTICK_Z)))) - { - pev->SetState(STATE_ENABLE, m_app->GetJoystickEnabled()); - pev->SetMaxValue(m_app->GetJoystick().axisCount-1); - pev->SetValue(m_input->GetJoyAxisBinding(JOY_AXIS_SLOT_Z).axis); - } - if (nullptr != (pc = static_cast(pw->SearchControl(EVENT_INTERFACE_JOYSTICK_Z_INVERT)))) - { - pc->SetState(STATE_ENABLE, m_app->GetJoystickEnabled()); - pc->SetState(STATE_CHECK, m_input->GetJoyAxisBinding(JOY_AXIS_SLOT_Z).invert); - } + if (nullptr != (pev = static_cast(pw->SearchControl(bindingControl)))) + { + pev->SetState(STATE_ENABLE, m_app->GetJoystickEnabled()); + pev->SetMaxValue(m_app->GetJoystick().axisCount-1); + pev->SetValue(m_input->GetJoyAxisBinding(joyAxis).axis); + } + if (nullptr != (pc = static_cast(pw->SearchControl(invertControl)))) + { + pc->SetState(STATE_ENABLE, m_app->GetJoystickEnabled()); + pc->SetState(STATE_CHECK, m_input->GetJoyAxisBinding(joyAxis).invert); + } + }; + HandleJoystickControls(JOY_AXIS_SLOT_X, EVENT_INTERFACE_JOYSTICK_X, EVENT_INTERFACE_JOYSTICK_X_INVERT); + HandleJoystickControls(JOY_AXIS_SLOT_Y, EVENT_INTERFACE_JOYSTICK_Y, EVENT_INTERFACE_JOYSTICK_Y_INVERT); + HandleJoystickControls(JOY_AXIS_SLOT_Z, EVENT_INTERFACE_JOYSTICK_Z, EVENT_INTERFACE_JOYSTICK_Z_INVERT); + HandleJoystickControls(JOY_AXIS_SLOT_CAM_X, EVENT_INTERFACE_JOYSTICK_CAM_X, EVENT_INTERFACE_JOYSTICK_CAM_X_INVERT); + HandleJoystickControls(JOY_AXIS_SLOT_CAM_Y, EVENT_INTERFACE_JOYSTICK_CAM_Y, EVENT_INTERFACE_JOYSTICK_CAM_Y_INVERT); + HandleJoystickControls(JOY_AXIS_SLOT_CAM_Z, EVENT_INTERFACE_JOYSTICK_CAM_Z, EVENT_INTERFACE_JOYSTICK_CAM_Z_INVERT); + if (nullptr != (pev = static_cast(pw->SearchControl(EVENT_INTERFACE_JOYSTICK_DEADZONE)))) { pev->SetState(STATE_ENABLE, m_app->GetJoystickEnabled()); From 2dd7ba7e9b36ec87f5612470fab121045673fb17 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 May 2016 15:40:54 +0200 Subject: [PATCH 084/125] Added camera keybindings (#653) --- po/colobot.pot | 15 ++++++++++++ po/de.po | 19 +++++++++++++++ po/fr.po | 19 +++++++++++++++ po/pl.po | 15 ++++++++++++ po/ru.po | 19 +++++++++++++++ src/app/input.cpp | 42 ++++++++++++++++++++++------------ src/common/key.h | 9 ++++++-- src/common/restext.cpp | 9 ++++++-- src/graphics/engine/camera.cpp | 7 +----- 9 files changed, 130 insertions(+), 24 deletions(-) diff --git a/po/colobot.pot b/po/colobot.pot index 08625b6f..1b624494 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -461,12 +461,27 @@ msgstr "" msgid "Standard action\\Standard action of the bot (take/grab, shoot, sniff, etc)" msgstr "" +msgid "Camera left\\Turns the camera left" +msgstr "" + +msgid "Camera right\\Turns the camera right" +msgstr "" + +msgid "Camera up\\Turns the camera up" +msgstr "" + +msgid "Camera down\\Turns the camera down" +msgstr "" + msgid "Camera closer\\Moves the camera forward" msgstr "" msgid "Camera back\\Moves the camera backward" msgstr "" +msgid "Alternative camera mode\\Move sideways instead of rotating (in free camera)" +msgstr "" + msgid "Next object\\Selects the next object" msgstr "" diff --git a/po/de.po b/po/de.po index c49e5cf0..453d1520 100644 --- a/po/de.po +++ b/po/de.po @@ -115,6 +115,9 @@ msgstr "Insektenkönigin tödlich verwundet" msgid "Already carrying something" msgstr "Trägt schon etwas" +msgid "Alternative camera mode\\Move sideways instead of rotating (in free camera)" +msgstr "" + msgid "Analysis already performed" msgstr "Analyse schon durchgeführt" @@ -330,15 +333,31 @@ msgstr "Kameradrehung mit der Maus\\Die Kamera dreht wenn die Maus den Rand erre msgid "Camera closer\\Moves the camera forward" msgstr "Kamera näher\\Bewegung der Kamera vorwärts" +#, fuzzy +msgid "Camera down\\Turns the camera down" +msgstr "Kamera näher\\Bewegung der Kamera vorwärts" + +#, fuzzy +msgid "Camera left\\Turns the camera left" +msgstr "Kamera näher\\Bewegung der Kamera vorwärts" + msgid "Camera nearest" msgstr "Kamera näher" +#, fuzzy +msgid "Camera right\\Turns the camera right" +msgstr "Drehung nach rechts\\Steuer rechts" + msgid "Camera to left" msgstr "Kamera links" msgid "Camera to right" msgstr "Kamera rechts" +#, fuzzy +msgid "Camera up\\Turns the camera up" +msgstr "Kamera (\\key camera;)" + msgid "Can not produce not researched object" msgstr "Das erforschte Objekt kann nicht produziert werden" diff --git a/po/fr.po b/po/fr.po index 880f1d02..4d919748 100644 --- a/po/fr.po +++ b/po/fr.po @@ -108,6 +108,9 @@ msgstr "Pondeuse mortellement touchée" msgid "Already carrying something" msgstr "Porte déjà quelque chose" +msgid "Alternative camera mode\\Move sideways instead of rotating (in free camera)" +msgstr "" + msgid "Analysis already performed" msgstr "Analyse déjà effectuée" @@ -321,15 +324,31 @@ msgstr "Défilement dans les bords\\Défilement lorsque la souris touche les bor msgid "Camera closer\\Moves the camera forward" msgstr "Caméra plus proche\\Avance la caméra" +#, fuzzy +msgid "Camera down\\Turns the camera down" +msgstr "Caméra plus proche\\Avance la caméra" + +#, fuzzy +msgid "Camera left\\Turns the camera left" +msgstr "Caméra plus proche\\Avance la caméra" + msgid "Camera nearest" msgstr "Caméra plus proche" +#, fuzzy +msgid "Camera right\\Turns the camera right" +msgstr "Tourner à droite\\Moteur à droite" + msgid "Camera to left" msgstr "Caméra à gauche" msgid "Camera to right" msgstr "Caméra à droite" +#, fuzzy +msgid "Camera up\\Turns the camera up" +msgstr "Caméra (\\key camera;)" + msgid "Can not produce not researched object" msgstr "Impossible de créer un objet n'ayant pas été recherché" diff --git a/po/pl.po b/po/pl.po index 67967286..68cd35a2 100644 --- a/po/pl.po +++ b/po/pl.po @@ -111,6 +111,9 @@ msgstr "Królowa Obcych została zabita" msgid "Already carrying something" msgstr "Nie można nieść więcej przedmiotów" +msgid "Alternative camera mode\\Move sideways instead of rotating (in free camera)" +msgstr "Alternatywny tryb kamery\\Poruszaj na boki zamiast obracać (w kamerze swobodnej)" + msgid "Analysis already performed" msgstr "Analiza została już wykonana" @@ -324,15 +327,27 @@ msgstr "Przewijanie kamery przy krawędzi\\Ekran jest przewijany gdy mysz dotkni msgid "Camera closer\\Moves the camera forward" msgstr "Kamera bliżej\\Przybliża kamerę" +msgid "Camera down\\Turns the camera down" +msgstr "Kamera w dół\\Obraca kamerę w dół" + +msgid "Camera left\\Turns the camera left" +msgstr "Kamera w lewo\\Obraca kamerę w lewo" + msgid "Camera nearest" msgstr "Camera nearest" +msgid "Camera right\\Turns the camera right" +msgstr "Kamera w prawo\\Obróć kamerę w prawo" + msgid "Camera to left" msgstr "Camera to left" msgid "Camera to right" msgstr "Camera to right" +msgid "Camera up\\Turns the camera up" +msgstr "Kamera w górę\\Obróć kamerę w górę" + msgid "Can not produce not researched object" msgstr "Nie można wyprodukować nie wynalezionego obiektu" diff --git a/po/ru.po b/po/ru.po index 563ba006..d6d4d05e 100644 --- a/po/ru.po +++ b/po/ru.po @@ -113,6 +113,9 @@ msgstr "Королева чужих убита" msgid "Already carrying something" msgstr "Уже что-то несу" +msgid "Alternative camera mode\\Move sideways instead of rotating (in free camera)" +msgstr "" + msgid "Analysis already performed" msgstr "Анализ уже выполнен" @@ -328,15 +331,31 @@ msgstr "Прокрутка\\Прокрутка, когда указатель м msgid "Camera closer\\Moves the camera forward" msgstr "Приблизать камеру\\Перемещение камеры вперед" +#, fuzzy +msgid "Camera down\\Turns the camera down" +msgstr "Приблизать камеру\\Перемещение камеры вперед" + +#, fuzzy +msgid "Camera left\\Turns the camera left" +msgstr "Приблизать камеру\\Перемещение камеры вперед" + msgid "Camera nearest" msgstr "Приблизить камеру" +#, fuzzy +msgid "Camera right\\Turns the camera right" +msgstr "Повернуть налево\\Поворот налево" + msgid "Camera to left" msgstr "Камеру влево" msgid "Camera to right" msgstr "Камеру вправо" +#, fuzzy +msgid "Camera up\\Turns the camera up" +msgstr "Камера (\\key camera;)" + msgid "Can not produce not researched object" msgstr "" diff --git a/src/app/input.cpp b/src/app/input.cpp index 62bad06f..87cedf34 100644 --- a/src/app/input.cpp +++ b/src/app/input.cpp @@ -49,8 +49,13 @@ CInput::CInput() { INPUT_SLOT_CAMERA, "camera" }, { INPUT_SLOT_DESEL, "desel" }, { INPUT_SLOT_ACTION, "action" }, - { INPUT_SLOT_NEAR, "near" }, - { INPUT_SLOT_AWAY, "away" }, + { INPUT_SLOT_CAM_LEFT, "cleft" }, + { INPUT_SLOT_CAM_RIGHT,"cright" }, + { INPUT_SLOT_CAM_UP, "cup" }, + { INPUT_SLOT_CAM_DOWN, "cdown" }, + { INPUT_SLOT_CAM_NEAR, "near" }, + { INPUT_SLOT_CAM_AWAY, "away" }, + { INPUT_SLOT_CAM_ALT, "camalt" }, { INPUT_SLOT_NEXT, "next" }, { INPUT_SLOT_HUMAN, "human" }, { INPUT_SLOT_QUIT, "quit" }, @@ -64,8 +69,8 @@ CInput::CInput() { INPUT_SLOT_SPEED30, "speed30" }, { INPUT_SLOT_SPEED40, "speed40" }, { INPUT_SLOT_SPEED60, "speed60" }, - { INPUT_SLOT_PAUSE, "pause" }, - { INPUT_SLOT_CMDLINE, "cmdline" }, + { INPUT_SLOT_PAUSE, "pause" }, + { INPUT_SLOT_CMDLINE, "cmdline" }, }; m_mousePos = Math::Point(); @@ -125,10 +130,12 @@ void CInput::EventProcess(Event& event) if (data->slot == INPUT_SLOT_GUP ) m_keyMotion.z = 1.0f; if (data->slot == INPUT_SLOT_GDOWN) m_keyMotion.z = -1.0f; - if (data->key == KEY(KP_4) ) m_cameraKeyMotion.x = -1.0f; - if (data->key == KEY(KP_6) ) m_cameraKeyMotion.x = 1.0f; - if (data->key == KEY(KP_8) ) m_cameraKeyMotion.y = 1.0f; - if (data->key == KEY(KP_2) ) m_cameraKeyMotion.y = -1.0f; + if (data->slot == INPUT_SLOT_CAM_LEFT ) m_cameraKeyMotion.x = -1.0f; + if (data->slot == INPUT_SLOT_CAM_RIGHT) m_cameraKeyMotion.x = 1.0f; + if (data->slot == INPUT_SLOT_CAM_UP ) m_cameraKeyMotion.y = 1.0f; + if (data->slot == INPUT_SLOT_CAM_DOWN ) m_cameraKeyMotion.y = -1.0f; + if (data->slot == INPUT_SLOT_CAM_NEAR ) m_cameraKeyMotion.z = -1.0f; + if (data->slot == INPUT_SLOT_CAM_AWAY ) m_cameraKeyMotion.z = 1.0f; } else if (event.type == EVENT_KEY_UP) { @@ -141,10 +148,12 @@ void CInput::EventProcess(Event& event) if (data->slot == INPUT_SLOT_GUP ) m_keyMotion.z = 0.0f; if (data->slot == INPUT_SLOT_GDOWN) m_keyMotion.z = 0.0f; - if (data->key == KEY(KP_4) ) m_cameraKeyMotion.x = 0.0f; - if (data->key == KEY(KP_6) ) m_cameraKeyMotion.x = 0.0f; - if (data->key == KEY(KP_8) ) m_cameraKeyMotion.y = 0.0f; - if (data->key == KEY(KP_2) ) m_cameraKeyMotion.y = 0.0f; + if (data->slot == INPUT_SLOT_CAM_LEFT ) m_cameraKeyMotion.x = 0.0f; + if (data->slot == INPUT_SLOT_CAM_RIGHT) m_cameraKeyMotion.x = 0.0f; + if (data->slot == INPUT_SLOT_CAM_UP ) m_cameraKeyMotion.y = 0.0f; + if (data->slot == INPUT_SLOT_CAM_DOWN ) m_cameraKeyMotion.y = 0.0f; + if (data->slot == INPUT_SLOT_CAM_NEAR ) m_cameraKeyMotion.z = 0.0f; + if (data->slot == INPUT_SLOT_CAM_AWAY ) m_cameraKeyMotion.z = 0.0f; } else if (event.type == EVENT_JOY_AXIS) { @@ -255,8 +264,13 @@ void CInput::SetDefaultInputBindings() m_inputBindings[INPUT_SLOT_DESEL ].primary = KEY(KP_0); m_inputBindings[INPUT_SLOT_ACTION ].primary = KEY(RETURN); m_inputBindings[INPUT_SLOT_ACTION ].secondary = KEY(e); - m_inputBindings[INPUT_SLOT_NEAR ].primary = KEY(KP_PLUS); - m_inputBindings[INPUT_SLOT_AWAY ].primary = KEY(KP_MINUS); + m_inputBindings[INPUT_SLOT_CAM_LEFT ].primary = KEY(KP_4); + m_inputBindings[INPUT_SLOT_CAM_RIGHT].primary = KEY(KP_6); + m_inputBindings[INPUT_SLOT_CAM_UP ].primary = KEY(KP_8); + m_inputBindings[INPUT_SLOT_CAM_DOWN ].primary = KEY(KP_2); + m_inputBindings[INPUT_SLOT_CAM_NEAR ].primary = KEY(KP_PLUS); + m_inputBindings[INPUT_SLOT_CAM_AWAY ].primary = KEY(KP_MINUS); + m_inputBindings[INPUT_SLOT_CAM_ALT ].primary = VIRTUAL_KMOD(ALT); m_inputBindings[INPUT_SLOT_NEXT ].primary = KEY(TAB); m_inputBindings[INPUT_SLOT_HUMAN ].primary = KEY(HOME); m_inputBindings[INPUT_SLOT_QUIT ].primary = KEY(ESCAPE); diff --git a/src/common/key.h b/src/common/key.h index f1209ed2..d249860c 100644 --- a/src/common/key.h +++ b/src/common/key.h @@ -87,8 +87,13 @@ enum InputSlot INPUT_SLOT_CAMERA, INPUT_SLOT_DESEL, INPUT_SLOT_ACTION, - INPUT_SLOT_NEAR, - INPUT_SLOT_AWAY, + INPUT_SLOT_CAM_LEFT, + INPUT_SLOT_CAM_RIGHT, + INPUT_SLOT_CAM_UP, + INPUT_SLOT_CAM_DOWN, + INPUT_SLOT_CAM_NEAR, + INPUT_SLOT_CAM_AWAY, + INPUT_SLOT_CAM_ALT, INPUT_SLOT_NEXT, INPUT_SLOT_HUMAN, INPUT_SLOT_QUIT, diff --git a/src/common/restext.cpp b/src/common/restext.cpp index ec88dc48..a9644a36 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -220,8 +220,13 @@ void InitializeRestext() stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_CAMERA] = TR("Change camera\\Switches between onboard camera and following camera"); stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_DESEL] = TR("Previous object\\Selects the previous object"); stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_ACTION] = TR("Standard action\\Standard action of the bot (take/grab, shoot, sniff, etc)"); - stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_NEAR] = TR("Camera closer\\Moves the camera forward"); - stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_AWAY] = TR("Camera back\\Moves the camera backward"); + stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_CAM_LEFT] = TR("Camera left\\Turns the camera left"); + stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_CAM_RIGHT] = TR("Camera right\\Turns the camera right"); + stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_CAM_UP] = TR("Camera up\\Turns the camera up"); + stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_CAM_DOWN] = TR("Camera down\\Turns the camera down"); + stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_CAM_NEAR] = TR("Camera closer\\Moves the camera forward"); + stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_CAM_AWAY] = TR("Camera back\\Moves the camera backward"); + stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_CAM_ALT] = TR("Alternative camera mode\\Move sideways instead of rotating (in free camera)"); stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_NEXT] = TR("Next object\\Selects the next object"); stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_HUMAN] = TR("Select the astronaut\\Selects the astronaut"); stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_QUIT] = TR("Quit\\Quit the current mission or exercise"); diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index 0b6157b8..44626130 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -1210,7 +1210,7 @@ bool CCamera::EventFrameFree(const Event &event, bool keysAllowed) Math::Vector cameraMove = CalculateCameraMovement(event, keysAllowed); float factor = m_heightEye * 0.5f + 30.0f; - bool secondary = event.kmodState & KEY_MOD(CTRL) || event.mouseButtonsState & MOUSE_BUTTON_MIDDLE; + bool secondary = m_input->GetKeyState(INPUT_SLOT_CAM_ALT) || event.mouseButtonsState & MOUSE_BUTTON_MIDDLE; // TODO: make mouse button a keybinding // Forward/Backward m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, -cameraMove.y * factor * 2); @@ -1609,11 +1609,6 @@ Math::Vector CCamera::CalculateCameraMovement(const Event &event, bool keysAllow delta.y -= event.motionInput.y * event.rTime * 0.5f * m_speed; delta.z -= event.motionInput.z * event.rTime * 20.0f * m_speed; } - - if (m_input->GetKeyState(INPUT_SLOT_NEAR)) - delta.z -= event.rTime * 20.0f * m_speed; - if (m_input->GetKeyState(INPUT_SLOT_AWAY)) - delta.z += event.rTime * 20.0f * m_speed; } if (delta.Length() > 0) From 89b495c6671f7651d20085d482f9dc8c335ebe7b Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 May 2016 15:56:56 +0200 Subject: [PATCH 085/125] Cleaned up whitespace in translation strings --- po/colobot.pot | 60 +++++++++---------- po/de.po | 127 ++++++++++++++++++++--------------------- po/fr.po | 116 ++++++++++++++++++------------------- po/pl.po | 116 ++++++++++++++++++------------------- po/ru.po | 121 +++++++++++++++++++-------------------- src/common/restext.cpp | 60 +++++++++---------- 6 files changed, 297 insertions(+), 303 deletions(-) diff --git a/po/colobot.pot b/po/colobot.pot index 1b624494..d17e297f 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -84,34 +84,34 @@ msgstr "" msgid "Load a saved mission" msgstr "" -msgid " Chapters:" +msgid "Chapters:" msgstr "" -msgid " Planets:" +msgid "Planets:" msgstr "" -msgid " Custom levels:" +msgid "Custom levels:" msgstr "" -msgid " Levels in this chapter:" +msgid "Levels in this chapter:" msgstr "" -msgid " Exercises in the chapter:" +msgid "Exercises in the chapter:" msgstr "" -msgid " Challenges in the chapter:" +msgid "Challenges in the chapter:" msgstr "" -msgid " Missions on this planet:" +msgid "Missions on this planet:" msgstr "" -msgid " Free game on this planet:" +msgid "Free game on this planet:" msgstr "" -msgid " Summary:" +msgid "Summary:" msgstr "" -msgid " Resolution:" +msgid "Resolution:" msgstr "" msgid "1) First click on the key you want to redefine." @@ -145,7 +145,7 @@ msgid "Do you really want to destroy the selected building?" msgstr "" #, c-format -msgid "Do you want to delete %s's saved games? " +msgid "Do you want to delete %s's saved games?" msgstr "" msgid "Yes" @@ -299,7 +299,7 @@ msgstr "" msgid "Restart\\Restart the mission from the beginning" msgstr "" -msgid "Save\\Save the current mission " +msgid "Save\\Save the current mission" msgstr "" msgid "Load\\Load a saved mission" @@ -530,7 +530,7 @@ msgstr "" msgid "Sound effects:\\Volume of engines, voice, shooting, etc." msgstr "" -msgid "Background sound :\\Volume of audio tracks" +msgid "Background sound:\\Volume of audio tracks" msgstr "" msgid "Lowest\\Minimum graphic quality (highest frame rate)" @@ -1049,22 +1049,22 @@ msgstr "" msgid "Clone program" msgstr "" -msgid "Open (Ctrl+o)" +msgid "Open (Ctrl+O)" msgstr "" -msgid "Save (Ctrl+s)" +msgid "Save (Ctrl+S)" msgstr "" -msgid "Undo (Ctrl+z)" +msgid "Undo (Ctrl+Z)" msgstr "" -msgid "Cut (Ctrl+x)" +msgid "Cut (Ctrl+X)" msgstr "" -msgid "Copy (Ctrl+c)" +msgid "Copy (Ctrl+C)" msgstr "" -msgid "Paste (Ctrl+v)" +msgid "Paste (Ctrl+V)" msgstr "" msgid "Font size" @@ -1073,7 +1073,7 @@ msgstr "" msgid "Instructions (\\key help;)" msgstr "" -msgid "Programming help (\\key prog;)" +msgid "Programming help (\\key prog;)" msgstr "" msgid "Compile" @@ -1454,10 +1454,10 @@ msgstr "" msgid "Transforms only titanium" msgstr "" -msgid "Doors blocked by a robot or another object " +msgid "Doors blocked by a robot or another object" msgstr "" -msgid "You must get on the spaceship to take off " +msgid "You must get on the spaceship to take off" msgstr "" msgid "Nothing to analyze" @@ -1535,7 +1535,7 @@ msgstr "" msgid "Research program completed" msgstr "" -msgid "Plans for tracked robots available " +msgid "Plans for tracked robots available" msgstr "" msgid "You can fly with the keys (\\key gup;) and (\\key gdown;)" @@ -1610,7 +1610,7 @@ msgstr "" msgid "Opening bracket missing" msgstr "" -msgid "Closing bracket missing " +msgid "Closing bracket missing" msgstr "" msgid "The expression must return a boolean value" @@ -1634,10 +1634,10 @@ msgstr "" msgid "End of block missing" msgstr "" -msgid "Instruction \"else\" without corresponding \"if\" " +msgid "Instruction \"else\" without corresponding \"if\"" msgstr "" -msgid "Opening brace missing " +msgid "Opening brace missing" msgstr "" msgid "Wrong type for the assignment" @@ -1646,7 +1646,7 @@ msgstr "" msgid "A variable can not be declared twice" msgstr "" -msgid "The types of the two operands are incompatible " +msgid "The types of the two operands are incompatible" msgstr "" msgid "Unknown function" @@ -1691,7 +1691,7 @@ msgstr "" msgid "Function already exists" msgstr "" -msgid "Parameters missing " +msgid "Parameters missing" msgstr "" msgid "No function with this name accepts this kind of parameter" @@ -1736,7 +1736,7 @@ msgstr "" msgid "Public required" msgstr "" -msgid "expression expected after =" +msgid "Expression expected after =" msgstr "" msgid "Dividing by zero" @@ -1748,7 +1748,7 @@ msgstr "" msgid "Negative value rejected by \"throw\"" msgstr "" -msgid "The function returned no value " +msgid "The function returned no value" msgstr "" msgid "No function running" diff --git a/po/de.po b/po/de.po index 453d1520..3e8cdea9 100644 --- a/po/de.po +++ b/po/de.po @@ -20,38 +20,6 @@ msgstr "" "X-Source-Language: en_US\n" "X-POOTLE-MTIME: 1406536037.000000\n" -msgid " Challenges in the chapter:" -msgstr " Liste der Challenges des Kapitels:" - -msgid " Chapters:" -msgstr " Liste der Kapitel:" - -#, fuzzy -msgid " Custom levels:" -msgstr " Userlevels:" - -msgid " Exercises in the chapter:" -msgstr " Liste der Übungen des Kapitels:" - -msgid " Free game on this planet:" -msgstr " Liste der freien Levels des Planeten:" - -#, fuzzy -msgid " Levels in this chapter:" -msgstr " Liste der Übungen des Kapitels:" - -msgid " Missions on this planet:" -msgstr " Liste der Missionen des Planeten:" - -msgid " Planets:" -msgstr " Liste der Planeten:" - -msgid " Resolution:" -msgstr " Auflösung:" - -msgid " Summary:" -msgstr " Zusammenfassung:" - msgid " or " msgstr " oder " @@ -167,7 +135,7 @@ msgid "Back" msgstr "Vorherg. Seite" #, fuzzy -msgid "Background sound :\\Volume of audio tracks" +msgid "Background sound:\\Volume of audio tracks" msgstr "Geräuschkulisse:\\Lautstärke der Soundtracks der CD" msgid "Backward (\\key down;)" @@ -376,6 +344,9 @@ msgstr "Abbrechen\\Editor schließen" msgid "Challenges" msgstr "Challenges" +msgid "Challenges in the chapter:" +msgstr "Liste der Challenges des Kapitels:" + msgid "Challenges\\Programming challenges" msgstr "Challenges\\Herausforderungen" @@ -385,6 +356,9 @@ msgstr "Andere Kamera\\Sichtpunkt einstellen" msgid "Change player\\Change player" msgstr "Anderer Spieler\\Spielername ändern" +msgid "Chapters:" +msgstr "Liste der Kapitel:" + msgid "Cheat console\\Show cheat console" msgstr "" @@ -404,7 +378,7 @@ msgstr "Gewähltes Programm bearbeiten" msgid "Close" msgstr "Schließen" -msgid "Closing bracket missing " +msgid "Closing bracket missing" msgstr "Es fehlt eine geschlossene Klammer \")\"" msgid "Code battles" @@ -416,9 +390,8 @@ msgstr "" msgid "Colobot rules!" msgstr "Colobot ist wunderbar!" -#, fuzzy msgid "Colobot: Gold Edition" -msgstr "COLOBOT: Gold Edition" +msgstr "Colobot: Gold Edition" msgid "Command line" msgstr "Befehleingabe" @@ -444,20 +417,24 @@ msgstr "Konverter Erz-Titan" msgid "Copy" msgstr "Kopieren" -msgid "Copy (Ctrl+c)" -msgstr "Kopieren (Ctrl+c)" +msgid "Copy (Ctrl+C)" +msgstr "Kopieren (Ctrl+C)" msgid "Current mission saved" msgstr "Mission gespeichert" +#, fuzzy +msgid "Custom levels:" +msgstr "Userlevels:" + msgid "Custom levels\\Levels from mods created by the users" msgstr "" msgid "Customize your appearance" msgstr "Aussehen einstellen" -msgid "Cut (Ctrl+x)" -msgstr "Ausschneiden (Ctrl+x)" +msgid "Cut (Ctrl+X)" +msgstr "Ausschneiden (Ctrl+X)" msgid "Defense tower" msgstr "Geschützturm" @@ -497,10 +474,10 @@ msgid "Do you really want to destroy the selected building?" msgstr "Wollen Sie das angewählte Gebäude wirklich zerstören ?" #, c-format -msgid "Do you want to delete %s's saved games? " +msgid "Do you want to delete %s's saved games?" msgstr "Wollen Sie die gespeicherten Missionen von %s löschen ?" -msgid "Doors blocked by a robot or another object " +msgid "Doors blocked by a robot or another object" msgstr "Die Türen werden von einem Gegenstand blockiert" msgid "Down (\\key gdown;)" @@ -548,6 +525,9 @@ msgstr "Gewähltes Programm ausführen" msgid "Execute/stop" msgstr "Start/Stop" +msgid "Exercises in the chapter:" +msgstr "Liste der Übungen des Kapitels:" + msgid "Exercises\\Programming exercises" msgstr "Programmieren\\Programmierübungen" @@ -557,6 +537,9 @@ msgstr "Explodieren (\\key action;)" msgid "Explosive" msgstr "Sprengstoff" +msgid "Expression expected after =" +msgstr "" + msgid "Extend shield (\\key action;)" msgstr "Schutzschild ausfahren (\\key action;)" @@ -627,6 +610,9 @@ msgstr "Markierung für vergrabenen Schlüssel D" msgid "Free game" msgstr "Freestyle" +msgid "Free game on this planet:" +msgstr "Liste der freien Levels des Planeten:" + msgid "Free game\\Free game without a specific goal" msgstr "Freestyle\\Freies Spielen ohne vorgegebenes Ziel" @@ -742,7 +728,7 @@ msgstr "Es fehlt eine Anweisung \"case\"" msgid "Instruction \"case\" outside a block \"switch\"" msgstr "Anweisung \"case\" ohne vorhergehende Anweisung \"switch\"" -msgid "Instruction \"else\" without corresponding \"if\" " +msgid "Instruction \"else\" without corresponding \"if\"" msgstr "Anweisung \"else\" ohne vorhergehende Anweisung \"if\"" msgid "Instructions (\\key help;)" @@ -802,6 +788,9 @@ msgstr "Shooter" msgid "Legged sniffer" msgstr "Schnüffler" +msgid "Levels in this chapter:" +msgstr "Liste der Übungen des Kapitels:" + msgid "Lightning conductor" msgstr "Blitzableiter" @@ -861,6 +850,9 @@ msgstr "Name der Mission" msgid "Missions" msgstr "Missionen" +msgid "Missions on this planet:" +msgstr "Liste der Missionen des Planeten:" + msgid "Missions\\Select mission" msgstr "Missionen\\Aufbruch ins Weltall" @@ -1019,10 +1011,10 @@ msgstr "Ein Schritt" msgid "Open" msgstr "Öffnen" -msgid "Open (Ctrl+o)" -msgstr "Öffnen (Ctrl+o)" +msgid "Open (Ctrl+O)" +msgstr "Öffnen (Ctrl+O)" -msgid "Opening brace missing " +msgid "Opening brace missing" msgstr "Es fehlt eine offene geschweifte Klammer\"{\"" msgid "Opening bracket missing" @@ -1046,14 +1038,14 @@ msgstr "Ort der Meldung\\Zeigt den Ort, von dem die letzte Meldung stammt" msgid "Original game developed by:" msgstr "Ursprünglichen Spiel entwickelt von:" -msgid "Parameters missing " +msgid "Parameters missing" msgstr "Nicht genug Parameter" msgid "Particles in the interface\\Steam clouds and sparks in the interface" msgstr "Partikel in den Menüs\\Funken und Sterne in den Menüs" -msgid "Paste (Ctrl+v)" -msgstr "Einfügen (Ctrl+v)" +msgid "Paste (Ctrl+V)" +msgstr "Einfügen (Ctrl+V)" msgid "Pause in background\\Pause the game when the window is unfocused" msgstr "" @@ -1073,6 +1065,9 @@ msgstr "Ansicht der Mission" msgid "Place occupied" msgstr "Stelle schon besetzt" +msgid "Planets:" +msgstr "Liste der Planeten:" + msgid "Plans for defense tower available" msgstr "Errichtung eines Geschützturms möglich" @@ -1091,7 +1086,7 @@ msgstr "Herstellung eines Shooters möglich" msgid "Plans for thumper available" msgstr "Herstellung eines Stampfers möglich" -msgid "Plans for tracked robots available " +msgid "Plans for tracked robots available" msgstr "Herstellung eines Roboters mit Kettenantrieb möglich" msgid "Plant a flag" @@ -1164,7 +1159,7 @@ msgstr "Programmieren" msgid "Programming help" msgstr "Hilfe über Programmieren" -msgid "Programming help (\\key prog;)" +msgid "Programming help (\\key prog;)" msgstr "Hilfe über Programmieren (\\key prog;)" msgid "Programming help\\Gives more detailed help with programming" @@ -1245,6 +1240,9 @@ msgstr "Dieses Wort ist reserviert" msgid "Resolution" msgstr "Auflösung" +msgid "Resolution:" +msgstr "Auflösung:" + msgid "Resources" msgstr "" @@ -1305,13 +1303,13 @@ msgstr "Satellitenbericht" msgid "Save" msgstr "Speichern" -msgid "Save (Ctrl+s)" -msgstr "Speichern (Ctrl+s)" +msgid "Save (Ctrl+S)" +msgstr "Speichern (Ctrl+S)" msgid "Save the current mission" msgstr "Aktuelle Mission speichern" -msgid "Save\\Save the current mission " +msgid "Save\\Save the current mission" msgstr "Speichern\\Aktuelle Mission speichern" msgid "Save\\Saves the current mission" @@ -1458,6 +1456,9 @@ msgstr "Farbe des Anzugs:" msgid "Suit\\Astronaut suit" msgstr "Anzug\\Raumfahrtanzug" +msgid "Summary:" +msgstr "Zusammenfassung:" + msgid "Survival kit" msgstr "Überlebenskit" @@ -1485,13 +1486,13 @@ msgstr "" msgid "The expression must return a boolean value" msgstr "Der Ausdruck muss einen boolschen Wert ergeben" -msgid "The function returned no value " +msgid "The function returned no value" msgstr "Die Funktion hat kein Ergebnis zurückgegeben" msgid "The mission is not accomplished yet (press \\key help; for more details)" msgstr "Mission noch nicht beendet (Drücken Sie auf \\key help; für weitere Informationen)" -msgid "The types of the two operands are incompatible " +msgid "The types of the two operands are incompatible" msgstr "Die zwei Operanden sind nicht kompatibel" msgid "This class already exists" @@ -1596,8 +1597,8 @@ msgstr "Hier muss ein Variablentyp stehen" msgid "Unable to control enemy objects" msgstr "" -msgid "Undo (Ctrl+z)" -msgstr "Widerrufen (Ctrl+z)" +msgid "Undo (Ctrl+Z)" +msgstr "Widerrufen (Ctrl+Z)" msgid "Unit" msgstr "Einheit" @@ -1726,7 +1727,7 @@ msgid_plural "You have to use \"%1$s\" at most %3$d times in this exercise (used msgstr[0] "In dieser Übung verboten" msgstr[1] "In dieser Übung verboten" -msgid "You must get on the spaceship to take off " +msgid "You must get on the spaceship to take off" msgstr "Gehen Sie an Bord, bevor Sie abheben" msgid "Zoom mini-map" @@ -1826,14 +1827,10 @@ msgid "\\Yellow flags" msgstr "\\Gelbe Fahne" msgid "colobot.info" -msgstr "" +msgstr "colobot.info" -#, fuzzy msgid "epsitec.com" -msgstr "www.epsitec.com" - -msgid "expression expected after =" -msgstr "" +msgstr "epsitec.com" #~ msgid " " #~ msgstr " " diff --git a/po/fr.po b/po/fr.po index 4d919748..b834222b 100644 --- a/po/fr.po +++ b/po/fr.po @@ -15,36 +15,6 @@ msgstr "" "X-Language: fr_FR\n" "X-Source-Language: en_US\n" -msgid " Challenges in the chapter:" -msgstr " Liste des défis du chapitre :" - -msgid " Chapters:" -msgstr " Liste des chapitres :" - -msgid " Custom levels:" -msgstr " Niveaux spéciaux :" - -msgid " Exercises in the chapter:" -msgstr " Liste des exercices du chapitre :" - -msgid " Free game on this planet:" -msgstr " Liste des jeux libres du chapitre :" - -msgid " Levels in this chapter:" -msgstr " Liste des niveaux du chapitre :" - -msgid " Missions on this planet:" -msgstr " Liste des missions du chapitre :" - -msgid " Planets:" -msgstr " Liste des planètes :" - -msgid " Resolution:" -msgstr " Résolutions :" - -msgid " Summary:" -msgstr " Résumé :" - msgid " or " msgstr " ou " @@ -159,7 +129,7 @@ msgstr "Auto-sauvegarde\\Active l'auto-sauvegarde" msgid "Back" msgstr "Page précédente" -msgid "Background sound :\\Volume of audio tracks" +msgid "Background sound:\\Volume of audio tracks" msgstr "Fond sonore :\\Volume des pistes audio" msgid "Backward (\\key down;)" @@ -367,6 +337,9 @@ msgstr "Annuler\\Annuler toutes les modifications" msgid "Challenges" msgstr "Défis" +msgid "Challenges in the chapter:" +msgstr "Liste des défis du chapitre :" + msgid "Challenges\\Programming challenges" msgstr "Défis\\Défis de programmation" @@ -376,6 +349,9 @@ msgstr "Changement de caméra\\Autre de point de vue" msgid "Change player\\Change player" msgstr "Autre joueur\\Choix du nom du joueur" +msgid "Chapters:" +msgstr "Liste des chapitres :" + msgid "Cheat console\\Show cheat console" msgstr "Console de triche\\Montre la console de triche" @@ -394,7 +370,7 @@ msgstr "Dupliquer le programme sélectionné" msgid "Close" msgstr "Fermer" -msgid "Closing bracket missing " +msgid "Closing bracket missing" msgstr "Il manque une parenthèse fermante" msgid "Code battles" @@ -433,20 +409,23 @@ msgstr "Conversion minerai en titanium" msgid "Copy" msgstr "Copier" -msgid "Copy (Ctrl+c)" -msgstr "Copier (Ctrl+c)" +msgid "Copy (Ctrl+C)" +msgstr "Copier (Ctrl+C)" msgid "Current mission saved" msgstr "Enregistrement effectué" +msgid "Custom levels:" +msgstr "Niveaux spéciaux :" + msgid "Custom levels\\Levels from mods created by the users" msgstr "Niveaux spéciaux\\Niveaux importés ou personnalisés" msgid "Customize your appearance" msgstr "Personnalisation de votre apparence" -msgid "Cut (Ctrl+x)" -msgstr "Couper (Ctrl+x)" +msgid "Cut (Ctrl+X)" +msgstr "Couper (Ctrl+X)" msgid "Defense tower" msgstr "Tour de défense" @@ -485,10 +464,10 @@ msgid "Do you really want to destroy the selected building?" msgstr "Voulez-vous vraiment détruire le bâtiment sélectionné ?" #, c-format -msgid "Do you want to delete %s's saved games? " +msgid "Do you want to delete %s's saved games?" msgstr "Voulez-vous détruire les sauvegardes de %s ?" -msgid "Doors blocked by a robot or another object " +msgid "Doors blocked by a robot or another object" msgstr "Portes bloquées par un robot ou un objet" msgid "Down (\\key gdown;)" @@ -536,6 +515,9 @@ msgstr "Exécute le programme sélectionné" msgid "Execute/stop" msgstr "Démarrer/stopper" +msgid "Exercises in the chapter:" +msgstr "Liste des exercices du chapitre :" + msgid "Exercises\\Programming exercises" msgstr "Programmation\\Exercices de programmation" @@ -545,6 +527,9 @@ msgstr "Exploser (\\key action;)" msgid "Explosive" msgstr "Explosif" +msgid "Expression expected after =" +msgstr "" + msgid "Extend shield (\\key action;)" msgstr "Déploie le bouclier (\\key action;)" @@ -615,6 +600,9 @@ msgstr "Emplacement pour derrick (clé D)" msgid "Free game" msgstr "Jeu libre" +msgid "Free game on this planet:" +msgstr "Liste des jeux libres du chapitre :" + msgid "Free game\\Free game without a specific goal" msgstr "Jeu libre\\Jeu libre sans but précis" @@ -729,7 +717,7 @@ msgstr "Manque une instruction \"case\"" msgid "Instruction \"case\" outside a block \"switch\"" msgstr "Instruction \"case\" hors d'un bloc \"switch\"" -msgid "Instruction \"else\" without corresponding \"if\" " +msgid "Instruction \"else\" without corresponding \"if\"" msgstr "Instruction \"else\" sans \"if\" correspondant" msgid "Instructions (\\key help;)" @@ -789,6 +777,9 @@ msgstr "Robot shooter" msgid "Legged sniffer" msgstr "Robot renifleur" +msgid "Levels in this chapter:" +msgstr "Liste des niveaux du chapitre :" + msgid "Lightning conductor" msgstr "Paratonnerre" @@ -846,6 +837,9 @@ msgstr "Nom de la mission" msgid "Missions" msgstr "Missions" +msgid "Missions on this planet:" +msgstr "Liste des missions du chapitre :" + msgid "Missions\\Select mission" msgstr "Missions\\La grande aventure" @@ -1002,10 +996,10 @@ msgstr "Un pas" msgid "Open" msgstr "Ouvrir" -msgid "Open (Ctrl+o)" -msgstr "Ouvrir (Ctrl+o)" +msgid "Open (Ctrl+O)" +msgstr "Ouvrir (Ctrl+O)" -msgid "Opening brace missing " +msgid "Opening brace missing" msgstr "Début d'un bloc attendu" msgid "Opening bracket missing" @@ -1029,14 +1023,14 @@ msgstr "Montrer le lieu d'un message\\Montrer le lieu du dernier message" msgid "Original game developed by:" msgstr "Jeu Original développé par :" -msgid "Parameters missing " +msgid "Parameters missing" msgstr "Pas assez de paramètres" msgid "Particles in the interface\\Steam clouds and sparks in the interface" msgstr "Particules dans l'interface\\Pluie de particules" -msgid "Paste (Ctrl+v)" -msgstr "Coller (Ctrl+v)" +msgid "Paste (Ctrl+V)" +msgstr "Coller (Ctrl+V)" msgid "Pause in background\\Pause the game when the window is unfocused" msgstr "" @@ -1056,6 +1050,9 @@ msgstr "Vue de la mission" msgid "Place occupied" msgstr "Emplacement occupé" +msgid "Planets:" +msgstr "Liste des planètes :" + msgid "Plans for defense tower available" msgstr "Construction d'une tour de défense possible" @@ -1074,7 +1071,7 @@ msgstr "Fabrication de robots shooter possible" msgid "Plans for thumper available" msgstr "Fabrication d'un robot secoueur possible" -msgid "Plans for tracked robots available " +msgid "Plans for tracked robots available" msgstr "Fabrication d'un robot à chenilles possible" msgid "Plant a flag" @@ -1146,7 +1143,7 @@ msgstr "Programmation" msgid "Programming help" msgstr "Aide à la programmation" -msgid "Programming help (\\key prog;)" +msgid "Programming help (\\key prog;)" msgstr "Aide à la programmation (\\key prog;)" msgid "Programming help\\Gives more detailed help with programming" @@ -1224,6 +1221,9 @@ msgstr "Ce mot est réservé" msgid "Resolution" msgstr "Résolution" +msgid "Resolution:" +msgstr "Résolutions :" + msgid "Resources" msgstr "" @@ -1284,13 +1284,13 @@ msgstr "Rapport du satellite" msgid "Save" msgstr "Enregistrer" -msgid "Save (Ctrl+s)" -msgstr "Enregistrer (Ctrl+s)" +msgid "Save (Ctrl+S)" +msgstr "Enregistrer (Ctrl+S)" msgid "Save the current mission" msgstr "Enregistrement de la mission en cours" -msgid "Save\\Save the current mission " +msgid "Save\\Save the current mission" msgstr "Enregistrer\\Enregistrer la mission en cours" msgid "Save\\Saves the current mission" @@ -1431,6 +1431,9 @@ msgstr "Couleur de la combinaison :" msgid "Suit\\Astronaut suit" msgstr "Corps\\Combinaison" +msgid "Summary:" +msgstr "Résumé :" + msgid "Survival kit" msgstr "Sac de survie" @@ -1458,13 +1461,13 @@ msgstr "Textures" msgid "The expression must return a boolean value" msgstr "L'expression doit ętre un boolean" -msgid "The function returned no value " +msgid "The function returned no value" msgstr "La fonction n'a pas retourné de résultat" msgid "The mission is not accomplished yet (press \\key help; for more details)" msgstr "La misssion n'est pas terminée (appuyez sur \\key help; pour plus de détails)" -msgid "The types of the two operands are incompatible " +msgid "The types of the two operands are incompatible" msgstr "Les deux opérandes ne sont pas de types compatibles" msgid "This class already exists" @@ -1569,8 +1572,8 @@ msgstr "Déclaration de type attendu" msgid "Unable to control enemy objects" msgstr "Impossible de contrôler les objets ennemis" -msgid "Undo (Ctrl+z)" -msgstr "Annuler (Ctrl+z)" +msgid "Undo (Ctrl+Z)" +msgstr "Annuler (Ctrl+Z)" msgid "Unit" msgstr "Unité" @@ -1699,7 +1702,7 @@ msgid_plural "You have to use \"%1$s\" at most %3$d times in this exercise (used msgstr[0] "Interdit dans cet exercice" msgstr[1] "Interdit dans cet exercice" -msgid "You must get on the spaceship to take off " +msgid "You must get on the spaceship to take off" msgstr "Vous devez embarquer pour pouvoir décoller" msgid "Zoom mini-map" @@ -1804,9 +1807,6 @@ msgstr "colobot.info" msgid "epsitec.com" msgstr "epsitec.com" -msgid "expression expected after =" -msgstr "" - #~ msgid " " #~ msgstr " " diff --git a/po/pl.po b/po/pl.po index 68cd35a2..64d57d87 100644 --- a/po/pl.po +++ b/po/pl.po @@ -18,36 +18,6 @@ msgstr "" "X-Language: pl_PL\n" "X-Source-Language: en_US\n" -msgid " Challenges in the chapter:" -msgstr " Wyzwania w tym rozdziale:" - -msgid " Chapters:" -msgstr " Rozdziały:" - -msgid " Custom levels:" -msgstr " Własne poziomy:" - -msgid " Exercises in the chapter:" -msgstr " Ćwiczenia w tym rozdziale:" - -msgid " Free game on this planet:" -msgstr " Swobodna gra na tej planecie:" - -msgid " Levels in this chapter:" -msgstr " Poziomy w tym rozdziale:" - -msgid " Missions on this planet:" -msgstr " Misje na tej planecie:" - -msgid " Planets:" -msgstr " Planety:" - -msgid " Resolution:" -msgstr " Rozdzielczość:" - -msgid " Summary:" -msgstr " Streszczenie:" - msgid " or " msgstr " lub " @@ -162,8 +132,8 @@ msgstr "Autozapis\\Włącza automatyczny zapis" msgid "Back" msgstr "Wstecz" -msgid "Background sound :\\Volume of audio tracks" -msgstr "Muzyka w tle :\\Głośność ścieżek dźwiękowych" +msgid "Background sound:\\Volume of audio tracks" +msgstr "Muzyka w tle:\\Głośność ścieżek dźwiękowych" msgid "Backward (\\key down;)" msgstr "Cofnij (\\key down;)" @@ -366,6 +336,9 @@ msgstr "Anuluj\\Pomija wszystkie zmiany" msgid "Challenges" msgstr "Wyzwania" +msgid "Challenges in the chapter:" +msgstr "Wyzwania w tym rozdziale:" + msgid "Challenges\\Programming challenges" msgstr "Wyzwania\\Wyzwania programistyczne" @@ -375,6 +348,9 @@ msgstr "Zmień kamerę\\Przełącza pomiędzy kamerą pokładową i śledzącą" msgid "Change player\\Change player" msgstr "Zmień gracza\\Zmień gracza" +msgid "Chapters:" +msgstr "Rozdziały:" + msgid "Cheat console\\Show cheat console" msgstr "Konsola komend\\Pokaż konsolę komend" @@ -393,7 +369,7 @@ msgstr "Skopiuj zaznaczony program" msgid "Close" msgstr "Zamknij" -msgid "Closing bracket missing " +msgid "Closing bracket missing" msgstr "Brak nawiasu zamykającego" msgid "Code battles" @@ -432,19 +408,22 @@ msgstr "Przetop rudę na tytan" msgid "Copy" msgstr "Kopiuj" -msgid "Copy (Ctrl+c)" +msgid "Copy (Ctrl+C)" msgstr "Kopiuj (Ctrl+C)" msgid "Current mission saved" msgstr "Bieżąca misja zapisana" +msgid "Custom levels:" +msgstr "Własne poziomy:" + msgid "Custom levels\\Levels from mods created by the users" msgstr "Własne poziomy\\Poziomy z modyfikacji stworzonych przez użytkowników" msgid "Customize your appearance" msgstr "Dostosuj wygląd" -msgid "Cut (Ctrl+x)" +msgid "Cut (Ctrl+X)" msgstr "Wytnij (Ctrl+X)" msgid "Defense tower" @@ -484,11 +463,11 @@ msgid "Do you really want to destroy the selected building?" msgstr "Czy na pewno chcesz zniszczyć zaznaczony budynek?" #, c-format -msgid "Do you want to delete %s's saved games? " -msgstr "Czy na pewno chcesz skasować zapisane gry gracza %s? " +msgid "Do you want to delete %s's saved games?" +msgstr "Czy na pewno chcesz skasować zapisane gry gracza %s?" -msgid "Doors blocked by a robot or another object " -msgstr "Drzwi zablokowane przez robota lub inny obiekt " +msgid "Doors blocked by a robot or another object" +msgstr "Drzwi zablokowane przez robota lub inny obiekt" msgid "Down (\\key gdown;)" msgstr "Dół (\\key gdown;)" @@ -535,6 +514,9 @@ msgstr "Wykonaj zaznaczony program" msgid "Execute/stop" msgstr "Wykonaj/Zatrzymaj" +msgid "Exercises in the chapter:" +msgstr "Ćwiczenia w tym rozdziale:" + msgid "Exercises\\Programming exercises" msgstr "Ćwiczenia\\Ćwiczenia programistyczne" @@ -544,6 +526,9 @@ msgstr "Wysadź (\\key action;)" msgid "Explosive" msgstr "Materiały wybuchowe" +msgid "Expression expected after =" +msgstr "Oczekiwano wyrażenia po =" + msgid "Extend shield (\\key action;)" msgstr "Rozszerz osłonę (\\key action;)" @@ -614,6 +599,9 @@ msgstr "Znaleziono klucz D (miejsce na kopalnię)" msgid "Free game" msgstr "Swobodna gra" +msgid "Free game on this planet:" +msgstr "Swobodna gra na tej planecie:" + msgid "Free game\\Free game without a specific goal" msgstr "Swobodna gra\\Swobodna gra bez konkretnych celów" @@ -728,8 +716,8 @@ msgstr "Brak polecenia \"case" msgid "Instruction \"case\" outside a block \"switch\"" msgstr "Polecenie \"case\" na zewnątrz bloku \"switch\"" -msgid "Instruction \"else\" without corresponding \"if\" " -msgstr "Polecenie \"else\" bez wystąpienia \"if\" " +msgid "Instruction \"else\" without corresponding \"if\"" +msgstr "Polecenie \"else\" bez wystąpienia \"if\"" msgid "Instructions (\\key help;)" msgstr "Rozkazy (\\key help;)" @@ -788,6 +776,9 @@ msgstr "Działo na nogach" msgid "Legged sniffer" msgstr "Szperacz na nogach" +msgid "Levels in this chapter:" +msgstr "Poziomy w tym rozdziale:" + msgid "Lightning conductor" msgstr "Odgromnik" @@ -845,6 +836,9 @@ msgstr "Nazwa misji" msgid "Missions" msgstr "Misje" +msgid "Missions on this planet:" +msgstr "Misje na tej planecie:" + msgid "Missions\\Select mission" msgstr "Misje\\Wybierz misję" @@ -1001,10 +995,10 @@ msgstr "Jeden krok" msgid "Open" msgstr "Otwórz" -msgid "Open (Ctrl+o)" +msgid "Open (Ctrl+O)" msgstr "Otwórz (Ctrl+O)" -msgid "Opening brace missing " +msgid "Opening brace missing" msgstr "Brak klamry otwierającej" msgid "Opening bracket missing" @@ -1028,13 +1022,13 @@ msgstr "Miejsce nadania wiadomości\\Pokazuje skąd została wysłana ostatnia w msgid "Original game developed by:" msgstr "Twórcy oryginalnej gry:" -msgid "Parameters missing " +msgid "Parameters missing" msgstr "Brak wymaganego parametru" msgid "Particles in the interface\\Steam clouds and sparks in the interface" msgstr "Cząstki w interfejsie\\Para i iskry z silników w interfejsie" -msgid "Paste (Ctrl+v)" +msgid "Paste (Ctrl+V)" msgstr "Wklej (Ctrl+V)" msgid "Pause in background\\Pause the game when the window is unfocused" @@ -1055,6 +1049,9 @@ msgstr "Fotografia" msgid "Place occupied" msgstr "Miejsce zajęte" +msgid "Planets:" +msgstr "Planety:" + msgid "Plans for defense tower available" msgstr "Dostępne plany wieży obronnej" @@ -1073,7 +1070,7 @@ msgstr "Dostępne plany działa" msgid "Plans for thumper available" msgstr "Dostępne plany robota uderzacza" -msgid "Plans for tracked robots available " +msgid "Plans for tracked robots available" msgstr "Dostępne plany tranporterów na gąsienicach" msgid "Plant a flag" @@ -1145,8 +1142,8 @@ msgstr "Ćwiczenia programistyczne" msgid "Programming help" msgstr "Podręcznik programowania" -msgid "Programming help (\\key prog;)" -msgstr "Podręcznik programowania (\\key prog;)" +msgid "Programming help (\\key prog;)" +msgstr "Podręcznik programowania (\\key prog;)" msgid "Programming help\\Gives more detailed help with programming" msgstr "Podręcznik programowania\\Dostarcza szczegółową pomoc w programowaniu" @@ -1223,6 +1220,9 @@ msgstr "Słowo zarezerwowane języka CBOT" msgid "Resolution" msgstr "Rozdzielczość" +msgid "Resolution:" +msgstr "Rozdzielczość:" + msgid "Resources" msgstr "Zasoby" @@ -1283,13 +1283,13 @@ msgstr "Raport z satelity" msgid "Save" msgstr "Zapisz" -msgid "Save (Ctrl+s)" +msgid "Save (Ctrl+S)" msgstr "Zapisz (Ctrl+S)" msgid "Save the current mission" msgstr "Zapisz bieżącą misję" -msgid "Save\\Save the current mission " +msgid "Save\\Save the current mission" msgstr "Zapisz\\Zapisuje bieżącą misję" msgid "Save\\Saves the current mission" @@ -1430,6 +1430,9 @@ msgstr "Kolor skafandra:" msgid "Suit\\Astronaut suit" msgstr "Skafander\\Skafander astronauty" +msgid "Summary:" +msgstr "Streszczenie:" + msgid "Survival kit" msgstr "Zestaw przetrwania" @@ -1457,13 +1460,13 @@ msgstr "Tekstury" msgid "The expression must return a boolean value" msgstr "Wyrażenie musi zwrócić wartość logiczną" -msgid "The function returned no value " -msgstr "Funkcja nie zwróciła żadnej wartości " +msgid "The function returned no value" +msgstr "Funkcja nie zwróciła żadnej wartości" msgid "The mission is not accomplished yet (press \\key help; for more details)" msgstr "Misja nie jest wypełniona (naciśnij \\key help; aby uzyskać szczegóły)" -msgid "The types of the two operands are incompatible " +msgid "The types of the two operands are incompatible" msgstr "Niezgodne typy operatorów" msgid "This class already exists" @@ -1568,7 +1571,7 @@ msgstr "Brak deklaracji typu" msgid "Unable to control enemy objects" msgstr "Nie można kontrolować wrogich obiektów" -msgid "Undo (Ctrl+z)" +msgid "Undo (Ctrl+Z)" msgstr "Cofnij (Ctrl+Z)" msgid "Unit" @@ -1700,7 +1703,7 @@ msgstr[0] "Możesz użyć \"%1$s\" najwyżej raz w tym ćwiczeniu (użyto: %2$d) msgstr[1] "Możesz użyć \"%1$s\" najwyżej %3$d razy w tym ćwiczeniu (użyto: %2$d)" msgstr[2] "Możesz użyć \"%1$s\" najwyżej %3$d razy w tym ćwiczeniu (użyto: %2$d)" -msgid "You must get on the spaceship to take off " +msgid "You must get on the spaceship to take off" msgstr "Musisz być na statku kosmicznym aby nim odlecieć" msgid "Zoom mini-map" @@ -1805,9 +1808,6 @@ msgstr "colobot.info" msgid "epsitec.com" msgstr "epsitec.com" -msgid "expression expected after =" -msgstr "" - #~ msgid " Drivers:" #~ msgstr " Sterowniki:" diff --git a/po/ru.po b/po/ru.po index d6d4d05e..9d5c0e31 100644 --- a/po/ru.po +++ b/po/ru.po @@ -18,38 +18,6 @@ msgstr "" "X-Language: ru_RU\n" "X-Source-Language: en_US\n" -msgid " Challenges in the chapter:" -msgstr " Задачи к главе:" - -msgid " Chapters:" -msgstr " Разделы:" - -#, fuzzy -msgid " Custom levels:" -msgstr " Пользовательские уровни:" - -msgid " Exercises in the chapter:" -msgstr " Упражнения в разделе:" - -msgid " Free game on this planet:" -msgstr " Свободная игра на этой планете:" - -#, fuzzy -msgid " Levels in this chapter:" -msgstr " Упражнения в разделе:" - -msgid " Missions on this planet:" -msgstr "Миссии на этой планете:" - -msgid " Planets:" -msgstr " Планеты:" - -msgid " Resolution:" -msgstr " Разрешение:" - -msgid " Summary:" -msgstr " Итог:" - msgid " or " msgstr " или " @@ -165,7 +133,7 @@ msgid "Back" msgstr "Назад" #, fuzzy -msgid "Background sound :\\Volume of audio tracks" +msgid "Background sound:\\Volume of audio tracks" msgstr "Фоновый звук:\\Громкость звуковых дорожек на CD" msgid "Backward (\\key down;)" @@ -374,6 +342,9 @@ msgstr "Отмена\\Отменить все изменения" msgid "Challenges" msgstr "Задания" +msgid "Challenges in the chapter:" +msgstr "Задачи к главе:" + msgid "Challenges\\Programming challenges" msgstr "Задания\\Практика программирования" @@ -383,6 +354,9 @@ msgstr "Изменить вид\\Переключение между борто msgid "Change player\\Change player" msgstr "Новый игрок\\Выберите имя для игрока" +msgid "Chapters:" +msgstr "Разделы:" + msgid "Cheat console\\Show cheat console" msgstr "" @@ -402,7 +376,7 @@ msgstr "Изменить выбранную программу" msgid "Close" msgstr "Закрыть" -msgid "Closing bracket missing " +msgid "Closing bracket missing" msgstr "Закрывающая скобка отсутствует" msgid "Code battles" @@ -441,19 +415,22 @@ msgstr "Преобразует руду в титан" msgid "Copy" msgstr "Копировать" -msgid "Copy (Ctrl+c)" +msgid "Copy (Ctrl+C)" msgstr "Копировать (Ctrl+C)" msgid "Current mission saved" msgstr "Текущая миссия сохранена" +msgid "Custom levels:" +msgstr "Пользовательские уровни:" + msgid "Custom levels\\Levels from mods created by the users" msgstr "" msgid "Customize your appearance" msgstr "Настроить свой внешний вид" -msgid "Cut (Ctrl+x)" +msgid "Cut (Ctrl+X)" msgstr "Вырезать (Ctrl+X)" msgid "Defense tower" @@ -494,10 +471,10 @@ msgid "Do you really want to destroy the selected building?" msgstr "Вы действительно хотите уничтожить выбранное здание?" #, c-format -msgid "Do you want to delete %s's saved games? " +msgid "Do you want to delete %s's saved games?" msgstr "Вы действительно хотите удалить сохраненные игры игрока %s?" -msgid "Doors blocked by a robot or another object " +msgid "Doors blocked by a robot or another object" msgstr "Двери заблокированы роботом или другим объектом" msgid "Down (\\key gdown;)" @@ -545,6 +522,9 @@ msgstr "Выполнить выбранную программу" msgid "Execute/stop" msgstr "Выполнить/стоп" +msgid "Exercises in the chapter:" +msgstr "Упражнения в разделе:" + msgid "Exercises\\Programming exercises" msgstr "Упражнения\\Упражнения по программированию" @@ -554,6 +534,9 @@ msgstr "" msgid "Explosive" msgstr "Взрывчатка" +msgid "Expression expected after =" +msgstr "" + msgid "Extend shield (\\key action;)" msgstr "Поднять щит (\\key action;)" @@ -624,6 +607,9 @@ msgstr "Найден ключ D (место для буровой вышки)" msgid "Free game" msgstr "Свободная игра" +msgid "Free game on this planet:" +msgstr "Свободная игра на этой планете:" + msgid "Free game\\Free game without a specific goal" msgstr "Свобод. игра\\Игра без четкой цели" @@ -738,7 +724,7 @@ msgstr "Отсутствует инструкция \"case\"" msgid "Instruction \"case\" outside a block \"switch\"" msgstr "Инструкция \"case\" вне блока \"switch\" " -msgid "Instruction \"else\" without corresponding \"if\" " +msgid "Instruction \"else\" without corresponding \"if\"" msgstr "Инструкция \"else\" без \"if\" " msgid "Instructions (\\key help;)" @@ -798,6 +784,9 @@ msgstr "Шагающий стрелок" msgid "Legged sniffer" msgstr "Шагающий искатель" +msgid "Levels in this chapter:" +msgstr "Упражнения в разделе:" + msgid "Lightning conductor" msgstr "Громоотвод" @@ -857,6 +846,9 @@ msgstr "Название миссии" msgid "Missions" msgstr "Миссии" +msgid "Missions on this planet:" +msgstr "Миссии на этой планете:" + msgid "Missions\\Select mission" msgstr "Миссии\\Выбор миссии" @@ -1015,11 +1007,11 @@ msgstr "Один шаг" msgid "Open" msgstr "Открыть" -msgid "Open (Ctrl+o)" -msgstr "Открыть (Ctrl+o)" +msgid "Open (Ctrl+O)" +msgstr "Открыть (Ctrl+O)" -msgid "Opening brace missing " -msgstr "Открывающая скобка отсутствует " +msgid "Opening brace missing" +msgstr "Открывающая скобка отсутствует" msgid "Opening bracket missing" msgstr "Открывающая скобка отсутствует" @@ -1042,13 +1034,13 @@ msgstr "Источник сообщения\\Показывает место, о msgid "Original game developed by:" msgstr "Оригинальная игра была разработана:" -msgid "Parameters missing " -msgstr "Отсутствуют параметры " +msgid "Parameters missing" +msgstr "Отсутствуют параметры" msgid "Particles in the interface\\Steam clouds and sparks in the interface" msgstr "Частицы в интерфейсе меню\\Пар из труб и искры в интерфейсе меню" -msgid "Paste (Ctrl+v)" +msgid "Paste (Ctrl+V)" msgstr "Вставить (Ctrl+V)" msgid "Pause in background\\Pause the game when the window is unfocused" @@ -1069,6 +1061,9 @@ msgstr "Фотография" msgid "Place occupied" msgstr "Место занято" +msgid "Planets:" +msgstr "Планеты:" + msgid "Plans for defense tower available" msgstr "Доступны схемы защитной башни" @@ -1087,8 +1082,8 @@ msgstr "Доступны схемы стрелка" msgid "Plans for thumper available" msgstr "Доступны схемы ударника" -msgid "Plans for tracked robots available " -msgstr "Доступны схемы гусеничных роботов " +msgid "Plans for tracked robots available" +msgstr "Доступны схемы гусеничных роботов" msgid "Plant a flag" msgstr "Установить флаг" @@ -1160,7 +1155,7 @@ msgstr "Упражнения" msgid "Programming help" msgstr "Помощь в программировании" -msgid "Programming help (\\key prog;)" +msgid "Programming help (\\key prog;)" msgstr "Помощь в программировании (\\key prog;)" msgid "Programming help\\Gives more detailed help with programming" @@ -1240,6 +1235,9 @@ msgstr "Резервное ключевое слово языка CBOT" msgid "Resolution" msgstr "Разрешение" +msgid "Resolution:" +msgstr "Разрешение:" + msgid "Resources" msgstr "" @@ -1300,13 +1298,13 @@ msgstr "Спутниковый отчет" msgid "Save" msgstr "Сохранить" -msgid "Save (Ctrl+s)" -msgstr "Сохранить (Ctrl+s)" +msgid "Save (Ctrl+S)" +msgstr "Сохранить (Ctrl+S)" msgid "Save the current mission" msgstr "Сохранить" -msgid "Save\\Save the current mission " +msgid "Save\\Save the current mission" msgstr "Сохранить\\Сохранить текущую миссию" msgid "Save\\Saves the current mission" @@ -1449,6 +1447,9 @@ msgstr "Костюм:" msgid "Suit\\Astronaut suit" msgstr "Костюм\\Костюм астронавта" +msgid "Summary:" +msgstr "Итог:" + msgid "Survival kit" msgstr "Аптечка" @@ -1476,13 +1477,13 @@ msgstr "" msgid "The expression must return a boolean value" msgstr "Выражение должно возвращать логическое значение" -msgid "The function returned no value " +msgid "The function returned no value" msgstr "Функция не возвратила значения" msgid "The mission is not accomplished yet (press \\key help; for more details)" msgstr "Миссия еще не выполнена (нажмите \\key help; для более подробной информации)" -msgid "The types of the two operands are incompatible " +msgid "The types of the two operands are incompatible" msgstr "Типы операндов несовместимы" msgid "This class already exists" @@ -1587,7 +1588,7 @@ msgstr "Не задан тип" msgid "Unable to control enemy objects" msgstr "" -msgid "Undo (Ctrl+z)" +msgid "Undo (Ctrl+Z)" msgstr "Отмена (Ctrl+Z)" msgid "Unit" @@ -1717,7 +1718,7 @@ msgid_plural "You have to use \"%1$s\" at most %3$d times in this exercise (used msgstr[0] "Не используй в этом упражнении" msgstr[1] "Не используй в этом упражнении" -msgid "You must get on the spaceship to take off " +msgid "You must get on the spaceship to take off" msgstr "Вы должны быть на борту корабля, чтобы взлететь" msgid "Zoom mini-map" @@ -1817,14 +1818,10 @@ msgid "\\Yellow flags" msgstr "\\Желтый флаг" msgid "colobot.info" -msgstr "" +msgstr "colobot.info" -#, fuzzy msgid "epsitec.com" -msgstr "www.epsitec.com" - -msgid "expression expected after =" -msgstr "" +msgstr "epsitec.com" #~ msgid " " #~ msgstr " " diff --git a/src/common/restext.cpp b/src/common/restext.cpp index a9644a36..c5cfd639 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -75,17 +75,17 @@ void InitializeRestext() stringsText[RT_TITLE_WRITE] = TR("Save the current mission"); stringsText[RT_TITLE_READ] = TR("Load a saved mission"); - stringsText[RT_PLAY_CHAP_CHAPTERS] = TR(" Chapters:"); - stringsText[RT_PLAY_CHAP_PLANETS] = TR(" Planets:"); - stringsText[RT_PLAY_CHAP_USERLVL] = TR(" Custom levels:"); - stringsText[RT_PLAY_LIST_LEVELS] = TR(" Levels in this chapter:"); - stringsText[RT_PLAY_LIST_EXERCISES] = TR(" Exercises in the chapter:"); - stringsText[RT_PLAY_LIST_CHALLENGES] = TR(" Challenges in the chapter:"); - stringsText[RT_PLAY_LIST_MISSIONS] = TR(" Missions on this planet:"); - stringsText[RT_PLAY_LIST_FREEGAME] = TR(" Free game on this planet:"); - stringsText[RT_PLAY_RESUME] = TR(" Summary:"); + stringsText[RT_PLAY_CHAP_CHAPTERS] = TR("Chapters:"); + stringsText[RT_PLAY_CHAP_PLANETS] = TR("Planets:"); + stringsText[RT_PLAY_CHAP_USERLVL] = TR("Custom levels:"); + stringsText[RT_PLAY_LIST_LEVELS] = TR("Levels in this chapter:"); + stringsText[RT_PLAY_LIST_EXERCISES] = TR("Exercises in the chapter:"); + stringsText[RT_PLAY_LIST_CHALLENGES] = TR("Challenges in the chapter:"); + stringsText[RT_PLAY_LIST_MISSIONS] = TR("Missions on this planet:"); + stringsText[RT_PLAY_LIST_FREEGAME] = TR("Free game on this planet:"); + stringsText[RT_PLAY_RESUME] = TR("Summary:"); - stringsText[RT_SETUP_MODE] = TR(" Resolution:"); + stringsText[RT_SETUP_MODE] = TR("Resolution:"); stringsText[RT_SETUP_KEY1] = TR("1) First click on the key you want to redefine."); stringsText[RT_SETUP_KEY2] = TR("2) Then press the key you want to use instead."); @@ -98,7 +98,7 @@ void InitializeRestext() stringsText[RT_DIALOG_ABORT] = TR("Abort\\Abort the current mission"); stringsText[RT_DIALOG_CONTINUE] = TR("Continue\\Continue the current mission"); stringsText[RT_DIALOG_DELOBJ] = TR("Do you really want to destroy the selected building?"); - stringsText[RT_DIALOG_DELGAME] = TR("Do you want to delete %s's saved games? "); + stringsText[RT_DIALOG_DELGAME] = TR("Do you want to delete %s's saved games?"); stringsText[RT_DIALOG_YES] = TR("Yes"); stringsText[RT_DIALOG_NO] = TR("No"); stringsText[RT_DIALOG_LOADING] = TR("LOADING"); @@ -163,7 +163,7 @@ void InitializeRestext() stringsEvent[EVENT_INTERFACE_NAME] = TR("Change player\\Change player"); stringsEvent[EVENT_INTERFACE_SETUP] = TR("Options\\Preferences"); stringsEvent[EVENT_INTERFACE_AGAIN] = TR("Restart\\Restart the mission from the beginning"); - stringsEvent[EVENT_INTERFACE_WRITE] = TR("Save\\Save the current mission "); + stringsEvent[EVENT_INTERFACE_WRITE] = TR("Save\\Save the current mission"); stringsEvent[EVENT_INTERFACE_READ] = TR("Load\\Load a saved mission"); stringsEvent[EVENT_INTERFACE_ABORT] = TR("\\Return to Colobot: Gold Edition"); stringsEvent[EVENT_INTERFACE_QUIT] = TR("Quit\\Quit Colobot: Gold Edition"); @@ -244,7 +244,7 @@ void InitializeRestext() stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_CMDLINE] = TR("Cheat console\\Show cheat console"); stringsEvent[EVENT_INTERFACE_VOLSOUND] = TR("Sound effects:\\Volume of engines, voice, shooting, etc."); - stringsEvent[EVENT_INTERFACE_VOLMUSIC] = TR("Background sound :\\Volume of audio tracks"); + stringsEvent[EVENT_INTERFACE_VOLMUSIC] = TR("Background sound:\\Volume of audio tracks"); stringsEvent[EVENT_INTERFACE_MIN] = TR("Lowest\\Minimum graphic quality (highest frame rate)"); stringsEvent[EVENT_INTERFACE_NORM] = TR("Normal\\Normal graphic quality"); @@ -442,15 +442,15 @@ void InitializeRestext() stringsEvent[EVENT_STUDIO_CANCEL] = TR("Cancel\\Cancel all changes"); stringsEvent[EVENT_STUDIO_CLONE] = TR("Clone program"); stringsEvent[EVENT_STUDIO_NEW] = TR("New"); - stringsEvent[EVENT_STUDIO_OPEN] = TR("Open (Ctrl+o)"); - stringsEvent[EVENT_STUDIO_SAVE] = TR("Save (Ctrl+s)"); - stringsEvent[EVENT_STUDIO_UNDO] = TR("Undo (Ctrl+z)"); - stringsEvent[EVENT_STUDIO_CUT] = TR("Cut (Ctrl+x)"); - stringsEvent[EVENT_STUDIO_COPY] = TR("Copy (Ctrl+c)"); - stringsEvent[EVENT_STUDIO_PASTE] = TR("Paste (Ctrl+v)"); + stringsEvent[EVENT_STUDIO_OPEN] = TR("Open (Ctrl+O)"); + stringsEvent[EVENT_STUDIO_SAVE] = TR("Save (Ctrl+S)"); + stringsEvent[EVENT_STUDIO_UNDO] = TR("Undo (Ctrl+Z)"); + stringsEvent[EVENT_STUDIO_CUT] = TR("Cut (Ctrl+X)"); + stringsEvent[EVENT_STUDIO_COPY] = TR("Copy (Ctrl+C)"); + stringsEvent[EVENT_STUDIO_PASTE] = TR("Paste (Ctrl+V)"); stringsEvent[EVENT_STUDIO_SIZE] = TR("Font size"); stringsEvent[EVENT_STUDIO_TOOL] = TR("Instructions (\\key help;)"); - stringsEvent[EVENT_STUDIO_HELP] = TR("Programming help (\\key prog;)"); + stringsEvent[EVENT_STUDIO_HELP] = TR("Programming help (\\key prog;)"); stringsEvent[EVENT_STUDIO_COMPILE] = TR("Compile"); stringsEvent[EVENT_STUDIO_RUN] = TR("Execute/stop"); stringsEvent[EVENT_STUDIO_REALTIME] = TR("Pause/continue"); @@ -611,8 +611,8 @@ void InitializeRestext() stringsErr[ERR_ENERGY_LOW] = TR("Not enough energy yet"); stringsErr[ERR_ENERGY_EMPTY] = TR("No titanium to transform"); stringsErr[ERR_ENERGY_BAD] = TR("Transforms only titanium"); - stringsErr[ERR_BASE_DLOCK] = TR("Doors blocked by a robot or another object "); - stringsErr[ERR_BASE_DHUMAN] = TR("You must get on the spaceship to take off "); + stringsErr[ERR_BASE_DLOCK] = TR("Doors blocked by a robot or another object"); + stringsErr[ERR_BASE_DHUMAN] = TR("You must get on the spaceship to take off"); stringsErr[ERR_LABO_NULL] = TR("Nothing to analyze"); stringsErr[ERR_LABO_BAD] = TR("Analyzes only organic matter"); stringsErr[ERR_LABO_ALREADY] = TR("Analysis already performed"); @@ -643,7 +643,7 @@ void InitializeRestext() stringsErr[INFO_BUILD] = TR("Building completed"); stringsErr[INFO_CONVERT] = TR("Titanium available"); stringsErr[INFO_RESEARCH] = TR("Research program completed"); - stringsErr[INFO_RESEARCHTANK] = TR("Plans for tracked robots available "); + stringsErr[INFO_RESEARCHTANK] = TR("Plans for tracked robots available"); stringsErr[INFO_RESEARCHFLY] = TR("You can fly with the keys (\\key gup;) and (\\key gdown;)"); stringsErr[INFO_RESEARCHTHUMP] = TR("Plans for thumper available"); stringsErr[INFO_RESEARCHCANON] = TR("Plans for shooter available"); @@ -677,7 +677,7 @@ void InitializeRestext() stringsCbot[CBot::CBotErrOpenPar] = TR("Opening bracket missing"); - stringsCbot[CBot::CBotErrClosePar] = TR("Closing bracket missing "); + stringsCbot[CBot::CBotErrClosePar] = TR("Closing bracket missing"); stringsCbot[CBot::CBotErrNotBoolean] = TR("The expression must return a boolean value"); stringsCbot[CBot::CBotErrUndefVar] = TR("Variable not declared"); stringsCbot[CBot::CBotErrBadLeft] = TR("Assignment impossible"); @@ -685,11 +685,11 @@ void InitializeRestext() stringsCbot[CBot::CBotErrCaseOut] = TR("Instruction \"case\" outside a block \"switch\""); stringsCbot[CBot::CBotErrNoEnd] = TR("Instructions after the final closing brace"); stringsCbot[CBot::CBotErrCloseBlock] = TR("End of block missing"); - stringsCbot[CBot::CBotErrElseWhitoutIf] = TR("Instruction \"else\" without corresponding \"if\" "); - stringsCbot[CBot::CBotErrOpenBlock] = TR("Opening brace missing "); + stringsCbot[CBot::CBotErrElseWhitoutIf] = TR("Instruction \"else\" without corresponding \"if\""); + stringsCbot[CBot::CBotErrOpenBlock] = TR("Opening brace missing"); stringsCbot[CBot::CBotErrBadType1] = TR("Wrong type for the assignment"); stringsCbot[CBot::CBotErrRedefVar] = TR("A variable can not be declared twice"); - stringsCbot[CBot::CBotErrBadType2] = TR("The types of the two operands are incompatible "); + stringsCbot[CBot::CBotErrBadType2] = TR("The types of the two operands are incompatible"); stringsCbot[CBot::CBotErrUndefCall] = TR("Unknown function"); stringsCbot[CBot::CBotErrNoDoubleDots] = TR("Sign \" : \" missing"); stringsCbot[CBot::CBotErrNoWhile] = TR("Keyword \"while\" missing"); @@ -704,7 +704,7 @@ void InitializeRestext() stringsCbot[CBot::CBotErrNoFunc] = TR("Function name missing"); stringsCbot[CBot::CBotErrOverParam] = TR("Too many parameters"); stringsCbot[CBot::CBotErrRedefFunc] = TR("Function already exists"); - stringsCbot[CBot::CBotErrLowParam] = TR("Parameters missing "); + stringsCbot[CBot::CBotErrLowParam] = TR("Parameters missing"); stringsCbot[CBot::CBotErrBadParam] = TR("No function with this name accepts this kind of parameter"); stringsCbot[CBot::CBotErrNbParam] = TR("No function with this name accepts this number of parameters"); stringsCbot[CBot::CBotErrUndefItem] = TR("This is not a member of this class"); @@ -719,12 +719,12 @@ void InitializeRestext() stringsCbot[CBot::CBotErrBadIndex] = TR("Incorrect index type"); stringsCbot[CBot::CBotErrPrivate] = TR("Private element"); stringsCbot[CBot::CBotErrNoPublic] = TR("Public required"); - stringsCbot[CBot::CBotErrNoExpression] = TR("expression expected after ="); + stringsCbot[CBot::CBotErrNoExpression] = TR("Expression expected after ="); stringsCbot[CBot::CBotErrZeroDiv] = TR("Dividing by zero"); stringsCbot[CBot::CBotErrNotInit] = TR("Variable not initialized"); stringsCbot[CBot::CBotErrBadThrow] = TR("Negative value rejected by \"throw\""); - stringsCbot[CBot::CBotErrNoRetVal] = TR("The function returned no value "); + stringsCbot[CBot::CBotErrNoRetVal] = TR("The function returned no value"); stringsCbot[CBot::CBotErrNoRun] = TR("No function running"); stringsCbot[CBot::CBotErrUndefFunc] = TR("Calling an unknown function"); stringsCbot[CBot::CBotErrNotClass] = TR("This class does not exist"); From d80fa387b9949bc8fad407a4847862f88973ce94 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 May 2016 16:16:48 +0200 Subject: [PATCH 086/125] Fixed some particle crashes after 99a831a03be068dd0c40ee3a7ca162cdcfb5e85d --- src/graphics/engine/particle.cpp | 24 ++++++++++++------------ src/graphics/engine/particle.h | 6 +++++- src/object/old_object.cpp | 1 + 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index 2642b74e..5f8b1601 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -641,22 +641,22 @@ void CParticle::GetRankFromChannel(int &channel) int uniqueStamp = (channel>>16)&0xffff; channel &= 0xffff; - assert(channel >= 0 && channel < MAXPARTICULE*MAXPARTITYPE); - - if (!m_particle[channel].used) assert(!!"Tried to access invalid particle channel (used=false) !\n"); - if (m_particle[channel].uniqueStamp != uniqueStamp) assert(!!"Tried to access invalid particle channel (uniqueStamp changed) !\n"); + if (channel < 0 || channel >= MAXPARTICULE*MAXPARTITYPE) throw std::runtime_error("Tried to access invalid particle channel (invalid ID)"); + if (!m_particle[channel].used) throw std::runtime_error("Tried to access invalid particle channel (used=false)"); + if (m_particle[channel].uniqueStamp != uniqueStamp) throw std::runtime_error("Tried to access invalid particle channel (uniqueStamp changed)"); } bool CParticle::ParticleExists(int channel) { - int uniqueStamp = (channel>>16)&0xffff; - channel &= 0xffff; - - assert(channel >= 0 && channel < MAXPARTICULE*MAXPARTITYPE); - - if (!m_particle[channel].used) return false; - if (m_particle[channel].uniqueStamp != uniqueStamp) return false; - return true; + try + { + GetRankFromChannel(channel); + return true; + } + catch (const std::runtime_error& e) + { + return false; + } } void CParticle::DeleteRank(int rank) diff --git a/src/graphics/engine/particle.h b/src/graphics/engine/particle.h index 55ef7baa..ec8d8820 100644 --- a/src/graphics/engine/particle.h +++ b/src/graphics/engine/particle.h @@ -297,7 +297,11 @@ public: protected: //! Removes a particle of given rank void DeleteRank(int rank); - //! Adapts the channel so it can be used as an offset in m_particle + /** + * \brief Adapts the channel so it can be used as an offset in m_particle + * \param channel Channel number to process, will be modified to be index of particle in m_particle + * \throw std::runtime_error if this particle does not exist any more + **/ void GetRankFromChannel(int &channel); //! Draws a triangular particle void DrawParticleTriangle(int i); diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index 7c2682d8..d945c5c8 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -2975,6 +2975,7 @@ void COldObject::UpdateSelectParticle() // Updates lens. for ( i=0 ; i<4 ; i++ ) { + if (m_partiSel[i] == -1) continue; pos[i] = Math::Transform(m_objectPart[0].matWorld, pos[i]); dim[i].y = dim[i].x; m_particle->SetParam(m_partiSel[i], pos[i], dim[i], zoom[i], angle, 1.0f); From bef27c3b3622c3646aadd16864bdadf364bc7e29 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 May 2016 16:48:36 +0200 Subject: [PATCH 087/125] Removed unused parameter from CEngine::SetViewParams --- src/graphics/engine/camera.cpp | 4 +--- src/graphics/engine/camera.h | 8 +++----- src/graphics/engine/engine.cpp | 3 +-- src/graphics/engine/engine.h | 3 +-- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index 44626130..8ce981b4 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -88,7 +88,6 @@ CCamera::CCamera() m_smooth = CAM_SMOOTH_NORM; m_cameraObj = nullptr; - m_eyeDistance = 10.0f; m_initDelay = 0.0f; m_actualEye = Math::Vector(0.0f, 0.0f, 0.0f); @@ -223,7 +222,6 @@ void CCamera::Init(Math::Vector eye, Math::Vector lookat, float delay) m_directionH = Math::RotateAngle(eye.x - lookat.x, eye.z - lookat.z) + Math::PI / 2.0f; m_directionV = -Math::RotateAngle(Math::DistanceProjected(eye, lookat), eye.y - lookat.y); - m_eyeDistance = 10.0f; m_heightLookat = 10.0f; m_backDist = 30.0f; m_backMin = 10.0f; @@ -1528,7 +1526,7 @@ void CCamera::SetScriptLookat(Math::Vector lookat) void CCamera::SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up) { - m_engine->SetViewParams(eye, lookat, up, m_eyeDistance); + m_engine->SetViewParams(eye, lookat, up); bool under = (eye.y < m_water->GetLevel()); // Is it underwater? if (m_type == CAM_TYPE_INFO) diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index ff4d62e7..5f995665 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -282,8 +282,6 @@ protected: //! Object linked to the camera CObject* m_cameraObj; - //! Distance between the eyes - float m_eyeDistance; //! Time of initial centering float m_initDelay; @@ -293,11 +291,11 @@ protected: Math::Vector m_actualLookat; //! Final eye Math::Vector m_finalEye; - //! Final aim + //! Final lookat Math::Vector m_finalLookat; - //! Normal eye + //! Eye position at the moment of entering CAM_TYPE_INFO/CAM_TYPE_VISIT Math::Vector m_normEye; - //! Normal aim + //! Lookat position at the moment of entering CAM_TYPE_INFO/CAM_TYPE_VISIT Math::Vector m_normLookat; float m_focus; diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index d8666731..8eb92754 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -2184,8 +2184,7 @@ void CEngine::SetMaterial(const Material& mat) m_device->SetMaterial(mat); } -void CEngine::SetViewParams(const Math::Vector& eyePt, const Math::Vector& lookatPt, - const Math::Vector& upVec, float eyeDistance) +void CEngine::SetViewParams(const Math::Vector &eyePt, const Math::Vector &lookatPt, const Math::Vector &upVec) { m_eyePt = eyePt; m_lookatPt = lookatPt; diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 8fb195a2..e60e6e37 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -901,8 +901,7 @@ public: void SetMaterial(const Material& mat); //! Specifies the location and direction of view - void SetViewParams(const Math::Vector& eyePt, const Math::Vector& lookatPt, - const Math::Vector& upVec, float eyeDistance); + void SetViewParams(const Math::Vector &eyePt, const Math::Vector &lookatPt, const Math::Vector &upVec); //! Loads texture, creating it if not already present Texture LoadTexture(const std::string& name); From 646e5104f6850154004f8a6c4dc82d85c4cc509d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 May 2016 18:42:48 +0200 Subject: [PATCH 088/125] Some CCamera cleanup and docs --- src/app/pathman.h | 2 +- src/common/event.cpp | 4 - src/common/restext.cpp | 4 - src/graphics/engine/camera.cpp | 505 ++++++++------------- src/graphics/engine/camera.h | 225 ++++----- src/graphics/opengl/gl21device.h | 2 +- src/level/mainmovie.cpp | 8 +- src/level/robotmain.cpp | 120 ----- src/level/robotmain.h | 5 - src/object/auto/autobase.cpp | 81 ++-- src/object/auto/autoportico.cpp | 29 +- src/object/interface/controllable_object.h | 4 - src/object/old_object.cpp | 12 - src/object/old_object.h | 3 - src/ui/object_interface.cpp | 20 - src/ui/screen/screen_apperance.cpp | 14 +- 16 files changed, 377 insertions(+), 661 deletions(-) diff --git a/src/app/pathman.h b/src/app/pathman.h index 9c5ed609..059c81fe 100644 --- a/src/app/pathman.h +++ b/src/app/pathman.h @@ -18,7 +18,7 @@ */ /** - * \file common/pathman.h + * \file app/pathman.h * \brief Class for managing data/lang/save paths */ diff --git a/src/common/event.cpp b/src/common/event.cpp index 5ffe4753..10d1ae9f 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -480,10 +480,6 @@ void InitializeEventTypeTexts() EVENT_TYPE_TEXT[EVENT_OBJECT_CAMERA] = "EVENT_OBJECT_CAMERA"; EVENT_TYPE_TEXT[EVENT_OBJECT_HELP] = "EVENT_OBJECT_HELP"; EVENT_TYPE_TEXT[EVENT_OBJECT_SOLUCE] = "EVENT_OBJECT_SOLUCE"; - EVENT_TYPE_TEXT[EVENT_OBJECT_CAMERAleft] = "EVENT_OBJECT_CAMERAleft"; - EVENT_TYPE_TEXT[EVENT_OBJECT_CAMERAright]= "EVENT_OBJECT_CAMERAright"; - EVENT_TYPE_TEXT[EVENT_OBJECT_CAMERAnear] = "EVENT_OBJECT_CAMERAnear"; - EVENT_TYPE_TEXT[EVENT_OBJECT_CAMERAaway] = "EVENT_OBJECT_CAMERAaway"; EVENT_TYPE_TEXT[EVENT_OBJECT_SHORTCUT_MODE] = "EVENT_OBJECT_SHORTCUT_MODE"; EVENT_TYPE_TEXT[EVENT_OBJECT_MOVIELOCK] = "EVENT_OBJECT_MOVIELOCK"; EVENT_TYPE_TEXT[EVENT_OBJECT_EDITLOCK] = "EVENT_OBJECT_EDITLOCK"; diff --git a/src/common/restext.cpp b/src/common/restext.cpp index c5cfd639..df63d839 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -394,10 +394,6 @@ void InitializeRestext() stringsEvent[EVENT_OBJECT_GINFO] = TR("Transmitted information"); stringsEvent[EVENT_OBJECT_MAPZOOM] = TR("Zoom mini-map"); stringsEvent[EVENT_OBJECT_CAMERA] = TR("Camera (\\key camera;)"); - stringsEvent[EVENT_OBJECT_CAMERAleft] = TR("Camera to left"); - stringsEvent[EVENT_OBJECT_CAMERAright] = TR("Camera to right"); - stringsEvent[EVENT_OBJECT_CAMERAnear] = TR("Camera nearest"); - stringsEvent[EVENT_OBJECT_CAMERAaway] = TR("Camera awayest"); stringsEvent[EVENT_OBJECT_HELP] = TR("Help about selected object"); stringsEvent[EVENT_OBJECT_SOLUCE] = TR("Show the solution"); stringsEvent[EVENT_OBJECT_SHORTCUT_MODE]= TR("Switch bots <-> buildings"); diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index 8ce981b4..08994999 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -94,8 +94,8 @@ CCamera::CCamera() m_actualLookat = Math::Vector(0.0f, 0.0f, 0.0f); m_finalEye = Math::Vector(0.0f, 0.0f, 0.0f); m_finalLookat = Math::Vector(0.0f, 0.0f, 0.0f); - m_normEye = Math::Vector(0.0f, 0.0f, 0.0f); - m_normLookat = Math::Vector(0.0f, 0.0f, 0.0f); + m_prevEye = Math::Vector(0.0f, 0.0f, 0.0f); + m_prevLookat = Math::Vector(0.0f, 0.0f, 0.0f); m_focus = 1.0f; m_eyePt = Math::Vector(0.0f, 0.0f, 0.0f); @@ -109,7 +109,6 @@ CCamera::CCamera() m_backMin = 0.0f; m_addDirectionH = 0.0f; m_addDirectionV = 0.0f; - m_transparency = false; m_fixDist = 0.0f; m_fixDirectionH = 0.0f; @@ -121,8 +120,6 @@ CCamera::CCamera() m_visitType = CAM_TYPE_NULL; m_visitDirectionV = 0.0f; - m_remotePan = 0.0f; - m_centeringPhase = CAM_PHASE_NULL; m_centeringAngleH = 0.0f; m_centeringAngleV = 0.0f; @@ -238,7 +235,6 @@ void CCamera::Init(Math::Vector eye, Math::Vector lookat, float delay) m_scriptEye = m_actualEye; m_scriptLookat = m_actualLookat; m_focus = 1.00f; - m_remotePan = 0.0f; FlushEffect(); FlushOver(); @@ -258,9 +254,7 @@ CObject* CCamera::GetControllingObject() void CCamera::SetType(CameraType type) { - m_remotePan = 0.0f; - - if ( (m_type == CAM_TYPE_BACK) && m_transparency ) + if ( (m_type == CAM_TYPE_BACK) ) { for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { @@ -270,13 +264,12 @@ void CCamera::SetType(CameraType type) SetTransparency(obj, 0.0f); // opaque object } } - m_transparency = false; if (type == CAM_TYPE_INFO || type == CAM_TYPE_VISIT) // xx -> info ? { - m_normEye = m_engine->GetEyePt(); - m_normLookat = m_engine->GetLookatPt(); + m_prevEye = m_engine->GetEyePt(); + m_prevLookat = m_engine->GetLookatPt(); m_engine->SetFocus(1.00f); // normal m_type = type; @@ -290,7 +283,7 @@ void CCamera::SetType(CameraType type) m_type = type; Math::Vector upVec = Math::Vector(0.0f, 1.0f, 0.0f); - SetViewParams(m_normEye, m_normLookat, upVec); + SetViewParams(m_prevEye, m_prevLookat, upVec); return; } @@ -386,70 +379,6 @@ CameraSmooth CCamera::GetSmooth() return m_smooth; } -void CCamera::SetDist(float dist) -{ - m_fixDist = dist; -} - -float CCamera::GetDist() -{ - return m_fixDist; -} - -void CCamera::SetFixDirectionH(float angle) -{ - m_fixDirectionH = angle; -} - -float CCamera::GetFixDirectionH() -{ - return m_fixDirectionH; -} - -void CCamera::SetFixDirectionV(float angle) -{ - m_fixDirectionV = angle; -} - -float CCamera::GetFixDirectionV() -{ - return m_fixDirectionV; -} - -void CCamera::SetRemotePan(float value) -{ - m_remotePan = value; -} - -float CCamera::GetRemotePan() -{ - return m_remotePan; -} - -void CCamera::SetRemoteZoom(float value) -{ - value = Math::Norm(value); - - if ( m_type == CAM_TYPE_BACK ) - m_backDist = m_backMin + (200.0f - m_backMin) * value; - - if ( m_type == CAM_TYPE_FIX || - m_type == CAM_TYPE_PLANE ) - m_fixDist = 10.0f + (200.0f - 10.0f) * value; -} - -float CCamera::GetRemoteZoom() -{ - if ( m_type == CAM_TYPE_BACK ) - return (m_backDist - m_backMin) / (200.0f - m_backMin); - - if ( m_type == CAM_TYPE_FIX || - m_type == CAM_TYPE_PLANE ) - return (m_fixDist - 10.0f) / (200.0f - 10.0f); - - return 0.0f; -} - void CCamera::StartVisit(Math::Vector goal, float dist) { m_visitType = m_type; @@ -824,98 +753,74 @@ void CCamera::OverFrame(const Event &event) } } -void CCamera::FixCamera() +void CCamera::UpdateCameraAnimation(const Math::Vector &eyePt, + const Math::Vector &lookatPt, + float rTime) { - m_initDelay = 0.0f; - m_actualEye = m_finalEye = m_scriptEye; - m_actualLookat = m_finalLookat = m_scriptLookat; - SetViewTime(m_scriptEye, m_scriptLookat, 0.0f); -} - -void CCamera::SetViewTime(const Math::Vector &eyePt, - const Math::Vector &lookatPt, - float rTime) -{ - Math::Vector eye, lookat; - - if (m_type == CAM_TYPE_INFO) + if (m_initDelay > 0.0f) { - eye = eyePt; - lookat = lookatPt; + m_initDelay -= rTime; + if (m_initDelay < 0.0f) + m_initDelay = 0.0f; + rTime /= 1.0f+m_initDelay; + } + + m_finalEye = eyePt; + m_finalLookat = lookatPt; + IsCollision(m_finalEye, m_finalLookat); + + float prog = 0.0f; + float dist = Math::Distance(m_finalEye, m_actualEye); + + if (m_smooth == CAM_SMOOTH_NONE) prog = dist; + if (m_smooth == CAM_SMOOTH_NORM) prog = powf(dist, 1.5f) * rTime * 0.75f; + if (m_smooth == CAM_SMOOTH_HARD) prog = dist * rTime * 4.0f; + if (dist == 0.0f) + { + m_actualEye = m_finalEye; } else { - if (m_initDelay > 0.0f) - { - m_initDelay -= rTime; - if (m_initDelay < 0.0f) - m_initDelay = 0.0f; - rTime /= 1.0f+m_initDelay; - } - - eye = eyePt; - lookat = lookatPt; - if ( !IsCollision(eye, lookat) ) - { - m_finalEye = eye; - m_finalLookat = lookat; - } - - float prog = 0.0f; - float dist = Math::Distance(m_finalEye, m_actualEye); - - if (m_smooth == CAM_SMOOTH_NONE) prog = dist; - if (m_smooth == CAM_SMOOTH_NORM) prog = powf(dist, 1.5f) * rTime * 0.75f; - if (m_smooth == CAM_SMOOTH_HARD) prog = dist * rTime * 4.0f; - if (dist == 0.0f) - { - m_actualEye = m_finalEye; - } - else - { - if (prog > dist) - prog = dist; - m_actualEye = (m_finalEye - m_actualEye) / dist * prog + m_actualEye; - } - - dist = Math::Distance(m_finalLookat, m_actualLookat); - if ( m_smooth == CAM_SMOOTH_NONE ) prog = dist; - if ( m_smooth == CAM_SMOOTH_NORM ) prog = powf(dist, 1.5f) * rTime * 3.0f; - if ( m_smooth == CAM_SMOOTH_HARD ) prog = dist * rTime * 4.0f; - if ( dist == 0.0f ) - { - m_actualLookat = m_finalLookat; - } - else - { - if (prog > dist) - prog = dist; - m_actualLookat = (m_finalLookat - m_actualLookat) / dist * prog + m_actualLookat; - } - - eye = m_effectOffset+m_actualEye; - m_water->AdjustEye(eye); - - float h = m_terrain->GetFloorLevel(eye); - if (eye.y < h + 4.0f) - eye.y = h + 4.0f; - - lookat = m_effectOffset+m_actualLookat; + if (prog > dist) + prog = dist; + m_actualEye = (m_finalEye - m_actualEye) / dist * prog + m_actualEye; } - Math::Vector upVec = Math::Vector(0.0f, 1.0f, 0.0f); - SetViewParams(eye, lookat, upVec); + dist = Math::Distance(m_finalLookat, m_actualLookat); + if ( m_smooth == CAM_SMOOTH_NONE ) prog = dist; + if ( m_smooth == CAM_SMOOTH_NORM ) prog = powf(dist, 1.5f) * rTime * 3.0f; + if ( m_smooth == CAM_SMOOTH_HARD ) prog = dist * rTime * 4.0f; + if ( dist == 0.0f ) + { + m_actualLookat = m_finalLookat; + } + else + { + if (prog > dist) + prog = dist; + m_actualLookat = (m_finalLookat - m_actualLookat) / dist * prog + m_actualLookat; + } + + Math::Vector eye = m_effectOffset+m_actualEye; + m_water->AdjustEye(eye); + + float h = m_terrain->GetFloorLevel(eye); + if (eye.y < h + 4.0f) + eye.y = h + 4.0f; + + Math::Vector lookat = m_effectOffset+m_actualLookat; + + SetViewParams(eye, lookat); } -bool CCamera::IsCollision(Math::Vector &eye, Math::Vector lookat) +void CCamera::IsCollision(Math::Vector &eye, Math::Vector lookat) { - if (m_type == CAM_TYPE_BACK ) return IsCollisionBack(eye, lookat); - if (m_type == CAM_TYPE_FIX ) return IsCollisionFix (eye, lookat); - if (m_type == CAM_TYPE_PLANE) return IsCollisionFix (eye, lookat); - return false; + if (m_type == CAM_TYPE_BACK ) IsCollisionBack(); + if (m_type == CAM_TYPE_FIX ) IsCollisionFix (eye, lookat); + if (m_type == CAM_TYPE_PLANE) IsCollisionFix (eye, lookat); } -bool CCamera::IsCollisionBack(Math::Vector &eye, Math::Vector lookat) +void CCamera::IsCollisionBack() { ObjectType iType; if (m_cameraObj == nullptr) @@ -933,8 +838,6 @@ bool CCamera::IsCollisionBack(Math::Vector &eye, Math::Vector lookat) max.y = Math::Max(m_actualEye.y, m_actualLookat.y); max.z = Math::Max(m_actualEye.z, m_actualLookat.z); - m_transparency = false; - for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { if (IsObjectBeingTransported(obj)) @@ -1001,12 +904,10 @@ bool CCamera::IsCollisionBack(Math::Vector &eye, Math::Vector lookat) if (len > del) continue; SetTransparency(obj, 1.0f); // transparent object - m_transparency = true; } - return false; } -bool CCamera::IsCollisionFix(Math::Vector &eye, Math::Vector lookat) +void CCamera::IsCollisionFix(Math::Vector &eye, Math::Vector lookat) { for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { @@ -1041,165 +942,135 @@ bool CCamera::IsCollisionFix(Math::Vector &eye, Math::Vector lookat) dist = Math::Distance(eye, lookat); Math::Vector proj = Projection(eye, lookat, objPos); eye = (lookat - eye) * objRadius / dist + proj; - return false; + return; } } - return false; } bool CCamera::EventProcess(const Event &event) { - switch (event.type) + if (event.type == EVENT_MOUSE_MOVE) { - case EVENT_FRAME: - EventFrame(event); - break; + if (m_engine->GetMouseType() == ENG_MOUSE_SCROLLR || + m_engine->GetMouseType() == ENG_MOUSE_SCROLLL || + m_engine->GetMouseType() == ENG_MOUSE_SCROLLU || + m_engine->GetMouseType() == ENG_MOUSE_SCROLLD || + m_engine->GetMouseType() == ENG_MOUSE_MOVE ) + { + m_engine->SetMouseType(ENG_MOUSE_NORM); + } - case EVENT_MOUSE_BUTTON_DOWN: - case EVENT_MOUSE_BUTTON_UP: - EventMouseButton(event); - break; + if ((event.mouseButtonsState & MOUSE_BUTTON_RIGHT) != 0 || (event.mouseButtonsState & MOUSE_BUTTON_MIDDLE) != 0) + { + Math::Point newDelta = event.mousePos - m_mousePos; + if (m_cameraInvertX) + newDelta.x = -newDelta.x; + if (m_cameraInvertY) + newDelta.y = -newDelta.y; + m_mouseDelta += newDelta; - case EVENT_MOUSE_MOVE: - EventMouseMove(event); - break; + m_engine->SetMouseType(ENG_MOUSE_MOVE); + } - case EVENT_MOUSE_WHEEL: - EventMouseWheel(event); - break; + m_mouseDeltaEdge.LoadZero(); + if (m_oldCameraScroll) + { + if (event.mousePos.x < MOUSE_EDGE_MARGIN) + m_mouseDeltaEdge.x = event.mousePos.x / MOUSE_EDGE_MARGIN - 1.0f; + if (event.mousePos.x > 1.0f - MOUSE_EDGE_MARGIN) + m_mouseDeltaEdge.x = 1.0f - (1.0f - event.mousePos.x) / MOUSE_EDGE_MARGIN; + if (event.mousePos.y < MOUSE_EDGE_MARGIN) + m_mouseDeltaEdge.y = event.mousePos.y / MOUSE_EDGE_MARGIN - 1.0f; + if (event.mousePos.y > 1.0f - MOUSE_EDGE_MARGIN) + m_mouseDeltaEdge.y = 1.0f - (1.0f - event.mousePos.y) / MOUSE_EDGE_MARGIN; - default: - break; - } - return true; -} + if (m_type == CAM_TYPE_FREE || + m_type == CAM_TYPE_EDIT || + m_type == CAM_TYPE_BACK || + m_type == CAM_TYPE_FIX || + m_type == CAM_TYPE_PLANE || + m_type == CAM_TYPE_EXPLO ) + { + if (m_mouseDeltaEdge.x > 0.0f) + m_engine->SetMouseType(ENG_MOUSE_SCROLLR); + if (m_mouseDeltaEdge.x < 0.0f) + m_engine->SetMouseType(ENG_MOUSE_SCROLLL); + } + if (m_type == CAM_TYPE_FREE || + m_type == CAM_TYPE_EDIT ) + { + if (m_mouseDeltaEdge.y > 0.0f) + m_engine->SetMouseType(ENG_MOUSE_SCROLLU); + if (m_mouseDeltaEdge.y < 0.0f) + m_engine->SetMouseType(ENG_MOUSE_SCROLLD); + } -bool CCamera::EventMouseMove(const Event &event) -{ - if (m_engine->GetMouseType() == ENG_MOUSE_SCROLLR || - m_engine->GetMouseType() == ENG_MOUSE_SCROLLL || - m_engine->GetMouseType() == ENG_MOUSE_SCROLLU || - m_engine->GetMouseType() == ENG_MOUSE_SCROLLD || - m_engine->GetMouseType() == ENG_MOUSE_MOVE ) - { - m_engine->SetMouseType(ENG_MOUSE_NORM); + m_mouseDeltaEdge.x /= 2*Math::PI; + m_mouseDeltaEdge.y /= Math::PI; + } + + m_mousePos = event.mousePos; } - if ((event.mouseButtonsState & MOUSE_BUTTON_RIGHT) != 0 || (event.mouseButtonsState & MOUSE_BUTTON_MIDDLE) != 0) + if (event.type == EVENT_MOUSE_WHEEL) { - Math::Point newDelta = event.mousePos - m_mousePos; + auto dir = event.GetData()->y; + m_mouseWheelDelta -= dir; + } + + if (event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP) + { + if (event.GetData()->button == MOUSE_BUTTON_RIGHT || event.GetData()->button == MOUSE_BUTTON_MIDDLE) + { + if ((event.mouseButtonsState & MOUSE_BUTTON_RIGHT) != 0 || (event.mouseButtonsState & MOUSE_BUTTON_MIDDLE) != 0) + { + m_engine->SetMouseType(ENG_MOUSE_MOVE); + } + else + { + m_engine->SetMouseType(ENG_MOUSE_NORM); + } + } + } + + if (event.type == EVENT_FRAME && !m_freeze) + { + Math::Point newDelta = m_mouseDeltaEdge * m_speed * event.rTime; if (m_cameraInvertX) newDelta.x = -newDelta.x; if (m_cameraInvertY) newDelta.y = -newDelta.y; m_mouseDelta += newDelta; - m_engine->SetMouseType(ENG_MOUSE_MOVE); - } + EffectFrame(event); + OverFrame(event); - m_mouseDeltaEdge.LoadZero(); - if (m_oldCameraScroll) - { - if (event.mousePos.x < MOUSE_EDGE_MARGIN) - m_mouseDeltaEdge.x = event.mousePos.x / MOUSE_EDGE_MARGIN - 1.0f; - if (event.mousePos.x > 1.0f - MOUSE_EDGE_MARGIN) - m_mouseDeltaEdge.x = 1.0f - (1.0f - event.mousePos.x) / MOUSE_EDGE_MARGIN; - if (event.mousePos.y < MOUSE_EDGE_MARGIN) - m_mouseDeltaEdge.y = event.mousePos.y / MOUSE_EDGE_MARGIN - 1.0f; - if (event.mousePos.y > 1.0f - MOUSE_EDGE_MARGIN) - m_mouseDeltaEdge.y = 1.0f - (1.0f - event.mousePos.y) / MOUSE_EDGE_MARGIN; - - if (m_type == CAM_TYPE_FREE || - m_type == CAM_TYPE_EDIT || - m_type == CAM_TYPE_BACK || - m_type == CAM_TYPE_FIX || - m_type == CAM_TYPE_PLANE || - m_type == CAM_TYPE_EXPLO ) - { - if (m_mouseDeltaEdge.x > 0.0f) - m_engine->SetMouseType(ENG_MOUSE_SCROLLR); - if (m_mouseDeltaEdge.x < 0.0f) - m_engine->SetMouseType(ENG_MOUSE_SCROLLL); - } if (m_type == CAM_TYPE_FREE || - m_type == CAM_TYPE_EDIT ) - { - if (m_mouseDeltaEdge.y > 0.0f) - m_engine->SetMouseType(ENG_MOUSE_SCROLLU); - if (m_mouseDeltaEdge.y < 0.0f) - m_engine->SetMouseType(ENG_MOUSE_SCROLLD); - } + m_type == CAM_TYPE_EDIT) + return EventFrameFree(event, m_type != CAM_TYPE_EDIT); - m_mouseDeltaEdge.x /= 2*Math::PI; - m_mouseDeltaEdge.y /= Math::PI; + if (m_type == CAM_TYPE_BACK) + return EventFrameBack(event); + + if (m_type == CAM_TYPE_FIX || + m_type == CAM_TYPE_PLANE) + return EventFrameFix(event); + + if (m_type == CAM_TYPE_EXPLO) + return EventFrameExplo(event); + + if (m_type == CAM_TYPE_ONBOARD) + return EventFrameOnBoard(event); + + if (m_type == CAM_TYPE_SCRIPT) + return EventFrameScript(event); + + if (m_type == CAM_TYPE_INFO) + return EventFrameInfo(event); + + if (m_type == CAM_TYPE_VISIT) + return EventFrameVisit(event); } - - m_mousePos = event.mousePos; - return true; -} - -void CCamera::EventMouseWheel(const Event &event) -{ - auto dir = event.GetData()->y; - m_mouseWheelDelta -= dir; -} - -void CCamera::EventMouseButton(const Event &event) -{ - if (event.GetData()->button == MOUSE_BUTTON_RIGHT || event.GetData()->button == MOUSE_BUTTON_MIDDLE) - { - if ((event.mouseButtonsState & MOUSE_BUTTON_RIGHT) != 0 || (event.mouseButtonsState & MOUSE_BUTTON_MIDDLE) != 0) - { - m_engine->SetMouseType(ENG_MOUSE_MOVE); - } - else - { - m_engine->SetMouseType(ENG_MOUSE_NORM); - } - } -} - -bool CCamera::EventFrame(const Event &event) -{ - if (m_freeze) - return true; - - Math::Point newDelta = m_mouseDeltaEdge * m_speed * event.rTime; - if (m_cameraInvertX) - newDelta.x = -newDelta.x; - if (m_cameraInvertY) - newDelta.y = -newDelta.y; - m_mouseDelta += newDelta; - - EffectFrame(event); - OverFrame(event); - - if (m_type == CAM_TYPE_FREE || - m_type == CAM_TYPE_EDIT) - return EventFrameFree(event, m_type != CAM_TYPE_EDIT); - - if (m_type == CAM_TYPE_BACK) - return EventFrameBack(event); - - if (m_type == CAM_TYPE_FIX || - m_type == CAM_TYPE_PLANE) - return EventFrameFix(event); - - if (m_type == CAM_TYPE_EXPLO) - return EventFrameExplo(event); - - if (m_type == CAM_TYPE_ONBOARD) - return EventFrameOnBoard(event); - - if (m_type == CAM_TYPE_SCRIPT) - return EventFrameScript(event); - - if (m_type == CAM_TYPE_INFO) - return EventFrameInfo(event); - - if (m_type == CAM_TYPE_VISIT) - return EventFrameVisit(event); - return true; } @@ -1255,7 +1126,7 @@ bool CCamera::EventFrameFree(const Event &event, bool keysAllowed) if (m_terrain->AdjustToFloor(lookatPt, true)) lookatPt.y += m_heightLookat; - SetViewTime(m_eyePt, lookatPt, event.rTime); + UpdateCameraAnimation(m_eyePt, lookatPt, event.rTime); return true; } @@ -1347,7 +1218,7 @@ bool CCamera::EventFrameBack(const Event &event) { h += Math::PI; // back } - h = Math::NormAngle(h)+m_remotePan; + h = Math::NormAngle(h); float v = 0.0f; //? h += m_centeringCurrentH; @@ -1382,7 +1253,7 @@ bool CCamera::EventFrameBack(const Event &event) m_eyePt = ExcludeTerrain(m_eyePt, lookatPt, h, v); m_eyePt = ExcludeObject(m_eyePt, lookatPt, h, v); - SetViewTime(m_eyePt, lookatPt, event.rTime); + UpdateCameraAnimation(m_eyePt, lookatPt, event.rTime); m_directionH = h + Math::PI / 2.0f; m_directionV = v; @@ -1407,7 +1278,7 @@ bool CCamera::EventFrameFix(const Event &event) { Math::Vector lookatPt = m_cameraObj->GetPosition(); - float h = m_fixDirectionH + m_remotePan; + float h = m_fixDirectionH; float v = m_fixDirectionV; float d = m_fixDist; @@ -1416,7 +1287,7 @@ bool CCamera::EventFrameFix(const Event &event) m_eyePt = ExcludeTerrain(m_eyePt, lookatPt, h, v); m_eyePt = ExcludeObject(m_eyePt, lookatPt, h, v); - SetViewTime(m_eyePt, lookatPt, event.rTime); + UpdateCameraAnimation(m_eyePt, lookatPt, event.rTime); m_directionH = h + Math::PI / 2.0f; m_directionV = v; @@ -1452,7 +1323,7 @@ bool CCamera::EventFrameExplo(const Event &event) if (m_terrain->AdjustToFloor(lookatPt, true)) lookatPt.y += m_heightLookat; - SetViewTime(m_eyePt, lookatPt, event.rTime); + UpdateCameraAnimation(m_eyePt, lookatPt, event.rTime); return true; } @@ -1476,9 +1347,8 @@ bool CCamera::EventFrameOnBoard(const Event &event) bool CCamera::EventFrameInfo(const Event &event) { - SetViewTime(Math::Vector(0.0f, 0.0f, 0.0f), - Math::Vector(0.0f, 0.0f, 1.0f), - event.rTime); + SetViewParams(Math::Vector(0.0f, 0.0f, 0.0f), + Math::Vector(0.0f, 0.0f, 1.0f)); return true; } @@ -1501,28 +1371,43 @@ bool CCamera::EventFrameVisit(const Event &event) Math::Vector eye = RotateView(m_visitGoal, angleH, angleV, m_visitDist); eye = ExcludeTerrain(eye, m_visitGoal, angleH, angleV); eye = ExcludeObject(eye, m_visitGoal, angleH, angleV); - SetViewTime(eye, m_visitGoal, event.rTime); + UpdateCameraAnimation(eye, m_visitGoal, event.rTime); return true; } bool CCamera::EventFrameScript(const Event &event) { - SetViewTime(m_scriptEye + m_effectOffset, - m_scriptLookat + m_effectOffset, event.rTime); + UpdateCameraAnimation(m_scriptEye + m_effectOffset, + m_scriptLookat + m_effectOffset, event.rTime); return true; } -void CCamera::SetScriptEye(Math::Vector eye) +void CCamera::SetScriptCameraAnimateEye(Math::Vector eye) { m_scriptEye = eye; } -void CCamera::SetScriptLookat(Math::Vector lookat) +void CCamera::SetScriptCameraAnimateLookat(Math::Vector lookat) { m_scriptLookat = lookat; } +void CCamera::SetScriptCamera(Math::Vector eye, Math::Vector lookat) +{ + SetScriptCameraAnimate(eye, lookat); + + m_initDelay = 0.0f; + m_actualEye = m_finalEye = m_scriptEye; + m_actualLookat = m_finalLookat = m_scriptLookat; +} + +void CCamera::SetScriptCameraAnimate(Math::Vector eye, Math::Vector lookat) +{ + m_scriptEye = eye; + m_scriptLookat = lookat; +} + void CCamera::SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up) { diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index 5f995665..5d4126e5 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -45,7 +45,7 @@ enum CameraType { //! Undefined CAM_TYPE_NULL = 0, - //! Free camera (? never in principle ?) + //! Free camera CAM_TYPE_FREE = 1, //! Camera while editing a program CAM_TYPE_EDIT = 2, @@ -57,11 +57,11 @@ enum CameraType CAM_TYPE_FIX = 5, //! Camera steady after explosion CAM_TYPE_EXPLO = 6, - //! Camera during a film script + //! Camera during a cutscene CAM_TYPE_SCRIPT = 7, - //! Camera for displaying information + //! Camera for displaying SatCom (???) CAM_TYPE_INFO = 8, - //! Visit instead of an error + //! Visit camera, rotates around given position CAM_TYPE_VISIT = 9, //! Static camera height CAM_TYPE_PLANE = 11, @@ -91,15 +91,15 @@ enum CameraEffect CAM_EFFECT_NULL = 0, //! Digging in CAM_EFFECT_TERRAFORM = 1, - //! ? Vehicle driving is severely ? + //! Hard landing CAM_EFFECT_CRASH = 2, //! Explosion CAM_EFFECT_EXPLO = 3, - //! ? Not mortal shot ? + //! Shot by an enemy CAM_EFFECT_SHOT = 4, //! Vibration during construction CAM_EFFECT_VIBRATION = 5, - //! ? Spleen reactor ? + //! Overheated reactor CAM_EFFECT_PET = 6, }; @@ -124,7 +124,9 @@ enum CameraOverEffect \class CCamera \brief Camera moving in 3D scene - ... */ + This class manages everything related to animating the camera in 3D scene. + Calculated values are then passed to Gfx::CEngine. +*/ class CCamera { public: @@ -134,70 +136,83 @@ public: //! Management of an event bool EventProcess(const Event &event); - //! Initializes the camera + /** + * \brief Initializes the camera + * \param eye Initial eye position + * \param lookat Initial lookat position + * \param delay Time of the initial entry animation + */ void Init(Math::Vector eye, Math::Vector lookat, float delay); //! Sets the object controlling the camera void SetControllingObject(CObject* object); + //! Gets the object controlling the camera CObject* GetControllingObject(); //! Change the type of camera void SetType(CameraType type); + //! Get the type of the camera CameraType GetType(); - //! Management of the smoothing mode + //! Set smoothing mode void SetSmooth(CameraSmooth type); + //! Get smoothing mode CameraSmooth GetSmooth(); - //! Management of the setback distance - void SetDist(float dist); - float GetDist(); - //! Manage angle mode CAM_TYPE_FIX - void SetFixDirectionH(float angle); - float GetFixDirectionH(); - void SetFixDirectionV(float angle); - float GetFixDirectionV(); - - //! Managing the triggering mode of the camera panning - void SetRemotePan(float value); - float GetRemotePan(); - - //! Management of the remote zoom (0 .. 1) of the camera - void SetRemoteZoom(float value); - float GetRemoteZoom(); - - //! Start with a tour round the camera - void StartVisit(Math::Vector goal, float dist); - //! Circular end of a visit with the camera - void StopVisit(); - - //! Returns the point of view of the camera + //! Returns the current point of view of the camera void GetCamera(Math::Vector &eye, Math::Vector &lookat); - //! Specifies a special movement of camera to frame action + //! \name Visit camera management (CAM_TYPE_VISIT) - camera in this mode shows a position, constantly rotating around it + //@{ + //! Start visit camera + void StartVisit(Math::Vector goal, float dist); + //! Stop visit camera + void StopVisit(); + //@} + + //! \name Camera "centering" - moves the camera to show some happening action (e.g. sniffer sniffing) + //@{ + //! Move camera to show happening action bool StartCentering(CObject *object, float angleH, float angleV, float dist, float time); - //! Ends a special movement of camera to frame action + //! Go back to normal position after showing some happening action bool StopCentering(CObject *object, float time); - //! Stop framing special in the current position + //! Abort centering animation in the current position void AbortCentering(); + //@} - //! Removes the special effect with the camera - void FlushEffect(); - //! Starts a special effect with the camera + //! \name Camera shake effects + //@{ + //! Starts a camera shake effect void StartEffect(CameraEffect effect, Math::Vector pos, float force); + //! Removes the camera shake effect + void FlushEffect(); + //@} - //! Removes the effect of superposition in the foreground - void FlushOver(); - //! Specifies the base color - void SetOverBaseColor(Color color); + //! \name Camera overlay effects + //@{ + //! Starts camera overlay effect void StartOver(CameraOverEffect effect, Math::Vector pos, float force); + //! Removes camera overlay effect + void FlushOver(); + //! Specifies camera overlay effect base color + void SetOverBaseColor(Color color); + //@} - //! Sets the soft movement of the camera - void FixCamera(); - void SetScriptEye(Math::Vector eye); - void SetScriptLookat(Math::Vector lookat); + //! \name Script camera - cutscenes controlled by external code + //@{ + //! Script camera: Set camera position + void SetScriptCamera(Math::Vector eye, Math::Vector lookat); + //! Script camera: Animate to given camera position + void SetScriptCameraAnimate(Math::Vector eye, Math::Vector lookat); + //! Script camera: Animate to given eye position + void SetScriptCameraAnimateEye(Math::Vector eye); + //! Script camera: Animate to given lookat position + void SetScriptCameraAnimateLookat(Math::Vector lookat); + //@} + //! \name Configuration settings + //@{ void SetEffect(bool enable); bool GetEffect(); void SetBlood(bool enable); @@ -208,58 +223,66 @@ public: bool GetCameraInvertX(); void SetCameraInvertY(bool invert); bool GetCameraInvertY(); + //@} //! Temporarily freeze camera movement void SetFreeze(bool freeze); + //! Set camera speed void SetCameraSpeed(float speed); protected: - //! Changes the camera according to the mouse moved - bool EventMouseMove(const Event &event); - //! Mouse wheel operation - void EventMouseWheel(const Event &event); - //! Mouse button handling - void EventMouseButton(const Event &event); - //! Changes the camera according to the time elapsed - bool EventFrame(const Event &event); - //! Moves the point of view + //! Advances the effect of the camera + void EffectFrame(const Event &event); + //! Advanced overlay effect in the foreground + void OverFrame(const Event &event); + bool EventFrameFree(const Event &event, bool keysAllowed); - //! Moves the point of view bool EventFrameBack(const Event &event); - //! Moves the point of view bool EventFrameFix(const Event &event); - //! Moves the point of view bool EventFrameExplo(const Event &event); - //! Moves the point of view bool EventFrameOnBoard(const Event &event); - //! Moves the point of view bool EventFrameInfo(const Event &event); - //! Moves the point of view bool EventFrameVisit(const Event &event); - //! Moves the point of view bool EventFrameScript(const Event &event); - //! Specifies the location and direction of view to the 3D engine - void SetViewTime(const Math::Vector &eyePt, const Math::Vector &lookatPt, float rTime); - //! Avoid the obstacles - bool IsCollision(Math::Vector &eye, Math::Vector lookat); - //! Avoid the obstacles - bool IsCollisionBack(Math::Vector &eye, Math::Vector lookat); - //! Avoid the obstacles - bool IsCollisionFix(Math::Vector &eye, Math::Vector lookat); + /** + * \brief Calculates camera animation and sends updated camera position to the 3D engine + * \param eyePt Eye point + * \param lookatPt Lookat point + * \param rTime Time since last time this function was called (used to calculate animation) + * \see SetViewParams + */ + void UpdateCameraAnimation(const Math::Vector &eyePt, const Math::Vector &lookatPt, float rTime); + + /** + * \brief Avoid the obstacles + * + * For CAM_TYPE_BACK: make obstacles transparent + * For CAM_TYPE_FIX or CAM_TYPE_PLANE: adjust eye not to hit the obstacles + * + * \param eye Eye position, may be adjusted + * \param lookat Lookat point + */ + void IsCollision(Math::Vector &eye, Math::Vector lookat); + //! Avoid the obstacles (CAM_TYPE_BACK) + void IsCollisionBack(); + //! Avoid the obstacles (CAM_TYPE_FIX or CAM_TYPE_PLANE) + void IsCollisionFix(Math::Vector &eye, Math::Vector lookat); //! Adjusts the camera not to enter the ground Math::Vector ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV); //! Adjusts the camera not to enter an object Math::Vector ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV); - //! Specifies the location and direction of view - void SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up); - //! Advances the effect of the camera - void EffectFrame(const Event &event); - //! Advanced overlay effect in the foreground - void OverFrame(const Event &event); + /** + * \brief Updates the location and direction of the camera in the 3D engine + * \param eye Eye point + * \param lookat Lookat point + * \param up Up vector + * \see CEngine::SetViewParams + */ + void SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up = Math::Vector(0.0f, 1.0f, 0.0f)); /** * \brief Calculate camera movement (from user inputs) to apply @@ -280,10 +303,10 @@ protected: //! Type of smoothing CameraSmooth m_smooth; //! Object linked to the camera - CObject* m_cameraObj; + CObject* m_cameraObj; - //! Time of initial centering - float m_initDelay; + //! Remaining time of initial camera entry animation + float m_initDelay; //! Current eye Math::Vector m_actualEye; @@ -294,11 +317,11 @@ protected: //! Final lookat Math::Vector m_finalLookat; //! Eye position at the moment of entering CAM_TYPE_INFO/CAM_TYPE_VISIT - Math::Vector m_normEye; + Math::Vector m_prevEye; //! Lookat position at the moment of entering CAM_TYPE_INFO/CAM_TYPE_VISIT - Math::Vector m_normLookat; + Math::Vector m_prevLookat; - float m_focus; + float m_focus; //! CAM_TYPE_FREE: eye Math::Vector m_eyePt; @@ -315,19 +338,18 @@ protected: //! CAM_TYPE_BACK: distance float m_backDist; - //! CAM_TYPE_BACK: distance minimal + //! CAM_TYPE_BACK: minimal distance float m_backMin; - //! CAM_TYPE_BACK: additional direction + //! CAM_TYPE_BACK: additional horizontal direction float m_addDirectionH; - //! CAM_TYPE_BACK: additional direction + //! CAM_TYPE_BACK: additional vertical direction float m_addDirectionV; - bool m_transparency; //! CAM_TYPE_FIX: distance float m_fixDist; - //! CAM_TYPE_FIX: direction + //! CAM_TYPE_FIX: horizontal direction float m_fixDirectionH; - //! CAM_TYPE_FIX: direction + //! CAM_TYPE_FIX: vertical direction float m_fixDirectionV; //! CAM_TYPE_VISIT: target position @@ -341,12 +363,13 @@ protected: //! CAM_TYPE_VISIT: direction float m_visitDirectionV; - float m_remotePan; - //! Last known mouse position, used to calculate change since last frame Math::Point m_mousePos = Math::Point(0.5f, 0.5f); + //! Change of mouse position since last frame Math::Point m_mouseDelta = Math::Point(0.0f, 0.0f); + //! Change of camera position caused by edge camera Math::Point m_mouseDeltaEdge = Math::Point(0.0f, 0.0f); + //! Change of mouse wheel since last frame float m_mouseWheelDelta = 0.0f; CenteringPhase m_centeringPhase; @@ -376,19 +399,17 @@ protected: Math::Vector m_scriptEye; Math::Vector m_scriptLookat; - //! Shocks if explosion? - bool m_effect; - //! Blood? - bool m_blood; - //! Scroll in the edges? - bool m_oldCameraScroll; - //! X inversion in the edges? - bool m_cameraInvertX; - //! Y inversion in the edges? - bool m_cameraInvertY; - //! Is camera frozen? bool m_freeze = false; + + //! \name Configuration settings + //@{ + bool m_effect; + bool m_blood; + bool m_oldCameraScroll; + bool m_cameraInvertX; + bool m_cameraInvertY; + //@} }; diff --git a/src/graphics/opengl/gl21device.h b/src/graphics/opengl/gl21device.h index 9b073e31..20cf2156 100644 --- a/src/graphics/opengl/gl21device.h +++ b/src/graphics/opengl/gl21device.h @@ -18,7 +18,7 @@ */ /** - * \file graphics/opengl/gldevice.h + * \file graphics/opengl/gl21device.h * \brief OpenGL implementation - CGL21Device class */ diff --git a/src/level/mainmovie.cpp b/src/level/mainmovie.cpp index 3bf37ebd..dc5f4cb0 100644 --- a/src/level/mainmovie.cpp +++ b/src/level/mainmovie.cpp @@ -95,9 +95,7 @@ bool CMainMovie::Start(MainMovieType type, float time) m_camera->GetCamera(m_initialEye, m_initialLookat); m_camera->SetType(Gfx::CAM_TYPE_SCRIPT); m_camera->SetSmooth(Gfx::CAM_SMOOTH_HARD); - m_camera->SetScriptEye(m_initialEye); - m_camera->SetScriptLookat(m_initialLookat); - m_camera->FixCamera(); + m_camera->SetScriptCamera(m_initialEye, m_initialLookat); mat = pObj->GetWorldMatrix(0); m_finalLookat[0] = Math::Transform(*mat, Math::Vector( 1.6f, 1.0f, 1.2f)); @@ -187,9 +185,7 @@ bool CMainMovie::EventProcess(const Event &event) eye = (finalEye-initialEye)*progress+initialEye; lookat = (finalLookat-initialLookat)*progress+initialLookat; - m_camera->SetScriptEye(eye); - m_camera->SetScriptLookat(lookat); -// m_camera->FixCamera(); + m_camera->SetScriptCameraAnimate(eye, lookat); } else { diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 9abd54a2..374a7495 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -239,9 +239,6 @@ CRobotMain::CRobotMain() m_shotSaving = 0; - m_cameraPan = 0.0f; - m_cameraZoom = 0.0f; - m_build = 0; m_researchDone.clear(); // no research done m_researchDone[0] = 0; @@ -459,8 +456,6 @@ void CRobotMain::ChangePhase(Phase phase) m_camera->SetType(Gfx::CAM_TYPE_NULL); m_movie->Flush(); m_movieInfoIndex = -1; - m_cameraPan = 0.0f; - m_cameraZoom = 0.0f; m_shortCut = true; } ClearInterface(); @@ -677,7 +672,6 @@ bool CRobotMain::ProcessEvent(Event &event) } m_displayText->EventProcess(event); - RemoteCamera(m_cameraPan, m_cameraZoom, event.rTime); if (m_displayInfo != nullptr) // current edition? m_displayInfo->EventProcess(event); @@ -852,7 +846,6 @@ bool CRobotMain::ProcessEvent(Event &event) { auto data = event.GetData(); - KeyCamera(event.type, data->slot); HiliteClear(); if (m_editLock) // current edition? { @@ -999,13 +992,6 @@ bool CRobotMain::ProcessEvent(Event &event) break; } - case EVENT_KEY_UP: - { - auto data = event.GetData(); - KeyCamera(event.type, data->slot); - break; - } - case EVENT_MOUSE_BUTTON_DOWN: { if (event.GetData()->button != MOUSE_BUTTON_LEFT) // only left mouse button @@ -1032,14 +1018,6 @@ bool CRobotMain::ProcessEvent(Event &event) break; } - case EVENT_MOUSE_BUTTON_UP: - if (event.GetData()->button != MOUSE_BUTTON_LEFT) // only left mouse button - break; - - m_cameraPan = 0.0f; - m_cameraZoom = 0.0f; - break; - case EVENT_OBJECT_LIMIT: StartShowLimit(); break; @@ -1057,19 +1035,6 @@ bool CRobotMain::ProcessEvent(Event &event) ChangeCamera(); break; - case EVENT_OBJECT_CAMERAleft: - m_cameraPan = -1.0f; - break; - case EVENT_OBJECT_CAMERAright: - m_cameraPan = 1.0f; - break; - case EVENT_OBJECT_CAMERAnear: - m_cameraZoom = -1.0f; - break; - case EVENT_OBJECT_CAMERAaway: - m_cameraZoom = 1.0f; - break; - case EVENT_OBJECT_DELETE: m_ui->GetDialog()->StartQuestion( RT_DIALOG_DELOBJ, true, false, false, @@ -1851,7 +1816,6 @@ void CRobotMain::SelectOneObject(CObject* obj, bool displayError) type == OBJECT_APOLLO2 ) { m_camera->SetType(dynamic_cast(obj)->GetCameraType()); - m_camera->SetDist(dynamic_cast(obj)->GetCameraDist()); } else { @@ -2323,84 +2287,6 @@ void CRobotMain::ChangeCamera() m_camera->SetType(type); } -//! Remote control the camera using the arrow keys -void CRobotMain::KeyCamera(EventType event, InputSlot key) -{ - if (event == EVENT_KEY_UP) - { - if (key == INPUT_SLOT_LEFT) - { - m_cameraPan = 0.0f; - } - - if (key == INPUT_SLOT_RIGHT) - { - m_cameraPan = 0.0f; - } - - if (key == INPUT_SLOT_UP) - { - m_cameraZoom = 0.0f; - } - - if (key == INPUT_SLOT_DOWN) - { - m_cameraZoom = 0.0f; - } - } - - if (m_phase != PHASE_SIMUL) return; - if (m_editLock) return; // current edition? - if (m_trainerPilot) return; - - CObject* obj = GetSelect(); - if (obj == nullptr) return; - assert(obj->Implements(ObjectInterfaceType::Controllable)); - if (!dynamic_cast(obj)->GetTrainer()) return; - - if (event == EVENT_KEY_DOWN) - { - if (key == INPUT_SLOT_LEFT) - { - m_cameraPan = -1.0f; - } - - if (key == INPUT_SLOT_RIGHT) - { - m_cameraPan = 1.0f; - } - - if (key == INPUT_SLOT_UP) - { - m_cameraZoom = -1.0f; - } - - if (key == INPUT_SLOT_DOWN) - { - m_cameraZoom = 1.0f; - } - } -} - -//! Panned with the camera if a button is pressed -void CRobotMain::RemoteCamera(float pan, float zoom, float rTime) -{ - if (pan != 0.0f) - { - float value = m_camera->GetRemotePan(); - value += pan*rTime*1.5f; - m_camera->SetRemotePan(value); - } - - if (zoom != 0.0f) - { - float value = m_camera->GetRemoteZoom(); - value += zoom*rTime*0.3f; - m_camera->SetRemoteZoom(value); - } -} - - //! Cancels the current movie void CRobotMain::AbortMovie() @@ -3660,8 +3546,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (line->GetParam("fadeIn")->AsBool(false)) m_camera->StartOver(Gfx::CAM_OVER_EFFECT_FADEIN_WHITE, Math::Vector(0.0f, 0.0f, 0.0f), 1.0f); - - m_camera->SetFixDirectionH(line->GetParam("fixDirection")->AsFloat(0.25f)*Math::PI); continue; } @@ -3822,7 +3706,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) { Math::Vector pos = sel->GetPosition(); m_camera->Init(pos, pos, 0.0f); - m_camera->FixCamera(); SelectObject(sel); m_camera->SetControllingObject(sel); @@ -5971,9 +5854,6 @@ void CRobotMain::SetCodeBattleSpectatorMode(bool mode) m_codeBattleSpectator = mode; SelectObject(obj, false); // this uses code battle selection mode already - - if (mode) - m_camera->SetFixDirectionV(-0.25f*Math::PI); } void CRobotMain::UpdateDebugCrashSpheres() diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 8c6b53e0..c25d1923 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -390,8 +390,6 @@ protected: void ClearTooltip(); CObject* DetectObject(Math::Point pos); void ChangeCamera(); - void RemoteCamera(float pan, float zoom, float rTime); - void KeyCamera(EventType event, InputSlot key); void AbortMovie(); void SelectOneObject(CObject* obj, bool displayError=true); void HelpObject(); @@ -535,9 +533,6 @@ protected: std::vector m_newScriptName; - float m_cameraPan = 0.0f; - float m_cameraZoom = 0.0f; - EventType m_visitLast = EVENT_NULL; CObject* m_visitObject = nullptr; CObject* m_visitArrow = nullptr; diff --git a/src/object/auto/autobase.cpp b/src/object/auto/autobase.cpp index 0fd8c43c..3200c612 100644 --- a/src/object/auto/autobase.cpp +++ b/src/object/auto/autobase.cpp @@ -170,7 +170,6 @@ begin: { assert(pObj->Implements(ObjectInterfaceType::Controllable)); m_camera->SetType(dynamic_cast(pObj)->GetCameraType()); - m_camera->SetDist(dynamic_cast(pObj)->GetCameraDist()); } m_main->StartMusic(); @@ -203,18 +202,17 @@ begin: m_camera->SetType(Gfx::CAM_TYPE_SCRIPT); - pos = m_pos; - pos.x -= 150.0f; - m_terrain->AdjustToFloor(pos); - pos.y += 10.0f; - m_camera->SetScriptEye(pos); - m_posSound = pos; + Math::Vector eye = m_pos; + eye.x -= 150.0f; + m_terrain->AdjustToFloor(eye); + eye.y += 10.0f; - pos = m_object->GetPosition(); - pos.y += 300.0f+50.0f; - m_camera->SetScriptLookat(pos); + Math::Vector lookat = m_object->GetPosition(); + lookat.y += 300.0f+50.0f; + + m_camera->SetScriptCamera(eye, lookat); + m_posSound = eye; - m_camera->FixCamera(); m_engine->SetFocus(2.0f); m_engine->SetFogStart(0.9f); @@ -266,9 +264,8 @@ begin: pos.x += 1000.0f; pos.z -= 60.0f; pos.y += 80.0f; - m_camera->SetScriptEye(pos); m_posSound = pos; - m_camera->FixCamera(); + m_camera->SetScriptCamera(pos, Math::Vector(0.0f, 0.0f, 0.0f)); m_engine->SetFocus(1.0f); BeginTransit(); @@ -345,15 +342,15 @@ begin: vibCir *= Math::Min(1.0f, (1.0f-m_progress)*3.0f); m_object->SetCirVibration(vibCir); - pos = m_pos; - pos.x -= 150.0f; - m_terrain->AdjustToFloor(pos); - pos.y += 10.0f; - m_camera->SetScriptEye(pos); + Math::Vector eye = m_pos; + eye.x -= 150.0f; + m_terrain->AdjustToFloor(eye); + eye.y += 10.0f; - pos = m_object->GetPosition(); - pos.y += 50.0f; - m_camera->SetScriptLookat(pos); + Math::Vector lookat = m_object->GetPosition(); + lookat.y += 50.0f; + + m_camera->SetScriptCameraAnimate(eye, lookat); m_engine->SetFocus(1.0f+(1.0f-m_progress)); @@ -494,7 +491,7 @@ begin: m_terrain->AdjustToFloor(pos); pos.y += 10.0f; pos.y += m_progress*40.0f; - m_camera->SetScriptEye(pos); + m_camera->SetScriptCameraAnimateEye(pos); m_engine->SetFogStart(0.9f-(0.9f-m_fogStart)*m_progress); } @@ -556,7 +553,7 @@ begin: m_terrain->AdjustToFloor(pos); pos.y += 10.0f; pos.y += m_progress*40.0f; - m_camera->SetScriptEye(pos); + m_camera->SetScriptCameraAnimateEye(pos); m_engine->SetFogStart(0.9f-(0.9f-m_fogStart)*m_progress); } @@ -598,7 +595,6 @@ begin: { assert(pObj->Implements(ObjectInterfaceType::Controllable)); m_camera->SetType(dynamic_cast(pObj)->GetCameraType()); - m_camera->SetDist(dynamic_cast(pObj)->GetCameraDist()); } m_sound->Play(SOUND_BOUM, m_object->GetPosition()); m_soundChannel = -1; @@ -749,15 +745,15 @@ begin: vibCir.y = 0.0f; m_object->SetCirVibration(vibCir); - pos = m_pos; - pos.x -= 110.0f+m_progress*250.0f; - m_terrain->AdjustToFloor(pos); - pos.y += 10.0f; - m_camera->SetScriptEye(pos); + Math::Vector eye = m_pos; + eye.x -= 110.0f+m_progress*250.0f; + m_terrain->AdjustToFloor(eye); + eye.y += 10.0f; - pos = m_object->GetPosition(); - pos.y += 50.0f; - m_camera->SetScriptLookat(pos); + Math::Vector lookat = m_object->GetPosition(); + lookat.y += 50.0f; + + m_camera->SetScriptCameraAnimate(eye, lookat); m_engine->SetFocus(1.0f+m_progress); @@ -907,7 +903,7 @@ begin: pos.x += event.rTime*(2000.0f/BASE_TRANSIT_TIME); m_object->SetPosition(pos); pos.x += 60.0f; - m_camera->SetScriptLookat(pos); + m_camera->SetScriptCameraAnimateLookat(pos); } else { @@ -1129,7 +1125,6 @@ bool CAutoBase::Abort() { assert(pObj->Implements(ObjectInterfaceType::Controllable)); m_camera->SetType(dynamic_cast(pObj)->GetCameraType()); - m_camera->SetDist(dynamic_cast(pObj)->GetCameraDist()); } m_engine->SetFogStart(m_fogStart); @@ -1387,16 +1382,16 @@ Error CAutoBase::TakeOff(bool printMsg) m_camera->SetType(Gfx::CAM_TYPE_SCRIPT); - Math::Vector pos = m_pos; - pos.x -= 110.0f; - m_terrain->AdjustToFloor(pos); - pos.y += 10.0f; - m_camera->SetScriptEye(pos); - m_posSound = pos; + Math::Vector eye = m_pos; + eye.x -= 110.0f; + m_terrain->AdjustToFloor(eye); + eye.y += 10.0f; - pos = m_object->GetPosition(); - pos.y += 50.0f; - m_camera->SetScriptLookat(pos); + Math::Vector lookat = m_object->GetPosition(); + lookat.y += 50.0f; + + m_camera->SetScriptCameraAnimate(eye, lookat); + m_posSound = eye; m_engine->SetFocus(1.0f); diff --git a/src/object/auto/autoportico.cpp b/src/object/auto/autoportico.cpp index b716dc54..042e7c31 100644 --- a/src/object/auto/autoportico.cpp +++ b/src/object/auto/autoportico.cpp @@ -164,19 +164,17 @@ bool CAutoPortico::EventProcess(const Event &event) m_camera->SetType(Gfx::CAM_TYPE_SCRIPT); - pos = m_startPos; - pos.x += -100.0f; - pos.y += 9.0f; - pos.z += -200.0f; - m_camera->SetScriptEye(pos); + Math::Vector eye = m_startPos; + eye.x += -100.0f; + eye.y += 9.0f; + eye.z += -200.0f; - pos = m_object->GetPosition(); - pos.x += 0.0f; - pos.y += 10.0f; - pos.z += -40.0f; - m_camera->SetScriptLookat(pos); + Math::Vector lookat = m_object->GetPosition(); + lookat.x += 0.0f; + lookat.y += 10.0f; + lookat.z += -40.0f; - m_camera->FixCamera(); + m_camera->SetScriptCamera(eye, lookat); } } @@ -329,23 +327,20 @@ bool CAutoPortico::EventProcess(const Event &event) if ( m_cameraProgress < 1.0f ) { - if ( m_cameraProgress < 0.5f ) - { - } - else + if ( m_cameraProgress >= 0.5f ) { pos = m_startPos; pos.x += -100.0f-(m_cameraProgress-0.5f)*1.0f*120.0f; pos.y += 9.0f; pos.z += -200.0f+(m_cameraProgress-0.5f)*1.0f*210.0f; - m_camera->SetScriptEye(pos); + m_camera->SetScriptCameraAnimateEye(pos); } pos = m_object->GetPosition(); pos.x += 0.0f; pos.y += 10.0f; pos.z += -40.0f; - m_camera->SetScriptLookat(pos); + m_camera->SetScriptCameraAnimateLookat(pos); } return true; diff --git a/src/object/interface/controllable_object.h b/src/object/interface/controllable_object.h index 5a04c3fc..9d1aabde 100644 --- a/src/object/interface/controllable_object.h +++ b/src/object/interface/controllable_object.h @@ -58,10 +58,6 @@ public: virtual void SetCameraType(Gfx::CameraType type) = 0; //! Return camera type for this object virtual Gfx::CameraType GetCameraType() = 0; - //! Set camera distance for this object - virtual void SetCameraDist(float dist) = 0; - //! Return camera distance for this object - virtual float GetCameraDist() = 0; //! Disallow camera changes virtual void SetCameraLock(bool lock) = 0; //! Check if camera changes are disallowed diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index d945c5c8..32861cca 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -150,7 +150,6 @@ COldObject::COldObject(int id) m_character.wheelRight = 1.0f; m_cameraType = Gfx::CAM_TYPE_BACK; - m_cameraDist = 50.0f; m_bCameraLock = false; for (int i=0 ; iGetParam("camera")->IsDefined()) SetCameraType(line->GetParam("camera")->AsCameraType()); - SetCameraDist(line->GetParam("cameraDist")->AsFloat(50.0f)); SetCameraLock(line->GetParam("cameraLock")->AsBool(false)); if (line->GetParam("pyro")->IsDefined()) @@ -2499,16 +2497,6 @@ Gfx::CameraType COldObject::GetCameraType() return m_cameraType; } -void COldObject::SetCameraDist(float dist) -{ - m_cameraDist = dist; -} - -float COldObject::GetCameraDist() -{ - return m_cameraDist; -} - void COldObject::SetCameraLock(bool lock) { m_bCameraLock = lock; diff --git a/src/object/old_object.h b/src/object/old_object.h index 5ba5c7eb..60e8e8fa 100644 --- a/src/object/old_object.h +++ b/src/object/old_object.h @@ -218,8 +218,6 @@ public: void SetCameraType(Gfx::CameraType type) override; Gfx::CameraType GetCameraType() override; - void SetCameraDist(float dist) override; - float GetCameraDist() override; void SetCameraLock(bool lock) override; bool GetCameraLock() override; @@ -351,7 +349,6 @@ protected: float m_gunGoalV; float m_gunGoalH; Gfx::CameraType m_cameraType; - float m_cameraDist; bool m_bCameraLock; float m_magnifyDamage; diff --git a/src/ui/object_interface.cpp b/src/ui/object_interface.cpp index aa52678a..1310015f 100644 --- a/src/ui/object_interface.cpp +++ b/src/ui/object_interface.cpp @@ -1324,26 +1324,6 @@ bool CObjectInterface::CreateInterface(bool bSelect) } } - if ( m_object->GetToy() && !m_object->GetManual() ) - { - pos.x = ox+sx*9.0f; - pos.y = oy+sy*0; - pb = pw->CreateButton(pos, dim, 55, EVENT_OBJECT_CAMERAleft); - pb->SetImmediat(true); - pos.x = ox+sx*11.0f; - pos.y = oy+sy*0; - pb = pw->CreateButton(pos, dim, 48, EVENT_OBJECT_CAMERAright); - pb->SetImmediat(true); - pos.x = ox+sx*10.0f; - pos.y = oy+sy*1; - pb = pw->CreateButton(pos, dim, 49, EVENT_OBJECT_CAMERAnear); - pb->SetImmediat(true); - pos.x = ox+sx*10.0f; - pos.y = oy+sy*0; - pb = pw->CreateButton(pos, dim, 50, EVENT_OBJECT_CAMERAaway); - pb->SetImmediat(true); - } - pos.x = ox+sx*13.4f; pos.y = oy+sy*0; if ( m_object->GetTrainer() ) // Training? diff --git a/src/ui/screen/screen_apperance.cpp b/src/ui/screen/screen_apperance.cpp index 9ae82c97..3e8cdd0d 100644 --- a/src/ui/screen/screen_apperance.cpp +++ b/src/ui/screen/screen_apperance.cpp @@ -619,21 +619,17 @@ void CScreenApperance::CameraPerso() { Gfx::CCamera* camera = m_main->GetCamera(); + camera->SetType(Gfx::CAM_TYPE_SCRIPT); if ( m_apperanceTab == 0 ) { -//? camera->Init(Math::Vector(4.0f, 0.0f, 0.0f), -//? Math::Vector(0.0f, 0.0f, 1.0f), 0.0f); - camera->Init(Math::Vector(6.0f, 0.0f, 0.0f), - Math::Vector(0.0f, 0.2f, 1.5f), 0.0f); + camera->SetScriptCamera(Math::Vector(6.0f, 0.0f, 0.0f), + Math::Vector(0.0f, 0.2f, 1.5f)); } else { - camera->Init(Math::Vector(18.0f, 0.0f, 4.5f), - Math::Vector(0.0f, 1.6f, 4.5f), 0.0f); + camera->SetScriptCamera(Math::Vector(18.0f, 0.0f, 4.5f), + Math::Vector(0.0f, 1.6f, 4.5f)); } - - camera->SetType(Gfx::CAM_TYPE_SCRIPT); - camera->FixCamera(); } // Sets a fixed color. From 0e101debe0d33faed5da6e69d356ae819afc4597 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 May 2016 18:52:30 +0200 Subject: [PATCH 089/125] Removed CAM_TYPE_INFO --- src/graphics/engine/camera.cpp | 28 +++++----------------------- src/graphics/engine/camera.h | 23 ++++++++++------------- src/ui/displayinfo.cpp | 6 +----- src/ui/displayinfo.h | 4 ++-- 4 files changed, 18 insertions(+), 43 deletions(-) diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index 08994999..5f5c254c 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -265,8 +265,7 @@ void CCamera::SetType(CameraType type) } } - if (type == CAM_TYPE_INFO || - type == CAM_TYPE_VISIT) // xx -> info ? + if (type == CAM_TYPE_VISIT) // *** -> visit ? { m_prevEye = m_engine->GetEyePt(); m_prevLookat = m_engine->GetLookatPt(); @@ -276,8 +275,7 @@ void CCamera::SetType(CameraType type) return; } - if (m_type == CAM_TYPE_INFO || - m_type == CAM_TYPE_VISIT) // info -> xx ? + if (m_type == CAM_TYPE_VISIT) // visit -> *** ? { m_engine->SetFocus(m_focus); // gives initial focus m_type = type; @@ -453,8 +451,7 @@ bool CCamera::StopCentering(CObject *object, float time) void CCamera::AbortCentering() { - if (m_type == CAM_TYPE_INFO || - m_type == CAM_TYPE_VISIT ) + if (m_type == CAM_TYPE_VISIT ) return; if (m_centeringPhase == CAM_PHASE_NULL) @@ -491,8 +488,7 @@ void CCamera::StartEffect(CameraEffect effect, Math::Vector pos, float force) void CCamera::EffectFrame(const Event &event) { - if (m_type == CAM_TYPE_INFO || - m_type == CAM_TYPE_VISIT) + if (m_type == CAM_TYPE_VISIT) return; if (m_effectType == CAM_EFFECT_NULL) @@ -667,8 +663,7 @@ void CCamera::StartOver(CameraOverEffect effect, Math::Vector pos, float force) void CCamera::OverFrame(const Event &event) { - if (m_type == CAM_TYPE_INFO || - m_type == CAM_TYPE_VISIT) + if (m_type == CAM_TYPE_VISIT) return; if (m_overType == CAM_OVER_EFFECT_NULL) @@ -1065,9 +1060,6 @@ bool CCamera::EventProcess(const Event &event) if (m_type == CAM_TYPE_SCRIPT) return EventFrameScript(event); - if (m_type == CAM_TYPE_INFO) - return EventFrameInfo(event); - if (m_type == CAM_TYPE_VISIT) return EventFrameVisit(event); } @@ -1345,13 +1337,6 @@ bool CCamera::EventFrameOnBoard(const Event &event) return true; } -bool CCamera::EventFrameInfo(const Event &event) -{ - SetViewParams(Math::Vector(0.0f, 0.0f, 0.0f), - Math::Vector(0.0f, 0.0f, 1.0f)); - return true; -} - bool CCamera::EventFrameVisit(const Event &event) { m_visitTime += event.rTime; @@ -1414,9 +1399,6 @@ void CCamera::SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, m_engine->SetViewParams(eye, lookat, up); bool under = (eye.y < m_water->GetLevel()); // Is it underwater? - if (m_type == CAM_TYPE_INFO) - under = false; - m_engine->SetRankView(under ? 1 : 0); } diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index 5d4126e5..83ac7afd 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -44,27 +44,25 @@ namespace Gfx enum CameraType { //! Undefined - CAM_TYPE_NULL = 0, + CAM_TYPE_NULL = 0, //! Free camera - CAM_TYPE_FREE = 1, + CAM_TYPE_FREE, //! Camera while editing a program - CAM_TYPE_EDIT = 2, + CAM_TYPE_EDIT, //! Camera on board a robot - CAM_TYPE_ONBOARD = 3, + CAM_TYPE_ONBOARD, //! Camera behind a robot - CAM_TYPE_BACK = 4, + CAM_TYPE_BACK, //! Static camera following robot - CAM_TYPE_FIX = 5, + CAM_TYPE_FIX, //! Camera steady after explosion - CAM_TYPE_EXPLO = 6, + CAM_TYPE_EXPLO, //! Camera during a cutscene - CAM_TYPE_SCRIPT = 7, - //! Camera for displaying SatCom (???) - CAM_TYPE_INFO = 8, + CAM_TYPE_SCRIPT, //! Visit camera, rotates around given position - CAM_TYPE_VISIT = 9, + CAM_TYPE_VISIT, //! Static camera height - CAM_TYPE_PLANE = 11, + CAM_TYPE_PLANE, }; enum CameraSmooth @@ -242,7 +240,6 @@ protected: bool EventFrameFix(const Event &event); bool EventFrameExplo(const Event &event); bool EventFrameOnBoard(const Event &event); - bool EventFrameInfo(const Event &event); bool EventFrameVisit(const Event &event); bool EventFrameScript(const Event &event); diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index 325a16aa..76aee701 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -80,7 +80,6 @@ CDisplayInfo::CDisplayInfo() m_toto = nullptr; m_bSoluce = false; m_bEditLock = false; - m_infoCamera = Gfx::CAM_TYPE_NULL; m_index = -1; } @@ -362,9 +361,7 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc m_main->SetEditLock(true, false); m_main->SetEditFull(false); - m_satcomPause = m_pause->ActivatePause(PAUSE_ENGINE|PAUSE_HIDE_SHORTCUTS|PAUSE_MUTE_SOUND, PAUSE_MUSIC_SATCOM); - m_infoCamera = m_camera->GetType(); - m_camera->SetType(Gfx::CAM_TYPE_INFO); + m_satcomPause = m_pause->ActivatePause(PAUSE_ENGINE|PAUSE_HIDE_SHORTCUTS|PAUSE_MUTE_SOUND|PAUSE_CAMERA, PAUSE_MUSIC_SATCOM); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW6)); if (pw != nullptr) pw->ClearState(STATE_VISIBLE | STATE_ENABLE); @@ -833,7 +830,6 @@ void CDisplayInfo::StopDisplayInfo() } m_pause->DeactivatePause(m_satcomPause); m_satcomPause = nullptr; - m_camera->SetType(m_infoCamera); m_engine->SetDrawWorld(true); // draws all on the interface m_engine->SetDrawFront(false); // draws nothing on the interface diff --git a/src/ui/displayinfo.h b/src/ui/displayinfo.h index ff43b1eb..eea3b255 100644 --- a/src/ui/displayinfo.h +++ b/src/ui/displayinfo.h @@ -19,7 +19,7 @@ #pragma once -#include "graphics/engine/camera.h" +#include "math/point.h" #include @@ -32,6 +32,7 @@ struct Event; namespace Gfx { +class CCamera; class CEngine; class CParticle; class CLightManager; @@ -80,7 +81,6 @@ protected: bool m_bInfoMinimized; int m_index; - Gfx::CameraType m_infoCamera; Math::Point m_infoNormalPos; Math::Point m_infoNormalDim; Math::Point m_infoActualPos; From df111dbf98eb76395e7d0c1b385120bb16620487 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 May 2016 22:59:34 +0200 Subject: [PATCH 090/125] Refactored CBotVar to templates --- src/CBot/CBotVar/CBotVar.cpp | 17 +- src/CBot/CBotVar/CBotVar.h | 5 + src/CBot/CBotVar/CBotVarBoolean.cpp | 118 +----------- src/CBot/CBotVar/CBotVarBoolean.h | 24 +-- src/CBot/CBotVar/CBotVarFloat.cpp | 196 ------------------- src/CBot/CBotVar/CBotVarFloat.h | 39 +--- src/CBot/CBotVar/CBotVarInt.cpp | 285 +++++----------------------- src/CBot/CBotVar/CBotVarInt.h | 36 +--- src/CBot/CBotVar/CBotVarString.cpp | 98 +--------- src/CBot/CBotVar/CBotVarString.h | 52 +++-- src/CBot/CBotVar/CBotVarValue.h | 177 +++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 12 files changed, 308 insertions(+), 740 deletions(-) create mode 100644 src/CBot/CBotVar/CBotVarValue.h diff --git a/src/CBot/CBotVar/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp index 8876ded2..fc4503ea 100644 --- a/src/CBot/CBotVar/CBotVar.cpp +++ b/src/CBot/CBotVar/CBotVar.cpp @@ -61,6 +61,11 @@ CBotVar::CBotVar( ) m_mPrivate = ProtectionLevel::Public; } +CBotVar::CBotVar(const CBotToken &name) : CBotVar() +{ + m_token = new CBotToken(name); +} + //////////////////////////////////////////////////////////////////////////////// CBotVar::~CBotVar( ) { @@ -698,7 +703,16 @@ void CBotVar::Dec() //////////////////////////////////////////////////////////////////////////////// void CBotVar::Copy(CBotVar* pSrc, bool bName) { - assert(0); + if (bName) *m_token = *pSrc->m_token; + m_type = pSrc->m_type; + m_binit = pSrc->m_binit; +//- m_bStatic = pSrc->m_bStatic; + m_next = nullptr; + m_pMyThis = nullptr;//p->m_pMyThis; + m_pUserPtr = pSrc->m_pUserPtr; + + // keeps indentificator the same (by default) + if (m_ident == 0) m_ident = pSrc->m_ident; } //////////////////////////////////////////////////////////////////////////////// @@ -727,4 +741,5 @@ CBotClass* CBotVar::GetClass() return nullptr; } + } // namespace CBot diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h index a4563b4b..be171783 100644 --- a/src/CBot/CBotVar/CBotVar.h +++ b/src/CBot/CBotVar/CBotVar.h @@ -50,6 +50,11 @@ public: */ CBotVar(); + /** + * \brief Constructor. Do not call directly, use CBotVar::Create() + */ + CBotVar(const CBotToken& name); + /** * \brief Destructor. Do not call directly, use CBotVar::Destroy() */ diff --git a/src/CBot/CBotVar/CBotVarBoolean.cpp b/src/CBot/CBotVar/CBotVarBoolean.cpp index 3a40772a..c9a9b52e 100644 --- a/src/CBot/CBotVar/CBotVarBoolean.cpp +++ b/src/CBot/CBotVar/CBotVarBoolean.cpp @@ -19,137 +19,27 @@ #include "CBot/CBotVar/CBotVarBoolean.h" -#include "CBot/CBotEnums.h" -#include "CBot/CBotUtils.h" - -#include "CBot/CBotToken.h" - namespace CBot { -//////////////////////////////////////////////////////////////////////////////// -CBotVarBoolean::CBotVarBoolean(const CBotToken& name) -{ - m_token = new CBotToken(name); - m_next = nullptr; - m_pMyThis = nullptr; - m_pUserPtr = nullptr; - m_InitExpr = nullptr; - m_LimExpr = nullptr; - m_type = CBotTypBoolean; - m_binit = InitType::UNDEF; - m_bStatic = false; - m_mPrivate = ProtectionLevel::Public; - m_val = 0; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarBoolean::Copy(CBotVar* pSrc, bool bName) -{ - CBotVarBoolean* p = static_cast(pSrc); - - if (bName) *m_token = *p->m_token; - m_type = p->m_type; - m_val = p->m_val; - m_binit = p->m_binit; -//- m_bStatic = p->m_bStatic; - m_next = nullptr; - m_pMyThis = nullptr;//p->m_pMyThis; - m_pUserPtr = p->m_pUserPtr; - - // keeps indentificator the same (by default) - if (m_ident == 0 ) m_ident = p->m_ident; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarBoolean::SetValInt(int val, const std::string& s) -{ - m_val = static_cast(val); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarBoolean::SetValFloat(float val) -{ - m_val = static_cast(val); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -int CBotVarBoolean::GetValInt() -{ - return m_val; -} - -//////////////////////////////////////////////////////////////////////////////// -float CBotVarBoolean::GetValFloat() -{ - return static_cast(m_val); -} - -//////////////////////////////////////////////////////////////////////////////// -std::string CBotVarBoolean::GetValString() -{ - std::string ret; - - std::string res; - - if ( m_binit == CBotVar::InitType::UNDEF ) - { - res = LoadString(TX_UNDEF); - return res; - } - if ( m_binit == CBotVar::InitType::IS_NAN ) - { - res = LoadString(TX_NAN); - return res; - } - - ret = LoadString( m_val > 0 ? ID_TRUE : ID_FALSE ); - return ret; -} - -//////////////////////////////////////////////////////////////////////////////// void CBotVarBoolean::And(CBotVar* left, CBotVar* right) { - m_val = left->GetValInt() && right->GetValInt(); - m_binit = CBotVar::InitType::DEF; + SetValInt(left->GetValInt() && right->GetValInt()); } - -//////////////////////////////////////////////////////////////////////////////// void CBotVarBoolean::Or(CBotVar* left, CBotVar* right) { - m_val = left->GetValInt() || right->GetValInt(); - m_binit = CBotVar::InitType::DEF; + SetValInt(left->GetValInt() || right->GetValInt()); } - -//////////////////////////////////////////////////////////////////////////////// void CBotVarBoolean::XOr(CBotVar* left, CBotVar* right) { - m_val = left->GetValInt() ^ right->GetValInt(); - m_binit = CBotVar::InitType::DEF; + SetValInt(left->GetValInt() ^ right->GetValInt()); } - -//////////////////////////////////////////////////////////////////////////////// void CBotVarBoolean::Not() { - m_val = m_val ? false : true ; + SetValInt(!GetValInt()); } -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarBoolean::Eq(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() == right->GetValInt(); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarBoolean::Ne(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() != right->GetValInt(); -} - -//////////////////////////////////////////////////////////////////////////////// bool CBotVarBoolean::Save1State(FILE* pf) { return WriteWord(pf, m_val); // the value of the variable diff --git a/src/CBot/CBotVar/CBotVarBoolean.h b/src/CBot/CBotVar/CBotVarBoolean.h index 6fee80ae..34f627bc 100644 --- a/src/CBot/CBotVar/CBotVarBoolean.h +++ b/src/CBot/CBotVar/CBotVarBoolean.h @@ -19,7 +19,7 @@ #pragma once -#include "CBot/CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVarValue.h" namespace CBot { @@ -27,35 +27,17 @@ namespace CBot /** * \brief CBotVar subclass for managing boolean values (::CBotTypBoolean) */ -class CBotVarBoolean : public CBotVar +class CBotVarBoolean : public CBotVarNumberBase { public: - /** - * \brief Constructor. Do not call directly, use CBotVar::Create() - */ - CBotVarBoolean(const CBotToken& name); - - void SetValInt(int val, const std::string& s = nullptr) override; - void SetValFloat(float val) override; - int GetValInt() override; - float GetValFloat() override; - std::string GetValString() override; - - void Copy(CBotVar* pSrc, bool bName = true) override; + CBotVarBoolean(const CBotToken &name) : CBotVarNumberBase(name) {} void And(CBotVar* left, CBotVar* right) override; void Or(CBotVar* left, CBotVar* right) override; void XOr(CBotVar* left, CBotVar* right) override; void Not() override; - bool Eq(CBotVar* left, CBotVar* right) override; - bool Ne(CBotVar* left, CBotVar* right) override; - bool Save1State(FILE* pf) override; - -private: - //! The value. - bool m_val; }; } // namespace CBot diff --git a/src/CBot/CBotVar/CBotVarFloat.cpp b/src/CBot/CBotVar/CBotVarFloat.cpp index ca178a3a..ae90966a 100644 --- a/src/CBot/CBotVar/CBotVarFloat.cpp +++ b/src/CBot/CBotVar/CBotVarFloat.cpp @@ -19,205 +19,9 @@ #include "CBot/CBotVar/CBotVarFloat.h" -#include "CBot/CBotEnums.h" -#include "CBot/CBotToken.h" - -#include "CBot/CBotUtils.h" - -#include - namespace CBot { -//////////////////////////////////////////////////////////////////////////////// -CBotVarFloat::CBotVarFloat(const CBotToken& name) -{ - m_token = new CBotToken(name); - m_next = nullptr; - m_pMyThis = nullptr; - m_pUserPtr = nullptr; - m_InitExpr = nullptr; - m_LimExpr = nullptr; - m_type = CBotTypFloat; - m_binit = InitType::UNDEF; - m_bStatic = false; - m_mPrivate = ProtectionLevel::Public; - - m_val = 0; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarFloat::Copy(CBotVar* pSrc, bool bName) -{ - CBotVarFloat* p = static_cast(pSrc); - - if (bName) *m_token = *p->m_token; - m_type = p->m_type; - m_val = p->m_val; - m_binit = p->m_binit; -//- m_bStatic = p->m_bStatic; - m_next = nullptr; - m_pMyThis = nullptr;//p->m_pMyThis; - m_pUserPtr = p->m_pUserPtr; - - // keeps indentificator the same (by default) - if (m_ident == 0 ) m_ident = p->m_ident; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarFloat::SetValInt(int val, const std::string& s) -{ - m_val = static_cast(val); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarFloat::SetValFloat(float val) -{ - m_val = val; - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -int CBotVarFloat::GetValInt() -{ - return static_cast(m_val); -} - -//////////////////////////////////////////////////////////////////////////////// -float CBotVarFloat::GetValFloat() -{ - return m_val; -} - -//////////////////////////////////////////////////////////////////////////////// -std::string CBotVarFloat::GetValString() -{ - std::string res; - - if ( m_binit == CBotVar::InitType::UNDEF ) - { - return LoadString(TX_UNDEF); - } - if ( m_binit == CBotVar::InitType::IS_NAN ) - { - return LoadString(TX_NAN); - } - - char buffer[300]; - sprintf(buffer, "%.2f", m_val); - res = buffer; - - return res; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarFloat::Mul(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValFloat() * right->GetValFloat(); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarFloat::Power(CBotVar* left, CBotVar* right) -{ - m_val = static_cast(pow( left->GetValFloat() , right->GetValFloat() )); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotError CBotVarFloat::Div(CBotVar* left, CBotVar* right) -{ - float r = right->GetValFloat(); - if ( r != 0 ) - { - m_val = left->GetValFloat() / r; - m_binit = CBotVar::InitType::DEF; - } - return ( r == 0 ? CBotErrZeroDiv : CBotNoErr ); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotError CBotVarFloat::Modulo(CBotVar* left, CBotVar* right) -{ - float r = right->GetValFloat(); - if ( r != 0 ) - { - m_val = static_cast(fmod( left->GetValFloat() , r )); - m_binit = CBotVar::InitType::DEF; - } - return ( r == 0 ? CBotErrZeroDiv : CBotNoErr ); -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarFloat::Add(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValFloat() + right->GetValFloat(); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarFloat::Sub(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValFloat() - right->GetValFloat(); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarFloat::Neg() -{ - m_val = -m_val; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarFloat::Inc() -{ - m_val++; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarFloat::Dec() -{ - m_val--; -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarFloat::Lo(CBotVar* left, CBotVar* right) -{ - return left->GetValFloat() < right->GetValFloat(); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarFloat::Hi(CBotVar* left, CBotVar* right) -{ - return left->GetValFloat() > right->GetValFloat(); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarFloat::Ls(CBotVar* left, CBotVar* right) -{ - return left->GetValFloat() <= right->GetValFloat(); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarFloat::Hs(CBotVar* left, CBotVar* right) -{ - return left->GetValFloat() >= right->GetValFloat(); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarFloat::Eq(CBotVar* left, CBotVar* right) -{ - return left->GetValFloat() == right->GetValFloat(); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarFloat::Ne(CBotVar* left, CBotVar* right) -{ - return left->GetValFloat() != right->GetValFloat(); -} - -//////////////////////////////////////////////////////////////////////////////// bool CBotVarFloat::Save1State(FILE* pf) { return WriteFloat(pf, m_val); // the value of the variable diff --git a/src/CBot/CBotVar/CBotVarFloat.h b/src/CBot/CBotVar/CBotVarFloat.h index 0e294867..84324e60 100644 --- a/src/CBot/CBotVar/CBotVarFloat.h +++ b/src/CBot/CBotVar/CBotVarFloat.h @@ -19,7 +19,7 @@ #pragma once -#include "CBot/CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVarValue.h" namespace CBot { @@ -27,45 +27,12 @@ namespace CBot /** * \brief CBotVar subclass for managing float values (::CBotTypFloat) */ -class CBotVarFloat : public CBotVar +class CBotVarFloat : public CBotVarNumber { public: - /** - * \brief Constructor. Do not call directly, use CBotVar::Create() - */ - CBotVarFloat(const CBotToken& name); - - void SetValInt(int val, const std::string& s = nullptr) override; - void SetValFloat(float val) override; - int GetValInt() override; - float GetValFloat() override; - std::string GetValString() override; - - void Copy(CBotVar* pSrc, bool bName = true) override; - - void Add(CBotVar* left, CBotVar* right) override; - void Sub(CBotVar* left, CBotVar* right) override; - void Mul(CBotVar* left, CBotVar* right) override; - CBotError Div(CBotVar* left, CBotVar* right) override; - CBotError Modulo(CBotVar* left, CBotVar* right) override; - void Power(CBotVar* left, CBotVar* right) override; - - bool Lo(CBotVar* left, CBotVar* right) override; - bool Hi(CBotVar* left, CBotVar* right) override; - bool Ls(CBotVar* left, CBotVar* right) override; - bool Hs(CBotVar* left, CBotVar* right) override; - bool Eq(CBotVar* left, CBotVar* right) override; - bool Ne(CBotVar* left, CBotVar* right) override; - - void Neg() override; - void Inc() override; - void Dec() override; + CBotVarFloat(const CBotToken &name) : CBotVarNumber(name) {} bool Save1State(FILE* pf) override; - -private: - //! The value. - float m_val; }; } // namespace CBot diff --git a/src/CBot/CBotVar/CBotVarInt.cpp b/src/CBot/CBotVar/CBotVarInt.cpp index 00704903..29715c9b 100644 --- a/src/CBot/CBotVar/CBotVarInt.cpp +++ b/src/CBot/CBotVar/CBotVarInt.cpp @@ -19,276 +19,93 @@ #include "CBot/CBotVar/CBotVarInt.h" -#include "CBot/CBotEnums.h" -#include "CBot/CBotToken.h" -#include "CBot/CBotUtils.h" - -#include - namespace CBot { -//////////////////////////////////////////////////////////////////////////////// -CBotVarInt::CBotVarInt(const CBotToken& name) -{ - m_token = new CBotToken(name); - m_next = nullptr; - m_pMyThis = nullptr; - m_pUserPtr = nullptr; - m_InitExpr = nullptr; - m_LimExpr = nullptr; - m_type = CBotTypInt; - m_binit = InitType::UNDEF; - m_bStatic = false; - m_mPrivate = ProtectionLevel::Public; - - m_val = 0; -} - -//////////////////////////////////////////////////////////////////////////////// void CBotVarInt::Copy(CBotVar* pSrc, bool bName) { - CBotVarInt* p = static_cast(pSrc); - - if ( bName) *m_token = *p->m_token; - m_type = p->m_type; - m_val = p->m_val; - m_binit = p->m_binit; - m_pMyThis = nullptr; - m_pUserPtr = p->m_pUserPtr; - - // identificator is the same (by défaut) - if (m_ident == 0 ) m_ident = p->m_ident; - - m_defnum = p->m_defnum; + CBotVarNumber::Copy(pSrc, bName); + CBotVarInt* p = static_cast(pSrc); + m_defnum = p->m_defnum; } -//////////////////////////////////////////////////////////////////////////////// void CBotVarInt::SetValInt(int val, const std::string& defnum) { - m_val = val; - m_binit = CBotVar::InitType::DEF; + CBotVarNumber::SetValInt(val, defnum); m_defnum = defnum; } -//////////////////////////////////////////////////////////////////////////////// -void CBotVarInt::SetValFloat(float val) -{ - m_val = static_cast(val); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -int CBotVarInt::GetValInt() -{ - return m_val; -} - -//////////////////////////////////////////////////////////////////////////////// -float CBotVarInt::GetValFloat() -{ - return static_cast(m_val); -} - -//////////////////////////////////////////////////////////////////////////////// std::string CBotVarInt::GetValString() { - if ( !m_defnum.empty() ) return m_defnum; - - std::string res; - - if ( m_binit == CBotVar::InitType::UNDEF ) - { - return LoadString(TX_UNDEF); - } - - if ( m_binit == CBotVar::InitType::IS_NAN ) - { - return LoadString(TX_NAN); - } - - char buffer[300]; - sprintf(buffer, "%d", m_val); - res = buffer; - - return res; + if (!m_defnum.empty()) return m_defnum; + return CBotVarValue::GetValString(); } -//////////////////////////////////////////////////////////////////////////////// -void CBotVarInt::Mul(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() * right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} -//////////////////////////////////////////////////////////////////////////////// -void CBotVarInt::Power(CBotVar* left, CBotVar* right) -{ - m_val = static_cast( pow( static_cast(left->GetValInt()) , static_cast(right->GetValInt()) )); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotError CBotVarInt::Div(CBotVar* left, CBotVar* right) -{ - int r = right->GetValInt(); - if ( r != 0 ) - { - m_val = left->GetValInt() / r; - m_binit = CBotVar::InitType::DEF; - } - return ( r == 0 ? CBotErrZeroDiv : CBotNoErr ); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotError CBotVarInt::Modulo(CBotVar* left, CBotVar* right) -{ - int r = right->GetValInt(); - if ( r != 0 ) - { - m_val = left->GetValInt() % r; - m_binit = CBotVar::InitType::DEF; - } - return ( r == 0 ? CBotErrZeroDiv : CBotNoErr ); -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarInt::Add(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() + right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarInt::Sub(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() - right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarInt::XOr(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() ^ right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarInt::And(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() & right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarInt::Or(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() | right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarInt::SL(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() << right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarInt::ASR(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() >> right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarInt::SR(CBotVar* left, CBotVar* right) -{ - int source = left->GetValInt(); - int shift = right->GetValInt(); - if (shift>=1) source &= 0x7fffffff; - m_val = source >> shift; - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// void CBotVarInt::Neg() { - m_val = -m_val; + CBotVarNumber::Neg(); + m_defnum.empty(); +} +void CBotVarInt::Inc() +{ + CBotVarNumber::Inc(); + m_defnum.empty(); +} +void CBotVarInt::Dec() +{ + CBotVarNumber::Dec(); + m_defnum.empty(); +} + +void CBotVarInt::XOr(CBotVar* left, CBotVar* right) +{ + SetValInt(left->GetValInt() ^ right->GetValInt()); +} +void CBotVarInt::And(CBotVar* left, CBotVar* right) +{ + SetValInt(left->GetValInt() & right->GetValInt()); +} +void CBotVarInt::Or(CBotVar* left, CBotVar* right) +{ + SetValInt(left->GetValInt() | right->GetValInt()); +} + +void CBotVarInt::SL(CBotVar* left, CBotVar* right) +{ + SetValInt(left->GetValInt() << right->GetValInt()); +} +void CBotVarInt::ASR(CBotVar* left, CBotVar* right) +{ + SetValInt(left->GetValInt() >> right->GetValInt()); +} +void CBotVarInt::SR(CBotVar* left, CBotVar* right) +{ + int source = left->GetValInt(); + int shift = right->GetValInt(); + if (shift >= 1) source &= 0x7fffffff; + SetValInt(source >> shift); } -//////////////////////////////////////////////////////////////////////////////// void CBotVarInt::Not() { m_val = ~m_val; } -//////////////////////////////////////////////////////////////////////////////// -void CBotVarInt::Inc() -{ - m_val++; - m_defnum.empty(); -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarInt::Dec() -{ - m_val--; - m_defnum.empty(); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarInt::Lo(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() < right->GetValInt(); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarInt::Hi(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() > right->GetValInt(); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarInt::Ls(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() <= right->GetValInt(); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarInt::Hs(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() >= right->GetValInt(); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarInt::Eq(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() == right->GetValInt(); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarInt::Ne(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() != right->GetValInt(); -} - -//////////////////////////////////////////////////////////////////////////////// bool CBotVarInt::Save0State(FILE* pf) { - if ( !m_defnum.empty() ) + if (!m_defnum.empty()) { - if(!WriteWord(pf, 200 )) return false; // special marker - if(!WriteString(pf, m_defnum)) return false; // name of the value + if(!WriteWord(pf, 200)) return false; // special marker + if(!WriteString(pf, m_defnum)) return false; } return CBotVar::Save0State(pf); } -//////////////////////////////////////////////////////////////////////////////// bool CBotVarInt::Save1State(FILE* pf) { - return WriteWord(pf, m_val); // the value of the variable + return WriteWord(pf, m_val); } } // namespace CBot diff --git a/src/CBot/CBotVar/CBotVarInt.h b/src/CBot/CBotVar/CBotVarInt.h index 8d7d4f97..32d0af0b 100644 --- a/src/CBot/CBotVar/CBotVarInt.h +++ b/src/CBot/CBotVar/CBotVarInt.h @@ -19,7 +19,7 @@ #pragma once -#include "CBot/CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVarValue.h" namespace CBot { @@ -27,35 +27,19 @@ namespace CBot /** * \brief CBotVar subclass for managing integer values (::CBotTypInt) */ -class CBotVarInt : public CBotVar +class CBotVarInt : public CBotVarNumber { public: - /** - * \brief Constructor. Do not call directly, use CBotVar::Create() - */ - CBotVarInt(const CBotToken& name); + CBotVarInt(const CBotToken &name) : CBotVarNumber(name) {} void SetValInt(int val, const std::string& s = "") override; - void SetValFloat(float val) override; - int GetValInt() override; - float GetValFloat() override; std::string GetValString() override; void Copy(CBotVar* pSrc, bool bName = true) override; - void Add(CBotVar* left, CBotVar* right) override; - void Sub(CBotVar* left, CBotVar* right) override; - void Mul(CBotVar* left, CBotVar* right) override; - CBotError Div(CBotVar* left, CBotVar* right) override; - CBotError Modulo(CBotVar* left, CBotVar* right) override; - void Power(CBotVar* left, CBotVar* right) override; - - bool Lo(CBotVar* left, CBotVar* right) override; - bool Hi(CBotVar* left, CBotVar* right) override; - bool Ls(CBotVar* left, CBotVar* right) override; - bool Hs(CBotVar* left, CBotVar* right) override; - bool Eq(CBotVar* left, CBotVar* right) override; - bool Ne(CBotVar* left, CBotVar* right) override; + void Neg() override; + void Inc() override; + void Dec() override; void XOr(CBotVar* left, CBotVar* right) override; void Or(CBotVar* left, CBotVar* right) override; @@ -66,16 +50,10 @@ public: void SR(CBotVar* left, CBotVar* right) override; void ASR(CBotVar* left, CBotVar* right) override; - void Neg() override; - void Inc() override; - void Dec() override; - bool Save0State(FILE* pf) override; bool Save1State(FILE* pf) override; -private: - //! The value. - int m_val; +protected: //! The name if given by DefineNum. std::string m_defnum; friend class CBotVar; diff --git a/src/CBot/CBotVar/CBotVarString.cpp b/src/CBot/CBotVar/CBotVarString.cpp index 653badf6..a5f3bba6 100644 --- a/src/CBot/CBotVar/CBotVarString.cpp +++ b/src/CBot/CBotVar/CBotVarString.cpp @@ -19,117 +19,27 @@ #include "CBot/CBotVar/CBotVarString.h" -#include "CBot/CBotEnums.h" -#include "CBot/CBotToken.h" -#include "CBot/CBotUtils.h" - namespace CBot { -//////////////////////////////////////////////////////////////////////////////// -CBotVarString::CBotVarString(const CBotToken& name) -{ - m_token = new CBotToken(name); - m_next = nullptr; - m_pMyThis = nullptr; - m_pUserPtr = nullptr; - m_InitExpr = nullptr; - m_LimExpr = nullptr; - m_type = CBotTypString; - m_binit = InitType::UNDEF; - m_bStatic = false; - m_mPrivate = ProtectionLevel::Public; - - m_val.clear(); -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarString::Copy(CBotVar* pSrc, bool bName) -{ - CBotVarString* p = static_cast(pSrc); - - if (bName) *m_token = *p->m_token; - m_type = p->m_type; - m_val = p->m_val; - m_binit = p->m_binit; -//- m_bStatic = p->m_bStatic; - m_next = nullptr; - m_pMyThis = nullptr;//p->m_pMyThis; - m_pUserPtr = p->m_pUserPtr; - - // keeps indentificator the same (by default) - if (m_ident == 0 ) m_ident = p->m_ident; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotVarString::SetValString(const std::string& val) -{ - m_val = val; - m_binit = CBotVar::InitType::DEF; -} - -//////////////////////////////////////////////////////////////////////////////// -std::string CBotVarString::GetValString() -{ - if ( m_binit == CBotVar::InitType::UNDEF ) - { - return LoadString(TX_UNDEF); - } - if ( m_binit == CBotVar::InitType::IS_NAN ) - { - return LoadString(TX_NAN); - } - - return m_val; -} - -//////////////////////////////////////////////////////////////////////////////// void CBotVarString::Add(CBotVar* left, CBotVar* right) { - m_val = left->GetValString() + right->GetValString(); - m_binit = CBotVar::InitType::DEF; + SetValString(left->GetValString() + right->GetValString()); } -//////////////////////////////////////////////////////////////////////////////// bool CBotVarString::Eq(CBotVar* left, CBotVar* right) { - return (left->GetValString() == right->GetValString()); + return left->GetValString() == right->GetValString(); } -//////////////////////////////////////////////////////////////////////////////// bool CBotVarString::Ne(CBotVar* left, CBotVar* right) { - return (left->GetValString() != right->GetValString()); + return left->GetValString() != right->GetValString(); } -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarString::Lo(CBotVar* left, CBotVar* right) -{ - return (left->GetValString() == right->GetValString()); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarString::Hi(CBotVar* left, CBotVar* right) -{ - return (left->GetValString() == right->GetValString()); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarString::Ls(CBotVar* left, CBotVar* right) -{ - return (left->GetValString() == right->GetValString()); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarString::Hs(CBotVar* left, CBotVar* right) -{ - return (left->GetValString() == right->GetValString()); -} - -//////////////////////////////////////////////////////////////////////////////// bool CBotVarString::Save1State(FILE* pf) { - return WriteString(pf, m_val); // the value of the variable + return WriteString(pf, m_val); } } // namespace CBot diff --git a/src/CBot/CBotVar/CBotVarString.h b/src/CBot/CBotVar/CBotVarString.h index 136294e5..5ff29d15 100644 --- a/src/CBot/CBotVar/CBotVarString.h +++ b/src/CBot/CBotVar/CBotVarString.h @@ -19,7 +19,7 @@ #pragma once -#include "CBot/CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVarValue.h" namespace CBot { @@ -27,33 +27,55 @@ namespace CBot /** * \brief CBotVar subclass for managing string values (::CBotTypString) */ -class CBotVarString : public CBotVar +class CBotVarString : public CBotVarValue { public: - /** - * \brief Constructor. Do not call directly, use CBotVar::Create() - */ - CBotVarString(const CBotToken& name); + CBotVarString(const CBotToken &name) : CBotVarValue(name) {} - void SetValString(const std::string& val) override; - std::string GetValString() override; + void SetValInt(int val, const std::string& s = "") override + { + SetValString(ToString(val)); + } - void Copy(CBotVar* pSrc, bool bName = true) override; + void SetValFloat(float val) override + { + SetValString(ToString(val)); + } + + int GetValInt() + { + return FromString(GetValString()); + } + + float GetValFloat() + { + return FromString(GetValString()); + } void Add(CBotVar* left, CBotVar* right) override; - bool Lo(CBotVar* left, CBotVar* right) override; - bool Hi(CBotVar* left, CBotVar* right) override; - bool Ls(CBotVar* left, CBotVar* right) override; - bool Hs(CBotVar* left, CBotVar* right) override; bool Eq(CBotVar* left, CBotVar* right) override; bool Ne(CBotVar* left, CBotVar* right) override; bool Save1State(FILE* pf) override; private: - //! The value. - std::string m_val; + template + static std::string ToString(T val) + { + std::ostringstream ss; + ss << val; + return ss.str(); + } + + template + static T FromString(std::string val) + { + std::istringstream ss(val); + T v; + ss >> v; + return v; + } }; } // namespace CBot diff --git a/src/CBot/CBotVar/CBotVarValue.h b/src/CBot/CBotVar/CBotVarValue.h new file mode 100644 index 00000000..3e184d7b --- /dev/null +++ b/src/CBot/CBotVar/CBotVarValue.h @@ -0,0 +1,177 @@ +#pragma once + +#include "CBot/CBotVar/CBotVar.h" + +#include "CBot/CBotEnums.h" +#include "CBot/CBotToken.h" + +#include +#include + + +namespace CBot +{ + +/** + * \brief A variable holding a simple value (bool, int, float, string) + */ +template +class CBotVarValue : public CBotVar +{ +public: + /** + * \brief Constructor. Do not call directly, use CBotVar::Create() + */ + CBotVarValue(const CBotToken& name) : CBotVar(name) + { + m_type = type; + } + + void Copy(CBotVar* pSrc, bool bName = true) override + { + CBotVar::Copy(pSrc, bName); + + CBotVarValue* p = static_cast(pSrc); + m_val = p->m_val; + } + + + void SetValString(const std::string& val) override + { + std::istringstream s(val); + s >> m_val; + m_binit = CBotVar::InitType::DEF; + } + + std::string GetValString() override + { + if (m_binit == CBotVar::InitType::UNDEF) + return LoadString(TX_UNDEF); + if (m_binit == CBotVar::InitType::IS_NAN) + return LoadString(TX_NAN); + + std::ostringstream s; + s << m_val; + return s.str(); + } + +protected: + //! The value + T m_val; +}; + +/** + * \brief A number based variable (bool, int, float) + */ +template +class CBotVarNumberBase : public CBotVarValue +{ +public: + CBotVarNumberBase(const CBotToken &name) : CBotVarValue(name) {} + + void SetValInt(int val, const std::string &s = "") override + { + this->m_val = static_cast(val); + this->m_binit = CBotVar::InitType::DEF; + } + + void SetValFloat(float val) override + { + this->m_val = static_cast(val); + this->m_binit = CBotVar::InitType::DEF; + } + + int GetValInt() override + { + return static_cast(this->m_val); + } + + float GetValFloat() override + { + return static_cast(this->m_val); + } + + + bool Eq(CBotVar* left, CBotVar* right) override + { + return left->GetValFloat() == right->GetValFloat(); + } + bool Ne(CBotVar* left, CBotVar* right) override + { + return left->GetValFloat() != right->GetValFloat(); + } +}; + +/** + * \brief A number variable (int, float) + */ +template +class CBotVarNumber : public CBotVarNumberBase +{ +public: + CBotVarNumber(const CBotToken &name) : CBotVarNumberBase(name) {} + + void Mul(CBotVar* left, CBotVar* right) override + { + this->SetValFloat(left->GetValFloat() * right->GetValFloat()); + } + void Power(CBotVar* left, CBotVar* right) override + { + this->SetValFloat(pow(left->GetValFloat(), right->GetValFloat())); + } + CBotError Div(CBotVar* left, CBotVar* right) override + { + float r = right->GetValFloat(); + if (r == 0) return CBotErrZeroDiv; + this->SetValFloat(left->GetValFloat() / r); + return CBotNoErr; + } + CBotError Modulo(CBotVar* left, CBotVar* right) override + { + float r = right->GetValFloat(); + if (r == 0) return CBotErrZeroDiv; + this->SetValFloat(fmod(left->GetValFloat(), r)); + return CBotNoErr; + } + void Add(CBotVar* left, CBotVar* right) override + { + this->SetValFloat(left->GetValFloat() + right->GetValFloat()); + } + void Sub(CBotVar* left, CBotVar* right) override + { + this->SetValFloat(left->GetValFloat() - right->GetValFloat()); + } + + void Neg() override + { + this->m_val = - this->m_val; + } + void Inc() override + { + this->m_val++; + } + void Dec() override + { + this->m_val--; + } + + bool Lo(CBotVar* left, CBotVar* right) override + { + return left->GetValFloat() < right->GetValFloat(); + } + bool Hi(CBotVar* left, CBotVar* right) override + { + return left->GetValFloat() > right->GetValFloat(); + } + bool Ls(CBotVar* left, CBotVar* right) override + { + return left->GetValFloat() <= right->GetValFloat(); + } + bool Hs(CBotVar* left, CBotVar* right) override + { + return left->GetValFloat() >= right->GetValFloat(); + } +}; + +} + diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index dbd3d02e..b77d0bbc 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -122,6 +122,7 @@ set(SOURCES CBotUtils.h CBotVar/CBotVar.cpp CBotVar/CBotVar.h + CBotVar/CBotVarValue.h CBotVar/CBotVarArray.cpp CBotVar/CBotVarArray.h CBotVar/CBotVarBoolean.cpp From 7b32f6388f08094d1631f7d74942826c4a33aee6 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 28 May 2016 23:33:49 +0200 Subject: [PATCH 091/125] Enabled fixed test --- test/unit/CBot/CBot_test.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/unit/CBot/CBot_test.cpp b/test/unit/CBot/CBot_test.cpp index 129d7972..e3c25db6 100644 --- a/test/unit/CBot/CBot_test.cpp +++ b/test/unit/CBot/CBot_test.cpp @@ -441,8 +441,7 @@ TEST_F(CBotUT, VarDefinitions) } // TODO: I don't actually know what the exact rules should be, but it looks a bit wrong -// TODO: Current version of this code causes a failed assertion -TEST_F(CBotUT, DISABLED_VarImplicitCast) +TEST_F(CBotUT, VarImplicitCast) { ExecuteTest( "extern void ImplicitCast()\n" @@ -464,7 +463,7 @@ TEST_F(CBotUT, DISABLED_VarImplicitCast) "{\n" " string a = 2;\n" " ASSERT(a == \"2\");\n" - //" a = 3;\n" + //" a = 3;\n" // TODO: this certainly looks wrong, you an assign a number in initialization but not in assignment //" ASSERT(a == \"3\");\n" " string b = 2.5;\n" " ASSERT(b == \"2.5\");\n" From b56cd11c9805e49957f13f7535cfbdc9c3a1dce7 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 29 May 2016 00:06:34 +0200 Subject: [PATCH 092/125] Added C++ operator overloads to CBotVar --- src/CBot/CBotVar/CBotVar.cpp | 34 ++++++++++++++++++++++++++++++++++ src/CBot/CBotVar/CBotVar.h | 8 ++++++++ 2 files changed, 42 insertions(+) diff --git a/src/CBot/CBotVar/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp index fc4503ea..4e88cd69 100644 --- a/src/CBot/CBotVar/CBotVar.cpp +++ b/src/CBot/CBotVar/CBotVar.cpp @@ -741,5 +741,39 @@ CBotClass* CBotVar::GetClass() return nullptr; } +CBotVar::operator int() +{ + return GetValInt(); +} + +CBotVar::operator float() +{ + return GetValFloat(); +} + +CBotVar::operator std::string() +{ + return GetValString(); +} + +void CBotVar::operator=(const CBotVar &var) +{ + SetVal(const_cast(&var)); +} + +void CBotVar::operator=(int x) +{ + SetValInt(x); +} + +void CBotVar::operator=(float x) +{ + SetValFloat(x); +} + +void CBotVar::operator=(const std::string &x) +{ + SetValString(x); +} } // namespace CBot diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h index be171783..7babb7d1 100644 --- a/src/CBot/CBotVar/CBotVar.h +++ b/src/CBot/CBotVar/CBotVar.h @@ -444,6 +444,14 @@ public: */ //@{ + operator int(); + operator float(); + operator std::string(); + void operator=(const CBotVar& var); + void operator=(int x); + void operator=(float x); + void operator=(const std::string &x); + /** * \brief Set the value * \param var Another variable to copy value from From 0165e8f348f7e257d8866287ae440ec4c8051916 Mon Sep 17 00:00:00 2001 From: melex750 Date: Sun, 29 May 2016 06:40:42 -0400 Subject: [PATCH 093/125] Fix and document TypeCompatible --- src/CBot/CBotInstr/CBotInstrUtils.cpp | 6 +++--- src/CBot/CBotInstr/CBotInstrUtils.h | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/CBot/CBotInstr/CBotInstrUtils.cpp b/src/CBot/CBotInstr/CBotInstrUtils.cpp index 05de1a47..bbe80b27 100644 --- a/src/CBot/CBotInstr/CBotInstrUtils.cpp +++ b/src/CBot/CBotInstr/CBotInstrUtils.cpp @@ -97,9 +97,9 @@ bool TypeCompatible(CBotTypResult& type1, CBotTypResult& type2, int op) if (max == 99) return false; // result is void? // special case for strin concatenation - if (op == ID_ADD && max >= CBotTypString) return true; - if (op == ID_ASSADD && max >= CBotTypString) return true; - if (op == ID_ASS && t1 == CBotTypString) return true; + if (op == ID_ADD && t1 == CBotTypString) return true; + if (op == ID_ASSADD && t2 == CBotTypString) return true; + if (op == ID_ASS && t2 == CBotTypString) return true; if (max >= CBotTypBoolean) { diff --git a/src/CBot/CBotInstr/CBotInstrUtils.h b/src/CBot/CBotInstr/CBotInstrUtils.h index a609988d..b5302883 100644 --- a/src/CBot/CBotInstr/CBotInstrUtils.h +++ b/src/CBot/CBotInstr/CBotInstrUtils.h @@ -39,7 +39,13 @@ CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars); /*! * \brief TypeCompatible Check if two results are consistent to make an - * operation. + * operation. TypeCompatible is used in two ways: + * For non-assignment operations: see CBotTwoOpExpr::Compile + * TypeCompatible( leftType, rightType, opType ) + + * For assignment or compound assignment operations (it's reversed): + * see CBotReturn::Compile & CBotExpression::Compile + * TypeCompatible( valueType, varType, opType ) * \param type1 * \param type2 * \param op From 6db2832577578dc7eda5c805513de99b5cf3ef22 Mon Sep 17 00:00:00 2001 From: melex750 Date: Sun, 29 May 2016 06:45:08 -0400 Subject: [PATCH 094/125] Fix conversion to string with + operator --- src/CBot/CBotInstr/CBotTwoOpExpr.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp index 23e11531..41321032 100644 --- a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp @@ -214,6 +214,13 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera type2 = pStk->GetTypResult(); // what kind of results? + if ( type1.Eq(99) || type2.Eq(99) ) // operand is void + { + pStack->SetError(CBotErrBadType2, &inst->m_token); + delete inst; + return nullptr; + } + // what kind of result? int TypeRes = std::max( type1.GetType(CBotTypResult::GetTypeMode::NULL_AS_POINTER), type2.GetType(CBotTypResult::GetTypeMode::NULL_AS_POINTER) ); if (typeOp == ID_ADD && type1.Eq(CBotTypString)) @@ -267,7 +274,7 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera return pStack->Return(nullptr, pStk); } - if ( TypeRes != CBotTypString ) + if ( TypeRes != CBotTypString ) // keep string conversion TypeRes = std::max(type1.GetType(), type2.GetType()); inst = i; } @@ -370,7 +377,9 @@ bool CBotTwoOpExpr::Execute(CBotStack* &pStack) // what kind of result? int TypeRes = std::max(type1.GetType(), type2.GetType()); - if ( GetTokenType() == ID_ADD && type1.Eq(CBotTypString) ) + // see "any type convertible chain" in compile method + if ( GetTokenType() == ID_ADD && + (type1.Eq(CBotTypString) || type2.Eq(CBotTypString)) ) { TypeRes = CBotTypString; } @@ -397,7 +406,8 @@ bool CBotTwoOpExpr::Execute(CBotStack* &pStack) CBotVar* result = CBotVar::Create("", TypeRes); // creates a variable to perform the calculation in the appropriate type - TypeRes = std::max(type1.GetType(), type2.GetType()); + if ( TypeRes != CBotTypString ) // keep string conversion + TypeRes = std::max(type1.GetType(), type2.GetType()); if ( GetTokenType() == ID_ADD && type1.Eq(CBotTypString) ) { From 37ab015c8db1c29cbd01e849fd6cc586b60c794d Mon Sep 17 00:00:00 2001 From: melex750 Date: Sun, 29 May 2016 06:55:28 -0400 Subject: [PATCH 095/125] Fix conversion to string with = operator --- src/CBot/CBotInstr/CBotExpression.cpp | 23 +++++++++++++++++++++-- src/CBot/CBotInstr/CBotLeftExprVar.cpp | 6 ++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/CBot/CBotInstr/CBotExpression.cpp b/src/CBot/CBotInstr/CBotExpression.cpp index cb7f3dfc..c98deca5 100644 --- a/src/CBot/CBotInstr/CBotExpression.cpp +++ b/src/CBot/CBotInstr/CBotExpression.cpp @@ -71,6 +71,13 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) return nullptr; } + if ( p->GetType() == ID_SEP ) + { + pStack->SetError(CBotErrNoExpression, p); + delete inst; + return nullptr; + } + inst->m_rightop = CBotExpression::Compile(p, pStack); if (inst->m_rightop == nullptr) { @@ -118,13 +125,13 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) break; case ID_ASSADD: if (type2.Eq(CBotTypBoolean) || - type2.Eq(CBotTypPointer) ) type2 = -1; // numbers and strings + type2.GetType() > CBotTypString ) type2.SetType(-1); // numbers and strings break; case ID_ASSSUB: case ID_ASSMUL: case ID_ASSDIV: case ID_ASSMODULO: - if (type2.GetType() >= CBotTypBoolean) type2 = -1; // numbers only + if (type2.GetType() >= CBotTypBoolean) type2.SetType(-1); // numbers only break; } @@ -179,6 +186,18 @@ bool CBotExpression::Execute(CBotStack* &pj) if ( pile2->GetState()==0) { if (m_rightop && !m_rightop->Execute(pile2)) return false; // initial value // interrupted? + if (m_rightop) + { + CBotVar* var = pile1->GetVar(); + CBotVar* value = pile2->GetVar(); + if (var->GetType() == CBotTypString && value->GetType() != CBotTypString) + { + CBotVar* newVal = CBotVar::Create("", var->GetTypResult()); + value->Update(pj->GetUserPtr()); + newVal->SetValString(value->GetValString()); + pile2->SetVar(newVal); + } + } pile2->IncState(); } diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.cpp b/src/CBot/CBotInstr/CBotLeftExprVar.cpp index 848d16a8..4394fc43 100644 --- a/src/CBot/CBotInstr/CBotLeftExprVar.cpp +++ b/src/CBot/CBotInstr/CBotLeftExprVar.cpp @@ -64,6 +64,12 @@ bool CBotLeftExprVar::Execute(CBotStack* &pj) CBotVar* var2 = pj->GetVar(); // Initial value on the stack if (var2 != nullptr) { + if (m_typevar.Eq(CBotTypString) && var2->GetType() != CBotTypString) + { + var2->Update(pj->GetUserPtr()); + var1->SetValString(var2->GetValString()); + return true; + } var1->SetVal(var2); // Set the value } From 2168b57cac9e20738718e323cf55ff3dbf9c733b Mon Sep 17 00:00:00 2001 From: Krzysztof Dermont Date: Sun, 10 Apr 2016 21:48:19 +0200 Subject: [PATCH 096/125] Remove part of boost::filesystem usage. --- src/app/app.cpp | 1 - src/common/resources/resourcemanager.cpp | 20 +++++--------------- src/sound/oalsound/alsound.cpp | 6 ------ src/sound/sound.cpp | 2 -- 4 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index c1439ff1..d34532f7 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -47,7 +47,6 @@ #include "sound/oalsound/alsound.h" #endif -#include #include #include diff --git a/src/common/resources/resourcemanager.cpp b/src/common/resources/resourcemanager.cpp index 94326a9f..9130b889 100644 --- a/src/common/resources/resourcemanager.cpp +++ b/src/common/resources/resourcemanager.cpp @@ -152,27 +152,17 @@ bool CResourceManager::CreateDirectory(const std::string& directory) return false; } -//TODO: Don't use boost::filesystem here bool CResourceManager::RemoveDirectory(const std::string& directory) { if (PHYSFS_isInit()) { - bool success = true; - std::string writeDir = PHYSFS_getWriteDir(); - try + std::string path = CleanPath(directory); + for (auto file : ListFiles(path)) { - std::string path = writeDir + "/" + CleanPath(directory); - #if PLATFORM_WINDOWS - fs::remove_all(CSystemUtilsWindows::UTF8_Decode(path)); - #else - fs::remove_all(path); - #endif + if (PHYSFS_delete((path + "/" + file).c_str()) == 0) + return false; } - catch (std::exception&) - { - success = false; - } - return success; + return PHYSFS_delete(path.c_str()) != 0; } return false; } diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 95b49a98..cfa335d1 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -25,7 +25,6 @@ #include #include -#include CALSound::CALSound() : m_enabled(false), @@ -586,11 +585,6 @@ bool CALSound::PlayMusic(const std::string &filename, bool repeat, float fadeTim if (m_music.find(filename) == m_music.end()) { GetLogger()->Debug("Music %s was not cached!\n", filename.c_str()); - /* TODO: if (!boost::filesystem::exists(filename)) - { - GetLogger()->Debug("Requested music %s was not found.\n", filename.c_str()); - return false; - } */ auto newBuffer = MakeUnique(); buffer = newBuffer.get(); diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp index d22523f0..3640c585 100644 --- a/src/sound/sound.cpp +++ b/src/sound/sound.cpp @@ -27,8 +27,6 @@ #include #include -#include - CSoundInterface::CSoundInterface() { From 32629a2f2ad631ccb8774ac846795208d4c87d18 Mon Sep 17 00:00:00 2001 From: Krzysztof Dermont Date: Sun, 15 May 2016 19:42:27 +0200 Subject: [PATCH 097/125] Refactor autosave rotation. In order to remove boost:filesystem from CResourceManager Move() function has to be removed or rewrited. Since Move is only used in autosave rotation it's simpler to change autosave rotation and remove Move(). Now oldest autosaves (with lowest timestamp) will be removed in rotation. --- src/common/resources/resourcemanager.cpp | 29 -------- src/common/resources/resourcemanager.h | 2 - src/level/robotmain.cpp | 85 ++++++------------------ src/level/robotmain.h | 2 +- src/ui/screen/screen_io.cpp | 2 +- 5 files changed, 22 insertions(+), 98 deletions(-) diff --git a/src/common/resources/resourcemanager.cpp b/src/common/resources/resourcemanager.cpp index 9130b889..3ed0dee6 100644 --- a/src/common/resources/resourcemanager.cpp +++ b/src/common/resources/resourcemanager.cpp @@ -31,11 +31,8 @@ #include -#include #include -namespace fs = boost::filesystem; - CResourceManager::CResourceManager(const char *argv0) { @@ -231,32 +228,6 @@ long long CResourceManager::GetLastModificationTime(const std::string& filename) return -1; } -//TODO: Don't use boost::filesystem. Why doesn't PHYSFS have this? -bool CResourceManager::Move(const std::string& from, const std::string& to) -{ - if (PHYSFS_isInit()) - { - bool success = true; - std::string writeDir = PHYSFS_getWriteDir(); - try - { - std::string path_from = writeDir + "/" + CleanPath(from); - std::string path_to = writeDir + "/" + CleanPath(to); - #if PLATFORM_WINDOWS - fs::rename(CSystemUtilsWindows::UTF8_Decode(path_from), CSystemUtilsWindows::UTF8_Decode(path_to)); - #else - fs::rename(path_from, path_to); - #endif - } - catch (std::exception&) - { - success = false; - } - return success; - } - return false; -} - bool CResourceManager::Remove(const std::string& filename) { if (PHYSFS_isInit()) diff --git a/src/common/resources/resourcemanager.h b/src/common/resources/resourcemanager.h index b21ad267..61f85b38 100644 --- a/src/common/resources/resourcemanager.h +++ b/src/common/resources/resourcemanager.h @@ -66,8 +66,6 @@ public: //! Returns last modification date as timestamp static long long GetLastModificationTime(const std::string &filename); - //! Move file/directory - static bool Move(const std::string &from, const std::string &to); //! Remove file static bool Remove(const std::string& filename); }; diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 374a7495..8019786b 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -105,6 +105,7 @@ #include "ui/screen/screen_loading.h" +#include #include #include #include @@ -5456,7 +5457,7 @@ void CRobotMain::SetAutosave(bool enable) m_autosave = enable; m_autosaveLast = m_gameTimeAbsolute; - AutosaveRotate(false); + AutosaveRotate(); } bool CRobotMain::GetAutosave() @@ -5482,7 +5483,7 @@ void CRobotMain::SetAutosaveSlots(int slots) if (m_autosaveSlots == slots) return; m_autosaveSlots = slots; - AutosaveRotate(false); + AutosaveRotate(); } int CRobotMain::GetAutosaveSlots() @@ -5490,85 +5491,39 @@ int CRobotMain::GetAutosaveSlots() return m_autosaveSlots; } -int CRobotMain::AutosaveRotate(bool freeOne) +// Remove oldest saves with autosave prefix +void CRobotMain::AutosaveRotate() { if (m_playerProfile == nullptr) - return 0; + return; GetLogger()->Debug("Rotate autosaves...\n"); - // Find autosave dirs auto saveDirs = CResourceManager::ListDirectories(m_playerProfile->GetSaveDir()); - std::map autosaveDirs; - for (auto& dir : saveDirs) - { - try - { - const std::string autosavePrefix = "autosave"; - if (dir.substr(0, autosavePrefix.length()) == autosavePrefix) - { - int id = boost::lexical_cast(dir.substr(autosavePrefix.length())); - autosaveDirs[id] = m_playerProfile->GetSaveFile(dir); - } - } - catch (...) - { - GetLogger()->Info("Bad autosave found: %s\n", dir.c_str()); - // skip - } - } - if (autosaveDirs.size() == 0) return 1; + const std::string autosavePrefix = "autosave"; + std::vector autosaves; + std::copy_if(saveDirs.begin(), saveDirs.end(), std::back_inserter(autosaves), [&](const std::string &save) { + return save.substr(0, autosavePrefix.length()) == autosavePrefix; + }); - // Remove all but last m_autosaveSlots - std::map autosavesToKeep; - int last_id = autosaveDirs.rbegin()->first; - int count = 0; - int to_keep = m_autosaveSlots-(freeOne ? 1 : 0); - int new_last_id = Math::Min(autosaveDirs.size(), to_keep); - bool rotate = false; - for (int i = last_id; i > 0; i--) + std::sort(autosaves.begin(), autosaves.end(), std::less()); + for (int i = 0; i < static_cast(autosaves.size()) - m_autosaveSlots + 1; i++) { - if (autosaveDirs.count(i) > 0) - { - count++; - if (count > m_autosaveSlots-(freeOne ? 1 : 0) || !m_autosave) - { - GetLogger()->Trace("Remove %s\n", autosaveDirs[i].c_str()); - CResourceManager::RemoveDirectory(autosaveDirs[i]); - rotate = true; - } - else - { - GetLogger()->Trace("Keep %s\n", autosaveDirs[i].c_str()); - autosavesToKeep[new_last_id-count+1] = autosaveDirs[i]; - } - } + CResourceManager::RemoveDirectory(m_playerProfile->GetSaveDir() + "/" + autosaves[i]); } - - // Rename autosaves that we kept - if (rotate) - { - for (auto& save : autosavesToKeep) - { - std::string newDir = m_playerProfile->GetSaveFile("autosave" + boost::lexical_cast(save.first)); - GetLogger()->Trace("Rename %s -> %s\n", save.second.c_str(), newDir.c_str()); - CResourceManager::Move(save.second, newDir); - } - } - - return rotate ? count : count+1; } void CRobotMain::Autosave() { - int id = AutosaveRotate(true); + AutosaveRotate(); GetLogger()->Info("Autosave!\n"); - std::string dir = m_playerProfile->GetSaveFile("autosave" + boost::lexical_cast(id)); - char timestr[100]; + char infostr[100]; time_t now = time(nullptr); - strftime(timestr, 99, "%x %X", localtime(&now)); - std::string info = std::string("[AUTOSAVE] ")+timestr; + strftime(timestr, 99, "%y%m%d%H%M%S", localtime(&now)); + strftime(infostr, 99, "%y.%m.%d %H:%M", localtime(&now)); + std::string info = std::string("[AUTOSAVE] ") + infostr; + std::string dir = m_playerProfile->GetSaveFile(std::string("autosave") + timestr); m_playerProfile->SaveScene(dir, info); } diff --git a/src/level/robotmain.h b/src/level/robotmain.h index c25d1923..18649c0e 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -402,7 +402,7 @@ protected: void ExecuteCmd(const std::string& cmd); void UpdateSpeedLabel(); - int AutosaveRotate(bool freeOne); + void AutosaveRotate(); void Autosave(); bool DestroySelectedObject(); void PushToSelectionHistory(CObject* obj); diff --git a/src/ui/screen/screen_io.cpp b/src/ui/screen/screen_io.cpp index 52e62ee2..82db8d12 100644 --- a/src/ui/screen/screen_io.cpp +++ b/src/ui/screen/screen_io.cpp @@ -80,7 +80,7 @@ void CScreenIO::IOReadName() } time(&now); - strftime(line, 99, "%y%m%d%H%M", localtime(&now)); + strftime(line, 99, "%y.%m.%d %H:%M", localtime(&now)); sprintf(name, "%s - %s %d", line, resume.c_str(), m_main->GetLevelRank()); pe->SetText(name); From 9017e5a25b37535b0fc6281effa861c9182c52e2 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 17 Jun 2016 21:13:16 +0200 Subject: [PATCH 098/125] Fixed links in CBot listings in SatCom --- src/graphics/engine/text.cpp | 98 ++++++++++++++++++------------------ src/graphics/engine/text.h | 7 +-- src/ui/controls/edit.cpp | 13 +++-- 3 files changed, 58 insertions(+), 60 deletions(-) diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 4fcf4acc..aece13e9 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -720,43 +720,42 @@ void CText::DrawString(const std::string &text, std::vector::itera Color c = color; FontHighlight hl = static_cast(format[fmtIndex] & FONT_MASK_HIGHLIGHT); - if (hl != FONT_HIGHLIGHT_NONE) + if (hl == FONT_HIGHLIGHT_TOKEN) { - if (hl == FONT_HIGHLIGHT_TOKEN) - { - c = Color(0.490f, 0.380f, 0.165f, 1.0f); // #7D612A - } - else if (hl == FONT_HIGHLIGHT_TYPE) - { - c = Color(0.31f, 0.443f, 0.196f, 1.0f); // #4F7132 - } - else if (hl == FONT_HIGHLIGHT_CONST) - { - c = Color(0.882f, 0.176f, 0.176f, 1.0f); // #E12D2D - } - else if (hl == FONT_HIGHLIGHT_THIS) - { - c = Color(0.545f, 0.329f, 0.608f, 1.0f); // #8B549B - } - else if (hl == FONT_HIGHLIGHT_COMMENT) - { - c = Color(0.251f, 0.271f, 0.306f, 1.0f); // #40454E - } - else if (hl == FONT_HIGHLIGHT_KEYWORD) - { - c = Color(0.239f, 0.431f, 0.588f, 1.0f); // #3D6E96 - } - else if (hl == FONT_HIGHLIGHT_STRING) - { - c = Color(0.239f, 0.384f, 0.341f, 1.0f); // #3D6257 - } - else - { - Math::IntPoint charSize; - charSize.x = GetCharWidthInt(ch, font, size, offset); - charSize.y = GetHeightInt(font, size); - DrawHighlight(hl, pos, charSize); - } + c = Color(0.490f, 0.380f, 0.165f, 1.0f); // #7D612A + } + else if (hl == FONT_HIGHLIGHT_TYPE) + { + c = Color(0.31f, 0.443f, 0.196f, 1.0f); // #4F7132 + } + else if (hl == FONT_HIGHLIGHT_CONST) + { + c = Color(0.882f, 0.176f, 0.176f, 1.0f); // #E12D2D + } + else if (hl == FONT_HIGHLIGHT_THIS) + { + c = Color(0.545f, 0.329f, 0.608f, 1.0f); // #8B549B + } + else if (hl == FONT_HIGHLIGHT_COMMENT) + { + c = Color(0.251f, 0.271f, 0.306f, 1.0f); // #40454E + } + else if (hl == FONT_HIGHLIGHT_KEYWORD) + { + c = Color(0.239f, 0.431f, 0.588f, 1.0f); // #3D6E96 + } + else if (hl == FONT_HIGHLIGHT_STRING) + { + c = Color(0.239f, 0.384f, 0.341f, 1.0f); // #3D6257 + } + + // draw highlight background or link underline + if (font != FONT_BUTTON) + { + Math::IntPoint charSize; + charSize.x = GetCharWidthInt(ch, font, size, offset); + charSize.y = GetHeightInt(font, size); + DrawHighlight(format[fmtIndex], pos, charSize); } DrawCharAndAdjustPos(ch, font, size, pos, c); @@ -854,26 +853,25 @@ void CText::DrawString(const std::string &text, FontType font, } } -void CText::DrawHighlight(FontHighlight hl, Math::IntPoint pos, Math::IntPoint size) +void CText::DrawHighlight(FontMetaChar hl, Math::IntPoint pos, Math::IntPoint size) { // Gradient colors Color grad[4]; // TODO: switch to alpha factors - switch (hl) + if ((hl & FONT_MASK_LINK) != 0) { - case FONT_HIGHLIGHT_LINK: - grad[0] = grad[1] = grad[2] = grad[3] = Color(0.0f, 0.0f, 1.0f, 0.5f); - break; - - case FONT_HIGHLIGHT_KEY: - grad[0] = grad[1] = grad[2] = grad[3] = - Color(192.0f / 256.0f, 192.0f / 256.0f, 192.0f / 256.0f, 0.5f); - break; - - default: - return; + grad[0] = grad[1] = grad[2] = grad[3] = Color(0.0f, 0.0f, 1.0f, 0.5f); + } + else if ((hl & FONT_MASK_HIGHLIGHT) == FONT_HIGHLIGHT_KEY) + { + grad[0] = grad[1] = grad[2] = grad[3] = + Color(192.0f / 256.0f, 192.0f / 256.0f, 192.0f / 256.0f, 0.5f); + } + else + { + return; } Math::IntPoint vsize = m_engine->GetWindowSize(); @@ -889,7 +887,7 @@ void CText::DrawHighlight(FontHighlight hl, Math::IntPoint pos, Math::IntPoint s p2.x = pos.x + size.x; p2.y = pos.y; - if (hl == FONT_HIGHLIGHT_LINK) + if ((hl & FONT_MASK_LINK) != 0) { p1.y = pos.y - h; // just emphasized } diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index 909dada5..f6414c00 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -118,7 +118,6 @@ enum FontTitle enum FontHighlight { FONT_HIGHLIGHT_NONE = 0x00 << 6, - FONT_HIGHLIGHT_LINK = 0x01 << 6, //!< link underline FONT_HIGHLIGHT_TABLE = 0x02 << 6, //!< code background in SatCom FONT_HIGHLIGHT_KEY = 0x03 << 6, //!< background for keys in documentation in SatCom FONT_HIGHLIGHT_TOKEN = 0x04 << 6, //!< keywords in CBot scripts @@ -142,8 +141,10 @@ enum FontMask FONT_MASK_TITLE = 0x030, //! Mask for FontHighlight FONT_MASK_HIGHLIGHT = 0x3c0, + //! Mask for links + FONT_MASK_LINK = 0x400, //! Mask for image bit (TODO: not used?) - FONT_MASK_IMAGE = 0x400 + FONT_MASK_IMAGE = 0x800 }; @@ -324,7 +325,7 @@ protected: float size, Math::IntPoint pos, int width, int eol, Color color); void DrawString(const std::string &text, FontType font, float size, Math::IntPoint pos, int width, int eol, Color color); - void DrawHighlight(FontHighlight hl, Math::IntPoint pos, Math::IntPoint size); + void DrawHighlight(FontMetaChar hl, Math::IntPoint pos, Math::IntPoint size); void DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::IntPoint &pos, Color color); void StringToUTFCharList(const std::string &text, std::vector &chars); void StringToUTFCharList(const std::string &text, std::vector &chars, std::vector::iterator format, std::vector::iterator end); diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index c46d5b0b..c50f9796 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -564,7 +564,7 @@ bool CEdit::IsLinkPos(Math::Point pos) if ( i == -1 ) return false; if ( i >= m_len ) return false; - if ( m_format.size() > static_cast(i) && ((m_format[i] & Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK)) return true; // TODO + if ( m_format.size() > static_cast(i) && ((m_format[i] & Gfx::FONT_MASK_LINK) != 0)) return true; // TODO return false; } @@ -637,13 +637,13 @@ void CEdit::MouseRelease(Math::Point mouse) if ( !m_bEdit ) { if ( m_format.size() > 0 && i < m_len && m_cursor1 == m_cursor2 && - (m_format[i]&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK) //TODO + (m_format[i]&Gfx::FONT_MASK_LINK) != 0) //TODO { int rank = -1; for ( int j=0 ; j<=i ; j++ ) { - if ( (j == 0 || (m_format[j-1]&Gfx::FONT_MASK_HIGHLIGHT) != Gfx::FONT_HIGHLIGHT_LINK) && // TODO check if good - (m_format[j+0]&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK) // TODO + if ( (j == 0 || (m_format[j-1]&Gfx::FONT_MASK_LINK) == 0) && // TODO check if good + (m_format[j+0]&Gfx::FONT_MASK_LINK) != 0) // TODO { rank ++; } @@ -1581,8 +1581,7 @@ bool CEdit::ReadText(std::string filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { - font &= ~Gfx::FONT_MASK_HIGHLIGHT; - font |= Gfx::FONT_HIGHLIGHT_LINK; + font |= Gfx::FONT_MASK_LINK; } i += 3; } @@ -1602,7 +1601,7 @@ bool CEdit::ReadText(std::string filename, int addSize) link.name = GetNameParam(buffer.data()+i+3, 0); link.marker = GetNameParam(buffer.data()+i+3, 1); m_link.push_back(link); - font &= ~Gfx::FONT_MASK_HIGHLIGHT; + font &= ~Gfx::FONT_MASK_LINK; } i += strchr(buffer.data()+i, ';')-(buffer.data()+i)+1; } From cd183413304e17537e04eb1adaaa5371ac33dded Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 17 Jun 2016 21:21:34 +0200 Subject: [PATCH 099/125] Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index cbd7b5b4..5614bfe9 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit cbd7b5b46a2098b8d88a96370cc8d9aeb05a71f7 +Subproject commit 5614bfe93c565d2f006138b0ec5b4fe380a04f08 From 7ce23fdf52f521b460e3a3522f353ee2431a3b88 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 17 Jun 2016 22:39:45 +0200 Subject: [PATCH 100/125] Do not rotate after changing autosave settings See https://github.com/colobot/colobot/pull/789#discussion_r67570610 --- src/level/robotmain.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 8019786b..760d1d5d 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -5457,7 +5457,6 @@ void CRobotMain::SetAutosave(bool enable) m_autosave = enable; m_autosaveLast = m_gameTimeAbsolute; - AutosaveRotate(); } bool CRobotMain::GetAutosave() @@ -5483,7 +5482,6 @@ void CRobotMain::SetAutosaveSlots(int slots) if (m_autosaveSlots == slots) return; m_autosaveSlots = slots; - AutosaveRotate(); } int CRobotMain::GetAutosaveSlots() From f0ed20fd670d62fd8b6f2977f37cbd5a94fad310 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 17 Jun 2016 22:49:15 +0200 Subject: [PATCH 101/125] Enabled working tests after bf2e3cdfaeb7114cc5ec60cb601b8f5305cbf4e6 --- test/unit/CBot/CBot_test.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/test/unit/CBot/CBot_test.cpp b/test/unit/CBot/CBot_test.cpp index e3c25db6..355e37ac 100644 --- a/test/unit/CBot/CBot_test.cpp +++ b/test/unit/CBot/CBot_test.cpp @@ -471,6 +471,18 @@ TEST_F(CBotUT, VarImplicitCast) //" ASSERT(b == \"3.5\");\n" "}\n" ); + + ExecuteTest( + "string func()\n" + "{\n" + " return 5;\n" + "}\n" + "extern void ImplicitCastOnReturn()\n" + "{\n" + " string a = func();\n" + " ASSERT(a == \"5\");" + "}\n" + ); } TEST_F(CBotUT, Arrays) @@ -660,8 +672,7 @@ TEST_F(CBotUT, FunctionRedefined) ); } -// TODO: Doesn't work -TEST_F(CBotUT, DISABLED_FunctionBadReturn) +TEST_F(CBotUT, FunctionBadReturn) { ExecuteTest( "int func()\n" @@ -672,7 +683,7 @@ TEST_F(CBotUT, DISABLED_FunctionBadReturn) "{\n" " int a = func();\n" "}\n", - static_cast(-1) // TODO: no error for that + CBotErrBadType1 ); } @@ -932,12 +943,11 @@ TEST_F(CBotUT, ThisEarlyContextSwitch_Issue436) ); } -// TODO: Gets a failed assertion -TEST_F(CBotUT, DISABLED_BadStringAdd_Issue535) +TEST_F(CBotUT, ClassStringAdd_Issue535) { ExecuteTest( "public class TestClass {}\n" - "extern void BadStringAdd()\n" + "extern void ClassStringAdd()\n" "{\n" " TestClass t();\n" " string s = t + \"!\";\n" From 543df84db6acd6ecf17c66ae8776715b99cb162c Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 18 Jun 2016 22:31:32 +0200 Subject: [PATCH 102/125] Enabled more tests See https://github.com/colobot/colobot/pull/783#issuecomment-226963085 --- test/unit/CBot/CBot_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/CBot/CBot_test.cpp b/test/unit/CBot/CBot_test.cpp index 355e37ac..e8cdcd1d 100644 --- a/test/unit/CBot/CBot_test.cpp +++ b/test/unit/CBot/CBot_test.cpp @@ -463,12 +463,12 @@ TEST_F(CBotUT, VarImplicitCast) "{\n" " string a = 2;\n" " ASSERT(a == \"2\");\n" - //" a = 3;\n" // TODO: this certainly looks wrong, you an assign a number in initialization but not in assignment - //" ASSERT(a == \"3\");\n" + " a = 3;\n" + " ASSERT(a == \"3\");\n" " string b = 2.5;\n" " ASSERT(b == \"2.5\");\n" - //" b = 3.5;\n" - //" ASSERT(b == \"3.5\");\n" + " b = 3.5;\n" + " ASSERT(b == \"3.5\");\n" "}\n" ); From 9d9131c3fba3a3fbf6d15d4b1816d87927fa172c Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 19 Jun 2016 11:45:56 +0200 Subject: [PATCH 103/125] Fixed pause blur with MSAA issue #656 --- src/graphics/engine/engine.cpp | 225 +++++++++++++++++---------------- src/graphics/engine/engine.h | 2 + 2 files changed, 116 insertions(+), 111 deletions(-) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 8eb92754..1617c986 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -3163,6 +3163,10 @@ void CEngine::Render() UseMSAA(false); + // marked to capture currently rendered world + if (m_captureWorld) + Capture3DScene(); + m_app->StartPerformanceCounter(PCNT_RENDER_INTERFACE); DrawInterface(); m_app->StopPerformanceCounter(PCNT_RENDER_INTERFACE); @@ -3171,6 +3175,116 @@ void CEngine::Render() m_device->EndScene(); } +void CEngine::Capture3DScene() +{ + // destroy existing texture + if (m_capturedWorldTexture.Valid()) + { + m_device->DestroyTexture(m_capturedWorldTexture); + m_capturedWorldTexture = Texture(); + } + + // obtain pixels from screen + int width = m_size.x; + int height = m_size.y; + + auto pixels = m_device->GetFrameBufferPixels(); + unsigned char* data = reinterpret_cast(pixels->GetPixelsData()); + + // calculate 2nd mipmap + int newWidth = width / 4; + int newHeight = height / 4; + std::unique_ptr mipmap(new unsigned char[4 * newWidth * newHeight]); + + for (int x = 0; x < newWidth; x++) + { + for (int y = 0; y < newHeight; y++) + { + float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + int index = 4 * ((4 * x + i) + width * (4 * y + j)); + + for (int k = 0; k < 4; k++) + color[k] += data[index + k]; + } + } + + int index = 4 * (x + newWidth * y); + + for (int k = 0; k < 4; k++) + { + mipmap[index + k] = static_cast(color[k] * (1.0f / 16.0f)); + } + } + } + + // calculate Gaussian blur + std::unique_ptr blured(new unsigned char[4 * newWidth * newHeight]); + + float matrix[7][7] = + { + { 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f }, + { 0.00002292f, 0.00078634f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f }, + { 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f }, + { 0.00038771f, 0.01330373f, 0.11098164f, 0.22508352f, 0.11098164f, 0.01330373f, 0.00038771f }, + { 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f }, + { 0.00002292f, 0.00078633f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f }, + { 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f } + }; + + for (int x = 0; x < newWidth; x++) + { + for (int y = 0; y < newHeight; y++) + { + float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + + for (int i = -3; i <= 3; i++) + { + for (int j = -3; j <= 3; j++) + { + int xp = Math::Clamp(x + i, 0, newWidth - 1); + int yp = Math::Clamp(y + j, 0, newHeight - 1); + + float weight = matrix[i + 3][j + 3]; + + int index = 4 * (newWidth * yp + xp); + + for (int k = 0; k < 4; k++) + color[k] += weight * mipmap[index + k]; + } + } + + int index = 4 * (newWidth * y + x); + + for (int k = 0; k < 4; k++) + { + float value = Math::Clamp(color[k], 0.0f, 255.0f); + blured[index + k] = static_cast(value); + } + } + } + + // create SDL surface and final texture + ImageData image; + image.surface = SDL_CreateRGBSurfaceFrom(blured.get(), newWidth, newHeight, 32, 0, 0, 0, 0, 0xFF000000); + + TextureCreateParams params; + params.filter = TEX_FILTER_BILINEAR; + params.format = TEX_IMG_RGBA; + params.mipmap = false; + + m_capturedWorldTexture = m_device->CreateTexture(&image, params); + + SDL_FreeSurface(image.surface); + + m_captureWorld = false; + m_worldCaptured = true; +} + void CEngine::Draw3DScene() { // use currently captured scene for world @@ -3451,117 +3565,6 @@ void CEngine::Draw3DScene() DrawForegroundImage(); // draws the foreground if (! m_overFront) DrawOverColor(); // draws the foreground color - - // marked to capture currently rendered world - if (m_captureWorld) - { - // destroy existing texture - if (m_capturedWorldTexture.Valid()) - { - m_device->DestroyTexture(m_capturedWorldTexture); - m_capturedWorldTexture = Texture(); - } - - // obtain pixels from screen - int width = m_size.x; - int height = m_size.y; - - auto pixels = m_device->GetFrameBufferPixels(); - unsigned char* data = reinterpret_cast(pixels->GetPixelsData()); - - // calculate 2nd mipmap - int newWidth = width / 4; - int newHeight = height / 4; - std::unique_ptr mipmap(new unsigned char[4 * newWidth * newHeight]); - - for (int x = 0; x < newWidth; x++) - { - for (int y = 0; y < newHeight; y++) - { - float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - - for (int i = 0; i < 4; i++) - { - for (int j = 0; j < 4; j++) - { - int index = 4 * ((4 * x + i) + width * (4 * y + j)); - - for (int k = 0; k < 4; k++) - color[k] += data[index + k]; - } - } - - int index = 4 * (x + newWidth * y); - - for (int k = 0; k < 4; k++) - { - mipmap[index + k] = static_cast(color[k] * (1.0f / 16.0f)); - } - } - } - - // calculate Gaussian blur - std::unique_ptr blured(new unsigned char[4 * newWidth * newHeight]); - - float matrix[7][7] = - { - { 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f }, - { 0.00002292f, 0.00078634f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f }, - { 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f }, - { 0.00038771f, 0.01330373f, 0.11098164f, 0.22508352f, 0.11098164f, 0.01330373f, 0.00038771f }, - { 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f }, - { 0.00002292f, 0.00078633f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f }, - { 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f } - }; - - for (int x = 0; x < newWidth; x++) - { - for (int y = 0; y < newHeight; y++) - { - float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - - for (int i = -3; i <= 3; i++) - { - for (int j = -3; j <= 3; j++) - { - int xp = Math::Clamp(x + i, 0, newWidth - 1); - int yp = Math::Clamp(y + j, 0, newHeight - 1); - - float weight = matrix[i + 3][j + 3]; - - int index = 4 * (newWidth * yp + xp); - - for (int k = 0; k < 4; k++) - color[k] += weight * mipmap[index + k]; - } - } - - int index = 4 * (newWidth * y + x); - - for (int k = 0; k < 4; k++) - { - float value = Math::Clamp(color[k], 0.0f, 255.0f); - blured[index + k] = static_cast(value); - } - } - } - - // create SDL surface and final texture - ImageData image; - image.surface = SDL_CreateRGBSurfaceFrom(blured.get(), newWidth, newHeight, 32, 0, 0, 0, 0, 0xFF000000); - - TextureCreateParams params; - params.filter = TEX_FILTER_BILINEAR; - params.format = TEX_IMG_RGBA; - params.mipmap = false; - - m_capturedWorldTexture = m_device->CreateTexture(&image, params); - - SDL_FreeSurface(image.surface); - - m_captureWorld = false; - m_worldCaptured = true; - } } void CEngine::DrawCrashSpheres() diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index e60e6e37..5b1b977f 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -1214,6 +1214,8 @@ protected: //! Prepares the interface for 3D scene void Draw3DScene(); + //! Capture the 3D scene for pause blur + void Capture3DScene(); //! Renders shadow map void RenderShadowMap(); //! Enables or disables shadow mapping From 125d1a32c7edb176d52d1280f9bd9561d542025d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 19 Jun 2016 12:23:54 +0200 Subject: [PATCH 104/125] Fixed pause blur blinking for one frame issue #656 --- src/graphics/engine/engine.cpp | 304 ++++++++++++++++++--------------- src/graphics/engine/engine.h | 2 + 2 files changed, 164 insertions(+), 142 deletions(-) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 1617c986..bb6319af 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -3153,19 +3153,30 @@ void CEngine::Render() m_device->BeginScene(); - UseMSAA(true); + // use currently captured scene for world + if (m_worldCaptured && !m_captureWorld) + { + DrawCaptured3DScene(); + } + else + { + UseMSAA(true); - if (!m_worldCaptured) DrawBackground(); // draws the background - if (m_drawWorld) - Draw3DScene(); + if (m_drawWorld) + Draw3DScene(); - UseMSAA(false); + UseMSAA(false); - // marked to capture currently rendered world - if (m_captureWorld) - Capture3DScene(); + // marked to capture currently rendered world + if (m_captureWorld) + { + Capture3DScene(); + m_device->Clear(); + DrawCaptured3DScene(); + } + } m_app->StartPerformanceCounter(PCNT_RENDER_INTERFACE); DrawInterface(); @@ -3175,143 +3186,15 @@ void CEngine::Render() m_device->EndScene(); } -void CEngine::Capture3DScene() -{ - // destroy existing texture - if (m_capturedWorldTexture.Valid()) - { - m_device->DestroyTexture(m_capturedWorldTexture); - m_capturedWorldTexture = Texture(); - } - - // obtain pixels from screen - int width = m_size.x; - int height = m_size.y; - - auto pixels = m_device->GetFrameBufferPixels(); - unsigned char* data = reinterpret_cast(pixels->GetPixelsData()); - - // calculate 2nd mipmap - int newWidth = width / 4; - int newHeight = height / 4; - std::unique_ptr mipmap(new unsigned char[4 * newWidth * newHeight]); - - for (int x = 0; x < newWidth; x++) - { - for (int y = 0; y < newHeight; y++) - { - float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - - for (int i = 0; i < 4; i++) - { - for (int j = 0; j < 4; j++) - { - int index = 4 * ((4 * x + i) + width * (4 * y + j)); - - for (int k = 0; k < 4; k++) - color[k] += data[index + k]; - } - } - - int index = 4 * (x + newWidth * y); - - for (int k = 0; k < 4; k++) - { - mipmap[index + k] = static_cast(color[k] * (1.0f / 16.0f)); - } - } - } - - // calculate Gaussian blur - std::unique_ptr blured(new unsigned char[4 * newWidth * newHeight]); - - float matrix[7][7] = - { - { 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f }, - { 0.00002292f, 0.00078634f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f }, - { 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f }, - { 0.00038771f, 0.01330373f, 0.11098164f, 0.22508352f, 0.11098164f, 0.01330373f, 0.00038771f }, - { 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f }, - { 0.00002292f, 0.00078633f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f }, - { 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f } - }; - - for (int x = 0; x < newWidth; x++) - { - for (int y = 0; y < newHeight; y++) - { - float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - - for (int i = -3; i <= 3; i++) - { - for (int j = -3; j <= 3; j++) - { - int xp = Math::Clamp(x + i, 0, newWidth - 1); - int yp = Math::Clamp(y + j, 0, newHeight - 1); - - float weight = matrix[i + 3][j + 3]; - - int index = 4 * (newWidth * yp + xp); - - for (int k = 0; k < 4; k++) - color[k] += weight * mipmap[index + k]; - } - } - - int index = 4 * (newWidth * y + x); - - for (int k = 0; k < 4; k++) - { - float value = Math::Clamp(color[k], 0.0f, 255.0f); - blured[index + k] = static_cast(value); - } - } - } - - // create SDL surface and final texture - ImageData image; - image.surface = SDL_CreateRGBSurfaceFrom(blured.get(), newWidth, newHeight, 32, 0, 0, 0, 0, 0xFF000000); - - TextureCreateParams params; - params.filter = TEX_FILTER_BILINEAR; - params.format = TEX_IMG_RGBA; - params.mipmap = false; - - m_capturedWorldTexture = m_device->CreateTexture(&image, params); - - SDL_FreeSurface(image.surface); - - m_captureWorld = false; - m_worldCaptured = true; -} - void CEngine::Draw3DScene() { - // use currently captured scene for world - if (m_worldCaptured) + if (!m_worldCaptured) { - Math::Matrix identity; - - m_device->SetTransform(TRANSFORM_PROJECTION, identity); - m_device->SetTransform(TRANSFORM_VIEW, identity); - m_device->SetTransform(TRANSFORM_WORLD, identity); - - Vertex vertices[4]; - - vertices[0] = Vertex(Math::Vector(-1.0f, -1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(0.0f, 0.0f)); - vertices[1] = Vertex(Math::Vector( 1.0f, -1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(1.0f, 0.0f)); - vertices[2] = Vertex(Math::Vector(-1.0f, 1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(0.0f, 1.0f)); - vertices[3] = Vertex(Math::Vector( 1.0f, 1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(1.0f, 1.0f)); - - m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false); - - m_device->SetTexture(TEXTURE_PRIMARY, m_capturedWorldTexture); - m_device->SetTextureEnabled(TEXTURE_PRIMARY, true); - m_device->SetTextureEnabled(TEXTURE_SECONDARY, false); - - m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertices, 4); - - return; + if (m_capturedWorldTexture.Valid()) + { + m_device->DestroyTexture(m_capturedWorldTexture); + m_capturedWorldTexture = Texture(); + } } m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false); @@ -3567,6 +3450,143 @@ void CEngine::Draw3DScene() if (! m_overFront) DrawOverColor(); // draws the foreground color } +void CEngine::Capture3DScene() +{ + // destroy existing texture + if (m_capturedWorldTexture.Valid()) + { + m_device->DestroyTexture(m_capturedWorldTexture); + m_capturedWorldTexture = Texture(); + } + + // obtain pixels from screen + int width = m_size.x; + int height = m_size.y; + + auto pixels = m_device->GetFrameBufferPixels(); + unsigned char* data = reinterpret_cast(pixels->GetPixelsData()); + + // calculate 2nd mipmap + int newWidth = width / 4; + int newHeight = height / 4; + std::unique_ptr mipmap(new unsigned char[4 * newWidth * newHeight]); + + for (int x = 0; x < newWidth; x++) + { + for (int y = 0; y < newHeight; y++) + { + float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + int index = 4 * ((4 * x + i) + width * (4 * y + j)); + + for (int k = 0; k < 4; k++) + color[k] += data[index + k]; + } + } + + int index = 4 * (x + newWidth * y); + + for (int k = 0; k < 4; k++) + { + mipmap[index + k] = static_cast(color[k] * (1.0f / 16.0f)); + } + } + } + + // calculate Gaussian blur + std::unique_ptr blured(new unsigned char[4 * newWidth * newHeight]); + + float matrix[7][7] = + { + { 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f }, + { 0.00002292f, 0.00078634f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f }, + { 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f }, + { 0.00038771f, 0.01330373f, 0.11098164f, 0.22508352f, 0.11098164f, 0.01330373f, 0.00038771f }, + { 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f }, + { 0.00002292f, 0.00078633f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f }, + { 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f } + }; + + for (int x = 0; x < newWidth; x++) + { + for (int y = 0; y < newHeight; y++) + { + float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + + for (int i = -3; i <= 3; i++) + { + for (int j = -3; j <= 3; j++) + { + int xp = Math::Clamp(x + i, 0, newWidth - 1); + int yp = Math::Clamp(y + j, 0, newHeight - 1); + + float weight = matrix[i + 3][j + 3]; + + int index = 4 * (newWidth * yp + xp); + + for (int k = 0; k < 4; k++) + color[k] += weight * mipmap[index + k]; + } + } + + int index = 4 * (newWidth * y + x); + + for (int k = 0; k < 4; k++) + { + float value = Math::Clamp(color[k], 0.0f, 255.0f); + blured[index + k] = static_cast(value); + } + } + } + + // create SDL surface and final texture + ImageData image; + image.surface = SDL_CreateRGBSurfaceFrom(blured.get(), newWidth, newHeight, 32, 0, 0, 0, 0, 0xFF000000); + + TextureCreateParams params; + params.filter = TEX_FILTER_BILINEAR; + params.format = TEX_IMG_RGBA; + params.mipmap = false; + + m_capturedWorldTexture = m_device->CreateTexture(&image, params); + + SDL_FreeSurface(image.surface); + + m_captureWorld = false; + m_worldCaptured = true; +} + +void CEngine::DrawCaptured3DScene() +{ + Math::Matrix identity; + + m_device->SetTransform(TRANSFORM_PROJECTION, identity); + m_device->SetTransform(TRANSFORM_VIEW, identity); + m_device->SetTransform(TRANSFORM_WORLD, identity); + + m_device->SetRenderState(RENDER_STATE_BLENDING, false); + m_device->SetRenderState(RENDER_STATE_CULLING, false); + + Vertex vertices[4]; + + vertices[0] = Vertex(Math::Vector(-1.0f, -1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(0.0f, 0.0f)); + vertices[1] = Vertex(Math::Vector(1.0f, -1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(1.0f, 0.0f)); + vertices[2] = Vertex(Math::Vector(-1.0f, 1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(0.0f, 1.0f)); + vertices[3] = Vertex(Math::Vector(1.0f, 1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(1.0f, 1.0f)); + + m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false); + + m_device->SetTexture(TEXTURE_PRIMARY, m_capturedWorldTexture); + m_device->SetTextureEnabled(TEXTURE_PRIMARY, true); + m_device->SetTextureEnabled(TEXTURE_SECONDARY, false); + + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertices, 4); +} + void CEngine::DrawCrashSpheres() { Math::Matrix worldMatrix; diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 5b1b977f..ab0cc524 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -1216,6 +1216,8 @@ protected: void Draw3DScene(); //! Capture the 3D scene for pause blur void Capture3DScene(); + //! Draw the 3D scene capured for pause blur + void DrawCaptured3DScene(); //! Renders shadow map void RenderShadowMap(); //! Enables or disables shadow mapping From a0b3f7a769b87639159c1774f18b4880dd1465bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Sun, 19 Jun 2016 16:52:01 +0200 Subject: [PATCH 105/125] Fixed problem with pause blur after changing some graphic settings --- src/graphics/engine/engine.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index bb6319af..ac5cf527 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -376,6 +376,13 @@ void CEngine::ReloadAllTextures() m_app->GetEventQueue()->AddEvent(Event(EVENT_RELOAD_TEXTURES)); UpdateGroundSpotTextures(); LoadAllTextures(); + + // recapture 3D scene + if (m_worldCaptured) + { + m_captureWorld = true; + m_worldCaptured = false; + } } bool CEngine::ProcessEvent(const Event &event) From bd4362e26ca9d2259864e5d997dfac2196ce6049 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 19 Jun 2016 19:57:55 +0200 Subject: [PATCH 106/125] Fixed dynamic textures not being reloaded properly --- src/graphics/engine/engine.cpp | 3 ++- src/level/robotmain.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index ac5cf527..7fdb2a46 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -375,7 +375,8 @@ void CEngine::ReloadAllTextures() m_app->GetEventQueue()->AddEvent(Event(EVENT_RELOAD_TEXTURES)); UpdateGroundSpotTextures(); - LoadAllTextures(); + // LoadAllTextures() is called from CRobotMain on EVENT_RELOAD_TEXTURES + // This is required because all dynamic textures need to be loaded first // recapture 3D scene if (m_worldCaptured) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 760d1d5d..d0f29ef6 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -689,6 +689,7 @@ bool CRobotMain::ProcessEvent(Event &event) ChangeColor(); UpdateMap(); } + m_engine->LoadAllTextures(); } if (event.type == EVENT_RESOLUTION_CHANGED) From 8ad53ce3278498dbdf38e4437a83536e240a1408 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 19 Jun 2016 22:18:03 +0200 Subject: [PATCH 107/125] Fixed pause blur in main menu --- src/level/robotmain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index d0f29ef6..86d1d168 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -1554,6 +1554,8 @@ char* CRobotMain::GetDisplayInfoName(int index) //! Beginning of a dialogue during the game void CRobotMain::StartSuspend() { + if (!IsPhaseWithWorld(m_phase)) return; + m_sound->MuteAll(true); ClearInterface(); m_suspend = m_pause->ActivatePause(PAUSE_ENGINE|PAUSE_HIDE_SHORTCUTS|PAUSE_MUTE_SOUND|PAUSE_CAMERA); From 5f7a8dbd5d3a9f7eeeb39a8e69ffbbae364c151a Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 21 Jun 2016 12:57:45 +0200 Subject: [PATCH 108/125] Fixed string values with spaces (closes #791) --- src/CBot/CBotVar/CBotVarString.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/CBot/CBotVar/CBotVarString.h b/src/CBot/CBotVar/CBotVarString.h index 5ff29d15..162264d2 100644 --- a/src/CBot/CBotVar/CBotVarString.h +++ b/src/CBot/CBotVar/CBotVarString.h @@ -32,6 +32,12 @@ class CBotVarString : public CBotVarValue public: CBotVarString(const CBotToken &name) : CBotVarValue(name) {} + void SetValString(const std::string& val) override + { + m_val = val; + m_binit = CBotVar::InitType::DEF; + } + void SetValInt(int val, const std::string& s = "") override { SetValString(ToString(val)); From c304ecd0cab9b62670d384d8ae93d9ab66c4d1fc Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 21 Jun 2016 12:58:43 +0200 Subject: [PATCH 109/125] Changed arrays to use {} when converted to string; added tests --- src/CBot/CBotVar/CBotVarClass.cpp | 7 +++++-- test/unit/CBot/CBot_test.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/CBot/CBotVar/CBotVarClass.cpp b/src/CBot/CBotVar/CBotVarClass.cpp index 919b43a6..08acffbe 100644 --- a/src/CBot/CBotVar/CBotVarClass.cpp +++ b/src/CBot/CBotVar/CBotVarClass.cpp @@ -343,10 +343,12 @@ std::string CBotVarClass::GetValString() res += " ("; } } + + res += " )"; } else { - res = "( "; + res = "{ "; CBotVar* pv = m_pVar; while ( pv != nullptr ) @@ -355,9 +357,10 @@ std::string CBotVarClass::GetValString() if ( pv->GetNext() != nullptr ) res += ", "; pv = pv->GetNext(); } + + res += " }"; } - res += " )"; return res; } diff --git a/test/unit/CBot/CBot_test.cpp b/test/unit/CBot/CBot_test.cpp index e8cdcd1d..c0d5e122 100644 --- a/test/unit/CBot/CBot_test.cpp +++ b/test/unit/CBot/CBot_test.cpp @@ -485,6 +485,30 @@ TEST_F(CBotUT, VarImplicitCast) ); } +TEST_F(CBotUT, ToString) +{ + ExecuteTest( + "extern void ArrayToString()\n" + "{\n" + " int[] array = {2, 4, 6};\n" + " string arrayStr = \"\"+array;\n" + " ASSERT(arrayStr == \"{ 2, 4, 6 }\");\n" + "}\n" + ); + + ExecuteTest( + "public class Test { int a = 1337; }\n" + "extern void ClassToString()\n" + "{\n" + " Test test();\n" + " string testStr = \"\"+test;\n" + " ASSERT(testStr == \"Pointer to Test( a=1337 )\");\n" + "}\n" + ); + + // TODO: IntrinsicClassToString ? (e.g. point) +} + TEST_F(CBotUT, Arrays) { ExecuteTest( From 0fbd2d107c43664ecc7e50a038645026cb6f29f0 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 21 Jun 2016 13:06:55 +0200 Subject: [PATCH 110/125] Allow using the CBot debugger during code battles --- src/ui/object_interface.cpp | 2 +- src/ui/studio.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ui/object_interface.cpp b/src/ui/object_interface.cpp index 1310015f..44140059 100644 --- a/src/ui/object_interface.cpp +++ b/src/ui/object_interface.cpp @@ -1622,7 +1622,7 @@ void CObjectInterface::UpdateInterface() bool bProgEnable = !m_programmable->IsProgram() && m_main->CanPlayerInteract(); bool scriptSelected = m_selScript >= 0 && m_selScript < m_programStorage->GetProgramCount(); - EnableInterface(pw, EVENT_OBJECT_PROGEDIT, m_main->CanPlayerInteract() && scriptSelected && !m_programmable->IsTraceRecord()); + EnableInterface(pw, EVENT_OBJECT_PROGEDIT, scriptSelected && !m_programmable->IsTraceRecord()); EnableInterface(pw, EVENT_OBJECT_PROGLIST, bProgEnable && !m_programmable->IsTraceRecord()); EnableInterface(pw, EVENT_OBJECT_PROGADD, bProgEnable); EnableInterface(pw, EVENT_OBJECT_PROGREMOVE, bProgEnable && scriptSelected && !m_programStorage->GetProgram(m_selScript)->readOnly); diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index 483d89b7..22268ecb 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -1028,17 +1028,17 @@ void CStudio::UpdateButtons() button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_CLONE)); if ( button == nullptr ) return; - button->SetState(STATE_ENABLE, m_program->runnable && !m_bRunning); + button->SetState(STATE_ENABLE, m_main->CanPlayerInteract() && (m_program->runnable && !m_bRunning)); button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_COMPILE)); if ( button == nullptr ) return; - button->SetState(STATE_ENABLE, m_program->runnable && !m_bRunning); + button->SetState(STATE_ENABLE, m_main->CanPlayerInteract() && (m_program->runnable && !m_bRunning)); button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_RUN)); if ( button == nullptr ) return; button->SetIcon(m_bRunning?8:21); // stop/run - button->SetState(STATE_ENABLE, m_program->runnable || m_bRunning); + button->SetState(STATE_ENABLE, m_main->CanPlayerInteract() && (m_program->runnable || m_bRunning)); button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_REALTIME)); if ( button == nullptr ) return; From 3b9b9b322a6f1e2ff4b08b803badf3af6f55f186 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 21 Jun 2016 13:07:40 +0200 Subject: [PATCH 111/125] Changed mouse scaling (again) --- src/graphics/engine/engine.cpp | 148 ++++++++++++++++++++------------- src/graphics/engine/engine.h | 40 +-------- src/math/intpoint.h | 96 +++++++++++++++++++++ src/math/point.h | 4 +- 4 files changed, 191 insertions(+), 97 deletions(-) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 7fdb2a46..f7d0b5a0 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -68,6 +68,60 @@ template<> Gfx::CEngine* CSingleton::m_instance = nullptr; namespace Gfx { +/** + * \struct EngineMouse + * \brief Information about mouse cursor + */ +struct EngineMouse +{ + //! Index of texture element for 1st image + int icon1; + //! Index of texture element for 2nd image + int icon2; + //! Shadow texture part + int iconShadow; + //! Mode to render 1st image in + EngineRenderState mode1; + //! Mode to render 2nd image in + EngineRenderState mode2; + //! Hot point + Math::IntPoint hotPoint; + + EngineMouse(int icon1 = -1, + int icon2 = -1, + int iconShadow = -1, + EngineRenderState mode1 = ENG_RSTATE_NORMAL, + EngineRenderState mode2 = ENG_RSTATE_NORMAL, + Math::IntPoint hotPoint = Math::IntPoint()) + : icon1(icon1) + , icon2(icon2) + , iconShadow(iconShadow) + , mode1(mode1) + , mode2(mode2) + , hotPoint(hotPoint) + {} +}; + +const Math::IntPoint MOUSE_SIZE(32, 32); +const std::map MOUSE_TYPES = { + {{ENG_MOUSE_NORM}, {EngineMouse( 0, 1, 32, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::IntPoint( 1, 1))}}, + {{ENG_MOUSE_WAIT}, {EngineMouse( 2, 3, 33, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::IntPoint( 8, 12))}}, + {{ENG_MOUSE_HAND}, {EngineMouse( 4, 5, 34, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::IntPoint( 7, 2))}}, + {{ENG_MOUSE_NO}, {EngineMouse( 6, 7, 35, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::IntPoint(10, 10))}}, + {{ENG_MOUSE_EDIT}, {EngineMouse( 8, 9, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::IntPoint( 6, 10))}}, + {{ENG_MOUSE_CROSS}, {EngineMouse(10, 11, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::IntPoint(10, 10))}}, + {{ENG_MOUSE_MOVEV}, {EngineMouse(12, 13, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::IntPoint( 5, 11))}}, + {{ENG_MOUSE_MOVEH}, {EngineMouse(14, 15, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::IntPoint(11, 5))}}, + {{ENG_MOUSE_MOVED}, {EngineMouse(16, 17, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::IntPoint( 9, 9))}}, + {{ENG_MOUSE_MOVEI}, {EngineMouse(18, 19, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::IntPoint( 9, 9))}}, + {{ENG_MOUSE_MOVE}, {EngineMouse(20, 21, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::IntPoint(11, 11))}}, + {{ENG_MOUSE_TARGET}, {EngineMouse(22, 23, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::IntPoint(15, 15))}}, + {{ENG_MOUSE_SCROLLL}, {EngineMouse(24, 25, 43, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::IntPoint( 2, 9))}}, + {{ENG_MOUSE_SCROLLR}, {EngineMouse(26, 27, 44, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::IntPoint(17, 9))}}, + {{ENG_MOUSE_SCROLLU}, {EngineMouse(28, 29, 45, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::IntPoint( 9, 2))}}, + {{ENG_MOUSE_SCROLLD}, {EngineMouse(30, 31, 46, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::IntPoint( 9, 17))}}, +}; + CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils) : m_app(app), m_systemUtils(systemUtils), @@ -75,8 +129,7 @@ CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils) m_fogColor(), m_deepView(), m_fogStart(), - m_highlightRank(), - m_mice() + m_highlightRank() { m_device = nullptr; @@ -160,24 +213,6 @@ CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils) m_debugLights = false; m_debugDumpLights = false; - m_mice[ENG_MOUSE_NORM] = EngineMouse( 0, 1, 32, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::Point( 1.0f, 1.0f)); - m_mice[ENG_MOUSE_WAIT] = EngineMouse( 2, 3, 33, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::Point( 8.0f, 12.0f)); - m_mice[ENG_MOUSE_HAND] = EngineMouse( 4, 5, 34, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::Point( 7.0f, 2.0f)); - m_mice[ENG_MOUSE_NO] = EngineMouse( 6, 7, 35, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::Point(10.0f, 10.0f)); - m_mice[ENG_MOUSE_EDIT] = EngineMouse( 8, 9, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 6.0f, 10.0f)); - m_mice[ENG_MOUSE_CROSS] = EngineMouse(10, 11, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point(10.0f, 10.0f)); - m_mice[ENG_MOUSE_MOVEV] = EngineMouse(12, 13, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 5.0f, 11.0f)); - m_mice[ENG_MOUSE_MOVEH] = EngineMouse(14, 15, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point(11.0f, 5.0f)); - m_mice[ENG_MOUSE_MOVED] = EngineMouse(16, 17, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 9.0f, 9.0f)); - m_mice[ENG_MOUSE_MOVEI] = EngineMouse(18, 19, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 9.0f, 9.0f)); - m_mice[ENG_MOUSE_MOVE] = EngineMouse(20, 21, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point(11.0f, 11.0f)); - m_mice[ENG_MOUSE_TARGET] = EngineMouse(22, 23, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point(15.0f, 15.0f)); - m_mice[ENG_MOUSE_SCROLLL] = EngineMouse(24, 25, 43, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 2.0f, 9.0f)); - m_mice[ENG_MOUSE_SCROLLR] = EngineMouse(26, 27, 44, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point(17.0f, 9.0f)); - m_mice[ENG_MOUSE_SCROLLU] = EngineMouse(28, 29, 45, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 9.0f, 2.0f)); - m_mice[ENG_MOUSE_SCROLLD] = EngineMouse(30, 31, 46, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 9.0f, 17.0f)); - - m_mouseSize = Math::Point(48.f/m_size.x, 48.f/m_size.x * (800.f/600.f)); m_mouseType = ENG_MOUSE_NORM; m_fpsCounter = 0; @@ -280,7 +315,6 @@ void CEngine::SetTerrain(CTerrain* terrain) bool CEngine::Create() { m_size = m_app->GetVideoConfig().size; - m_mouseSize = Math::Point(48.f/m_size.x, 48.f/m_size.x * (static_cast(m_size.x) / static_cast(m_size.y))); // Use the setters to set defaults, because they automatically disable what is not supported SetShadowMapping(m_shadowMapping); @@ -359,7 +393,6 @@ void CEngine::Destroy() void CEngine::ResetAfterVideoConfigChanged() { m_size = m_app->GetVideoConfig().size; - m_mouseSize = Math::Point(48.f/m_size.x, 48.f/m_size.x * (static_cast(m_size.x) / static_cast(m_size.y))); // Update the camera projection matrix for new aspect ratio ApplyChange(); @@ -4833,8 +4866,8 @@ void CEngine::DrawOverColor() void CEngine::DrawHighlight() { Math::Point min, max; - min.x = 1000000.0f; - min.y = 1000000.0f; + min.x = 1000000.0f; + min.y = 1000000.0f; max.x = -1000000.0f; max.y = -1000000.0f; @@ -4851,10 +4884,10 @@ void CEngine::DrawHighlight() } } - if ( min.x == 1000000.0f || - min.y == 1000000.0f || - max.x == -1000000.0f || - max.y == -1000000.0f ) + if (min.x == 1000000.0f || + min.y == 1000000.0f || + max.x == -1000000.0f || + max.y == -1000000.0f) { m_highlight = false; // not highlighted } @@ -4865,7 +4898,7 @@ void CEngine::DrawHighlight() m_highlight = true; } - if (! m_highlight) + if (!m_highlight) return; Math::Point p1 = m_highlightP1; @@ -4881,8 +4914,8 @@ void CEngine::DrawHighlight() SetState(ENG_RSTATE_OPAQUE_COLOR); - float d = 0.5f+sinf(m_highlightTime*6.0f)*0.5f; - d *= (p2.x-p1.x)*0.1f; + float d = 0.5f + sinf(m_highlightTime * 6.0f) * 0.5f; + d *= (p2.x - p1.x) * 0.1f; p1.x += d; p1.y += d; p2.x -= d; @@ -4891,11 +4924,11 @@ void CEngine::DrawHighlight() Color color(1.0f, 1.0f, 0.0f); // yellow VertexCol line[3] = - { - VertexCol(Math::Vector(), color), - VertexCol(Math::Vector(), color), - VertexCol(Math::Vector(), color) - }; + { + VertexCol(Math::Vector(), color), + VertexCol(Math::Vector(), color), + VertexCol(Math::Vector(), color) + }; float dx = (p2.x - p1.x) / 5.0f; float dy = (p2.y - p1.y) / 5.0f; @@ -4927,6 +4960,8 @@ void CEngine::DrawMouse() if (mode != MOUSE_ENGINE && mode != MOUSE_BOTH) return; + SetWindowCoordinates(); + Material material; material.diffuse = Color(1.0f, 1.0f, 1.0f); material.ambient = Color(0.5f, 0.5f, 0.5f); @@ -4934,33 +4969,34 @@ void CEngine::DrawMouse() m_device->SetMaterial(material); m_device->SetTexture(0, m_miceTexture); - int index = static_cast(m_mouseType); + Math::Point mousePos = CInput::GetInstancePointer()->GetMousePos(); + Math::IntPoint pos(mousePos.x * m_size.x, m_size.y - mousePos.y * m_size.y); + pos.x -= MOUSE_TYPES.at(m_mouseType).hotPoint.x; + pos.y -= MOUSE_TYPES.at(m_mouseType).hotPoint.y; - Math::Point pos = CInput::GetInstancePointer()->GetMousePos(); - pos.x = pos.x - (m_mice[index].hotPoint.x * m_mouseSize.x) / 32.0f; - pos.y = pos.y - ((32.0f - m_mice[index].hotPoint.y) * m_mouseSize.y) / 32.0f; - - Math::Point shadowPos; - shadowPos.x = pos.x + (4.0f/800.0f); - shadowPos.y = pos.y - (3.0f/600.0f); + Math::IntPoint shadowPos; + shadowPos.x = pos.x + 4; + shadowPos.y = pos.y - 3; SetState(ENG_RSTATE_TCOLOR_WHITE); - DrawMouseSprite(shadowPos, m_mouseSize, m_mice[index].iconShadow); + DrawMouseSprite(shadowPos, MOUSE_SIZE, MOUSE_TYPES.at(m_mouseType).iconShadow); - SetState(m_mice[index].mode1); - DrawMouseSprite(pos, m_mouseSize, m_mice[index].icon1); + SetState(MOUSE_TYPES.at(m_mouseType).mode1); + DrawMouseSprite(pos, MOUSE_SIZE, MOUSE_TYPES.at(m_mouseType).icon1); - SetState(m_mice[index].mode2); - DrawMouseSprite(pos, m_mouseSize, m_mice[index].icon2); + SetState(MOUSE_TYPES.at(m_mouseType).mode2); + DrawMouseSprite(pos, MOUSE_SIZE, MOUSE_TYPES.at(m_mouseType).icon2); + + SetInterfaceCoordinates(); } -void CEngine::DrawMouseSprite(Math::Point pos, Math::Point size, int icon) +void CEngine::DrawMouseSprite(Math::IntPoint pos, Math::IntPoint size, int icon) { if (icon == -1) return; - Math::Point p1 = pos; - Math::Point p2 = p1 + size; + Math::IntPoint p1 = pos; + Math::IntPoint p2 = p1 + size; float u1 = (32.0f / 256.0f) * (icon % 8); float v1 = (32.0f / 256.0f) * (icon / 8); @@ -4977,10 +5013,10 @@ void CEngine::DrawMouseSprite(Math::Point pos, Math::Point size, int icon) Vertex vertex[4] = { - Vertex(Math::Vector(p1.x, p1.y, 0.0f), normal, Math::Point(u1, v2)), - Vertex(Math::Vector(p1.x, p2.y, 0.0f), normal, Math::Point(u1, v1)), - Vertex(Math::Vector(p2.x, p1.y, 0.0f), normal, Math::Point(u2, v2)), - Vertex(Math::Vector(p2.x, p2.y, 0.0f), normal, Math::Point(u2, v1)) + Vertex(Math::Vector(p1.x, p2.y, 0.0f), normal, Math::Point(u1, v2)), + Vertex(Math::Vector(p1.x, p1.y, 0.0f), normal, Math::Point(u1, v1)), + Vertex(Math::Vector(p2.x, p2.y, 0.0f), normal, Math::Point(u2, v2)), + Vertex(Math::Vector(p2.x, p1.y, 0.0f), normal, Math::Point(u2, v1)) }; m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4); diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index ab0cc524..1f4eca63 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -482,40 +482,6 @@ enum EngineMouseType ENG_MOUSE_COUNT }; -/** - * \struct EngineMouse - * \brief Information about mouse cursor - */ -struct EngineMouse -{ - //! Index of texture element for 1st image - int icon1; - //! Index of texture element for 2nd image - int icon2; - //! Shadow texture part - int iconShadow; - //! Mode to render 1st image in - EngineRenderState mode1; - //! Mode to render 2nd image in - EngineRenderState mode2; - //! Hot point - Math::Point hotPoint; - - EngineMouse(int icon1 = -1, - int icon2 = -1, - int iconShadow = -1, - EngineRenderState mode1 = ENG_RSTATE_NORMAL, - EngineRenderState mode2 = ENG_RSTATE_NORMAL, - Math::Point hotPoint = Math::Point()) - : icon1(icon1) - , icon2(icon2) - , iconShadow(iconShadow) - , mode1(mode1) - , mode2(mode2) - , hotPoint(hotPoint) - {} -}; - /** * \class CEngine @@ -1251,7 +1217,7 @@ protected: //! Draws the mouse cursor void DrawMouse(); //! Draw part of mouse cursor sprite - void DrawMouseSprite(Math::Point pos, Math::Point size, int icon); + void DrawMouseSprite(Math::IntPoint pos, Math::IntPoint size, int icon); //! Draw statistic texts void DrawStats(); //! Draw mission timer @@ -1478,12 +1444,8 @@ protected: * so are disabled for subsequent load calls. */ std::set m_texBlacklist; - //! Mouse cursor definitions - EngineMouse m_mice[ENG_MOUSE_COUNT]; //! Texture with mouse cursors Texture m_miceTexture; - //! Size of mouse cursor - Math::Point m_mouseSize; //! Type of mouse cursor EngineMouseType m_mouseType; diff --git a/src/math/intpoint.h b/src/math/intpoint.h index 876d9e54..470abf38 100644 --- a/src/math/intpoint.h +++ b/src/math/intpoint.h @@ -25,6 +25,8 @@ #pragma once #include +#include +#include // Math module namespace namespace Math @@ -59,6 +61,100 @@ struct IntPoint { return sqrtf(x*x + y*y); } + + //! Sets the zero point: (0,0) + inline void LoadZero() + { + x = y = 0.0f; + } + + //! Returns the struct cast to \c int* array; use with care! + inline int* Array() + { + return reinterpret_cast(this); + } + + //! Returns the struct cast to const int* array; use with care! + inline const int* Array() const + { + return reinterpret_cast(this); + } + + //! Returns the inverted point + inline IntPoint operator-() const + { + return IntPoint(-x, -y); + } + + //! Adds the given point + inline const IntPoint& operator+=(const IntPoint &right) + { + x += right.x; + y += right.y; + return *this; + } + + //! Adds two points + inline friend const IntPoint operator+(const IntPoint &left, const IntPoint &right) + { + return IntPoint(left.x + right.x, left.y + right.y); + } + + //! Subtracts the given point + inline const IntPoint& operator-=(const IntPoint &right) + { + x -= right.x; + y -= right.y; + return *this; + } + + //! Subtracts two points + inline friend const IntPoint operator-(const IntPoint &left, const IntPoint &right) + { + return IntPoint(left.x - right.x, left.y - right.y); + } + + //! Multiplies by given scalar + inline const IntPoint& operator*=(const float &right) + { + x *= right; + y *= right; + return *this; + } + + //! Multiplies point by scalar + inline friend const IntPoint operator*(const float &left, const IntPoint &right) + { + return IntPoint(left * right.x, left * right.y); + } + + //! Multiplies point by scalar + inline friend const IntPoint operator*(const IntPoint &left, const int &right) + { + return IntPoint(left.x * right, left.y * right); + } + + //! Divides by given scalar + inline const IntPoint& operator/=(const float &right) + { + x /= right; + y /= right; + return *this; + } + + //! Divides point by scalar + inline friend const IntPoint operator/(const IntPoint &left, const int &right) + { + return IntPoint(left.x / right, left.y / right); + } + + //! Returns a string "[x, y]" + inline std::string ToString() const + { + std::stringstream s; + s << "[" << x << ", " << y << "]"; + return s.str(); + } }; diff --git a/src/math/point.h b/src/math/point.h index 786e8202..cd568ac1 100644 --- a/src/math/point.h +++ b/src/math/point.h @@ -90,7 +90,7 @@ struct Point return sqrtf(x*x + y*y); } - //! Returns the inverted point + //! Returns the inverted point inline Point operator-() const { return Point(-x, -y); @@ -110,7 +110,7 @@ struct Point return Point(left.x + right.x, left.y + right.y); } - //! Subtracts the given vector + //! Subtracts the given point inline const Point& operator-=(const Point &right) { x -= right.x; From 0d74b4f36b8e9fbd6236c56976d82abf56545fea Mon Sep 17 00:00:00 2001 From: melex750 Date: Fri, 24 Jun 2016 16:56:17 -0400 Subject: [PATCH 112/125] Fix initializing an array using variables Resolves a conflict between CBotListArray and CBotExprVar --- src/CBot/CBotInstr/CBotListArray.cpp | 19 +++++++++---------- src/CBot/CBotInstr/CBotListArray.h | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp index 559bb9d9..89cbb79a 100644 --- a/src/CBot/CBotInstr/CBotListArray.cpp +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -98,7 +98,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu } } - inst->m_expr->AddNext3(i); + inst->m_expr->AddNext3b(i); if ( p->GetType() == ID_COMMA ) continue; if ( p->GetType() == ID_CLBLK ) break; @@ -114,10 +114,10 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu { goto error; } - CBotVar* pv = pStk->GetVar(); // result of the expression - if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) && - !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer)) )) + CBotTypResult valType = pStk->GetTypResult(); + + if (!TypeCompatible(valType, type, ID_ASS) ) { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; @@ -133,15 +133,14 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu goto error; } - CBotVar* pv = pStk->GetVar(); // result of the expression + CBotTypResult valType = pStk->GetTypResult(); - if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) && - !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer)) )) + if (!TypeCompatible(valType, type, ID_ASS) ) { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; } - inst->m_expr->AddNext3(i); + inst->m_expr->AddNext3b(i); if (p->GetType() == ID_COMMA) continue; if (p->GetType() == ID_CLBLK) break; @@ -175,7 +174,7 @@ bool CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar) int n = 0; - for (; p != nullptr ; n++, p = p->GetNext3()) + for (; p != nullptr ; n++, p = p->GetNext3b()) { if (pile1->GetState() > n) continue; @@ -207,7 +206,7 @@ void CBotListArray::RestoreState(CBotStack* &pj, bool bMain) int state = pile->GetState(); - while(state-- > 0) p = p->GetNext3() ; + while(state-- > 0) p = p->GetNext3b() ; p->RestoreState(pile, bMain); // size calculation //interrupted! } diff --git a/src/CBot/CBotInstr/CBotListArray.h b/src/CBot/CBotInstr/CBotListArray.h index c5f800b0..18d6b567 100644 --- a/src/CBot/CBotInstr/CBotListArray.h +++ b/src/CBot/CBotInstr/CBotListArray.h @@ -62,7 +62,7 @@ protected: virtual std::map GetDebugLinks() override; private: - //! An expression for an element others are linked with CBotInstr :: m_next3; + //! An expression for an element others are linked with CBotInstr :: m_next3b; CBotInstr* m_expr; }; From 66984a4bb3a0c3249322b85184f8d3c17953fb59 Mon Sep 17 00:00:00 2001 From: melex750 Date: Fri, 24 Jun 2016 17:00:41 -0400 Subject: [PATCH 113/125] Fix using compound-assignment with an array ...that was initialized in the definition --- src/CBot/CBotInstr/CBotDefArray.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/CBot/CBotInstr/CBotDefArray.cpp b/src/CBot/CBotInstr/CBotDefArray.cpp index 473fdc8d..c1995d92 100644 --- a/src/CBot/CBotInstr/CBotDefArray.cpp +++ b/src/CBot/CBotInstr/CBotDefArray.cpp @@ -121,6 +121,15 @@ CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResul } } } + + if (pStk->IsOk()) while (true) // mark initialized + { + var = var->GetItem(0, true); + if (var == nullptr) break; + if (var->GetType() == CBotTypArrayPointer) continue; + if (var->GetType() <= CBotTypString) var->SetInit(CBotVar::InitType::DEF); + break; + } } if (pStk->IsOk()) return pStack->Return(inst, pStk); From 51665e8396800391fdc9a7eb20df824ab28ed033 Mon Sep 17 00:00:00 2001 From: melex750 Date: Fri, 24 Jun 2016 17:03:50 -0400 Subject: [PATCH 114/125] Fix "new" keyword syntax checking --- src/CBot/CBotInstr/CBotNew.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp index 7da8e417..a302b394 100644 --- a/src/CBot/CBotInstr/CBotNew.cpp +++ b/src/CBot/CBotInstr/CBotNew.cpp @@ -50,7 +50,11 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack) if (!IsOfType(p, ID_NEW)) return nullptr; // verifies that the token is a class name - if (p->GetType() != TokenTypVar) return nullptr; + if (p->GetType() != TokenTypVar) + { + pStack->SetError(CBotErrBadNew, p); + return nullptr; + } CBotClass* pClass = CBotClass::Find(p); if (pClass == nullptr) From 64157090e66aeb5cec7ac1b72748ac1eeeb09dfa Mon Sep 17 00:00:00 2001 From: melex750 Date: Fri, 24 Jun 2016 17:18:11 -0400 Subject: [PATCH 115/125] Fix crash when calling method on a null object --- src/CBot/CBotInstr/CBotInstrMethode.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp index e0d08a99..3bdf8492 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.cpp +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -103,6 +103,7 @@ bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre if (pVar->GetPointer() == nullptr) { pj->SetError(CBotErrNull, prevToken); + return pj->Return(pile1); } if (pile1->IfStep()) return false; From d0d0c4f197f82fa4aa134cdd6ab2c436c1748715 Mon Sep 17 00:00:00 2001 From: melex750 Date: Fri, 24 Jun 2016 17:29:32 -0400 Subject: [PATCH 116/125] Fix class not unlocked when program is stopped #626 --- src/CBot/CBotProgram.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index dde36bb4..d0284ea2 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -214,6 +214,7 @@ bool CBotProgram::Run(void* pUser, int timer) m_error = m_stack->GetError(m_errorStart, m_errorEnd); m_stack->Delete(); m_stack = nullptr; + CBotClass::FreeLock(this); return true; // execution is finished! } @@ -226,6 +227,7 @@ void CBotProgram::Stop() m_stack->Delete(); m_stack = nullptr; m_entryPoint = nullptr; + CBotClass::FreeLock(this); } //////////////////////////////////////////////////////////////////////////////// From 11d40197eea2f162bfc495a25709edfa4b0c3719 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 4 Jul 2016 12:23:48 +0200 Subject: [PATCH 117/125] Added some more CBot tests after #793 --- test/unit/CBot/CBot_test.cpp | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/unit/CBot/CBot_test.cpp b/test/unit/CBot/CBot_test.cpp index c0d5e122..2d96d59e 100644 --- a/test/unit/CBot/CBot_test.cpp +++ b/test/unit/CBot/CBot_test.cpp @@ -808,6 +808,33 @@ TEST_F(CBotUT, ClassDestructor) ); } +TEST_F(CBotUT, ClassBadNew) +{ + ExecuteTest( + "public class AClass {};\n" + "extern void ClassBadNew()\n" + "{\n" + " AClass a = new \"abc\";\n" + "}\n", + CBotErrBadNew + ); +} + +TEST_F(CBotUT, ClassCallOnNull) +{ + ExecuteTest( + "public class AClass {\n" + " public void test() {}\n" + "};\n" + "extern void ClassCallOnNull()\n" + "{\n" + " AClass a = null;\n" + " a.test();\n" + "}\n", + CBotErrNull + ); +} + TEST_F(CBotUT, ClassNullPointer) { ExecuteTest( @@ -1105,6 +1132,19 @@ TEST_F(CBotUT, TestArrayInitialization) "}\n", CBotErrOutArray ); + + ExecuteTest( + "extern void TestArrayInitializationWithVars() {\n" + " int x=1, y=2, z=3;\n" + " int i[] = { x, y, z };\n" + " ASSERT(i[0] == 1);\n" + " ASSERT(i[1] == 2);\n" + " ASSERT(i[2] == 3);\n" + " i[0] += 1;\n" + " ASSERT(i[0] == 2);\n" + " ASSERT(x == 1);\n" + "}\n" + ); } TEST_F(CBotUT, TestArrayFunctionReturn) From 7bfe9fdd0adea1d1374009a31f63066040ccf604 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 4 Jul 2016 13:23:37 +0200 Subject: [PATCH 118/125] Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 5614bfe9..60fb1c5d 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 5614bfe93c565d2f006138b0ec5b4fe380a04f08 +Subproject commit 60fb1c5dc12f4c951cc10d979dc080bd43057363 From 58815059eaad11fa8ecf206dc03165a7b4f209ec Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 4 Jul 2016 16:30:22 +0200 Subject: [PATCH 119/125] Added warnings about planned changes to EndMisisonTake (#759) --- src/app/pathman.cpp | 1 + src/level/robotmain.cpp | 18 ++++++++++++++++++ tools/check-levels.sh | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/app/pathman.cpp b/src/app/pathman.cpp index 2e32ddf0..8f862110 100644 --- a/src/app/pathman.cpp +++ b/src/app/pathman.cpp @@ -145,6 +145,7 @@ void CPathManager::InitPaths() void CPathManager::LoadModsFromDir(const std::string &dir) { + GetLogger()->Trace("Looking for mods in '%s' ...\n", dir.c_str()); try { #if PLATFORM_WINDOWS diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 86d1d168..36ee5031 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -2785,6 +2785,12 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) Gfx::Color backgroundCloudDown = Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f); bool backgroundFull = false; + auto LoadingWarning = [&](const std::string& message) + { + GetLogger()->Warn("%s\n", message.c_str()); + m_ui->GetDialog()->StartInformation("Level loading warning", "This level contains problems. It may stop working in future versions of the game.", message); + }; + try { m_ui->GetLoadingScreen()->SetProgress(0.05f, RT_LOADING_PROCESSING); @@ -2868,6 +2874,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) int rank = boost::lexical_cast(line->GetParam(type)->GetValue()); if (rank >= 0) { + // TODO: Fix default levels and add a future removal warning GetLogger()->Warn("This level is using deprecated way of defining %1$s scene. Please change the %1$s= parameter in EndingFile from %2$d to \"levels/other/%1$s%2$03d.txt\".\n", type.c_str(), rank); std::stringstream ss; ss << "levels/other/" << type << std::setfill('0') << std::setw(3) << rank << ".txt"; @@ -2875,6 +2882,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } else { + // TODO: Fix default levels and add a future removal warning GetLogger()->Warn("This level is using deprecated way of defining %1$s scene. Please remove the %1$s= parameter in EndingFile.\n", type.c_str()); return ""; } @@ -2931,6 +2939,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_ui->GetLoadingScreen()->SetProgress(0.15f, RT_LOADING_MUSIC, audioChange->music); m_sound->CacheMusic(audioChange->music); m_audioChange.push_back(std::move(audioChange)); + + if (!line->GetParam("pos")->IsDefined() || !line->GetParam("dist")->IsDefined()) + { + LoadingWarning("The defaults for pos= and dist= are going to change, specify them explicitly. See issue #759 (https://git.io/vVBzH)"); + } continue; } @@ -3560,6 +3573,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (endTake->immediat) m_endTakeImmediat = true; m_endTake.push_back(std::move(endTake)); + + if (!line->GetParam("pos")->IsDefined() || !line->GetParam("dist")->IsDefined()) + { + LoadingWarning("The defaults for pos= and dist= are going to change, specify them explicitly. See issue #759 (https://git.io/vVBzH)"); + } continue; } if (line->GetCommand() == "EndMissionDelay" && !resetObject) diff --git a/tools/check-levels.sh b/tools/check-levels.sh index c2778673..2d980b08 100755 --- a/tools/check-levels.sh +++ b/tools/check-levels.sh @@ -13,7 +13,7 @@ for category in $categories; do if [ ! -d /usr/local/share/games/colobot/levels/$category/chapter00$chapter/$level ]; then continue; fi level=`echo -n $level | cut -d . -f 1 | tail -c 3` echo $category$chapter$level - colobot -runscene $category$chapter$level -scenetest -loglevel warn -headless 2>&1 | grep -v --line-buffered "Colobot starting" | grep -v --line-buffered "Log level changed" | grep -v --line-buffered "Running scene" + colobot -runscene $category$chapter$level -scenetest -loglevel warn -headless 2>&1 | grep -vE --line-buffered "Colobot.*starting" | grep -v --line-buffered "Log level changed" | grep -v --line-buffered "Running scene" done done done From fb3245977c0b3d7a7625141d0170b78424c44bff Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 4 Jul 2016 17:01:48 +0200 Subject: [PATCH 120/125] Added logging to CPauseManager --- src/app/pausemanager.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/app/pausemanager.cpp b/src/app/pausemanager.cpp index ead940ab..69bc487b 100644 --- a/src/app/pausemanager.cpp +++ b/src/app/pausemanager.cpp @@ -26,6 +26,7 @@ #include "level/robotmain.h" #include +#include struct ActivePause { @@ -41,6 +42,17 @@ struct ActivePause PauseMusic music; }; +std::string GetPauseName(PauseType type) +{ + std::vector x; + if ((type & PAUSE_ENGINE) != 0) x.push_back("engine"); + if ((type & PAUSE_HIDE_SHORTCUTS) != 0) x.push_back("hide_shortcuts"); + if ((type & PAUSE_PHOTO) != 0) x.push_back("photo"); + if ((type & PAUSE_OBJECT_UPDATES) != 0) x.push_back("object_updates"); + if ((type & PAUSE_MUTE_SOUND) != 0) x.push_back("mute_sound"); + if ((type & PAUSE_CAMERA) != 0) x.push_back("camera"); + return boost::algorithm::join(x, "|"); +} CPauseManager::CPauseManager() { @@ -52,7 +64,7 @@ CPauseManager::~CPauseManager() ActivePause* CPauseManager::ActivatePause(PauseType type, PauseMusic music) { - //GetLogger()->Debug("Activated pause mode - %s\n", GetPauseName(type).c_str()); + GetLogger()->Debug("Activated pause mode - %s\n", GetPauseName(type).c_str()); auto pause = MakeUnique(type, music); ActivePause* ptr = pause.get(); m_activePause.push_back(std::move(pause)); @@ -63,7 +75,7 @@ ActivePause* CPauseManager::ActivatePause(PauseType type, PauseMusic music) void CPauseManager::DeactivatePause(ActivePause* pause) { if (pause == nullptr) return; - //GetLogger()->Debug("Deactivated pause mode - %s\n", GetPauseName(pause->type).c_str()); + GetLogger()->Debug("Deactivated pause mode - %s\n", GetPauseName(pause->type).c_str()); auto it = std::remove_if( m_activePause.begin(), m_activePause.end(), [&](const std::unique_ptr& x) { return x.get() == pause; } From 6f412df2327174b4c2f1e36007d6dbf79376bb7e Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 4 Jul 2016 17:02:39 +0200 Subject: [PATCH 121/125] Fixed lockups when calling StartSuspend multiple times --- src/level/robotmain.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 36ee5031..2aab95c9 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -1554,11 +1554,13 @@ char* CRobotMain::GetDisplayInfoName(int index) //! Beginning of a dialogue during the game void CRobotMain::StartSuspend() { + if (m_suspend != nullptr) return; // already suspended if (!IsPhaseWithWorld(m_phase)) return; + GetLogger()->Info("Start suspend\n"); m_sound->MuteAll(true); ClearInterface(); - m_suspend = m_pause->ActivatePause(PAUSE_ENGINE|PAUSE_HIDE_SHORTCUTS|PAUSE_MUTE_SOUND|PAUSE_CAMERA); + m_suspend = m_pause->ActivatePause(PAUSE_ENGINE | PAUSE_HIDE_SHORTCUTS | PAUSE_MUTE_SOUND | PAUSE_CAMERA); m_engine->SetOverFront(false); // over flat behind CreateShortcuts(); @@ -1572,6 +1574,9 @@ void CRobotMain::StartSuspend() //! End of dialogue during the game void CRobotMain::StopSuspend() { + if (m_suspend == nullptr) return; // not suspended + GetLogger()->Info("Stop suspend\n"); + m_sound->MuteAll(false); ClearInterface(); m_pause->DeactivatePause(m_suspend); @@ -1579,7 +1584,7 @@ void CRobotMain::StopSuspend() m_engine->SetOverFront(true); // over flat front CreateShortcuts(); - if(m_infoObject != nullptr) + if (m_infoObject != nullptr) SelectObject(m_infoObject, false); // gives the command buttons m_map->ShowMap(m_mapShow); m_displayText->HideText(false); From 9b9dd43c2a2dfbea8367407b8b0db0843e35e084 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 4 Jul 2016 20:36:03 +0200 Subject: [PATCH 122/125] Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 60fb1c5d..0a55d94b 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 60fb1c5dc12f4c951cc10d979dc080bd43057363 +Subproject commit 0a55d94b4e8a80b6873cf6c3f86d9438deed7c84 From 8a17bc901c8ea526278287548bf687640c8a5973 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 9 Jul 2016 12:13:51 +0200 Subject: [PATCH 123/125] Added pause blur config setting, enabled by default --- po/colobot.pot | 15 +++----------- po/de.po | 27 ++++++++++++++----------- po/fr.po | 27 ++++++++++++++----------- po/pl.po | 27 ++++++++++++++----------- po/ru.po | 27 ++++++++++++++----------- src/common/event.h | 1 + src/common/restext.cpp | 1 + src/common/settings.cpp | 8 ++++---- src/graphics/engine/engine.cpp | 14 ++++++------- src/graphics/engine/engine.h | 6 +++--- src/ui/screen/screen_setup_graphics.cpp | 14 +++++++++++++ 11 files changed, 92 insertions(+), 75 deletions(-) diff --git a/po/colobot.pot b/po/colobot.pot index d17e297f..91bfcdbd 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -359,6 +359,9 @@ msgstr "" msgid "Render distance\\Maximum visibility" msgstr "" +msgid "Pause blur\\Blur the background on the pause screen" +msgstr "" + msgid "Particles in the interface\\Steam clouds and sparks in the interface" msgstr "" @@ -926,18 +929,6 @@ msgstr "" msgid "Camera (\\key camera;)" msgstr "" -msgid "Camera to left" -msgstr "" - -msgid "Camera to right" -msgstr "" - -msgid "Camera nearest" -msgstr "" - -msgid "Camera awayest" -msgstr "" - msgid "Help about selected object" msgstr "" diff --git a/po/de.po b/po/de.po index 3e8cdea9..be31b511 100644 --- a/po/de.po +++ b/po/de.po @@ -288,9 +288,6 @@ msgstr "Die aufgerufene Funktion existiert nicht" msgid "Camera (\\key camera;)" msgstr "Kamera (\\key camera;)" -msgid "Camera awayest" -msgstr "Kamera weiter weg" - msgid "Camera back\\Moves the camera backward" msgstr "Kamera weiter\\Bewegung der Kamera rückwärts" @@ -309,19 +306,10 @@ msgstr "Kamera näher\\Bewegung der Kamera vorwärts" msgid "Camera left\\Turns the camera left" msgstr "Kamera näher\\Bewegung der Kamera vorwärts" -msgid "Camera nearest" -msgstr "Kamera näher" - #, fuzzy msgid "Camera right\\Turns the camera right" msgstr "Drehung nach rechts\\Steuer rechts" -msgid "Camera to left" -msgstr "Kamera links" - -msgid "Camera to right" -msgstr "Kamera rechts" - #, fuzzy msgid "Camera up\\Turns the camera up" msgstr "Kamera (\\key camera;)" @@ -1047,6 +1035,9 @@ msgstr "Partikel in den Menüs\\Funken und Sterne in den Menüs" msgid "Paste (Ctrl+V)" msgstr "Einfügen (Ctrl+V)" +msgid "Pause blur\\Blur the background on the pause screen" +msgstr "" + msgid "Pause in background\\Pause the game when the window is unfocused" msgstr "" @@ -1853,6 +1844,18 @@ msgstr "epsitec.com" #~ msgid "COLOBOT" #~ msgstr "COLOBOT" +#~ msgid "Camera awayest" +#~ msgstr "Kamera weiter weg" + +#~ msgid "Camera nearest" +#~ msgstr "Kamera näher" + +#~ msgid "Camera to left" +#~ msgstr "Kamera links" + +#~ msgid "Camera to right" +#~ msgstr "Kamera rechts" + #~ msgid "Can not create this; there are too many objects" #~ msgstr "Kein neues Objekt kann erstellt werden (zu viele vorhanden)" diff --git a/po/fr.po b/po/fr.po index b834222b..996fc6fb 100644 --- a/po/fr.po +++ b/po/fr.po @@ -282,9 +282,6 @@ msgstr "Appel d'une fonction inexistante" msgid "Camera (\\key camera;)" msgstr "Caméra (\\key camera;)" -msgid "Camera awayest" -msgstr "Caméra plus loin" - msgid "Camera back\\Moves the camera backward" msgstr "Caméra plus loin\\Recule la caméra" @@ -302,19 +299,10 @@ msgstr "Caméra plus proche\\Avance la caméra" msgid "Camera left\\Turns the camera left" msgstr "Caméra plus proche\\Avance la caméra" -msgid "Camera nearest" -msgstr "Caméra plus proche" - #, fuzzy msgid "Camera right\\Turns the camera right" msgstr "Tourner à droite\\Moteur à droite" -msgid "Camera to left" -msgstr "Caméra à gauche" - -msgid "Camera to right" -msgstr "Caméra à droite" - #, fuzzy msgid "Camera up\\Turns the camera up" msgstr "Caméra (\\key camera;)" @@ -1032,6 +1020,9 @@ msgstr "Particules dans l'interface\\Pluie de particules" msgid "Paste (Ctrl+V)" msgstr "Coller (Ctrl+V)" +msgid "Pause blur\\Blur the background on the pause screen" +msgstr "" + msgid "Pause in background\\Pause the game when the window is unfocused" msgstr "" @@ -1828,9 +1819,21 @@ msgstr "epsitec.com" #~ msgid "COLOBOT" #~ msgstr "COLOBOT" +#~ msgid "Camera awayest" +#~ msgstr "Caméra plus loin" + #~ msgid "Camera down\\Decrease camera angle while visiting message origin" #~ msgstr "Caméra plus basse\\Réduit l'angle de caméra lors de la vue de l'origine des messages" +#~ msgid "Camera nearest" +#~ msgstr "Caméra plus proche" + +#~ msgid "Camera to left" +#~ msgstr "Caméra à gauche" + +#~ msgid "Camera to right" +#~ msgstr "Caméra à droite" + #~ msgid "Camera up\\Increase camera angle while visiting message origin" #~ msgstr "Caméra plus haute\\Augmente l'angle de caméra lors de la vue de l'origine des messages" diff --git a/po/pl.po b/po/pl.po index 64d57d87..1b0dc6d4 100644 --- a/po/pl.po +++ b/po/pl.po @@ -285,9 +285,6 @@ msgstr "Odwołanie do nieznanej funkcji" msgid "Camera (\\key camera;)" msgstr "Kamera (\\key camera;)" -msgid "Camera awayest" -msgstr "Camera awayest" - msgid "Camera back\\Moves the camera backward" msgstr "Kamera dalej\\Oddala kamerę" @@ -303,18 +300,9 @@ msgstr "Kamera w dół\\Obraca kamerę w dół" msgid "Camera left\\Turns the camera left" msgstr "Kamera w lewo\\Obraca kamerę w lewo" -msgid "Camera nearest" -msgstr "Camera nearest" - msgid "Camera right\\Turns the camera right" msgstr "Kamera w prawo\\Obróć kamerę w prawo" -msgid "Camera to left" -msgstr "Camera to left" - -msgid "Camera to right" -msgstr "Camera to right" - msgid "Camera up\\Turns the camera up" msgstr "Kamera w górę\\Obróć kamerę w górę" @@ -1031,6 +1019,9 @@ msgstr "Cząstki w interfejsie\\Para i iskry z silników w interfejsie" msgid "Paste (Ctrl+V)" msgstr "Wklej (Ctrl+V)" +msgid "Pause blur\\Blur the background on the pause screen" +msgstr "" + msgid "Pause in background\\Pause the game when the window is unfocused" msgstr "Wstrzymaj w tle\\Wstrzymaj grę gdy okno stanie się nieaktywne" @@ -1820,9 +1811,21 @@ msgstr "epsitec.com" #~ msgid "Building too close" #~ msgstr "Budynek za blisko" +#~ msgid "Camera awayest" +#~ msgstr "Camera awayest" + #~ msgid "Camera down\\Decrease camera angle while visiting message origin" #~ msgstr "Kamera w dół\\Opuść kamerę podczas sprawdzania źródła wiadomości" +#~ msgid "Camera nearest" +#~ msgstr "Camera nearest" + +#~ msgid "Camera to left" +#~ msgstr "Camera to left" + +#~ msgid "Camera to right" +#~ msgstr "Camera to right" + #~ msgid "Camera up\\Increase camera angle while visiting message origin" #~ msgstr "Kamera w górę\\Podnieś kamerę podczas sprawdzania źródła wiadomości" diff --git a/po/ru.po b/po/ru.po index 9d5c0e31..539ed447 100644 --- a/po/ru.po +++ b/po/ru.po @@ -286,9 +286,6 @@ msgstr "Вызов неизвестной функции" msgid "Camera (\\key camera;)" msgstr "Камера (\\key camera;)" -msgid "Camera awayest" -msgstr "Отдалить камеру" - msgid "Camera back\\Moves the camera backward" msgstr "Отдалить камеру\\Перемещение камеры назад" @@ -307,19 +304,10 @@ msgstr "Приблизать камеру\\Перемещение камеры msgid "Camera left\\Turns the camera left" msgstr "Приблизать камеру\\Перемещение камеры вперед" -msgid "Camera nearest" -msgstr "Приблизить камеру" - #, fuzzy msgid "Camera right\\Turns the camera right" msgstr "Повернуть налево\\Поворот налево" -msgid "Camera to left" -msgstr "Камеру влево" - -msgid "Camera to right" -msgstr "Камеру вправо" - #, fuzzy msgid "Camera up\\Turns the camera up" msgstr "Камера (\\key camera;)" @@ -1043,6 +1031,9 @@ msgstr "Частицы в интерфейсе меню\\Пар из труб и msgid "Paste (Ctrl+V)" msgstr "Вставить (Ctrl+V)" +msgid "Pause blur\\Blur the background on the pause screen" +msgstr "" + msgid "Pause in background\\Pause the game when the window is unfocused" msgstr "" @@ -1844,6 +1835,18 @@ msgstr "epsitec.com" #~ msgid "COLOBOT" #~ msgstr "КОЛОБОТ" +#~ msgid "Camera awayest" +#~ msgstr "Отдалить камеру" + +#~ msgid "Camera nearest" +#~ msgstr "Приблизить камеру" + +#~ msgid "Camera to left" +#~ msgstr "Камеру влево" + +#~ msgid "Camera to right" +#~ msgstr "Камеру вправо" + #~ msgid "Can not create this; there are too many objects" #~ msgstr "Не удается это создать, слишком много объектов" diff --git a/src/common/event.h b/src/common/event.h index 061cba67..315a4b5b 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -237,6 +237,7 @@ enum EventType EVENT_INTERFACE_LIGHT = 457, EVENT_INTERFACE_PARTI = 458, EVENT_INTERFACE_CLIP = 459, + EVENT_INTERFACE_PAUSE_BLUR = 460, EVENT_INTERFACE_RAIN = 462, EVENT_INTERFACE_GLINT = 463, EVENT_INTERFACE_TOOLTIP = 464, diff --git a/src/common/restext.cpp b/src/common/restext.cpp index df63d839..9770c32a 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -184,6 +184,7 @@ void InitializeRestext() stringsEvent[EVENT_INTERFACE_LIGHT] = TR("Dynamic lighting\\Mobile light sources"); stringsEvent[EVENT_INTERFACE_PARTI] = TR("Number of particles\\Explosions, dust, reflections, etc."); stringsEvent[EVENT_INTERFACE_CLIP] = TR("Render distance\\Maximum visibility"); + stringsEvent[EVENT_INTERFACE_PAUSE_BLUR]= TR("Pause blur\\Blur the background on the pause screen"); stringsEvent[EVENT_INTERFACE_RAIN] = TR("Particles in the interface\\Steam clouds and sparks in the interface"); stringsEvent[EVENT_INTERFACE_GLINT] = TR("Reflections on the buttons \\Shiny buttons"); stringsEvent[EVENT_INTERFACE_TOOLTIP] = TR("Help balloons\\Explain the function of the buttons"); diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 10039848..4519b079 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -98,6 +98,7 @@ void CSettings::SaveSettings() GetConfigFile().SetIntProperty("Setup", "MusicVolume", sound->GetMusicVolume()); GetConfigFile().SetBoolProperty("Setup", "EditIndentMode", engine->GetEditIndentMode()); GetConfigFile().SetIntProperty("Setup", "EditIndentValue", engine->GetEditIndentValue()); + GetConfigFile().SetBoolProperty("Setup", "PauseBlur", engine->GetPauseBlurEnabled()); GetConfigFile().SetIntProperty("Setup", "MipmapLevel", engine->GetTextureMipmapLevel()); GetConfigFile().SetIntProperty("Setup", "Anisotropy", engine->GetTextureAnisotropyLevel()); @@ -112,7 +113,6 @@ void CSettings::SaveSettings() // Experimental settings GetConfigFile().SetBoolProperty("Experimental", "TerrainShadows", engine->GetTerrainShadows()); - GetConfigFile().SetBoolProperty("Experimental", "PauseBlur", engine->GetPauseBlur()); CInput::GetInstancePointer()->SaveKeyBindings(); @@ -230,6 +230,9 @@ void CSettings::LoadSettings() if (GetConfigFile().GetIntProperty("Setup", "EditIndentValue", iValue)) engine->SetEditIndentValue(iValue); + if (GetConfigFile().GetBoolProperty("Setup", "PauseBlur", bValue)) + engine->SetPauseBlurEnabled(bValue); + if (GetConfigFile().GetIntProperty("Setup", "MipmapLevel", iValue)) engine->SetTextureMipmapLevel(iValue); @@ -271,9 +274,6 @@ void CSettings::LoadSettings() if (GetConfigFile().GetBoolProperty("Experimental", "TerrainShadows", bValue)) engine->SetTerrainShadows(bValue); - if (GetConfigFile().GetBoolProperty("Experimental", "PauseBlur", bValue)) - engine->SetPauseBlur(bValue); - CInput::GetInstancePointer()->LoadKeyBindings(); diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index f7d0b5a0..a6adbad2 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -202,7 +202,7 @@ CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils) m_editIndentMode = true; m_editIndentValue = 4; m_tracePrecision = 1.0f; - m_pauseBlur = false; + m_pauseBlurEnabled = true; m_updateGeometry = false; @@ -3070,14 +3070,14 @@ EngineMouseType CEngine::GetMouseType() return m_mouseType; } -void CEngine::SetPauseBlur(bool enable) +void CEngine::SetPauseBlurEnabled(bool enable) { - m_pauseBlur = enable; + m_pauseBlurEnabled = enable; } -bool CEngine::GetPauseBlur() +bool CEngine::GetPauseBlurEnabled() { - return m_pauseBlur; + return m_pauseBlurEnabled; } const Math::Matrix& CEngine::GetMatView() @@ -5414,7 +5414,7 @@ void CEngine::SetInterfaceCoordinates() void CEngine::EnablePauseBlur() { - if (!m_pauseBlur) return; + if (!m_pauseBlurEnabled) return; m_captureWorld = true; m_worldCaptured = false; @@ -5422,8 +5422,6 @@ void CEngine::EnablePauseBlur() void CEngine::DisablePauseBlur() { - if (!m_pauseBlur) return; - m_captureWorld = false; m_worldCaptured = false; } diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 1f4eca63..e1dadf4d 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -1129,8 +1129,8 @@ public: //@{ //! Management of pause blur - void SetPauseBlur(bool enable); - bool GetPauseBlur(); + void SetPauseBlurEnabled(bool enable); + bool GetPauseBlurEnabled(); //@} //! Returns the view matrix @@ -1386,7 +1386,7 @@ protected: float m_terrainVision; bool m_backForce; float m_tracePrecision; - bool m_pauseBlur; + bool m_pauseBlurEnabled; bool m_dirty; bool m_fog; diff --git a/src/ui/screen/screen_setup_graphics.cpp b/src/ui/screen/screen_setup_graphics.cpp index 93467540..45808135 100644 --- a/src/ui/screen/screen_setup_graphics.cpp +++ b/src/ui/screen/screen_setup_graphics.cpp @@ -112,6 +112,9 @@ void CScreenSetupGraphics::CreateInterface() { pc->SetState(STATE_DEAD); } + pos.y -= 0.048f; + pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_PAUSE_BLUR); + pc->SetState(STATE_SHADOW); pos.x = ox+sx*8.5f; pos.y = 0.65f; @@ -272,6 +275,11 @@ bool CScreenSetupGraphics::EventProcess(const Event &event) UpdateSetupButtons(); break; + case EVENT_INTERFACE_PAUSE_BLUR: + m_engine->SetPauseBlurEnabled(!m_engine->GetPauseBlurEnabled()); + UpdateSetupButtons(); + break; + case EVENT_INTERFACE_SHADOW_SPOTS: m_engine->SetShadowMapping(false); m_engine->SetShadowMappingQuality(false); @@ -363,6 +371,12 @@ void CScreenSetupGraphics::UpdateSetupButtons() pc->SetState(STATE_CHECK, m_engine->GetLightMode()); } + pc = static_cast(pw->SearchControl(EVENT_INTERFACE_PAUSE_BLUR)); + if ( pc != nullptr ) + { + pc->SetState(STATE_CHECK, m_engine->GetPauseBlurEnabled()); + } + pc = static_cast(pw->SearchControl(EVENT_INTERFACE_SHADOW_SPOTS)); if ( pc != nullptr ) { From 9e545d0d39077eac131a7d3fa9ddb51cb55adb41 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 9 Jul 2016 20:39:18 +0200 Subject: [PATCH 124/125] Fixed colobot-lint warnings --- src/CBot/CBotVar/CBotVarValue.h | 19 +++++++++++++++++++ src/graphics/engine/camera.cpp | 2 +- src/graphics/engine/engine.cpp | 4 ++-- src/level/robotmain.cpp | 3 ++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/CBot/CBotVar/CBotVarValue.h b/src/CBot/CBotVar/CBotVarValue.h index 3e184d7b..3fd15286 100644 --- a/src/CBot/CBotVar/CBotVarValue.h +++ b/src/CBot/CBotVar/CBotVarValue.h @@ -1,3 +1,22 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + #pragma once #include "CBot/CBotVar/CBotVar.h" diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index 5f5c254c..9f7fc40e 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -254,7 +254,7 @@ CObject* CCamera::GetControllingObject() void CCamera::SetType(CameraType type) { - if ( (m_type == CAM_TYPE_BACK) ) + if (m_type == CAM_TYPE_BACK) { for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects()) { diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index a6adbad2..27d2db70 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -3510,7 +3510,7 @@ void CEngine::Capture3DScene() // calculate 2nd mipmap int newWidth = width / 4; int newHeight = height / 4; - std::unique_ptr mipmap(new unsigned char[4 * newWidth * newHeight]); + std::unique_ptr mipmap = MakeUniqueArray(4 * newWidth * newHeight); for (int x = 0; x < newWidth; x++) { @@ -3539,7 +3539,7 @@ void CEngine::Capture3DScene() } // calculate Gaussian blur - std::unique_ptr blured(new unsigned char[4 * newWidth * newHeight]); + std::unique_ptr blured = MakeUniqueArray(4 * newWidth * newHeight); float matrix[7][7] = { diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 2aab95c9..75c12f8a 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -5525,7 +5525,8 @@ void CRobotMain::AutosaveRotate() auto saveDirs = CResourceManager::ListDirectories(m_playerProfile->GetSaveDir()); const std::string autosavePrefix = "autosave"; std::vector autosaves; - std::copy_if(saveDirs.begin(), saveDirs.end(), std::back_inserter(autosaves), [&](const std::string &save) { + std::copy_if(saveDirs.begin(), saveDirs.end(), std::back_inserter(autosaves), [&](const std::string &save) + { return save.substr(0, autosavePrefix.length()) == autosavePrefix; }); From 19cc25f7164aafe4576075afb935c985fe9f9a53 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 10 Jul 2016 20:12:44 +0200 Subject: [PATCH 125/125] Fixed sound channels not being unmuted properly --- src/sound/oalsound/alsound.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index cfa335d1..020bfbae 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -356,6 +356,7 @@ int CALSound::Play(SoundType sound, const Math::Vector &pos, float amplitude, fl chn->SetFrequency(frequency); chn->SetVolume(powf(amplitude * chn->GetVolumeAtrib(), 0.2f) * m_audioVolume); chn->SetLoop(loop); + chn->Mute(false); if (!chn->Play()) {