aboutsummaryrefslogtreecommitdiff
path: root/engines/cruise
diff options
context:
space:
mode:
authorVincent Hamm2007-11-04 00:31:52 +0000
committerVincent Hamm2007-11-04 00:31:52 +0000
commitdcc71a36eb444723d8c645db32ea068b3e706f53 (patch)
treeba1e83d0c469d63111c1e72bb64c80e91639572f /engines/cruise
parent75a5c41ab4570538a4ccf74fabef637ace12682b (diff)
downloadscummvm-rg350-dcc71a36eb444723d8c645db32ea068b3e706f53.tar.gz
scummvm-rg350-dcc71a36eb444723d8c645db32ea068b3e706f53.tar.bz2
scummvm-rg350-dcc71a36eb444723d8c645db32ea068b3e706f53.zip
Click on polygon detection
Object menu fix for doors svn-id: r29395
Diffstat (limited to 'engines/cruise')
-rw-r--r--engines/cruise/cruise_main.cpp50
-rw-r--r--engines/cruise/mainDraw.cpp171
-rw-r--r--engines/cruise/mainDraw.h1
3 files changed, 218 insertions, 4 deletions
diff --git a/engines/cruise/cruise_main.cpp b/engines/cruise/cruise_main.cpp
index 6ca5155587..f417201326 100644
--- a/engines/cruise/cruise_main.cpp
+++ b/engines/cruise/cruise_main.cpp
@@ -659,10 +659,52 @@ int findObject(int mouseX, int mouseY, int *outObjOvl, int *outObjIdx)
j += j2;
}
- /*if ((filesDatabase[j].subData.resourceType == OBJ_TYPE_POLY) && (filesDatabase[j].subData.ptr)) {
- ASSERT(0);
+ if ((filesDatabase[j].subData.resourceType == OBJ_TYPE_POLY) && (filesDatabase[j].subData.ptr)) {
+ int zoom = params.scale;
+
+ int16* dataPtr = (int16*)filesDatabase[j].subData.ptr;
+
+ if (*dataPtr == 0)
+ {
+ int16 offset;
+ int16 newX;
+ int16 newY;
+
+ dataPtr ++;
+
+ offset = *(dataPtr++);
+ flipShort(&offset);
+
+ newX = *(dataPtr++);
+ flipShort(&newX);
+
+ newY = *(dataPtr++);
+ flipShort(&newY);
+
+ offset += j;
+
+ if (offset >= 0 )
+ {
+ if (filesDatabase[offset].resType == 0 && filesDatabase[offset].subData.ptr)
+ {
+ dataPtr = (int16 *)filesDatabase[offset].subData.ptr;
+ }
+ }
+
+ zoom = -zoom;
+ x -= newX;
+ y -= newY;
+ }
+
+ if(dataPtr && findPoly((char*)dataPtr, x, y, zoom, mouseX, mouseY))
+ {
+ *outObjOvl = objOvl;
+ *outObjIdx = objIdx;
+
+ return (currentObject->type);
+ }
}
- else*/
+ else
{
int numBitPlanes = filesDatabase[j].resType;
@@ -917,7 +959,7 @@ bool findRelation(int objOvl, int objIdx, int x, int y)
first = false;
}
}
- if((ovl2) && (ptrHead->verbNumber))
+ if((ovl2) && (ptrHead->verbNumber>=0))
{
if(ovl2->nameVerbGlob)
{
diff --git a/engines/cruise/mainDraw.cpp b/engines/cruise/mainDraw.cpp
index b66c57deaf..0b6d1de50c 100644
--- a/engines/cruise/mainDraw.cpp
+++ b/engines/cruise/mainDraw.cpp
@@ -850,6 +850,177 @@ void buildPolyModel(int positionX, int positionY, int scale, char *pMask, char *
} while (*dataPointer != 0xFF);
}
+bool findPoly(char* dataPtr, int positionX, int positionY, int scale, int mouseX, int mouseY)
+{
+ int counter = 0; // numbers of coordinates to process
+ int startX = 0; // first X in model
+ int startY = 0; // first Y in model
+ int x = 0; // current X
+ int y = 0; // current Y
+ int offsetXinModel = 0; // offset of the X value in the model
+ int offsetYinModel = 0; // offset of the Y value in the model
+ unsigned char *dataPointer = (unsigned char *)dataPtr;
+ int16 *ptrPoly_1_Buf = DIST_3D;
+ int16 *ptrPoly_2_Buf;
+
+ m_flipLeftRight = 0;
+ m_useSmallScale = 0;
+ m_lowerX = *(dataPointer + 3);
+ m_lowerY = *(dataPointer + 4);
+
+ if (scale < 0) {
+ scale = -scale; // flip left right
+ m_flipLeftRight = 1;
+ }
+
+ if (scale < 0x180) { // If scale is smaller than 384
+ m_useSmallScale = 1;
+ m_scaleValue = scale << 1; // double scale
+ } else {
+ m_scaleValue = scale;
+ }
+
+ dataPointer += 5;
+
+ m_coordCount = (*(dataPointer++)) + 1; // original uses +1 here but its later substracted again, we could skip it
+ m_first_X = *(dataPointer);
+ dataPointer++;
+ m_first_Y = *(dataPointer);
+ dataPointer++;
+ startX = m_lowerX - m_first_X;
+ startY = m_lowerY - m_first_Y;
+
+ if (m_useSmallScale) {
+ startX >>= 1;
+ startY >>= 1;
+ }
+
+ if (m_flipLeftRight) {
+ startX = -startX;
+ }
+
+ /*
+ * NOTE:
+ *
+ * The original code continues here with using X, Y instead of startX and StartY.
+ *
+ * Original code:
+ * positionX -= (upscaleValue(startX, m_scaleValue) + 0x8000) >> 16;
+ * positionY -= (upscaleValue(startX, m_scaleValue) + 0x8000) >> 16;
+ */
+
+ // get coordinates from data
+
+ startX = positionX - ((upscaleValue(startX, m_scaleValue) + 0x8000) >> 16);
+ startY = positionY - ((upscaleValue(startY, m_scaleValue) + 0x8000) >> 16);
+
+ ptrPoly_1_Buf[0] = 0;
+ ptrPoly_1_Buf[1] = 0;
+ ptrPoly_1_Buf += 2;
+ counter = m_coordCount - 1 - 1; // skip the first pair, we already have the values
+
+ // dpbcl0
+ do {
+ x = *(dataPointer) - m_first_X;
+ dataPointer++;
+ if (m_useSmallScale) { // shrink all coordinates by factor 2 if a scale smaller than 384 is used
+ x >>= 1;
+ }
+ ptrPoly_1_Buf[0] = offsetXinModel - x;
+ ptrPoly_1_Buf++;
+ offsetXinModel = x;
+
+ y = *(dataPointer) - m_first_Y;
+ dataPointer++;
+ if (m_useSmallScale) {
+ y >>= 1;
+ }
+ ptrPoly_1_Buf[0] = -(offsetYinModel - y);
+ ptrPoly_1_Buf++;
+ offsetYinModel = y;
+
+ } while (--counter);
+
+ // scale and adjust coordinates with offset (using two polybuffers by doing that)
+ ptrPoly_2_Buf = DIST_3D;
+ ptrPoly_1_Buf = polyBuffer2;
+ counter = m_coordCount - 1; // reset counter // process first pair two
+ int m_current_X = 0;
+ int m_current_Y = 0;
+
+ do {
+ x = ptrPoly_2_Buf[0];
+
+ if (m_flipLeftRight == 0) {
+ x = -x;
+ }
+ //////////////////
+
+ m_current_X += upscaleValue(x, m_scaleValue);
+ ptrPoly_1_Buf[0] = ((m_current_X + 0x8000) >> 16) + startX; // adjust X value with start offset
+
+ m_current_Y += upscaleValue(ptrPoly_2_Buf[1], m_scaleValue);
+ ptrPoly_1_Buf[1] = ((m_current_Y + 0x8000) >> 16) + startY; // adjust Y value with start offset
+
+ /////////////////
+
+ ptrPoly_1_Buf += 2;
+ ptrPoly_2_Buf += 2;
+
+ } while (--counter);
+
+ // position of the dataPointer is m_coordCount * 2
+
+ int polygonCount = 0;
+
+ do {
+ int linesToDraw = *dataPointer++;
+
+ if (linesToDraw > 1){ // if value not zero
+ uint16 minimumScale;
+
+ m_color = *dataPointer; // color
+ dataPointer += 2;
+
+ minimumScale = *(uint16 *) (dataPointer);
+ dataPointer += 2;
+
+ flipShort(&minimumScale);
+
+ if ((minimumScale <= scale))
+ {
+ if (m_flipLeftRight) {
+ drawPolyMode1((unsigned char *)dataPointer, linesToDraw);
+ } else {
+ drawPolyMode2((unsigned char *)dataPointer, linesToDraw);
+ }
+
+ int polygonYMin = XMIN_XMAX[0];
+ int polygonYMax = polygonYMin + nbligne;
+
+ if((mouseY >= polygonYMin) && (mouseY <= polygonYMax))
+ {
+ int polygonLineNumber = mouseY - polygonYMin;
+
+ int XMIN = XMIN_XMAX[1+polygonLineNumber*2];
+ int XMAX = XMIN_XMAX[1+polygonLineNumber*2+1];
+
+ if((mouseX >= XMIN) && (mouseX <= XMAX))
+ return true;
+ }
+ }
+
+ dataPointer += linesToDraw;
+ } else {
+ dataPointer += 4;
+ }
+
+ polygonCount ++;
+ } while (*dataPointer != 0xFF);
+
+ return false;
+}
+
// draw poly sprite (OLD: mainDrawSub1)
void mainDrawPolygons(int fileIndex, cellStruct *pObject, int X, int scale, int Y, char *destBuffer, char *dataPtr) {
int newX;
diff --git a/engines/cruise/mainDraw.h b/engines/cruise/mainDraw.h
index 90dd4881a8..cd935bd2d8 100644
--- a/engines/cruise/mainDraw.h
+++ b/engines/cruise/mainDraw.h
@@ -43,6 +43,7 @@ void buildPolyModel(int X, int Y, int scale, char *ptr2, char *destBuffer,
void mainDrawSub4(int objX1, int var_6, cellStruct * currentObjPtr,
char *data1, int objY2, int objX2, char *output, char *data2);
+bool findPoly(char* dataPtr, int x, int y, int zoom, int mouseX, int mouseY);
unsigned char *drawPolyMode2(unsigned char *dataPointer, int linesToDraw);
} // End of namespace Cruise