|
|
@@ -1,16 +1,19 @@
|
|
|
+#include <math.h>
|
|
|
+#include <stdio.h>
|
|
|
+#include <stdlib.h>
|
|
|
+
|
|
|
#include "Control.h"
|
|
|
#include "GameEngine.h"
|
|
|
#include "Vector3D.h"
|
|
|
-#include <math.h>
|
|
|
|
|
|
-long tickCounter = 0;
|
|
|
-long renderTickCounter = 0;
|
|
|
+int64_t tickCounter = 0;
|
|
|
+int64_t renderTickCounter = 0;
|
|
|
|
|
|
-long tickSum = 0;
|
|
|
-long renderTickSum = 0;
|
|
|
+int64_t tickSum = 0;
|
|
|
+int64_t renderTickSum = 0;
|
|
|
|
|
|
-long tickTime = -1;
|
|
|
-long renderTickTime = -1;
|
|
|
+int64_t tickTime = -1;
|
|
|
+int64_t renderTickTime = -1;
|
|
|
|
|
|
typedef struct GameField {
|
|
|
int id;
|
|
|
@@ -20,16 +23,16 @@ typedef struct GameField {
|
|
|
float a;
|
|
|
} GameField;
|
|
|
|
|
|
-int amountGameFields = -1;
|
|
|
+size_t amountGameFields = 0;
|
|
|
GameField* gameFields = NULL;
|
|
|
|
|
|
-GLuint vbo = -1;
|
|
|
-GLuint vba = -1;
|
|
|
+GLuint vbo = 0;
|
|
|
+GLuint vba = 0;
|
|
|
|
|
|
-int fieldSize = 0;
|
|
|
-int quality = 0;
|
|
|
-int vertices = 0;
|
|
|
-GLsizeiptr size = 0;
|
|
|
+size_t fieldSize = 0;
|
|
|
+size_t quality = 0;
|
|
|
+size_t vertices = 0;
|
|
|
+size_t size = 0;
|
|
|
GLfloat* data = NULL;
|
|
|
|
|
|
Vector3D oldCamera;
|
|
|
@@ -52,7 +55,7 @@ Vector3D down;
|
|
|
int selectedIndex = -1;
|
|
|
int selectedLayer = -1;
|
|
|
|
|
|
-GameField* getGameField(int layer, int index) {
|
|
|
+static GameField* getGameField(size_t layer, size_t index) {
|
|
|
if(layer == 0) {
|
|
|
return &gameFields[0];
|
|
|
} else if(layer == 1 + fieldSize) {
|
|
|
@@ -66,11 +69,11 @@ GameField* getGameField(int layer, int index) {
|
|
|
return &gameFields[index];
|
|
|
}
|
|
|
|
|
|
-float interpolate(float lag, float old, float new) {
|
|
|
+static float interpolate(float lag, float old, float new) {
|
|
|
return old + lag * (new - old);
|
|
|
}
|
|
|
|
|
|
-void colorField(GameField* field) {
|
|
|
+static void colorField(GameField* field) {
|
|
|
if(field->id) {
|
|
|
field->r = 1.0f;
|
|
|
field->g = 0.0f;
|
|
|
@@ -84,14 +87,14 @@ void colorField(GameField* field) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void generateSphere() {
|
|
|
- int triangles = fieldSize * quality;
|
|
|
- int layers = (2 + fieldSize) * quality;
|
|
|
+static void generateSphere(void) {
|
|
|
+ size_t triangles = fieldSize * quality;
|
|
|
+ size_t layers = (2 + fieldSize) * quality;
|
|
|
|
|
|
if(gameFields == NULL) {
|
|
|
amountGameFields = 2 + fieldSize * fieldSize;
|
|
|
gameFields = malloc(sizeof(GameField) * amountGameFields);
|
|
|
- for(int i = 0; i < amountGameFields; i++) {
|
|
|
+ for(size_t i = 0; i < amountGameFields; i++) {
|
|
|
gameFields[i].id = (rand() < RAND_MAX / 2) ? 1 : 0;
|
|
|
colorField(&gameFields[i]);
|
|
|
}
|
|
|
@@ -103,15 +106,15 @@ void generateSphere() {
|
|
|
data = malloc(size);
|
|
|
}
|
|
|
|
|
|
- for(int l = 0; l < layers; l++) {
|
|
|
- float high1 = cos((M_PI * l) / layers);
|
|
|
- float high2 = cos((M_PI * (l + 1)) / layers);
|
|
|
+ for(size_t l = 0; l < layers; l++) {
|
|
|
+ float high1 = cosf((float)(M_PI * (double)l) / (float)layers);
|
|
|
+ float high2 = cosf((float)(M_PI * (double)(l + 1)) / (float)layers);
|
|
|
|
|
|
- float texHigh1 = (l % quality) * (1.0f / quality);
|
|
|
- float texHigh2 = texHigh1 + (1.0f / quality);
|
|
|
+ float texHigh1 = (float)(l % quality) * (1.0f / (float)quality);
|
|
|
+ float texHigh2 = texHigh1 + (1.0f / (float)quality);
|
|
|
|
|
|
- float r1 = sqrt(1 - high1 * high1);
|
|
|
- float r2 = sqrt(1 - high2 * high2);
|
|
|
+ float r1 = sqrtf(1.0f - high1 * high1);
|
|
|
+ float r2 = sqrtf(1.0f - high2 * high2);
|
|
|
|
|
|
int flag = (l / quality) == 0;
|
|
|
if(flag) {
|
|
|
@@ -120,14 +123,15 @@ void generateSphere() {
|
|
|
}
|
|
|
flag |= (l / quality) >= fieldSize + 1;
|
|
|
|
|
|
- for(int i = 0; i < triangles; i++) {
|
|
|
- float first = 2 * M_PI * i / triangles;
|
|
|
- float second = 2 * M_PI * (i + 1) / triangles;
|
|
|
+ for(size_t i = 0; i < triangles; i++) {
|
|
|
+ float first = (float)(2 * M_PI * (double)i) / (float)triangles;
|
|
|
+ float second =
|
|
|
+ (float)(2 * M_PI * (double)(i + 1)) / (float)triangles;
|
|
|
|
|
|
- int off = 27 * 2 * i + l * triangles * 27 * 2;
|
|
|
+ size_t off = 27 * 2 * i + l * triangles * 27 * 2;
|
|
|
|
|
|
- float texWidth1 = (i % quality) * (1.0f / quality);
|
|
|
- float texWidth2 = texWidth1 + (1.0f / quality);
|
|
|
+ float texWidth1 = (float)(i % quality) * (1.0f / (float)quality);
|
|
|
+ float texWidth2 = texWidth1 + (1.0f / (float)quality);
|
|
|
|
|
|
float r = 0.0f;
|
|
|
float g = 0.0f;
|
|
|
@@ -142,24 +146,24 @@ void generateSphere() {
|
|
|
a = field->a;
|
|
|
}
|
|
|
|
|
|
- for(int j = 0; j < 54; j += 9) {
|
|
|
+ for(size_t j = 0; j < 54; j += 9) {
|
|
|
data[3 + off + j] = r;
|
|
|
data[4 + off + j] = g;
|
|
|
data[5 + off + j] = b;
|
|
|
data[6 + off + j] = a;
|
|
|
}
|
|
|
|
|
|
- data[0 + off] = r2 * cos(first);
|
|
|
+ data[0 + off] = r2 * cosf(first);
|
|
|
data[1 + off] = high2;
|
|
|
- data[2 + off] = r2 * sin(first);
|
|
|
+ data[2 + off] = r2 * sinf(first);
|
|
|
|
|
|
- data[9 + off] = r1 * cos(first);
|
|
|
+ data[9 + off] = r1 * cosf(first);
|
|
|
data[10 + off] = high1;
|
|
|
- data[11 + off] = r1 * sin(first);
|
|
|
+ data[11 + off] = r1 * sinf(first);
|
|
|
|
|
|
- data[18 + off] = r1 * cos(second);
|
|
|
+ data[18 + off] = r1 * cosf(second);
|
|
|
data[19 + off] = high1;
|
|
|
- data[20 + off] = r1 * sin(second);
|
|
|
+ data[20 + off] = r1 * sinf(second);
|
|
|
|
|
|
if(flag) {
|
|
|
data[7 + off] = texHigh2 * 0.5f;
|
|
|
@@ -181,17 +185,17 @@ void generateSphere() {
|
|
|
data[26 + off] = texHigh1;
|
|
|
}
|
|
|
|
|
|
- data[27 + off] = r2 * cos(first);
|
|
|
+ data[27 + off] = r2 * cosf(first);
|
|
|
data[28 + off] = high2;
|
|
|
- data[29 + off] = r2 * sin(first);
|
|
|
+ data[29 + off] = r2 * sinf(first);
|
|
|
|
|
|
- data[36 + off] = r1 * cos(second);
|
|
|
+ data[36 + off] = r1 * cosf(second);
|
|
|
data[37 + off] = high1;
|
|
|
- data[38 + off] = r1 * sin(second);
|
|
|
+ data[38 + off] = r1 * sinf(second);
|
|
|
|
|
|
- data[45 + off] = r2 * cos(second);
|
|
|
+ data[45 + off] = r2 * cosf(second);
|
|
|
data[46 + off] = high2;
|
|
|
- data[47 + off] = r2 * sin(second);
|
|
|
+ data[47 + off] = r2 * sinf(second);
|
|
|
|
|
|
if(flag) {
|
|
|
data[34 + off] = texHigh2 * 0.5f;
|
|
|
@@ -215,45 +219,45 @@ void generateSphere() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
|
|
|
+ glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)size, data, GL_STATIC_DRAW);
|
|
|
}
|
|
|
|
|
|
-void updateProjection(float aspect, int program) {
|
|
|
+static void updateProjection(float aspect, GLuint program) {
|
|
|
float fovY = 60.0f;
|
|
|
float nearClip = 0.1f;
|
|
|
float farClip = 1000;
|
|
|
|
|
|
- float q = 1.0f / (float)tan((0.5f * fovY) * M_PI / 180.0f);
|
|
|
+ float q = 1.0f / tanf((0.5f * fovY) * (float)M_PI / 180.0f);
|
|
|
float a = q / aspect;
|
|
|
float b = (nearClip + farClip) / (nearClip - farClip);
|
|
|
float c = (2.0f * nearClip * farClip) / (nearClip - farClip);
|
|
|
|
|
|
- GLfloat data[16];
|
|
|
- data[0] = a;
|
|
|
- data[1] = 0.0f;
|
|
|
- data[2] = 0.0f;
|
|
|
- data[3] = 0.0f;
|
|
|
+ GLfloat mData[16];
|
|
|
+ mData[0] = a;
|
|
|
+ mData[1] = 0.0f;
|
|
|
+ mData[2] = 0.0f;
|
|
|
+ mData[3] = 0.0f;
|
|
|
|
|
|
- data[4] = 0.0f;
|
|
|
- data[5] = q;
|
|
|
- data[6] = 0.0f;
|
|
|
- data[7] = 0.0f;
|
|
|
+ mData[4] = 0.0f;
|
|
|
+ mData[5] = q;
|
|
|
+ mData[6] = 0.0f;
|
|
|
+ mData[7] = 0.0f;
|
|
|
|
|
|
- data[8] = 0.0f;
|
|
|
- data[9] = 0.0f;
|
|
|
- data[10] = b;
|
|
|
- data[11] = -1.0f;
|
|
|
+ mData[8] = 0.0f;
|
|
|
+ mData[9] = 0.0f;
|
|
|
+ mData[10] = b;
|
|
|
+ mData[11] = -1.0f;
|
|
|
|
|
|
- data[12] = 0.0f;
|
|
|
- data[13] = 0.0f;
|
|
|
- data[14] = c;
|
|
|
- data[15] = 0;
|
|
|
+ mData[12] = 0.0f;
|
|
|
+ mData[13] = 0.0f;
|
|
|
+ mData[14] = c;
|
|
|
+ mData[15] = 0;
|
|
|
|
|
|
GLint loc = glGetUniformLocation(program, "projMatrix");
|
|
|
- glUniformMatrix4fv(loc, 1, 0, data);
|
|
|
+ glUniformMatrix4fv(loc, 1, 0, mData);
|
|
|
}
|
|
|
|
|
|
-float chooseSmallerPositive(float a, float b) {
|
|
|
+static float chooseSmallerPositive(float a, float b) {
|
|
|
if(a < 0) {
|
|
|
return b;
|
|
|
} else if(b < 0 || b > a) {
|
|
|
@@ -262,13 +266,17 @@ float chooseSmallerPositive(float a, float b) {
|
|
|
return b;
|
|
|
}
|
|
|
|
|
|
-void updateView(int program, float lag) {
|
|
|
+static void updateView(GLuint program, float lag) {
|
|
|
// front
|
|
|
- vectorSetAngles(&front, interpolate(lag, oldLengthAngle, lengthAngle), interpolate(lag, oldWidthAngle, widthAngle));
|
|
|
+ vectorSetAngles(
|
|
|
+ &front, interpolate(lag, oldLengthAngle, lengthAngle),
|
|
|
+ interpolate(lag, oldWidthAngle, widthAngle));
|
|
|
|
|
|
// calculate selected tile
|
|
|
- float a = camera.x * camera.x + camera.y * camera.y + camera.z * camera.z - 1;
|
|
|
- float b = 2 * (camera.x * front.x + camera.y * front.y + camera.z * front.z);
|
|
|
+ float a =
|
|
|
+ camera.x * camera.x + camera.y * camera.y + camera.z * camera.z - 1;
|
|
|
+ float b =
|
|
|
+ 2 * (camera.x * front.x + camera.y * front.y + camera.z * front.z);
|
|
|
float c = front.x * front.x + front.y * front.y + front.z * front.z;
|
|
|
|
|
|
float p = b / c;
|
|
|
@@ -276,21 +284,22 @@ void updateView(int program, float lag) {
|
|
|
|
|
|
float det = p * p * 0.25f - q;
|
|
|
if(det >= 0) {
|
|
|
- float k = sqrt(det);
|
|
|
+ float k = sqrtf(det);
|
|
|
k = chooseSmallerPositive(-0.5f * p + k, -0.5f * p - k);
|
|
|
if(k >= 0) {
|
|
|
Vector3D v;
|
|
|
vectorSetTo(&v, &camera);
|
|
|
vectorAddMul(&v, &front, k);
|
|
|
|
|
|
- selectedLayer = (asin(-v.y) + M_PI_2) * M_1_PI * (2 + fieldSize);
|
|
|
- if(selectedLayer == 2 + fieldSize) {
|
|
|
- selectedLayer = fieldSize + 1;
|
|
|
+ selectedLayer = (int)((asin((double)-v.y) + M_PI_2) * M_1_PI *
|
|
|
+ (double)(2 + fieldSize));
|
|
|
+ if(selectedLayer == (int)(2 + fieldSize)) {
|
|
|
+ selectedLayer = (int)(fieldSize + 1);
|
|
|
}
|
|
|
|
|
|
- float tan = atan2(v.z, v.x) * M_1_PI * 0.5;
|
|
|
+ float tan = atan2f(v.z, v.x) * (float)M_1_PI * 0.5f;
|
|
|
tan += (tan < 0);
|
|
|
- selectedIndex = tan * fieldSize;
|
|
|
+ selectedIndex = (int)(tan * (float)fieldSize);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -313,39 +322,41 @@ void updateView(int program, float lag) {
|
|
|
// down
|
|
|
vectorSetToInverse(&down, &up);
|
|
|
|
|
|
- GLfloat data[16];
|
|
|
- data[0] = right.x;
|
|
|
- data[1] = up.x;
|
|
|
- data[2] = back.x;
|
|
|
- data[3] = 0.0f;
|
|
|
+ GLfloat mData[16];
|
|
|
+ mData[0] = right.x;
|
|
|
+ mData[1] = up.x;
|
|
|
+ mData[2] = back.x;
|
|
|
+ mData[3] = 0.0f;
|
|
|
|
|
|
- data[4] = right.y;
|
|
|
- data[5] = up.y;
|
|
|
- data[6] = back.y;
|
|
|
- data[7] = 0.0f;
|
|
|
+ mData[4] = right.y;
|
|
|
+ mData[5] = up.y;
|
|
|
+ mData[6] = back.y;
|
|
|
+ mData[7] = 0.0f;
|
|
|
|
|
|
- data[8] = right.z;
|
|
|
- data[9] = up.z;
|
|
|
- data[10] = back.z;
|
|
|
- data[11] = 0.0f;
|
|
|
+ mData[8] = right.z;
|
|
|
+ mData[9] = up.z;
|
|
|
+ mData[10] = back.z;
|
|
|
+ mData[11] = 0.0f;
|
|
|
|
|
|
Vector3D interCam;
|
|
|
vectorSetTo(&interCam, &oldCamera);
|
|
|
vectorAddMul(&interCam, &camera, lag);
|
|
|
vectorAddMul(&interCam, &oldCamera, -lag);
|
|
|
|
|
|
- data[12] = vectorDotInverse(&right, &interCam);
|
|
|
- data[13] = vectorDotInverse(&up, &interCam);
|
|
|
- data[14] = vectorDotInverse(&back, &interCam);
|
|
|
- data[15] = 1.0f;
|
|
|
+ mData[12] = vectorDotInverse(&right, &interCam);
|
|
|
+ mData[13] = vectorDotInverse(&up, &interCam);
|
|
|
+ mData[14] = vectorDotInverse(&back, &interCam);
|
|
|
+ mData[15] = 1.0f;
|
|
|
|
|
|
- // printf("%f %f %f %f\n", data[0], data[4], data[8], data[12]);
|
|
|
- // printf("%f %f %f %f\n", data[1], data[5], data[9], data[13]);
|
|
|
- // printf("%f %f %f %f\n", data[2], data[6], data[10], data[14]);
|
|
|
- // printf("%f %f %f %f\n", data[3], data[7], data[11], data[15]);
|
|
|
+ // printf("%f %f %f %f\n", mData[0], mData[4], mData[8], mData[12]);
|
|
|
+ // printf("%f %f %f %f\n", mData[1], mData[5], mData[9], mData[13]);
|
|
|
+ // printf("%f %f %f %f\n", mData[2], mData[6], mData[10], mData[14]);
|
|
|
+ // printf("%f %f %f %f\n", mData[3], mData[7], mData[11], mData[15]);
|
|
|
|
|
|
// front
|
|
|
- vectorSetAngles(&front, interpolate(lag, oldLengthAngle, lengthAngle), interpolate(lag, oldWidthAngle, widthAngle));
|
|
|
+ vectorSetAngles(
|
|
|
+ &front, interpolate(lag, oldLengthAngle, lengthAngle),
|
|
|
+ interpolate(lag, oldWidthAngle, widthAngle));
|
|
|
front.y = 0;
|
|
|
vectorNormalize(&front);
|
|
|
|
|
|
@@ -367,10 +378,10 @@ void updateView(int program, float lag) {
|
|
|
vectorSetToInverse(&down, &up);
|
|
|
|
|
|
GLint loc = glGetUniformLocation(program, "viewMatrix");
|
|
|
- glUniformMatrix4fv(loc, 1, 0, data);
|
|
|
+ glUniformMatrix4fv(loc, 1, 0, mData);
|
|
|
}
|
|
|
|
|
|
-void init(int program) {
|
|
|
+static void init(GLuint program) {
|
|
|
printf("Init\n");
|
|
|
|
|
|
glGenBuffers(1, &vbo);
|
|
|
@@ -397,7 +408,7 @@ void init(int program) {
|
|
|
updateProjection(4.0f / 3.0f, program);
|
|
|
}
|
|
|
|
|
|
-void invertField(int layer, int index) {
|
|
|
+static void invertField(size_t layer, size_t index) {
|
|
|
GameField* field = getGameField(layer, index);
|
|
|
if(field != NULL) {
|
|
|
field->id = 1 - field->id;
|
|
|
@@ -405,17 +416,17 @@ void invertField(int layer, int index) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void invertAt(int layer, int index) {
|
|
|
+static void invertAt(size_t layer, size_t index) {
|
|
|
if(layer == 0) {
|
|
|
invertField(layer, index);
|
|
|
layer++;
|
|
|
- for(int i = 0; i < fieldSize; i++) {
|
|
|
+ for(size_t i = 0; i < fieldSize; i++) {
|
|
|
invertField(layer, i);
|
|
|
}
|
|
|
} else if(layer == fieldSize + 1) {
|
|
|
invertField(layer, index);
|
|
|
layer--;
|
|
|
- for(int i = 0; i < fieldSize; i++) {
|
|
|
+ for(size_t i = 0; i < fieldSize; i++) {
|
|
|
invertField(layer, i);
|
|
|
}
|
|
|
} else {
|
|
|
@@ -427,11 +438,11 @@ void invertAt(int layer, int index) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void tick(int program) {
|
|
|
+static void tick(void) {
|
|
|
if(tickTime == -1) {
|
|
|
- tickTime = glfwGetTimerValue();
|
|
|
+ tickTime = (int64_t)glfwGetTimerValue();
|
|
|
} else {
|
|
|
- long time = glfwGetTimerValue();
|
|
|
+ int64_t time = (int64_t)glfwGetTimerValue();
|
|
|
tickSum += time - tickTime;
|
|
|
tickTime = time;
|
|
|
|
|
|
@@ -462,8 +473,9 @@ void tick(int program) {
|
|
|
vectorAddMul(&camera, &down, factor);
|
|
|
}
|
|
|
|
|
|
- if(mouseIsJustDown(GLFW_MOUSE_BUTTON_1) && selectedLayer != -1 && selectedIndex != -1) {
|
|
|
- invertAt(selectedLayer, selectedIndex);
|
|
|
+ if(mouseIsJustDown(GLFW_MOUSE_BUTTON_1) && selectedLayer != -1 &&
|
|
|
+ selectedIndex != -1) {
|
|
|
+ invertAt((size_t)selectedLayer, (size_t)selectedIndex);
|
|
|
generateSphere();
|
|
|
selectedLayer = -1;
|
|
|
selectedIndex = -1;
|
|
|
@@ -472,9 +484,9 @@ void tick(int program) {
|
|
|
widthAngle -= mouseY * 0.1f;
|
|
|
lengthAngle -= mouseX * 0.1f;
|
|
|
|
|
|
- if(widthAngle >= 89.5) {
|
|
|
+ if(widthAngle >= 89.5f) {
|
|
|
widthAngle = 89.5f;
|
|
|
- } else if(widthAngle <= -89.5) {
|
|
|
+ } else if(widthAngle <= -89.5f) {
|
|
|
widthAngle = -89.5f;
|
|
|
}
|
|
|
|
|
|
@@ -482,11 +494,11 @@ void tick(int program) {
|
|
|
mouseY = 0.0f;
|
|
|
}
|
|
|
|
|
|
-void renderTick(int program, float lag) {
|
|
|
+static void renderTick(GLuint program, float lag) {
|
|
|
if(renderTickTime == -1) {
|
|
|
- renderTickTime = glfwGetTimerValue();
|
|
|
+ renderTickTime = (int64_t)glfwGetTimerValue();
|
|
|
} else {
|
|
|
- long time = glfwGetTimerValue();
|
|
|
+ int64_t time = (int64_t)glfwGetTimerValue();
|
|
|
renderTickSum += time - renderTickTime;
|
|
|
renderTickTime = time;
|
|
|
|
|
|
@@ -497,25 +509,25 @@ void renderTick(int program, float lag) {
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
|
glBindVertexArray(vba);
|
|
|
- glDrawArrays(GL_TRIANGLES, 0, vertices);
|
|
|
+ glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertices);
|
|
|
}
|
|
|
|
|
|
-void onWindowResize(int width, int height) {
|
|
|
- updateProjection((float)width / height, getProgram());
|
|
|
+static void onWindowResize(int width, int height) {
|
|
|
+ updateProjection((float)width / (float)height, getProgram());
|
|
|
}
|
|
|
|
|
|
-void onMouseMove(float x, float y) {
|
|
|
+static void onMouseMove(float x, float y) {
|
|
|
mouseX += x;
|
|
|
mouseY += y;
|
|
|
}
|
|
|
|
|
|
-int readPositiveInt(int from, int to, char* message, int error) {
|
|
|
+static int readPositiveInt(int from, int to, char* message, int error) {
|
|
|
fputs(message, stdout);
|
|
|
fflush(stdout);
|
|
|
|
|
|
- int size = 16;
|
|
|
- int index = 0;
|
|
|
- char* buffer = malloc(sizeof(char) * size);
|
|
|
+ size_t bufferSize = 16;
|
|
|
+ size_t index = 0;
|
|
|
+ char* buffer = malloc(sizeof(char) * bufferSize);
|
|
|
|
|
|
while(1) {
|
|
|
int c = fgetc(stdin);
|
|
|
@@ -524,7 +536,7 @@ int readPositiveInt(int from, int to, char* message, int error) {
|
|
|
return error;
|
|
|
} else if(c == '\n') {
|
|
|
int number = 0;
|
|
|
- int i = 0;
|
|
|
+ size_t i = 0;
|
|
|
while(i < index) {
|
|
|
int n = buffer[i] - '0';
|
|
|
if(n < 0 || n > 9) {
|
|
|
@@ -548,34 +560,36 @@ int readPositiveInt(int from, int to, char* message, int error) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if(index >= size) {
|
|
|
- size *= 2;
|
|
|
- buffer = realloc(buffer, sizeof(char) * size);
|
|
|
+ if(index >= bufferSize) {
|
|
|
+ bufferSize *= 2;
|
|
|
+ buffer = realloc(buffer, sizeof(char) * bufferSize);
|
|
|
}
|
|
|
- buffer[index] = c;
|
|
|
+ buffer[index] = (char)c;
|
|
|
index++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-int main() {
|
|
|
- /*fieldSize = readPositiveInt(5, 20, "Select a game size from 5 to 20:\n", 0);
|
|
|
- if(fieldSize == 0)
|
|
|
+int main(void) {
|
|
|
+ (void)readPositiveInt;
|
|
|
+ /*fieldSize = readPositiveInt(5, 20, "Select a game size from 5 to 20:\n",
|
|
|
+ 0); if(fieldSize == 0)
|
|
|
{
|
|
|
printf("Cannot read from stdin\n");
|
|
|
return EXIT_SUCCESS;
|
|
|
}
|
|
|
- quality = readPositiveInt(1, 9, "Select a rendering quality from 1 to 9:\n", 0);
|
|
|
- if(quality == 0)
|
|
|
+ quality = readPositiveInt(1, 9, "Select a rendering quality from 1 to 9:\n",
|
|
|
+ 0); if(quality == 0)
|
|
|
{
|
|
|
printf("Cannot read from stdin\n");
|
|
|
return EXIT_SUCCESS;
|
|
|
- }*/
|
|
|
+ }/*/
|
|
|
fieldSize = 5;
|
|
|
quality = 8;
|
|
|
|
|
|
- if(startGame("Test Game", init, tick, renderTick, onWindowResize, onMouseMove)) {
|
|
|
+ if(startGame(
|
|
|
+ "Test Game", init, tick, renderTick, onWindowResize, onMouseMove)) {
|
|
|
fprintf(stderr, "Exited with error\n");
|
|
|
- // return EXIT_FAILURE;
|
|
|
+ return EXIT_FAILURE;
|
|
|
}
|
|
|
|
|
|
if(data != NULL) {
|
|
|
@@ -590,11 +604,13 @@ int main() {
|
|
|
|
|
|
printf("_______________TPS_______________\n");
|
|
|
printf("%ld %ld %ld\n", tickCounter, tickSum, tickTime);
|
|
|
- printf("%lf\n", (double)tickSum / tickCounter);
|
|
|
- printf("%lf\n", 1000000000.0 * tickCounter / tickSum);
|
|
|
+ printf("%lf\n", (double)tickSum / (double)tickCounter);
|
|
|
+ printf("%lf\n", 1000000000.0 * (double)tickCounter / (double)tickSum);
|
|
|
printf("_______________FPS_______________\n");
|
|
|
printf("%ld %ld %ld\n", renderTickCounter, renderTickSum, renderTickTime);
|
|
|
- printf("%lf\n", (double)renderTickSum / renderTickCounter);
|
|
|
- printf("%lf\n", 1000000000.0 * renderTickCounter / renderTickSum);
|
|
|
+ printf("%lf\n", (double)renderTickSum / (double)renderTickCounter);
|
|
|
+ printf(
|
|
|
+ "%lf\n",
|
|
|
+ 1000000000.0 * (double)renderTickCounter / (double)renderTickSum);
|
|
|
return EXIT_SUCCESS;
|
|
|
-}
|
|
|
+}
|