Skip to content

Commit

Permalink
Fix draw issues on zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Nov 13, 2017
1 parent 0815f03 commit eab566e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
2 changes: 0 additions & 2 deletions CIO/CFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,7 @@ bobMAP* CFile::open_wld()
// go to real map height and width
fseek(fp, 2348, SEEK_SET);
freadChecked(&myMap->width, 2, 1, fp);
myMap->width_pixel = myMap->width * TRIANGLE_WIDTH;
freadChecked(&myMap->height, 2, 1, fp);
myMap->height_pixel = myMap->height * TRIANGLE_HEIGHT;

if((myMap->vertex = (point*)malloc(sizeof(point) * myMap->width * myMap->height)) == NULL)
{
Expand Down
13 changes: 7 additions & 6 deletions CMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ void bobMAP::initVertexCoords()

void bobMAP::updateVertexCoords()
{
width_pixel = width * TRIANGLE_WIDTH;
height_pixel = height * TRIANGLE_HEIGHT;

Sint32 b = 0;
for(unsigned j = 0; j < height; j++)
{
Expand Down Expand Up @@ -214,10 +217,8 @@ bobMAP* CMap::generateMap(int width, int height, int type, int texture, int bord
strcpy(myMap->name, "Ohne Namen");
myMap->width = width;
myMap->width_old = width;
myMap->width_pixel = myMap->width * TRIANGLE_WIDTH;
myMap->height = height;
myMap->height_old = height;
myMap->height_pixel = myMap->height * TRIANGLE_HEIGHT;
myMap->type = type;
myMap->player = 0;
strcpy(myMap->author, "Niemand");
Expand Down Expand Up @@ -891,15 +892,15 @@ void CMap::setKeyboardData(const SDL_KeyboardEvent& key)
displayRect.y += (key.keysym.sym == SDLK_UP ? -100 : (key.keysym.sym == SDLK_DOWN ? 100 : 0));

// reset coords of displayRects when end of map is reached
if(displayRect.x >= map->width * TRIANGLE_WIDTH)
if(displayRect.x >= map->width_pixel)
displayRect.x = 0;
else if(displayRect.x <= -displayRect.w)
displayRect.x = map->width * TRIANGLE_WIDTH - displayRect.w;
displayRect.x = map->width_pixel - displayRect.w;

if(displayRect.y >= map->height * TRIANGLE_HEIGHT)
if(displayRect.y >= map->height_pixel)
displayRect.y = 0;
else if(displayRect.y <= -displayRect.h)
displayRect.y = map->height * TRIANGLE_HEIGHT - displayRect.h;
displayRect.y = map->height_pixel - displayRect.h;
}
#ifdef _EDITORMODE
// help menu
Expand Down
19 changes: 12 additions & 7 deletions CSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ Uint32 CSurface::GetPixel(SDL_Surface* surface, int x, int y)
}
}

void CSurface::DrawTriangleField(SDL_Surface* display, const DisplayRectangle& displayRect, bobMAP* myMap)
void CSurface::DrawTriangleField(SDL_Surface* display, DisplayRectangle displayRect, bobMAP* myMap)
{
Uint16 width = myMap->width;
Uint16 height = myMap->height;
Expand All @@ -291,6 +291,13 @@ void CSurface::DrawTriangleField(SDL_Surface* display, const DisplayRectangle& d
if(width < 8 || height < 8)
return;

assert(displayRect.x < myMap->width_pixel);
assert(-displayRect.x <= displayRect.w);
assert(displayRect.x + displayRect.w > 0);
assert(displayRect.y < myMap->height_pixel);
assert(-displayRect.y <= displayRect.h);
assert(displayRect.y + displayRect.h > 0);

// draw triangle field
// NOTE: WE DO THIS TWICE, AT FIRST ONLY TRIANGLE-TEXTURES, AT SECOND THE TEXTURE-BORDERS AND OBJECTS
for(int i = 0; i < 2; i++)
Expand Down Expand Up @@ -323,12 +330,10 @@ void CSurface::DrawTriangleField(SDL_Surface* display, const DisplayRectangle& d
// at first call DrawTriangle for all triangles up or down outside
if(displayRect.y < 0)
{
row_start = height - 1 - (-displayRect.y / TRIANGLE_HEIGHT) - 1;
row_start = std::max(0, height - 1 - (-displayRect.y / TRIANGLE_HEIGHT) - 1);
row_end = height - 1;
view_outside_edges = true;
}

else if((displayRect.y + displayRect.h) > myMap->height_pixel)
} else if((displayRect.y + displayRect.h) > myMap->height_pixel)
{
row_start = 0;
row_end = ((displayRect.y + displayRect.h) - myMap->height_pixel) / TRIANGLE_HEIGHT + 8;
Expand All @@ -354,7 +359,7 @@ void CSurface::DrawTriangleField(SDL_Surface* display, const DisplayRectangle& d
// now call DrawTriangle for all triangles left or right outside
if(displayRect.x <= 0)
{
col_start = width - 1 - (-displayRect.x / TRIANGLE_WIDTH) - 1;
col_start = std::max(0, width - 1 - (-displayRect.x / TRIANGLE_WIDTH) - 1);
col_end = width - 1;
view_outside_edges = true;
} else if(displayRect.x < TRIANGLE_WIDTH)
Expand Down Expand Up @@ -390,7 +395,7 @@ void CSurface::DrawTriangleField(SDL_Surface* display, const DisplayRectangle& d
tempP2.z = myMap->getVertex(width - 1, j + 1).z;
tempP2.i = myMap->getVertex(width - 1, j + 1).i;
DrawTriangle(display, displayRect, myMap, type, myMap->getVertex(0, j), tempP2, myMap->getVertex(0, j + 1));
for(int i = /*1*/ (col_start > 0 ? col_start : 1); i < width && i <= col_end; i++)
for(int i = std::max(col_start, 1); i < width && i <= col_end; i++)
{
// RightSideUp
DrawTriangle(display, displayRect, myMap, type, myMap->getVertex(i, j), myMap->getVertex(i - 1, j + 1),
Expand Down
2 changes: 1 addition & 1 deletion CSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CSurface
static void DrawPixel_RGB(SDL_Surface* screen, int x, int y, Uint8 R, Uint8 G, Uint8 B);
static void DrawPixel_RGBA(SDL_Surface* screen, int x, int y, Uint8 R, Uint8 G, Uint8 B, Uint8 A);
static Uint32 GetPixel(SDL_Surface* surface, int x, int y);
static void DrawTriangleField(SDL_Surface* display, const DisplayRectangle& displayRect, bobMAP* myMap);
static void DrawTriangleField(SDL_Surface* display, DisplayRectangle displayRect, bobMAP* myMap);
static void DrawTriangle(SDL_Surface* display, DisplayRectangle displayRect, bobMAP* myMap, Uint8 type, point P1, point P2, point P3);
static void get_nodeVectors(bobMAP* myMap);
static void update_shading(bobMAP* myMap, int VertexX, int VertexY);
Expand Down

0 comments on commit eab566e

Please sign in to comment.