Ejemplo n.º 1
0
 inline var falling_factorial(const double& a,
                              const var& b) {
   return var(new falling_factorial_dv_vari(a, b.vi_));
 }
Ejemplo n.º 2
0
			} else {
				NDebugOverlay::Line(begin, end, 0xff, 0x00, 0x00, true, 10.0f);
			}
			
			
			// ...
		}
		
		return result;
	}
	
	
	class CMod : public IMod
	{
	public:
		CMod() : IMod("Visualize:Melee_Range")
		{
			MOD_ADD_DETOUR_MEMBER(CTFWeaponBaseMelee_DoSwingTraceInternal, "CTFWeaponBaseMelee::DoSwingTraceInternal");
		}
	};
	CMod s_Mod;
	
	
	ConVar cvar_enable("sig_visualize_melee_range", "0", FCVAR_NOTIFY,
		"Visualization: melee range and bounds",
		[](IConVar *pConVar, const char *pOldValue, float flOldValue) {
			ConVarRef var(pConVar);
			s_Mod.Toggle(var.GetBool());
		});
}
Ejemplo n.º 3
0
    void desugar(AST *&ast_)
    {
        if (auto *ast = dynamic_cast<Apply*>(ast_)) {
                
            desugar(ast->target);
            for (AST *&arg : ast->arguments)
                desugar(arg);

        } else if (auto *ast = dynamic_cast<Array*>(ast_)) {
            for (AST *&el : ast->elements)
                desugar(el);

        } else if (auto *ast = dynamic_cast<ArrayComprehension*>(ast_)) {
            for (ComprehensionSpec &spec : ast->specs)
                desugar(spec.expr);
            desugar(ast->body);

            int n = ast->specs.size();
            AST *zero = make<LiteralNumber>(E, 0.0);
            AST *one = make<LiteralNumber>(E, 1.0);
            auto *_r = id(U"$r");
            auto *_l = id(U"$l");
            std::vector<const Identifier*> _i(n);
            for (int i = 0; i < n ; ++i) {
                StringStream ss;
                ss << U"$i_" << i;
                _i[i] = id(ss.str());
            }
            std::vector<const Identifier*> _aux(n);
            for (int i = 0; i < n ; ++i) {
                StringStream ss;
                ss << U"$aux_" << i;
                _aux[i] = id(ss.str());
            }

            // Build it from the inside out.  We keep wrapping 'in' with more ASTs.
            assert(ast->specs[0].kind == ComprehensionSpec::FOR);

            int last_for = n - 1;
            while (ast->specs[last_for].kind != ComprehensionSpec::FOR)
                last_for--;
            // $aux_{last_for}($i_{last_for} + 1, $r + [body])
            AST *in = make<Apply>(
                ast->body->location,
                var(_aux[last_for]),
                std::vector<AST*> {
                    make<Binary>(E, var(_i[last_for]), BOP_PLUS, one),
                    make<Binary>(E, var(_r), BOP_PLUS, singleton(ast->body))
                },
                true  // tailstrict
            );
            for (int i = n - 1; i >= 0 ; --i) {
                const ComprehensionSpec &spec = ast->specs[i];
                AST *out;
                if (i > 0) {
                    int prev_for = i - 1;
                    while (ast->specs[prev_for].kind != ComprehensionSpec::FOR)
                        prev_for--;

                    // aux_{prev_for}($i_{prev_for} + 1, $r)
                    out = make<Apply>(  // False branch.
                        E,
                        var(_aux[prev_for]), 
                        std::vector<AST*> {
                            make<Binary>(E, var(_i[prev_for]), BOP_PLUS, one), var(_r)},
                        true  // tailstrict
                    );
                } else {
                    out = var(_r);
                }
                switch (spec.kind) {
                    case ComprehensionSpec::IF: {
                        /*
                            if [[[...cond...]]] then
                                [[[...in...]]]
                            else
                                [[[...out...]]]
                        */
                        in = make<Conditional>(
                            ast->location,
                            spec.expr,
                            in,  // True branch.
                            out);  // False branch.
                    } break;
                    case ComprehensionSpec::FOR: {
                        /*
                            local $l = [[[...array...]]];
                            local aux_{i}(i_{i}, r) =
                                if i_{i} >= std.length(l) then
                                    [[[...out...]]]
                                else
                                    local [[[...var...]]] = l[i_{i}];
                                    [[[...in...]]]
                            aux_{i}(0, r) tailstrict;
                        */
                        in = make<Local>(
                            ast->location,
                            Local::Binds {
                                {_l, spec.expr},
                                {_aux[i], make<Function>(
                                    ast->location,
                                    std::vector<const Identifier*>{_i[i], _r},
                                    make<Conditional>(
                                        ast->location, 
                                        make<Binary>(
                                            E, var(_i[i]), BOP_GREATER_EQ, length(var(_l))),
                                        out,
                                        make<Local>(
                                            ast->location,
                                            Local::Binds {{
                                                spec.var,
                                                make<Index>(E, var(_l), var(_i[i]))
                                            }},
                                            in)
                                    )
                                )}},
                                make<Apply>(
                                    E,
                                    var(_aux[i]),
                                    std::vector<AST*> {
                                        zero,
                                        i == 0 ? make<Array>(E, std::vector<AST*>{})
                                               : static_cast<AST*>(var(_r))
                                    },
                                    true));  // tailstrict
                    } break;
                }
            }
                    
            ast_ = in;

        } else if (auto *ast = dynamic_cast<Binary*>(ast_)) {
            desugar(ast->left);
            desugar(ast->right);

        } else if (dynamic_cast<const BuiltinFunction*>(ast_)) {
            // Nothing to do.

        } else if (auto *ast = dynamic_cast<Conditional*>(ast_)) {
            desugar(ast->cond);
            desugar(ast->branchTrue);
            desugar(ast->branchFalse);

        } else if (auto *ast = dynamic_cast<Error*>(ast_)) {
            desugar(ast->expr);

        } else if (auto *ast = dynamic_cast<Function*>(ast_)) {
            desugar(ast->body);

        } else if (dynamic_cast<const Import*>(ast_)) {
            // Nothing to do.

        } else if (dynamic_cast<const Importstr*>(ast_)) {
            // Nothing to do.

        } else if (auto *ast = dynamic_cast<Index*>(ast_)) {
            desugar(ast->target);
            desugar(ast->index);

        } else if (auto *ast = dynamic_cast<Local*>(ast_)) {
            for (auto &bind: ast->binds)
                desugar(bind.second);
            desugar(ast->body);

        } else if (dynamic_cast<const LiteralBoolean*>(ast_)) {
            // Nothing to do.

        } else if (dynamic_cast<const LiteralNumber*>(ast_)) {
            // Nothing to do.

        } else if (dynamic_cast<const LiteralString*>(ast_)) {
            // Nothing to do.

        } else if (dynamic_cast<const LiteralNull*>(ast_)) {
            // Nothing to do.

        } else if (auto *ast = dynamic_cast<Object*>(ast_)) {
            for (auto &assert : ast->asserts) {
                desugar(assert);
            }
            for (auto &field : ast->fields) {
                desugar(field.name);
                desugar(field.body);
            }

        } else if (auto *ast = dynamic_cast<ObjectComprehension*>(ast_)) {
            for (ComprehensionSpec &spec : ast->specs)
                desugar(spec.expr);
            desugar(ast->field);
            desugar(ast->value);

            /*  {
                    [arr[0]]: local x = arr[1], y = arr[2], z = arr[3]; val_expr
                    for arr in [ [key_expr, x, y, z] for ...  ]
                }
            */
            auto *_arr = id(U"$arr");
            AST *zero = make<LiteralNumber>(E, 0.0);
            int counter = 1;
            Local::Binds binds;
            auto arr_e = std::vector<AST*> {ast->field};
            for (ComprehensionSpec &spec : ast->specs) {
                if (spec.kind == ComprehensionSpec::FOR) {
                    binds[spec.var] =
                        make<Index>(E, var(_arr), make<LiteralNumber>(E, double(counter++)));
                    arr_e.push_back(var(spec.var));
                }
            }
            AST *arr = make<ArrayComprehension>(
                ast->location,
                make<Array>(ast->location, arr_e),
                ast->specs);
            desugar(arr);
            ast_ = make<ObjectComprehensionSimple>(
                ast->location,
                make<Index>(E, var(_arr), zero),
                make<Local>(
                    ast->location,
                    binds,
                    ast->value),
                _arr,
                arr);

        } else if (auto *ast = dynamic_cast<ObjectComprehensionSimple*>(ast_)) {
            desugar(ast->field);
            desugar(ast->value);
            desugar(ast->array);

        } else if (dynamic_cast<const Self*>(ast_)) {
            // Nothing to do.

        } else if (dynamic_cast<const Super*>(ast_)) {
            // Nothing to do.

        } else if (auto *ast = dynamic_cast<Unary*>(ast_)) {
            desugar(ast->expr);

        } else if (dynamic_cast<const Var*>(ast_)) {
            // Nothing to do.

        } else {
            std::cerr << "INTERNAL ERROR: Unknown AST: " << ast_ << std::endl;
            std::abort();

        }
    }
Ejemplo n.º 4
0
void PHPSourceFile::ParseFunctionSignature(int startingDepth)
{
    phpLexerToken token;
    if(startingDepth == 0) {
        // loop until we find the open brace
        while(NextToken(token)) {
            if(token.type == '(') {
                ++startingDepth;
                break;
            }
        }
        if(startingDepth == 0) return;
    }

    // at this point the 'depth' is 1, as we already read the open brace
    int depth = 1;
    wxString typeHint;
    wxString defaultValue;
    PHPEntityVariable* var(NULL);
    bool collectingDefaultValue = false;
    while(NextToken(token)) {
        switch(token.type) {
        case kPHP_T_VARIABLE:
            if(!var) {
                // var can be non null if we are parsing PHP-7 function arguments
                // with type-hinting
                var = new PHPEntityVariable();
            }

            var->SetFullName(token.text);
            var->SetLine(token.lineNumber);
            var->SetFilename(m_filename);
            // Mark this variable as function argument
            var->SetFlag(kVar_FunctionArg);
            if(typeHint.EndsWith("&")) {
                var->SetIsReference(true);
                typeHint.RemoveLast();
            }
            var->SetTypeHint(MakeIdentifierAbsolute(typeHint));
            break;
        case '(':
            depth++;
            if(collectingDefaultValue) {
                defaultValue << "(";
            }
            break;
        case ')':
            depth--;
            // if the depth goes under 1 - we are done
            if(depth < 1) {
                if(var) {
                    var->SetDefaultValue(defaultValue);
                    CurrentScope()->AddChild(PHPEntityBase::Ptr_t(var));
                }
                return;

            } else if(depth) {
                defaultValue << token.text;
            }
            break;
        case '=':
            // default value
            collectingDefaultValue = true;
            break;
        case ',':
            if(var) {
                var->SetDefaultValue(defaultValue);
                CurrentScope()->AddChild(PHPEntityBase::Ptr_t(var));
            }
            var = NULL;
            typeHint.Clear();
            defaultValue.Clear();
            collectingDefaultValue = false;
            break;
        case kPHP_T_IDENTIFIER:
            if(!var) {
                // PHP-7 type hinting function arguments
                var = new PHPEntityVariable();
                UngetToken(token);
                typeHint = ReadType();
                if(!typeHint.IsEmpty()) {
                    break;
                }
            }
        // all "else" cases simply fall into the default case
        default:
            if(collectingDefaultValue) {
                defaultValue << token.text;
            } else {
                typeHint << token.text;
            }
            break;
        }
    }
}
Ejemplo n.º 5
0
QByteArray GraphExport::generateBin()
{
    GraphCurve *c = m_curves->at(ui->curveBox->itemData(ui->curveBox->currentIndex()).toInt())->curve;
    Q_ASSERT(c);

    QByteArray bin;
    QBuffer buff(&bin);
    buff.open(QIODevice::WriteOnly);

    bool big = !ui->endianBox->currentIndex();
    int idxW = (1 << ui->idxWidthBox->currentIndex());

    for(quint32 i = 0; i < c->getSize(); ++i)
    {
        emit updateProgress(i*100/c->getSize());

        if(ui->indexBox->isChecked())
        {
            quint64 idx = i;
            Utils::swapEndian(idx);
            if(!big)
                Utils::swapEndian(((char*)&idx)+(sizeof(idx)-idxW), idxW);
            buff.write(((char*)&idx)+(sizeof(idx)-idxW), idxW);
        }

        qreal s = c->sample(i).y();
        switch(c->getDataType())
        {
            case NUM_FLOAT:
            {
                float f = s;
                buff.write((char*)&f, sizeof(f));
                break;
            }
            case NUM_DOUBLE:
                buff.write((char*)&s, sizeof(s));
                break;
            default:
            {
                QVariant var(s);
                switch(c->getDataType())
                {
                    case NUM_UINT8:
                    case NUM_INT8:
                    {
                        quint8 y = var.toInt();
                        if(big) Utils::swapEndian((char*)&y, sizeof(y));
                        buff.write((char*)&y, sizeof(y));
                        break;
                    }
                    case NUM_UINT16:
                    case NUM_INT16:
                    {
                        quint16 y = var.toInt();
                        if(big) Utils::swapEndian((char*)&y, sizeof(y));
                        buff.write((char*)&y, sizeof(y));
                        break;
                    }
                    case NUM_UINT32:
                    case NUM_INT32:
                    {
                        quint32 y = var.toInt();
                        if(big) Utils::swapEndian((char*)&y, sizeof(y));
                        buff.write((char*)&y, sizeof(y));
                        break;
                    }
                    case NUM_UINT64:
                    case NUM_INT64:
                    {
                        quint64 y = var.toLongLong();
                        if(big) Utils::swapEndian((char*)&y, sizeof(y));
                        buff.write((char*)&y, sizeof(y));
                        break;
                    }
                }
                break;
            }
        }
    }
    buff.close();
    return bin;
}
Ejemplo n.º 6
0
void Win32MakefileGenerator::writeStandardParts(QTextStream &t)
{
    t << "####### Compiler, tools and options" << endl << endl;
    t << "CC            = " << var("QMAKE_CC") << endl;
    t << "CXX           = " << var("QMAKE_CXX") << endl;
    t << "DEFINES       = "
      << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ")
      << varGlue("DEFINES","-D"," -D","") << endl;
    t << "CFLAGS        = " << var("QMAKE_CFLAGS") << " $(DEFINES)" << endl;
    t << "CXXFLAGS      = " << var("QMAKE_CXXFLAGS") << " $(DEFINES)" << endl;

    writeIncPart(t);
    writeLibsPart(t);

    t << "QMAKE         = " << var("QMAKE_QMAKE") << endl;
    t << "IDC           = " << (project->isEmpty("QMAKE_IDC") ? QString("idc") :
                              Option::fixPathToTargetOS(var("QMAKE_IDC"), false)) << endl;
    t << "IDL           = " << (project->isEmpty("QMAKE_IDL") ? QString("midl") :
                              Option::fixPathToTargetOS(var("QMAKE_IDL"), false)) << endl;
    t << "ZIP           = " << var("QMAKE_ZIP") << endl;
    t << "DEF_FILE      = " << varList("DEF_FILE") << endl;
    t << "RES_FILE      = " << varList("RES_FILE") << endl; // Not on mingw, can't see why not though...
    t << "COPY          = " << var("QMAKE_COPY") << endl;
    t << "COPY_FILE     = " << var("QMAKE_COPY_FILE") << endl;
    t << "COPY_DIR      = " << var("QMAKE_COPY_DIR") << endl;
    t << "DEL_FILE      = " << var("QMAKE_DEL_FILE") << endl;
    t << "DEL_DIR       = " << var("QMAKE_DEL_DIR") << endl;
    t << "MOVE          = " << var("QMAKE_MOVE") << endl;
    t << "CHK_DIR_EXISTS= " << var("QMAKE_CHK_DIR_EXISTS") << endl;
    t << "MKDIR         = " << var("QMAKE_MKDIR") << endl;
    t << "INSTALL_FILE    = " << var("QMAKE_INSTALL_FILE") << endl;
    t << "INSTALL_PROGRAM = " << var("QMAKE_INSTALL_PROGRAM") << endl;
    t << "INSTALL_DIR     = " << var("QMAKE_INSTALL_DIR") << endl;
    t << endl;

    t << "####### Output directory" << endl << endl;
    if(!project->values("OBJECTS_DIR").isEmpty())
        t << "OBJECTS_DIR   = " << var("OBJECTS_DIR").replace(QRegExp("\\\\$"),"") << endl;
    else
        t << "OBJECTS_DIR   = . " << endl;
    t << endl;

    t << "####### Files" << endl << endl;
    t << "SOURCES       = " << valList(escapeFilePaths(project->values("SOURCES")))
      << " " << valList(escapeFilePaths(project->values("GENERATED_SOURCES"))) << endl;

    // do this here so we can set DEST_TARGET to be the complete path to the final target if it is needed.
    QString orgDestDir = var("DESTDIR");
    QString destDir = Option::fixPathToTargetOS(orgDestDir, false);
    if (!destDir.isEmpty() && (orgDestDir.endsWith('/') || orgDestDir.endsWith(Option::dir_sep)))
        destDir += Option::dir_sep;
    QString target = QString(project->first("TARGET")+project->first("TARGET_EXT"));
    target.remove("\"");
    project->values("DEST_TARGET").prepend(destDir + target);

    writeObjectsPart(t);

    writeExtraCompilerVariables(t);
    writeExtraVariables(t);

    t << "DIST          = " << varList("DISTFILES") << endl;
    t << "QMAKE_TARGET  = " << var("QMAKE_ORIG_TARGET") << endl;
    // The comment is important to maintain variable compatibility with Unix
    // Makefiles, while not interpreting a trailing-slash as a linebreak
    t << "DESTDIR        = " << escapeFilePath(destDir) << " #avoid trailing-slash linebreak" << endl;
    t << "TARGET         = " << escapeFilePath(target) << endl;
    t << "DESTDIR_TARGET = " << escapeFilePath(var("DEST_TARGET")) << endl;
    t << endl;

    t << "####### Implicit rules" << endl << endl;
    writeImplicitRulesPart(t);

    t << "####### Build rules" << endl << endl;
    writeBuildRulesPart(t);

    if(project->isActiveConfig("shared") && !project->values("DLLDESTDIR").isEmpty()) {
        QStringList dlldirs = project->values("DLLDESTDIR");
        for (QStringList::Iterator dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir) {
            t << "\n\t" << "-$(COPY_FILE) \"$(DESTDIR_TARGET)\" " << Option::fixPathToTargetOS(*dlldir, false);
        }
    }
    t << endl << endl;

    writeRcFilePart(t);

    writeMakeQmake(t);

    QStringList dist_files = fileFixify(Option::mkfile::project_files);
    if(!project->isEmpty("QMAKE_INTERNAL_INCLUDED_FILES"))
        dist_files += project->values("QMAKE_INTERNAL_INCLUDED_FILES");
    if(!project->isEmpty("TRANSLATIONS"))
        dist_files << var("TRANSLATIONS");
    if(!project->isEmpty("FORMS")) {
        QStringList &forms = project->values("FORMS");
        for(QStringList::Iterator formit = forms.begin(); formit != forms.end(); ++formit) {
            QString ui_h = fileFixify((*formit) + Option::h_ext.first());
            if(exists(ui_h))
                dist_files << ui_h;
        }
    }
    t << "dist:" << "\n\t"
      << "$(ZIP) " << var("QMAKE_ORIG_TARGET") << ".zip " << "$(SOURCES) $(DIST) "
      << dist_files.join(" ") << " " << var("TRANSLATIONS") << " ";
    if(!project->isEmpty("QMAKE_EXTRA_COMPILERS")) {
        const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
        for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
            const QStringList &inputs = project->values((*it)+".input");
            for(QStringList::ConstIterator input = inputs.begin(); input != inputs.end(); ++input) {
                t << (*input) << " ";
            }
        }
    }
    t << endl << endl;

    writeCleanParts(t);
    writeExtraTargets(t);
    writeExtraCompilerTargets(t);
    t << endl << endl;
}
Ejemplo n.º 7
0
 /**
  * Return the value of a*log(b).
  *
  * When both a and b are 0, the value returned is 0.
  * The partial deriviative with respect to a is log(b).
  * The partial deriviative with respect to b is a/b. When
  * a and b are both 0, this is set to Inf.
  *
  * @param a First variable.
  * @param b Second variable.
  * @return Value of a*log(b)
  */
 inline var multiply_log(const var& a, const var& b) {
   return var(new multiply_log_vv_vari(a.vi_, b.vi_));
 }
Ejemplo n.º 8
0
TEST(Variant, Casts) {
  // Test Resource cast operations
  {
    EXPECT_FALSE(isa<DummyResource>(Variant()));
    EXPECT_TRUE(isa_or_null<DummyResource>(Variant()));
    EXPECT_FALSE(isa<DummyResource>(Variant(true)));
    EXPECT_FALSE(isa_or_null<DummyResource>(Variant(true)));

    auto dummy = req::make<DummyResource>();
    Variant var(dummy);
    Variant empty;
    EXPECT_TRUE(isa<DummyResource>(var));
    EXPECT_TRUE(isa_or_null<DummyResource>(var));

    EXPECT_FALSE(isa<File>(var));
    EXPECT_FALSE(isa_or_null<File>(var));

    // cast tests
    // Bad types and null pointers should throw.
    EXPECT_EQ(cast<DummyResource>(var), dummy);
    EXPECT_EQ(cast<ResourceData>(var), dummy);
    try {
      cast<File>(var);
      EXPECT_FALSE(true);
    } catch(...) {
      EXPECT_TRUE(true);
    }
    try {
      cast<c_Map>(var);
      EXPECT_FALSE(true);
    } catch(...) {
      EXPECT_TRUE(true);
    }
    try {
      cast<DummyResource>(empty);
      EXPECT_FALSE(true);
    } catch(...) {
      EXPECT_TRUE(true);
    }

    // cast_or_null tests
    // Bad types should throw, null pointers are ok.
    EXPECT_EQ(cast_or_null<ResourceData>(empty), nullptr);
    EXPECT_EQ(cast_or_null<ResourceData>(var), dummy);

    try {
      cast_or_null<File>(var);
      EXPECT_FALSE(true);
    } catch(...) {
      EXPECT_TRUE(true);
    }
    try {
      cast_or_null<c_Map>(var);
      EXPECT_FALSE(true);
    } catch(...) {
      EXPECT_TRUE(true);
    }

    // dyn_cast tests
    // Bad types are ok, null pointers should throw.
    EXPECT_EQ(dyn_cast<DummyResource>(var), dummy);
    EXPECT_EQ(dyn_cast<ResourceData>(var), dummy);
    EXPECT_EQ(dyn_cast<File>(var), nullptr);
    EXPECT_EQ(dyn_cast<c_Map>(var), nullptr);
    try {
      dyn_cast<DummyResource>(Variant());
      EXPECT_FALSE(true);
    } catch(...) {
      EXPECT_TRUE(true);
    }

    // dyn_cast_or_null
    // Bad types and null pointers are ok.  Should never throw.
    EXPECT_EQ(dyn_cast_or_null<ResourceData>(empty), nullptr);
    EXPECT_EQ(dyn_cast_or_null<ResourceData>(var), dummy);
    EXPECT_EQ(dyn_cast_or_null<c_Map>(var), nullptr);
  }

  // Test Object cast operations
  {
    EXPECT_FALSE(isa<c_Vector>(Variant()));
    EXPECT_TRUE(isa_or_null<c_Vector>(Variant()));
    EXPECT_FALSE(isa<c_Vector>(Variant(true)));
    EXPECT_FALSE(isa_or_null<c_Vector>(Variant(true)));

    auto dummy = req::make<c_Vector>();
    Variant var(dummy);
    Variant empty;
    EXPECT_TRUE(isa<c_Vector>(var));
    EXPECT_TRUE(isa_or_null<c_Vector>(var));

    EXPECT_FALSE(isa<c_Map>(var));
    EXPECT_FALSE(isa_or_null<c_Map>(var));

    // cast tests
    // Bad types and null pointers should throw.
    EXPECT_EQ(cast<c_Vector>(var), dummy);
    EXPECT_EQ(cast<ObjectData>(var), dummy);
    try {
      cast<c_Map>(var);
      EXPECT_FALSE(true);
    } catch(...) {
      EXPECT_TRUE(true);
    }
    try {
      cast<c_Vector>(empty);
      EXPECT_FALSE(true);
    } catch(...) {
      EXPECT_TRUE(true);
    }
    try {
      cast<File>(empty);
      EXPECT_FALSE(true);
    } catch(...) {
      EXPECT_TRUE(true);
    }

    // cast_or_null tests
    // Bad types should throw, null pointers are ok.
    EXPECT_EQ(cast_or_null<c_Vector>(empty), nullptr);
    EXPECT_EQ(cast_or_null<c_Vector>(var), dummy);

    try {
      cast_or_null<File>(var);
      EXPECT_FALSE(true);
    } catch(...) {
      EXPECT_TRUE(true);
    }
    try {
      cast_or_null<c_Map>(var);
      EXPECT_FALSE(true);
    } catch(...) {
      EXPECT_TRUE(true);
    }

    // dyn_cast tests
    // Bad types are ok, null pointers should throw.
    EXPECT_EQ(dyn_cast<c_Vector>(var), dummy);
    EXPECT_EQ(dyn_cast<ObjectData>(var), dummy);
    EXPECT_EQ(dyn_cast<c_Map>(var), nullptr);
    EXPECT_EQ(dyn_cast<File>(var), nullptr);
    try {
      dyn_cast<c_Vector>(empty);
      EXPECT_FALSE(true);
    } catch(...) {
      EXPECT_TRUE(true);
    }

    // dyn_cast_or_null
    // Bad types and null pointers are ok.  Should never throw.
    EXPECT_EQ(dyn_cast_or_null<c_Map>(empty), nullptr);
    EXPECT_EQ(dyn_cast_or_null<c_Vector>(var), dummy);
    EXPECT_EQ(dyn_cast_or_null<c_Map>(var), nullptr);
  }
}
Ejemplo n.º 9
0
void DynamicObject::setMethod (const Identifier& name,
                               var::MethodFunction methodFunction)
{
    properties.set (name, var (methodFunction));
}
Ejemplo n.º 10
0
 /**
  * The Owen's T function of h and a.
  *
  * Used to compute the cumulative density function for the skew normal
  * distribution.
  *
  * @param h double parameter.
  * @param a var parameter.
  * @return The Owen's T function.
  */
 inline var owens_t(double h, const var& a) {
   return var(new owens_t_dv_vari(h, a.vi_));
 }
Ejemplo n.º 11
0
void LC::CalcBelief (size_t i) {
    _beliefs[i] = _pancakes[i].marginal(var(i));
}
Ejemplo n.º 12
0
 /**
  * The Owen's T function of h and a.
  *
  * Used to compute the cumulative density function for the skew normal
  * distribution.
  *
  * @param h var parameter.
  * @param a double parameter.
  * @return The Owen's T function.
  */
 inline var owens_t(const var& h, double a) {
   return var(new owens_t_vd_vari(h.vi_, a));
 }
Ejemplo n.º 13
0
 /**
  * The Owen's T function of h and a.
  *
  * Used to compute the cumulative density function for the skew normal
  * distribution.
  *
  * @param h var parameter.
  * @param a var parameter.
  * @return The Owen's T function.
  */
 inline var owens_t(const var& h, const var& a) {
   return var(new owens_t_vv_vari(h.vi_, a.vi_));
 }
Ejemplo n.º 14
0
namespace Mod_Sniper_Charge_Uncap
{
#if defined _LINUX
	
	constexpr uint8_t s_Buf[] = {
		0xf3, 0x0f, 0x10, 0x45, 0x00,                   // +0000  movss xmm0,DWORD PTR [ebp-0xXX]
		0xf3, 0x0f, 0x58, 0x45, 0x00,                   // +0005  addss xmm0,DWORD PTR [ebp-0xXX]
		0xf3, 0x0f, 0x10, 0xc8,                         // +000A  movss xmm1,xmm0
		0x0f, 0x28, 0xc1,                               // +000E  movaps xmm0,xmm1
		0x0f, 0x57, 0xc9,                               // +0011  xorps xmm1,xmm1
		0xf3, 0x0f, 0x5f, 0xc1,                         // +0014  maxss xmm0,xmm1
		0xf3, 0x0f, 0x5d, 0x05, 0x00, 0x00, 0x00, 0x00, // +0018  minss xmm0,DWORD PTR [XXXXXXXX]
		0xf3, 0x0f, 0x11, 0x45, 0x00,                   // +0020  movss DWORD PTR [ebp-0xXX],xmm0
		0xf3, 0x0f, 0x59, 0x40, 0x10,                   // +0025  mulss xmm0,DWORD PTR [eax+0x10]
	};
	
	struct CPatch_UncapChargeRate_Common : public CPatch
	{
		CPatch_UncapChargeRate_Common() : CPatch(sizeof(s_Buf)) {}
		
		virtual bool GetVerifyInfo(ByteBuf& buf, ByteBuf& mask) const override
		{
			buf.CopyFrom(s_Buf);
			
			mask.SetRange(0x05 + 4, 1, 0x00);
			mask.SetRange(0x00 + 4, 1, 0x00);
			mask.SetRange(0x18 + 4, 4, 0x00);
			mask.SetRange(0x20 + 4, 1, 0x00);
			
			return true;
		}
		
		virtual bool GetPatchInfo(ByteBuf& buf, ByteBuf& mask) const override
		{
			/* NOP out the MINSS instruction */
			buf.SetRange(0x18, 8, 0x90);
			mask.SetRange(0x18, 8, 0xff);
			
			return true;
		}
	};
	
	struct CPatch_UncapChargeRate_CTFSniperRifle : public CPatch_UncapChargeRate_Common
	{
		virtual const char *GetFuncName() const override { return "CTFSniperRifle::ItemPostFrame"; }
		virtual uint32_t GetFuncOffMin() const override  { return 0x0000; }
		virtual uint32_t GetFuncOffMax() const override  { return 0x0380; } // @ 0x026a
	};
	
	struct CPatch_UncapChargeRate_CTFSniperRifleClassic : CPatch_UncapChargeRate_Common
	{
		virtual const char *GetFuncName() const override { return "CTFSniperRifleClassic::ItemPostFrame"; }
		virtual uint32_t GetFuncOffMin() const override  { return 0x0000; }
		virtual uint32_t GetFuncOffMax() const override  { return 0x0280; } // @ 0x0146
	};
	
#elif defined _WINDOWS
	
	constexpr uint8_t s_Buf[] = {
		0xa1, 0x00, 0x00, 0x00, 0x00,                   // +0000  mov eax,DWORD PTR [xxxxxxxx]
		0xf3, 0x0f, 0x10, 0x05, 0x00, 0x00, 0x00, 0x00, // +0005  movss xmm0,DWORD PTR [xxxxxxxx]
		0xf3, 0x0f, 0x10, 0x50, 0x10,                   // +000D  movss xmm2,DWORD PTR [eax+0x10]
		0xd9, 0x5d, 0x00,                               // +0012  fstp [ebp-0xXX]
		0xf3, 0x0f, 0x10, 0x4d, 0x00,                   // +0015  movss xmm1,[ebp-0xXX]
		0xf3, 0x0f, 0x5f, 0xc8,                         // +001A  maxss xmm1,xmm0
		0xf3, 0x0f, 0x10, 0x05, 0x00, 0x00, 0x00, 0x00, // +001E  movss xmm0,DWORD PTR [xxxxxxxx]
		0xf3, 0x0f, 0x5d, 0xc8,                         // +0026  minss xmm1,xmm0
		0xf3, 0x0f, 0x10, 0x05, 0x00, 0x00, 0x00, 0x00, // +002A  movss xmm0,DWORD PTR [xxxxxxxx]
	};
	
	struct CPatch_UncapChargeRate_Common : public CPatch
	{
		CPatch_UncapChargeRate_Common() : CPatch(sizeof(s_Buf)) {}
		
		virtual bool GetVerifyInfo(ByteBuf& buf, ByteBuf& mask) const override
		{
			buf.CopyFrom(s_Buf);
			
			mask.SetRange(0x00 + 1, 4, 0x00);
			mask.SetRange(0x05 + 4, 4, 0x00);
			mask.SetRange(0x12 + 2, 1, 0x00);
			mask.SetRange(0x15 + 4, 1, 0x00);
			mask.SetRange(0x1e + 4, 4, 0x00);
			mask.SetRange(0x2a + 4, 4, 0x00);
			
			return true;
		}
		
		virtual bool GetPatchInfo(ByteBuf& buf, ByteBuf& mask) const override
		{
			/* NOP out the MINSS instruction */
			buf.SetRange(0x26, 4, 0x90);
			mask.SetRange(0x26, 4, 0xff);
			
			return true;
		}
	};
	
	struct CPatch_UncapChargeRate_CTFSniperRifle : public CPatch_UncapChargeRate_Common
	{
		virtual const char *GetFuncName() const override { return "CTFSniperRifle::ItemPostFrame"; }
		virtual uint32_t GetFuncOffMin() const override  { return 0x0000; }
		virtual uint32_t GetFuncOffMax() const override  { return 0x0200; } // @ 0x16e
	};
	
	struct CPatch_UncapChargeRate_CTFSniperRifleClassic : CPatch_UncapChargeRate_Common
	{
		virtual const char *GetFuncName() const override { return "CTFSniperRifleClassic::ItemPostFrame"; }
		virtual uint32_t GetFuncOffMin() const override  { return 0x0000; }
		virtual uint32_t GetFuncOffMax() const override  { return 0x0200; } // @ 0x162
	};
	
#endif
	
	
	class CMod : public IMod
	{
	public:
		CMod() : IMod("Sniper:Charge_Uncap")
		{
			this->AddPatch(new CPatch_UncapChargeRate_CTFSniperRifle());
			this->AddPatch(new CPatch_UncapChargeRate_CTFSniperRifleClassic());
		}
	};
	CMod s_Mod;
	
	
	ConVar cvar_enable("sig_sniper_charge_uncap", "0", FCVAR_NOTIFY,
		"Mod: remove the 200 percent upper limit on sniper rifle charge rate",
		[](IConVar *pConVar, const char *pOldValue, float flOldValue) {
			ConVarRef var(pConVar);
			s_Mod.Toggle(var.GetBool());
		});
}
Ejemplo n.º 15
0
namespace Mod_Robot_Building_Stomp
{
	RefCount rc_CTFBotMainAction_OnContact;
	RefCount rc_CTFBotMainAction_OnStuck;
	
	CTFBot *bot_contact = nullptr;
	CTFBot *bot_stuck   = nullptr;
	
	DETOUR_DECL_MEMBER(EventDesiredResult<CTFBot>, CTFBotMainAction_OnContact, CTFBot *actor, CBaseEntity *ent, CGameTrace *trace)
	{
		SCOPED_INCREMENT(rc_CTFBotMainAction_OnContact);
		bot_contact = actor;
		return DETOUR_MEMBER_CALL(CTFBotMainAction_OnContact)(actor, ent, trace);
	}
	
	DETOUR_DECL_MEMBER(EventDesiredResult<CTFBot>, CTFBotMainAction_OnStuck, CTFBot *actor)
	{
		SCOPED_INCREMENT(rc_CTFBotMainAction_OnStuck);
		bot_stuck = actor;
		return DETOUR_MEMBER_CALL(CTFBotMainAction_OnStuck)(actor);
	}
	
	
	// CTFBotMainAction::OnContact: giant bots instant stomp
	// CTFBotMainAction::OnStuck:   all   bots delayed stomp
	
	
	ConVar cvar_contact_nodamage("sig_robot_building_stomp_contact_nodamage", "1", FCVAR_NOTIFY,
		"OnContact stomp (instant, giants only): prevent damage from being done");
	ConVar cvar_contact_addknown("sig_robot_building_stomp_contact_addknown", "1", FCVAR_NOTIFY,
		"OnContact stomp (instant, giants only): make robot immediately aware of building");
	
	ConVar cvar_stuck_nodamage("sig_robot_building_stomp_stuck_nodamage", "1", FCVAR_NOTIFY,
		"OnStuck stomp   (delayed, all robots):  prevent damage from being done");
	ConVar cvar_stuck_addknown("sig_robot_building_stomp_stuck_addknown", "1", FCVAR_NOTIFY,
		"OnStuck stomp   (delayed, all robots):  make robot immediately aware of building");
	
	
	void AddKnownToBot(CTFBot *bot, CBaseEntity *ent)
	{
		IVision *vision = bot->GetVisionInterface();
		
		if (vision->GetKnown(ent) == nullptr) {
			vision->AddKnownEntity(ent);
		}
	}
	
	
	DETOUR_DECL_MEMBER(int, CBaseEntity_TakeDamage, const CTakeDamageInfo& info)
	{
		auto ent = reinterpret_cast<CBaseEntity *>(this);
		
		if (ent->IsBaseObject() && info.GetDamageType() == DMG_BLAST && info.GetDamageCustom() == TF_DMG_CUSTOM_NONE) {
			if (rc_CTFBotMainAction_OnContact > 0 && bot_contact != nullptr && info.GetInflictor() == bot_contact && info.GetAttacker() == bot_contact) {
				if (cvar_contact_addknown.GetBool()) {
					AddKnownToBot(bot_contact, ent);
				}
				
				if (cvar_contact_nodamage.GetBool()) {
					DevMsg("Preventing damage due to giant-robot-vs-building instant stomp from CTFBotMainAction::OnContact\n");
					return 0;
				}
			}
			
			if (rc_CTFBotMainAction_OnStuck > 0 && bot_stuck != nullptr && info.GetInflictor() == bot_stuck && info.GetAttacker() == bot_stuck) {
				if (cvar_stuck_addknown.GetBool()) {
					AddKnownToBot(bot_stuck, ent);
				}
				
				if (cvar_stuck_nodamage.GetBool()) {
					DevMsg("Preventing damage due to robot-vs-building delayed stomp from CTFBotMainAction::OnStuck\n");
					return 0;
				}
			}
		}
		
		return DETOUR_MEMBER_CALL(CBaseEntity_TakeDamage)(info);
	}
	
	
	class CMod : public IMod
	{
	public:
		CMod() : IMod("Robot:Building_Stomp")
		{
			MOD_ADD_DETOUR_MEMBER(CTFBotMainAction_OnContact, "CTFBotMainAction::OnContact");
			MOD_ADD_DETOUR_MEMBER(CTFBotMainAction_OnStuck,   "CTFBotMainAction::OnStuck");
			
			MOD_ADD_DETOUR_MEMBER(CBaseEntity_TakeDamage, "CBaseEntity::TakeDamage");
		}
	};
	CMod s_Mod;
	
	
	ConVar cvar_enable("sig_robot_building_stomp", "0", FCVAR_NOTIFY,
		"Mod: replace robots' stuck-with-building-stomp ability with something less stupid",
		[](IConVar *pConVar, const char *pOldValue, float flOldValue) {
			ConVarRef var(pConVar);
			s_Mod.Toggle(var.GetBool());
		});
	
	
	// TODO:
	// add a priority boost for entities that have been responsible for recent
	// OnContact or OnStuck events of the bot
}
Ejemplo n.º 16
0
 inline var log_determinant_spd(const Eigen::Matrix<var,R,C>& m) {
   stan::math::validate_square(m,"log_determinant_spd");
   return var(new log_determinant_spd_vari<R,C>(m));
 }
Ejemplo n.º 17
0
void Win32MakefileGenerator::writeCleanParts(QTextStream &t)
{
    t << "clean: compiler_clean " << var("CLEAN_DEPS");
    {
        const char *clean_targets[] = { "OBJECTS", "QMAKE_CLEAN", "CLEAN_FILES", 0 };
        for(int i = 0; clean_targets[i]; ++i) {
            const QStringList &list = project->values(clean_targets[i]);
            const QString del_statement("-$(DEL_FILE)");
            if(project->isActiveConfig("no_delete_multiple_files")) {
                for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it)
                    t << "\n\t" << del_statement << " " << escapeFilePath((*it));
            } else {
                QString files, file;
                const int commandlineLimit = 2047; // NT limit, expanded
                for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
                    file = " " + escapeFilePath((*it));
                    if(del_statement.length() + files.length() +
                       qMax(fixEnvVariables(file).length(), file.length()) > commandlineLimit) {
                        t << "\n\t" << del_statement << files;
                        files.clear();
                    }
                    files += file;
                }
                if(!files.isEmpty())
                    t << "\n\t" << del_statement << files;
            }
        }
    }
    t << endl << endl;

    t << "distclean: clean";
    {
        const char *clean_targets[] = { "QMAKE_DISTCLEAN", 0 };
        for(int i = 0; clean_targets[i]; ++i) {
            const QStringList &list = project->values(clean_targets[i]);
            const QString del_statement("-$(DEL_FILE)");
            if(project->isActiveConfig("no_delete_multiple_files")) {
                for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it)
                    t << "\n\t" << del_statement << " " << escapeFilePath((*it));
            } else {
                QString files, file;
                const int commandlineLimit = 2047; // NT limit, expanded
                for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
                    file = " " + escapeFilePath((*it));
                    if(del_statement.length() + files.length() +
                       qMax(fixEnvVariables(file).length(), file.length()) > commandlineLimit) {
                        t << "\n\t" << del_statement << files;
                        files.clear();
                    }
                    files += file;
                }
                if(!files.isEmpty())
                    t << "\n\t" << del_statement << files;
            }
        }
    }
    t << "\n\t-$(DEL_FILE) $(DESTDIR_TARGET)" << endl;
    {
        QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.fileName()));
        if(!ofile.isEmpty())
            t << "\t-$(DEL_FILE) " << ofile << endl;
    }
    t << endl;
}
Ejemplo n.º 18
0
void MingwMakefileGenerator::init()
{
    if(init_flag)
        return;
    init_flag = true;

    /* this should probably not be here, but I'm using it to wrap the .t files */
    if(project->first("TEMPLATE") == "app")
        project->values("QMAKE_APP_FLAG").append("1");
    else if(project->first("TEMPLATE") == "lib")
        project->values("QMAKE_LIB_FLAG").append("1");
    else if(project->first("TEMPLATE") == "subdirs") {
        MakefileGenerator::init();
        if(project->isEmpty("QMAKE_COPY_FILE"))
            project->values("QMAKE_COPY_FILE").append("$(COPY)");
        if(project->isEmpty("QMAKE_COPY_DIR"))
            project->values("QMAKE_COPY_DIR").append("xcopy /s /q /y /i");
        if(project->isEmpty("QMAKE_INSTALL_FILE"))
            project->values("QMAKE_INSTALL_FILE").append("$(COPY_FILE)");
        if(project->isEmpty("QMAKE_INSTALL_PROGRAM"))
            project->values("QMAKE_INSTALL_PROGRAM").append("$(COPY_FILE)");
        if(project->isEmpty("QMAKE_INSTALL_DIR"))
            project->values("QMAKE_INSTALL_DIR").append("$(COPY_DIR)");
        if(project->values("MAKEFILE").isEmpty())
            project->values("MAKEFILE").append("Makefile");
        return;
    }

    project->values("TARGET_PRL").append(project->first("TARGET"));

    processVars();

    if (!project->values("RES_FILE").isEmpty()) {
        project->values("QMAKE_LIBS") += escapeFilePaths(project->values("RES_FILE"));
    }

    // LIBS defined in Profile comes first for gcc
    project->values("QMAKE_LIBS") += escapeFilePaths(project->values("LIBS"));
    project->values("QMAKE_LIBS_PRIVATE") += escapeFilePaths(project->values("LIBS_PRIVATE"));

    QString targetfilename = project->values("TARGET").first();
    QStringList &configs = project->values("CONFIG");

    if(project->isActiveConfig("qt_dll"))
        if(configs.indexOf("qt") == -1)
            configs.append("qt");

    if(project->isActiveConfig("dll") && project->values("QMAKE_SYMBIAN_SHLIB").isEmpty()) {
        QString destDir = "";
        if(!project->first("DESTDIR").isEmpty())
            destDir = Option::fixPathToTargetOS(project->first("DESTDIR") + Option::dir_sep, false, false);
        project->values("MINGW_IMPORT_LIB").prepend(destDir + "lib" + project->first("TARGET")
                                                         + project->first("TARGET_VERSION_EXT") + ".a");
	project->values("QMAKE_LFLAGS").append(QString("-Wl,--out-implib,") + project->first("MINGW_IMPORT_LIB"));
    }

    if(!project->values("DEF_FILE").isEmpty() && project->values("QMAKE_SYMBIAN_SHLIB").isEmpty())
        project->values("QMAKE_LFLAGS").append(QString("-Wl,") + project->first("DEF_FILE"));

    MakefileGenerator::init();

    // precomp
    if (!project->first("PRECOMPILED_HEADER").isEmpty()
        && project->isActiveConfig("precompile_header")) {
        QString preCompHeader = var("PRECOMPILED_DIR")
		         + QFileInfo(project->first("PRECOMPILED_HEADER")).fileName();
	preCompHeaderOut = preCompHeader + ".gch";
	project->values("QMAKE_CLEAN").append(preCompHeaderOut + Option::dir_sep + "c");
	project->values("QMAKE_CLEAN").append(preCompHeaderOut + Option::dir_sep + "c++");

	project->values("QMAKE_RUN_CC").clear();
	project->values("QMAKE_RUN_CC").append("$(CC) -c -include " + preCompHeader +
                                                    " $(CFLAGS) $(INCPATH) -o $obj $src");
        project->values("QMAKE_RUN_CC_IMP").clear();
	project->values("QMAKE_RUN_CC_IMP").append("$(CC)  -c -include " + preCompHeader +
                                                        " $(CFLAGS) $(INCPATH) -o $@ $<");
        project->values("QMAKE_RUN_CXX").clear();
	project->values("QMAKE_RUN_CXX").append("$(CXX) -c -include " + preCompHeader +
                                                     " $(CXXFLAGS) $(INCPATH) -o $obj $src");
        project->values("QMAKE_RUN_CXX_IMP").clear();
	project->values("QMAKE_RUN_CXX_IMP").append("$(CXX) -c -include " + preCompHeader +
                                                         " $(CXXFLAGS) $(INCPATH) -o $@ $<");
    }

    if(project->isActiveConfig("dll")) {
        project->values("QMAKE_CLEAN").append(project->first("MINGW_IMPORT_LIB"));
    }
}
Ejemplo n.º 19
0
 /**
  * Return the value of a*log(b).
  *
  * When both a and b are 0, the value returned is 0.
  * The partial deriviative with respect to b is a/b. When
  * a and b are both 0, this is set to Inf.
  *
  * @param a First scalar.
  * @param b Second variable.
  * @return Value of a*log(b)
  */
 inline var multiply_log(const double a, const var& b) {
   if (a == 1.0)
     return log(b);
   return var(new multiply_log_dv_vari(a, b.vi_));
 }
Ejemplo n.º 20
0
void MingwMakefileGenerator::writeObjectsPart(QTextStream &t)
{
    if (project->values("OBJECTS").count() < var("QMAKE_LINK_OBJECT_MAX").toInt()) {
        objectsLinkLine = "$(OBJECTS)";
    } else if (project->isActiveConfig("staticlib") && project->first("TEMPLATE") == "lib") {
	QString ar_script_file = var("QMAKE_LINK_OBJECT_SCRIPT") + "." + var("TARGET");
	if (!var("BUILD_NAME").isEmpty()) {
	    ar_script_file += "." + var("BUILD_NAME");
	}
        // QMAKE_LIB is used for win32, including mingw, whereas QMAKE_AR is used on Unix.
        if (project->isActiveConfig("rvct_linker")) {
            createRvctObjectScriptFile(ar_script_file, project->values("OBJECTS"));
            QString ar_cmd = project->values("QMAKE_LIB").join(" ");
            if (ar_cmd.isEmpty())
                ar_cmd = "armar --create";
            objectsLinkLine = ar_cmd + " " + var("DEST_TARGET") + " --via " + ar_script_file;
        } else {
            // Strip off any options since the ar commands will be read from file.
            QString ar_cmd = var("QMAKE_LIB").section(" ", 0, 0);;
            if (ar_cmd.isEmpty())
                ar_cmd = "ar";
            createArObjectScriptFile(ar_script_file, var("DEST_TARGET"), project->values("OBJECTS"));
            objectsLinkLine = ar_cmd + " -M < " + ar_script_file;
        }
    } else {
        QString ld_script_file = var("QMAKE_LINK_OBJECT_SCRIPT") + "." + var("TARGET");
	if (!var("BUILD_NAME").isEmpty()) {
	    ld_script_file += "." + var("BUILD_NAME");
	}
        if (project->isActiveConfig("rvct_linker")) {
            createRvctObjectScriptFile(ld_script_file, project->values("OBJECTS"));
            objectsLinkLine = QString::fromLatin1("--via ") + ld_script_file;
        } else {
            createLdObjectScriptFile(ld_script_file, project->values("OBJECTS"));
            objectsLinkLine = ld_script_file;
        }
    }
    Win32MakefileGenerator::writeObjectsPart(t);
}
Ejemplo n.º 21
0
 /**
  * Return the value of a*log(b).
  *
  * When both a and b are 0, the value returned is 0.
  * The partial deriviative with respect to a is log(b).
  *
  * @param a First variable.
  * @param b Second scalar.
  * @return Value of a*log(b)
  */
 inline var multiply_log(const var& a, const double b) {
   return var(new multiply_log_vd_vari(a.vi_, b));
 }
Ejemplo n.º 22
0
 void removeAllProperties (UndoManager* const undoManager)
 {
     if (undoManager == nullptr)
     {
         while (properties.size() > 0)
         {
             const Identifier name (properties.getName (properties.size() - 1));
             properties.remove (name);
             sendPropertyChangeMessage (name);
         }
     }
     else
     {
         for (int i = properties.size(); --i >= 0;)
             undoManager->perform (new SetPropertyAction (this, properties.getName(i), var(),
                                                          properties.getValueAt(i), false, true));
     }
 }
Ejemplo n.º 23
0
void PHPSourceFile::ParseFunctionBody()
{
    m_lookBackTokens.clear();

    // when we reach the current depth-1 -> leave
    int exitDepth = m_depth - 1;
    phpLexerToken token;
    PHPEntityBase::Ptr_t var(NULL);
    while(NextToken(token)) {
        switch(token.type) {
        case '{':
            m_lookBackTokens.clear();
            break;
        case '}':
            m_lookBackTokens.clear();
            if(m_depth == exitDepth) {
                return;
            }
            break;
        case ';':
            m_lookBackTokens.clear();
            break;
        case kPHP_T_CATCH:
            OnCatch();
            break;
        case kPHP_T_VARIABLE: {
            var.Reset(new PHPEntityVariable());
            var->SetFullName(token.text);
            var->SetFilename(m_filename.GetFullPath());
            var->SetLine(token.lineNumber);
            CurrentScope()->AddChild(var);

            // Peek at the next token
            if(!NextToken(token)) return; // EOF
            if(token.type != '=') {
                m_lookBackTokens.clear();
                var.Reset(NULL);
                UngetToken(token);

            } else {

                wxString expr;
                if(!ReadExpression(expr)) return; // EOF

                // Optimize 'new ClassName(..)' expression
                if(expr.StartsWith("new")) {
                    expr = expr.Mid(3);
                    expr.Trim().Trim(false);
                    expr = expr.BeforeFirst('(');
                    expr.Trim().Trim(false);
                    var->Cast<PHPEntityVariable>()->SetTypeHint(MakeIdentifierAbsolute(expr));

                } else {
                    // keep the expression
                    var->Cast<PHPEntityVariable>()->SetExpressionHint(expr);
                }
            }
        } break;
        default:
            break;
        }
    }
}
Ejemplo n.º 24
0
void init_arrays(
		 Search_settings *sett, 
		 Command_line_opts *opts,
		 Aux_arrays *aux_arr
		 ) {

  int i, status; 
  // Allocates and initializes to zero the data, detector ephemeris
  // and the F-statistic arrays

  FILE *data;

  for(i=0; i<sett->nifo; i++) { 

    ifo[i].sig.xDat = (double *) calloc(sett->N, sizeof(double));
    
    // Input time-domain data handling
    // 
    // The file name ifo[i].xdatname is constructed 
    // in settings.c, while looking for the detector 
    // subdirectories
    
    if((data = fopen(ifo[i].xdatname, "r")) != NULL) {
      status = fread((void *)(ifo[i].sig.xDat), 
		     sizeof(double), sett->N, data);
      fclose (data);
      
    } else {
      perror (ifo[i].xdatname);
      exit(EXIT_FAILURE); 
    }
    
    int j, Nzeros=0;
    // Checking for null values in the data
    for(j=0; j < sett->N; j++)
      if(!ifo[i].sig.xDat[j]) Nzeros++;
    
    ifo[i].sig.Nzeros = Nzeros; 
    
    // factor N/(N - Nzeros) to account for null values in the data
    ifo[i].sig.crf0 = (double)sett->N/(sett->N - ifo[i].sig.Nzeros);

    // Estimation of the variance for each detector 
    ifo[i].sig.sig2 = (ifo[i].sig.crf0)*var(ifo[i].sig.xDat, sett->N);

    ifo[i].sig.DetSSB = (double *) calloc(3*sett->N, sizeof(double));
    /* 
    const size_t array_bytes = 3*sett->N*sizeof(double);
    ifo[i].sig.DetSSB = NULL;
    if ( posix_memalign((void**)&ifo[i].sig.DetSSB, 32, array_bytes) ) exit (1);
    */

    // Ephemeris file handling
    char filename[512];
    sprintf (filename, "%s/%03d/%s/DetSSB.bin", 
        opts->dtaprefix, opts->ident, ifo[i].name);

    if((data = fopen(filename, "r")) != NULL) {
      // Detector position w.r.t Solar System Baricenter
      // for every datapoint
      status = fread((void *)(ifo[i].sig.DetSSB), 
               sizeof(double), 3*sett->N, data);

      // Deterministic phase defining the position of the Earth
      // in its diurnal motion at t=0 
      status = fread((void *)(&ifo[i].sig.phir), 
               sizeof(double), 1, data);

      // Earth's axis inclination to the ecliptic at t=0
      status = fread((void *)(&ifo[i].sig.epsm), 
               sizeof(double), 1, data);
      fclose (data);

      printf("Using %s as detector %s ephemerids...\n", filename, ifo[i].name);

    } else {
      perror (filename);
      return ;
    }

    // sincos 
    ifo[i].sig.sphir = sin(ifo[i].sig.phir);
    ifo[i].sig.cphir = cos(ifo[i].sig.phir);
    ifo[i].sig.sepsm = sin(ifo[i].sig.epsm);
    ifo[i].sig.cepsm = cos(ifo[i].sig.epsm);

    sett->sepsm = ifo[i].sig.sepsm; 
    sett->cepsm = ifo[i].sig.cepsm; 

    //    ifo[i].sig.xDatma = (complex double *) calloc(sett->N, sizeof(complex double));
    //ifo[i].sig.xDatmb = (complex double *) calloc(sett->N, sizeof(complex double));
    ifo[i].sig.xDatma = fftw_malloc(sett->N*sizeof(complex double));
    ifo[i].sig.xDatmb = fftw_malloc(sett->N*sizeof(complex double));

    ifo[i].sig.aa = (double *) calloc(sett->N, sizeof(double));
    ifo[i].sig.bb = (double *) calloc(sett->N, sizeof(double));

    ifo[i].sig.shft = (double *) calloc(sett->N, sizeof(double));
    ifo[i].sig.shftf = (double *) calloc(sett->N, sizeof(double));
 
  } // end loop for detectors 

  // Check if the ephemerids have the same epsm parameter
  for(i=1; i<sett->nifo; i++) {  
    if(!(ifo[i-1].sig.sepsm == ifo[i].sig.sepsm)) { 
      printf("The parameter epsm (DetSSB.bin) differs for detectors %s and %s. Aborting...\n", ifo[i-1].name, ifo[i].name); 
      exit(EXIT_FAILURE);
    } 

  } 

  // if all is well with epsm, take the first value 
  sett->sepsm = ifo[0].sig.sepsm;
  sett->cepsm = ifo[0].sig.cepsm;
  
  // Auxiliary arrays, Earth's rotation
  aux_arr->t2 = (double *) calloc(sett->N, sizeof (double));
  aux_arr->cosmodf = (double *) calloc(sett->N, sizeof (double));
  aux_arr->sinmodf = (double *) calloc(sett->N, sizeof (double));
  double omrt;

  for (i=0; i<sett->N; i++) {
    omrt = (sett->omr)*i;     // Earth angular velocity * dt * i
    aux_arr->t2[i] = sqr((double)i);
    aux_arr->cosmodf[i] = cos(omrt);
    aux_arr->sinmodf[i] = sin(omrt);
  }
  
} // end of init arrays 
Ejemplo n.º 25
0
//-----------------------------------------------------------------------------
// Purpose: Advanced joystick setup
//-----------------------------------------------------------------------------
void CInput::Joystick_Advanced(void)
{
	// called whenever an update is needed
	int	i;
	DWORD dwTemp;

	if ( IsX360() )
	{
		// Xbox always uses a joystick
		in_joystick.SetValue( 1 );
	}

	// Initialize all the maps
	for ( i = 0; i < MAX_JOYSTICK_AXES; i++ )
	{
		m_rgAxes[i].AxisMap = GAME_AXIS_NONE;
		m_rgAxes[i].ControlMap = JOY_ABSOLUTE_AXIS;
	}

	if ( !joy_advanced.GetBool() )
	{
		// default joystick initialization
		// 2 axes only with joystick control
		m_rgAxes[JOY_AXIS_X].AxisMap = GAME_AXIS_YAW;
		m_rgAxes[JOY_AXIS_Y].AxisMap = GAME_AXIS_FORWARD;
	}
	else
	{
		if ( Q_stricmp( joy_name.GetString(), "joystick") != 0 )
		{
			// notify user of advanced controller
			Msg( "Using joystick '%s' configuration\n", joy_name.GetString() );
		}

		// advanced initialization here
		// data supplied by user via joy_axisn cvars
		dwTemp = ( joy_movement_stick.GetBool() ) ? (DWORD)joy_advaxisu.GetInt() : (DWORD)joy_advaxisx.GetInt();
		m_rgAxes[JOY_AXIS_X].AxisMap = dwTemp & 0x0000000f;
		m_rgAxes[JOY_AXIS_X].ControlMap = dwTemp & JOY_RELATIVE_AXIS;

		DescribeJoystickAxis( "JOY_AXIS_X", &m_rgAxes[JOY_AXIS_X] );

		dwTemp = ( joy_movement_stick.GetBool() ) ? (DWORD)joy_advaxisr.GetInt() : (DWORD)joy_advaxisy.GetInt();
		m_rgAxes[JOY_AXIS_Y].AxisMap = dwTemp & 0x0000000f;
		m_rgAxes[JOY_AXIS_Y].ControlMap = dwTemp & JOY_RELATIVE_AXIS;

		DescribeJoystickAxis( "JOY_AXIS_Y", &m_rgAxes[JOY_AXIS_Y] );

		dwTemp = (DWORD)joy_advaxisz.GetInt();
		m_rgAxes[JOY_AXIS_Z].AxisMap = dwTemp & 0x0000000f;
		m_rgAxes[JOY_AXIS_Z].ControlMap = dwTemp & JOY_RELATIVE_AXIS;

		DescribeJoystickAxis( "JOY_AXIS_Z", &m_rgAxes[JOY_AXIS_Z] );

		dwTemp = ( joy_movement_stick.GetBool() ) ? (DWORD)joy_advaxisy.GetInt() : (DWORD)joy_advaxisr.GetInt();
		m_rgAxes[JOY_AXIS_R].AxisMap = dwTemp & 0x0000000f;
		m_rgAxes[JOY_AXIS_R].ControlMap = dwTemp & JOY_RELATIVE_AXIS;

		DescribeJoystickAxis( "JOY_AXIS_R", &m_rgAxes[JOY_AXIS_R] );

		dwTemp = ( joy_movement_stick.GetBool() ) ? (DWORD)joy_advaxisx.GetInt() : (DWORD)joy_advaxisu.GetInt();
		m_rgAxes[JOY_AXIS_U].AxisMap = dwTemp & 0x0000000f;
		m_rgAxes[JOY_AXIS_U].ControlMap = dwTemp & JOY_RELATIVE_AXIS;

		DescribeJoystickAxis( "JOY_AXIS_U", &m_rgAxes[JOY_AXIS_U] );

		dwTemp = (DWORD)joy_advaxisv.GetInt();
		m_rgAxes[JOY_AXIS_V].AxisMap = dwTemp & 0x0000000f;
		m_rgAxes[JOY_AXIS_V].ControlMap = dwTemp & JOY_RELATIVE_AXIS;

		DescribeJoystickAxis( "JOY_AXIS_V", &m_rgAxes[JOY_AXIS_V] );

		Msg( "Advanced Joystick settings initialized\n" );
	}

	// If we have an xcontroller, load the cfg file if it hasn't been loaded.
	ConVarRef var( "joy_xcontroller_found" );
	if ( var.IsValid() && var.GetBool() && in_joystick.GetBool() )
	{
		if ( joy_xcontroller_cfg_loaded.GetBool() == false )
		{
			engine->ClientCmd( "exec 360controller.cfg" );
			joy_xcontroller_cfg_loaded.SetValue( 1 );
		}
	}
	else if ( joy_xcontroller_cfg_loaded.GetBool() )
	{
		engine->ClientCmd( "exec undo360controller.cfg" );
		joy_xcontroller_cfg_loaded.SetValue( 0 );
	}
}
Ejemplo n.º 26
0
CFSWString asWStr(std::string const& s) {
    CFSVar var(s.c_str());
    CFSWString ws = var.GetWString();
    return ws;
}
Ejemplo n.º 27
0
namespace Mod_AI_RocketJump
{
	/* base class */
	class CTFBotRocketJump : public IHotplugAction
	{
	protected:
		CTFBotRocketJump() {}
		
		virtual QueryResponse ShouldHurry(const INextBot *nextbot) const override
		{
			return QueryResponse::YES;
		}
		
		virtual QueryResponse ShouldRetreat(const INextBot *nextbot) const override
		{
			return QueryResponse::NO;
		}
		
		virtual QueryResponse ShouldAttack(const INextBot *nextbot, const CKnownEntity *threat) const override
		{
			return QueryResponse::NO;
		}
		
		
		virtual EventDesiredResult<CTFBot> OnLeaveGround(CTFBot *actor, CBaseEntity *ent) override
		{
			DevMsg("[%8.3f] %s(#%d): OnLeaveGround(#%d)\n", gpGlobals->curtime, this->GetName(), ENTINDEX(actor), ENTINDEX(ent));
			return EventDesiredResult<CTFBot>::Continue();
		}
		virtual EventDesiredResult<CTFBot> OnLandOnGround(CTFBot *actor, CBaseEntity *ent) override
		{
			DevMsg("[%8.3f] %s(#%d): OnLandOnGround(#%d)\n", gpGlobals->curtime, this->GetName(), ENTINDEX(actor), ENTINDEX(ent));
			return EventDesiredResult<CTFBot>::Continue();
		}
		
//		virtual EventDesiredResult<CTFBot> OnContact(CTFBot *actor, CBaseEntity *ent, CGameTrace *trace) override
//		{
//			DevMsg("[%8.3f] %s(#%d): OnContact(#%d)\n", gpGlobals->curtime, this->GetName(), ENTINDEX(actor), ENTINDEX(ent));
//			return EventDesiredResult<CTFBot>::Continue();
//		}
		
		virtual EventDesiredResult<CTFBot> OnPostureChanged(CTFBot *actor) override
		{
			DevMsg("[%8.3f] %s(#%d): OnPostureChanged\n", gpGlobals->curtime, this->GetName(), ENTINDEX(actor));
			return EventDesiredResult<CTFBot>::Continue();
		}
		virtual EventDesiredResult<CTFBot> OnAnimationActivityComplete(CTFBot *actor, int i1) override
		{
			DevMsg("[%8.3f] %s(#%d): OnAnimationActivityComplete(%d)\n", gpGlobals->curtime, this->GetName(), ENTINDEX(actor), i1);
			return EventDesiredResult<CTFBot>::Continue();
		}
		virtual EventDesiredResult<CTFBot> OnAnimationActivityInterrupted(CTFBot *actor, int i1) override
		{
			DevMsg("[%8.3f] %s(#%d): OnAnimationActivityInterrupted(%d)\n", gpGlobals->curtime, this->GetName(), ENTINDEX(actor), i1);
			return EventDesiredResult<CTFBot>::Continue();
		}
		virtual EventDesiredResult<CTFBot> OnAnimationEvent(CTFBot *actor, animevent_t *a1) override
		{
			DevMsg("[%8.3f] %s(#%d): OnAnimationEvent(...)\n", gpGlobals->curtime, this->GetName(), ENTINDEX(actor));
			return EventDesiredResult<CTFBot>::Continue();
		}
		
		virtual EventDesiredResult<CTFBot> OnInjured(CTFBot *actor, const CTakeDamageInfo& info) override
		{
			DevMsg("[%8.3f] %s(#%d): OnInjured(...)\n", gpGlobals->curtime, this->GetName(), ENTINDEX(actor));
			return EventDesiredResult<CTFBot>::Continue();
		}
		
		virtual EventDesiredResult<CTFBot> OnSpokeConcept(CTFBot *actor, CBaseCombatCharacter *who, const char *s1, AI_Response *response) override
		{
			DevMsg("[%8.3f] %s(#%d): OnSpokeConcept(#%d, \"%s\", ...)\n", gpGlobals->curtime, this->GetName(), ENTINDEX(actor), ENTINDEX(who), s1);
			return EventDesiredResult<CTFBot>::Continue();
		}
		virtual EventDesiredResult<CTFBot> OnWeaponFired(CTFBot *actor, CBaseCombatCharacter *who, CBaseCombatWeapon *weapon) override
		{
			DevMsg("[%8.3f] %s(#%d): OnWeaponFired(#%d, #%d)\n", gpGlobals->curtime, this->GetName(), ENTINDEX(actor), ENTINDEX(who), ENTINDEX(weapon));
			return EventDesiredResult<CTFBot>::Continue();
		}
		
		virtual EventDesiredResult<CTFBot> OnActorEmoted(CTFBot *actor, CBaseCombatCharacter *who, int concept) override
		{
			DevMsg("[%8.3f] %s(#%d): OnActorEmoted(#%d, %d)\n", gpGlobals->curtime, this->GetName(), ENTINDEX(actor), ENTINDEX(who), concept);
			return EventDesiredResult<CTFBot>::Continue();
		}
	};
	
	
	/* wait for commands */
	class CTFBotRocketJump_Wait : public CTFBotRocketJump
	{
	public:
		virtual const char *GetName() const override { return "RocketJump_Wait"; }
		
		virtual ActionResult<CTFBot> Update(CTFBot *actor, float dt) override;
		
		virtual EventDesiredResult<CTFBot> OnActorEmoted(CTFBot *actor, CBaseCombatCharacter *who, int concept) override;
		virtual EventDesiredResult<CTFBot> OnCommandString(CTFBot *actor, const char *cmd) override;
		
	private:
		CountdownTimer m_ctRespond;
	};
	
	
	/* do a vertical jump */
	class CTFBotRocketJump_JumpVertical : public CTFBotRocketJump
	{
	public:
		virtual const char *GetName() const override { return "RocketJump_JumpVertical"; }
		
		virtual ActionResult<CTFBot> OnStart(CTFBot *actor, Action<CTFBot> *action) override;
		virtual ActionResult<CTFBot> Update(CTFBot *actor, float dt) override;
		virtual void OnEnd(CTFBot *actor, Action<CTFBot> *action) override;
		
	private:
		IntervalTimer m_itTimeout;
	};
	
	
	inline ActionResult<CTFBot> CTFBotRocketJump_Wait::Update(CTFBot *actor, float dt)
	{
		if (this->m_ctRespond.HasStarted() && this->m_ctRespond.IsElapsed()) {
			this->m_ctRespond.Invalidate();
			actor->SpeakConceptIfAllowed(MP_CONCEPT_PLAYER_YES);
			return ActionResult<CTFBot>::SuspendFor(new CTFBotRocketJump_JumpVertical(), "Doing a vertical jump");
		}
		
		return ActionResult<CTFBot>::Continue();
	}
	
	inline EventDesiredResult<CTFBot> CTFBotRocketJump_Wait::OnActorEmoted(CTFBot *actor, CBaseCombatCharacter *who, int concept)
	{
		CTFPlayer *player = ToTFPlayer(who);
		if (player != nullptr && !player->IsBot() && concept == MP_CONCEPT_PLAYER_GO) {
			if (!this->m_ctRespond.HasStarted()) {
				this->m_ctRespond.Start(0.6f);
			}
			
		//	actor->SpeakConceptIfAllowed(MP_CONCEPT_PLAYER_YES);
		//	return EventDesiredResult<CTFBot>::SuspendFor(new CTFBotRocketJump_JumpVertical(), "Doing a vertical jump");
		}
		
		return EventDesiredResult<CTFBot>::Continue();
	}
	
	inline EventDesiredResult<CTFBot> CTFBotRocketJump_Wait::OnCommandString(CTFBot *actor, const char *cmd)
	{
		if (V_stricmp(cmd, "JumpVertical") == 0) {
			return EventDesiredResult<CTFBot>::SuspendFor(new CTFBotRocketJump_JumpVertical(), "Doing a vertical jump");
		}
		
		return EventDesiredResult<CTFBot>::Continue();
	}
	
	
	inline ActionResult<CTFBot> CTFBotRocketJump_JumpVertical::OnStart(CTFBot *actor, Action<CTFBot> *action)
	{
		constexpr float duration = 1.0f;
		
		Vector vecAim = actor->EyePosition() + Vector(0.0f, 0.0f, -100.0f);
		actor->GetBodyInterface()->AimHeadTowards(vecAim, IBody::LookAtPriorityType::OVERRIDE_ALL, duration, nullptr, "Aiming downward for a rocket jump");
		
		this->m_itTimeout.Start();
		
		return ActionResult<CTFBot>::Continue();
	}
	
	inline ActionResult<CTFBot> CTFBotRocketJump_JumpVertical::Update(CTFBot *actor, float dt)
	{
		Vector vecEyes;
		actor->EyeVectors(&vecEyes);
		
		Vector vecDown(0.0f, 0.0f, -1.0f);
		
		constexpr float tolerance = cos(5_deg);
		bool is_aiming_down	= (DotProduct(vecEyes, vecDown) >= tolerance);
		
		if (is_aiming_down) {
			const QAngle& eyeang = actor->EyeAngles();
			DevMsg("*** EyeAngles:  [ %f %f %f ]\n", eyeang.x, eyeang.y, eyeang.z);
			DevMsg("*** EyeVectors: [ %f %f %f ]\n", vecEyes.x, vecEyes.y, vecEyes.z);
			
			actor->PressJumpButton(0.1f);
			actor->PressCrouchButton(3.0f);
			actor->PressFireButton();
			return ActionResult<CTFBot>::Done("Jumped successfully");
		}
		
		if (this->m_itTimeout.IsGreaterThen(1.0f)) {
			return ActionResult<CTFBot>::Done("Timed out");
		}
		
		return ActionResult<CTFBot>::Continue();
	}
	
	inline void CTFBotRocketJump_JumpVertical::OnEnd(CTFBot *actor, Action<CTFBot> *action)
	{
		
	}
	
	
	DETOUR_DECL_MEMBER(Action<CTFBot> *, CTFBotScenarioMonitor_DesiredScenarioAndClassAction, CTFBot *actor)
	{
		return new CTFBotRocketJump_Wait();
	}
	
	
	/* disable the faulty underground detection logic, which warps bots back to
	 * their last nav area if airborne for more than 3 seconds */
	RefCount rc_CTFBotMainAction_Update;
	DETOUR_DECL_MEMBER(ActionResult<CTFBot>, CTFBotMainAction_Update, CTFBot *actor, float dt)
	{
		constexpr int OFF_CTFBotMainAction_m_itUnderground = 0x70;
		auto m_itUnderground = (IntervalTimer *)((uintptr_t)this + OFF_CTFBotMainAction_m_itUnderground);
		
		m_itUnderground->Reset();
		
		return DETOUR_MEMBER_CALL(CTFBotMainAction_Update)(actor, dt);
	}
	
	
	RefCount rc_CTFPlayer_ApplyPushFromDamage;
	const CTakeDamageInfo *dmginfo = nullptr;
	DETOUR_DECL_MEMBER(void, CTFPlayer_ApplyPushFromDamage, const CTakeDamageInfo& info, Vector vec)
	{
		dmginfo = &info;
		SCOPED_INCREMENT(rc_CTFPlayer_ApplyPushFromDamage);
		DETOUR_MEMBER_CALL(CTFPlayer_ApplyPushFromDamage)(info, vec);
	}
	
	DETOUR_DECL_MEMBER(void, CTFPlayer_ApplyAbsVelocityImpulse, const Vector& impulse)
	{
		if (rc_CTFPlayer_ApplyPushFromDamage > 0) {
			auto player = reinterpret_cast<CTFPlayer *>(this);
			if (player->IsBot()) {
				if (dmginfo->GetAttacker() == player) {
					float magnitude = impulse.Length();
					
					QAngle angles;
					VectorAngles(impulse, angles);
					
					DevMsg("IMPULSE: mag %.1f, dir [ %.1f %.1f %.1f ]\n",
						magnitude, angles.x, angles.y, angles.z);
					
					constexpr float duration = 3.0f;
					char buf[1024];
					
					NDebugOverlay::VertArrow(player->GetAbsOrigin(), player->GetAbsOrigin() + impulse,
						5.0f, 0x00, 0xff, 0x00, 0xff, false, duration);
					
					snprintf(buf, sizeof(buf), "Mag: %.1f", magnitude);
					NDebugOverlay::EntityTextAtPosition(player->GetAbsOrigin(), 0,
						buf, duration, 0xff, 0xff, 0xff, 0xff);
					
					snprintf(buf, sizeof(buf), "Dir: [ %.1f %.1f %.1f ]", angles.x, angles.y, angles.z);
					NDebugOverlay::EntityTextAtPosition(player->GetAbsOrigin(), 1,
						buf, duration, 0xff, 0xff, 0xff, 0xff);
				}
			}
		}
		
		DETOUR_MEMBER_CALL(CTFPlayer_ApplyAbsVelocityImpulse)(impulse);
	}
	
	
	class CMod : public IMod
	{
	public:
		CMod() : IMod("AI:RocketJump")
		{
			MOD_ADD_DETOUR_MEMBER(CTFBotScenarioMonitor_DesiredScenarioAndClassAction, "CTFBotScenarioMonitor::DesiredScenarioAndClassAction");
			
			MOD_ADD_DETOUR_MEMBER(CTFBotMainAction_Update, "CTFBotMainAction::Update");
			
			// TODO: draw vector of rocket start-to-end positions
			// TODO: draw vector of explosion position to bot origin
			//MOD_ADD_DETOUR_MEMBER()
			
			MOD_ADD_DETOUR_MEMBER(CTFPlayer_ApplyPushFromDamage,     "CTFPlayer::ApplyPushFromDamage");
			MOD_ADD_DETOUR_MEMBER(CTFPlayer_ApplyAbsVelocityImpulse, "CTFPlayer::ApplyAbsVelocityImpulse");
		}
	};
	CMod s_Mod;
	
	
	ConVar cvar_enable("sig_ai_rocketjump", "0", FCVAR_NOTIFY,
		"Mod: bot AI for rocket jumping",
		[](IConVar *pConVar, const char *pOldValue, float flOldValue) {
			ConVarRef var(pConVar);
			s_Mod.Toggle(var.GetBool());
		});
}
Ejemplo n.º 28
0
std::string asString(CFSWString const& ws) {
    CFSVar var(ws);
    return std::string(var.GetAString());
}
Ejemplo n.º 29
0
    void canFindMatchingBracketsNeedsOpen() const {
        givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");

        const Token* t = var.tokens()->findClosingBracket();
        ASSERT(t == nullptr);
    }
Ejemplo n.º 30
0
 inline var falling_factorial(const var& a,
                              const var& b) {
   return var(new falling_factorial_vv_vari(a.vi_, b.vi_));
 }