Beispiel #1
0
// assure that floating point precision is 53 bits
void AssureFPT_53(void)
{
  if (GetFPUPrecision()!=FPT_53BIT) {
    ASSERTALWAYS( "Floating precision must be set to 53 bits during CSG!");
    SetFPUPrecision(FPT_53BIT);
  }
}
inline CParticlesAbsorption *CreateAbsorption(PARTICLES_ABSORPTION_TYPE pat)
{
	switch(pat)
	{
	case PAT_DEFAULT: return new CParticlesAbsorptionDefault;
	case PAT_SPHERE: return new CParticlesAbsorptionSphere;
	default: ASSERTALWAYS("Unknown Absorption Type.");
	}
	return NULL;
}
Beispiel #3
0
 // Unlock array
 inline void Unlock(void) {
   ASSERT(tda_ulFlags&TDAF_LOCK_READ || tda_ulFlags&TDAF_LOCK_WRITE); // must be locked
   if(tda_ulFlags&TDAF_USEVXBUFFS) {
     ASSERTALWAYS("Undone");
   } else {
     // no unlock in software
     NOTHING;
   }
   tda_ulFlags&=~TDAF_LOCK_READ;
   tda_ulFlags&=~TDAF_LOCK_WRITE;
 }
inline CParticlesEmitter *CreateEmitter(PARTICLES_EMITTER_TYPE pet)
{
	switch(pet)
	{
	case PET_SPHERE:	return new CParticlesEmitterSphere;
	case PET_CONE:		return new CParticlesEmitterCone;
	case PET_CYLINDER:	return new CParticlesEmitterCylinder;
	default: ASSERTALWAYS("Unknown Emitter Type.");
	}
	return NULL;
}
// change texture filtering mode if needed
extern void MimicTexParams_D3D( CTexParams &tpLocal)
{
  ASSERT( &tpLocal!=NULL);
  _pfGfxProfile.StartTimer( CGfxProfile::PTI_TEXTUREPARAMS);

  // update texture filtering mode if required
  if( tpLocal.tp_iFilter != _tpGlobal[0].tp_iFilter) tpLocal.tp_iFilter = _tpGlobal[0].tp_iFilter;

  // eventually adjust filtering for textures w/o mipmaps
  const INDEX iMipFilter = _tpGlobal[0].tp_iFilter % 10;
  if( (!tpLocal.tp_bSingleMipmap != !_tpGlobal[GFX_iActiveTexUnit].tp_bSingleMipmap) && iMipFilter!=0)
  { 
    HRESULT hr;
    _D3DTEXTUREFILTERTYPE eMipFilter;
    extern INDEX GFX_iActiveTexUnit;

    // no mipmaps?
    if( tpLocal.tp_bSingleMipmap) {
#ifndef NDEBUG
      // paranoid!
      hr = _pGfx->gl_pd3dDevice->GetTextureStageState( GFX_iActiveTexUnit, D3DTSS_MIPFILTER, (ULONG*)&eMipFilter);
      D3D_CHECKERROR(hr);
      ASSERT( eMipFilter==D3DTEXF_POINT || eMipFilter==D3DTEXF_LINEAR);
#endif // set it
      hr = _pGfx->gl_pd3dDevice->SetTextureStageState( GFX_iActiveTexUnit, D3DTSS_MIPFILTER, D3DTEXF_NONE);
    }
    // yes mipmaps?
    else {
      switch( iMipFilter) {
      case 0: eMipFilter = D3DTEXF_NONE;   break; 
      case 1: eMipFilter = D3DTEXF_POINT;  break; 
      case 2: eMipFilter = D3DTEXF_LINEAR; break; 
      default: ASSERTALWAYS( "Invalid mipmap filtering mode.");
      } // set it
      hr = _pGfx->gl_pd3dDevice->SetTextureStageState( GFX_iActiveTexUnit, D3DTSS_MIPFILTER, eMipFilter);
    } 
    // check and update mipmap state
    D3D_CHECKERROR(hr);
    _tpGlobal[GFX_iActiveTexUnit].tp_bSingleMipmap = tpLocal.tp_bSingleMipmap;
  }

  // update texture anisotropy degree
  if( tpLocal.tp_iAnisotropy != _tpGlobal[0].tp_iAnisotropy) tpLocal.tp_iAnisotropy = _tpGlobal[0].tp_iAnisotropy;

  // update texture clamping modes if changed
  if( tpLocal.tp_eWrapU!=_tpGlobal[GFX_iActiveTexUnit].tp_eWrapU || tpLocal.tp_eWrapV!=_tpGlobal[GFX_iActiveTexUnit].tp_eWrapV) { 
    tpLocal.tp_eWrapU = _tpGlobal[GFX_iActiveTexUnit].tp_eWrapU;
    tpLocal.tp_eWrapV = _tpGlobal[GFX_iActiveTexUnit].tp_eWrapV;
  }

  // keep last texture params (for tex upload and stuff)
  _tpCurrent = &tpLocal;
  _pfGfxProfile.StopTimer( CGfxProfile::PTI_TEXTUREPARAMS);
}
INDEX CDynamicContainer<Type>::GetIndex(Type *ptMember) {
  ASSERT(this!=NULL);
  // slow !!!!
  // check all members
  for (INDEX iMember=0; iMember<Count(); iMember++) {
    if(sa_Array[iMember]==ptMember) {
      return iMember;
    }
  }
  ASSERTALWAYS("CDynamicContainer<Type><>::Index(): Not a member of this container!");
  return 0;
}
Beispiel #7
0
  // Lock array
  inline void Lock(ULONG ulFlags) {
    ASSERT(!(tda_ulFlags&TDAF_LOCK_READ));  // must not be locked
    ASSERT(!(tda_ulFlags&TDAF_LOCK_WRITE)); // must not be locked
    ASSERT(ulFlags&TDAF_LOCK_READ || ulFlags&TDAF_LOCK_WRITE); // validate lock flags

    if(tda_ulFlags&TDAF_USEVXBUFFS) {
      ASSERTALWAYS("Undone");
    } else {
      // no lock in software
      NOTHING;
    }
    tda_ulFlags|=ulFlags;
  }
inline CParticlesCommonProcess *CreateProcess(PARTICLES_COMMON_PROCESS_TYPE pcpt)
{
	switch(pcpt)
	{
	case PCPT_DYNAMIC_STATE: return new CParticlesProcessDynamicState;
	case PCPT_FORCE: return new CParticlesProcessForce;
	case PCPT_POINT_GOAL: return new CParticlesProcessPointGoal;
	case PCPT_CONTROL: return new CParticlesProcessControl;
	case PCPT_VELOCITY: return new CParticlesProcessVelocity;
	default: ASSERTALWAYS("Unknown Process Type.");
	}
	return NULL;
}
// helper for blending operation function
__forceinline GLenum BlendToOGL( GfxBlend eFunc) {
  switch( eFunc) {
  case GFX_ZERO:          return GL_ZERO;
  case GFX_ONE:           return GL_ONE;
  case GFX_SRC_COLOR:     return GL_SRC_COLOR;
  case GFX_INV_SRC_COLOR: return GL_ONE_MINUS_SRC_COLOR;
  case GFX_DST_COLOR:     return GL_DST_COLOR;          
  case GFX_INV_DST_COLOR: return GL_ONE_MINUS_DST_COLOR;
  case GFX_SRC_ALPHA:     return GL_SRC_ALPHA;          
  case GFX_INV_SRC_ALPHA: return GL_ONE_MINUS_SRC_ALPHA;
  default: ASSERTALWAYS("Invalid GFX blending function!");
  } return GL_ONE;
}
__forceinline GfxComp CompFromOGL( GLenum gFunc) {
  switch( gFunc) {
  case GL_NEVER:    return GFX_NEVER;
  case GL_LESS:     return GFX_LESS;
  case GL_LEQUAL:   return GFX_LESS_EQUAL;
  case GL_EQUAL:    return GFX_EQUAL;
  case GL_NOTEQUAL: return GFX_NOT_EQUAL;
  case GL_GEQUAL:   return GFX_GREATER_EQUAL;
  case GL_GREATER:  return GFX_GREATER;
  case GL_ALWAYS:   return GFX_ALWAYS;
  default: ASSERTALWAYS("Invalid OGL compare function!");
  } return GFX_ALWAYS;
}
__forceinline GfxBlend BlendFromOGL( GLenum gFunc) {
  switch( gFunc) {
  case GL_ZERO:                return GFX_ZERO;
  case GL_ONE:                 return GFX_ONE;
  case GL_SRC_COLOR:           return GFX_SRC_COLOR;
  case GL_ONE_MINUS_SRC_COLOR: return GFX_INV_SRC_COLOR;
  case GL_DST_COLOR:           return GFX_DST_COLOR;
  case GL_ONE_MINUS_DST_COLOR: return GFX_INV_DST_COLOR;
  case GL_SRC_ALPHA:           return GFX_SRC_ALPHA;
  case GL_ONE_MINUS_SRC_ALPHA: return GFX_INV_SRC_ALPHA;
  default: ASSERTALWAYS("Unsupported OGL blending function!");
  } return GFX_ONE;
}
// set polygon mode (point, line or fill)
static void ogl_PolygonMode( GfxPolyMode ePolyMode)
{
  ASSERT( _pGfx->gl_eCurrentAPI==GAT_OGL);
  _sfStats.StartTimer(CStatForm::STI_GFXAPI);

  switch(ePolyMode) {
  case GFX_POINT:  pglPolygonMode( GL_FRONT_AND_BACK, GL_POINT);  break;
  case GFX_LINE:   pglPolygonMode( GL_FRONT_AND_BACK, GL_LINE);   break;
  case GFX_FILL:   pglPolygonMode( GL_FRONT_AND_BACK, GL_FILL);   break;
  default:  ASSERTALWAYS("Wrong polygon mode!");
  } // check
  OGL_CHECKERROR;

  _sfStats.StopTimer(CStatForm::STI_GFXAPI);
}
Beispiel #13
0
  inline void Clear(void) {
    ASSERT(!(tda_ulFlags&TDAF_LOCK_READ));  // must not be locked
    ASSERT(!(tda_ulFlags&TDAF_LOCK_WRITE)); // must not be locked

    if(tda_ulFlags&TDAF_USEVXBUFFS) {
      ASSERT(tda_paObjects==NULL); // must not be used
      ASSERTALWAYS("Undone");
    } else {
      if(tda_paObjects!=NULL) {
        delete[] tda_paObjects;
        tda_paObjects = NULL;
      }
    }
    tda_ulFlags     = 0;
    tda_ctObjects   = 0;
    tda_ctAllocated = 0;
  }
Beispiel #14
0
  // Allocation of array
  inline void Allocate(INDEX ctObjects, ULONG ulFlags) {
    ASSERT(this!=NULL);
    ASSERT(tda_paObjects==NULL);        // must not be initialize
    ASSERT(ctObjects>0);                // must be valid
    ASSERT(!(ulFlags&TDAF_LOCK_READ));  // must not have lock flag
    ASSERT(!(ulFlags&TDAF_LOCK_WRITE)); // must not have lock flag

    // if array does uses vertex buffers
    if(ulFlags&TDAF_USEVXBUFFS) {
      ASSERTALWAYS("Undone");
    // if plain array
    } else {
      // allocate array
      tda_paObjects = new Type[ctObjects];
    }
    tda_ctObjects   = ctObjects;
    tda_ctAllocated = ctObjects;
    tda_ulFlags     = ulFlags;
  }
// unpacks texture filtering from one INDEX to two GLenums (and eventually re-adjust input INDEX)
extern void UnpackFilter_D3D( INDEX iFilter, _D3DTEXTUREFILTERTYPE &eMagFilter,
                             _D3DTEXTUREFILTERTYPE &eMinFilter, _D3DTEXTUREFILTERTYPE &eMipFilter)
{
  switch( iFilter) {
  case 110:  case 10:  eMagFilter=D3DTEXF_POINT;  eMinFilter=D3DTEXF_POINT;  eMipFilter=D3DTEXF_NONE;   break;
  case 111:  case 11:  eMagFilter=D3DTEXF_POINT;  eMinFilter=D3DTEXF_POINT;  eMipFilter=D3DTEXF_POINT;  break;
  case 112:  case 12:  eMagFilter=D3DTEXF_POINT;  eMinFilter=D3DTEXF_POINT;  eMipFilter=D3DTEXF_LINEAR; break;
  case 220:  case 20:  eMagFilter=D3DTEXF_LINEAR; eMinFilter=D3DTEXF_LINEAR; eMipFilter=D3DTEXF_NONE;   break;
  case 221:  case 21:  eMagFilter=D3DTEXF_LINEAR; eMinFilter=D3DTEXF_LINEAR; eMipFilter=D3DTEXF_POINT;  break;
  case 222:  case 22:  eMagFilter=D3DTEXF_LINEAR; eMinFilter=D3DTEXF_LINEAR; eMipFilter=D3DTEXF_LINEAR; break;
  case 120:            eMagFilter=D3DTEXF_POINT;  eMinFilter=D3DTEXF_LINEAR; eMipFilter=D3DTEXF_NONE;   break;
  case 121:            eMagFilter=D3DTEXF_POINT;  eMinFilter=D3DTEXF_LINEAR; eMipFilter=D3DTEXF_POINT;  break;
  case 122:            eMagFilter=D3DTEXF_POINT;  eMinFilter=D3DTEXF_LINEAR; eMipFilter=D3DTEXF_LINEAR; break;
  case 210:            eMagFilter=D3DTEXF_LINEAR; eMinFilter=D3DTEXF_POINT;  eMipFilter=D3DTEXF_NONE;   break;
  case 211:            eMagFilter=D3DTEXF_LINEAR; eMinFilter=D3DTEXF_POINT;  eMipFilter=D3DTEXF_POINT;  break;
  case 212:            eMagFilter=D3DTEXF_LINEAR; eMinFilter=D3DTEXF_POINT;  eMipFilter=D3DTEXF_LINEAR; break;
  default: ASSERTALWAYS( "Illegal Direct3D texture filtering mode."); break;
  }
}
static void UpdateEditedTerrainTiles(CTerrain *ptrTerrain, Rect &rcExtract, BufferType btBufferType)
{
  // Update terrain tiles
  if(btBufferType == BT_HEIGHT_MAP) {
    AddFlagsToTilesInRect(ptrTerrain, rcExtract, TT_NO_LODING|TT_QUADTREENODE_REGEN, TRUE);
    UpdateShadowMapRect(ptrTerrain, rcExtract);

  } else if(btBufferType == BT_LAYER_MASK) {
    AddFlagsToTilesInRect(ptrTerrain, rcExtract, TT_NO_LODING|TT_FORCE_TOPMAP_REGEN, TRUE);
    UpdateTerrainGlobalTopMap(ptrTerrain,rcExtract);

  } else if(btBufferType == BT_EDGE_MAP) {
    AddFlagsToTilesInRect(ptrTerrain, rcExtract, TT_NO_LODING|TT_FORCE_TOPMAP_REGEN, TRUE);
    UpdateTerrainGlobalTopMap(ptrTerrain,rcExtract);

  } else {
    ASSERTALWAYS("Ilegal buffer type");
    return;
  }
}
Beispiel #17
0
void CCheckBox::OnClicked() 
{
  BOOL bCheched = FALSE;
  
  switch(GetCheck()) {
    case 0:
      bCheched = FALSE;
    break;
    case 1:
      bCheched = TRUE;
    break;
    default:
      ASSERTALWAYS("Unknown state");
      return;
    break;
  }

  // control is in shader dialog
  theApp.m_dlgBarTreeView.ChangeFlagOnSelectedSurfaces(m_strID,bCheched,m_iIndex);
}
void CWndTerrainTilePalette::OnLButtonUp(UINT nFlags, CPoint point) 
{
  PIXaabbox2D boxPoint( PIX2D( point.x, point.y), PIX2D(point.x, point.y) );
  // for all tiles
  for( INDEX iTile=0; iTile<m_dcTileInfo.Count(); iTile++)
  {
    if( (GetTileBBox(iTile) & boxPoint) == boxPoint)
    {
      CTerrainLayer *ptlLayer=GetLayer();
      if(ptlLayer==NULL) return;
      if( ptlLayer->tl_ltType==LT_TILE)
      {
        ASSERTALWAYS("Undone");
        // ptlLayer->tl_iSelectedTile=iTile;
      }
      break;
    }
  }
  DestroyWindow();
  DeleteTempMap();
}
/*
 * Get placement for a ray through a projected point.
 */
void CParallelProjection3D::RayThroughPoint(const FLOAT3D &v3dViewPoint,
                                               CPlacement3D &plRay) const
{
  ASSERTALWAYS("Function not supported");
}
void CWndTerrainTilePalette::OnPaint() 
{
  ASSERTALWAYS("Undone");
/*
  CTerrainLayer *ptlLayer=GetLayer();
  if(ptlLayer==NULL) return;

  {
  CPaintDC dc(this); // device context for painting
  }
  // skip if already drawing
  extern BOOL _bInTestGame; 
	if( _bInTestGame) return;

  if( m_iTimerID == -1)
  {
    m_iTimerID = (int) SetTimer( 1, 10, NULL);
  }

  POINT ptMouse;
  GetCursorPos( &ptMouse); 
  ScreenToClient( &ptMouse);

  // if there is a valid drawport, and the drawport can be locked
  if(m_pDrawPort != NULL) {
    m_pDrawPort->SetAsCurrent();

    CWorldEditorView *pWorldEditorView = theApp.GetActiveView();
    ASSERT( pWorldEditorView != NULL);
    // clear background
    m_pDrawPort->Fill( C_BLACK|CT_OPAQUE);
    // erase z-buffer
    m_pDrawPort->FillZBuffer(ZBUF_BACK);

    CTextureObject to;
    to.SetData(m_ptd);
    PIX pixTexW=m_ptd->GetPixWidth();
    PIX pixTexH=m_ptd->GetPixHeight();
    PIX pixTileSize=pixTexW/m_ctTilesPerRaw;
    PIX pixdpw=m_pDrawPort->GetWidth();
    PIX pixdph=m_pDrawPort->GetHeight();

    for(INDEX iTile=0; iTile<m_dcTileInfo.Count(); iTile++)
    {
      CTileInfo &ti=m_dcTileInfo[iTile];
      MEXaabbox2D boxTex=MEXaabbox2D(
        MEX2D(ti.ti_ix*pixTileSize, ti.ti_iy*pixTileSize),
        MEX2D((ti.ti_ix+1)*pixTileSize, (ti.ti_iy+1)*pixTileSize) );
      PIXaabbox2D boxScr=GetTileBBox(iTile);

      // draw tile
      FLOAT fU0=boxTex.Min()(1)/(FLOAT)pixTexW;
      FLOAT fV0=boxTex.Min()(2)/(FLOAT)pixTexH;
      FLOAT fU1=boxTex.Min()(1)/(FLOAT)pixTexW;
      FLOAT fV1=boxTex.Max()(2)/(FLOAT)pixTexH;
      FLOAT fU2=boxTex.Max()(1)/(FLOAT)pixTexW;
      FLOAT fV2=boxTex.Max()(2)/(FLOAT)pixTexH;
      FLOAT fU3=boxTex.Max()(1)/(FLOAT)pixTexW;
      FLOAT fV3=boxTex.Min()(2)/(FLOAT)pixTexH;

      FLOAT fI0=boxScr.Min()(1);
      FLOAT fJ0=boxScr.Min()(2);
      FLOAT fI1=boxScr.Min()(1);
      FLOAT fJ1=boxScr.Max()(2);
      FLOAT fI2=boxScr.Max()(1);
      FLOAT fJ2=boxScr.Max()(2);
      FLOAT fI3=boxScr.Max()(1);
      FLOAT fJ3=boxScr.Min()(2);

      if(ti.ti_bFlipX)
      {
        Swap(fI0,fI3);
        Swap(fJ0,fJ3);
        Swap(fI1,fI2);
        Swap(fJ1,fJ2);
      }

      if(ti.ti_bFlipY)
      {
        Swap(fI0,fI1);
        Swap(fJ0,fJ1);
        Swap(fI2,fI3);
        Swap(fJ2,fJ3);
      }

      if(ti.ti_bSwapXY)
      {
        Swap(fI1,fI3);
        Swap(fJ1,fJ3);
      }

      m_pDrawPort->InitTexture( &to);
      COLOR col=C_WHITE|CT_OPAQUE;
      m_pDrawPort->AddTexture(fI0, fJ0, fU0, fV0, col,
                              fI1, fJ1, fU1, fV1, col,
                              fI2, fJ2, fU2, fV2, col,
                              fI3, fJ3, fU3, fV3, col);
      m_pDrawPort->FlushRenderingQueue(); 
      
      // draw border
      m_pDrawPort->DrawBorder( boxScr.Min()(1), boxScr.Min()(2), boxScr.Size()(1), boxScr.Size()(2), C_lGRAY|CT_OPAQUE);
    }
    m_pDrawPort->DrawBorder( 0,0, m_pDrawPort->GetWidth(),m_pDrawPort->GetHeight(), C_vlGRAY|CT_OPAQUE);

    // draw selected tile
    CTileInfo &ti=m_dcTileInfo[ptlLayer->tl_iSelectedTile];    
    MEXaabbox2D boxTex=MEXaabbox2D(
      MEX2D(ti.ti_ix*pixTileSize, ti.ti_iy*pixTileSize),
      MEX2D((ti.ti_ix+1)*pixTileSize, (ti.ti_iy+1)*pixTileSize) );
    PIXaabbox2D boxScr=GetTileBBox(ptlLayer->tl_iSelectedTile);
    TIME tm=_pTimer->GetRealTimeTick();
    FLOAT fFactor=sin(tm*8)/2.0f+0.5f;
    COLOR colSelected=LerpColor(C_vlGRAY,C_RED,fFactor);
    m_pDrawPort->DrawBorder(boxScr.Min()(1), boxScr.Min()(2), 
                            boxScr.Size()(1), boxScr.Size()(2),
                            colSelected|CT_OPAQUE);

    // draw tile under mouse
    PIXaabbox2D boxPoint( PIX2D( ptMouse.x, ptMouse.y), PIX2D(ptMouse.x, ptMouse.y));
    for( INDEX itum=0; itum<m_dcTileInfo.Count(); itum++)
    {
      CTileInfo &ti=m_dcTileInfo[itum];    
      PIXaabbox2D boxScr=GetTileBBox(itum);
      if( (boxScr & boxPoint) == boxPoint)
      {
        INDEX iRot=((ULONG)(tm*25.0f))&7;
        ULONG ulLineType=0x0f0f0f0f<<iRot;
        m_pDrawPort->DrawBorder(boxScr.Min()(1), boxScr.Min()(2), 
                                boxScr.Size()(1), boxScr.Size()(2),
                                C_BLUE|CT_OPAQUE, ulLineType);
        break;
      }
    }

    // if there is a valid viewport
    if (m_pViewPort!=NULL)
    {
      m_pViewPort->SwapBuffers();
    }
  }
*/
}
/*
 * Project 3D object axis aligned bounding box into 3D view space.
 */
void CPerspectiveProjection3D::ProjectAABBox(const FLOATaabbox3D &boxObject,
                                             FLOATaabbox3D &boxView) const
{
  ASSERTALWAYS( "This is not yet implemented");
}
Beispiel #22
0
CTFileName &CTFileName::operator=(const char *strCharString)
{
    ASSERTALWAYS( "Use CTFILENAME for conversion from char *!");
    return *this;
}
void CDlgPgCollision::DoDataExchange(CDataExchange* pDX)
{
  CModelerView *pModelerView = CModelerView::GetActiveView();
  if(pModelerView == NULL) return;
  CModelerDoc* pDoc = pModelerView->GetDocument();  

  // if transfering data from document to dialog
  if( !pDX->m_bSaveAndValidate)
  {
    // get collision min vector
    FLOAT3D vMinCollisionBox = pDoc->m_emEditModel.GetCollisionBoxMin();
    // get collision max vector
    FLOAT3D vMaxCollisionBox = pDoc->m_emEditModel.GetCollisionBoxMax();

    FLOATaabbox3D bboxCollision = FLOATaabbox3D( vMinCollisionBox, vMaxCollisionBox);

    m_fWidth   = bboxCollision.Size()(1);
    m_fHeight  = bboxCollision.Size()(2);
    m_fLenght  = bboxCollision.Size()(3);
    m_fXCenter = bboxCollision.Center()(1);
    m_fYDown   = vMinCollisionBox(2);
    m_fZCenter = bboxCollision.Center()(3);
    
    // set equality radio initial value
    INDEX iEqualityType = pDoc->m_emEditModel.GetCollisionBoxDimensionEquality();

    // get index of curently selected collision box
    char achrString[ 256];
    sprintf( achrString, "%d.", pDoc->m_emEditModel.GetActiveCollisionBoxIndex());
    m_strCollisionBoxIndex = achrString;
    // get name of curently selected collision box
    sprintf( achrString, "%s", pDoc->m_emEditModel.GetCollisionBoxName());
    m_strCollisionBoxName = achrString;

    // enable all controls
    GetDlgItem( IDC_STATIC_WIDTH)->EnableWindow( TRUE);
    GetDlgItem( IDC_EDIT_WIDTH)->EnableWindow( TRUE);
    GetDlgItem( IDC_STATIC_HEIGHT)->EnableWindow( TRUE);
    GetDlgItem( IDC_EDIT_HEIGHT)->EnableWindow( TRUE);
    GetDlgItem( IDC_STATIC_LENGHT)->EnableWindow( TRUE);
    GetDlgItem( IDC_EDIT_LENGHT)->EnableWindow( TRUE);

    m_bCollideAsBox = pDoc->m_emEditModel.edm_md.md_bCollideAsCube;
    // if we are colliding using sphere approximation
    switch( iEqualityType)
    {
      case HEIGHT_EQ_WIDTH:
      {
        m_EqualityRadio = 0;
        if( !m_bCollideAsBox)
        {
          GetDlgItem( IDC_STATIC_HEIGHT)->EnableWindow( FALSE);
          GetDlgItem( IDC_EDIT_HEIGHT)->EnableWindow( FALSE);
          m_fHeight = m_fWidth;
        }
        break;
      }
      case LENGTH_EQ_WIDTH:
      {
        m_EqualityRadio = 1;
        if( !m_bCollideAsBox)
        {
          GetDlgItem( IDC_STATIC_LENGHT)->EnableWindow( FALSE);
          GetDlgItem( IDC_EDIT_LENGHT)->EnableWindow( FALSE);
          m_fLenght = m_fWidth;
        }
        break;
      }
      case LENGTH_EQ_HEIGHT:
      {
        m_EqualityRadio = 2;
        if( !m_bCollideAsBox)
        {
          GetDlgItem( IDC_STATIC_LENGHT)->EnableWindow( FALSE);
          GetDlgItem( IDC_EDIT_LENGHT)->EnableWindow( FALSE);
          m_fLenght = m_fHeight;
        }
        break;
      }
      default:
      {
        ASSERTALWAYS( "None of collision dimensions are the same and that can't be.");
      }
    }
    // mark that the values have been updated to reflect the state of the view
    m_udAllValues.MarkUpdated();
  }
    
  CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgPgCollision)
	DDX_SkyFloat(pDX, IDC_EDIT_WIDTH, m_fWidth);
	DDX_SkyFloat(pDX, IDC_EDIT_HEIGHT, m_fHeight);
	DDX_SkyFloat(pDX, IDC_EDIT_LENGHT, m_fLenght);
	DDX_SkyFloat(pDX, IDC_EDIT_XCENTER, m_fXCenter);
	DDX_SkyFloat(pDX, IDC_EDIT_YDOWN, m_fYDown);
	DDX_SkyFloat(pDX, IDC_EDIT_ZCENTER, m_fZCenter);
	DDX_Radio(pDX, IDC_H_EQ_W, m_EqualityRadio);
	DDX_Text(pDX, IDC_COLLISION_BOX_NAME, m_strCollisionBoxName);
	DDX_Text(pDX, IDC_COLLISION_BOX_INDEX, m_strCollisionBoxIndex);
	DDX_Check(pDX, IDC_COLLIDE_AS_BOX, m_bCollideAsBox);
	//}}AFX_DATA_MAP

  // if transfering data from dialog to document
  if( pDX->m_bSaveAndValidate)
  {
    // if we are colliding using sphere approximation
    if( !pDoc->m_emEditModel.edm_md.md_bCollideAsCube)
    {
      INDEX iEqualityType;
      switch( m_EqualityRadio)
      {
        case 0:
        {
          iEqualityType = HEIGHT_EQ_WIDTH;
          CString strWidth;
          GetDlgItem( IDC_EDIT_WIDTH)->GetWindowText(strWidth);
          GetDlgItem( IDC_EDIT_HEIGHT)->SetWindowText(strWidth);
          break;
        }
        case 1:
        {
          iEqualityType = LENGTH_EQ_WIDTH;
          CString strWidth;
          GetDlgItem( IDC_EDIT_WIDTH)->GetWindowText(strWidth);
          GetDlgItem( IDC_EDIT_LENGHT)->SetWindowText( strWidth );
          break;
        }
        case 2:
        {
          iEqualityType = LENGTH_EQ_HEIGHT;
          CString strHeight;
          GetDlgItem( IDC_EDIT_HEIGHT)->GetWindowText(strHeight);
          GetDlgItem( IDC_EDIT_LENGHT)->SetWindowText( strHeight);
          break;
        }
        default:
        {
          ASSERTALWAYS( "Illegal value found in collision dimensions equality radio.");
        }
      }
      // set collision equality value
      if( pDoc->m_emEditModel.GetCollisionBoxDimensionEquality() != iEqualityType)
      {
        pDoc->m_emEditModel.SetCollisionBoxDimensionEquality( iEqualityType);
      }
    }

    // set name of curently selected collision box
    pDoc->m_emEditModel.SetCollisionBoxName( CTString( m_strCollisionBoxName) );
    
    // get collision min and max vectors
    FLOAT3D vMinCollisionBox;
    FLOAT3D vMaxCollisionBox;
    // get sizing values
    vMinCollisionBox(1) = m_fXCenter-m_fWidth/2.0f;
    vMinCollisionBox(2) = m_fYDown;
    vMinCollisionBox(3) = m_fZCenter-m_fLenght/2.0f;
    // get origin coordinates
    vMaxCollisionBox(1) = m_fXCenter+m_fWidth/2.0f; 
    vMaxCollisionBox(2) = m_fYDown+m_fHeight;
    vMaxCollisionBox(3) = m_fZCenter+m_fLenght/2.0f;
    
    // transfer data from dialog to document
    pDoc->m_emEditModel.SetCollisionBox( vMinCollisionBox, vMaxCollisionBox);

    pDoc->SetModifiedFlag();
    // update all views
    pDoc->UpdateAllViews( NULL);
  }
}
Beispiel #24
0
void CUIImageBox::SetImageByType(eImageType type, int index, int nSyndiType /* = 0 */)
{
	FLOAT fTexWidth;
	FLOAT fTexHeight;
	int nTexRow, nTexCol;
	int nTextureID;
	
	switch(type)
	{
	case IT_EXP://hardcoding	
		{
			nTextureID = 1;
			nTexRow = 15;
			nTexCol = 5;
			m_eUBType = UBET_ITEM;
		} break;
	case IT_SP:	// [090617: selo] SP 이미지 추가 하드코딩
		{
			// only russia sp icon [9/9/2010 rumist]
#if defined (G_RUSSIA)
			nTextureID = 12;
			nTexRow = 0;
			nTexCol = 2;
			m_eUBType = UBET_ITEM;
#else
			nTextureID = 9;
			nTexRow = 12;
			nTexCol = 11;
			m_eUBType = UBET_ITEM;
#endif			
		} break;
	case IT_MONEY:
	case IT_ITEM:
		{
			if(IT_MONEY == type) index = 19;//hardcoding
			CItemData*	pItemData = _pNetwork->GetItemData( index );
			nTextureID = pItemData->GetIconTexID();
			nTexRow = pItemData->GetIconTexRow();
			nTexCol = pItemData->GetIconTexCol();
			m_eUBType = UBET_ITEM;
		} break;
	case IT_SKILL:
		{
			CSkill	&rSkillData = _pNetwork->GetSkillData( index );
			nTextureID = rSkillData.GetIconTexID();
			nTexRow = rSkillData.GetIconTexRow();
			nTexCol = rSkillData.GetIconTexCol();
			m_eUBType = UBET_SKILL;
		} break;
	case IT_SSKILL:// Special Skill
		{
			CSpecialSkill* pSSkillData = CSpecialSkill::getData(index);
			if (pSSkillData == NULL)
				return;
			nTextureID = pSSkillData->GetIconTexID();
			nTexRow = pSSkillData->GetIconTexRow();
			nTexCol = pSSkillData->GetIconTexCol();
			m_eUBType = UBET_SKILL;
		} break;
	case IT_ACTION:
		{
			CAction* pActionData = CAction::getData(index);
			if (pActionData == NULL)
				return;
			nTextureID = pActionData->GetTexID();
			nTexRow = pActionData->GetTexRow();
			nTexCol = pActionData->GetTexCol();
			m_eUBType = UBET_ACTION;
		} break;
	case IT_RVR_POINT:
		{
			nTextureID = 19;
			nTexRow = 2;
			nTexCol = 3;
			m_eUBType = UBET_ITEM;

			// 딜라문 npc면
			if (nSyndiType == 2)	
				nTexCol = 4;
		} break;
	case IT_CORPS:
		{
			InitCorpsImageBox();
			SetImageForCorps( type, index );
			return;
		} break;

	case IT_AFFINITY: // 친화도 개편2 이미지 박스에 친화도 추가 [2/6/2013 Ranma]
		{
			CAffinityData*	rAffinityData = _pNetwork->GetAffinityData();
					
			nTextureID = rAffinityData->GetAffinityDataByIndex(index)->nIconTextureID;
			nTexRow = rAffinityData->GetAffinityDataByIndex(index)->nIconTextureRow;
			nTexCol = rAffinityData->GetAffinityDataByIndex(index)->nIconTextureCol;
			m_eUBType = UBET_SKILL;
		} break;

	case IT_AFFINITY_MONSTER: // 친화도 개편2 이미지 박스에 친화도 추가 [2/6/2013 Ranma]
		{
			CAffinityData* pTempAffinityData = _pNetwork->GetAffinityData();
				
			// 맵은 키값으로 소팅이 되기 때문에 값이 뒤에서부터 들어가 있다. 그래서 뒤에서 부터 값을 가져도록 하자 최대한 근접하게 [2/7/2013 Ranma]
			CAffinityData::mapAffReverseIter itermapBegin = pTempAffinityData->mapAffinity_Data.rbegin();
			CAffinityData::mapAffReverseIter itermapEnd = pTempAffinityData->mapAffinity_Data.rend();
			CAffinityData::mapAffReverseIter itermapP = itermapBegin;
			
			for (; itermapP != itermapEnd; itermapP++)
			{
				int pInfoIndex = (*itermapP).first;

				int nNPCIndex = _pNetwork->GetAffinityData()->GetAdminNPCIndex(pInfoIndex);
							
				std::vector<CAffinityData::_AffinityMonsterInfo>::iterator b, e;
				b = _pNetwork->GetAffinityData()->GetAffinityData(nNPCIndex)->vecMonsterList.begin();
				e = _pNetwork->GetAffinityData()->GetAffinityData(nNPCIndex)->vecMonsterList.end();
				for (int i = 0; b != e; b++, i++)
				{
					if ( b->index ==  index)
					{
						nTextureID = b->TextureID;
						nTexRow = b->TextureRow;
						nTexCol = b->TextureCol;
						m_eUBType = UBET_COMBO;

						fTexWidth = _pUIBtnTexMgr->GetTexWidth( UIBtnExType(m_eUBType), nTextureID );
						fTexHeight = _pUIBtnTexMgr->GetTexHeight( UIBtnExType(m_eUBType), nTextureID );
						m_ptdBaseTexture = _pUIBtnTexMgr->GetTex( UIBtnExType(m_eUBType), nTextureID );
						m_ptdBaseTexture->AddReference();
						
						int	nUVSX = 50 * nTexCol;
						int	nUVSY = 50 * nTexRow;
						SetUV( nUVSX, nUVSY, nUVSX + 50, nUVSY + 50, fTexWidth, fTexHeight );
						
						m_eImageType = type;
						m_nTextureID = nTextureID;
						return;
					}
				}
			}
		} break;

	default:
		{
			ASSERTALWAYS("Somthing wrong");
		} break;
	}

	fTexWidth = _pUIBtnTexMgr->GetTexWidth( UIBtnExType(m_eUBType), nTextureID );
	fTexHeight = _pUIBtnTexMgr->GetTexHeight( UIBtnExType(m_eUBType), nTextureID );
	m_ptdBaseTexture = _pUIBtnTexMgr->GetTex( UIBtnExType(m_eUBType), nTextureID );
	m_ptdBaseTexture->AddReference();

	int	nUVSX = BTN_SIZE * nTexCol;
	int	nUVSY = BTN_SIZE * nTexRow;
	SetUV( nUVSX, nUVSY, nUVSX + BTN_SIZE, nUVSY + BTN_SIZE, fTexWidth, fTexHeight );

	m_eImageType = type;
	m_nTextureID = nTextureID;
}
/*
 * Copy one entity property from property of another entity.
 */
void CEntity::CopyOneProperty( CEntityProperty &epPropertySrc, CEntityProperty &epPropertyDest,
                               CEntity &enOther, ULONG ulFlags)
{
// a helper macro
#define COPYPROPERTY(flag)                                            \
  (flag &)ENTITYPROPERTY(this, epPropertyDest.ep_slOffset, flag)      \
    = (flag &)ENTITYPROPERTY(&enOther, epPropertySrc.ep_slOffset, flag)

  // depending on the property type
  switch (epPropertySrc.ep_eptType) {
  // if it is BOOL
  case CEntityProperty::EPT_BOOL:
    // copy BOOL
    COPYPROPERTY(INDEX);
    break;
  // if it is INDEX
  case CEntityProperty::EPT_INDEX:
  case CEntityProperty::EPT_ENUM:
  case CEntityProperty::EPT_FLAGS:
  case CEntityProperty::EPT_ANIMATION:
  case CEntityProperty::EPT_ILLUMINATIONTYPE:
  case CEntityProperty::EPT_COLOR:
  case CEntityProperty::EPT_ANGLE:
    // copy INDEX
    COPYPROPERTY(INDEX);
    break;
  // if it is FLOAT
  case CEntityProperty::EPT_FLOAT:
  case CEntityProperty::EPT_RANGE:
    // copy FLOAT
    COPYPROPERTY(FLOAT);
    break;
  // if it is STRING
  case CEntityProperty::EPT_STRING:
  case CEntityProperty::EPT_STRINGTRANS:
    // copy STRING
    COPYPROPERTY(CTString);
    break;
  // if it is FILENAME
  case CEntityProperty::EPT_FILENAME:
    // copy FILENAME
    COPYPROPERTY(CTFileName);
    break;
  // if it is FILENAMENODEP
  case CEntityProperty::EPT_FILENAMENODEP:
    // copy FILENAMENODEP
    COPYPROPERTY(CTFileNameNoDep);
    break;
  // if it is FLOATAABBOX3D
  case CEntityProperty::EPT_FLOATAABBOX3D:
    // copy FLOATAABBOX3D
    COPYPROPERTY(FLOATaabbox3D);
    break;
  // if it is FLOATMATRIX3D
  case CEntityProperty::EPT_FLOATMATRIX3D:
    // copy FLOATMATRIX3D
    COPYPROPERTY(FLOATmatrix3D);
    break;
    
  // if it is FLOAT3D
  case CEntityProperty::EPT_FLOAT3D:
    // copy FLOAT3D
    COPYPROPERTY(FLOAT3D);
    break;
  // if it is ANGLE3D
  case CEntityProperty::EPT_ANGLE3D:
    // copy ANGLE3D
    COPYPROPERTY(ANGLE3D);
    break;
  // if it is QUATERNION3D
  case CEntityProperty::EPT_FLOATQUAT3D:
    // copy ANGLE3D
    COPYPROPERTY(FLOATquat3D);
    break;
  // if it is FLOATplane3D
  case CEntityProperty::EPT_FLOATplane3D:
    // copy FLOATplane3D
    COPYPROPERTY(FLOATplane3D);
    break;
  // if it is ENTITYPTR
  case CEntityProperty::EPT_ENTITYPTR:
    // remap and copy the pointer
    if (ulFlags & COPY_REMAP) {
      ENTITYPROPERTY(this, epPropertyDest.ep_slOffset, CEntityPointer) =
        FindRemappedEntityPointer(ENTITYPROPERTY(&enOther, epPropertySrc.ep_slOffset, CEntityPointer));
    // copy CEntityPointer
    } else {
      COPYPROPERTY(CEntityPointer);
    }
    break;
  // if it is MODELOBJECT
  case CEntityProperty::EPT_MODELOBJECT:
    // copy CModelObject
    ENTITYPROPERTY(this, epPropertyDest.ep_slOffset, CModelObject).
      Copy(ENTITYPROPERTY(&enOther, epPropertySrc.ep_slOffset, CModelObject));
    // model objects are not copied, but should be initialized in Main()
    break;
  // if it is MODELINSTANCE
  case CEntityProperty::EPT_MODELINSTANCE:
    // copy CModelInstance
    ENTITYPROPERTY(this, epPropertyDest.ep_slOffset, CModelInstance).
      Copy(ENTITYPROPERTY(&enOther, epPropertySrc.ep_slOffset, CModelInstance));
    // model objects are not copied, but should be initialized in Main()
    break;
  // if it is ANIMOBJECT
  case CEntityProperty::EPT_ANIMOBJECT:
    // copy CAnimObject
    ENTITYPROPERTY(this, epPropertyDest.ep_slOffset, CAnimObject).
      Copy(ENTITYPROPERTY(&enOther, epPropertySrc.ep_slOffset, CAnimObject));
    break;
  // if it is SOUNDOBJECT
  case CEntityProperty::EPT_SOUNDOBJECT:
    {
      // copy CSoundObject
      CSoundObject &so = ENTITYPROPERTY(this, epPropertyDest.ep_slOffset, CSoundObject);
      so.Copy(ENTITYPROPERTY(&enOther, epPropertySrc.ep_slOffset, CSoundObject));
      so.so_penEntity = this;
    }
    break;
  // if it is CPlacement3D
  case CEntityProperty::EPT_PLACEMENT3D:
    // copy CPlacement3D
    COPYPROPERTY(CPlacement3D);
    break;
  default:
    ASSERTALWAYS("Unknown property type");
  }
}
Beispiel #26
0
void CImageInfo::LoadTGA_t( const CTFileName &strFileName) // throw char *
{
  TGAHeader *pTGAHdr;
  UBYTE *pTGABuffer, *pTGAImage;
  SLONG slFileSize;
  CTFileStream TGAFile;

  Clear();

  // determine file size
  TGAFile.Open_t( strFileName, CTStream::OM_READ);
  slFileSize = TGAFile.GetStreamSize();

  // load entire TGA file to memory, as is, and close it (no further usage)
  pTGABuffer = (UBYTE*)AllocMemory( slFileSize);
  TGAFile.Read_t( pTGABuffer, slFileSize);
  TGAFile.Close();

  // TGA header starts at the begining of the TGA file
  pTGAHdr = (struct TGAHeader*)pTGABuffer;
  // TGA image bytes definition follows up
  pTGAImage = pTGABuffer + sizeof(struct TGAHeader) + pTGAHdr->IdLenght;

  // detremine picture size dimensions
  ii_Width        = (SLONG)pTGAHdr->Width;
  ii_Height       = (SLONG)pTGAHdr->Height;
  ii_BitsPerPixel = (SLONG)pTGAHdr->BitsPerPixel;
  SLONG slBytesPerPixel = ii_BitsPerPixel/8;
  PIX pixBitmapSize     = ii_Width*ii_Height;
  BOOL bAlphaChannel    = (slBytesPerPixel==4);

  // check for supported file types
  ASSERT( slBytesPerPixel==3 || slBytesPerPixel==4);
  if( slBytesPerPixel!=3 && slBytesPerPixel!=4) throw( TRANS("Unsupported BitsPerPixel in TGA format."));

  // allocate memory for image content
  ii_Picture = (UBYTE*)AllocMemory( ii_Width*ii_Height *slBytesPerPixel);
  UBYTE *pubSrc = pTGAImage;  // need 'walking' pointers
  UBYTE *pubDst = ii_Picture;

  // determine TGA image type
  if( pTGAHdr->ImageType==10) {
    // RLE encoded
    UBYTE ubControl;
    INDEX iBlockSize;
    BOOL  bRepeat;
    PIX pixCurrentSize=0;
    // loop thru blocks
    while( pixCurrentSize<pixBitmapSize)
    { // readout control byte
      ubControl  = *pubSrc++;
      bRepeat    =  ubControl&0x80;
      iBlockSize = (ubControl&0x7F) +1;
      // repeat or copy color values
      for( INDEX i=0; i<iBlockSize; i++) {
        *pubDst++ = pubSrc[0]; 
        *pubDst++ = pubSrc[1]; 
        *pubDst++ = pubSrc[2]; 
        if( bAlphaChannel) *pubDst++ = pubSrc[3];
        if( !bRepeat) pubSrc += slBytesPerPixel;
      }
      // advance for next block if repeated
      if( bRepeat) pubSrc += slBytesPerPixel;
      // update image size
      pixCurrentSize += iBlockSize;
    }
    // mark that image was encoded to ImageInfo buffer
    pTGAImage = ii_Picture; 
  } 
  // not true-colored?
  else if( pTGAHdr->ImageType!=2) {
    // whoops!
    ASSERTALWAYS("Unsupported TGA format.");
    throw( TRANS("Unsupported TGA format."));
  }

  // determine image flipping
  INDEX iFlipType;
  switch( (pTGAHdr->Descriptor&0x30)>>4) {
  case 0:  iFlipType = 1;  break; // vertical flipping
  case 1:  iFlipType = 3;  break; // diagonal flipping
  case 3:  iFlipType = 2;  break; // horizontal flipping
  default: iFlipType = 0;  break; // no flipping (just copying)
  }
  // do flipping
  FlipBitmap( pTGAImage, ii_Picture, ii_Width, ii_Height, iFlipType, bAlphaChannel);

  // convert TGA pixel format to CroTeam
  pubSrc = ii_Picture;  // need 'walking' pointer again
  for( INDEX iPix=0; iPix<pixBitmapSize; iPix++)
  { // flip bytes
    Swap( pubSrc[0], pubSrc[2]);  // R & B channels
    pubSrc += slBytesPerPixel; 
  }

  // free temorary allocated memory for TGA image format
  FreeMemory( pTGABuffer);
}
UWORD *GetBufferForEditing(CTerrain *ptrTerrain, Rect &rcExtract, BufferType btBufferType, INDEX iBufferData/*=-1*/)
{
  ASSERT(ptrTerrain!=NULL);
  ASSERT(rcExtract.Width()>0);
  ASSERT(rcExtract.Height()>0);

  PIX pixLeft   = rcExtract.rc_iLeft;
  PIX pixRight  = rcExtract.rc_iRight;
  PIX pixTop    = rcExtract.rc_iTop;
  PIX pixBottom = rcExtract.rc_iBottom;

  PIX pixWidht  = pixRight-pixLeft;
  PIX pixHeight = pixBottom-pixTop;
  PIX pixMaxWidth  = ptrTerrain->tr_pixHeightMapWidth;
  PIX pixMaxHeight = ptrTerrain->tr_pixHeightMapHeight;

  // allocate memory for editing buffer
  UWORD *pauwEditingBuffer = (UWORD*)AllocMemory(pixWidht*pixHeight*sizeof(UWORD));

  // Get pointer to first member in editing pointer
  UWORD *puwBufferData = &pauwEditingBuffer[0];

  // if buffer type is height map
  if(btBufferType==BT_HEIGHT_MAP) {
    // Extract data from terrain height map
    UWORD *puwFirstInHeightMap = &ptrTerrain->tr_auwHeightMap[0];
    // for each row
    for(PIX pixY=pixTop;pixY<pixBottom;pixY++) {
      PIX pixRealY = Clamp(pixY,0,pixMaxHeight-1);
      // for each col
      for(PIX pixX=pixLeft;pixX<pixRight;pixX++) {
        PIX pixRealX = Clamp(pixX,0,pixMaxWidth-1);
        // Copy current pixel from height map to dest buffer
        UWORD *puwHeight = &puwFirstInHeightMap[pixRealX + pixRealY*pixMaxWidth];
        *puwBufferData = *puwHeight;
        puwBufferData++;
      }
    }
  // if buffer type is layer mask
  } else if(btBufferType==BT_LAYER_MASK) {
    // Extract data from layer mask
    CTerrainLayer &tl = ptrTerrain->GetLayer(iBufferData);
    UBYTE *pubFirstInLayer  = &tl.tl_aubColors[0];
    // for each row
    for(PIX pixY=pixTop;pixY<pixBottom;pixY++) {
      PIX pixRealY = Clamp(pixY,0,pixMaxHeight-1);
      // for each col
      for(PIX pixX=pixLeft;pixX<pixRight;pixX++) {
        PIX pixRealX = Clamp(pixX,0,pixMaxWidth-1);
        // Copy current pixel from layer mask to dest buffer
        UBYTE *pubMaskValue = &pubFirstInLayer[pixRealX + pixRealY*pixMaxWidth];
        *puwBufferData = (*pubMaskValue)<<8|(*pubMaskValue);
        puwBufferData++;
      }
    }
  // if buffer type is edge map
  } else if(btBufferType==BT_EDGE_MAP) {
    // Extract data from edge map
    UBYTE *pubFirstInEdgeMap = &ptrTerrain->tr_aubEdgeMap[0];
    // for each row
    for(PIX pixY=pixTop;pixY<pixBottom;pixY++) {
      PIX pixRealY = Clamp(pixY,0,pixMaxHeight-1);
      // for each col
      for(PIX pixX=pixLeft;pixX<pixRight;pixX++) {
        PIX pixRealX = Clamp(pixX,0,pixMaxWidth-1);
        // Copy current pixel from layer mask to dest buffer
        UBYTE *pubEdgeValue = &pubFirstInEdgeMap[pixRealX + pixRealY*pixMaxWidth];
        if((*pubEdgeValue)==255) {
          *puwBufferData = 1;
        } else {
          *puwBufferData = 0;
        }
        puwBufferData++;
      }
    }
  } else {
    ASSERTALWAYS("Ilegal buffer type");
  }

  return &pauwEditingBuffer[0];
}
void CDlgRenderingPreferences::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);

  CModelRenderPrefs &pmrpPrefs = theApp.m_vpViewPrefs[ m_iBuffer].m_mrpModelRenderPrefs;
  CWorldRenderPrefs &pwrpPrefs = theApp.m_vpViewPrefs[ m_iBuffer].m_wrpWorldRenderPrefs;
  // if dialog is recieving data
  if( (pDX->m_bSaveAndValidate == FALSE) && IsWindow( m_hWnd) &&
      IsWindow( m_VertexFillType.m_hWnd) &&
      IsWindow( m_EdgesFillType.m_hWnd) &&
      IsWindow( m_PolygonFillType.m_hWnd) &&
      IsWindow( m_TextureFillType.m_hWnd) )      
  {
    // world rendering preferences
    m_VertexColors.SetColor( pwrpPrefs.GetVerticesInkColor());
    m_EdgesColors.SetColor( pwrpPrefs.GetEdgesInkColor());
    m_PolygonColors.SetColor( pwrpPrefs.GetPolygonsInkColor());
    m_PaperColor.SetColor( theApp.m_vpViewPrefs[ m_iBuffer].m_PaperColor);
    m_SelectionColor.SetColor( theApp.m_vpViewPrefs[ m_iBuffer].m_SelectionColor);
    m_GridColor.SetColor( theApp.m_vpViewPrefs[ m_iBuffer].m_GridColor);
    m_fFarClipPlane=pwrpPrefs.wrp_fFarClipPlane;
    m_bApplyFarClipInIsometricProjection=pwrpPrefs.wrp_bApplyFarClipPlaneInIsometricProjection;
    
    m_strBcgTexture = CTFileName(CTString( theApp.m_vpViewPrefs[ m_iBuffer].m_achrBcgPicture)).FileName();

    // get render editor models flag
    m_bRenderEditorModels = pwrpPrefs.IsEditorModelsOn();
    // get render field brushes flag
    m_bRenderFieldBrushes = pwrpPrefs.IsFieldBrushesOn();
    // get use texture for background flag
    m_bUseTextureForBcg = pwrpPrefs.IsBackgroundTextureOn();

    m_bRenderMirrors = pwrpPrefs.IsMirrorsOn();
    m_bRenderFog = pwrpPrefs.IsFogOn();
    m_bRenderHaze = pwrpPrefs.IsHazeOn();

    // get auto rendering range flag
    m_bAutoRenderingRange = theApp.m_vpViewPrefs[ m_iBuffer].m_bAutoRenderingRange;
    // get rendering range
    m_fRenderingRange = theApp.m_vpViewPrefs[ m_iBuffer].m_fRenderingRange;
    // enable/disable edit render range control depending on auto range flag
    UpdateEditRangeControl();

    // fill values for vertice's combo box
    m_VertexFillType.ResetContent();
    m_VertexFillType.AddString( L"No vertices");
    m_VertexFillType.AddString( L"Vertices ink");
    m_VertexFillType.AddString( L"Polygon color");
    m_VertexFillType.AddString( L"Sector color");
    // fill values for edges's combo box
    m_EdgesFillType.ResetContent();
    m_EdgesFillType.AddString( L"No edges");
    m_EdgesFillType.AddString( L"Edges ink");
    m_EdgesFillType.AddString( L"Polygon color");
    m_EdgesFillType.AddString( L"Sector color");
    // fill values for polygons's combo box
    m_PolygonFillType.ResetContent();
    m_PolygonFillType.AddString( L"No polygons");
    m_PolygonFillType.AddString( L"Polygons ink");
    m_PolygonFillType.AddString( L"Polygon color");
    m_PolygonFillType.AddString( L"Sector color");
    m_PolygonFillType.AddString( L"Texture");
    // fill values for model's texture combo
    m_TextureFillType.ResetContent();
    m_TextureFillType.AddString( L"No fill");
    m_TextureFillType.AddString( L"White color");
    m_TextureFillType.AddString( L"Surface colors");
    m_TextureFillType.AddString( L"On colors");
    m_TextureFillType.AddString( L"Off colors");
    m_TextureFillType.AddString( L"Texture");
    // fill values for flare FX combo
    m_comboFlareFX.ResetContent();
    m_comboFlareFX.AddString( L"None");
    m_comboFlareFX.AddString( L"Single flare");
    m_comboFlareFX.AddString( L"Reflections");
    m_comboFlareFX.AddString( L"Reflections and glare");
  	  
    INDEX iFillType;
    // set current fill type to vertices combo box
    iFillType = pwrpPrefs.GetVerticesFillType();
    m_VertexFillType.SetCurSel( iFillType);
    // set current fill type to edges combo box
    iFillType = pwrpPrefs.GetEdgesFillType();
    m_EdgesFillType.SetCurSel( iFillType);
    // set current fill type to polygons combo box
    iFillType = pwrpPrefs.GetPolygonsFillType();
    m_PolygonFillType.SetCurSel( iFillType);
    // set currently selected modeler's texture rendering type
    ULONG rtRenderType = pmrpPrefs.GetRenderType();
    iFillType = 0;
    if( (rtRenderType & RT_NO_POLYGON_FILL) != 0)       iFillType = 0;
    else if( (rtRenderType & RT_WHITE_TEXTURE) != 0)    iFillType = 1;
    else if( (rtRenderType & RT_SURFACE_COLORS) != 0)   iFillType = 2;
    else if( (rtRenderType & RT_ON_COLORS) != 0)        iFillType = 3;
    else if( (rtRenderType & RT_OFF_COLORS) != 0)       iFillType = 4;
    else if( (rtRenderType & RT_TEXTURE) != 0)          iFillType = 5;
    m_TextureFillType.SetCurSel( iFillType);

    enum CWorldRenderPrefs::LensFlaresType lftFlareFX = pwrpPrefs.GetLensFlares();
    m_comboFlareFX.SetCurSel( (INDEX) lftFlareFX);

    // set model rendering flags
    m_bBoundingBox = pmrpPrefs.BBoxAllVisible();
    m_bHidenLines = pmrpPrefs.HiddenLines();
    m_bShadows = pmrpPrefs.GetShadowQuality() == 0;
    m_bWireFrame = pmrpPrefs.WireOn();
  }

  //{{AFX_DATA_MAP(CDlgRenderingPreferences)
	DDX_Control(pDX, IDC_FLARE_FX, m_comboFlareFX);
	DDX_Control(pDX, IDC_SELECTION_COLOR, m_SelectionColor);
	DDX_Control(pDX, IDC_GRID_COLOR, m_GridColor);
	DDX_Control(pDX, IDC_PAPER_COLOR, m_PaperColor);
	DDX_Control(pDX, IDC_TEXTURE_FILL_TYPE, m_TextureFillType);
	DDX_Control(pDX, IDC_EDGES_FILL_TYPE, m_EdgesFillType);
	DDX_Control(pDX, IDC_POLYGON_FILL_TYPE, m_PolygonFillType);
	DDX_Control(pDX, IDC_VERTEX_FILL_TYPE, m_VertexFillType);
	DDX_Control(pDX, IDC_VERTEX_COLORS, m_VertexColors);
	DDX_Control(pDX, IDC_POLYGON_COLORS, m_PolygonColors);
	DDX_Control(pDX, IDC_EDGES_COLORS, m_EdgesColors);
	DDX_Check(pDX, IDC_BBOX, m_bBoundingBox);
	DDX_Check(pDX, IDC_HIDEN_LINES, m_bHidenLines);
	DDX_Check(pDX, IDC_SHADOWS, m_bShadows);
	DDX_Check(pDX, IDC_WIRE_FRAME, m_bWireFrame);
	DDX_Text(pDX, IDC_RENDERING_RANGE, m_fRenderingRange);
	DDV_MinMaxFloat(pDX, m_fRenderingRange, 1.f, 10000.f);
	DDX_Check(pDX, IDC_AUTO_RENDERING_RANGE, m_bAutoRenderingRange);
	DDX_Check(pDX, IDC_RENDER_EDITOR_MODELS, m_bRenderEditorModels);
	DDX_Check(pDX, IDC_USE_TEXTURE_FOR_BCG, m_bUseTextureForBcg);
	DDX_Check(pDX, IDC_RENDER_FIELDS, m_bRenderFieldBrushes);
	DDX_Check(pDX, IDC_RENDER_FOG, m_bRenderFog);
	DDX_Check(pDX, IDC_RENDER_HAZE, m_bRenderHaze);
	DDX_Check(pDX, IDC_RENDER_MIRRORS, m_bRenderMirrors);
	DDX_Text(pDX, IDC_BCG_PICTURE_T, m_strBcgTexture);
	DDX_Text(pDX, IDC_FAR_CLIP_PLANE, m_fFarClipPlane);
	DDV_MinMaxFloat(pDX, m_fFarClipPlane, -1.f, 1.e+007f);
	DDX_Check(pDX, IDC_APPLY_CLIP_FOR_ISOMETRIC, m_bApplyFarClipInIsometricProjection);
	//}}AFX_DATA_MAP

  // if dialog is giving data
  if( pDX->m_bSaveAndValidate != FALSE)
  {
    // set auto rendering range flag
    theApp.m_vpViewPrefs[ m_iBuffer].m_bAutoRenderingRange = m_bAutoRenderingRange;

    // set rendering range
    theApp.m_vpViewPrefs[ m_iBuffer].m_fRenderingRange = m_fRenderingRange;

    // set drawing of editor models on or off
    pwrpPrefs.SetEditorModelsOn( m_bRenderEditorModels);
    // set render field brushes flag
    pwrpPrefs.SetFieldBrushesOn( m_bRenderFieldBrushes);
    // set use texture for background flag
    pwrpPrefs.SetBackgroundTextureOn( m_bUseTextureForBcg);

    pwrpPrefs.SetMirrorsOn( m_bRenderMirrors);
    pwrpPrefs.SetFogOn( m_bRenderFog);
    pwrpPrefs.SetHazeOn( m_bRenderHaze);

    // enable/disable edit render range control depending on auto range flag
    UpdateEditRangeControl();

    // set colors
    pwrpPrefs.SetVerticesInkColor( m_VertexColors.GetColor());
    pwrpPrefs.SetEdgesInkColor( m_EdgesColors.GetColor());
    pwrpPrefs.SetPolygonsInkColor( m_PolygonColors.GetColor());
    theApp.m_vpViewPrefs[ m_iBuffer].m_PaperColor = m_PaperColor.GetColor();
    theApp.m_vpViewPrefs[ m_iBuffer].m_GridColor = m_GridColor.GetColor();
    theApp.m_vpViewPrefs[ m_iBuffer].m_SelectionColor = m_SelectionColor.GetColor();
    pwrpPrefs.wrp_fFarClipPlane=m_fFarClipPlane;
    pwrpPrefs.wrp_bApplyFarClipPlaneInIsometricProjection=m_bApplyFarClipInIsometricProjection;
    enum CWorldRenderPrefs::FillType ftFillType;
    // get current fill type from vertices combo box
    ftFillType = (enum CWorldRenderPrefs::FillType) m_VertexFillType.GetCurSel();
    pwrpPrefs.SetVerticesFillType( ftFillType);
    // get current fill type from edges combo box
    ftFillType = (enum CWorldRenderPrefs::FillType) m_EdgesFillType.GetCurSel();
    pwrpPrefs.SetEdgesFillType( ftFillType);
    // get current fill type from polygons combo box
    ftFillType = (enum CWorldRenderPrefs::FillType) m_PolygonFillType.GetCurSel();
    pwrpPrefs.SetPolygonsFillType( ftFillType);

    enum CWorldRenderPrefs::LensFlaresType lftFlares;
    // get type for rendering flares
    lftFlares = (enum CWorldRenderPrefs::LensFlaresType) m_comboFlareFX.GetCurSel();
    pwrpPrefs.SetLensFlaresType( lftFlares);

    // get current model's texturizing type from model's texture combo box
    ULONG ulMdlFillType;
    ulMdlFillType = m_TextureFillType.GetCurSel();
    switch( ulMdlFillType)
    {
      case 0: {
        pmrpPrefs.SetRenderType( RT_NO_POLYGON_FILL);
        break;
      }
      case 1: {
        pmrpPrefs.SetRenderType( RT_WHITE_TEXTURE);
        break;
      }
      case 2: {
        pmrpPrefs.SetRenderType( RT_SURFACE_COLORS);
        break;
      }
      case 3: {
        pmrpPrefs.SetRenderType( RT_ON_COLORS);
        break;
      }
      case 4: {
        pmrpPrefs.SetRenderType( RT_OFF_COLORS);
        break;
      }
      case 5: {
        pmrpPrefs.SetRenderType( RT_TEXTURE);
        break;
      }
      default: {
        ASSERTALWAYS( "Invalid selection found in model's texture combo box");
      }
    }
    // get rest of model's rendering preferences
    pmrpPrefs.SetWire( m_bWireFrame);
    pmrpPrefs.SetHiddenLines( m_bHidenLines);
    pmrpPrefs.BBoxAllShow( m_bBoundingBox);
    if( m_bShadows) {
      pmrpPrefs.SetShadowQuality( 0);
    } else {
      pmrpPrefs.SetShadowQuality( 255);
    }
  }
}