You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
616 lines
17 KiB
616 lines
17 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: Shadow.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of Shadow.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "shadow.h"
|
|
#include "detector.h"
|
|
#include "..\LgLib\version.h"
|
|
|
|
BOOL CShadow::AddShadow( INT nAngle, BYTE bType, INT nMin, INT nMax )
|
|
{
|
|
if( LGS_MAX_SHADOW_ANGLES <= nAngle )
|
|
return FALSE;
|
|
|
|
// range should be in the same system ( 0..2047 )
|
|
LPRAY_LINE pShadowLine = &m_pShadowLine[ (INT)nAngle ];
|
|
|
|
// realloc memory for shadows
|
|
pShadowLine->lpShadow = (LPRAY)farrealloc( pShadowLine->lpShadow,
|
|
sizeof( RAY ) * ( pShadowLine->nCount + 1 ) );
|
|
if( !pShadowLine->lpShadow )
|
|
{
|
|
pShadowLine->nCount = 0;
|
|
return FALSE;
|
|
}
|
|
|
|
// store shadow
|
|
pShadowLine->lpShadow[ pShadowLine->nCount ].bType = bType;
|
|
pShadowLine->lpShadow[ pShadowLine->nCount ].nMin = nMin;
|
|
pShadowLine->lpShadow[ pShadowLine->nCount ].nMax = nMax;
|
|
pShadowLine->nCount++;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CShadow::Destroy()
|
|
{
|
|
for( INT i = 0; i < LGS_MAX_SHADOW_ANGLES; i++ )
|
|
{
|
|
if( m_pShadowLine[i].lpShadow )
|
|
{
|
|
farfree( m_pShadowLine[i].lpShadow );
|
|
m_pShadowLine[i].lpShadow = NULL;
|
|
}
|
|
|
|
m_pShadowLine[i].nCount = 0;
|
|
}
|
|
|
|
for( i = 0; i < m_nPolygon; i++ )
|
|
if( m_lpPolygon[i].lpPoint )
|
|
farfree( m_lpPolygon[i].lpPoint );
|
|
|
|
m_nPolygon = 0;
|
|
|
|
if( m_lpPolygon )
|
|
{
|
|
farfree( m_lpPolygon );
|
|
m_lpPolygon = NULL;
|
|
}
|
|
}
|
|
|
|
BOOL CShadow::LoadRays( PCHAR pFileName )
|
|
{
|
|
FILE *pFile = fopen( pFileName, "rt" );
|
|
if( !pFile )
|
|
return TRUE;
|
|
|
|
// while not end-of-file
|
|
while( !feof( pFile ) )
|
|
{
|
|
const INT nMaxLineLength = 128;
|
|
CHAR pBuffer[ nMaxLineLength ];
|
|
|
|
// get line string from file
|
|
if( fgets( pBuffer, nMaxLineLength, pFile ) )
|
|
{
|
|
INT nAngle;
|
|
INT bType;
|
|
INT nMin;
|
|
INT nMax;
|
|
|
|
// load shadow from line
|
|
if( sscanf( pBuffer, "%d %d %d %d", &nAngle, &bType, &nMin, &nMax ) == 4 )
|
|
// add shadow
|
|
AddShadow( nAngle, bType, nMin, nMax );
|
|
}
|
|
}
|
|
|
|
fclose( pFile );
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CShadow::LoadPolygons( PCHAR pFileName )
|
|
{
|
|
FILE *pFile = fopen( pFileName, "rt" );
|
|
if( !pFile )
|
|
return TRUE;
|
|
|
|
INT nPolygon = 0;
|
|
INT nPolygonPoint = 0;
|
|
|
|
// while not end-of-file
|
|
while( !feof( pFile ) )
|
|
{
|
|
const INT nMaxLineLength = 1024;
|
|
CHAR pBuffer[ nMaxLineLength ];
|
|
|
|
// get line string from file
|
|
if( fgets( pBuffer, nMaxLineLength, pFile ) )
|
|
{
|
|
// load shadow from line
|
|
if( strstr( pBuffer, "type" ) )
|
|
{
|
|
DWORD dwTypeOn;
|
|
if( sscanf( pBuffer, "type %lu", &dwTypeOn ) == 1 )
|
|
{
|
|
m_dwTypeOn = dwTypeOn;
|
|
for( INT i = 0; i < LGS_MAX_SHADOW_TYPES; i++ )
|
|
{
|
|
DWORD bBit = 1 << i;
|
|
m_pTypeOn[i] = ( m_dwTypeOn & bBit ) == bBit;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
// load shadow from line
|
|
if( strstr( pBuffer, "polygon" ) )
|
|
{
|
|
INT nType;
|
|
if( sscanf( pBuffer, "polygon %d", &nType ) == 1 )
|
|
{
|
|
nPolygon++;
|
|
nPolygonPoint = 0;
|
|
|
|
if( m_nPolygon < nPolygon )
|
|
{
|
|
m_lpPolygon = (LPHZ_POLYGON)farrealloc( m_lpPolygon, nPolygon * sizeof(HZ_POLYGON) );
|
|
if( !m_lpPolygon )
|
|
{
|
|
m_nPolygon = 0;
|
|
fclose( pFile );
|
|
return TRUE;
|
|
}
|
|
m_lpPolygon[nPolygon-1].lpPoint = NULL;
|
|
m_lpPolygon[nPolygon-1].wCount = 0;
|
|
m_lpPolygon[nPolygon-1].bType = nType;
|
|
m_nPolygon = nPolygon;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
if( nPolygon )
|
|
{
|
|
INT nX,nY;
|
|
if( sscanf( pBuffer, "%d %d", &nX, &nY ) == 2 )
|
|
{
|
|
nPolygonPoint++;
|
|
|
|
if( m_lpPolygon[nPolygon-1].wCount < nPolygonPoint )
|
|
{
|
|
m_lpPolygon[nPolygon-1].lpPoint = (LGS::LPHZ_POINT)farrealloc( m_lpPolygon[nPolygon-1].lpPoint, nPolygonPoint * sizeof(LGS::HZ_POINT) );
|
|
if( !m_lpPolygon[nPolygon-1].lpPoint )
|
|
{
|
|
m_lpPolygon[nPolygon-1].wCount = 0;
|
|
fclose( pFile );
|
|
return TRUE;
|
|
}
|
|
m_lpPolygon[nPolygon-1].lpPoint[nPolygonPoint-1].wX = nX;
|
|
m_lpPolygon[nPolygon-1].lpPoint[nPolygonPoint-1].wY = nY;
|
|
m_lpPolygon[nPolygon-1].wCount = nPolygonPoint;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
fclose( pFile );
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CShadow::SaveRays( PCHAR pFileName )
|
|
{
|
|
FILE *pFile = fopen( pFileName, "wt" );
|
|
if( !pFile )
|
|
return TRUE;
|
|
|
|
// while not end-of-file
|
|
for( INT i = 0; i < LGS_MAX_SHADOW_ANGLES; i++ )
|
|
{
|
|
for( INT j = 0; j < m_pShadowLine[i].nCount; j++ )
|
|
{
|
|
// load shadow from line
|
|
fprintf( pFile, "%d %d %d %d\n", i, m_pShadowLine[i].lpShadow[j].bType, m_pShadowLine[i].lpShadow[j].nMin, m_pShadowLine[i].lpShadow[j].nMax );
|
|
}
|
|
}
|
|
|
|
fclose( pFile );
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CShadow::SavePolygons( PCHAR pFileName )
|
|
{
|
|
FILE *pFile = fopen( pFileName, "wt" );
|
|
if( !pFile )
|
|
return TRUE;
|
|
|
|
// save shadow from line
|
|
fprintf( pFile, "type %lu\n", m_dwTypeOn );
|
|
|
|
// while not end-of-file
|
|
for( INT i = 0; i < m_nPolygon; i++ )
|
|
{
|
|
// save shadow from line
|
|
fprintf( pFile, "polygon %d\n", m_lpPolygon[i].bType );
|
|
|
|
for( INT j = 0; j < m_lpPolygon[i].wCount; j++ )
|
|
{
|
|
// load shadow from line
|
|
fprintf( pFile, "%d %d\n", m_lpPolygon[i].lpPoint[j].wX, m_lpPolygon[i].lpPoint[j].wY );
|
|
}
|
|
}
|
|
|
|
fclose( pFile );
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CShadow::Load()
|
|
{
|
|
Destroy();
|
|
|
|
if( !LoadRays( "hidden.txt" ) )
|
|
return FALSE;
|
|
|
|
if( !LoadPolygons( "polygons.txt" ) )
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CShadow::Save()
|
|
{
|
|
if( !SaveRays( "hidden.txt" ) )
|
|
return FALSE;
|
|
|
|
if( !SavePolygons( "polygons.txt" ) )
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CShadow::IsOutside( INT nAngle, INT nRange )
|
|
{
|
|
LONG nShadow = nAngle;
|
|
|
|
// convert angle to shadow system
|
|
#ifdef LGS_MIRROR
|
|
nShadow <<= 1;
|
|
|
|
nShadow = ( nShadow * LGS_MAX_SHADOW_ANGLES ) / (LGS_MAX_DETECTOR_ANGLES * LGS_MIRROR );
|
|
#else
|
|
nShadow = ( nShadow * LGS_MAX_SHADOW_ANGLES ) / LGS_MAX_DETECTOR_ANGLES;
|
|
#endif
|
|
|
|
// range should be in the same system ( 0..2047 )
|
|
LPRAY_LINE pShadowLine = &m_pShadowLine[ (INT)nShadow ];
|
|
if( !pShadowLine->nCount )
|
|
return TRUE;
|
|
|
|
LPRAY pShadow = pShadowLine->lpShadow;
|
|
for( INT i = 0; i < pShadowLine->nCount; i++ )
|
|
{
|
|
if( m_pTypeOn[pShadow->bType] && nRange >= pShadow->nMin && nRange <= pShadow->nMax )
|
|
return FALSE;
|
|
|
|
pShadow++;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CShadow::OnCmdGetHzData( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
|
|
{
|
|
union
|
|
{
|
|
LGS::PHZ_PACKET pPacket;
|
|
LGS::PHZ_CMD_GET_HEADER pHzCmdHeader;
|
|
LGS::PHZ_CMD_GET_POLYGON pHzCmdPolygon;
|
|
LGS::PHZ_CMD_GET_POLYGON_POINT pHzCmdPolygonPoint;
|
|
LGS::PHZ_CMD_GET_RAY pHzCmdRay;
|
|
LGS::PHZ_CMD_GET_RAY_LINE pHzCmdRayLine;
|
|
};
|
|
|
|
union
|
|
{
|
|
LGS::HZ_PACKET HzPacket;
|
|
LGS::HZ_EVT_GET_HEADER HzEvtHeader;
|
|
LGS::HZ_EVT_GET_POLYGON HzEvtPolygon;
|
|
LGS::HZ_EVT_GET_POLYGON_POINT HzEvtPolygonPoint;
|
|
LGS::HZ_EVT_GET_RAY HzEvtRay;
|
|
LGS::HZ_EVT_GET_RAY_LINE HzEvtRayLine;
|
|
LGS::HZ_EVT_ERROR HzEvtError;
|
|
};
|
|
|
|
// read packet
|
|
nReadCount -= LGS::GetCmdHzGetData( pReadBufferPtr, &pPacket );
|
|
|
|
|
|
// set sequence
|
|
HzPacket.bSequence = pPacket->bSequence;
|
|
|
|
BYTE bError = LGS::HZER_NONE;
|
|
switch( pPacket->bType )
|
|
{
|
|
case LGS::HZIT_CMD_GET_HEADER:
|
|
HzEvtHeader.bType = LGS::HZIT_EVT_GET_HEADER;
|
|
HzEvtHeader.bSubSize = sizeof(LGS::HZ_EVT_GET_HEADER) - sizeof(LGS::HZ_PACKET);
|
|
HzEvtHeader.wPolygonCount = m_nPolygon;
|
|
HzEvtHeader.wRayCount = LGS_MAX_SHADOW_ANGLES;
|
|
HzEvtHeader.dwTypeOn = m_dwTypeOn;
|
|
break;
|
|
|
|
case LGS::HZIT_CMD_GET_POLYGON:
|
|
if( pHzCmdPolygon->wPolygonIndex >= m_nPolygon )
|
|
{
|
|
bError = LGS::HZER_POLYGON_INDEX;
|
|
break;
|
|
}
|
|
|
|
HzEvtPolygon.bType = LGS::HZIT_EVT_GET_POLYGON;
|
|
HzEvtPolygon.bSubSize = sizeof(LGS::HZ_EVT_GET_POLYGON) - sizeof(LGS::HZ_PACKET);
|
|
HzEvtPolygon.bPolygonType = m_lpPolygon[pHzCmdPolygon->wPolygonIndex].bType;
|
|
HzEvtPolygon.wPointCount = m_lpPolygon[pHzCmdPolygon->wPolygonIndex].wCount;
|
|
break;
|
|
|
|
case LGS::HZIT_CMD_GET_POLYGON_POINT:
|
|
if( pHzCmdPolygonPoint->wPolygonIndex >= m_nPolygon )
|
|
{
|
|
bError = LGS::HZER_POLYGON_INDEX;
|
|
break;
|
|
}
|
|
|
|
if( pHzCmdPolygonPoint->wPointIndex >= m_lpPolygon[pHzCmdPolygonPoint->wPolygonIndex].wCount )
|
|
{
|
|
bError = LGS::HZER_POLYGON_POINT_INDEX;
|
|
break;
|
|
}
|
|
|
|
HzEvtPolygonPoint.bType = LGS::HZIT_EVT_GET_POLYGON_POINT;
|
|
HzEvtPolygonPoint.bSubSize = sizeof(LGS::HZ_EVT_GET_POLYGON_POINT) - sizeof(LGS::HZ_PACKET);
|
|
HzEvtPolygonPoint.Point = m_lpPolygon[pHzCmdPolygonPoint->wPolygonIndex].lpPoint[pHzCmdPolygonPoint->wPointIndex];
|
|
break;
|
|
|
|
case LGS::HZIT_CMD_GET_RAY:
|
|
if( pHzCmdRay->wRayIndex >= LGS_MAX_SHADOW_ANGLES )
|
|
{
|
|
bError = LGS::HZER_RAY_INDEX;
|
|
break;
|
|
}
|
|
|
|
HzEvtRay.bType = LGS::HZIT_EVT_GET_RAY;
|
|
HzEvtRay.bSubSize = sizeof(LGS::HZ_EVT_GET_RAY) - sizeof(LGS::HZ_PACKET);
|
|
HzEvtRay.wLineCount = m_pShadowLine[pHzCmdRay->wRayIndex].nCount;
|
|
break;
|
|
|
|
case LGS::HZIT_CMD_GET_RAY_LINE:
|
|
if( pHzCmdRayLine->wRayIndex >= LGS_MAX_SHADOW_ANGLES )
|
|
{
|
|
bError = LGS::HZER_RAY_INDEX;
|
|
break;
|
|
}
|
|
if( pHzCmdRayLine->wLineIndex >= m_pShadowLine[pHzCmdRayLine->wRayIndex].nCount )
|
|
{
|
|
bError = LGS::HZER_RAY_LINE_INDEX;
|
|
break;
|
|
}
|
|
|
|
HzEvtRayLine.bType = LGS::HZIT_EVT_GET_RAY_LINE;
|
|
HzEvtRayLine.bSubSize = sizeof(LGS::HZ_EVT_GET_RAY_LINE) - sizeof(LGS::HZ_PACKET);
|
|
HzEvtRayLine.Line.bType = m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].bType;
|
|
HzEvtRayLine.Line.wMin = m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].nMin;
|
|
HzEvtRayLine.Line.wMax = m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].nMax;
|
|
break;
|
|
}
|
|
|
|
// fill error
|
|
if( bError != LGS::HZER_NONE )
|
|
{
|
|
HzEvtError.bType = LGS::HZIT_EVT_ERROR;
|
|
HzEvtError.bSubSize = sizeof(LGS::HZ_EVT_ERROR) - sizeof(LGS::HZ_PACKET);
|
|
HzEvtError.bCmdType = pPacket->bType;
|
|
HzEvtError.bErrorId = bError;
|
|
}
|
|
|
|
// build CMD_SET_WIDHT_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_HZ_DATA;
|
|
|
|
// write command
|
|
nSendCount += LGS::BuildEvtHzGetData( pSendBufferPtr, &HzPacket );
|
|
}
|
|
|
|
|
|
BOOL CShadow::OnCmdSetHzData( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
|
|
{
|
|
union
|
|
{
|
|
LGS::PHZ_PACKET pPacket;
|
|
LGS::PHZ_CMD_SET_HEADER pHzCmdHeader;
|
|
LGS::PHZ_CMD_SET_POLYGON pHzCmdPolygon;
|
|
LGS::PHZ_CMD_SET_POLYGON_POINT pHzCmdPolygonPoint;
|
|
LGS::PHZ_CMD_SET_RAY pHzCmdRay;
|
|
LGS::PHZ_CMD_SET_RAY_LINE pHzCmdRayLine;
|
|
LGS::PHZ_CMD_SET_DONE pHzCmdDone;
|
|
};
|
|
|
|
union
|
|
{
|
|
LGS::HZ_PACKET HzPacket;
|
|
LGS::HZ_EVT_SET_HEADER HzEvtHeader;
|
|
LGS::HZ_EVT_SET_POLYGON HzEvtPolygon;
|
|
LGS::HZ_EVT_SET_POLYGON_POINT HzEvtPolygonPoint;
|
|
LGS::HZ_EVT_SET_RAY HzEvtRay;
|
|
LGS::HZ_EVT_SET_RAY_LINE HzEvtRayLine;
|
|
LGS::HZ_EVT_SET_DONE HzEvtDone;
|
|
LGS::HZ_EVT_ERROR HzEvtError;
|
|
};
|
|
|
|
//
|
|
BOOL bPendingSave = FALSE;
|
|
|
|
// read packet
|
|
nReadCount -= LGS::GetCmdHzSetData( pReadBufferPtr, &pPacket );
|
|
|
|
// set sequence
|
|
HzPacket.bSequence = pPacket->bSequence;
|
|
|
|
BYTE bError = LGS::HZER_NONE;
|
|
switch( pPacket->bType )
|
|
{
|
|
case LGS::HZIT_CMD_SET_HEADER:
|
|
// destroy old content
|
|
Destroy();
|
|
// check shadow rays count
|
|
if( pHzCmdHeader->wRayCount != LGS_MAX_SHADOW_ANGLES )
|
|
{
|
|
bError = LGS::HZER_RAY_COUNT;
|
|
break;
|
|
}
|
|
// create empty polygons
|
|
m_lpPolygon = (LPHZ_POLYGON)farmalloc( pHzCmdHeader->wPolygonCount * sizeof(HZ_POLYGON) );
|
|
if( pHzCmdHeader->wPolygonCount && !m_lpPolygon )
|
|
{
|
|
bError = LGS::HZER_OUT_OF_MEMORY;
|
|
break;
|
|
}
|
|
_fmemset( m_lpPolygon, 0, pHzCmdHeader->wPolygonCount * sizeof(HZ_POLYGON) );
|
|
m_nPolygon = pHzCmdHeader->wPolygonCount;
|
|
m_dwTypeOn = pHzCmdHeader->dwTypeOn;
|
|
{
|
|
for( INT i = 0; i < LGS_MAX_SHADOW_TYPES; i++ )
|
|
{
|
|
DWORD bBit = 1 << i;
|
|
m_pTypeOn[i] = ( m_dwTypeOn & bBit ) == bBit;
|
|
}
|
|
}
|
|
// prepare reply
|
|
HzEvtHeader.bType = LGS::HZIT_EVT_SET_HEADER;
|
|
HzEvtHeader.bSubSize = sizeof(LGS::HZ_EVT_SET_HEADER) - sizeof(LGS::HZ_PACKET);
|
|
break;
|
|
|
|
case LGS::HZIT_CMD_SET_POLYGON:
|
|
// check index
|
|
if( pHzCmdPolygon->wPolygonIndex >= m_nPolygon )
|
|
{
|
|
bError = LGS::HZER_POLYGON_INDEX;
|
|
break;
|
|
}
|
|
|
|
// reallocate memory
|
|
m_lpPolygon[pHzCmdPolygon->wPolygonIndex].wCount = 0;
|
|
m_lpPolygon[pHzCmdPolygon->wPolygonIndex].lpPoint = (LGS::LPHZ_POINT)farrealloc( m_lpPolygon[pHzCmdPolygon->wPolygonIndex].lpPoint, sizeof(LGS::HZ_POINT) * pHzCmdPolygon->wPointCount );
|
|
if( pHzCmdPolygon->wPointCount && !m_lpPolygon[pHzCmdPolygon->wPolygonIndex].lpPoint )
|
|
{
|
|
bError = LGS::HZER_OUT_OF_MEMORY;
|
|
break;
|
|
}
|
|
m_lpPolygon[pHzCmdPolygon->wPolygonIndex].wCount = pHzCmdPolygon->wPointCount;
|
|
m_lpPolygon[pHzCmdPolygon->wPolygonIndex].bType = pHzCmdPolygon->bPolygonType;
|
|
|
|
// prepare reply
|
|
HzEvtPolygon.bType = LGS::HZIT_EVT_SET_POLYGON;
|
|
HzEvtPolygon.bSubSize = sizeof(LGS::HZ_EVT_SET_POLYGON) - sizeof(LGS::HZ_PACKET);
|
|
break;
|
|
|
|
case LGS::HZIT_CMD_SET_POLYGON_POINT:
|
|
// check indexes
|
|
if( pHzCmdPolygonPoint->wPolygonIndex >= m_nPolygon )
|
|
{
|
|
bError = LGS::HZER_POLYGON_INDEX;
|
|
break;
|
|
}
|
|
if( pHzCmdPolygonPoint->wPointIndex >= m_lpPolygon[pHzCmdPolygonPoint->wPolygonIndex].wCount )
|
|
{
|
|
bError = LGS::HZER_POLYGON_POINT_INDEX;
|
|
break;
|
|
}
|
|
m_lpPolygon[pHzCmdPolygonPoint->wPolygonIndex].lpPoint[pHzCmdPolygonPoint->wPointIndex] = pHzCmdPolygonPoint->Point;
|
|
|
|
// prepare reply
|
|
HzEvtPolygonPoint.bType = LGS::HZIT_EVT_SET_POLYGON_POINT;
|
|
HzEvtPolygonPoint.bSubSize = sizeof(LGS::HZ_EVT_SET_POLYGON_POINT) - sizeof(LGS::HZ_PACKET);
|
|
break;
|
|
|
|
case LGS::HZIT_CMD_SET_RAY:
|
|
// check indexes
|
|
if( pHzCmdRay->wRayIndex >= LGS_MAX_SHADOW_ANGLES )
|
|
{
|
|
bError = LGS::HZER_RAY_INDEX;
|
|
break;
|
|
}
|
|
m_pShadowLine[pHzCmdRay->wRayIndex].nCount = 0;
|
|
m_pShadowLine[pHzCmdRay->wRayIndex].lpShadow = (LPRAY)farrealloc( m_pShadowLine[pHzCmdRay->wRayIndex].lpShadow, pHzCmdRay->wLineCount * sizeof(RAY) );
|
|
if( pHzCmdRay->wLineCount && !m_pShadowLine[pHzCmdRay->wRayIndex].lpShadow )
|
|
{
|
|
bError = LGS::HZER_OUT_OF_MEMORY;
|
|
break;
|
|
}
|
|
m_pShadowLine[pHzCmdRay->wRayIndex].nCount = pHzCmdRay->wLineCount;
|
|
|
|
// prepare reply
|
|
HzEvtRay.bType = LGS::HZIT_EVT_SET_RAY;
|
|
HzEvtRay.bSubSize = sizeof(LGS::HZ_EVT_SET_RAY) - sizeof(LGS::HZ_PACKET);
|
|
break;
|
|
|
|
case LGS::HZIT_CMD_SET_RAY_LINE:
|
|
if( pHzCmdRayLine->wRayIndex >= LGS_MAX_SHADOW_ANGLES )
|
|
{
|
|
bError = LGS::HZER_RAY_INDEX;
|
|
break;
|
|
}
|
|
if( pHzCmdRayLine->wLineIndex >= m_pShadowLine[pHzCmdRayLine->wRayIndex].nCount )
|
|
{
|
|
bError = LGS::HZER_RAY_LINE_INDEX;
|
|
break;
|
|
}
|
|
m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].bType = pHzCmdRayLine->Line.bType;
|
|
m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].nMin = pHzCmdRayLine->Line.wMin;
|
|
m_pShadowLine[pHzCmdRayLine->wRayIndex].lpShadow[pHzCmdRayLine->wLineIndex].nMax = pHzCmdRayLine->Line.wMax;
|
|
|
|
HzEvtRayLine.bType = LGS::HZIT_EVT_SET_RAY_LINE;
|
|
HzEvtRayLine.bSubSize = sizeof(LGS::HZ_EVT_SET_RAY_LINE) - sizeof(LGS::HZ_PACKET);
|
|
break;
|
|
|
|
case LGS::HZIT_CMD_SET_DONE:
|
|
HzEvtDone.bType = LGS::HZIT_EVT_SET_DONE;
|
|
HzEvtDone.bSubSize = sizeof(LGS::HZ_EVT_SET_DONE) - sizeof(LGS::HZ_PACKET);
|
|
|
|
bPendingSave = TRUE;
|
|
break;
|
|
}
|
|
|
|
// fill error
|
|
if( bError != LGS::HZER_NONE )
|
|
{
|
|
HzEvtError.bType = LGS::HZIT_EVT_ERROR;
|
|
HzEvtError.bSubSize = sizeof(LGS::HZ_EVT_ERROR) - sizeof(LGS::HZ_PACKET);
|
|
HzEvtError.bCmdType = pPacket->bType;
|
|
HzEvtError.bErrorId = bError;
|
|
}
|
|
|
|
// build CMD_SET_WIDHT_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_HZ_DATA;
|
|
|
|
// write command
|
|
nSendCount += LGS::BuildEvtHzSetData( pSendBufferPtr, &HzPacket );
|
|
|
|
return bPendingSave;
|
|
}
|
|
|
|
void CShadow::OnCmdGetHzEnable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
|
|
{
|
|
// build CMD_SET_WIDHT_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_GET_HZ_ENABLE;
|
|
|
|
// write command
|
|
nSendCount += LGS::BuildEvtGetHzEnable( pSendBufferPtr, m_dwTypeOn );
|
|
|
|
}
|
|
|
|
BOOL CShadow::OnCmdSetHzEnable( PBYTE& pReadBufferPtr, INT& nReadCount, PBYTE& pSendBufferPtr, INT& nSendCount )
|
|
{
|
|
// read packet
|
|
nReadCount -= LGS::GetCmdSetHzEnable( pReadBufferPtr, &m_dwTypeOn );
|
|
for( INT i = 0; i < LGS_MAX_SHADOW_TYPES; i++ )
|
|
{
|
|
DWORD bBit = 1 << i;
|
|
m_pTypeOn[i] = ( m_dwTypeOn & bBit ) == bBit;
|
|
}
|
|
|
|
// build CMD_SET_WIDHT_TABLE command
|
|
*pSendBufferPtr++ = LGS::CMD_SET_HZ_ENABLE;
|
|
|
|
// write command
|
|
nSendCount += LGS::BuildEvtSetHzEnable( pSendBufferPtr, m_dwTypeOn );
|
|
|
|
return TRUE;
|
|
}
|