<commit_before>/*
 * Copyright © 2012 Intel Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Benjamin Segovia <benjamin.segovia@intel.com>
 */

/**
 * \file gen_context.hpp
 * \author Benjamin Segovia <benjamin.segovia@intel.com>
 */

#ifndef __GBE_GEN_CONTEXT_HPP__
#define __GBE_GEN_CONTEXT_HPP__

#include "backend/context.hpp"
#include "backend/program.h"
#include "backend/gen_register.hpp"
#include "ir/function.hpp"
#include "ir/liveness.hpp"
#include "sys/map.hpp"
#include <string>

namespace gbe
{
  class Kernel;               // We build this structure
  class GenEncoder;           // Helps emitting Gen ISA
  class GenRegAllocator;      // Handle the register allocation
  class Selection;            // Performs instruction selection
  class SelectionInstruction; // Pre-RA Gen instruction
  class SelectionReg;         // Pre-RA Gen register
  class GenRegister;
  typedef enum {
    NO_ERROR,
    REGISTER_ALLOCATION_FAIL,
    REGISTER_SPILL_EXCEED_THRESHOLD,
    REGISTER_SPILL_FAIL,
    OUT_OF_RANGE_IF_ENDIF,
  } CompileErrorCode;

  /*! Context is the helper structure to build the Gen ISA or simulation code
   *  from GenIR
   */
  class GenContext : public Context
  {
  public:
    /*! Create a new context. name is the name of the function we want to
     *  compile
     */
    GenContext(const ir::Unit &unit, const std::string &name, uint32_t deviceID, bool relaxMath = false);
    /*! Release everything needed */
    ~GenContext(void);
    /*! Start new code generation with specific parameters */
    void startNewCG(uint32_t simdWidth, uint32_t reservedSpillRegs, bool limitRegisterPressure);
    /*! Target device ID*/
    uint32_t deviceID;
    /*! Implements base class */
    virtual bool emitCode(void);
    /*! Function we emit code for */
    INLINE const ir::Function &getFunction(void) const { return fn; }
    /*! Simd width chosen for the current function */
    INLINE uint32_t getSimdWidth(void) const { return simdWidth; }
    void clearFlagRegister(void);
    /*! check the flag reg, if is grf, use f0.1 instead */
    GenRegister checkFlagRegister(GenRegister flagReg);
    /*! Emit the per-lane stack pointer computation */
    void emitStackPointer(void);
    /*! Emit the instructions */
    void emitInstructionStream(void);
    /*! Set the correct target values for the branches */
    bool patchBranches(void);
    /*! Forward ir::Function isSpecialReg method */
    INLINE bool isSpecialReg(ir::Register reg) const {
      return fn.isSpecialReg(reg);
    }
    /*! Get the liveOut information for the given block */
    INLINE const ir::Liveness::LiveOut &getLiveOut(const ir::BasicBlock *bb) const {
      return this->liveness->getLiveOut(bb);
    }
    /*! Get the LiveIn information for the given block */
    INLINE const ir::Liveness::UEVar &getLiveIn(const ir::BasicBlock *bb) const {
      return this->liveness->getLiveIn(bb);
    }

    void collectShifter(GenRegister dest, GenRegister src);
    void loadTopHalf(GenRegister dest, GenRegister src);
    void storeTopHalf(GenRegister dest, GenRegister src);

    void loadBottomHalf(GenRegister dest, GenRegister src);
    void storeBottomHalf(GenRegister dest, GenRegister src);

    void addWithCarry(GenRegister dest, GenRegister src0, GenRegister src1);
    void subWithBorrow(GenRegister dest, GenRegister src0, GenRegister src1);
    void I64Neg(GenRegister high, GenRegister low, GenRegister tmp);
    void I64ABS(GenRegister sign, GenRegister high, GenRegister low, GenRegister tmp, GenRegister flagReg);
    void I64FullAdd(GenRegister high1, GenRegister low1, GenRegister high2, GenRegister low2);
    void I32FullMult(GenRegister high, GenRegister low, GenRegister src0, GenRegister src1);
    void I64FullMult(GenRegister dst1, GenRegister dst2, GenRegister dst3, GenRegister dst4, GenRegister x_high, GenRegister x_low, GenRegister y_high, GenRegister y_low);
    void saveFlag(GenRegister dest, int flag, int subFlag);
    void UnsignedI64ToFloat(GenRegister dst, GenRegister high, GenRegister low, GenRegister exp, GenRegister mantissa, GenRegister tmp, GenRegister flag);

    /*! Final Gen ISA emission helper functions */
    void emitLabelInstruction(const SelectionInstruction &insn);
    void emitUnaryInstruction(const SelectionInstruction &insn);
    void emitUnaryWithTempInstruction(const SelectionInstruction &insn);
    void emitBinaryInstruction(const SelectionInstruction &insn);
    void emitBinaryWithTempInstruction(const SelectionInstruction &insn);
    void emitTernaryInstruction(const SelectionInstruction &insn);
    void emitI64MULHIInstruction(const SelectionInstruction &insn);
    void emitI64MADSATInstruction(const SelectionInstruction &insn);
    void emitI64HADDInstruction(const SelectionInstruction &insn);
    void emitI64RHADDInstruction(const SelectionInstruction &insn);
    void emitI64ShiftInstruction(const SelectionInstruction &insn);
    void emitI64CompareInstruction(const SelectionInstruction &insn);
    void emitI64SATADDInstruction(const SelectionInstruction &insn);
    void emitI64SATSUBInstruction(const SelectionInstruction &insn);
    void emitI64ToFloatInstruction(const SelectionInstruction &insn);
    void emitFloatToI64Instruction(const SelectionInstruction &insn);
    void emitCompareInstruction(const SelectionInstruction &insn);
    void emitJumpInstruction(const SelectionInstruction &insn);
    void emitIndirectMoveInstruction(const SelectionInstruction &insn);
    void emitEotInstruction(const SelectionInstruction &insn);
    void emitNoOpInstruction(const SelectionInstruction &insn);
    void emitWaitInstruction(const SelectionInstruction &insn);
    void emitBarrierInstruction(const SelectionInstruction &insn);
    void emitFenceInstruction(const SelectionInstruction &insn);
    void emitMathInstruction(const SelectionInstruction &insn);
    void emitRead64Instruction(const SelectionInstruction &insn);
    void emitWrite64Instruction(const SelectionInstruction &insn);
    void emitUntypedReadInstruction(const SelectionInstruction &insn);
    void emitUntypedWriteInstruction(const SelectionInstruction &insn);
    void emitAtomicInstruction(const SelectionInstruction &insn);
    void emitByteGatherInstruction(const SelectionInstruction &insn);
    void emitByteScatterInstruction(const SelectionInstruction &insn);
    void emitPackByteInstruction(const SelectionInstruction &insn);
    void emitUnpackByteInstruction(const SelectionInstruction &insn);
    void emitDWordGatherInstruction(const SelectionInstruction &insn);
    void emitSampleInstruction(const SelectionInstruction &insn);
    void emitTypedWriteInstruction(const SelectionInstruction &insn);
    void emitSpillRegInstruction(const SelectionInstruction &insn);
    void emitUnSpillRegInstruction(const SelectionInstruction &insn);
    void emitGetImageInfoInstruction(const SelectionInstruction &insn);
    void emitI64MULInstruction(const SelectionInstruction &insn);
    void emitI64DIVREMInstruction(const SelectionInstruction &insn);
    void scratchWrite(const GenRegister header, uint32_t offset, uint32_t reg_num, uint32_t reg_type, uint32_t channel_mode);
    void scratchRead(const GenRegister dst, const GenRegister header, uint32_t offset, uint32_t reg_num, uint32_t reg_type, uint32_t channel_mode);

    /*! Implements base class */
    virtual Kernel *allocateKernel(void);
    /*! Store the position of each label instruction in the Gen ISA stream */
    map<ir::LabelIndex, uint32_t> labelPos;
    typedef struct LabelPair {
      LabelPair(ir::LabelIndex l0, ir::LabelIndex l1) :
                l0(l0), l1(l1){};
      ir::LabelIndex l0;
      ir::LabelIndex l1;
    } LabelPair;
    /*! Store the Gen instructions to patch */
    vector<std::pair<LabelPair, uint32_t>> branchPos3;
    vector<std::pair<ir::LabelIndex, uint32_t>> branchPos2;

    void insertJumpPos(const SelectionInstruction &insn);
    /*! Encode Gen ISA */
    GenEncoder *p;
    /*! Instruction selection on Gen ISA (pre-register allocation) */
    Selection *sel;
    /*! Perform the register allocation */
    GenRegAllocator *ra;
    /*! Indicate if we need to tackle a register pressure issue when
     * regenerating the code
     */
    uint32_t reservedSpillRegs;
    bool limitRegisterPressure;
    bool relaxMath;
    const bool getIFENDIFFix(void) const { return ifEndifFix; }
    void setIFENDIFFix(bool fix) { ifEndifFix = fix; }
    const CompileErrorCode getErrCode() { return errCode; }
  private:
    CompileErrorCode errCode;
    bool ifEndifFix;
    /*! Build the curbe patch list for the given kernel */
    void buildPatchList(void);
    /*! allocate a new curbe register and insert to curbe pool. */
    void allocCurbeReg(ir::Register reg, gbe_curbe_type value, uint32_t subValue = 0);

    friend GenRegAllocator;               //!< need to access errCode directly.

  };

} /* namespace gbe */

#endif /* __GBE_GEN_CONTEXT_HPP__ */

<commit_msg>GBE: Fix one build error of friend declaration for a class.<commit_after>/*
 * Copyright © 2012 Intel Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Benjamin Segovia <benjamin.segovia@intel.com>
 */

/**
 * \file gen_context.hpp
 * \author Benjamin Segovia <benjamin.segovia@intel.com>
 */

#ifndef __GBE_GEN_CONTEXT_HPP__
#define __GBE_GEN_CONTEXT_HPP__

#include "backend/context.hpp"
#include "backend/program.h"
#include "backend/gen_register.hpp"
#include "ir/function.hpp"
#include "ir/liveness.hpp"
#include "sys/map.hpp"
#include <string>

namespace gbe
{
  class Kernel;               // We build this structure
  class GenEncoder;           // Helps emitting Gen ISA
  class GenRegAllocator;      // Handle the register allocation
  class Selection;            // Performs instruction selection
  class SelectionInstruction; // Pre-RA Gen instruction
  class SelectionReg;         // Pre-RA Gen register
  class GenRegister;
  typedef enum {
    NO_ERROR,
    REGISTER_ALLOCATION_FAIL,
    REGISTER_SPILL_EXCEED_THRESHOLD,
    REGISTER_SPILL_FAIL,
    OUT_OF_RANGE_IF_ENDIF,
  } CompileErrorCode;

  /*! Context is the helper structure to build the Gen ISA or simulation code
   *  from GenIR
   */
  class GenContext : public Context
  {
  public:
    /*! Create a new context. name is the name of the function we want to
     *  compile
     */
    GenContext(const ir::Unit &unit, const std::string &name, uint32_t deviceID, bool relaxMath = false);
    /*! Release everything needed */
    ~GenContext(void);
    /*! Start new code generation with specific parameters */
    void startNewCG(uint32_t simdWidth, uint32_t reservedSpillRegs, bool limitRegisterPressure);
    /*! Target device ID*/
    uint32_t deviceID;
    /*! Implements base class */
    virtual bool emitCode(void);
    /*! Function we emit code for */
    INLINE const ir::Function &getFunction(void) const { return fn; }
    /*! Simd width chosen for the current function */
    INLINE uint32_t getSimdWidth(void) const { return simdWidth; }
    void clearFlagRegister(void);
    /*! check the flag reg, if is grf, use f0.1 instead */
    GenRegister checkFlagRegister(GenRegister flagReg);
    /*! Emit the per-lane stack pointer computation */
    void emitStackPointer(void);
    /*! Emit the instructions */
    void emitInstructionStream(void);
    /*! Set the correct target values for the branches */
    bool patchBranches(void);
    /*! Forward ir::Function isSpecialReg method */
    INLINE bool isSpecialReg(ir::Register reg) const {
      return fn.isSpecialReg(reg);
    }
    /*! Get the liveOut information for the given block */
    INLINE const ir::Liveness::LiveOut &getLiveOut(const ir::BasicBlock *bb) const {
      return this->liveness->getLiveOut(bb);
    }
    /*! Get the LiveIn information for the given block */
    INLINE const ir::Liveness::UEVar &getLiveIn(const ir::BasicBlock *bb) const {
      return this->liveness->getLiveIn(bb);
    }

    void collectShifter(GenRegister dest, GenRegister src);
    void loadTopHalf(GenRegister dest, GenRegister src);
    void storeTopHalf(GenRegister dest, GenRegister src);

    void loadBottomHalf(GenRegister dest, GenRegister src);
    void storeBottomHalf(GenRegister dest, GenRegister src);

    void addWithCarry(GenRegister dest, GenRegister src0, GenRegister src1);
    void subWithBorrow(GenRegister dest, GenRegister src0, GenRegister src1);
    void I64Neg(GenRegister high, GenRegister low, GenRegister tmp);
    void I64ABS(GenRegister sign, GenRegister high, GenRegister low, GenRegister tmp, GenRegister flagReg);
    void I64FullAdd(GenRegister high1, GenRegister low1, GenRegister high2, GenRegister low2);
    void I32FullMult(GenRegister high, GenRegister low, GenRegister src0, GenRegister src1);
    void I64FullMult(GenRegister dst1, GenRegister dst2, GenRegister dst3, GenRegister dst4, GenRegister x_high, GenRegister x_low, GenRegister y_high, GenRegister y_low);
    void saveFlag(GenRegister dest, int flag, int subFlag);
    void UnsignedI64ToFloat(GenRegister dst, GenRegister high, GenRegister low, GenRegister exp, GenRegister mantissa, GenRegister tmp, GenRegister flag);

    /*! Final Gen ISA emission helper functions */
    void emitLabelInstruction(const SelectionInstruction &insn);
    void emitUnaryInstruction(const SelectionInstruction &insn);
    void emitUnaryWithTempInstruction(const SelectionInstruction &insn);
    void emitBinaryInstruction(const SelectionInstruction &insn);
    void emitBinaryWithTempInstruction(const SelectionInstruction &insn);
    void emitTernaryInstruction(const SelectionInstruction &insn);
    void emitI64MULHIInstruction(const SelectionInstruction &insn);
    void emitI64MADSATInstruction(const SelectionInstruction &insn);
    void emitI64HADDInstruction(const SelectionInstruction &insn);
    void emitI64RHADDInstruction(const SelectionInstruction &insn);
    void emitI64ShiftInstruction(const SelectionInstruction &insn);
    void emitI64CompareInstruction(const SelectionInstruction &insn);
    void emitI64SATADDInstruction(const SelectionInstruction &insn);
    void emitI64SATSUBInstruction(const SelectionInstruction &insn);
    void emitI64ToFloatInstruction(const SelectionInstruction &insn);
    void emitFloatToI64Instruction(const SelectionInstruction &insn);
    void emitCompareInstruction(const SelectionInstruction &insn);
    void emitJumpInstruction(const SelectionInstruction &insn);
    void emitIndirectMoveInstruction(const SelectionInstruction &insn);
    void emitEotInstruction(const SelectionInstruction &insn);
    void emitNoOpInstruction(const SelectionInstruction &insn);
    void emitWaitInstruction(const SelectionInstruction &insn);
    void emitBarrierInstruction(const SelectionInstruction &insn);
    void emitFenceInstruction(const SelectionInstruction &insn);
    void emitMathInstruction(const SelectionInstruction &insn);
    void emitRead64Instruction(const SelectionInstruction &insn);
    void emitWrite64Instruction(const SelectionInstruction &insn);
    void emitUntypedReadInstruction(const SelectionInstruction &insn);
    void emitUntypedWriteInstruction(const SelectionInstruction &insn);
    void emitAtomicInstruction(const SelectionInstruction &insn);
    void emitByteGatherInstruction(const SelectionInstruction &insn);
    void emitByteScatterInstruction(const SelectionInstruction &insn);
    void emitPackByteInstruction(const SelectionInstruction &insn);
    void emitUnpackByteInstruction(const SelectionInstruction &insn);
    void emitDWordGatherInstruction(const SelectionInstruction &insn);
    void emitSampleInstruction(const SelectionInstruction &insn);
    void emitTypedWriteInstruction(const SelectionInstruction &insn);
    void emitSpillRegInstruction(const SelectionInstruction &insn);
    void emitUnSpillRegInstruction(const SelectionInstruction &insn);
    void emitGetImageInfoInstruction(const SelectionInstruction &insn);
    void emitI64MULInstruction(const SelectionInstruction &insn);
    void emitI64DIVREMInstruction(const SelectionInstruction &insn);
    void scratchWrite(const GenRegister header, uint32_t offset, uint32_t reg_num, uint32_t reg_type, uint32_t channel_mode);
    void scratchRead(const GenRegister dst, const GenRegister header, uint32_t offset, uint32_t reg_num, uint32_t reg_type, uint32_t channel_mode);

    /*! Implements base class */
    virtual Kernel *allocateKernel(void);
    /*! Store the position of each label instruction in the Gen ISA stream */
    map<ir::LabelIndex, uint32_t> labelPos;
    typedef struct LabelPair {
      LabelPair(ir::LabelIndex l0, ir::LabelIndex l1) :
                l0(l0), l1(l1){};
      ir::LabelIndex l0;
      ir::LabelIndex l1;
    } LabelPair;
    /*! Store the Gen instructions to patch */
    vector<std::pair<LabelPair, uint32_t>> branchPos3;
    vector<std::pair<ir::LabelIndex, uint32_t>> branchPos2;

    void insertJumpPos(const SelectionInstruction &insn);
    /*! Encode Gen ISA */
    GenEncoder *p;
    /*! Instruction selection on Gen ISA (pre-register allocation) */
    Selection *sel;
    /*! Perform the register allocation */
    GenRegAllocator *ra;
    /*! Indicate if we need to tackle a register pressure issue when
     * regenerating the code
     */
    uint32_t reservedSpillRegs;
    bool limitRegisterPressure;
    bool relaxMath;
    const bool getIFENDIFFix(void) const { return ifEndifFix; }
    void setIFENDIFFix(bool fix) { ifEndifFix = fix; }
    const CompileErrorCode getErrCode() { return errCode; }
  private:
    CompileErrorCode errCode;
    bool ifEndifFix;
    /*! Build the curbe patch list for the given kernel */
    void buildPatchList(void);
    /*! allocate a new curbe register and insert to curbe pool. */
    void allocCurbeReg(ir::Register reg, gbe_curbe_type value, uint32_t subValue = 0);

    friend class GenRegAllocator;               //!< need to access errCode directly.

  };

} /* namespace gbe */

#endif /* __GBE_GEN_CONTEXT_HPP__ */

<|endoftext|>


<commit_before>#pragma once

#include "Runtime/Collision/CJointCollisionDescription.hpp"
#include "Runtime/Character/CBoneTracking.hpp"
#include "Runtime/Weapon/CProjectileInfo.hpp"
#include "Runtime/World/CPathFindSearch.hpp"
#include "Runtime/World/CPatterned.hpp"

namespace urde {
class CCollisionActorManager;
class CElementGen;
class CParticleElectric;
namespace MP1 {
class CIceSheegothData {
  float x0_;
  float x4_;
  zeus::CVector3f x8_;
  float x14_;
  CDamageVulnerability x18_;
  CDamageVulnerability x80_;
  CDamageVulnerability xe8_;
  CAssetId x150_;
  CDamageInfo x154_;
  float x170_;
  float x174_;
  CAssetId x178_;
  CAssetId x17c_fireBreathResId;
  CDamageInfo x180_fireBreathDamage;
  CAssetId x19c_;
  CAssetId x1a0_;
  CAssetId x1a4_;
  CAssetId x1a8_;
  CAssetId x1ac_;
  float x1b0_;
  float x1b4_;
  CDamageInfo x1b8_;
  s16 x1d4_;
  float x1d8_;
  float x1dc_;
  float x1e0_maxInterestTime;
  CAssetId x1e4_;
  s16 x1e8_;
  CAssetId x1ec_;
  bool x1f0_24_ : 1;
  bool x1f0_25_ : 1;

public:
  CIceSheegothData(CInputStream& in, s32 propertyCount);
  [[nodiscard]] float Get_x0() const { return x0_; }
  [[nodiscard]] float Get_x4() const { return x4_; }
  [[nodiscard]] zeus::CVector3f Get_x8() const { return x8_; }
  [[nodiscard]] float Get_x14() const { return x14_; }
  [[nodiscard]] CDamageVulnerability Get_x18() const { return x18_; }
  [[nodiscard]] CDamageVulnerability Get_x80() const { return x80_; }
  [[nodiscard]] CDamageVulnerability Get_xe8() const { return xe8_; }
  [[nodiscard]] CAssetId Get_x150() const { return x150_; }
  [[nodiscard]] CDamageInfo Get_x154() const { return x154_; }
  [[nodiscard]] float Get_x170() const { return x170_; }
  [[nodiscard]] float Get_x174() const { return x174_; }
  [[nodiscard]] CAssetId Get_x178() const { return x178_; }
  [[nodiscard]] CAssetId GetFireBreathResId() const { return x17c_fireBreathResId; }
  [[nodiscard]] CDamageInfo GetFireBreathDamage() const { return x180_fireBreathDamage; }
  [[nodiscard]] CAssetId Get_x19c() const { return x19c_; }
  [[nodiscard]] CAssetId Get_x1a0() const { return x1a0_; }
  [[nodiscard]] CAssetId Get_x1a4() const { return x1a4_; }
  [[nodiscard]] CAssetId Get_x1a8() const { return x1a8_; }
  [[nodiscard]] CAssetId Get_x1ac() const { return x1ac_; }
  [[nodiscard]] float Get_x1b0() const { return x1b0_; }
  [[nodiscard]] CDamageInfo Get_x1b8() const { return x1b8_; }
  [[nodiscard]] s16 Get_x1d4() const { return x1d4_; }
  [[nodiscard]] float Get_x1d8() const { return x1d8_; }
  [[nodiscard]] float Get_x1dc() const { return x1dc_; }
  [[nodiscard]] float GetMaxInterestTime() const { return x1e0_maxInterestTime; }
  [[nodiscard]] CAssetId Get_x1e4() const { return x1e4_; }
  [[nodiscard]] s16 Get_x1e8() const { return x1e8_; }
  [[nodiscard]] CAssetId Get_x1ec() const { return x1ec_; }
  [[nodiscard]] bool Get_x1f0_24() const { return x1f0_24_; }
  [[nodiscard]] bool Get_x1f0_25() const { return x1f0_25_; }
};

class CIceSheegoth : public CPatterned {
  enum class EPathFindMode { Normal, Approach };
  s32 x568_ = -1;
  CIceSheegothData x56c_sheegothData;
  CPathFindSearch x760_pathSearch;
  CPathFindSearch x844_approachSearch;
  EPathFindMode x928_pathFindMode = EPathFindMode::Normal;
  zeus::CVector3f x92c_lastDest = zeus::skZero3f;
  zeus::CVector3f x938_ = zeus::skZero3f;
  float x944_ = 1.f;
  float x948_ = 1.f;
  float x94c_;
  float x950_ = 0.f;
  float x954_attackTimeLeft = 0.f;
  float x958_ = 0.f;
  float x95c_ = 0.f;
  float x960_ = 0.f;
  /* x964_ */
  float x968_interestTimer = 0.f;
  float x96c_ = 2.f;
  float x970_maxHp = 0.f;
  float x974_;
  float x978_ = 0.f;
  float x97c_ = 0.f;
  zeus::CVector3f x980_ = zeus::skZero3f;
  CDamageVulnerability x98c_mouthVulnerability;
  CBoneTracking x9f4_boneTracking;
  std::unique_ptr<CCollisionActorManager> xa2c_collisionManager;
  CCollidableAABox xa30_;
  CProjectileInfo xa58_;
  TUniqueId xa80_flameThrowerId = kInvalidUniqueId;
  TToken<CWeaponDescription> xa84_;
  TCachedToken<CGenDescription> xa8c_;
  // bool xa98_;
  std::unique_ptr<CElementGen> xa9c_;
  TCachedToken<CGenDescription> xaa0_;
  // bool xaac_;
  std::unique_ptr<CElementGen> xab0_;
  TCachedToken<CGenDescription> xab4_;
  // bool xac0_;
  std::unique_ptr<CElementGen> xac4_;
  TCachedToken<CElectricDescription> xac8_;
  // bool xad4_;
  std::unique_ptr<CParticleElectric> xad8_;
  TCachedToken<CGenDescription> xadc_;
  // bool xae8_;
  std::unique_ptr<CElementGen> xaec_;
  CSfxHandle xaf0_crackleSfx;
  CSegId xaf4_mouthLocator;
  TUniqueId xaf6_iceShardsCollider = kInvalidUniqueId;
  TUniqueId xaf8_mouthCollider = kInvalidUniqueId;
  rstl::reserved_vector<TUniqueId, 2> xafc_gillColliders;
  rstl::reserved_vector<TUniqueId, 10> xb04_;
  rstl::reserved_vector<CSegId, 7> xb1c_;
  bool xb28_24_shotAt : 1 = false;
  bool xb28_25_ : 1 = false;
  bool xb28_26_ : 1 = false;
  bool xb28_27_ : 1 = false;
  bool xb28_28_ : 1 = false;
  bool xb28_29_ : 1 = false;
  bool xb28_30_ : 1 = false;
  bool xb28_31_ : 1 = false;
  bool xb29_24_ : 1 = false;
  bool xb29_25_ : 1 = false;
  bool xb29_26_ : 1 = false;
  bool xb29_27_ : 1 = false;
  bool xb29_28_ : 1 = false;
  bool xb29_29_scanned : 1 = false;

  void UpdateTouchBounds();
  [[nodiscard]] bool IsMouthCollider(TUniqueId uid) const { return xaf8_mouthCollider == uid; }
  [[nodiscard]] bool IsGillCollider(const CEntity* ent) const {
    return std::find_if(xafc_gillColliders.cbegin(), xafc_gillColliders.cend(),
                        [&ent](TUniqueId uid) { return uid == ent->GetUniqueId(); }) != xafc_gillColliders.cend();
  }
  void sub_8019ebf0(CStateManager& mgr, float damage);
  void ApplyWeaponDamage(CStateManager& mgr, TUniqueId sender);
  void CreateFlameThrower(CStateManager& mgr);
  void ApplyContactDamage(TUniqueId sender, CStateManager& mgr);
  void AddSphereCollisionList(const SSphereJointInfo* info, size_t count,
                              std::vector<CJointCollisionDescription>& vecOut);
  void AddCollisionList(const SJointInfo* info, size_t count, std::vector<CJointCollisionDescription>& vecOut);
  void SetupCollisionActorManager(CStateManager& mgr);
  void SetupHealthInfo(CStateManager& mgr);
  void AttractProjectiles(CStateManager& mgr);
  void UpdateTimers(float dt);
  void UpdateScanState(CStateManager& mgr);
  void SetPassthroughVulnerability(CStateManager& mgr);
  void PreventWorldCollisions(float dt, CStateManager& mgr);
  void UpdateHealthInfo(CStateManager& mgr);
  void SetSteeringSpeed(float dt, CStateManager& mgr);
  void SetPathFindMode(EPathFindMode mode) { x928_pathFindMode = mode; }
  void UpdateParticleEffects(float dt, CStateManager& mgr);
  bool sub_801a1794(CStateManager& mgr) const {
    const CHealthInfo* hInfo = GetHealthInfo(mgr);
    return hInfo != nullptr && hInfo->GetHP() < 0.3f * x970_maxHp;
  }

  bool sub_8019ecbc() const { return xb28_27_ || xb29_26_; }
  bool sub_8019ecdc(CStateManager& mgr, float minAngle);
  void SetMouthVulnerability(CStateManager& mgr, bool isVulnerable);
  void SetGillVulnerability(CStateManager& mgr, bool isVulnerable);
  void ShakePlayer(CStateManager& mgr);
  void SetCollisionActorExtendedTouchBounds(CStateManager& mgr, const zeus::CVector3f& extents);

  void UpdateAttackPosition(CStateManager& mgr, zeus::CVector3f& attackPos);
  zeus::CVector3f GetEnergyAttractionPos(CStateManager& mgr) const;
  bool ShouldAttractProjectile(const CGameProjectile& proj, CStateManager& mgr) const;
  bool IsClosestSheegoth(CStateManager& mgr, const rstl::reserved_vector<TUniqueId, 1024>& nearList,
                         const zeus::CVector3f& projectileOffset) const;

public:
  DEFINE_PATTERNED(IceSheeegoth);
  CIceSheegoth(TUniqueId uid, std::string_view name, const CEntityInfo& info, zeus::CTransform& xf, CModelData&& mData,
               const CPatternedInfo& pInfo, const CActorParameters& actorParameters,
               const CIceSheegothData& sheegothData);

  void Accept(IVisitor& visitor) override;
  void Think(float dt, CStateManager& mgr) override;
  void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) override;
  void AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) override;
  [[nodiscard]] const CDamageVulnerability* GetDamageVulnerability() const override {
    return &CDamageVulnerability::PassThroughVulnerabilty();
  }
  [[nodiscard]] const CDamageVulnerability* GetDamageVulnerability(const zeus::CVector3f&, const zeus::CVector3f&,
                                                                   const CDamageInfo&) const override {
    return &CDamageVulnerability::PassThroughVulnerabilty();
  }

  [[nodiscard]] zeus::CVector3f GetAimPosition(const CStateManager& mgr, float dt) const override;
  [[nodiscard]] EWeaponCollisionResponseTypes GetCollisionResponseType(const zeus::CVector3f&, const zeus::CVector3f&,
                                                                       const CWeaponMode&,
                                                                       EProjectileAttrib) const override;
  [[nodiscard]] zeus::CAABox GetSortingBounds(const CStateManager& mgr) const override;
  void DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, EUserEventType type, float dt) override;
  [[nodiscard]] const CCollisionPrimitive* GetCollisionPrimitive() const override { return &xa30_; }
  void PathFind(CStateManager& mgr, EStateMsg msg, float dt) override;
  void TargetPatrol(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Generate(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Deactivate(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Attack(CStateManager& mgr, EStateMsg msg, float dt) override;
  void DoubleSnap(CStateManager& mgr, EStateMsg msg, float dt) override;
  void TurnAround(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Crouch(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Taunt(CStateManager& mgr, EStateMsg msg, float dt) override;
  void ProjectileAttack(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Flinch(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Approach(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Enraged(CStateManager& mgr, EStateMsg msg, float dt) override;
  void SpecialAttack(CStateManager& mgr, EStateMsg msg, float dt) override;
  bool Leash(CStateManager& mgr, float arg) override;
  bool OffLine(CStateManager& mgr, float arg) override;
  bool TooClose(CStateManager& mgr, float arg) override;
  bool InMaxRange(CStateManager& mgr, float arg) override;
  bool InDetectionRange(CStateManager& mgr, float arg) override;
  bool SpotPlayer(CStateManager& mgr, float arg) override;
  bool AnimOver(CStateManager& mgr, float arg) override;
  bool ShouldAttack(CStateManager& mgr, float arg) override;
  bool ShouldDoubleSnap(CStateManager& mgr, float arg) override;
  bool InPosition(CStateManager& mgr, float arg) override;
  bool ShouldTurn(CStateManager& mgr, float arg) override;
  bool AggressionCheck(CStateManager& mgr, float arg) override;
  bool ShouldFire(CStateManager& mgr, float arg) override;
  bool ShouldFlinch(CStateManager& mgr, float arg) override;
  bool ShotAt(CStateManager& mgr, float arg) override;
  bool ShouldSpecialAttack(CStateManager& mgr, float arg) override;
  bool LostInterest(CStateManager& mgr, float arg) override;
  CPathFindSearch* GetSearchPath() override {
    return x928_pathFindMode == EPathFindMode::Normal ? &x760_pathSearch : &x844_approachSearch;
  }
  [[nodiscard]] constexpr float GetGravityConstant() const override { return 10.f * 24.525f; }
  CProjectileInfo* GetProjectileInfo() override { return &xa58_; }
};
} // namespace MP1
} // namespace urde
<commit_msg>CIceSheegoth: Remove constexpr from virtual function<commit_after>#pragma once

#include "Runtime/Collision/CJointCollisionDescription.hpp"
#include "Runtime/Character/CBoneTracking.hpp"
#include "Runtime/Weapon/CProjectileInfo.hpp"
#include "Runtime/World/CPathFindSearch.hpp"
#include "Runtime/World/CPatterned.hpp"

namespace urde {
class CCollisionActorManager;
class CElementGen;
class CParticleElectric;
namespace MP1 {
class CIceSheegothData {
  float x0_;
  float x4_;
  zeus::CVector3f x8_;
  float x14_;
  CDamageVulnerability x18_;
  CDamageVulnerability x80_;
  CDamageVulnerability xe8_;
  CAssetId x150_;
  CDamageInfo x154_;
  float x170_;
  float x174_;
  CAssetId x178_;
  CAssetId x17c_fireBreathResId;
  CDamageInfo x180_fireBreathDamage;
  CAssetId x19c_;
  CAssetId x1a0_;
  CAssetId x1a4_;
  CAssetId x1a8_;
  CAssetId x1ac_;
  float x1b0_;
  float x1b4_;
  CDamageInfo x1b8_;
  s16 x1d4_;
  float x1d8_;
  float x1dc_;
  float x1e0_maxInterestTime;
  CAssetId x1e4_;
  s16 x1e8_;
  CAssetId x1ec_;
  bool x1f0_24_ : 1;
  bool x1f0_25_ : 1;

public:
  CIceSheegothData(CInputStream& in, s32 propertyCount);
  [[nodiscard]] float Get_x0() const { return x0_; }
  [[nodiscard]] float Get_x4() const { return x4_; }
  [[nodiscard]] zeus::CVector3f Get_x8() const { return x8_; }
  [[nodiscard]] float Get_x14() const { return x14_; }
  [[nodiscard]] CDamageVulnerability Get_x18() const { return x18_; }
  [[nodiscard]] CDamageVulnerability Get_x80() const { return x80_; }
  [[nodiscard]] CDamageVulnerability Get_xe8() const { return xe8_; }
  [[nodiscard]] CAssetId Get_x150() const { return x150_; }
  [[nodiscard]] CDamageInfo Get_x154() const { return x154_; }
  [[nodiscard]] float Get_x170() const { return x170_; }
  [[nodiscard]] float Get_x174() const { return x174_; }
  [[nodiscard]] CAssetId Get_x178() const { return x178_; }
  [[nodiscard]] CAssetId GetFireBreathResId() const { return x17c_fireBreathResId; }
  [[nodiscard]] CDamageInfo GetFireBreathDamage() const { return x180_fireBreathDamage; }
  [[nodiscard]] CAssetId Get_x19c() const { return x19c_; }
  [[nodiscard]] CAssetId Get_x1a0() const { return x1a0_; }
  [[nodiscard]] CAssetId Get_x1a4() const { return x1a4_; }
  [[nodiscard]] CAssetId Get_x1a8() const { return x1a8_; }
  [[nodiscard]] CAssetId Get_x1ac() const { return x1ac_; }
  [[nodiscard]] float Get_x1b0() const { return x1b0_; }
  [[nodiscard]] CDamageInfo Get_x1b8() const { return x1b8_; }
  [[nodiscard]] s16 Get_x1d4() const { return x1d4_; }
  [[nodiscard]] float Get_x1d8() const { return x1d8_; }
  [[nodiscard]] float Get_x1dc() const { return x1dc_; }
  [[nodiscard]] float GetMaxInterestTime() const { return x1e0_maxInterestTime; }
  [[nodiscard]] CAssetId Get_x1e4() const { return x1e4_; }
  [[nodiscard]] s16 Get_x1e8() const { return x1e8_; }
  [[nodiscard]] CAssetId Get_x1ec() const { return x1ec_; }
  [[nodiscard]] bool Get_x1f0_24() const { return x1f0_24_; }
  [[nodiscard]] bool Get_x1f0_25() const { return x1f0_25_; }
};

class CIceSheegoth : public CPatterned {
  enum class EPathFindMode { Normal, Approach };
  s32 x568_ = -1;
  CIceSheegothData x56c_sheegothData;
  CPathFindSearch x760_pathSearch;
  CPathFindSearch x844_approachSearch;
  EPathFindMode x928_pathFindMode = EPathFindMode::Normal;
  zeus::CVector3f x92c_lastDest = zeus::skZero3f;
  zeus::CVector3f x938_ = zeus::skZero3f;
  float x944_ = 1.f;
  float x948_ = 1.f;
  float x94c_;
  float x950_ = 0.f;
  float x954_attackTimeLeft = 0.f;
  float x958_ = 0.f;
  float x95c_ = 0.f;
  float x960_ = 0.f;
  /* x964_ */
  float x968_interestTimer = 0.f;
  float x96c_ = 2.f;
  float x970_maxHp = 0.f;
  float x974_;
  float x978_ = 0.f;
  float x97c_ = 0.f;
  zeus::CVector3f x980_ = zeus::skZero3f;
  CDamageVulnerability x98c_mouthVulnerability;
  CBoneTracking x9f4_boneTracking;
  std::unique_ptr<CCollisionActorManager> xa2c_collisionManager;
  CCollidableAABox xa30_;
  CProjectileInfo xa58_;
  TUniqueId xa80_flameThrowerId = kInvalidUniqueId;
  TToken<CWeaponDescription> xa84_;
  TCachedToken<CGenDescription> xa8c_;
  // bool xa98_;
  std::unique_ptr<CElementGen> xa9c_;
  TCachedToken<CGenDescription> xaa0_;
  // bool xaac_;
  std::unique_ptr<CElementGen> xab0_;
  TCachedToken<CGenDescription> xab4_;
  // bool xac0_;
  std::unique_ptr<CElementGen> xac4_;
  TCachedToken<CElectricDescription> xac8_;
  // bool xad4_;
  std::unique_ptr<CParticleElectric> xad8_;
  TCachedToken<CGenDescription> xadc_;
  // bool xae8_;
  std::unique_ptr<CElementGen> xaec_;
  CSfxHandle xaf0_crackleSfx;
  CSegId xaf4_mouthLocator;
  TUniqueId xaf6_iceShardsCollider = kInvalidUniqueId;
  TUniqueId xaf8_mouthCollider = kInvalidUniqueId;
  rstl::reserved_vector<TUniqueId, 2> xafc_gillColliders;
  rstl::reserved_vector<TUniqueId, 10> xb04_;
  rstl::reserved_vector<CSegId, 7> xb1c_;
  bool xb28_24_shotAt : 1 = false;
  bool xb28_25_ : 1 = false;
  bool xb28_26_ : 1 = false;
  bool xb28_27_ : 1 = false;
  bool xb28_28_ : 1 = false;
  bool xb28_29_ : 1 = false;
  bool xb28_30_ : 1 = false;
  bool xb28_31_ : 1 = false;
  bool xb29_24_ : 1 = false;
  bool xb29_25_ : 1 = false;
  bool xb29_26_ : 1 = false;
  bool xb29_27_ : 1 = false;
  bool xb29_28_ : 1 = false;
  bool xb29_29_scanned : 1 = false;

  void UpdateTouchBounds();
  [[nodiscard]] bool IsMouthCollider(TUniqueId uid) const { return xaf8_mouthCollider == uid; }
  [[nodiscard]] bool IsGillCollider(const CEntity* ent) const {
    return std::find_if(xafc_gillColliders.cbegin(), xafc_gillColliders.cend(),
                        [&ent](TUniqueId uid) { return uid == ent->GetUniqueId(); }) != xafc_gillColliders.cend();
  }
  void sub_8019ebf0(CStateManager& mgr, float damage);
  void ApplyWeaponDamage(CStateManager& mgr, TUniqueId sender);
  void CreateFlameThrower(CStateManager& mgr);
  void ApplyContactDamage(TUniqueId sender, CStateManager& mgr);
  void AddSphereCollisionList(const SSphereJointInfo* info, size_t count,
                              std::vector<CJointCollisionDescription>& vecOut);
  void AddCollisionList(const SJointInfo* info, size_t count, std::vector<CJointCollisionDescription>& vecOut);
  void SetupCollisionActorManager(CStateManager& mgr);
  void SetupHealthInfo(CStateManager& mgr);
  void AttractProjectiles(CStateManager& mgr);
  void UpdateTimers(float dt);
  void UpdateScanState(CStateManager& mgr);
  void SetPassthroughVulnerability(CStateManager& mgr);
  void PreventWorldCollisions(float dt, CStateManager& mgr);
  void UpdateHealthInfo(CStateManager& mgr);
  void SetSteeringSpeed(float dt, CStateManager& mgr);
  void SetPathFindMode(EPathFindMode mode) { x928_pathFindMode = mode; }
  void UpdateParticleEffects(float dt, CStateManager& mgr);
  bool sub_801a1794(CStateManager& mgr) const {
    const CHealthInfo* hInfo = GetHealthInfo(mgr);
    return hInfo != nullptr && hInfo->GetHP() < 0.3f * x970_maxHp;
  }

  bool sub_8019ecbc() const { return xb28_27_ || xb29_26_; }
  bool sub_8019ecdc(CStateManager& mgr, float minAngle);
  void SetMouthVulnerability(CStateManager& mgr, bool isVulnerable);
  void SetGillVulnerability(CStateManager& mgr, bool isVulnerable);
  void ShakePlayer(CStateManager& mgr);
  void SetCollisionActorExtendedTouchBounds(CStateManager& mgr, const zeus::CVector3f& extents);

  void UpdateAttackPosition(CStateManager& mgr, zeus::CVector3f& attackPos);
  zeus::CVector3f GetEnergyAttractionPos(CStateManager& mgr) const;
  bool ShouldAttractProjectile(const CGameProjectile& proj, CStateManager& mgr) const;
  bool IsClosestSheegoth(CStateManager& mgr, const rstl::reserved_vector<TUniqueId, 1024>& nearList,
                         const zeus::CVector3f& projectileOffset) const;

public:
  DEFINE_PATTERNED(IceSheeegoth);
  CIceSheegoth(TUniqueId uid, std::string_view name, const CEntityInfo& info, zeus::CTransform& xf, CModelData&& mData,
               const CPatternedInfo& pInfo, const CActorParameters& actorParameters,
               const CIceSheegothData& sheegothData);

  void Accept(IVisitor& visitor) override;
  void Think(float dt, CStateManager& mgr) override;
  void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) override;
  void AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) override;
  [[nodiscard]] const CDamageVulnerability* GetDamageVulnerability() const override {
    return &CDamageVulnerability::PassThroughVulnerabilty();
  }
  [[nodiscard]] const CDamageVulnerability* GetDamageVulnerability(const zeus::CVector3f&, const zeus::CVector3f&,
                                                                   const CDamageInfo&) const override {
    return &CDamageVulnerability::PassThroughVulnerabilty();
  }

  [[nodiscard]] zeus::CVector3f GetAimPosition(const CStateManager& mgr, float dt) const override;
  [[nodiscard]] EWeaponCollisionResponseTypes GetCollisionResponseType(const zeus::CVector3f&, const zeus::CVector3f&,
                                                                       const CWeaponMode&,
                                                                       EProjectileAttrib) const override;
  [[nodiscard]] zeus::CAABox GetSortingBounds(const CStateManager& mgr) const override;
  void DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, EUserEventType type, float dt) override;
  [[nodiscard]] const CCollisionPrimitive* GetCollisionPrimitive() const override { return &xa30_; }
  void PathFind(CStateManager& mgr, EStateMsg msg, float dt) override;
  void TargetPatrol(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Generate(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Deactivate(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Attack(CStateManager& mgr, EStateMsg msg, float dt) override;
  void DoubleSnap(CStateManager& mgr, EStateMsg msg, float dt) override;
  void TurnAround(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Crouch(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Taunt(CStateManager& mgr, EStateMsg msg, float dt) override;
  void ProjectileAttack(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Flinch(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Approach(CStateManager& mgr, EStateMsg msg, float dt) override;
  void Enraged(CStateManager& mgr, EStateMsg msg, float dt) override;
  void SpecialAttack(CStateManager& mgr, EStateMsg msg, float dt) override;
  bool Leash(CStateManager& mgr, float arg) override;
  bool OffLine(CStateManager& mgr, float arg) override;
  bool TooClose(CStateManager& mgr, float arg) override;
  bool InMaxRange(CStateManager& mgr, float arg) override;
  bool InDetectionRange(CStateManager& mgr, float arg) override;
  bool SpotPlayer(CStateManager& mgr, float arg) override;
  bool AnimOver(CStateManager& mgr, float arg) override;
  bool ShouldAttack(CStateManager& mgr, float arg) override;
  bool ShouldDoubleSnap(CStateManager& mgr, float arg) override;
  bool InPosition(CStateManager& mgr, float arg) override;
  bool ShouldTurn(CStateManager& mgr, float arg) override;
  bool AggressionCheck(CStateManager& mgr, float arg) override;
  bool ShouldFire(CStateManager& mgr, float arg) override;
  bool ShouldFlinch(CStateManager& mgr, float arg) override;
  bool ShotAt(CStateManager& mgr, float arg) override;
  bool ShouldSpecialAttack(CStateManager& mgr, float arg) override;
  bool LostInterest(CStateManager& mgr, float arg) override;
  CPathFindSearch* GetSearchPath() override {
    return x928_pathFindMode == EPathFindMode::Normal ? &x760_pathSearch : &x844_approachSearch;
  }
  [[nodiscard]] float GetGravityConstant() const override { return 10.f * 24.525f; }
  CProjectileInfo* GetProjectileInfo() override { return &xa58_; }
};
} // namespace MP1
} // namespace urde
<|endoftext|>


<commit_before>#ifndef IMAGE_TRANSFORM_HPP
#define IMAGE_TRANSFORM_HPP

#include <stdio.h>
#include <opencv2/opencv.hpp>

namespace image_transform {

int persp_transform_width = 2700;
int persp_transform_height = 4900;

cv::Point2f persp_transform_src_pts[4] = {
  cv::Point2f(1593,2168),
  cv::Point2f(1850,2168),
  cv::Point2f(1859,2345),
  cv::Point2f(1577,2345)
};
cv::Point2f persp_transform_dst_pts[4] = {
  cv::Point2f(-20+(persp_transform_width/2),persp_transform_height-50),
  cv::Point2f(20+(persp_transform_width/2),persp_transform_height-50),
  cv::Point2f(20+(persp_transform_width/2),persp_transform_height-10),
  cv::Point2f(-20+(persp_transform_width/2),persp_transform_height-10)
};

cv::Mat transform = getPerspectiveTransform(persp_transform_src_pts, persp_transform_dst_pts);

void transform_perspective(const cv::Mat &input, cv::Mat &output) {
  cv::warpPerspective(input, output, transform, cv::Size(persp_transform_width,persp_transform_height));
}

}

#endif // IMAGE_UTILS_HPP
<commit_msg>see more of road.jpg in projection<commit_after>#ifndef IMAGE_TRANSFORM_HPP
#define IMAGE_TRANSFORM_HPP

#include <stdio.h>
#include <opencv2/opencv.hpp>

namespace image_transform {

int persp_transform_width = 3700;
int persp_transform_height = 6500;

cv::Point2f persp_transform_src_pts[4] = {
  cv::Point2f(1593,2168),
  cv::Point2f(1850,2168),
  cv::Point2f(1859,2345),
  cv::Point2f(1577,2345)
};
cv::Point2f persp_transform_dst_pts[4] = {
  cv::Point2f(-20+(persp_transform_width/2),persp_transform_height-50),
  cv::Point2f(20+(persp_transform_width/2),persp_transform_height-50),
  cv::Point2f(20+(persp_transform_width/2),persp_transform_height-10),
  cv::Point2f(-20+(persp_transform_width/2),persp_transform_height-10)
};

cv::Mat transform = getPerspectiveTransform(persp_transform_src_pts, persp_transform_dst_pts);

void transform_perspective(const cv::Mat &input, cv::Mat &output) {
  cv::warpPerspective(input, output, transform, cv::Size(persp_transform_width,persp_transform_height));
}

}

#endif // IMAGE_UTILS_HPP
<|endoftext|>


<commit_before>// This file is part of the dune-gdt project:
//   http://users.dune-project.org/projects/dune-gdt
// Copyright holders: Felix Schindler
// License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

#ifndef DUNE_STUFF_COMMON_TMP_STORAGE_HH
#define DUNE_STUFF_COMMON_TMP_STORAGE_HH

#include <vector>

#include <dune/common/dynmatrix.hh>
#include <dune/common/dynvector.hh>

#include <dune/stuff/common/parallel/threadmanager.hh>

namespace Dune {
namespace Stuff {
namespace Common {

template< class FieldType = double >
class TmpMatricesStorage
{
public:
  typedef DynamicMatrix< FieldType > LocalMatrixType;
protected:
  typedef std::vector< std::vector< LocalMatrixType > > LocalMatrixContainerType;

public:

  /**
   * \brief constructs the appropriate amount of matrix and indices storage
   *
   *        We construct 4 indices vectors since this is the maximum amount needed for discretizations (at least that
   *        we know of atm), namely one for each entity/neighbor and ansatz/test combination.
   */
  TmpMatricesStorage(const std::vector< size_t >& num_tmp_objects,
                     const size_t max_rows,
                     const size_t max_cols)
    : matrices_(LocalMatrixContainerType({std::vector< LocalMatrixType >(num_tmp_objects.at(0),
                                                                         LocalMatrixType(max_rows, max_cols, FieldType(0))),
                                          std::vector< LocalMatrixType >(num_tmp_objects.at(1),
                                                                         LocalMatrixType(max_rows, max_cols, FieldType(0)))}))
    , indices_(4, Dune::DynamicVector< size_t >(std::max(max_rows, max_cols)))
  {}

  virtual ~TmpMatricesStorage() {}

  std::vector< std::vector< LocalMatrixType > >& matrices()
  {
    return *matrices_;
  }

  std::vector< Dune::DynamicVector< size_t > >& indices()
  {
    return *indices_;
  }

protected:
  PerThreadValue< LocalMatrixContainerType > matrices_;
  PerThreadValue< std::vector< DynamicVector< size_t > > > indices_;
}; // class Matrices

template< class FieldType = double >
class TmpVectorsStorage
{
public:
  typedef DynamicVector< FieldType > LocalVectorType;
protected:
  typedef std::vector< std::vector< LocalVectorType > > LocalVectorContainerType;

  TmpVectorsStorage(const std::vector< size_t >& num_tmp_objects,
          const size_t max_size)
    : vectors_(LocalVectorContainerType({std::vector< LocalVectorType >(num_tmp_objects.at(0),
                                                                        LocalVectorType(max_size, FieldType(0))),
                                         std::vector< LocalVectorType >(num_tmp_objects.at(1),
                                                                        LocalVectorType(max_size, FieldType(0)))}))
    , indices_(max_size)
  {}

  virtual ~TmpVectorsStorage() {}

  std::vector< std::vector< LocalVectorType > >& vectors()
  {
    return *vectors_;
  }

  Dune::DynamicVector< size_t >& indices()
  {
    return *indices_;
  }

protected:
  PerThreadValue< std::vector< std::vector< LocalVectorType > > > vectors_;
  PerThreadValue< Dune::DynamicVector< size_t > > indices_;
}; // class Vectors

} // namespace Common
} // namespace Stuff
} // namespace Dune

#endif // DUNE_STUFF_COMMON_TMP_STORAGE_HH
<commit_msg>[common.tmp-storage] change include to fix compilation error<commit_after>// This file is part of the dune-gdt project:
//   http://users.dune-project.org/projects/dune-gdt
// Copyright holders: Felix Schindler
// License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

#ifndef DUNE_STUFF_COMMON_TMP_STORAGE_HH
#define DUNE_STUFF_COMMON_TMP_STORAGE_HH

#include <vector>

#include <dune/common/dynmatrix.hh>
#include <dune/common/dynvector.hh>

#include <dune/stuff/common/parallel/threadstorage.hh>

namespace Dune {
namespace Stuff {
namespace Common {

template< class FieldType = double >
class TmpMatricesStorage
{
public:
  typedef DynamicMatrix< FieldType > LocalMatrixType;
protected:
  typedef std::vector< std::vector< LocalMatrixType > > LocalMatrixContainerType;

public:

  /**
   * \brief constructs the appropriate amount of matrix and indices storage
   *
   *        We construct 4 indices vectors since this is the maximum amount needed for discretizations (at least that
   *        we know of atm), namely one for each entity/neighbor and ansatz/test combination.
   */
  TmpMatricesStorage(const std::vector< size_t >& num_tmp_objects,
                     const size_t max_rows,
                     const size_t max_cols)
    : matrices_(LocalMatrixContainerType({std::vector< LocalMatrixType >(num_tmp_objects.at(0),
                                                                         LocalMatrixType(max_rows, max_cols, FieldType(0))),
                                          std::vector< LocalMatrixType >(num_tmp_objects.at(1),
                                                                         LocalMatrixType(max_rows, max_cols, FieldType(0)))}))
    , indices_(4, Dune::DynamicVector< size_t >(std::max(max_rows, max_cols)))
  {}

  virtual ~TmpMatricesStorage() {}

  std::vector< std::vector< LocalMatrixType > >& matrices()
  {
    return *matrices_;
  }

  std::vector< Dune::DynamicVector< size_t > >& indices()
  {
    return *indices_;
  }

protected:
  PerThreadValue< LocalMatrixContainerType > matrices_;
  PerThreadValue< std::vector< DynamicVector< size_t > > > indices_;
}; // class Matrices

template< class FieldType = double >
class TmpVectorsStorage
{
public:
  typedef DynamicVector< FieldType > LocalVectorType;
protected:
  typedef std::vector< std::vector< LocalVectorType > > LocalVectorContainerType;

  TmpVectorsStorage(const std::vector< size_t >& num_tmp_objects,
          const size_t max_size)
    : vectors_(LocalVectorContainerType({std::vector< LocalVectorType >(num_tmp_objects.at(0),
                                                                        LocalVectorType(max_size, FieldType(0))),
                                         std::vector< LocalVectorType >(num_tmp_objects.at(1),
                                                                        LocalVectorType(max_size, FieldType(0)))}))
    , indices_(max_size)
  {}

  virtual ~TmpVectorsStorage() {}

  std::vector< std::vector< LocalVectorType > >& vectors()
  {
    return *vectors_;
  }

  Dune::DynamicVector< size_t >& indices()
  {
    return *indices_;
  }

protected:
  PerThreadValue< std::vector< std::vector< LocalVectorType > > > vectors_;
  PerThreadValue< Dune::DynamicVector< size_t > > indices_;
}; // class Vectors

} // namespace Common
} // namespace Stuff
} // namespace Dune

#endif // DUNE_STUFF_COMMON_TMP_STORAGE_HH
<|endoftext|>


<commit_before>// Copyright (C) 2017 Jérôme Leclercq, Arnaud Cadot
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

#include <NDK/Lua/LuaBinding_SDK.hpp>
#include <NDK/LuaAPI.hpp>
#include <NDK/Lua/LuaBinding.hpp>
#include <NDK/Lua/LuaBinding_Utility.hpp>

#ifndef NDK_SERVER
#include <NDK/Lua/LuaBinding_Graphics.hpp>
#endif

namespace Ndk
{
	std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindSDK(LuaBinding& binding)
	{
		return std::make_unique<LuaBinding_SDK>(binding);
	}

	LuaBinding_SDK::LuaBinding_SDK(LuaBinding& binding) :
	LuaBinding_Base(binding)
	{
		#ifndef NDK_SERVER
		LuaBinding_Graphics& graphics = static_cast<LuaBinding_Graphics&>(*m_binding.graphics);
		#endif

		LuaBinding_Utility& utility = static_cast<LuaBinding_Utility&>(*m_binding.utility);

		/*********************************** Ndk::Application **********************************/
		application.Reset("Application");
		{
			#ifndef NDK_SERVER
			//application.SetMethod("AddWindow", &Application::AddWindow);

			application.BindMethod("EnableConsole",    &Application::EnableConsole);
			application.BindMethod("EnableFPSCounter", &Application::EnableFPSCounter);

			application.BindMethod("IsConsoleEnabled",    &Application::IsConsoleEnabled);
			application.BindMethod("IsFPSCounterEnabled", &Application::IsFPSCounterEnabled);
			#endif

			application.BindMethod("AddWorld", [] (Nz::LuaState& lua, Application* instance, std::size_t /*argumentCount*/) -> int
			{
				lua.Push(instance->AddWorld().CreateHandle());
				return 1;
			});

			application.BindMethod("GetUpdateTime", &Application::GetUpdateTime);
			application.BindMethod("Quit", &Application::Quit);
		}

		/*********************************** Ndk::Console **********************************/
		#ifndef NDK_SERVER
		console.Reset("Console");
		{
			console.Inherit<Nz::Node>(utility.node, [] (ConsoleHandle* handle) -> Nz::Node*
			{
				return handle->GetObject();
			});

			console.BindMethod("AddLine", &Console::AddLine, Nz::Color::White);
			console.BindMethod("Clear", &Console::Clear);
			console.BindMethod("GetCharacterSize", &Console::GetCharacterSize);
			console.BindMethod("GetHistory", &Console::GetHistory);
			console.BindMethod("GetHistoryBackground", &Console::GetHistoryBackground);
			console.BindMethod("GetInput", &Console::GetInput);
			console.BindMethod("GetInputBackground", &Console::GetInputBackground);
			console.BindMethod("GetSize", &Console::GetSize);
			console.BindMethod("GetTextFont", &Console::GetTextFont);

			console.BindMethod("IsVisible", &Console::IsVisible);

			console.BindMethod("SendCharacter", &Console::SendCharacter);
			//consoleClass.SetMethod("SendEvent", &Console::SendEvent);

			console.BindMethod("SetCharacterSize", &Console::SetCharacterSize);
			console.BindMethod("SetSize", &Console::SetSize);
			console.BindMethod("SetTextFont", &Console::SetTextFont);

			console.BindMethod("Show", &Console::Show, true);
		}
		#endif

		/*********************************** Ndk::Entity **********************************/
		entity.Reset("Entity");
		{
			entity.BindMethod("Enable", &Entity::Enable, true);
			entity.BindMethod("GetId", &Entity::GetId);
			entity.BindMethod("GetWorld", &Entity::GetWorld);
			entity.BindMethod("Kill", &Entity::Kill);
			entity.BindMethod("IsEnabled", &Entity::IsEnabled);
			entity.BindMethod("IsValid", &Entity::IsValid);
			entity.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents);
			entity.BindMethod("__tostring", &EntityHandle::ToString);

			entity.BindMethod("AddComponent", [this] (Nz::LuaState& state, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
			{
				LuaBinding::ComponentBinding* bindingComponent = m_binding.QueryComponentIndex(state);

				return bindingComponent->adder(state, handle);
			});

			entity.BindMethod("GetComponent", [this] (Nz::LuaState& state, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
			{
				LuaBinding::ComponentBinding* bindingComponent = m_binding.QueryComponentIndex(state);

				return bindingComponent->getter(state, handle->GetComponent(bindingComponent->index));
			});

			entity.BindMethod("RemoveComponent", [this] (Nz::LuaState& state, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
			{
				LuaBinding::ComponentBinding* bindingComponent = m_binding.QueryComponentIndex(state);

				handle->RemoveComponent(bindingComponent->index);
				return 0;
			});
		}

		/*********************************** Ndk::NodeComponent **********************************/
		nodeComponent.Reset("NodeComponent");
		{
			nodeComponent.Inherit<Nz::Node>(utility.node, [] (NodeComponentHandle* handle) -> Nz::Node*
			{
				return handle->GetObject();
			});
		}

		/*********************************** Ndk::VelocityComponent **********************************/
		velocityComponent.Reset("VelocityComponent");
		{
			velocityComponent.SetGetter([] (Nz::LuaState& lua, VelocityComponentHandle& instance)
			{
				std::size_t length;
				const char* member = lua.CheckString(2, &length);

				if (std::strcmp(member, "Linear") == 0)
				{
					lua.Push(instance->linearVelocity);
					return true;
				}

				return false;
			});

			velocityComponent.SetSetter([] (Nz::LuaState& lua, VelocityComponentHandle& instance)
			{
				std::size_t length;
				const char* member = lua.CheckString(2, &length);

				int argIndex = 3;
				if (std::strcmp(member, "Linear") == 0)
				{
					instance->linearVelocity = lua.Check<Nz::Vector3f>(&argIndex);
					return true;
				}

				return false;
			});
		}

		/*********************************** Ndk::World **********************************/
		world.Reset("World");
		{
			world.BindMethod("CreateEntity", &World::CreateEntity);
			world.BindMethod("CreateEntities", &World::CreateEntities);
			world.BindMethod("Clear", &World::Clear);
		}

		#ifndef NDK_SERVER
		/*********************************** Ndk::CameraComponent **********************************/
		cameraComponent.Reset("CameraComponent");
		{
			cameraComponent.Inherit<Nz::AbstractViewer>(graphics.abstractViewer, [] (CameraComponentHandle* handle) -> Nz::AbstractViewer*
			{
				return handle->GetObject();
			});

			cameraComponent.BindMethod("GetFOV", &Ndk::CameraComponent::GetFOV);
			cameraComponent.BindMethod("GetLayer", &Ndk::CameraComponent::GetLayer);

			cameraComponent.BindMethod("SetFOV", &Ndk::CameraComponent::SetFOV);
			cameraComponent.BindMethod("SetLayer", &Ndk::CameraComponent::SetLayer);
			cameraComponent.BindMethod("SetProjectionType", &Ndk::CameraComponent::SetProjectionType);
			cameraComponent.BindMethod("SetSize", (void(Ndk::CameraComponent::*)(const Nz::Vector2f&)) &Ndk::CameraComponent::SetSize);
			//cameraComponent.BindMethod("SetTarget", &Ndk::CameraComponent::SetTarget);
			cameraComponent.BindMethod("SetTargetRegion", &Ndk::CameraComponent::SetTargetRegion);
			cameraComponent.BindMethod("SetViewport", &Ndk::CameraComponent::SetViewport);
			cameraComponent.BindMethod("SetZFar", &Ndk::CameraComponent::SetZFar);
			cameraComponent.BindMethod("SetZNear", &Ndk::CameraComponent::SetZNear);
		}

		/*********************************** Ndk::GraphicsComponent **********************************/
		graphicsComponent.Reset("GraphicsComponent");
		{
			graphicsComponent.BindMethod("Attach", [] (Nz::LuaState& lua, Ndk::GraphicsComponent* instance, std::size_t argumentCount) -> int
			{
				/*
				void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
				void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0);
				*/

				std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);

				switch (argCount)
				{
					case 1:
					{
						int argIndex = 2;
						instance->Attach(lua.Check<Nz::InstancedRenderableRef>(&argIndex));
						return 0;
					}

					case 2:
					{
						int argIndex = 2;
						Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&argIndex);

						if (lua.IsOfType(argIndex, Nz::LuaType_Number))
						{
							int renderOrder = lua.Check<int>(&argIndex);

							instance->Attach(renderable, renderOrder);
						}
						else if (lua.IsOfType(argIndex, "Matrix4"))
						{
							Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&argIndex);

							instance->Attach(renderable, localMatrix);
						}
						else
							break;

						return 0;
					}

					case 3:
					{
						int argIndex = 2;
						Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&argIndex);
						Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&argIndex);
						int renderOrder = lua.Check<int>(&argIndex);

						instance->Attach(renderable, localMatrix, renderOrder);
						return 0;
					}
				}

				lua.Error("No matching overload for method GetMemoryUsage");
				return 0;
			});
		}
		#endif

		// Components functions
		m_binding.BindComponent<NodeComponent>("Node");
		m_binding.BindComponent<VelocityComponent>("Velocity");

		#ifndef NDK_SERVER
		m_binding.BindComponent<CameraComponent>("Camera");
		m_binding.BindComponent<GraphicsComponent>("Graphics");
		#endif
	}

	/*!
	* \brief Registers the classes that will be used by the Lua instance
	*
	* \param instance Lua instance that will interact with the SDK classes
	*/
	void LuaBinding_SDK::Register(Nz::LuaState& state)
	{
		// Classes
		application.Register(state);
		entity.Register(state);
		nodeComponent.Register(state);
		velocityComponent.Register(state);
		world.Register(state);

		#ifndef NDK_SERVER
		cameraComponent.Register(state);
		console.Register(state);
		graphicsComponent.Register(state);
		#endif

		// Enums
	}

	/*!
	* \brief Gets the index of the component
	* \return A pointer to the binding linked to a component
	*
	* \param instance Lua instance that will interact with the component
	* \param argIndex Index of the component
	*/
	LuaBinding::ComponentBinding* LuaBinding::QueryComponentIndex(Nz::LuaState& state, int argIndex)
	{
		switch (state.GetType(argIndex))
		{
			case Nz::LuaType_Number:
			{
				ComponentIndex componentIndex = state.Check<ComponentIndex>(&argIndex);
				if (componentIndex > m_componentBinding.size())
				{
					state.Error("Invalid component index");
					return nullptr;
				}

				ComponentBinding& binding = m_componentBinding[componentIndex];
				if (binding.name.IsEmpty())
				{
					state.Error("Invalid component index");
					return nullptr;
				}

				return &binding;
			}

			case Nz::LuaType_String:
			{
				const char* key = state.CheckString(argIndex);
				auto it = m_componentBindingByName.find(key);
				if (it == m_componentBindingByName.end())
				{
					state.Error("Invalid component name");
					return nullptr;
				}

				return &m_componentBinding[it->second];
			}

			default:
				break;
		}

		state.Error("Invalid component index at #" + Nz::String::Number(argIndex));
		return nullptr;
	}
}
<commit_msg>SDK/LuaBinding: Bind IsValidHandle for handled types<commit_after>// Copyright (C) 2017 Jérôme Leclercq, Arnaud Cadot
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

#include <NDK/Lua/LuaBinding_SDK.hpp>
#include <NDK/LuaAPI.hpp>
#include <NDK/Lua/LuaBinding.hpp>
#include <NDK/Lua/LuaBinding_Utility.hpp>

#ifndef NDK_SERVER
#include <NDK/Lua/LuaBinding_Graphics.hpp>
#endif

namespace Ndk
{
	std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindSDK(LuaBinding& binding)
	{
		return std::make_unique<LuaBinding_SDK>(binding);
	}

	LuaBinding_SDK::LuaBinding_SDK(LuaBinding& binding) :
	LuaBinding_Base(binding)
	{
		#ifndef NDK_SERVER
		LuaBinding_Graphics& graphics = static_cast<LuaBinding_Graphics&>(*m_binding.graphics);
		#endif

		LuaBinding_Utility& utility = static_cast<LuaBinding_Utility&>(*m_binding.utility);

		/*********************************** Ndk::Application **********************************/
		application.Reset("Application");
		{
			#ifndef NDK_SERVER
			//application.SetMethod("AddWindow", &Application::AddWindow);

			application.BindMethod("EnableConsole",    &Application::EnableConsole);
			application.BindMethod("EnableFPSCounter", &Application::EnableFPSCounter);

			application.BindMethod("IsConsoleEnabled",    &Application::IsConsoleEnabled);
			application.BindMethod("IsFPSCounterEnabled", &Application::IsFPSCounterEnabled);
			#endif

			application.BindMethod("AddWorld", [] (Nz::LuaState& lua, Application* instance, std::size_t /*argumentCount*/) -> int
			{
				lua.Push(instance->AddWorld().CreateHandle());
				return 1;
			});

			application.BindMethod("GetUpdateTime", &Application::GetUpdateTime);
			application.BindMethod("Quit", &Application::Quit);
		}

		/*********************************** Ndk::Console **********************************/
		#ifndef NDK_SERVER
		console.Reset("Console");
		{
			console.Inherit<Nz::Node>(utility.node, [] (ConsoleHandle* handle) -> Nz::Node*
			{
				return handle->GetObject();
			});

			console.BindMethod("AddLine", &Console::AddLine, Nz::Color::White);
			console.BindMethod("Clear", &Console::Clear);
			console.BindMethod("GetCharacterSize", &Console::GetCharacterSize);
			console.BindMethod("GetHistory", &Console::GetHistory);
			console.BindMethod("GetHistoryBackground", &Console::GetHistoryBackground);
			console.BindMethod("GetInput", &Console::GetInput);
			console.BindMethod("GetInputBackground", &Console::GetInputBackground);
			console.BindMethod("GetSize", &Console::GetSize);
			console.BindMethod("GetTextFont", &Console::GetTextFont);

			console.BindMethod("IsValidHandle", &ConsoleHandle::IsValid);
			console.BindMethod("IsVisible", &Console::IsVisible);

			console.BindMethod("SendCharacter", &Console::SendCharacter);
			//consoleClass.SetMethod("SendEvent", &Console::SendEvent);

			console.BindMethod("SetCharacterSize", &Console::SetCharacterSize);
			console.BindMethod("SetSize", &Console::SetSize);
			console.BindMethod("SetTextFont", &Console::SetTextFont);

			console.BindMethod("Show", &Console::Show, true);
		}
		#endif

		/*********************************** Ndk::Entity **********************************/
		entity.Reset("Entity");
		{
			entity.BindMethod("Enable", &Entity::Enable, true);
			entity.BindMethod("GetId", &Entity::GetId);
			entity.BindMethod("GetWorld", &Entity::GetWorld);
			entity.BindMethod("Kill", &Entity::Kill);
			entity.BindMethod("IsEnabled", &Entity::IsEnabled);
			entity.BindMethod("IsValid", &Entity::IsValid);
			entity.BindMethod("IsValidHandle", &EntityHandle::IsValid);
			entity.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents);
			entity.BindMethod("__tostring", &EntityHandle::ToString);

			entity.BindMethod("AddComponent", [this] (Nz::LuaState& state, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
			{
				LuaBinding::ComponentBinding* bindingComponent = m_binding.QueryComponentIndex(state);

				return bindingComponent->adder(state, handle);
			});

			entity.BindMethod("GetComponent", [this] (Nz::LuaState& state, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
			{
				LuaBinding::ComponentBinding* bindingComponent = m_binding.QueryComponentIndex(state);

				return bindingComponent->getter(state, handle->GetComponent(bindingComponent->index));
			});

			entity.BindMethod("RemoveComponent", [this] (Nz::LuaState& state, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
			{
				LuaBinding::ComponentBinding* bindingComponent = m_binding.QueryComponentIndex(state);

				handle->RemoveComponent(bindingComponent->index);
				return 0;
			});
		}

		/*********************************** Ndk::NodeComponent **********************************/
		nodeComponent.Reset("NodeComponent");
		{
			nodeComponent.BindMethod("IsValidHandle", &NodeComponentHandle::IsValid);

			nodeComponent.Inherit<Nz::Node>(utility.node, [] (NodeComponentHandle* handle) -> Nz::Node*
			{
				return handle->GetObject();
			});
		}

		/*********************************** Ndk::VelocityComponent **********************************/
		velocityComponent.Reset("VelocityComponent");
		{
			velocityComponent.BindMethod("IsValidHandle", &VelocityComponentHandle::IsValid);

			velocityComponent.SetGetter([] (Nz::LuaState& lua, VelocityComponentHandle& instance)
			{
				std::size_t length;
				const char* member = lua.CheckString(2, &length);

				if (std::strcmp(member, "Linear") == 0)
				{
					lua.Push(instance->linearVelocity);
					return true;
				}

				return false;
			});

			velocityComponent.SetSetter([] (Nz::LuaState& lua, VelocityComponentHandle& instance)
			{
				std::size_t length;
				const char* member = lua.CheckString(2, &length);

				int argIndex = 3;
				if (std::strcmp(member, "Linear") == 0)
				{
					instance->linearVelocity = lua.Check<Nz::Vector3f>(&argIndex);
					return true;
				}

				return false;
			});
		}

		/*********************************** Ndk::World **********************************/
		world.Reset("World");
		{
			world.BindMethod("CreateEntity", &World::CreateEntity);
			world.BindMethod("CreateEntities", &World::CreateEntities);
			world.BindMethod("Clear", &World::Clear);

			world.BindMethod("IsValidHandle", &WorldHandle::IsValid);
		}

		#ifndef NDK_SERVER
		/*********************************** Ndk::CameraComponent **********************************/
		cameraComponent.Reset("CameraComponent");
		{
			cameraComponent.Inherit<Nz::AbstractViewer>(graphics.abstractViewer, [] (CameraComponentHandle* handle) -> Nz::AbstractViewer*
			{
				return handle->GetObject();
			});

			cameraComponent.BindMethod("GetFOV", &CameraComponent::GetFOV);
			cameraComponent.BindMethod("GetLayer", &CameraComponent::GetLayer);

			cameraComponent.BindMethod("IsValidHandle", &CameraComponentHandle::IsValid);

			cameraComponent.BindMethod("SetFOV", &CameraComponent::SetFOV);
			cameraComponent.BindMethod("SetLayer", &CameraComponent::SetLayer);
			cameraComponent.BindMethod("SetProjectionType", &CameraComponent::SetProjectionType);
			cameraComponent.BindMethod("SetSize", (void(CameraComponent::*)(const Nz::Vector2f&)) &CameraComponent::SetSize);
			//cameraComponent.BindMethod("SetTarget", &CameraComponent::SetTarget);
			cameraComponent.BindMethod("SetTargetRegion", &CameraComponent::SetTargetRegion);
			cameraComponent.BindMethod("SetViewport", &CameraComponent::SetViewport);
			cameraComponent.BindMethod("SetZFar", &CameraComponent::SetZFar);
			cameraComponent.BindMethod("SetZNear", &CameraComponent::SetZNear);
		}

		/*********************************** Ndk::GraphicsComponent **********************************/
		graphicsComponent.Reset("GraphicsComponent");
		{
			graphicsComponent.BindMethod("Attach", [] (Nz::LuaState& lua, Ndk::GraphicsComponent* instance, std::size_t argumentCount) -> int
			{
				/*
				void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
				void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0);
				*/

				std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);

				switch (argCount)
				{
					case 1:
					{
						int argIndex = 2;
						instance->Attach(lua.Check<Nz::InstancedRenderableRef>(&argIndex));
						return 0;
					}

					case 2:
					{
						int argIndex = 2;
						Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&argIndex);

						if (lua.IsOfType(argIndex, Nz::LuaType_Number))
						{
							int renderOrder = lua.Check<int>(&argIndex);

							instance->Attach(renderable, renderOrder);
						}
						else if (lua.IsOfType(argIndex, "Matrix4"))
						{
							Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&argIndex);

							instance->Attach(renderable, localMatrix);
						}
						else
							break;

						return 0;
					}

					case 3:
					{
						int argIndex = 2;
						Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&argIndex);
						Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&argIndex);
						int renderOrder = lua.Check<int>(&argIndex);

						instance->Attach(renderable, localMatrix, renderOrder);
						return 0;
					}
				}

				lua.Error("No matching overload for method GetMemoryUsage");
				return 0;
			});

			graphicsComponent.BindMethod("IsValidHandle", &GraphicsComponentHandle::IsValid);
		}
		#endif

		// Components functions
		m_binding.BindComponent<NodeComponent>("Node");
		m_binding.BindComponent<VelocityComponent>("Velocity");

		#ifndef NDK_SERVER
		m_binding.BindComponent<CameraComponent>("Camera");
		m_binding.BindComponent<GraphicsComponent>("Graphics");
		#endif
	}

	/*!
	* \brief Registers the classes that will be used by the Lua instance
	*
	* \param instance Lua instance that will interact with the SDK classes
	*/
	void LuaBinding_SDK::Register(Nz::LuaState& state)
	{
		// Classes
		application.Register(state);
		entity.Register(state);
		nodeComponent.Register(state);
		velocityComponent.Register(state);
		world.Register(state);

		#ifndef NDK_SERVER
		cameraComponent.Register(state);
		console.Register(state);
		graphicsComponent.Register(state);
		#endif

		// Enums
	}

	/*!
	* \brief Gets the index of the component
	* \return A pointer to the binding linked to a component
	*
	* \param instance Lua instance that will interact with the component
	* \param argIndex Index of the component
	*/
	LuaBinding::ComponentBinding* LuaBinding::QueryComponentIndex(Nz::LuaState& state, int argIndex)
	{
		switch (state.GetType(argIndex))
		{
			case Nz::LuaType_Number:
			{
				ComponentIndex componentIndex = state.Check<ComponentIndex>(&argIndex);
				if (componentIndex > m_componentBinding.size())
				{
					state.Error("Invalid component index");
					return nullptr;
				}

				ComponentBinding& binding = m_componentBinding[componentIndex];
				if (binding.name.IsEmpty())
				{
					state.Error("Invalid component index");
					return nullptr;
				}

				return &binding;
			}

			case Nz::LuaType_String:
			{
				const char* key = state.CheckString(argIndex);
				auto it = m_componentBindingByName.find(key);
				if (it == m_componentBindingByName.end())
				{
					state.Error("Invalid component name");
					return nullptr;
				}

				return &m_componentBinding[it->second];
			}

			default:
				break;
		}

		state.Error("Invalid component index at #" + Nz::String::Number(argIndex));
		return nullptr;
	}
}
<|endoftext|>


<commit_before>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2015 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#ifndef CONFIG_HPP
#define CONFIG_HPP

// stl
#include <vector>
#include <string>

// boost
#include <boost/filesystem.hpp>

namespace visual_tests
{

struct map_size
{
    map_size(int width, int height) : width(width), height(height) { }
    map_size() { }
    unsigned width;
    unsigned height;
};

struct config
{
    config() : status(true),
               scales({ 1.0, 2.0 }),
               sizes({ { 500, 100 } }) { }

    bool status;
    std::vector<double> scales;
    std::vector<map_size> sizes;
};

enum result_state : std::uint8_t
{
    STATE_OK,
    STATE_FAIL,
    STATE_ERROR,
    STATE_OVERWRITE
};

struct result
{
    std::string name;
    result_state state;
    char const * renderer_name;
    map_size size;
    double scale_factor;
    boost::filesystem::path actual_image_path;
    boost::filesystem::path reference_image_path;
    std::string error_message;
    unsigned diff;
};

using result_list = std::vector<result>;

bool ensure_dir(boost::filesystem::path const & dir);

}

#endif
<commit_msg>avoid crash on uninitialized pointer [skip ci]<commit_after>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2015 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#ifndef CONFIG_HPP
#define CONFIG_HPP

// stl
#include <vector>
#include <string>

// boost
#include <boost/filesystem.hpp>

namespace visual_tests
{

struct map_size
{
    map_size(int width, int height) : width(width), height(height) { }
    map_size() { }
    unsigned width;
    unsigned height;
};

struct config
{
    config() : status(true),
               scales({ 1.0, 2.0 }),
               sizes({ { 500, 100 } }) { }

    bool status;
    std::vector<double> scales;
    std::vector<map_size> sizes;
};

enum result_state : std::uint8_t
{
    STATE_OK,
    STATE_FAIL,
    STATE_ERROR,
    STATE_OVERWRITE
};

struct result
{
    std::string name;
    result_state state;
    std::string renderer_name;
    map_size size;
    double scale_factor;
    boost::filesystem::path actual_image_path;
    boost::filesystem::path reference_image_path;
    std::string error_message;
    unsigned diff;
};

using result_list = std::vector<result>;

bool ensure_dir(boost::filesystem::path const & dir);

}

#endif
<|endoftext|>