diff --git a/src/Misc.cpp b/src/Misc.cpp index fb0005a9a..e303f5ae2 100644 --- a/src/Misc.cpp +++ b/src/Misc.cpp @@ -9,34 +9,6 @@ #include "common/tpt-minmax.h" -//Signum function -int isign(float i) //TODO: INline or macro -{ - if (i<0) - return -1; - if (i>0) - return 1; - return 0; -} - -unsigned clamp_flt(float f, float min, float max) //TODO: Also inline/macro -{ - if (fmax) - return 255; - return (int)(255.0f*(f-min)/(max-min)); -} - -float restrict_flt(float f, float min, float max) //TODO Inline or macro or something -{ - if (fmax) - return max; - return f; -} - const static char hex[] = "0123456789ABCDEF"; void strcaturl(char *dst, char *src) { @@ -227,7 +199,7 @@ void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v)//convert 0-255 RGB value else { c = (rr==a) ? gg-bb : ((bb==a) ? rr-gg : bb-rr); - d = (rr==a) ? 3 : ((bb==a) ? 1 : 5); + d = (rr==a) ? 3.f : ((bb==a) ? 1.f : 5.f); *h = (int)(60.0*(d - c/(x - a))); *s = (int)(255.0*((x - a)/x)); *v = (int)(255.0*x); diff --git a/src/Misc.h b/src/Misc.h index 48348b07d..5731a1c79 100644 --- a/src/Misc.h +++ b/src/Misc.h @@ -12,12 +12,43 @@ template inline T LinearInterpolate(T val1, T val2, T lowerCoord, T return (((val2 - val1) / (upperCoord - lowerCoord)) * (coord - lowerCoord)) + val1; } + //Signum function -int isign(float i); +inline int isign(int i) +{ + if (i<0) + return -1; + if (i>0) + return 1; + return 0; +} -unsigned clamp_flt(float f, float min, float max); +inline int isign(float i) +{ + if (i<0) + return -1; + if (i>0) + return 1; + return 0; +} -float restrict_flt(float f, float min, float max); +inline unsigned clamp_flt(float f, float min, float max) +{ + if (fmax) + return 255; + return (int)(255.0f*(f-min)/(max-min)); +} + +inline float restrict_flt(float f, float min, float max) +{ + if (fmax) + return max; + return f; +} void save_presets(int do_update); diff --git a/src/Platform.cpp b/src/Platform.cpp index a66c57736..84669b4f7 100644 --- a/src/Platform.cpp +++ b/src/Platform.cpp @@ -81,7 +81,7 @@ void DoRestart() if (exename.length()) { #ifdef WIN - int ret = (int)ShellExecute(NULL, NULL, exename.c_str(), NULL, NULL, SW_SHOWNORMAL); + int ret = int(INT_PTR(ShellExecute(NULL, NULL, exename.c_str(), NULL, NULL, SW_SHOWNORMAL))); if (ret <= 32) { fprintf(stderr, "cannot restart: ShellExecute(...) failed: code %i\n", ret); @@ -109,7 +109,7 @@ void DoRestart() void OpenURI(ByteString uri) { #if defined(WIN) - if ((int)ShellExecute(NULL, NULL, uri.c_str(), NULL, NULL, SW_SHOWNORMAL) <= 32) + if (int(INT_PTR(ShellExecute(NULL, NULL, uri.c_str(), NULL, NULL, SW_SHOWNORMAL))) <= 32) { fprintf(stderr, "cannot open URI: ShellExecute(...) failed\n"); } diff --git a/src/PowderToyFontEditor.cpp b/src/PowderToyFontEditor.cpp index c557e20c1..7388a2514 100644 --- a/src/PowderToyFontEditor.cpp +++ b/src/PowderToyFontEditor.cpp @@ -390,12 +390,12 @@ void EngineProcess() int frameTime = SDL_GetTicks() - frameStart; frameTimeAvg = frameTimeAvg * 0.8 + frameTime * 0.2; - int fpsLimit = ui::Engine::Ref().FpsLimit; + float fpsLimit = ui::Engine::Ref().FpsLimit; if(fpsLimit > 2) { double offset = 1000.0 / fpsLimit - frameTimeAvg; if(offset > 0) - SDL_Delay(offset + 0.5); + SDL_Delay(Uint32(offset + 0.5)); } int correctedFrameTime = SDL_GetTicks() - frameStart; correctedFrameTimeAvg = correctedFrameTimeAvg * 0.95 + correctedFrameTime * 0.05; @@ -464,7 +464,8 @@ int main(int argc, char * argv[]) } else { - throw std::runtime_error("path to font.cpp not supplied"); + std::cerr << "path to font.cpp not supplied" << std::endl; + exit(1); } EngineProcess(); diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index 55abadea3..8f0cf9516 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -575,12 +575,12 @@ void EngineProcess() int frameTime = SDL_GetTicks() - frameStart; frameTimeAvg = frameTimeAvg * 0.8 + frameTime * 0.2; - int fpsLimit = ui::Engine::Ref().FpsLimit; + float fpsLimit = ui::Engine::Ref().FpsLimit; if(fpsLimit > 2) { double offset = 1000.0 / fpsLimit - frameTimeAvg; if(offset > 0) - SDL_Delay(offset + 0.5); + SDL_Delay(Uint32(offset + 0.5)); } int correctedFrameTime = SDL_GetTicks() - frameStart; correctedFrameTimeAvg = correctedFrameTimeAvg * 0.95 + correctedFrameTime * 0.05; @@ -758,12 +758,7 @@ int main(int argc, char * argv[]) FILE *new_stderr = freopen("stderr.log", "w", stderr); if (!new_stdout || !new_stderr) { - // no point in printing an error to stdout/stderr since the user probably - // requests those streams be redirected because they can't see them - // otherwise. so just throw an exception instead anf hope that the OS - // and the standard library is smart enough to display the error message - // in some useful manner. - throw std::runtime_error("cannot honour request to redirect standard streams to log files"); + exit(42); } } diff --git a/src/bson/BSON.cpp b/src/bson/BSON.cpp index 370cf76a0..d4d16b0ef 100644 --- a/src/bson/BSON.cpp +++ b/src/bson/BSON.cpp @@ -442,7 +442,7 @@ int bson_iterator_int( const bson_iterator *i ) { case BSON_LONG: return bson_iterator_long_raw( i ); case BSON_DOUBLE: - return bson_iterator_double_raw( i ); + return int(bson_iterator_double_raw( i )); default: return 0; } @@ -453,7 +453,7 @@ double bson_iterator_double( const bson_iterator *i ) { case BSON_INT: return bson_iterator_int_raw( i ); case BSON_LONG: - return bson_iterator_long_raw( i ); + return double(bson_iterator_long_raw( i )); case BSON_DOUBLE: return bson_iterator_double_raw( i ); default: @@ -468,7 +468,7 @@ int64_t bson_iterator_long( const bson_iterator *i ) { case BSON_LONG: return bson_iterator_long_raw( i ); case BSON_DOUBLE: - return bson_iterator_double_raw( i ); + return int64_t(bson_iterator_double_raw( i )); default: return 0; } @@ -625,7 +625,7 @@ int bson_ensure_space( bson *b, const int bytesNeeded ) { if ( pos + bytesNeeded <= b->dataSize ) return BSON_OK; - new_size = 1.5 * ( b->dataSize + bytesNeeded ); + new_size = int(1.5 * ( b->dataSize + bytesNeeded )); if( new_size < b->dataSize ) { if( ( b->dataSize + bytesNeeded ) < INT_MAX ) diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 6e6e7a493..596df4920 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -286,14 +286,14 @@ vector2d GameSave::Translate(vector2d translate) { if (Collapsed()) Expand(); - int nx, ny; + float nx, ny; vector2d pos; vector2d translateReal = translate; float minx = 0, miny = 0, maxx = 0, maxy = 0; // determine minimum and maximum position of all particles / signs for (size_t i = 0; i < signs.size(); i++) { - pos = v2d_new(signs[i].x, signs[i].y); + pos = v2d_new(float(signs[i].x), float(signs[i].y)); pos = v2d_add(pos,translate); nx = floor(pos.x+0.5f); ny = floor(pos.y+0.5f); @@ -329,13 +329,13 @@ vector2d GameSave::Translate(vector2d translate) ); int blockBoundsX = int(maxx / CELL) + 1, blockBoundsY = int(maxy / CELL) + 1; vector2d frontCorrection = v2d_new( - (blockBoundsX > blockWidth) ? (blockBoundsX - blockWidth) : 0, - (blockBoundsY > blockHeight) ? (blockBoundsY - blockHeight) : 0 + float((blockBoundsX > blockWidth) ? (blockBoundsX - blockWidth) : 0), + float((blockBoundsY > blockHeight) ? (blockBoundsY - blockHeight) : 0) ); // get new width based on corrections - int newWidth = (blockWidth + backCorrection.x + frontCorrection.x) * CELL; - int newHeight = (blockHeight + backCorrection.y + frontCorrection.y) * CELL; + auto newWidth = int((blockWidth + backCorrection.x + frontCorrection.x) * CELL); + auto newHeight = int((blockHeight + backCorrection.y + frontCorrection.y) * CELL); if (newWidth > XRES) frontCorrection.x = backCorrection.x = 0; if (newHeight > YRES) @@ -344,8 +344,8 @@ vector2d GameSave::Translate(vector2d translate) // call Transform to do the transformation we wanted when calling this function translate = v2d_add(translate, v2d_multiply_float(backCorrection, CELL)); Transform(m2d_identity, translate, translateReal, - (blockWidth + backCorrection.x + frontCorrection.x) * CELL, - (blockHeight + backCorrection.y + frontCorrection.y) * CELL + int((blockWidth + backCorrection.x + frontCorrection.x) * CELL), + int((blockHeight + backCorrection.y + frontCorrection.y) * CELL) ); // return how much we corrected. This is used to offset the position of the current stamp @@ -364,9 +364,9 @@ void GameSave::Transform(matrix2d transform, vector2d translate) vector2d translateReal = translate; // undo any translation caused by rotation cornerso[0] = v2d_new(0,0); - cornerso[1] = v2d_new(width-1,0); - cornerso[2] = v2d_new(0,height-1); - cornerso[3] = v2d_new(width-1,height-1); + cornerso[1] = v2d_new(float(width-1),0); + cornerso[2] = v2d_new(0,float(height-1)); + cornerso[3] = v2d_new(float(width-1),float(height-1)); for (int i = 0; i < 4; i++) { tmp = m2d_multiply_v2d(transform,cornerso[i]); @@ -379,8 +379,8 @@ void GameSave::Transform(matrix2d transform, vector2d translate) // casting as int doesn't quite do what we want with negative numbers, so use floor() tmp = v2d_new(floor(ctl.x+0.5f),floor(ctl.y+0.5f)); translate = v2d_sub(translate,tmp); - newWidth = floor(cbr.x+0.5f)-floor(ctl.x+0.5f)+1; - newHeight = floor(cbr.y+0.5f)-floor(ctl.y+0.5f)+1; + newWidth = int(floor(cbr.x+0.5f))-int(floor(ctl.x+0.5f))+1; + newHeight = int(floor(cbr.y+0.5f))-int(floor(ctl.y+0.5f))+1; Transform(transform, translate, translateReal, newWidth, newHeight); } @@ -416,10 +416,10 @@ void GameSave::Transform(matrix2d transform, vector2d translate, vector2d transl // rotate and translate signs, parts, walls for (size_t i = 0; i < signs.size(); i++) { - pos = v2d_new(signs[i].x, signs[i].y); + pos = v2d_new(float(signs[i].x), float(signs[i].y)); pos = v2d_add(m2d_multiply_v2d(transform,pos),translate); - nx = floor(pos.x+0.5f); - ny = floor(pos.y+0.5f); + nx = int(floor(pos.x+0.5f)); + ny = int(floor(pos.y+0.5f)); if (nx<0 || nx>=newWidth || ny<0 || ny>=newHeight) { signs[i].text[0] = 0; @@ -433,15 +433,15 @@ void GameSave::Transform(matrix2d transform, vector2d translate, vector2d transl if (!particles[i].type) continue; pos = v2d_new(particles[i].x, particles[i].y); pos = v2d_add(m2d_multiply_v2d(transform,pos),translate); - nx = floor(pos.x+0.5f); - ny = floor(pos.y+0.5f); + nx = int(floor(pos.x+0.5f)); + ny = int(floor(pos.y+0.5f)); if (nx<0 || nx>=newWidth || ny<0 || ny>=newHeight) { particles[i].type = PT_NONE; continue; } - particles[i].x = nx; - particles[i].y = ny; + particles[i].x = float(nx); + particles[i].y = float(ny); vel = v2d_new(particles[i].vx, particles[i].vy); vel = m2d_multiply_v2d(transform, vel); particles[i].vx = vel.x; @@ -473,8 +473,8 @@ void GameSave::Transform(matrix2d transform, vector2d translate, vector2d transl { pos = v2d_new(x*CELL+CELL*0.4f+translateX, y*CELL+CELL*0.4f+translateY); pos = v2d_add(m2d_multiply_v2d(transform,pos),translate); - nx = pos.x/CELL; - ny = pos.y/CELL; + nx = int(pos.x/CELL); + ny = int(pos.y/CELL); if (pos.x<0 || nx>=newBlockWidth || pos.y<0 || ny>=newBlockHeight) continue; if (blockMap[y][x]) @@ -996,7 +996,7 @@ void GameSave::readOPS(char * data, int dataLength) { tempTemp = ambientData[i++]; tempTemp |= (((unsigned)ambientData[i++]) << 8); - ambientHeat[blockY+y][blockX+x] = tempTemp; + ambientHeat[blockY+y][blockX+x] = float(tempTemp); } } hasAmbientHeat = true; @@ -1046,8 +1046,8 @@ void GameSave::readOPS(char * data, int dataLength) //Required fields particles[newIndex].type = partsData[i]; - particles[newIndex].x = x; - particles[newIndex].y = y; + particles[newIndex].x = float(x); + particles[newIndex].y = float(y); i+=3; // Read type (2nd byte) @@ -1060,7 +1060,7 @@ void GameSave::readOPS(char * data, int dataLength) //Full 16bit int tempTemp = partsData[i++]; tempTemp |= (((unsigned)partsData[i++]) << 8); - particles[newIndex].temp = tempTemp; + particles[newIndex].temp = float(tempTemp); } else { @@ -1220,7 +1220,7 @@ void GameSave::readOPS(char * data, int dataLength) case PT_FIRW: if (particles[newIndex].tmp>=2 && savedVersion < 81) { - int caddress = restrict_flt(restrict_flt((float)(particles[newIndex].tmp-4), 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3); + auto caddress = int(restrict_flt(float(particles[newIndex].tmp-4), 0.0f, 199.0f)) * 3; particles[newIndex].type = PT_EMBR; particles[newIndex].tmp = 1; particles[newIndex].ctype = (((firw_data[caddress]))<<16) | (((firw_data[caddress+1]))<<8) | ((firw_data[caddress+2])); @@ -1230,7 +1230,7 @@ void GameSave::readOPS(char * data, int dataLength) if (savedVersion < 87 && particles[newIndex].ctype) particles[newIndex].life = 1; if (savedVersion < 91) - particles[newIndex].temp = 283.15; + particles[newIndex].temp = 283.15f; break; case PT_FILT: if (savedVersion < 89) @@ -1799,13 +1799,13 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) if (particles[i-1].type==PT_PUMP) { particles[i-1].temp = ttv + 0.15;//fix PUMP saved at 0, so that it loads at 0. } else { - particles[i-1].temp = ttv; + particles[i-1].temp = float(ttv); } } else { - particles[i-1].temp = (data[p++]*((MAX_TEMP+(-MIN_TEMP))/255))+MIN_TEMP; + particles[i-1].temp = float((data[p++]*((MAX_TEMP+(-MIN_TEMP))/255))+MIN_TEMP); } } else { - particles[i-1].temp = ((data[p++]*((O_MAX_TEMP+(-O_MIN_TEMP))/255))+O_MIN_TEMP)+273; + particles[i-1].temp = float(((data[p++]*((O_MAX_TEMP+(-O_MIN_TEMP))/255))+O_MIN_TEMP)+273); } } else @@ -1930,7 +1930,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) } if (particles[i-1].type==PT_FIRW && particles[i-1].tmp>=2) { - int caddress = restrict_flt(restrict_flt((float)(particles[i-1].tmp-4), 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3); + auto caddress = int(restrict_flt(float(particles[i-1].tmp-4), 0.0f, 199.0f))*3; particles[i-1].type = PT_EMBR; particles[i-1].tmp = 1; particles[i-1].ctype = (((firw_data[caddress]))<<16) | (((firw_data[caddress+1]))<<8) | ((firw_data[caddress+2])); @@ -2235,7 +2235,7 @@ char * GameSave::serialiseOPS(unsigned int & dataLength) //Store temperature as an offset of 21C(294.15K) or go into a 16byte int and store the whole thing if(fabs(particles[i].temp-294.15f)<127) { - tempTemp = floor(particles[i].temp-294.15f+0.5f); + tempTemp = int(floor(particles[i].temp-294.15f+0.5f)); partsData[partsDataLen++] = tempTemp; } else @@ -2581,7 +2581,7 @@ char * GameSave::serialiseOPS(unsigned int & dataLength) bson_append_int(&b, "pmapbits", pmapbits); if (partsData && partsDataLen) { - bson_append_binary(&b, "parts", BSON_BIN_USER, (const char *)partsData.get(), partsDataLen); + bson_append_binary(&b, "parts", (char)BSON_BIN_USER, (const char *)partsData.get(), partsDataLen); if (palette.size()) { @@ -2594,12 +2594,12 @@ char * GameSave::serialiseOPS(unsigned int & dataLength) } if (partsPosData && partsPosDataLen) - bson_append_binary(&b, "partsPos", BSON_BIN_USER, (const char *)partsPosData.get(), partsPosDataLen); + bson_append_binary(&b, "partsPos", (char)BSON_BIN_USER, (const char *)partsPosData.get(), partsPosDataLen); } if (wallData && hasWallData) - bson_append_binary(&b, "wallMap", BSON_BIN_USER, (const char *)wallData.get(), wallDataLen); + bson_append_binary(&b, "wallMap", (char)BSON_BIN_USER, (const char *)wallData.get(), wallDataLen); if (fanData && fanDataLen) - bson_append_binary(&b, "fanMap", BSON_BIN_USER, (const char *)fanData.get(), fanDataLen); + bson_append_binary(&b, "fanMap", (char)BSON_BIN_USER, (const char *)fanData.get(), fanDataLen); if (pressData && hasPressure && pressDataLen) bson_append_binary(&b, "pressMap", (char)BSON_BIN_USER, (const char*)pressData.get(), pressDataLen); if (vxData && hasPressure && vxDataLen) @@ -2609,7 +2609,7 @@ char * GameSave::serialiseOPS(unsigned int & dataLength) if (ambientData && hasAmbientHeat && this->aheatEnable && ambientDataLen) bson_append_binary(&b, "ambientMap", (char)BSON_BIN_USER, (const char*)ambientData.get(), ambientDataLen); if (soapLinkData && soapLinkDataLen) - bson_append_binary(&b, "soapLinks", BSON_BIN_USER, (const char *)soapLinkData, soapLinkDataLen); + bson_append_binary(&b, "soapLinks", (char)BSON_BIN_USER, (const char *)soapLinkData, soapLinkDataLen); unsigned int signsCount = 0; for (size_t i = 0; i < signs.size(); i++) { diff --git a/src/client/http/GetUserInfoRequest.cpp b/src/client/http/GetUserInfoRequest.cpp index 30ec0f390..64d8c5a8b 100644 --- a/src/client/http/GetUserInfoRequest.cpp +++ b/src/client/http/GetUserInfoRequest.cpp @@ -32,7 +32,7 @@ namespace http ByteString(user["Location"].asString()).FromUtf8(), user["Website"].asString(), user["Saves"]["Count"].asInt(), - user["Saves"]["AverageScore"].asInt(), + user["Saves"]["AverageScore"].asFloat(), user["Saves"]["HighestScore"].asInt(), user["Forum"]["Topics"].asInt(), user["Forum"]["Replies"].asInt(), diff --git a/src/debug/ElementPopulation.cpp b/src/debug/ElementPopulation.cpp index a6fa75284..9833b544e 100644 --- a/src/debug/ElementPopulation.cpp +++ b/src/debug/ElementPopulation.cpp @@ -33,7 +33,7 @@ void ElementPopulationDebug::Draw() if(sim->elements[i].Enabled) { if(maxVal < sim->elementCount[i]) - maxVal = sim->elementCount[i]; + maxVal = float(sim->elementCount[i]); bars++; } } @@ -51,8 +51,8 @@ void ElementPopulationDebug::Draw() { if(sim->elements[i].Enabled) { - float count = sim->elementCount[i]; - int barSize = (count * scale - 0.5f); + auto count = sim->elementCount[i]; + auto barSize = int(count * scale - 0.5f); int barX = bars;//*2; g->draw_line(xStart+barX, yBottom+3, xStart+barX, yBottom+2, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), 255); diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp index af765b3d3..543e6e968 100644 --- a/src/graphics/Graphics.cpp +++ b/src/graphics/Graphics.cpp @@ -46,8 +46,8 @@ VideoBuffer::VideoBuffer(pixel * buffer, int width, int height): void VideoBuffer::Resize(float factor, bool resample) { - int newWidth = ((float)Width)*factor; - int newHeight = ((float)Height)*factor; + int newWidth = int(Width * factor); + int newHeight = int(Height * factor); Resize(newWidth, newHeight, resample); } @@ -61,9 +61,9 @@ void VideoBuffer::Resize(int width, int height, bool resample, bool fixedRatio) if(newHeight == -1 || newWidth == -1) { if(newHeight == -1) - newHeight = ((float)Height)*((float)newWidth/(float)Width); + newHeight = int(float(Height) * newWidth / Width); if(newWidth == -1) - newWidth = ((float)Width)*((float)newHeight/(float)Height); + newWidth = int(float(Width) * newHeight / Height); } else if(fixedRatio) { @@ -164,9 +164,9 @@ char * Graphics::GenerateGradient(pixel * colours, float * points, int pointcoun cccpos = ccpos / (pose - poss); if(cccpos > 1.0f) cccpos = 1.0f; - newdata[(cp*3)] = PIXR(colours[i])*(1.0f-cccpos) + PIXR(colours[j])*(cccpos); - newdata[(cp*3)+1] = PIXG(colours[i])*(1.0f-cccpos) + PIXG(colours[j])*(cccpos); - newdata[(cp*3)+2] = PIXB(colours[i])*(1.0f-cccpos) + PIXB(colours[j])*(cccpos); + newdata[(cp*3) ] = char(PIXR(colours[i])*(1.0f-cccpos) + PIXR(colours[j])*(cccpos)); + newdata[(cp*3)+1] = char(PIXG(colours[i])*(1.0f-cccpos) + PIXG(colours[j])*(cccpos)); + newdata[(cp*3)+2] = char(PIXB(colours[i])*(1.0f-cccpos) + PIXB(colours[j])*(cccpos)); } return newdata; } diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 0f1b177e6..f14aad31f 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -1348,10 +1348,10 @@ void Renderer::render_parts() if((elements[t].Properties & PROP_HOT_GLOW) && sim->parts[i].temp>(elements[t].HighTemperature-800.0f)) { gradv = 3.1415/(2*elements[t].HighTemperature-(elements[t].HighTemperature-800.0f)); - caddress = (sim->parts[i].temp>elements[t].HighTemperature)?elements[t].HighTemperature-(elements[t].HighTemperature-800.0f):sim->parts[i].temp-(elements[t].HighTemperature-800.0f); - colr += sin(gradv*caddress) * 226;; - colg += sin(gradv*caddress*4.55 +3.14) * 34; - colb += sin(gradv*caddress*2.22 +3.14) * 64; + caddress = int((sim->parts[i].temp>elements[t].HighTemperature)?elements[t].HighTemperature-(elements[t].HighTemperature-800.0f):sim->parts[i].temp-(elements[t].HighTemperature-800.0f)); + colr += int(sin(gradv*caddress) * 226); + colg += int(sin(gradv*caddress*4.55 +3.14) * 34); + colb += int(sin(gradv*caddress*2.22 +3.14) * 64); } if((pixel_mode & FIRE_ADD) && !(render_mode & FIRE_ADD)) @@ -1370,7 +1370,9 @@ void Renderer::render_parts() //Alter colour based on display mode if(colour_mode & COLOUR_HEAT) { - caddress = restrict_flt((int)( restrict_flt((float)(sim->parts[i].temp+(-MIN_TEMP)), 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3); + constexpr float min_temp = MIN_TEMP; + constexpr float max_temp = MAX_TEMP; + caddress = int(restrict_flt((sim->parts[i].temp - min_temp) / (max_temp - min_temp) * 1024, 0, 1023)) * 3; firea = 255; firer = colr = color_data[caddress]; fireg = colg = color_data[caddress+1]; @@ -1387,10 +1389,10 @@ void Renderer::render_parts() { gradv = 0.4f; if (!(sim->parts[i].life<5)) - q = sqrt((float)sim->parts[i].life); + q = int(sqrt((float)sim->parts[i].life)); else q = sim->parts[i].life; - colr = colg = colb = sin(gradv*q) * 100 + 128; + colr = colg = colb = int(sin(gradv*q) * 100 + 128); cola = 255; if(pixel_mode & (FIREMODE | PMODE_GLOW)) pixel_mode = (pixel_mode & ~(FIREMODE|PMODE_GLOW)) | PMODE_BLUR; @@ -1448,11 +1450,11 @@ void Renderer::render_parts() if (colour_mode & COLOUR_GRAD) { - float frequency = 0.05; - int q = sim->parts[i].temp-40; - colr = sin(frequency*q) * 16 + colr; - colg = sin(frequency*q) * 16 + colg; - colb = sin(frequency*q) * 16 + colb; + auto frequency = 0.05f; + auto q = int(sim->parts[i].temp-40); + colr = int(sin(frequency*q) * 16 + colr); + colg = int(sin(frequency*q) * 16 + colg); + colb = int(sin(frequency*q) * 16 + colb); if(pixel_mode & (FIREMODE | PMODE_GLOW)) pixel_mode = (pixel_mode & ~(FIREMODE|PMODE_GLOW)) | PMODE_BLUR; } @@ -1625,15 +1627,15 @@ void Renderer::render_parts() draw_line(nx+2, ny-2, nx+2, ny+2, colr, colg, colb, 255); } //legs - draw_line(nx, ny+3, cplayer->legs[0], cplayer->legs[1], legr, legg, legb, 255); - draw_line(cplayer->legs[0], cplayer->legs[1], cplayer->legs[4], cplayer->legs[5], legr, legg, legb, 255); - draw_line(nx, ny+3, cplayer->legs[8], cplayer->legs[9], legr, legg, legb, 255); - draw_line(cplayer->legs[8], cplayer->legs[9], cplayer->legs[12], cplayer->legs[13], legr, legg, legb, 255); + draw_line(nx, ny+3, int(cplayer->legs[0]), int(cplayer->legs[1]), legr, legg, legb, 255); + draw_line(int(cplayer->legs[0]), int(cplayer->legs[1]), int(cplayer->legs[4]), int(cplayer->legs[5]), legr, legg, legb, 255); + draw_line(nx, ny+3, int(cplayer->legs[8]), int(cplayer->legs[9]), legr, legg, legb, 255); + draw_line(int(cplayer->legs[8]), int(cplayer->legs[9]), int(cplayer->legs[12]), int(cplayer->legs[13]), legr, legg, legb, 255); if (cplayer->rocketBoots) { for (int leg=0; leg<2; leg++) { - int nx = cplayer->legs[leg*8+4], ny = cplayer->legs[leg*8+5]; + int nx = int(cplayer->legs[leg*8+4]), ny = int(cplayer->legs[leg*8+5]); int colr = 255, colg = 0, colb = 255; if (((int)(cplayer->comm)&0x04) == 0x04 || (((int)(cplayer->comm)&0x01) == 0x01 && leg==0) || (((int)(cplayer->comm)&0x02) == 0x02 && leg==1)) blendpixel(nx, ny, 0, 255, 0, 255); @@ -1779,7 +1781,7 @@ void Renderer::render_parts() } if(pixel_mode & PMODE_SPARK) { - flicker = random_gen()%20; + flicker = float(random_gen()%20); #ifdef OGLR //Oh god, this is awful lineC[clineC++] = ((float)colr)/255.0f; @@ -1832,18 +1834,18 @@ void Renderer::render_parts() #else gradv = 4*sim->parts[i].life + flicker; for (x = 0; gradv>0.5; x++) { - addpixel(nx+x, ny, colr, colg, colb, gradv); - addpixel(nx-x, ny, colr, colg, colb, gradv); + addpixel(nx+x, ny, colr, colg, colb, int(gradv)); + addpixel(nx-x, ny, colr, colg, colb, int(gradv)); - addpixel(nx, ny+x, colr, colg, colb, gradv); - addpixel(nx, ny-x, colr, colg, colb, gradv); + addpixel(nx, ny+x, colr, colg, colb, int(gradv)); + addpixel(nx, ny-x, colr, colg, colb, int(gradv)); gradv = gradv/1.5f; } #endif } if(pixel_mode & PMODE_FLARE) { - flicker = random_gen()%20; + flicker = float(random_gen()%20); #ifdef OGLR //Oh god, this is awful lineC[clineC++] = ((float)colr)/255.0f; @@ -1895,28 +1897,28 @@ void Renderer::render_parts() cline++; #else gradv = flicker + fabs(parts[i].vx)*17 + fabs(sim->parts[i].vy)*17; - blendpixel(nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) ); - blendpixel(nx+1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - blendpixel(nx-1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - blendpixel(nx, ny+1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - blendpixel(nx, ny-1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx, ny, colr, colg, colb, int((gradv*4)>255?255:(gradv*4)) ); + blendpixel(nx+1, ny, colr, colg, colb,int( (gradv*2)>255?255:(gradv*2)) ); + blendpixel(nx-1, ny, colr, colg, colb, int((gradv*2)>255?255:(gradv*2)) ); + blendpixel(nx, ny+1, colr, colg, colb, int((gradv*2)>255?255:(gradv*2)) ); + blendpixel(nx, ny-1, colr, colg, colb, int((gradv*2)>255?255:(gradv*2)) ); if (gradv>255) gradv=255; - blendpixel(nx+1, ny-1, colr, colg, colb, gradv); - blendpixel(nx-1, ny-1, colr, colg, colb, gradv); - blendpixel(nx+1, ny+1, colr, colg, colb, gradv); - blendpixel(nx-1, ny+1, colr, colg, colb, gradv); + blendpixel(nx+1, ny-1, colr, colg, colb, int(gradv)); + blendpixel(nx-1, ny-1, colr, colg, colb, int(gradv)); + blendpixel(nx+1, ny+1, colr, colg, colb, int(gradv)); + blendpixel(nx-1, ny+1, colr, colg, colb, int(gradv)); for (x = 1; gradv>0.5; x++) { - addpixel(nx+x, ny, colr, colg, colb, gradv); - addpixel(nx-x, ny, colr, colg, colb, gradv); - addpixel(nx, ny+x, colr, colg, colb, gradv); - addpixel(nx, ny-x, colr, colg, colb, gradv); + addpixel(nx+x, ny, colr, colg, colb, int(gradv)); + addpixel(nx-x, ny, colr, colg, colb, int(gradv)); + addpixel(nx, ny+x, colr, colg, colb, int(gradv)); + addpixel(nx, ny-x, colr, colg, colb, int(gradv)); gradv = gradv/1.2f; } #endif } if(pixel_mode & PMODE_LFLARE) { - flicker = random_gen()%20; + flicker = float(random_gen()%20); #ifdef OGLR //Oh god, this is awful lineC[clineC++] = ((float)colr)/255.0f; @@ -1968,21 +1970,21 @@ void Renderer::render_parts() cline++; #else gradv = flicker + fabs(parts[i].vx)*17 + fabs(parts[i].vy)*17; - blendpixel(nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) ); - blendpixel(nx+1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - blendpixel(nx-1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - blendpixel(nx, ny+1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - blendpixel(nx, ny-1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx, ny, colr, colg, colb, int((gradv*4)>255?255:(gradv*4)) ); + blendpixel(nx+1, ny, colr, colg, colb, int((gradv*2)>255?255:(gradv*2)) ); + blendpixel(nx-1, ny, colr, colg, colb, int((gradv*2)>255?255:(gradv*2)) ); + blendpixel(nx, ny+1, colr, colg, colb, int((gradv*2)>255?255:(gradv*2)) ); + blendpixel(nx, ny-1, colr, colg, colb, int((gradv*2)>255?255:(gradv*2)) ); if (gradv>255) gradv=255; - blendpixel(nx+1, ny-1, colr, colg, colb, gradv); - blendpixel(nx-1, ny-1, colr, colg, colb, gradv); - blendpixel(nx+1, ny+1, colr, colg, colb, gradv); - blendpixel(nx-1, ny+1, colr, colg, colb, gradv); + blendpixel(nx+1, ny-1, colr, colg, colb, int(gradv)); + blendpixel(nx-1, ny-1, colr, colg, colb, int(gradv)); + blendpixel(nx+1, ny+1, colr, colg, colb, int(gradv)); + blendpixel(nx-1, ny+1, colr, colg, colb, int(gradv)); for (x = 1; gradv>0.5; x++) { - addpixel(nx+x, ny, colr, colg, colb, gradv); - addpixel(nx-x, ny, colr, colg, colb, gradv); - addpixel(nx, ny+x, colr, colg, colb, gradv); - addpixel(nx, ny-x, colr, colg, colb, gradv); + addpixel(nx+x, ny, colr, colg, colb, int(gradv)); + addpixel(nx-x, ny, colr, colg, colb, int(gradv)); + addpixel(nx, ny+x, colr, colg, colb, int(gradv)); + addpixel(nx, ny-x, colr, colg, colb, int(gradv)); gradv = gradv/1.01f; } #endif @@ -2322,8 +2324,8 @@ void Renderer::draw_other() // EMP effect glTranslated(0, -MENUSIZE, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); #else - int r=emp_decor*2.5, g=100+emp_decor*1.5, b=255; - int a=(1.0*emp_decor/110)*255; + int r=int(emp_decor*2.5), g=int(100+emp_decor*1.5), b=255; + int a=int((1.0*emp_decor/110)*255); if (r>255) r=255; if (g>255) g=255; if (b>255) g=255; @@ -2353,8 +2355,8 @@ void Renderer::draw_grav() ca = y*(XRES/CELL)+x; if(fabsf(sim->gravx[ca]) <= 0.001f && fabsf(sim->gravy[ca]) <= 0.001f) continue; - nx = x*CELL; - ny = y*CELL; + nx = float(x*CELL); + ny = float(y*CELL); dist = fabsf(sim->gravy[ca])+fabsf(sim->gravx[ca]); for(i = 0; i < 4; i++) { @@ -2397,8 +2399,9 @@ void Renderer::draw_air() } else if (display_mode & DISPLAY_AIRH) { - float ttemp = hv[y][x]+(-MIN_TEMP); - int caddress = restrict_flt((int)( restrict_flt(ttemp, 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3); + constexpr float min_temp = MIN_TEMP; + constexpr float max_temp = MAX_TEMP; + int caddress = int(restrict_flt((hv[y][x] - min_temp) / (max_temp - min_temp), 0, 1023)) * 3; c = PIXRGB((int)(color_data[caddress]*0.7f), (int)(color_data[caddress+1]*0.7f), (int)(color_data[caddress+2]*0.7f)); //c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red // clamp_flt(hv[y][x], 0.0f, 1600.0f),//heat adds green diff --git a/src/gui/colourpicker/ColourPickerActivity.cpp b/src/gui/colourpicker/ColourPickerActivity.cpp index 9c92aebe3..8e0836d9c 100644 --- a/src/gui/colourpicker/ColourPickerActivity.cpp +++ b/src/gui/colourpicker/ColourPickerActivity.cpp @@ -105,7 +105,7 @@ void ColourPickerActivity::OnMouseMove(int x, int y, int dx, int dy) x -= Position.X+5; y -= Position.Y+5; - currentHue = (float(x)/float(255))*359.0f; + currentHue = int((float(x)/float(255))*359.0f); currentSaturation = 255-(y*2); if(currentSaturation > 255) @@ -146,7 +146,7 @@ void ColourPickerActivity::OnMouseDown(int x, int y, unsigned button) if(x >= 0 && x < 256 && y >= 0 && y <= 128) { mouseDown = true; - currentHue = (float(x)/float(255))*359.0f; + currentHue = int((float(x)/float(255))*359.0f); currentSaturation = 255-(y*2); if(currentSaturation > 255) @@ -193,7 +193,7 @@ void ColourPickerActivity::OnMouseUp(int x, int y, unsigned button) x -= Position.X+5; y -= Position.Y+5; - currentHue = (float(x)/float(255))*359.0f; + currentHue = int((float(x)/float(255))*359.0f); currentSaturation = 255-(y*2); if(currentSaturation > 255) @@ -261,7 +261,7 @@ void ColourPickerActivity::OnDraw() { for(int hue = 0; hue <= 359; hue++) { - currx = clamp_flt(hue, 0, 359)+offsetX; + currx = int(restrict_flt(float(hue), 0, 359))+offsetX; if (currx == lastx) continue; lastx = currx; @@ -286,7 +286,7 @@ void ColourPickerActivity::OnDraw() } //draw color square pointer - int currentHueX = clamp_flt(currentHue, 0, 359); + int currentHueX = int(restrict_flt(float(currentHue), 0, 359)); int currentSaturationY = ((255-currentSaturation)/2); g->xor_line(offsetX+currentHueX, offsetY+currentSaturationY-5, offsetX+currentHueX, offsetY+currentSaturationY-1); g->xor_line(offsetX+currentHueX, offsetY+currentSaturationY+1, offsetX+currentHueX, offsetY+currentSaturationY+5); @@ -294,7 +294,7 @@ void ColourPickerActivity::OnDraw() g->xor_line(offsetX+currentHueX+1, offsetY+currentSaturationY, offsetX+currentHueX+5, offsetY+currentSaturationY); //draw brightness bar pointer - int currentValueX = restrict_flt(currentValue, 0, 254); + int currentValueX = int(restrict_flt(float(currentValue), 0, 254)); g->xor_line(offsetX+currentValueX, offsetY+4+128, offsetX+currentValueX, offsetY+13+128); g->xor_line(offsetX+currentValueX+1, offsetY+4+128, offsetX+currentValueX+1, offsetY+13+128); } diff --git a/src/gui/filebrowser/FileBrowserActivity.cpp b/src/gui/filebrowser/FileBrowserActivity.cpp index fc8537edf..2a07f6a6e 100644 --- a/src/gui/filebrowser/FileBrowserActivity.cpp +++ b/src/gui/filebrowser/FileBrowserActivity.cpp @@ -281,7 +281,7 @@ void FileBrowserActivity::OnTick(float dt) }); progressBar->SetStatus("Rendering thumbnails"); - progressBar->SetProgress((float(totalFiles-files.size())/float(totalFiles))*100.0f); + progressBar->SetProgress(totalFiles ? (totalFiles - files.size()) * 100 / totalFiles : 0); componentsQueue.push_back(saveButton); fileX++; } diff --git a/src/gui/game/BitmapBrush.cpp b/src/gui/game/BitmapBrush.cpp index 75f6796f7..5df87f7e8 100644 --- a/src/gui/game/BitmapBrush.cpp +++ b/src/gui/game/BitmapBrush.cpp @@ -55,18 +55,18 @@ void BitmapBrush::GenerateBitmap() float originalY = ((float)y)*factorY; float originalX = ((float)x)*factorX; - int lowerX = std::floor(originalX); - int upperX = std::min((float)(origSize.X-1), std::floor(originalX+1.0f)); - int lowerY = std::floor(originalY); - int upperY = std::min((float)(origSize.Y-1), std::floor(originalY+1.0f)); + auto lowerX = int(std::floor(originalX)); + auto upperX = int(std::min((float)(origSize.X-1), std::floor(originalX+1.0f))); + auto lowerY = int(std::floor(originalY)); + auto upperY = int(std::min((float)(origSize.Y-1), std::floor(originalY+1.0f))); unsigned char topRight = origBitmap[(lowerY*origSize.X)+upperX]; unsigned char topLeft = origBitmap[(lowerY*origSize.X)+lowerX]; unsigned char bottomRight = origBitmap[(upperY*origSize.X)+upperX]; unsigned char bottomLeft = origBitmap[(upperY*origSize.X)+lowerX]; - float top = LinearInterpolate(topLeft, topRight, lowerX, upperX, originalX); - float bottom = LinearInterpolate(bottomLeft, bottomRight, lowerX, upperX, originalX); - float mid = LinearInterpolate(top, bottom, lowerY, upperY, originalY); + float top = LinearInterpolate(topLeft, topRight, float(lowerX), float(upperX), originalX); + float bottom = LinearInterpolate(bottomLeft, bottomRight, float(lowerX), float(upperX), originalX); + float mid = LinearInterpolate(top, bottom, float(lowerY), float(upperY), originalY); bitmap[(y*size.X)+x] = mid > 128 ? 255 : 0; } } diff --git a/src/gui/game/GOLTool.cpp b/src/gui/game/GOLTool.cpp index 88c27404d..6f613a4d6 100644 --- a/src/gui/game/GOLTool.cpp +++ b/src/gui/game/GOLTool.cpp @@ -200,9 +200,9 @@ void GOLWindow::OnDraw() auto f = xx / (float)width; for (int yy = 0; yy < 16; ++yy) { - int rr = highColour.Red * (1.f - f) + lowColour.Red * f; - int gg = highColour.Green * (1.f - f) + lowColour.Green * f; - int bb = highColour.Blue * (1.f - f) + lowColour.Blue * f; + auto rr = int(highColour.Red * (1.f - f) + lowColour.Red * f); + auto gg = int(highColour.Green * (1.f - f) + lowColour.Green * f); + auto bb = int(highColour.Blue * (1.f - f) + lowColour.Blue * f); g->blendpixel(Position.X + xx + 30, Position.Y + yy + 67, rr, gg, bb, 255); } } diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 2394526f6..92f986a0c 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -485,12 +485,12 @@ void GameController::LoadStamp(GameSave *stamp) void GameController::TranslateSave(ui::Point point) { - vector2d translate = v2d_new(point.X, point.Y); + vector2d translate = v2d_new(float(point.X), float(point.Y)); vector2d translated = gameModel->GetPlaceSave()->Translate(translate); ui::Point currentPlaceSaveOffset = gameView->GetPlaceSaveOffset(); // resets placeSaveOffset to 0, which is why we back it up first gameModel->SetPlaceSave(gameModel->GetPlaceSave()); - gameView->SetPlaceSaveOffset(ui::Point(translated.x, translated.y) + currentPlaceSaveOffset); + gameView->SetPlaceSaveOffset(ui::Point(int(translated.x), int(translated.y)) + currentPlaceSaveOffset); } void GameController::TransformSave(matrix2d transform) diff --git a/src/gui/game/GameModel.cpp b/src/gui/game/GameModel.cpp index 8da338396..0aaad4a82 100644 --- a/src/gui/game/GameModel.cpp +++ b/src/gui/game/GameModel.cpp @@ -481,7 +481,7 @@ void GameModel::BuildBrushList() std::cout << "Brushes: Skipping " << brushFiles[i] << ". Could not open" << std::endl; continue; } - size_t dimension = std::sqrt((float)brushData.size()); + auto dimension = size_t(std::sqrt(float(brushData.size()))); if (dimension * dimension != brushData.size()) { std::cout << "Brushes: Skipping " << brushFiles[i] << ". Invalid bitmap size" << std::endl; diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index d78140daf..740182d9b 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -929,9 +929,9 @@ void GameView::updateToolButtonScroll() scrollBar->Position.X = (int)(((float)mouseX/((float)XRES))*(float)(XRES-scrollSize)); - float overflow = totalWidth-(XRES-BARSIZE), mouseLocation = float(XRES-3)/float((XRES-2)-mouseX); //mouseLocation adjusted slightly in case you have 200 elements in one menu + float overflow = float(totalWidth-(XRES-BARSIZE)), mouseLocation = float(XRES-3)/float((XRES-2)-mouseX); //mouseLocation adjusted slightly in case you have 200 elements in one menu - newInitialX += overflow/mouseLocation; + newInitialX += int(overflow/mouseLocation); } else { @@ -1616,7 +1616,7 @@ void GameView::OnTick(float dt) if(introText) { - introText -= int(dt)>0?((int)dt < 5? dt:5):1; + introText -= int(dt)>0?(int(dt) < 5? int(dt):5):1; if(introText < 0) introText = 0; } @@ -2107,7 +2107,7 @@ void GameView::OnDraw() String sampleInfo = String::Build("#", screenshotIndex, " ", String(0xE00E), " REC"); int textWidth = Graphics::textwidth(sampleInfo); - g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, 255*0.5); + g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, 127); g->drawtext(XRES-16-textWidth, 16, sampleInfo, 255, 50, 20, 255); } else if(showHud) @@ -2220,8 +2220,8 @@ void GameView::OnDraw() } int textWidth = Graphics::textwidth(sampleInfo.Build()); - g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, alpha*0.5f); - g->drawtext(XRES-16-textWidth, 16, sampleInfo.Build(), 255, 255, 255, alpha*0.75f); + g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, int(alpha*0.5f)); + g->drawtext(XRES-16-textWidth, 16, sampleInfo.Build(), 255, 255, 255, int(alpha*0.75f)); #ifndef OGLI if (wavelengthGfx) @@ -2277,8 +2277,8 @@ void GameView::OnDraw() sampleInfo << ", AHeat: " << sample.AirTemperature - 273.15f << " C"; textWidth = Graphics::textwidth(sampleInfo.Build()); - g->fillrect(XRES-20-textWidth, 27, textWidth+8, 14, 0, 0, 0, alpha*0.5f); - g->drawtext(XRES-16-textWidth, 30, sampleInfo.Build(), 255, 255, 255, alpha*0.75f); + g->fillrect(XRES-20-textWidth, 27, textWidth+8, 14, 0, 0, 0, int(alpha*0.5f)); + g->drawtext(XRES-16-textWidth, 30, sampleInfo.Build(), 255, 255, 255, int(alpha*0.75f)); } } @@ -2306,8 +2306,8 @@ void GameView::OnDraw() int textWidth = Graphics::textwidth(fpsInfo.Build()); int alpha = 255-introText*5; - g->fillrect(12, 12, textWidth+8, 15, 0, 0, 0, alpha*0.5); - g->drawtext(16, 16, fpsInfo.Build(), 32, 216, 255, alpha*0.75); + g->fillrect(12, 12, textWidth+8, 15, 0, 0, 0, int(alpha*0.5)); + g->drawtext(16, 16, fpsInfo.Build(), 32, 216, 255, int(alpha*0.75)); } //Tooltips diff --git a/src/gui/game/PropertyTool.cpp b/src/gui/game/PropertyTool.cpp index b425b1348..2dbabcb90 100644 --- a/src/gui/game/PropertyTool.cpp +++ b/src/gui/game/PropertyTool.cpp @@ -70,7 +70,7 @@ sim(sim_) property = new ui::DropDown(ui::Point(8, 25), ui::Point(Size.X-16, 16)); property->SetActionCallback({ [this] { FocusComponent(textField); } }); AddComponent(property); - for (size_t i = 0; i < properties.size(); i++) + for (int i = 0; i < int(properties.size()); i++) { property->AddOption(std::pair(properties[i].Name.FromAscii(), i)); } @@ -251,7 +251,7 @@ void PropertyTool::SetProperty(Simulation *sim, ui::Point position) if (changeType) { - sim->part_change_type(ID(i), sim->parts[ID(i)].x+0.5f, sim->parts[ID(i)].y+0.5f, propValue.Integer); + sim->part_change_type(ID(i), int(sim->parts[ID(i)].x+0.5f), int(sim->parts[ID(i)].y+0.5f), propValue.Integer); return; } diff --git a/src/gui/interface/Engine.cpp b/src/gui/interface/Engine.cpp index 6c8981f03..7c322e933 100644 --- a/src/gui/interface/Engine.cpp +++ b/src/gui/interface/Engine.cpp @@ -222,7 +222,7 @@ void Engine::Draw() memcpy(g->vid, lastBuffer, (width_ * height_) * PIXELSIZE); if(windowOpenState < 20) windowOpenState++; - g->fillrect(0, 0, width_, height_, 0, 0, 0, 255-std::pow(.98, windowOpenState)*255); + g->fillrect(0, 0, width_, height_, 0, 0, 0, int(255-std::pow(.98, windowOpenState)*255)); #endif } else diff --git a/src/gui/interface/ProgressBar.cpp b/src/gui/interface/ProgressBar.cpp index c5eb5f81e..45617a39c 100644 --- a/src/gui/interface/ProgressBar.cpp +++ b/src/gui/interface/ProgressBar.cpp @@ -56,17 +56,17 @@ void ProgressBar::Draw(const Point & screenPos) progress = 100; float size = float(Size.X-4)*(float(progress)/100.0f); // TIL... size = std::min(std::max(size, 0.0f), float(Size.X-4)); - g->fillrect(screenPos.X + 2, screenPos.Y + 2, size, Size.Y-4, progressBarColour.Red, progressBarColour.Green, progressBarColour.Blue, 255); + g->fillrect(screenPos.X + 2, screenPos.Y + 2, int(size), Size.Y-4, progressBarColour.Red, progressBarColour.Green, progressBarColour.Blue, 255); } } else { int size = 40, rsize = 0; float position = float(Size.X-4)*(intermediatePos/100.0f); if(position + size - 1 > Size.X-4) { - size = (Size.X-4)-position+1; + size = int((Size.X-4)-position+1); rsize = 40-size; } - g->fillrect(screenPos.X + 2 + position, screenPos.Y + 2, size, Size.Y-4, progressBarColour.Red, progressBarColour.Green, progressBarColour.Blue, 255); + g->fillrect(screenPos.X + 2 + int(position), screenPos.Y + 2, size, Size.Y-4, progressBarColour.Red, progressBarColour.Green, progressBarColour.Blue, 255); if(rsize) { g->fillrect(screenPos.X + 2, screenPos.Y + 2, rsize, Size.Y-4, progressBarColour.Red, progressBarColour.Green, progressBarColour.Blue, 255); diff --git a/src/gui/interface/SaveButton.cpp b/src/gui/interface/SaveButton.cpp index a4ae9c82c..4ff680f35 100644 --- a/src/gui/interface/SaveButton.cpp +++ b/src/gui/interface/SaveButton.cpp @@ -129,7 +129,7 @@ void SaveButton::Tick(float dt) if (!triedThumbnail) { float scaleFactor = (Size.Y-25)/((float)YRES); - ui::Point thumbBoxSize = ui::Point(((float)XRES)*scaleFactor, ((float)YRES)*scaleFactor); + ui::Point thumbBoxSize = ui::Point(int(XRES*scaleFactor), int(YRES*scaleFactor)); if (save) { if(save->GetGameSave()) @@ -176,7 +176,7 @@ void SaveButton::Draw(const Point& screenPos) { Graphics * g = GetGraphics(); float scaleFactor = (Size.Y-25)/((float)YRES); - ui::Point thumbBoxSize = ui::Point(((float)XRES)*scaleFactor, ((float)YRES)*scaleFactor); + ui::Point thumbBoxSize = ui::Point(int(XRES*scaleFactor), int(YRES*scaleFactor)); wantsDraw = true; diff --git a/src/gui/interface/ScrollPanel.cpp b/src/gui/interface/ScrollPanel.cpp index 878eb76c4..3a4f15661 100644 --- a/src/gui/interface/ScrollPanel.cpp +++ b/src/gui/interface/ScrollPanel.cpp @@ -37,7 +37,7 @@ int ScrollPanel::GetScrollLimit() void ScrollPanel::SetScrollPosition(int position) { - offsetY = position; + offsetY = float(position); ViewportPosition.Y = -position; } @@ -68,7 +68,7 @@ void ScrollPanel::Draw(const Point& screenPos) } g->fillrect(screenPos.X+(Size.X-scrollBarWidth), screenPos.Y, scrollBarWidth, Size.Y, 125, 125, 125, 100); - g->fillrect(screenPos.X+(Size.X-scrollBarWidth), screenPos.Y+scrollPos, scrollBarWidth, scrollHeight+1, 255, 255, 255, 255); + g->fillrect(screenPos.X+(Size.X-scrollBarWidth), screenPos.Y+int(scrollPos), scrollBarWidth, int(scrollHeight)+1, 255, 255, 255, 255); } } @@ -77,7 +77,7 @@ void ScrollPanel::XOnMouseClick(int x, int y, unsigned int button) if (isMouseInsideScrollbar) { scrollbarSelected = true; - scrollbarInitialYOffset = offsetY; + scrollbarInitialYOffset = int(offsetY); } scrollbarInitialYClick = y; scrollbarClickLocation = 100; @@ -105,14 +105,14 @@ void ScrollPanel::XOnMouseMoved(int x, int y, int dx, int dy) { if (x > 0) { - int scrollY = float(y-scrollbarInitialYClick)/float(Size.Y)*float(InnerSize.Y)+scrollbarInitialYOffset; + auto scrollY = int(float(y-scrollbarInitialYClick)/float(Size.Y)*float(InnerSize.Y)+scrollbarInitialYOffset); ViewportPosition.Y = -scrollY; - offsetY = scrollY; + offsetY = float(scrollY); } else { ViewportPosition.Y = -scrollbarInitialYOffset; - offsetY = scrollbarInitialYOffset; + offsetY = float(scrollbarInitialYOffset); } } @@ -138,7 +138,7 @@ void ScrollPanel::XTick(float dt) maxOffset.Y = std::max(0, maxOffset.Y); maxOffset.X = std::max(0, maxOffset.X); - int oldOffsetY = offsetY; + auto oldOffsetY = int(offsetY); offsetY += yScrollVel; offsetX += xScrollVel; @@ -165,10 +165,10 @@ void ScrollPanel::XTick(float dt) } else if (offsetY>maxOffset.Y) { - offsetY = maxOffset.Y; + offsetY = float(maxOffset.Y); yScrollVel = 0; } - ViewportPosition.Y = -offsetY; + ViewportPosition.Y = -int(offsetY); } else { @@ -176,12 +176,12 @@ void ScrollPanel::XTick(float dt) { offsetY = 0; yScrollVel = 0; - ViewportPosition.Y = -offsetY; + ViewportPosition.Y = -int(offsetY); } else if (offsetY>maxOffset.Y) { - offsetY = maxOffset.Y; - ViewportPosition.Y = -offsetY; + offsetY = float(maxOffset.Y); + ViewportPosition.Y = -int(offsetY); } } @@ -205,6 +205,6 @@ void ScrollPanel::XTick(float dt) scrollbarClickLocation = 0; offsetY += scrollbarClickLocation*scrollHeight/10; - ViewportPosition.Y -= scrollbarClickLocation*scrollHeight/10; + ViewportPosition.Y -= int(scrollbarClickLocation*scrollHeight/10); } } diff --git a/src/gui/interface/Slider.cpp b/src/gui/interface/Slider.cpp index ed864ba10..c8fb0d56c 100644 --- a/src/gui/interface/Slider.cpp +++ b/src/gui/interface/Slider.cpp @@ -23,12 +23,12 @@ void Slider::updatePosition(int position) if(position > Size.X-3) position = Size.X-3; - float fPosition = position-3; - float fSize = Size.X-6; + auto fPosition = float(position-3); + auto fSize = float(Size.X-6); float fSliderPosition = (fPosition/fSize)*sliderSteps;//position;//((x-3)/(Size.X-6))*sliderSteps; - int newSliderPosition = fSliderPosition; + auto newSliderPosition = int(fSliderPosition); if(newSliderPosition == sliderPosition) return; @@ -120,12 +120,12 @@ void Slider::Draw(const Point& screenPos) g->drawrect(screenPos.X+3, screenPos.Y+3, Size.X-6, Size.Y-6, 255, 255, 255, 255); - float fPosition = sliderPosition; - float fSize = Size.X-6; - float fSteps = sliderSteps; + auto fPosition = float(sliderPosition); + auto fSize = float(Size.X-6); + auto fSteps = float(sliderSteps); - float fSliderX = (fSize/fSteps)*fPosition;//sliderPosition;//((Size.X-6)/sliderSteps)*sliderPosition; - int sliderX = fSliderX; + auto fSliderX = (fSize/fSteps)*fPosition;//sliderPosition;//((Size.X-6)/sliderSteps)*sliderPosition; + auto sliderX = int(fSliderX); sliderX += 3; g->fillrect(screenPos.X+sliderX-2, screenPos.Y+1, 4, Size.Y-2, 20, 20, 20, 255); diff --git a/src/gui/interface/Spinner.cpp b/src/gui/interface/Spinner.cpp index 19485d1ec..272b39488 100644 --- a/src/gui/interface/Spinner.cpp +++ b/src/gui/interface/Spinner.cpp @@ -30,7 +30,7 @@ void Spinner::Draw(const Point& screenPos) for(float t = 0.0f; t < 6.0f; t+=0.25f) { //g->drawblob(baseX+(sin(cValue+t)*(Size.X/2)), baseY+(cos(cValue+t)*(Size.X/2)), t*255, t*255, t*255); - g->draw_line(baseX+(sin(cValue+t)*lineInner), baseY+(cos(cValue+t)*lineInner), baseX+(sin(cValue+t)*lineOuter), baseY+(cos(cValue+t)*lineOuter), (t/6)*255, (t/6)*255, (t/6)*255, 255); + g->draw_line(int(baseX+(sin(cValue+t)*lineInner)), int(baseY+(cos(cValue+t)*lineInner)), int(baseX+(sin(cValue+t)*lineOuter)), int(baseY+(cos(cValue+t)*lineOuter)), int((t/6)*255), int((t/6)*255), int((t/6)*255), 255); } } Spinner::~Spinner() diff --git a/src/gui/localbrowser/LocalBrowserController.cpp b/src/gui/localbrowser/LocalBrowserController.cpp index 5df09b958..bbadf38fc 100644 --- a/src/gui/localbrowser/LocalBrowserController.cpp +++ b/src/gui/localbrowser/LocalBrowserController.cpp @@ -59,7 +59,7 @@ void LocalBrowserController::removeSelectedC() { notifyStatus(String::Build("Deleting stamp [", saves[i].FromUtf8(), "] ...")); Client::Ref().DeleteStamp(saves[i]); - notifyProgress((float(i+1)/float(saves.size())*100)); + notifyProgress((i + 1) * 100 / saves.size()); } return true; } diff --git a/src/gui/preview/PreviewView.cpp b/src/gui/preview/PreviewView.cpp index 2b25152d2..ae28dbf37 100644 --- a/src/gui/preview/PreviewView.cpp +++ b/src/gui/preview/PreviewView.cpp @@ -176,9 +176,9 @@ void PreviewView::commentBoxAutoHeight() commentBoxHeight = newSize+22; commentBoxPositionX = (XRES/2)+4; - commentBoxPositionY = Size.Y-(newSize+21); - commentBoxSizeX = Size.X-(XRES/2)-8; - commentBoxSizeY = newSize; + commentBoxPositionY = float(Size.Y-(newSize+21)); + commentBoxSizeX = float(Size.X-(XRES/2)-8); + commentBoxSizeY = float(newSize); if (commentWarningLabel && commentHelpText && !commentWarningLabel->Visible && addCommentBox->Position.Y+addCommentBox->Size.Y < Size.Y-14) { @@ -191,8 +191,8 @@ void PreviewView::commentBoxAutoHeight() addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; commentBoxPositionX = (XRES/2)+4; - commentBoxPositionY = Size.Y-19; - commentBoxSizeX = Size.X-(XRES/2)-48; + commentBoxPositionY = float(Size.Y-19); + commentBoxSizeX = float(Size.X-(XRES/2)-48); commentBoxSizeY = 17; if (commentWarningLabel && commentWarningLabel->Visible) @@ -299,14 +299,14 @@ void PreviewView::OnDraw() if (50>lv) { ryf = 50.0f/((float)lv); - nyu = votesUp*ryf; - nyd = votesDown*ryf; + nyu = int(votesUp*ryf); + nyd = int(votesDown*ryf); } else { ryf = ((float)lv)/50.0f; - nyu = votesUp/ryf; - nyd = votesDown/ryf; + nyu = int(votesUp/ryf); + nyd = int(votesDown/ryf); } nyu = nyu>50?50:nyu; nyd = nyd>50?50:nyd; @@ -325,8 +325,8 @@ void PreviewView::OnTick(float dt) { if(addCommentBox) { - ui::Point positionDiff = ui::Point(commentBoxPositionX, commentBoxPositionY)-addCommentBox->Position; - ui::Point sizeDiff = ui::Point(commentBoxSizeX, commentBoxSizeY)-addCommentBox->Size; + ui::Point positionDiff = ui::Point(int(commentBoxPositionX), int(commentBoxPositionY))-addCommentBox->Position; + ui::Point sizeDiff = ui::Point(int(commentBoxSizeX), int(commentBoxSizeY))-addCommentBox->Size; if(positionDiff.X!=0) { @@ -468,10 +468,10 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender) float factorX = ((float)XRES/2)/((float)savePreview->Width); float factorY = ((float)YRES/2)/((float)savePreview->Height); float scaleFactor = factorY < factorX ? factorY : factorX; - savePreview->Buffer = Graphics::resample_img(oldData, savePreview->Width, savePreview->Height, savePreview->Width*scaleFactor, savePreview->Height*scaleFactor); + savePreview->Buffer = Graphics::resample_img(oldData, savePreview->Width, savePreview->Height, int(savePreview->Width*scaleFactor), int(savePreview->Height*scaleFactor)); delete[] oldData; - savePreview->Width *= scaleFactor; - savePreview->Height *= scaleFactor; + savePreview->Width = int(savePreview->Width * scaleFactor); + savePreview->Height = int(savePreview->Height * scaleFactor); } } else if (!sender->GetCanOpen()) @@ -527,8 +527,8 @@ void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender) if(sender->GetCommentBoxEnabled()) { commentBoxPositionX = (XRES/2)+4; - commentBoxPositionY = Size.Y-19; - commentBoxSizeX = Size.X-(XRES/2)-48; + commentBoxPositionY = float(Size.Y-19); + commentBoxSizeX = float(Size.X-(XRES/2)-48); commentBoxSizeY = 17; addCommentBox = new ui::Textbox(ui::Point((XRES/2)+4, Size.Y-19), ui::Point(Size.X-(XRES/2)-48, 17), "", "Add Comment"); diff --git a/src/gui/search/SearchController.cpp b/src/gui/search/SearchController.cpp index b281549b1..d5fa5c008 100644 --- a/src/gui/search/SearchController.cpp +++ b/src/gui/search/SearchController.cpp @@ -259,7 +259,7 @@ void SearchController::removeSelectedC() c->Refresh(); return false; } - notifyProgress((float(i+1)/float(saves.size())*100)); + notifyProgress((i + 1) * 100 / saves.size()); } c->Refresh(); return true; @@ -328,7 +328,7 @@ void SearchController::unpublishSelectedC(bool publish) c->Refresh(); return false; } - notifyProgress((float(i+1)/float(saves.size())*100)); + notifyProgress((i + 1) * 100 / saves.size()); } c->Refresh(); return true; @@ -356,7 +356,7 @@ void SearchController::FavouriteSelected() notifyError(String::Build("Failed to favourite [", saves[i], "]: " + Client::Ref().GetLastError())); return false; } - notifyProgress((float(i+1)/float(saves.size())*100)); + notifyProgress((i + 1) * 100 / saves.size()); } return true; } @@ -377,7 +377,7 @@ void SearchController::FavouriteSelected() notifyError(String::Build("Failed to unfavourite [", saves[i], "]: " + Client::Ref().GetLastError())); return false; } - notifyProgress((float(i+1)/float(saves.size())*100)); + notifyProgress((i + 1) * 100 / saves.size()); } return true; } diff --git a/src/gui/update/UpdateActivity.cpp b/src/gui/update/UpdateActivity.cpp index 1b9b5472a..79edfb8e6 100644 --- a/src/gui/update/UpdateActivity.cpp +++ b/src/gui/update/UpdateActivity.cpp @@ -40,7 +40,7 @@ private: { int total, done; request->CheckProgress(&total, &done); - notifyProgress((float(done)/float(total))*100.0f); + notifyProgress(total ? done * 100 / total : 0); Platform::Millisleep(1); } diff --git a/src/lua/LegacyLuaAPI.cpp b/src/lua/LegacyLuaAPI.cpp index 886fd9ea9..52ca230fa 100644 --- a/src/lua/LegacyLuaAPI.cpp +++ b/src/lua/LegacyLuaAPI.cpp @@ -135,7 +135,7 @@ int luacon_partwrite(lua_State* l) *((float*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = luaL_optnumber(l, 3, 0); break; case CommandInterface::FormatElement: - luacon_sim->part_change_type(i, luacon_sim->parts[i].x, luacon_sim->parts[i].y, luaL_optinteger(l, 3, 0)); + luacon_sim->part_change_type(i, int(luacon_sim->parts[i].x + 0.5f), int(luacon_sim->parts[i].y + 0.5f), luaL_optinteger(l, 3, 0)); default: break; } @@ -256,7 +256,7 @@ int luacon_elementwrite(lua_State* l) if (prop.Name == "type") // i.e. it's .type { - luacon_sim->part_change_type(i, luacon_sim->parts[i].x+0.5f, luacon_sim->parts[i].y+0.5f, luaL_checkinteger(l, 3)); + luacon_sim->part_change_type(i, int(luacon_sim->parts[i].x+0.5f), int(luacon_sim->parts[i].y+0.5f), luaL_checkinteger(l, 3)); } else { @@ -591,7 +591,7 @@ int luatpt_set_pressure(lua_State* l) y1 = abs(luaL_optint(l, 2, 0)); width = abs(luaL_optint(l, 3, XRES/CELL)); height = abs(luaL_optint(l, 4, YRES/CELL)); - value = (float)luaL_optint(l, 5, 0.0f); + value = luaL_optnumber(l, 5, 0.0f); if(value > 256.0f) value = 256.0f; else if(value < -256.0f) @@ -622,7 +622,7 @@ int luatpt_set_gravity(lua_State* l) y1 = abs(luaL_optint(l, 2, 0)); width = abs(luaL_optint(l, 3, XRES/CELL)); height = abs(luaL_optint(l, 4, YRES/CELL)); - value = (float)luaL_optint(l, 5, 0.0f); + value = luaL_optnumber(l, 5, 0.0f); if(value > 256.0f) value = 256.0f; else if(value < -256.0f) @@ -809,7 +809,7 @@ int luatpt_set_property(lua_State* l) return 0; if (format == CommandInterface::FormatElement) - luacon_sim->part_change_type(i, luacon_sim->parts[i].x, luacon_sim->parts[i].y, t); + luacon_sim->part_change_type(i, int(luacon_sim->parts[i].x + 0.5f), int(luacon_sim->parts[i].y + 0.5f), t); else if (format == CommandInterface::FormatFloat) *((float*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = f; else @@ -875,14 +875,14 @@ int luatpt_set_elecmap(lua_State* l) { int nx, ny, acount; int x1, y1, width, height; - float value; + unsigned char value; acount = lua_gettop(l); x1 = abs(luaL_optint(l, 1, 0)); y1 = abs(luaL_optint(l, 2, 0)); width = abs(luaL_optint(l, 3, XRES/CELL)); height = abs(luaL_optint(l, 4, YRES/CELL)); - value = (float)luaL_optint(l, acount, 0); + value = luaL_optint(l, acount, 0); if(acount==5) //Draw rect { @@ -1369,10 +1369,10 @@ int luatpt_setfpscap(lua_State* l) int acount = lua_gettop(l); if (acount == 0) { - lua_pushinteger(l, ui::Engine::Ref().FpsLimit); + lua_pushnumber(l, ui::Engine::Ref().FpsLimit); return 1; } - int fpscap = luaL_checkint(l, 1); + float fpscap = luaL_checknumber(l, 1); if (fpscap < 2) return luaL_error(l, "fps cap too small"); ui::Engine::Ref().FpsLimit = fpscap; diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index d4a6f030b..b8c39c67a 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -65,6 +65,14 @@ extern "C" #include "socket.lua.h" #include "eventcompat.lua.h" +// idea from mniip, makes things much simpler +#define SETCONST(L, NAME)\ + lua_pushinteger(L, NAME);\ + lua_setfield(L, -2, #NAME) +#define SETCONSTF(L, NAME)\ + lua_pushnumber(L, NAME);\ + lua_setfield(L, -2, #NAME) + GameModel * luacon_model; GameController * luacon_controller; Simulation * luacon_sim; @@ -733,7 +741,7 @@ int LuaScriptInterface::simulation_newsign(lua_State *l) luacon_sim->signs.push_back(sign(text, x, y, (sign::Justification)ju)); - lua_pushnumber(l, luacon_sim->signs.size()); + lua_pushinteger(l, luacon_sim->signs.size()); return 1; } @@ -829,8 +837,8 @@ void LuaScriptInterface::initSimulationAPI() SETCONST(l, ST); SETCONST(l, ITH); SETCONST(l, ITL); - SETCONST(l, IPH); - SETCONST(l, IPL); + SETCONSTF(l, IPH); + SETCONSTF(l, IPL); SETCONST(l, PT_NUM); lua_pushinteger(l, 0); lua_setfield(l, -2, "NUM_PARTS"); SETCONST(l, R_TEMP); @@ -964,7 +972,7 @@ int LuaScriptInterface::simulation_partChangeType(lua_State * l) int partIndex = lua_tointeger(l, 1); if(partIndex < 0 || partIndex >= NPART || !luacon_sim->parts[partIndex].type) return 0; - luacon_sim->part_change_type(partIndex, luacon_sim->parts[partIndex].x+0.5f, luacon_sim->parts[partIndex].y+0.5f, lua_tointeger(l, 2)); + luacon_sim->part_change_type(partIndex, int(luacon_sim->parts[partIndex].x+0.5f), int(luacon_sim->parts[partIndex].y+0.5f), lua_tointeger(l, 2)); return 0; } @@ -1092,7 +1100,7 @@ int LuaScriptInterface::simulation_partProperty(lua_State * l) { if (prop == properties.begin() + 0) // i.e. it's .type { - luacon_sim->part_change_type(particleID, luacon_sim->parts[particleID].x+0.5f, luacon_sim->parts[particleID].y+0.5f, luaL_checkinteger(l, 3)); + luacon_sim->part_change_type(particleID, int(luacon_sim->parts[particleID].x+0.5f), int(luacon_sim->parts[particleID].y+0.5f), luaL_checkinteger(l, 3)); } else { diff --git a/src/lua/LuaScriptInterface.h b/src/lua/LuaScriptInterface.h index 61376bbe5..caa30a8aa 100644 --- a/src/lua/LuaScriptInterface.h +++ b/src/lua/LuaScriptInterface.h @@ -33,11 +33,6 @@ class Tool; #define LUACON_EL_MODIFIED_GRAPHICS 0x2 #define LUACON_EL_MODIFIED_MENUS 0x4 -// idea from mniip, makes things much simpler -#define SETCONST(L, NAME)\ - lua_pushinteger(L, NAME);\ - lua_setfield(L, -2, #NAME) - class Simulation; class TPTScriptInterface; class LuaComponent; diff --git a/src/lua/TPTSTypes.cpp b/src/lua/TPTSTypes.cpp index 00b84bec1..3019f5c53 100644 --- a/src/lua/TPTSTypes.cpp +++ b/src/lua/TPTSTypes.cpp @@ -26,7 +26,7 @@ AnyType::operator NumberType() if (type == TypeNumber) return NumberType(value.num); else if (type == TypeFloat) - return NumberType(value.numf); + return NumberType(int(value.numf)); else throw InvalidConversionException(type, TypeNumber); } @@ -34,7 +34,7 @@ AnyType::operator NumberType() AnyType::operator FloatType() { if (type == TypeNumber) - return FloatType(value.num); + return FloatType(float(value.num)); else if (type == TypeFloat) return FloatType(value.numf); else diff --git a/src/lua/TPTScriptInterface.cpp b/src/lua/TPTScriptInterface.cpp index 5d3c0ba72..e5c110108 100644 --- a/src/lua/TPTScriptInterface.cpp +++ b/src/lua/TPTScriptInterface.cpp @@ -273,11 +273,11 @@ AnyType TPTScriptInterface::tptS_set(std::deque * words) float newValuef = 0.0f; if (value.GetType() == TypeNumber) { - newValuef = newValue = ((NumberType)value).Value(); + newValuef = float(newValue = ((NumberType)value).Value()); } else if (value.GetType() == TypeFloat) { - newValue = newValuef = ((FloatType)value).Value(); + newValue = int(newValuef = ((FloatType)value).Value()); } else if(value.GetType() == TypeString) { @@ -332,7 +332,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque * words) *((float*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValuef; break; case FormatElement: - sim->part_change_type(partIndex, sim->parts[partIndex].x, sim->parts[partIndex].y, newValue); + sim->part_change_type(partIndex, int(sim->parts[partIndex].x + 0.5f), int(sim->parts[partIndex].y + 0.5f), newValue); break; default: break; @@ -369,7 +369,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque * words) if (sim->parts[j].type) { returnValue++; - sim->part_change_type(j, sim->parts[j].x, sim->parts[j].y, newValue); + sim->part_change_type(j, int(sim->parts[j].x + 0.5f), int(sim->parts[j].y + 0.5f), newValue); } } break; @@ -417,7 +417,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque * words) if (sim->parts[j].type == type) { returnValue++; - sim->part_change_type(j, sim->parts[j].x, sim->parts[j].y, newValue); + sim->part_change_type(j, int(sim->parts[j].x + 0.5f), int(sim->parts[j].y + 0.5f), newValue); } } break; @@ -523,7 +523,7 @@ AnyType TPTScriptInterface::tptS_bubble(std::deque * words) for (int i = 1; i<=30; i++) { - rem2 = sim->create_part(-1, bubblePos.X+18*cosf(i/5.0), bubblePos.Y+18*sinf(i/5.0), PT_SOAP); + rem2 = sim->create_part(-1, int(bubblePos.X+18*cosf(i/5.0)+0.5f), int(bubblePos.Y+18*sinf(i/5.0)+0.5f), PT_SOAP); sim->parts[rem1].ctype = 7; sim->parts[rem1].tmp = rem2; diff --git a/src/simulation/Air.cpp b/src/simulation/Air.cpp index 97e58b2f9..5e4c8f0cd 100644 --- a/src/simulation/Air.cpp +++ b/src/simulation/Air.cpp @@ -242,18 +242,18 @@ void Air::update_air(void) // Trying to take velocity from far away, check whether there is an intervening wall. Step from current position to desired source location, looking for walls, with either the x or y step size being 1 cell if (std::abs(dx)>std::abs(dy)) { - stepX = (dx<0.0f) ? 1 : -1; + stepX = (dx<0.0f) ? 1.f : -1.f; stepY = -dy/fabsf(dx); stepLimit = (int)(fabsf(dx*advDistanceMult)); } else { - stepY = (dy<0.0f) ? 1 : -1; + stepY = (dy<0.0f) ? 1.f : -1.f; stepX = -dx/fabsf(dy); stepLimit = (int)(fabsf(dy*advDistanceMult)); } - tx = x; - ty = y; + tx = float(x); + ty = float(y); for (step=0; step sign::split() return std::make_pair(0, Type::Normal); } } - return std::make_pair(pipe, text[1] == 'c' ? Type::Save : Type::Thread); + return std::make_pair(int(pipe), text[1] == 'c' ? Type::Save : Type::Thread); } break; @@ -174,7 +174,7 @@ std::pair sign::split() case 's': if (text[2] == ':' && (pipe = text.find('|', 3)) != text.npos) { - return std::make_pair(pipe, Type::Search); + return std::make_pair(int(pipe), Type::Search); } break; } diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 1920534e5..9f2d7bd78 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -903,8 +903,8 @@ bool Simulation::flood_water(int x, int y, int i) int oldy = (int)(parts[i].y + 0.5f); pmap[y - 1][x] = pmap[oldy][oldx]; pmap[oldy][oldx] = 0; - parts[i].x = x; - parts[i].y = y - 1; + parts[i].x = float(x); + parts[i].y = float(y - 1); return true; } @@ -991,7 +991,7 @@ void Simulation::SetEdgeMode(int newEdgeMode) void Simulation::ApplyDecoration(int x, int y, int colR_, int colG_, int colB_, int colA_, int mode) { int rp; - float tr, tg, tb, ta, colR = colR_, colG = colG_, colB = colB_, colA = colA_; + float tr, tg, tb, ta, colR = float(colR_), colG = float(colG_), colB = float(colB_), colA = float(colA_); float strength = 0.01f; rp = pmap[y][x]; if (!rp) @@ -999,10 +999,10 @@ void Simulation::ApplyDecoration(int x, int y, int colR_, int colG_, int colB_, if (!rp) return; - ta = (parts[ID(rp)].dcolour>>24)&0xFF; - tr = (parts[ID(rp)].dcolour>>16)&0xFF; - tg = (parts[ID(rp)].dcolour>>8)&0xFF; - tb = (parts[ID(rp)].dcolour)&0xFF; + ta = float((parts[ID(rp)].dcolour>>24)&0xFF); + tr = float((parts[ID(rp)].dcolour>>16)&0xFF); + tg = float((parts[ID(rp)].dcolour>>8)&0xFF); + tb = float((parts[ID(rp)].dcolour)&0xFF); ta /= 255.0f; tr /= 255.0f; tg /= 255.0f; tb /= 255.0f; colR /= 255.0f; colG /= 255.0f; colB /= 255.0f; colA /= 255.0f; @@ -1135,10 +1135,10 @@ void Simulation::ApplyDecoration(int x, int y, int colR_, int colG_, int colB_, ta *= 255.0f; tr *= 255.0f; tg *= 255.0f; tb *= 255.0f; ta += .5f; tr += .5f; tg += .5f; tb += .5f; - colA_ = ta; - colR_ = tr; - colG_ = tg; - colB_ = tb; + colA_ = int(ta); + colR_ = int(tr); + colG_ = int(tg); + colB_ = int(tb); if(colA_ > 255) colA_ = 255; @@ -2226,8 +2226,8 @@ void Simulation::create_arc(int sx, int sy, int dx, int dy, int midpoints, int v for(i = 1; i <= midpoints; i++) { - ymid[i] = ymid[i-1]+yint; - xmid[i] = xmid[i-1]+xint; + ymid[i] = ymid[i-1]+int(yint); + xmid[i] = xmid[i-1]+int(xint); } for(i = 0; i <= midpoints; i++) @@ -2692,7 +2692,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) if (parts[ID(r)].life == 0) { part_change_type(i, x, y, PT_GRVT); - parts[i].tmp = parts[ID(r)].temp - 273.15f; + parts[i].tmp = int(parts[ID(r)].temp - 273.15f); } break; } @@ -2811,21 +2811,21 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) if (s) { pmap[ny][nx] = (s&~PMAPMASK)|parts[ID(s)].type; - parts[ID(s)].x = nx; - parts[ID(s)].y = ny; + parts[ID(s)].x = float(nx); + parts[ID(s)].y = float(ny); } else pmap[ny][nx] = 0; - parts[ri].x = x; - parts[ri].y = y; + parts[ri].x = float(x); + parts[ri].y = float(y); pmap[y][x] = PMAP(ri, parts[ri].type); return 1; } if (ID(pmap[ny][nx]) == ri) pmap[ny][nx] = 0; - parts[ri].x += x-nx; - parts[ri].y += y-ny; + parts[ri].x += float(x-nx); + parts[ri].y += float(y-ny); pmap[(int)(parts[ri].y+0.5f)][(int)(parts[ri].x+0.5f)] = PMAP(ri, parts[ri].type); } return 1; @@ -3016,8 +3016,8 @@ int Simulation::get_normal(int pt, int x, int y, float dx, float dy, float *nx, if ((lx == rx) && (ly == ry)) return 0; - ex = rx - lx; - ey = ry - ly; + ex = float(rx - lx); + ey = float(ry - ly); r = 1.0f/hypot(ex, ey); *nx = ey * r; *ny = -ex * r; @@ -3246,9 +3246,9 @@ int Simulation::create_part(int p, int x, int y, int t, int v) if((elements[t].Properties & TYPE_PART) && pretty_powder) { int colr, colg, colb; - colr = PIXR(elements[t].Colour) + sandcolour * 1.3 + RNG::Ref().between(-20, 20) + RNG::Ref().between(-15, 15); - colg = PIXG(elements[t].Colour) + sandcolour * 1.3 + RNG::Ref().between(-20, 20) + RNG::Ref().between(-15, 15); - colb = PIXB(elements[t].Colour) + sandcolour * 1.3 + RNG::Ref().between(-20, 20) + RNG::Ref().between(-15, 15); + colr = PIXR(elements[t].Colour) + int(sandcolour * 1.3) + RNG::Ref().between(-20, 20) + RNG::Ref().between(-15, 15); + colg = PIXG(elements[t].Colour) + int(sandcolour * 1.3) + RNG::Ref().between(-20, 20) + RNG::Ref().between(-15, 15); + colb = PIXB(elements[t].Colour) + int(sandcolour * 1.3) + RNG::Ref().between(-20, 20) + RNG::Ref().between(-15, 15); colr = colr>255 ? 255 : (colr<0 ? 0 : colr); colg = colg>255 ? 255 : (colg<0 ? 0 : colg); colb = colb>255 ? 255 : (colb<0 ? 0 : colb); @@ -3281,7 +3281,7 @@ void Simulation::GetGravityField(int x, int y, float particleGrav, float newtonG case 2: //radial gravity if (x-XCNTR != 0 || y-YCNTR != 0) { - float pGravMult = particleGrav/sqrtf((x-XCNTR)*(x-XCNTR) + (y-YCNTR)*(y-YCNTR)); + float pGravMult = particleGrav/sqrtf(float((x-XCNTR)*(x-XCNTR) + (y-YCNTR)*(y-YCNTR))); pGravX -= pGravMult * (float)(x - XCNTR); pGravY -= pGravMult * (float)(y - YCNTR); } @@ -3499,7 +3499,7 @@ void Simulation::UpdateParticles(int start, int end) pGravX = pGravY = 0.0f; break; case 2: - pGravD = 0.01f - hypotf((x - XCNTR), (y - YCNTR)); + pGravD = 0.01f - hypotf(float(x - XCNTR), float(y - YCNTR)); pGravX = elements[t].Gravity * ((float)(x - XCNTR) / pGravD); pGravY = elements[t].Gravity * ((float)(y - YCNTR) / pGravD); break; @@ -3573,7 +3573,7 @@ void Simulation::UpdateParticles(int start, int end) #ifdef REALISTIC if (t&&(t!=PT_HSWC||parts[i].life==10)&&(elements[t].HeatConduct*gel_scale)) #else - if (t && (t!=PT_HSWC||parts[i].life==10) && RNG::Ref().chance(elements[t].HeatConduct*gel_scale, 250)) + if (t && (t!=PT_HSWC||parts[i].life==10) && RNG::Ref().chance(int(elements[t].HeatConduct*gel_scale), 250)) #endif { if (aheat_enable && !(elements[t].Properties&PROP_NOAMBHEAT)) @@ -3908,7 +3908,7 @@ void Simulation::UpdateParticles(int start, int end) pt = parts[i].temp = restrict_flt(parts[i].temp, MIN_TEMP, MAX_TEMP); if (t == PT_LAVA) { - parts[i].life = restrict_flt((parts[i].temp-700)/7, 0.0f, 400.0f); + parts[i].life = int(restrict_flt((parts[i].temp-700)/7, 0, 400)); if (parts[i].ctype==PT_THRM&&parts[i].tmp>0) { parts[i].tmp--; @@ -4315,8 +4315,8 @@ killed: parts[ID(r)].ctype = parts[i].type; parts[ID(r)].temp = parts[i].temp; parts[ID(r)].tmp2 = parts[i].life; - parts[ID(r)].pavg[0] = parts[i].tmp; - parts[ID(r)].pavg[1] = parts[i].ctype; + parts[ID(r)].pavg[0] = float(parts[i].tmp); + parts[ID(r)].pavg[1] = float(parts[i].ctype); kill_part(i); continue; } @@ -4453,7 +4453,7 @@ killed: rt = 10; if (t==PT_GEL) - rt = parts[i].tmp*0.20f+5.0f; + rt = int(parts[i].tmp*0.20f+5.0f); for (j=clear_x+r; j>=0 && j>=clear_x-rt && j 1000 ? 1000 : (parts[i].life < 0 ? 0 : parts[i].life); + auto change = parts[i].life > 1000 ? 1000 : (parts[i].life < 0 ? 0 : parts[i].life); multiplier = 1.0f+(change/100.0f); } else diff --git a/src/simulation/elements/ACID.cpp b/src/simulation/elements/ACID.cpp index 009c5f86a..499476c97 100644 --- a/src/simulation/elements/ACID.cpp +++ b/src/simulation/elements/ACID.cpp @@ -79,7 +79,7 @@ static int update(UPDATE_FUNC_ARGS) sim->kill_part(ID(r)); } } - else if (rt != PT_CLNE && rt != PT_PCLN && parts[i].life >= 50 && RNG::Ref().chance(sim->elements[rt].Hardness, 1000.0)) + else if (rt != PT_CLNE && rt != PT_PCLN && parts[i].life >= 50 && RNG::Ref().chance(sim->elements[rt].Hardness, 1000)) { if (sim->parts_avg(i, ID(r),PT_GLAS)!= PT_GLAS)//GLAS protects stuff from acid { diff --git a/src/simulation/elements/ARAY.cpp b/src/simulation/elements/ARAY.cpp index 0286a2a5b..ac567cd2a 100644 --- a/src/simulation/elements/ARAY.cpp +++ b/src/simulation/elements/ARAY.cpp @@ -150,8 +150,8 @@ static int update(UPDATE_FUNC_ARGS) { parts[np].temp = parts[r].temp; parts[np].life = parts[r].tmp2; - parts[np].tmp = parts[r].pavg[0]; - parts[np].ctype = parts[r].pavg[1]; + parts[np].tmp = int(parts[r].pavg[0]); + parts[np].ctype = int(parts[r].pavg[1]); parts[r].tmp = 0; parts[r].life = 10; break; diff --git a/src/simulation/elements/BANG.cpp b/src/simulation/elements/BANG.cpp index 4dd5098a5..ceb5fe1b9 100644 --- a/src/simulation/elements/BANG.cpp +++ b/src/simulation/elements/BANG.cpp @@ -108,8 +108,8 @@ static int update(UPDATE_FUNC_ARGS) parts[i].tmp = 0; parts[i].life = 50; parts[i].temp = restrict_flt((MAX_TEMP/3)+otemp, MIN_TEMP, MAX_TEMP); - parts[i].vx = RNG::Ref().between(-10, 10); - parts[i].vy = RNG::Ref().between(-10, 10); + parts[i].vx = float(RNG::Ref().between(-10, 10)); + parts[i].vy = float(RNG::Ref().between(-10, 10)); } else { diff --git a/src/simulation/elements/BIZR.cpp b/src/simulation/elements/BIZR.cpp index 92eae129a..64f907868 100644 --- a/src/simulation/elements/BIZR.cpp +++ b/src/simulation/elements/BIZR.cpp @@ -65,20 +65,20 @@ int Element_BIZR_update(UPDATE_FUNC_ARGS) continue; if (TYP(r)!=PT_BIZR && TYP(r)!=PT_BIZRG && TYP(r)!=PT_BIZRS) { - tr = (parts[ID(r)].dcolour>>16)&0xFF; - tg = (parts[ID(r)].dcolour>>8)&0xFF; - tb = (parts[ID(r)].dcolour)&0xFF; - ta = (parts[ID(r)].dcolour>>24)&0xFF; + tr = float((parts[ID(r)].dcolour>>16)&0xFF); + tg = float((parts[ID(r)].dcolour>>8)&0xFF); + tb = float((parts[ID(r)].dcolour)&0xFF); + ta = float((parts[ID(r)].dcolour>>24)&0xFF); - mr = (parts[i].dcolour>>16)&0xFF; - mg = (parts[i].dcolour>>8)&0xFF; - mb = (parts[i].dcolour)&0xFF; - ma = (parts[i].dcolour>>24)&0xFF; + mr = float((parts[i].dcolour>>16)&0xFF); + mg = float((parts[i].dcolour>>8)&0xFF); + mb = float((parts[i].dcolour)&0xFF); + ma = float((parts[i].dcolour>>24)&0xFF); - nr = (tr*BLEND) + (mr*(1 - BLEND)); - ng = (tg*BLEND) + (mg*(1 - BLEND)); - nb = (tb*BLEND) + (mb*(1 - BLEND)); - na = (ta*BLEND) + (ma*(1 - BLEND)); + nr = int((tr*BLEND) + (mr*(1 - BLEND))); + ng = int((tg*BLEND) + (mg*(1 - BLEND))); + nb = int((tb*BLEND) + (mb*(1 - BLEND))); + na = int((ta*BLEND) + (ma*(1 - BLEND))); parts[ID(r)].dcolour = nr<<16 | ng<<8 | nb | na<<24; } @@ -113,9 +113,9 @@ int Element_BIZR_graphics(GRAPHICS_FUNC_ARGS) { brightness /= 5; *firea = 255; - *fireg = *colg * brightness; - *fireb = *colb * brightness; - *firer = *colr * brightness; + *fireg = int(*colg * brightness); + *fireb = int(*colb * brightness); + *firer = int(*colr * brightness); *pixel_mode |= FIRE_ADD; } *pixel_mode |= PMODE_BLUR; diff --git a/src/simulation/elements/BOMB.cpp b/src/simulation/elements/BOMB.cpp index a6ef4f59c..3b6481990 100644 --- a/src/simulation/elements/BOMB.cpp +++ b/src/simulation/elements/BOMB.cpp @@ -99,8 +99,8 @@ static int update(UPDATE_FUNC_ARGS) parts[nb].tmp = 0; parts[nb].life = 50; parts[nb].temp = MAX_TEMP; - parts[nb].vx = RNG::Ref().between(-20, 20); - parts[nb].vy = RNG::Ref().between(-20, 20); + parts[nb].vx = float(RNG::Ref().between(-20, 20)); + parts[nb].vy = float(RNG::Ref().between(-20, 20)); } } sim->kill_part(i); diff --git a/src/simulation/elements/BRMT.cpp b/src/simulation/elements/BRMT.cpp index 318ea889e..5413a92da 100644 --- a/src/simulation/elements/BRMT.cpp +++ b/src/simulation/elements/BRMT.cpp @@ -50,7 +50,7 @@ static int update(UPDATE_FUNC_ARGS) int r, rx, ry, tempFactor; if (parts[i].temp > 523.15f)//250.0f+273.15f { - tempFactor = 1000 - ((523.15f-parts[i].temp)*2); + tempFactor = int(1000 - ((523.15f-parts[i].temp)*2)); if(tempFactor < 2) tempFactor = 2; for (rx=-1; rx<2; rx++) diff --git a/src/simulation/elements/CBNW.cpp b/src/simulation/elements/CBNW.cpp index 3a9438ca5..37e21cc95 100644 --- a/src/simulation/elements/CBNW.cpp +++ b/src/simulation/elements/CBNW.cpp @@ -91,7 +91,7 @@ static int update(UPDATE_FUNC_ARGS) //Start explode parts[i].tmp = RNG::Ref().between(0, 24); } - else if((sim->elements[TYP(r)].Properties&TYPE_SOLID) && TYP(r)!=PT_DMND && TYP(r)!=PT_GLAS && parts[i].tmp == 0 && RNG::Ref().chance(2 - sim->pv[y/CELL][x/CELL], 6667)) + else if((sim->elements[TYP(r)].Properties&TYPE_SOLID) && TYP(r)!=PT_DMND && TYP(r)!=PT_GLAS && parts[i].tmp == 0 && RNG::Ref().chance(int(2 - sim->pv[y/CELL][x/CELL]), 6667)) { sim->part_change_type(i,x,y,PT_CO2); parts[i].ctype = 5; diff --git a/src/simulation/elements/CFLM.cpp b/src/simulation/elements/CFLM.cpp index 2ea9beca9..d11216da3 100644 --- a/src/simulation/elements/CFLM.cpp +++ b/src/simulation/elements/CFLM.cpp @@ -51,7 +51,7 @@ void Element::Element_CFLM() static int graphics(GRAPHICS_FUNC_ARGS) { - int caddress = restrict_flt(restrict_flt((float)((int)(cpart->life/2)), 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3); + int caddress = int(restrict_flt(float(cpart->life / 2), 0, 199)) * 3; *colr = hflm_data[caddress]; *colg = hflm_data[caddress+1]; *colb = hflm_data[caddress+2]; diff --git a/src/simulation/elements/CLST.cpp b/src/simulation/elements/CLST.cpp index 83ff51f53..25442207d 100644 --- a/src/simulation/elements/CLST.cpp +++ b/src/simulation/elements/CLST.cpp @@ -76,13 +76,13 @@ static int update(UPDATE_FUNC_ARGS) else if (TYP(r)==PT_CLST) { if(parts[i].temp <195) - cxy = 0.05; + cxy = 0.05f; else if(parts[i].temp <295) - cxy = 0.015; + cxy = 0.015f; else if(parts[i].temp <350) - cxy = 0.01; + cxy = 0.01f; else - cxy = 0.005; + cxy = 0.005f; parts[i].vx += cxy*rx; parts[i].vy += cxy*ry;//These two can be set not to calculate over 350 later. They do virtually nothing over 0.005. } diff --git a/src/simulation/elements/COAL.cpp b/src/simulation/elements/COAL.cpp index a87930831..e79c88902 100644 --- a/src/simulation/elements/COAL.cpp +++ b/src/simulation/elements/COAL.cpp @@ -72,16 +72,16 @@ int Element_COAL_update(UPDATE_FUNC_ARGS) } } if(parts[i].temp > parts[i].tmp2) - parts[i].tmp2 = parts[i].temp; + parts[i].tmp2 = int(parts[i].temp); return 0; } -constexpr float FREQUENCY = 3.1415/(2*300.0f-(300.0f-200.0f)); +constexpr float FREQUENCY = 3.1415f/(2*300.0f-(300.0f-200.0f)); int Element_COAL_graphics(GRAPHICS_FUNC_ARGS) //Both COAL and Broken Coal { - *colr += (cpart->tmp2-295.15f)/3; + *colr += int((cpart->tmp2-295.15f)/3); if (*colr > 170) *colr = 170; @@ -94,11 +94,11 @@ int Element_COAL_graphics(GRAPHICS_FUNC_ARGS) if (cpart->temp > 395.15f) { // q = ((cpart->temp-295.15f)>300.0f)?300.0f-(300.0f-200.0f):(cpart->temp-295.15f)-(300.0f-200.0f); - int q = (cpart->temp > 595.15f) ? 200.0f : cpart->temp - 395.15f; + auto q = int((cpart->temp > 595.15f) ? 200.0f : cpart->temp - 395.15f); - *colr += sin(FREQUENCY*q) * 226; - *colg += sin(FREQUENCY*q*4.55 + 3.14) * 34; - *colb += sin(FREQUENCY*q*2.22 + 3.14) * 64; + *colr += int(sin(FREQUENCY*q) * 226); + *colg += int(sin(FREQUENCY*q*4.55 + 3.14) * 34); + *colb += int(sin(FREQUENCY*q*2.22 + 3.14) * 64); } return 0; } diff --git a/src/simulation/elements/DEUT.cpp b/src/simulation/elements/DEUT.cpp index 748020cca..60d51aa3d 100644 --- a/src/simulation/elements/DEUT.cpp +++ b/src/simulation/elements/DEUT.cpp @@ -57,12 +57,12 @@ static int update(UPDATE_FUNC_ARGS) float gravtot = fabs(sim->gravy[(y/CELL)*(XRES/CELL)+(x/CELL)])+fabs(sim->gravx[(y/CELL)*(XRES/CELL)+(x/CELL)]); // Prevent division by 0 float temp = std::max(1.0f, (parts[i].temp + 1)); - int maxlife = ((10000/(temp + 1))-1); + auto maxlife = int(((10000/(temp + 1))-1)); if (RNG::Ref().chance(10000 % static_cast(temp + 1), static_cast(temp + 1))) maxlife++; // Compress when Newtonian gravity is applied // multiplier=1 when gravtot=0, multiplier -> 5 as gravtot -> inf - maxlife = maxlife*(5.0f - 8.0f/(gravtot+2.0f)); + maxlife = maxlife*int(5.0f - 8.0f/(gravtot+2.0f)); if (parts[i].life < maxlife) { for (rx=-1; rx<2; rx++) diff --git a/src/simulation/elements/DMG.cpp b/src/simulation/elements/DMG.cpp index 86af71246..d550d47e7 100644 --- a/src/simulation/elements/DMG.cpp +++ b/src/simulation/elements/DMG.cpp @@ -68,7 +68,7 @@ static int update(UPDATE_FUNC_ARGS) for (nxi=-rad; nxi<=rad; nxi++) if (x+nxi>=0 && y+nxj>=0 && x+nxiphotons[yCurrent][xCurrent])]; else parts[p] = parts[ID(pmap[yCurrent][xCurrent])]; - parts[p].x = xCopyTo; - parts[p].y = yCopyTo; + parts[p].x = float(xCopyTo); + parts[p].y = float(yCopyTo); } } } diff --git a/src/simulation/elements/ELEC.cpp b/src/simulation/elements/ELEC.cpp index f4d9a687a..f8df72039 100644 --- a/src/simulation/elements/ELEC.cpp +++ b/src/simulation/elements/ELEC.cpp @@ -73,8 +73,8 @@ static int update(UPDATE_FUNC_ARGS) parts[nb].tmp = 0; parts[nb].life = 50; parts[nb].temp = parts[i].temp*0.8f; - parts[nb].vx = RNG::Ref().between(-10, 10); - parts[nb].vy = RNG::Ref().between(-10, 10); + parts[nb].vx = float(RNG::Ref().between(-10, 10)); + parts[nb].vy = float(RNG::Ref().between(-10, 10)); } } sim->kill_part(i); diff --git a/src/simulation/elements/EMBR.cpp b/src/simulation/elements/EMBR.cpp index 5bdda6cc5..2c7e256f4 100644 --- a/src/simulation/elements/EMBR.cpp +++ b/src/simulation/elements/EMBR.cpp @@ -84,9 +84,9 @@ static int graphics(GRAPHICS_FUNC_ARGS) if (maxComponent<60)//make sure it isn't too dark to see { float multiplier = 60.0f/maxComponent; - *colr *= multiplier; - *colg *= multiplier; - *colb *= multiplier; + *colr = int(*colr * multiplier); + *colg = int(*colg * multiplier); + *colb = int(*colb * multiplier); } } else if (cpart->tmp != 0) diff --git a/src/simulation/elements/EMP.cpp b/src/simulation/elements/EMP.cpp index 8a9a67978..0a464097d 100644 --- a/src/simulation/elements/EMP.cpp +++ b/src/simulation/elements/EMP.cpp @@ -108,8 +108,8 @@ void Element_EMP_Trigger(Simulation *sim, int triggerCount) for (int r = 0; r <=sim->parts_lastActiveIndex; r++) { int t = parts[r].type; - int rx = parts[r].x; - int ry = parts[r].y; + auto rx = int(parts[r].x); + auto ry = int(parts[r].y); if (t==PT_SPRK || (t==PT_SWCH && parts[r].life!=0 && parts[r].life!=10) || (t==PT_WIRE && parts[r].ctype>0)) { bool is_elec = false; @@ -165,7 +165,7 @@ void Element_EMP_Trigger(Simulation *sim, int triggerCount) if (RNG::Ref().uniform01() < prob_randWIFI) { // Randomize channel - parts[n].temp = RNG::Ref().between(0, MAX_TEMP-1); + parts[n].temp = float(RNG::Ref().between(0, MAX_TEMP-1)); } if (RNG::Ref().uniform01() < prob_breakWIFI) { @@ -210,8 +210,8 @@ static int graphics(GRAPHICS_FUNC_ARGS) { if(cpart->life) { - *colr = cpart->life*1.5; - *colg = cpart->life*1.5; + *colr = int(cpart->life*1.5); + *colg = int(cpart->life*1.5); *colb = 200-(cpart->life); } return 0; diff --git a/src/simulation/elements/ETRD.cpp b/src/simulation/elements/ETRD.cpp index 37903ca07..f7114dbf6 100644 --- a/src/simulation/elements/ETRD.cpp +++ b/src/simulation/elements/ETRD.cpp @@ -102,7 +102,7 @@ int Element_ETRD_nearestSparkablePart(Simulation *sim, int targetId) Particle *parts = sim->parts; int foundDistance = XRES + YRES; int foundI = -1; - ui::Point targetPos = ui::Point(parts[targetId].x, parts[targetId].y); + ui::Point targetPos = ui::Point(int(parts[targetId].x), int(parts[targetId].y)); if (sim->etrd_count_valid) { @@ -141,7 +141,7 @@ int Element_ETRD_nearestSparkablePart(Simulation *sim, int targetId) { if (parts[i].type == PT_ETRD && !parts[i].life) { - ui::Point checkPos = ui::Point(parts[i].x-targetPos.X, parts[i].y-targetPos.Y); + ui::Point checkPos = ui::Point(int(parts[i].x)-targetPos.X, int(parts[i].y)-targetPos.Y); int checkDistance = std::abs(checkPos.X) + std::abs(checkPos.Y); if (checkDistance < foundDistance && i != targetId) { @@ -161,7 +161,7 @@ int Element_ETRD_nearestSparkablePart(Simulation *sim, int targetId) if (parts[i].type == PT_ETRD && !parts[i].life) { countLife0++; - ui::Point checkPos = ui::Point(parts[i].x-targetPos.X, parts[i].y-targetPos.Y); + ui::Point checkPos = ui::Point(int(parts[i].x)-targetPos.X, int(parts[i].y)-targetPos.Y); int checkDistance = std::abs(checkPos.X) + std::abs(checkPos.Y); if (checkDistance < foundDistance && i != targetId) { diff --git a/src/simulation/elements/EXOT.cpp b/src/simulation/elements/EXOT.cpp index 5665ae92a..315ccc785 100644 --- a/src/simulation/elements/EXOT.cpp +++ b/src/simulation/elements/EXOT.cpp @@ -176,7 +176,7 @@ static int update(UPDATE_FUNC_ARGS) { parts[i].vx = 0; parts[i].vy = 0; - sim->pv[y/CELL][x/CELL] -= 0.01; + sim->pv[y/CELL][x/CELL] -= 0.01f; parts[i].tmp--; } return 0; @@ -184,17 +184,17 @@ static int update(UPDATE_FUNC_ARGS) static int graphics(GRAPHICS_FUNC_ARGS) { - int q = cpart->temp; - int b = cpart->tmp; - int c = cpart->tmp2; + auto q = cpart->temp; + auto b = cpart->tmp; + auto c = cpart->tmp2; if (cpart->life < 1001) { if (RNG::Ref().chance(cpart->tmp2 - 1, 1000)) { - float frequency = 0.04045; - *colr = (sin(frequency*c + 4) * 127 + 150); - *colg = (sin(frequency*c + 6) * 127 + 150); - *colb = (sin(frequency*c + 8) * 127 + 150); + float frequency = 0.04045f; + *colr = int(sin(frequency*c + 4) * 127 + 150); + *colg = int(sin(frequency*c + 6) * 127 + 150); + *colb = int(sin(frequency*c + 8) * 127 + 150); *firea = 100; *firer = 0; @@ -206,10 +206,10 @@ static int graphics(GRAPHICS_FUNC_ARGS) } else { - float frequency = 0.00045; - *colr = (sin(frequency*q + 4) * 127 + (b/1.7)); - *colg = (sin(frequency*q + 6) * 127 + (b/1.7)); - *colb = (sin(frequency*q + 8) * 127 + (b/1.7)); + float frequency = 0.00045f; + *colr = int(sin(frequency*q + 4) * 127 + (b/1.7)); + *colg = int(sin(frequency*q + 6) * 127 + (b/1.7)); + *colb = int(sin(frequency*q + 8) * 127 + (b/1.7)); *cola = cpart->tmp / 6; *firea = *cola; @@ -223,10 +223,10 @@ static int graphics(GRAPHICS_FUNC_ARGS) } else { - float frequency = 0.01300; - *colr = (sin(frequency*q + 6.00) * 127 + ((b/2.9) + 80)); - *colg = (sin(frequency*q + 6.00) * 127 + ((b/2.9) + 80)); - *colb = (sin(frequency*q + 6.00) * 127 + ((b/2.9) + 80)); + float frequency = 0.01300f; + *colr = int(sin(frequency*q + 6.00) * 127 + ((b/2.9) + 80)); + *colg = int(sin(frequency*q + 6.00) * 127 + ((b/2.9) + 80)); + *colb = int(sin(frequency*q + 6.00) * 127 + ((b/2.9) + 80)); *cola = cpart->tmp / 6; *firea = *cola; *firer = *colr; diff --git a/src/simulation/elements/FIGH.cpp b/src/simulation/elements/FIGH.cpp index bdf2a4ae7..f2d0b2c4a 100644 --- a/src/simulation/elements/FIGH.cpp +++ b/src/simulation/elements/FIGH.cpp @@ -109,8 +109,8 @@ static int update(UPDATE_FUNC_ARGS) } else if (tarxrocketBoots || !(sim->eval_move(PT_FIGH, figh->legs[4]-10, figh->legs[5]+6, NULL) - && sim->eval_move(PT_FIGH, figh->legs[4]-10, figh->legs[5]+3, NULL))) + if(figh->rocketBoots || !(sim->eval_move(PT_FIGH, int(figh->legs[4])-10, int(figh->legs[5])+6, NULL) + && sim->eval_move(PT_FIGH, int(figh->legs[4])-10, int(figh->legs[5])+3, NULL))) figh->comm = 0x01; else figh->comm = 0x02; @@ -120,15 +120,15 @@ static int update(UPDATE_FUNC_ARGS) if (tarycomm = (int)figh->comm | 0x04; } - else if (!sim->eval_move(PT_FIGH, figh->legs[4]-4, figh->legs[5]-1, NULL) - || !sim->eval_move(PT_FIGH, figh->legs[12]-4, figh->legs[13]-1, NULL) - || sim->eval_move(PT_FIGH, 2*figh->legs[4]-figh->legs[6], figh->legs[5]+5, NULL)) + else if (!sim->eval_move(PT_FIGH, int(figh->legs[4])-4, int(figh->legs[5])-1, NULL) + || !sim->eval_move(PT_FIGH, int(figh->legs[12])-4, int(figh->legs[13])-1, NULL) + || sim->eval_move(PT_FIGH, 2*int(figh->legs[4])-int(figh->legs[6]), int(figh->legs[5])+5, NULL)) figh->comm = (int)figh->comm | 0x04; } else { - if (figh->rocketBoots || !(sim->eval_move(PT_FIGH, figh->legs[12]+10, figh->legs[13]+6, NULL) - && sim->eval_move(PT_FIGH, figh->legs[12]+10, figh->legs[13]+3, NULL))) + if (figh->rocketBoots || !(sim->eval_move(PT_FIGH, int(figh->legs[12])+10, int(figh->legs[13])+6, NULL) + && sim->eval_move(PT_FIGH, int(figh->legs[12])+10, int(figh->legs[13])+3, NULL))) figh->comm = 0x02; else figh->comm = 0x01; @@ -138,9 +138,9 @@ static int update(UPDATE_FUNC_ARGS) if (tarycomm = (int)figh->comm | 0x04; } - else if (!sim->eval_move(PT_FIGH, figh->legs[4]+4, figh->legs[5]-1, NULL) - || !sim->eval_move(PT_FIGH, figh->legs[4]+4, figh->legs[5]-1, NULL) - || sim->eval_move(PT_FIGH, 2*figh->legs[12]-figh->legs[14], figh->legs[13]+5, NULL)) + else if (!sim->eval_move(PT_FIGH, int(figh->legs[4])+4, int(figh->legs[5])-1, NULL) + || !sim->eval_move(PT_FIGH, int(figh->legs[4])+4, int(figh->legs[5])-1, NULL) + || sim->eval_move(PT_FIGH, 2*int(figh->legs[12])-int(figh->legs[14]), int(figh->legs[13])+5, NULL)) figh->comm = (int)figh->comm | 0x04; } break; diff --git a/src/simulation/elements/FIRE.cpp b/src/simulation/elements/FIRE.cpp index 24218e2e1..074f2b7e7 100644 --- a/src/simulation/elements/FIRE.cpp +++ b/src/simulation/elements/FIRE.cpp @@ -256,7 +256,7 @@ int Element_FIRE_update(UPDATE_FUNC_ARGS) } if ((surround_space || sim->elements[rt].Explosive) && - sim->elements[rt].Flammable && RNG::Ref().chance(sim->elements[rt].Flammable + (sim->pv[(y+ry)/CELL][(x+rx)/CELL] * 10.0f), 1000) && + sim->elements[rt].Flammable && RNG::Ref().chance(int(sim->elements[rt].Flammable + (sim->pv[(y+ry)/CELL][(x+rx)/CELL] * 10.0f)), 1000) && //exceptions, t is the thing causing the spark and rt is what's burning (t != PT_SPRK || (rt != PT_RBDM && rt != PT_LRBD && rt != PT_INSL)) && (t != PT_PHOT || rt != PT_INSL) && @@ -350,7 +350,7 @@ static int updateLegacy(UPDATE_FUNC_ARGS) static int graphics(GRAPHICS_FUNC_ARGS) { - int caddress = restrict_flt(restrict_flt((float)cpart->life, 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3); + int caddress = int(restrict_flt(float(cpart->life), 0, 199)) * 3; *colr = (unsigned char)ren->flm_data[caddress]; *colg = (unsigned char)ren->flm_data[caddress+1]; *colb = (unsigned char)ren->flm_data[caddress+2]; diff --git a/src/simulation/elements/FIRW.cpp b/src/simulation/elements/FIRW.cpp index 6135f3fd3..642f0ebcb 100644 --- a/src/simulation/elements/FIRW.cpp +++ b/src/simulation/elements/FIRW.cpp @@ -104,7 +104,7 @@ static int update(UPDATE_FUNC_ARGS) parts[np].ctype = col; parts[np].tmp = 1; parts[np].life = RNG::Ref().between(70, 109); - parts[np].temp = RNG::Ref().between(5750, 6249); + parts[np].temp = float(RNG::Ref().between(5750, 6249)); parts[np].dcolour = parts[i].dcolour; } } diff --git a/src/simulation/elements/FRZZ.cpp b/src/simulation/elements/FRZZ.cpp index 2cafa88f9..5cf71423b 100644 --- a/src/simulation/elements/FRZZ.cpp +++ b/src/simulation/elements/FRZZ.cpp @@ -40,7 +40,7 @@ void Element::Element_FRZZ() HighPressureTransition = PT_SNOW; LowTemperature = 50.0f; LowTemperatureTransition = PT_ICEI; - HighTemperature = 273.15; + HighTemperature = 273.15f; HighTemperatureTransition = PT_FRZW; Update = &update; diff --git a/src/simulation/elements/FWRK.cpp b/src/simulation/elements/FWRK.cpp index 34165217e..8f6f52396 100644 --- a/src/simulation/elements/FWRK.cpp +++ b/src/simulation/elements/FWRK.cpp @@ -48,7 +48,7 @@ void Element::Element_FWRK() static int update(UPDATE_FUNC_ARGS) { - if (parts[i].life == 0 && ((surround_space && parts[i].temp>400 && RNG::Ref().chance(9+parts[i].temp/40, 100000)) || parts[i].ctype == PT_DUST)) + if (parts[i].life == 0 && ((surround_space && parts[i].temp>400 && RNG::Ref().chance(int(9+parts[i].temp/40), 100000)) || parts[i].ctype == PT_DUST)) { float gx, gy, multiplier, gmax; int randTmp; @@ -100,7 +100,7 @@ static int update(UPDATE_FUNC_ARGS) parts[np].ctype = col; parts[np].tmp = 1; parts[np].life = RNG::Ref().between(70, 109); - parts[np].temp = RNG::Ref().between(5750, 6249); + parts[np].temp = float(RNG::Ref().between(5750, 6249)); parts[np].dcolour = parts[i].dcolour; } } diff --git a/src/simulation/elements/GEL.cpp b/src/simulation/elements/GEL.cpp index bf4c7f0e6..aa0b8a7fc 100644 --- a/src/simulation/elements/GEL.cpp +++ b/src/simulation/elements/GEL.cpp @@ -139,7 +139,7 @@ static int update(UPDATE_FUNC_ARGS) nd = dx*dx + dy*dy - 0.5; per = 5*(1 - parts[i].tmp/100)*(nd/(dx*dx + dy*dy + nd) - 0.5); if (sim->elements[rt].Properties&TYPE_LIQUID) - per *= 0.1; + per *= 0.1f; dx *= per; dy *= per; parts[i].vx += dx; parts[i].vy += dy; diff --git a/src/simulation/elements/GLOW.cpp b/src/simulation/elements/GLOW.cpp index ac03a3f13..26a312405 100644 --- a/src/simulation/elements/GLOW.cpp +++ b/src/simulation/elements/GLOW.cpp @@ -66,7 +66,7 @@ static int update(UPDATE_FUNC_ARGS) return 1; } } - parts[i].ctype = sim->pv[y/CELL][x/CELL]*16; + parts[i].ctype = int(sim->pv[y/CELL][x/CELL]*16); parts[i].tmp = abs((int)((sim->vx[y/CELL][x/CELL]+sim->vy[y/CELL][x/CELL])*16.0f)) + abs((int)((parts[i].vx+parts[i].vy)*64.0f)); return 0; @@ -74,13 +74,13 @@ static int update(UPDATE_FUNC_ARGS) static int graphics(GRAPHICS_FUNC_ARGS) { - *firer = restrict_flt(cpart->temp-(275.13f+32.0f), 0, 128)/50.0f; - *fireg = restrict_flt(cpart->ctype, 0, 128)/50.0f; - *fireb = restrict_flt(cpart->tmp, 0, 128)/50.0f; + *firer = int(restrict_flt(cpart->temp-(275.13f+32.0f), 0, 128)/50.0f); + *fireg = int(restrict_flt(float(cpart->ctype), 0, 128)/50.0f); + *fireb = int(restrict_flt(float(cpart->tmp), 0, 128)/50.0f); - *colr = restrict_flt(64.0f+cpart->temp-(275.13f+32.0f), 0, 255); - *colg = restrict_flt(64.0f+cpart->ctype, 0, 255); - *colb = restrict_flt(64.0f+cpart->tmp, 0, 255); + *colr = int(restrict_flt(64.0f+cpart->temp-(275.13f+32.0f), 0, 255)); + *colg = int(restrict_flt(64.0f+cpart->ctype, 0, 255)); + *colb = int(restrict_flt(64.0f+cpart->tmp, 0, 255)); *pixel_mode |= FIRE_ADD; return 0; diff --git a/src/simulation/elements/GPMP.cpp b/src/simulation/elements/GPMP.cpp index 845baa9b2..aaed7af39 100644 --- a/src/simulation/elements/GPMP.cpp +++ b/src/simulation/elements/GPMP.cpp @@ -59,10 +59,10 @@ static int update(UPDATE_FUNC_ARGS) } else { - if (parts[i].temp>=256.0+273.15) - parts[i].temp=256.0+273.15; - if (parts[i].temp<= -256.0+273.15) - parts[i].temp = -256.0+273.15; + if (parts[i].temp>=256.0f+273.15f) + parts[i].temp=256.0f+273.15f; + if (parts[i].temp<= -256.0f+273.15f) + parts[i].temp = -256.0f+273.15f; sim->gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = 0.2f*(parts[i].temp-273.15); for (rx=-2; rx<3; rx++) diff --git a/src/simulation/elements/GRAV.cpp b/src/simulation/elements/GRAV.cpp index 51bc907bd..4fca0d105 100644 --- a/src/simulation/elements/GRAV.cpp +++ b/src/simulation/elements/GRAV.cpp @@ -76,29 +76,29 @@ static int graphics(GRAPHICS_FUNC_ARGS) *colb = 20; if (cpart->vx>0) { - *colr += (cpart->vx)*GRAV_R; - *colg += (cpart->vx)*GRAV_G; - *colb += (cpart->vx)*GRAV_B; + *colr += int((cpart->vx)*GRAV_R); + *colg += int((cpart->vx)*GRAV_G); + *colb += int((cpart->vx)*GRAV_B); } if (cpart->vy>0) { - *colr += (cpart->vy)*GRAV_G; - *colg += (cpart->vy)*GRAV_B; - *colb += (cpart->vy)*GRAV_R; + *colr += int((cpart->vy)*GRAV_G); + *colg += int((cpart->vy)*GRAV_B); + *colb += int((cpart->vy)*GRAV_R); } if (cpart->vx<0) { - *colr -= (cpart->vx)*GRAV_B; - *colg -= (cpart->vx)*GRAV_R; - *colb -= (cpart->vx)*GRAV_G; + *colr -= int((cpart->vx)*GRAV_B); + *colg -= int((cpart->vx)*GRAV_R); + *colb -= int((cpart->vx)*GRAV_G); } if (cpart->vy<0) { - *colr -= (cpart->vy)*GRAV_R2; - *colg -= (cpart->vy)*GRAV_G2; - *colb -= (cpart->vy)*GRAV_B2; + *colr -= int((cpart->vy)*GRAV_R2); + *colg -= int((cpart->vy)*GRAV_G2); + *colb -= int((cpart->vy)*GRAV_B2); } if (cpart->life) diff --git a/src/simulation/elements/HSWC.cpp b/src/simulation/elements/HSWC.cpp index 268130d39..f34198860 100644 --- a/src/simulation/elements/HSWC.cpp +++ b/src/simulation/elements/HSWC.cpp @@ -80,7 +80,7 @@ static int update(UPDATE_FUNC_ARGS) { int newTemp = parts[ID(r)].ctype - 0x10000000; if (newTemp >= MIN_TEMP && newTemp <= MAX_TEMP) - parts[i].temp = parts[ID(r)].ctype - 0x10000000; + parts[i].temp = float(parts[ID(r)].ctype - 0x10000000); } } } diff --git a/src/simulation/elements/IGNT.cpp b/src/simulation/elements/IGNT.cpp index 6f8e8ec6e..624a68b3d 100644 --- a/src/simulation/elements/IGNT.cpp +++ b/src/simulation/elements/IGNT.cpp @@ -74,8 +74,8 @@ static int update(UPDATE_FUNC_ARGS) if (nb!=-1) { parts[nb].tmp = 0; parts[nb].life = 30; - parts[nb].vx = RNG::Ref().between(-10, 10); - parts[nb].vy = RNG::Ref().between(-10, 10); + parts[nb].vx = float(RNG::Ref().between(-10, 10)); + parts[nb].vy = float(RNG::Ref().between(-10, 10)); parts[nb].temp = restrict_flt(parts[i].temp-273.15f+400.0f, MIN_TEMP, MAX_TEMP); } } diff --git a/src/simulation/elements/ISOZ.cpp b/src/simulation/elements/ISOZ.cpp index 63ee50ace..20480cd0a 100644 --- a/src/simulation/elements/ISOZ.cpp +++ b/src/simulation/elements/ISOZ.cpp @@ -49,7 +49,7 @@ void Element::Element_ISOZ() static int update(UPDATE_FUNC_ARGS) { float rr, rrr; - if (RNG::Ref().chance(1, 200) && RNG::Ref().chance(-4.0f * sim->pv[y/CELL][x/CELL], 1000)) + if (RNG::Ref().chance(1, 200) && RNG::Ref().chance(int(-4.0f * sim->pv[y/CELL][x/CELL]), 1000)) { sim->create_part(i, x, y, PT_PHOT); rr = RNG::Ref().between(128, 355) / 127.0f; diff --git a/src/simulation/elements/ISZS.cpp b/src/simulation/elements/ISZS.cpp index 61cbe0e63..2864f5268 100644 --- a/src/simulation/elements/ISZS.cpp +++ b/src/simulation/elements/ISZS.cpp @@ -49,7 +49,7 @@ void Element::Element_ISZS() static int update(UPDATE_FUNC_ARGS) { float rr, rrr; - if (RNG::Ref().chance(1, 200) && RNG::Ref().chance(-4.0f * sim->pv[y/CELL][x/CELL], 1000)) + if (RNG::Ref().chance(1, 200) && RNG::Ref().chance(int(-4.0f * sim->pv[y/CELL][x/CELL]), 1000)) { sim->create_part(i, x, y, PT_PHOT); rr = RNG::Ref().between(128, 355) / 127.0f; diff --git a/src/simulation/elements/LIFE.cpp b/src/simulation/elements/LIFE.cpp index 565b99782..4ca096051 100644 --- a/src/simulation/elements/LIFE.cpp +++ b/src/simulation/elements/LIFE.cpp @@ -80,9 +80,9 @@ static int graphics(GRAPHICS_FUNC_ARGS) else { auto mul = (cpart->tmp2 - 1) / float(states - 2); - *colr = PIXR(colour1) * mul + PIXR(colour2) * (1.f - mul); - *colg = PIXG(colour1) * mul + PIXG(colour2) * (1.f - mul); - *colb = PIXB(colour1) * mul + PIXB(colour2) * (1.f - mul); + *colr = int(PIXR(colour1) * mul + PIXR(colour2) * (1.f - mul)); + *colg = int(PIXG(colour1) * mul + PIXG(colour2) * (1.f - mul)); + *colb = int(PIXB(colour1) * mul + PIXB(colour2) * (1.f - mul)); } } *pixel_mode |= NO_DECO; diff --git a/src/simulation/elements/LIGH.cpp b/src/simulation/elements/LIGH.cpp index b7e1c571e..ee9968f3e 100644 --- a/src/simulation/elements/LIGH.cpp +++ b/src/simulation/elements/LIGH.cpp @@ -3,7 +3,7 @@ static int update(UPDATE_FUNC_ARGS); static int graphics(GRAPHICS_FUNC_ARGS); static void create(ELEMENT_CREATE_FUNC_ARGS); -static void create_line_par(Simulation * sim, int x1, int y1, int x2, int y2, int c, int temp, int life, int tmp, int tmp2); +static void create_line_par(Simulation * sim, int x1, int y1, int x2, int y2, int c, float temp, int life, int tmp, int tmp2); void Element::Element_LIGH() { @@ -71,7 +71,7 @@ static int update(UPDATE_FUNC_ARGS) */ int r,rx,ry,rt, multipler, powderful; float angle, angle2=-1; - powderful = parts[i].temp*(1+parts[i].life/40)*LIGHTING_POWER; + powderful = int(parts[i].temp*(1+parts[i].life/40)*LIGHTING_POWER); //Element_FIRE::update(UPDATE_FUNC_SUBCALL_ARGS); if (sim->aheat_enable) { @@ -93,7 +93,7 @@ static int update(UPDATE_FUNC_ARGS) rt = TYP(r); if ((surround_space || sim->elements[rt].Explosive) && (rt!=PT_SPNG || parts[ID(r)].life==0) && - sim->elements[rt].Flammable && RNG::Ref().chance(sim->elements[rt].Flammable + sim->pv[(y+ry)/CELL][(x+rx)/CELL] * 10.0f, 1000)) + sim->elements[rt].Flammable && RNG::Ref().chance(sim->elements[rt].Flammable + int(sim->pv[(y+ry)/CELL][(x+rx)/CELL] * 10.0f), 1000)) { sim->part_change_type(ID(r),x+rx,y+ry,PT_FIRE); parts[ID(r)].temp = restrict_flt(sim->elements[PT_FIRE].DefaultProperties.temp + (sim->elements[rt].Flammable/2), MIN_TEMP, MAX_TEMP); @@ -121,8 +121,8 @@ static int update(UPDATE_FUNC_ARGS) { sim->part_change_type(ID(r),x+rx,y+ry,PT_NEUT); parts[ID(r)].life = RNG::Ref().between(480, 959); - parts[ID(r)].vx = RNG::Ref().between(-5, 5); - parts[ID(r)].vy = RNG::Ref().between(-5, 5); + parts[ID(r)].vx = float(RNG::Ref().between(-5, 5)); + parts[ID(r)].vy = float(RNG::Ref().between(-5, 5)); } break; case PT_COAL: @@ -172,29 +172,29 @@ static int update(UPDATE_FUNC_ARGS) return 1; } - angle = (parts[i].tmp + RNG::Ref().between(-30, 30)) % 360; - multipler = parts[i].life * 1.5 + RNG::Ref().between(0, parts[i].life); - rx=cos(angle*M_PI/180)*multipler; - ry=-sin(angle*M_PI/180)*multipler; - create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, angle, parts[i].tmp2); + angle = float((parts[i].tmp + RNG::Ref().between(-30, 30)) % 360); + multipler = int(parts[i].life * 1.5) + RNG::Ref().between(0, parts[i].life); + rx=int(cos(angle*M_PI/180)*multipler); + ry=int(-sin(angle*M_PI/180)*multipler); + create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, int(angle), parts[i].tmp2); if (parts[i].tmp2==2)// && pNear==-1) { - angle2 = ((int)angle + RNG::Ref().between(-100, 100)) % 360; - rx=cos(angle2*M_PI/180)*multipler; - ry=-sin(angle2*M_PI/180)*multipler; - create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, angle2, parts[i].tmp2); + angle2 = float(((int)angle + RNG::Ref().between(-100, 100)) % 360); + rx=int(cos(angle2*M_PI/180)*multipler); + ry=int(-sin(angle2*M_PI/180)*multipler); + create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, int(angle2), parts[i].tmp2); } parts[i].tmp2=-1; return 1; } -static bool create_LIGH(Simulation * sim, int x, int y, int c, int temp, int life, int tmp, int tmp2, bool last) +static bool create_LIGH(Simulation * sim, int x, int y, int c, float temp, int life, int tmp, int tmp2, bool last) { int p = sim->create_part(-1, x, y,c); if (p != -1) { - sim->parts[p].temp = temp; + sim->parts[p].temp = float(temp); sim->parts[p].tmp = tmp; if (last) { @@ -217,7 +217,7 @@ static bool create_LIGH(Simulation * sim, int x, int y, int c, int temp, int lif return false; } -static void create_line_par(Simulation * sim, int x1, int y1, int x2, int y2, int c, int temp, int life, int tmp, int tmp2) +static void create_line_par(Simulation * sim, int x1, int y1, int x2, int y2, int c, float temp, int life, int tmp, int tmp2) { bool reverseXY = abs(y2-y1) > abs(x2-x1), back = false; int x, y, dx, dy, Ystep; diff --git a/src/simulation/elements/MERC.cpp b/src/simulation/elements/MERC.cpp index d64e5afa7..a546b2d89 100644 --- a/src/simulation/elements/MERC.cpp +++ b/src/simulation/elements/MERC.cpp @@ -55,8 +55,8 @@ static int update(UPDATE_FUNC_ARGS) // Obscure division by 0 fix if (parts[i].temp + 1 == 0) parts[i].temp = 0; - int maxtmp = (absorbScale/(parts[i].temp + 1))-1; - if (RNG::Ref().chance(absorbScale%((int)parts[i].temp+1), parts[i].temp+1)) + int maxtmp = int(absorbScale/(parts[i].temp + 1))-1; + if (RNG::Ref().chance(absorbScale%(int(parts[i].temp)+1), int(parts[i].temp)+1)) maxtmp ++; if (parts[i].tmp < 0) diff --git a/src/simulation/elements/NEUT.cpp b/src/simulation/elements/NEUT.cpp index 7dbc2993a..d3ebdc2a7 100644 --- a/src/simulation/elements/NEUT.cpp +++ b/src/simulation/elements/NEUT.cpp @@ -68,8 +68,8 @@ static int update(UPDATE_FUNC_ARGS) sim->part_change_type(ID(r),x+rx,y+ry,PT_DSTW); case PT_ICEI: case PT_SNOW: - parts[i].vx *= 0.995; - parts[i].vy *= 0.995; + parts[i].vx *= 0.995f; + parts[i].vy *= 0.995f; break; case PT_PLUT: if (RNG::Ref().chance(pressureFactor, 1000)) diff --git a/src/simulation/elements/PBCN.cpp b/src/simulation/elements/PBCN.cpp index 968792af2..edd6bae1c 100644 --- a/src/simulation/elements/PBCN.cpp +++ b/src/simulation/elements/PBCN.cpp @@ -120,8 +120,8 @@ static int update(UPDATE_FUNC_ARGS) int r = sim->create_part(-1, x + rx, y + ry, PT_PHOT); if (r != -1) { - parts[r].vx = rx * 3; - parts[r].vy = ry * 3; + parts[r].vx = float(rx * 3); + parts[r].vy = float(ry * 3); if (r>i) { // Make sure movement doesn't happen until next frame, to avoid gaps in the beams of photons produced diff --git a/src/simulation/elements/PCLN.cpp b/src/simulation/elements/PCLN.cpp index e6f30c9c6..523c76c88 100644 --- a/src/simulation/elements/PCLN.cpp +++ b/src/simulation/elements/PCLN.cpp @@ -111,8 +111,8 @@ static int update(UPDATE_FUNC_ARGS) int r = sim->create_part(-1, x + rx, y + ry, PT_PHOT); if (r != -1) { - parts[r].vx = rx * 3; - parts[r].vy = ry * 3; + parts[r].vx = float(rx * 3); + parts[r].vy = float(ry * 3); if (r>i) { // Make sure movement doesn't happen until next frame, to avoid gaps in the beams of photons produced diff --git a/src/simulation/elements/PHOT.cpp b/src/simulation/elements/PHOT.cpp index 82d5468d9..8efbd9f19 100644 --- a/src/simulation/elements/PHOT.cpp +++ b/src/simulation/elements/PHOT.cpp @@ -75,8 +75,8 @@ static int update(UPDATE_FUNC_ARGS) { if (RNG::Ref().chance(1, 400)) { - parts[i].vx *= 0.90; - parts[i].vy *= 0.90; + parts[i].vx *= 0.90f; + parts[i].vy *= 0.90f; sim->create_part(ID(r), x+rx, y+ry, PT_PHOT); rrr = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; if (TYP(r) == PT_ISOZ) diff --git a/src/simulation/elements/PIPE.cpp b/src/simulation/elements/PIPE.cpp index 3c8028f0a..f5f741e07 100644 --- a/src/simulation/elements/PIPE.cpp +++ b/src/simulation/elements/PIPE.cpp @@ -355,8 +355,8 @@ int Element_PIPE_graphics(GRAPHICS_FUNC_ARGS) tpart.type = t; tpart.temp = cpart->temp; tpart.life = cpart->tmp2; - tpart.tmp = cpart->pavg[0]; - tpart.ctype = cpart->pavg[1]; + tpart.tmp = int(cpart->pavg[0]); + tpart.ctype = int(cpart->pavg[1]); if (t == PT_PHOT && tpart.ctype == 0x40000000) tpart.ctype = 0x3FFFFFFF; @@ -418,8 +418,8 @@ void Element_PIPE_transfer_pipe_to_part(Simulation * sim, Particle *pipe, Partic } part->temp = pipe->temp; part->life = pipe->tmp2; - part->tmp = pipe->pavg[0]; - part->ctype = pipe->pavg[1]; + part->tmp = int(pipe->pavg[0]); + part->ctype = int(pipe->pavg[1]); if (!(sim->elements[part->type].Properties & TYPE_ENERGY)) { @@ -438,8 +438,8 @@ static void transfer_part_to_pipe(Particle *part, Particle *pipe) pipe->ctype = part->type; pipe->temp = part->temp; pipe->tmp2 = part->life; - pipe->pavg[0] = part->tmp; - pipe->pavg[1] = part->ctype; + pipe->pavg[0] = float(part->tmp); + pipe->pavg[1] = float(part->ctype); } static void transfer_pipe_to_pipe(Particle *src, Particle *dest, bool STOR) diff --git a/src/simulation/elements/PLSM.cpp b/src/simulation/elements/PLSM.cpp index 660e941ee..dd95bb874 100644 --- a/src/simulation/elements/PLSM.cpp +++ b/src/simulation/elements/PLSM.cpp @@ -52,7 +52,7 @@ void Element::Element_PLSM() static int graphics(GRAPHICS_FUNC_ARGS) { - int caddress = restrict_flt(restrict_flt((float)cpart->life, 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3); + int caddress = int(restrict_flt(float(cpart->life), 0, 199)) * 3; *colr = (unsigned char)ren->plasma_data[caddress]; *colg = (unsigned char)ren->plasma_data[caddress+1]; *colb = (unsigned char)ren->plasma_data[caddress+2]; diff --git a/src/simulation/elements/PLUT.cpp b/src/simulation/elements/PLUT.cpp index bb2914780..1ce583af9 100644 --- a/src/simulation/elements/PLUT.cpp +++ b/src/simulation/elements/PLUT.cpp @@ -49,7 +49,7 @@ void Element::Element_PLUT() static int update(UPDATE_FUNC_ARGS) { - if (RNG::Ref().chance(1, 100) && RNG::Ref().chance(5.0f*sim->pv[y/CELL][x/CELL], 1000)) + if (RNG::Ref().chance(1, 100) && RNG::Ref().chance(int(5.0f*sim->pv[y/CELL][x/CELL]), 1000)) { sim->create_part(i, x, y, PT_NEUT); } diff --git a/src/simulation/elements/PROT.cpp b/src/simulation/elements/PROT.cpp index 992de405a..e3adfbb12 100644 --- a/src/simulation/elements/PROT.cpp +++ b/src/simulation/elements/PROT.cpp @@ -114,7 +114,7 @@ static int update(UPDATE_FUNC_ARGS) if (parts[i].temp > 273.15f + 500.0f && (sim->elements[utype].Flammable || sim->elements[utype].Explosive || utype == PT_BANG)) { sim->create_part(uID, x, y, PT_FIRE); - parts[uID].temp += restrict_flt(sim->elements[utype].Flammable * 5, MIN_TEMP, MAX_TEMP); + parts[uID].temp += restrict_flt(float(sim->elements[utype].Flammable * 5), MIN_TEMP, MAX_TEMP); sim->pv[y / CELL][x / CELL] += 1.00f; } //prevent inactive sparkable elements from being sparked diff --git a/src/simulation/elements/PRTO.cpp b/src/simulation/elements/PRTO.cpp index 7dfbd38f1..48a07862f 100644 --- a/src/simulation/elements/PRTO.cpp +++ b/src/simulation/elements/PRTO.cpp @@ -130,8 +130,8 @@ static int update(UPDATE_FUNC_ARGS) } else parts[np] = sim->portalp[parts[i].tmp][randomness][nnx]; - parts[np].x = x+rx; - parts[np].y = y+ry; + parts[np].x = float(x+rx); + parts[np].y = float(y+ry); memset(&sim->portalp[parts[i].tmp][randomness][nnx], 0, sizeof(Particle)); break; } diff --git a/src/simulation/elements/PSNS.cpp b/src/simulation/elements/PSNS.cpp index 371d9d4a2..e2065fa91 100644 --- a/src/simulation/elements/PSNS.cpp +++ b/src/simulation/elements/PSNS.cpp @@ -90,7 +90,7 @@ static int update(UPDATE_FUNC_ARGS) ny = y + ry; while (TYP(r) == PT_FILT) { - parts[ID(r)].ctype = 0x10000000 + roundl(photonWl) + 256; + parts[ID(r)].ctype = 0x10000000 + int(round(photonWl)) + 256; nx += rx; ny += ry; if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES) diff --git a/src/simulation/elements/PSTN.cpp b/src/simulation/elements/PSTN.cpp index 94693d528..920542e8a 100644 --- a/src/simulation/elements/PSTN.cpp +++ b/src/simulation/elements/PSTN.cpp @@ -136,14 +136,14 @@ static int update(UPDATE_FUNC_ARGS) } else { - pistonCount += floor((parts[ID(r)].temp-268.15)/10);// How many tens of degrees above 0 C, rounded to nearest ten degrees. Can be negative. + pistonCount += int(floor((parts[ID(r)].temp-268.15f)/10));// How many tens of degrees above 0 C, rounded to nearest ten degrees. Can be negative. } } else if (nxx==0 && nyy==0) { // compatibility with BAD THINGS: starting PSTN layered underneath other particles // (in v90, it started scanning from the neighbouring particle, so could not break out of loop at offset=(0,0)) - pistonCount += floor((parts[i].temp-268.15)/10); + pistonCount += int(floor((parts[i].temp-268.15f)/10)); continue; } else @@ -305,8 +305,8 @@ static int MoveStack(Simulation * sim, int stackX, int stackY, int directionX, i int srcX = (int)(sim->parts[jP].x + 0.5f), srcY = (int)(sim->parts[jP].y + 0.5f); int destX = srcX-directionX*amount, destY = srcY-directionY*amount; sim->pmap[srcY][srcX] = 0; - sim->parts[jP].x = destX; - sim->parts[jP].y = destY; + sim->parts[jP].x = float(destX); + sim->parts[jP].y = float(destY); sim->pmap[destY][destX] = PMAP(jP, sim->parts[jP].type); } return amount; @@ -328,8 +328,8 @@ static int MoveStack(Simulation * sim, int stackX, int stackY, int directionX, i int srcX = (int)(sim->parts[jP].x + 0.5f), srcY = (int)(sim->parts[jP].y + 0.5f); int destX = srcX+directionX*possibleMovement, destY = srcY+directionY*possibleMovement; sim->pmap[srcY][srcX] = 0; - sim->parts[jP].x = destX; - sim->parts[jP].y = destY; + sim->parts[jP].x = float(destX); + sim->parts[jP].y = float(destY); sim->pmap[destY][destX] = PMAP(jP, sim->parts[jP].type); } return possibleMovement; diff --git a/src/simulation/elements/PUMP.cpp b/src/simulation/elements/PUMP.cpp index a0bef227e..f700ce93d 100644 --- a/src/simulation/elements/PUMP.cpp +++ b/src/simulation/elements/PUMP.cpp @@ -60,10 +60,10 @@ static int update(UPDATE_FUNC_ARGS) } else { - if (parts[i].temp >= 256.0+273.15) - parts[i].temp = 256.0+273.15; - if (parts[i].temp <= -256.0+273.15) - parts[i].temp = -256.0+273.15; + if (parts[i].temp >= 256.0f+273.15f) + parts[i].temp = 256.0f+273.15f; + if (parts[i].temp <= -256.0f+273.15f) + parts[i].temp = -256.0f+273.15f; for (rx = -1; rx <= 1; rx++) for (ry = -1; ry <= 1; ry++) @@ -81,7 +81,7 @@ static int update(UPDATE_FUNC_ARGS) int newPressure = parts[ID(r)].ctype - 0x10000000; if (newPressure >= 0 && newPressure <= 512) { - sim->pv[(y + ry) / CELL][(x + rx) / CELL] = newPressure - 256; + sim->pv[(y + ry) / CELL][(x + rx) / CELL] = float(newPressure - 256); } } } diff --git a/src/simulation/elements/ROCK.cpp b/src/simulation/elements/ROCK.cpp index 3c6e4687f..d1cfdef42 100644 --- a/src/simulation/elements/ROCK.cpp +++ b/src/simulation/elements/ROCK.cpp @@ -59,7 +59,7 @@ static int graphics(GRAPHICS_FUNC_ARGS) { *pixel_mode |= FIRE_ADD; - *firea = ((cpart->temp)-810.15)/45; + *firea = int(((cpart->temp)-810.15)/45); *firer = *colr; *fireg = *colg; *fireb = *colb; diff --git a/src/simulation/elements/SING.cpp b/src/simulation/elements/SING.cpp index 99619085f..5ec9e0e28 100644 --- a/src/simulation/elements/SING.cpp +++ b/src/simulation/elements/SING.cpp @@ -77,7 +77,7 @@ static int update(UPDATE_FUNC_ARGS) } } spawncount = std::abs(parts[i].tmp); - spawncount = (spawncount>255) ? 3019 : std::pow((double)(spawncount/8), 2)*M_PI; + spawncount = (spawncount>255) ? 3019 : int(std::pow((double)(spawncount/8), 2)*M_PI); for (int j = 0;j < spawncount; j++) { switch (RNG::Ref().gen() % 3) diff --git a/src/simulation/elements/SOAP.cpp b/src/simulation/elements/SOAP.cpp index 7a183db92..cb68a1fad 100644 --- a/src/simulation/elements/SOAP.cpp +++ b/src/simulation/elements/SOAP.cpp @@ -260,14 +260,14 @@ static int update(UPDATE_FUNC_ARGS) continue; if (TYP(r)!=PT_SOAP) { - tr = (parts[ID(r)].dcolour>>16)&0xFF; - tg = (parts[ID(r)].dcolour>>8)&0xFF; - tb = (parts[ID(r)].dcolour)&0xFF; - ta = (parts[ID(r)].dcolour>>24)&0xFF; - nr = (tr*BLEND); - ng = (tg*BLEND); - nb = (tb*BLEND); - na = (ta*BLEND); + tr = float((parts[ID(r)].dcolour>>16)&0xFF); + tg = float((parts[ID(r)].dcolour>>8)&0xFF); + tb = float((parts[ID(r)].dcolour)&0xFF); + ta = float((parts[ID(r)].dcolour>>24)&0xFF); + nr = int(tr*BLEND); + ng = int(tg*BLEND); + nb = int(tb*BLEND); + na = int(ta*BLEND); parts[ID(r)].dcolour = nr<<16 | ng<<8 | nb | na<<24; } } diff --git a/src/simulation/elements/SPRK.cpp b/src/simulation/elements/SPRK.cpp index ebfcf8080..a0a8d9176 100644 --- a/src/simulation/elements/SPRK.cpp +++ b/src/simulation/elements/SPRK.cpp @@ -132,7 +132,7 @@ static int update(UPDATE_FUNC_ARGS) parts[i].life=60; parts[p].temp=parts[p].life*parts[i].tmp/2.5; parts[p].tmp2=1; - parts[p].tmp=atan2(-ry, (float)rx)/M_PI*360; + parts[p].tmp=int(atan2(-ry, (float)rx)/M_PI*360); parts[i].temp-=parts[i].tmp*2+parts[i].temp/5; // slight self-cooling if (fabs(sim->pv[y/CELL][x/CELL])!=0.0f) { diff --git a/src/simulation/elements/STKM.cpp b/src/simulation/elements/STKM.cpp index 7a3469aea..838aae58a 100644 --- a/src/simulation/elements/STKM.cpp +++ b/src/simulation/elements/STKM.cpp @@ -104,7 +104,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) int r, rx, ry; int t = parts[i].type; float pp, d; - float dt = 0.9;///(FPSB*FPSB); //Delta time in square + float dt = 0.9f;///(FPSB*FPSB); //Delta time in square float gvx, gvy; float gx, gy, dl, dr; float rocketBootsHeadEffect = 0.35f; @@ -243,7 +243,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) bool moved = false; if (dl>dr) { - if (INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, playerp->legs[4], playerp->legs[5], NULL)) + if (INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, int(playerp->legs[4]), int(playerp->legs[5]), NULL)) { playerp->accs[2] = -3*gvy-3*gvx; playerp->accs[3] = 3*gvx-3*gvy; @@ -254,7 +254,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) } else { - if (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, playerp->legs[12], playerp->legs[13], NULL)) + if (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, int(playerp->legs[12]), int(playerp->legs[13]), NULL)) { playerp->accs[6] = -3*gvy-3*gvx; playerp->accs[7] = 3*gvx-3*gvy; @@ -275,7 +275,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) { if (leg==1 && (((int)(playerp->comm)&0x02) == 0x02)) continue; - int footX = playerp->legs[leg*8+4], footY = playerp->legs[leg*8+5]; + int footX = int(playerp->legs[leg*8+4]), footY = int(playerp->legs[leg*8+5]); int np = sim->create_part(-1, footX, footY, PT_PLSM); if (np>=0) { @@ -293,7 +293,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) bool moved = false; if (dllegs[4], playerp->legs[5]) && !sim->eval_move(t, playerp->legs[4], playerp->legs[5], NULL)) + if (INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, int(playerp->legs[4]), int(playerp->legs[5]), NULL)) { playerp->accs[2] = 3*gvy-3*gvx; playerp->accs[3] = -3*gvx-3*gvy; @@ -304,7 +304,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) } else { - if (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, playerp->legs[12], playerp->legs[13], NULL)) + if (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, int(playerp->legs[12]), int(playerp->legs[13]), NULL)) { playerp->accs[6] = 3*gvy-3*gvx; playerp->accs[7] = -3*gvx-3*gvy; @@ -325,7 +325,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) { if (leg==0 && (((int)(playerp->comm)&0x01) == 0x01)) continue; - int footX = playerp->legs[leg*8+4], footY = playerp->legs[leg*8+5]; + int footX = int(playerp->legs[leg*8+4]), footY = int(playerp->legs[leg*8+5]); int np = sim->create_part(-1, footX, footY, PT_PLSM); if (np>=0) { @@ -360,7 +360,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) playerp->accs[7] -= rocketBootsFeetEffectV*rby; for (int leg=0; leg<2; leg++) { - int footX = playerp->legs[leg*8+4], footY = playerp->legs[leg*8+5]; + int footX = int(playerp->legs[leg*8+4]), footY = int(playerp->legs[leg*8+5]); int np = sim->create_part(-1, footX, footY+1, PT_PLSM); if (np>=0) { @@ -370,8 +370,8 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) } } } - else if ((INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, playerp->legs[4], playerp->legs[5], NULL)) || - (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, playerp->legs[12], playerp->legs[13], NULL))) + else if ((INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, int(playerp->legs[4]), int(playerp->legs[5]), NULL)) || + (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, int(playerp->legs[12]), int(playerp->legs[13]), NULL))) { parts[i].vx -= 4*gvx; parts[i].vy -= 4*gvy; @@ -415,7 +415,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) if (TYP(r) == PT_NEUT) { if (parts[i].life<=100) parts[i].life -= (102-parts[i].life)/2; - else parts[i].life *= 0.9f; + else parts[i].life = int(parts[i].life * 0.9f); sim->kill_part(ID(r)); } if (sim->bmap[(ry+y)/CELL][(rx+x)/CELL]==WL_FAN) @@ -482,17 +482,17 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) { parts[np].vy = 0; if (((int)playerp->pcomm)&(0x01|0x02)) - parts[np].vx = (((((int)playerp->pcomm)&0x02) == 0x02) - (((int)(playerp->pcomm)&0x01) == 0x01))*random; + parts[np].vx = float((((((int)playerp->pcomm)&0x02) == 0x02) - (((int)(playerp->pcomm)&0x01) == 0x01))*random); else - parts[np].vx = random; + parts[np].vx = float(random); } } else if (playerp->elem == PT_LIGH) { - float angle; + int angle; int power = 100; if (gvx!=0 || gvy!=0) - angle = atan2(gvx, gvy)*180.0f/M_PI; + angle = int(atan2(gvx, gvy)*180.0f/M_PI); else angle = RNG::Ref().between(0, 359); if (((int)playerp->pcomm)&0x01) @@ -543,27 +543,27 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) playerp->legs[8] += (playerp->legs[8]-parts[i].x)*d; playerp->legs[9] += (playerp->legs[9]-parts[i].y)*d; - if (INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, playerp->legs[4], playerp->legs[5], NULL)) + if (INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, int(playerp->legs[4]), int(playerp->legs[5]), NULL)) { playerp->legs[4] = playerp->legs[6]; playerp->legs[5] = playerp->legs[7]; } - if (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, playerp->legs[12], playerp->legs[13], NULL)) + if (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, int(playerp->legs[12]), int(playerp->legs[13]), NULL)) { playerp->legs[12] = playerp->legs[14]; playerp->legs[13] = playerp->legs[15]; } //This makes stick man "pop" from obstacles - if (INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, playerp->legs[4], playerp->legs[5], NULL)) + if (INBOND(playerp->legs[4], playerp->legs[5]) && !sim->eval_move(t, int(playerp->legs[4]), int(playerp->legs[5]), NULL)) { float t; t = playerp->legs[4]; playerp->legs[4] = playerp->legs[6]; playerp->legs[6] = t; t = playerp->legs[5]; playerp->legs[5] = playerp->legs[7]; playerp->legs[7] = t; } - if (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, playerp->legs[12], playerp->legs[13], NULL)) + if (INBOND(playerp->legs[12], playerp->legs[13]) && !sim->eval_move(t, int(playerp->legs[12]), int(playerp->legs[13]), NULL)) { float t; t = playerp->legs[12]; playerp->legs[12] = playerp->legs[14]; playerp->legs[14] = t; @@ -688,25 +688,25 @@ void Element_STKM_init_legs(Simulation * sim, playerst *playerp, int i) x = (int)(sim->parts[i].x+0.5f); y = (int)(sim->parts[i].y+0.5f); - playerp->legs[0] = x-1; - playerp->legs[1] = y+6; - playerp->legs[2] = x-1; - playerp->legs[3] = y+6; + playerp->legs[0] = float(x-1); + playerp->legs[1] = float(y+6); + playerp->legs[2] = float(x-1); + playerp->legs[3] = float(y+6); - playerp->legs[4] = x-3; - playerp->legs[5] = y+12; - playerp->legs[6] = x-3; - playerp->legs[7] = y+12; + playerp->legs[4] = float(x-3); + playerp->legs[5] = float(y+12); + playerp->legs[6] = float(x-3); + playerp->legs[7] = float(y+12); - playerp->legs[8] = x+1; - playerp->legs[9] = y+6; - playerp->legs[10] = x+1; - playerp->legs[11] = y+6; + playerp->legs[8] = float(x+1); + playerp->legs[9] = float(y+6); + playerp->legs[10] = float(x+1); + playerp->legs[11] = float(y+6); - playerp->legs[12] = x+3; - playerp->legs[13] = y+12; - playerp->legs[14] = x+3; - playerp->legs[15] = y+12; + playerp->legs[12] = float(x+3); + playerp->legs[13] = float(y+12); + playerp->legs[14] = float(x+3); + playerp->legs[15] = float(y+12); for (int i = 0; i < 8; i++) playerp->accs[i] = 0; diff --git a/src/simulation/elements/STOR.cpp b/src/simulation/elements/STOR.cpp index cab1280e2..8896d52e0 100644 --- a/src/simulation/elements/STOR.cpp +++ b/src/simulation/elements/STOR.cpp @@ -71,8 +71,8 @@ static int update(UPDATE_FUNC_ARGS) parts[i].tmp = parts[ID(r)].type; parts[i].temp = parts[ID(r)].temp; parts[i].tmp2 = parts[ID(r)].life; - parts[i].pavg[0] = parts[ID(r)].tmp; - parts[i].pavg[1] = parts[ID(r)].ctype; + parts[i].pavg[0] = float(parts[ID(r)].tmp); + parts[i].pavg[1] = float(parts[ID(r)].ctype); sim->kill_part(ID(r)); } if(parts[i].tmp && TYP(r)==PT_SPRK && parts[ID(r)].ctype==PT_PSCN && parts[ID(r)].life>0 && parts[ID(r)].life<4) @@ -84,8 +84,8 @@ static int update(UPDATE_FUNC_ARGS) { parts[np].temp = parts[i].temp; parts[np].life = parts[i].tmp2; - parts[np].tmp = parts[i].pavg[0]; - parts[np].ctype = parts[i].pavg[1]; + parts[np].tmp = int(parts[i].pavg[0]); + parts[np].ctype = int(parts[i].pavg[1]); parts[i].tmp = 0; parts[i].life = 10; break; diff --git a/src/simulation/elements/TSNS.cpp b/src/simulation/elements/TSNS.cpp index 3282bf835..a554d6501 100644 --- a/src/simulation/elements/TSNS.cpp +++ b/src/simulation/elements/TSNS.cpp @@ -94,7 +94,7 @@ static int update(UPDATE_FUNC_ARGS) if (parts[i].tmp == 1 && TYP(r) != PT_TSNS && TYP(r) != PT_FILT) { setFilt = true; - photonWl = parts[ID(r)].temp; + photonWl = int(parts[ID(r)].temp); } } if (setFilt) diff --git a/src/simulation/elements/VIRS.cpp b/src/simulation/elements/VIRS.cpp index a3c820b54..dfd7b2bcc 100644 --- a/src/simulation/elements/VIRS.cpp +++ b/src/simulation/elements/VIRS.cpp @@ -105,7 +105,7 @@ int Element_VIRS_update(UPDATE_FUNC_ARGS) } else if (TYP(r) == PT_PLSM) { - if (surround_space && RNG::Ref().chance(10 + sim->pv[(y+ry)/CELL][(x+rx)/CELL], 100)) + if (surround_space && RNG::Ref().chance(10 + int(sim->pv[(y+ry)/CELL][(x+rx)/CELL]), 100)) { sim->create_part(i, x, y, PT_PLSM); return 1; diff --git a/src/simulation/elements/VSNS.cpp b/src/simulation/elements/VSNS.cpp index 53ac536f2..a5e8693a0 100644 --- a/src/simulation/elements/VSNS.cpp +++ b/src/simulation/elements/VSNS.cpp @@ -108,7 +108,7 @@ static int update(UPDATE_FUNC_ARGS) if (vel >= 0 && vel < SIM_MAXVELOCITY) { doDeserialization = true; - Vs = vel; + Vs = float(vel); } } break; diff --git a/src/simulation/elements/WARP.cpp b/src/simulation/elements/WARP.cpp index 6aa2687f6..30b180f42 100644 --- a/src/simulation/elements/WARP.cpp +++ b/src/simulation/elements/WARP.cpp @@ -72,10 +72,10 @@ static int update(UPDATE_FUNC_ARGS) { parts[i].x = parts[ID(r)].x; parts[i].y = parts[ID(r)].y; - parts[ID(r)].x = x; - parts[ID(r)].y = y; + parts[ID(r)].x = float(x); + parts[ID(r)].y = float(y); parts[ID(r)].vx = RNG::Ref().chance(-2, 1) + 0.5f; - parts[ID(r)].vy = RNG::Ref().between(-2, 1); + parts[ID(r)].vy = float(RNG::Ref().between(-2, 1)); parts[i].life += 4; pmap[y][x] = r; pmap[y+ry][x+rx] = PMAP(i, parts[i].type); diff --git a/src/simulation/elements/WIFI.cpp b/src/simulation/elements/WIFI.cpp index f63c132ce..4a4b1f49e 100644 --- a/src/simulation/elements/WIFI.cpp +++ b/src/simulation/elements/WIFI.cpp @@ -85,9 +85,9 @@ constexpr float FREQUENCY = 0.0628f; static int graphics(GRAPHICS_FUNC_ARGS) { int q = (int)((cpart->temp-73.15f)/100+1); - *colr = sin(FREQUENCY*q + 0) * 127 + 128; - *colg = sin(FREQUENCY*q + 2) * 127 + 128; - *colb = sin(FREQUENCY*q + 4) * 127 + 128; + *colr = int(sin(FREQUENCY*q + 0) * 127 + 128); + *colg = int(sin(FREQUENCY*q + 2) * 127 + 128); + *colb = int(sin(FREQUENCY*q + 4) * 127 + 128); *pixel_mode |= EFFECT_DBGLINES; return 0; } diff --git a/src/simulation/simtools/CYCL.cpp b/src/simulation/simtools/CYCL.cpp index 368ff5c0e..164c87eb0 100644 --- a/src/simulation/simtools/CYCL.cpp +++ b/src/simulation/simtools/CYCL.cpp @@ -29,8 +29,8 @@ static int perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, float *vx = &sim->air->vx[y / CELL][x / CELL]; float *vy = &sim->air->vy[y / CELL][x / CELL]; - float dvx = brushX - x; - float dvy = brushY - y; + auto dvx = float(brushX - x); + auto dvy = float(brushY - y); float invsqr = 1/sqrtf(dvx*dvx + dvy*dvy); *vx -= (strength / 16) * (-dvy)*invsqr; diff --git a/src/simulation/simtools/MIX.cpp b/src/simulation/simtools/MIX.cpp index 71cb8ec9c..2d28e463b 100644 --- a/src/simulation/simtools/MIX.cpp +++ b/src/simulation/simtools/MIX.cpp @@ -42,12 +42,12 @@ static int perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, return 0; sim->pmap[y][x] = thatPart; - sim->parts[ID(thatPart)].x = x; - sim->parts[ID(thatPart)].y = y; + sim->parts[ID(thatPart)].x = float(x); + sim->parts[ID(thatPart)].y = float(y); sim->pmap[newY][newX] = thisPart; - sim->parts[ID(thisPart)].x = newX; - sim->parts[ID(thisPart)].y = newY; + sim->parts[ID(thisPart)].x = float(newX); + sim->parts[ID(thisPart)].y = float(newY); return 1; } diff --git a/src/tasks/TaskWindow.cpp b/src/tasks/TaskWindow.cpp index 3ff447b24..12d941c97 100644 --- a/src/tasks/TaskWindow.cpp +++ b/src/tasks/TaskWindow.cpp @@ -101,17 +101,17 @@ void TaskWindow::OnDraw() progress = 100; float size = float(Size.X-4)*(float(progress)/100.0f); // TIL... size = std::min(std::max(size, 0.0f), float(Size.X-4)); - g->fillrect(Position.X + 2, Position.Y + Size.Y-15, size, 13, progressBarColour.Red, progressBarColour.Green, progressBarColour.Blue, 255); + g->fillrect(Position.X + 2, Position.Y + Size.Y-15, int(size), 13, progressBarColour.Red, progressBarColour.Green, progressBarColour.Blue, 255); } } else { int size = 40, rsize = 0; float position = float(Size.X-4)*(intermediatePos/100.0f); if(position + size - 1 > Size.X-4) { - size = (Size.X-4)-position+1; + size = (Size.X-4)-int(position)+1; rsize = 40-size; } - g->fillrect(Position.X + 2 + position, Position.Y + Size.Y-15, size, 13, progressBarColour.Red, progressBarColour.Green, progressBarColour.Blue, 255); + g->fillrect(Position.X + 2 + int(position), Position.Y + Size.Y-15, size, 13, progressBarColour.Red, progressBarColour.Green, progressBarColour.Blue, 255); if(rsize) { g->fillrect(Position.X + 2, Position.Y + Size.Y-15, rsize, 13, progressBarColour.Red, progressBarColour.Green, progressBarColour.Blue, 255);