aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-03-06 22:59:13 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-03-06 22:59:13 +0100
commit98da4bb94fbd2e65b1634f01519e3bbd59b76592 (patch)
treeb70d3c45d6df559fea00bc4b5aa792ae259c3275
parenta472dc51a18ad16bd8c72337023a08251a5888a8 (diff)
downloadtermgl-98da4bb94fbd2e65b1634f01519e3bbd59b76592.tar.gz
converting size variables to unsigned #1
-rw-r--r--src/cObject.cpp9
-rw-r--r--src/cObject.h2
-rw-r--r--src/cRender.cpp9
-rw-r--r--src/cRender.h2
4 files changed, 13 insertions, 9 deletions
diff --git a/src/cObject.cpp b/src/cObject.cpp
index 217affc..bba7509 100644
--- a/src/cObject.cpp
+++ b/src/cObject.cpp
@@ -32,6 +32,7 @@ sObject cObject::getObject()
{
return sObject{pos, wColor, cScreen, sizeX, sizeY};
}
+
void cObject::write(cRender *_render, sPos _cameraPosition)
{
if(!bSizeSet)
@@ -51,7 +52,7 @@ void cObject::write(cRender *_render, sPos _cameraPosition)
//protected
cObject::cObject() : pos({0,0}) , bSizeSet(false){}
-void cObject::setSize(int _sx, int _sy)
+void cObject::setSize(unsigned int _sx, unsigned int _sy)
{
if(bSizeSet)
return;
@@ -63,16 +64,16 @@ void cObject::setSize(int _sx, int _sy)
//Initialize 2D array
cScreen = (char**) malloc(sizeof *cScreen * _sx);
- for (int i = 0; i < _sx; i++)
+ for (unsigned int i = 0; i < _sx; i++)
cScreen[i] = (char*)malloc(sizeof *cScreen[i] * _sy);
wColor = (WORD**)malloc(sizeof *wColor * _sx);
- for (int i = 0; i < _sx; i++)
+ for (unsigned int i = 0; i < _sx; i++)
wColor[i] = (WORD*)malloc(sizeof *wColor[i] * _sy);
for (int i = 0; i < sizeY; i++) {
for (int o = 0; o < sizeX; o++) {
- cScreen[o][i] = NULL;
+ cScreen[o][i] = 0;
wColor[o][i] = _COL_DEFAULT;
}
}
diff --git a/src/cObject.h b/src/cObject.h
index 08594b3..2504d71 100644
--- a/src/cObject.h
+++ b/src/cObject.h
@@ -89,7 +89,7 @@ protected: //For child classes
cObject();
/** For inheriting classes: sets size of framebuffer
*/
- void setSize(int _sx, int _sy);
+ void setSize(unsigned int _sx, unsigned int _sy);
/** For inheriting classes: frees the framebuffer
*/
diff --git a/src/cRender.cpp b/src/cRender.cpp
index 9fbdc8f..df518ee 100644
--- a/src/cRender.cpp
+++ b/src/cRender.cpp
@@ -305,6 +305,9 @@ void cRender::setBufferSize(sPos _size)
if(_size.x == sizeX && _size.y == sizeY)
return;
+ if(_size.x < 0 || _size.y < 0)
+ return;
+
if(sizeX!=0 && sizeY!=0) //resize. delete first
{
for (int i = 0; i < sizeX; i++) {
@@ -323,15 +326,15 @@ void cRender::setBufferSize(sPos _size)
//Initialize 2D array
cScreen = (char**)malloc(sizeof *cScreen * sizeX);
- for (int i = 0; i < sizeX; i++)
+ for (unsigned int i = 0; i < sizeX; i++)
cScreen[i] = (char*)malloc(sizeof *cScreen[i] * sizeY);
wColor = (WORD**)malloc(sizeof *wColor * sizeX);
- for (int i = 0; i < sizeX; i++)
+ for (unsigned int i = 0; i < sizeX; i++)
wColor[i] = (WORD*)malloc(sizeof *wColor[i] * sizeY);
bChanged = (bool**)malloc(sizeof *bChanged * sizeX);
- for (int i = 0; i < sizeX; i++)
+ for (unsigned int i = 0; i < sizeX; i++)
bChanged[i] = (bool*)malloc(sizeof *bChanged[i] * sizeY);
clear(true);
diff --git a/src/cRender.h b/src/cRender.h
index 415db6e..5808c82 100644
--- a/src/cRender.h
+++ b/src/cRender.h
@@ -143,7 +143,7 @@ protected:
//* Default backround
WORD wBackColor;
//* Default backround color
- int sizeX, sizeY;
+ unsigned int sizeX, sizeY;
//* Size of screen array
#ifdef _WIN32