diff --git a/bin/back b/bin/back index e2c5d4c..ff072cc 100755 Binary files a/bin/back and b/bin/back differ diff --git a/obj/display.o b/obj/display.o index ae36caf..81a9792 100644 Binary files a/obj/display.o and b/obj/display.o differ diff --git a/obj/generation.o b/obj/generation.o index f86691c..751cac4 100644 Binary files a/obj/generation.o and b/obj/generation.o differ diff --git a/obj/main.o b/obj/main.o index 86b5558..6a38388 100644 Binary files a/obj/main.o and b/obj/main.o differ diff --git a/src/display.c b/src/display.c index 04bbdb5..51a2c69 100644 --- a/src/display.c +++ b/src/display.c @@ -240,9 +240,9 @@ double square_z_distance_to_camera( void rotate_cube(double x0, double y0, double z0, double* rx, double* ry, double* rz, cube_0* cb) { // align pt to (0, 0, 0) - double x = x0 - (cb->x + cb->w/2) ; - double y = y0 - (cb->y + cb->h/2) ; - double z = z0 - (cb->z + cb->d/2) ; + double x = x0 - (cb->x + cb->w/2.0) ; + double y = y0 - (cb->y + cb->h/2.0) ; + double z = z0 - (cb->z + cb->d/2.0) ; // rotate (y) double xry = x*cos(cb->hz_angle) - z*sin(cb->hz_angle) ; @@ -250,9 +250,9 @@ void rotate_cube(double x0, double y0, double z0, double* rx, double* ry, double double zry = z*cos(cb->hz_angle) + x*sin(cb->hz_angle) ; // rotate (x) - *rx = (cb->x + cb->w/2) + xry ; - *ry = (cb->y + cb->h/2) + yry*cos(cb->vt_angle) - zry*sin(cb->vt_angle) ; - *rz = (cb->z + cb->d/2) + zry*cos(cb->vt_angle) + yry*sin(cb->vt_angle) ; + *rx = (cb->x + cb->w/2.0) + xry ; + *ry = (cb->y + cb->h/2.0) + yry*cos(cb->vt_angle) - zry*sin(cb->vt_angle) ; + *rz = (cb->z + cb->d/2.0) + zry*cos(cb->vt_angle) + yry*sin(cb->vt_angle) ; } pt_2d pt_rotate_cube_3d(double x0, double y0, double z0, cube_0* cb) { @@ -985,54 +985,54 @@ pt_2d gl_project(pt_2d p) { void gl_renderSurface(unsigned int shaderProgram, unsigned int VAO, unsigned int VBO, cube_0* c, int sf) { float vertices[] = { - (float)(c->x), (float)(c->y) , (float)(c->z), - (float)(c->x), (float)(c->y + c->h), (float)(c->z), - (float)(c->x), (float)(c->y + c->h), (float)(c->z + c->d), - (float)(c->x), (float)(c->y) , (float)(c->z), - (float)(c->x), (float)(c->y) , (float)(c->z + c->d), - (float)(c->x), (float)(c->y + c->h), (float)(c->z + c->d), + (float)(-c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0), + (float)(-c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0), + (float)(-c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0), + (float)(-c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0), + (float)(-c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0), + (float)(-c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0), - (float)(c->x + c->w), (float)(c->y) , (float)(c->z), - (float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z), - (float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z + c->d), - (float)(c->x + c->w), (float)(c->y) , (float)(c->z), - (float)(c->x + c->w), (float)(c->y) , (float)(c->z + c->d), - (float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z + c->d), + (float)(c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0), + (float)(c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0), + (float)(c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0), + (float)(c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0), + (float)(c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0), + (float)(c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0), - (float)(c->x) , (float)(c->y), (float)(c->z), - (float)(c->x + c->w), (float)(c->y), (float)(c->z), - (float)(c->x + c->w), (float)(c->y), (float)(c->z + c->d), - (float)(c->x) , (float)(c->y), (float)(c->z), - (float)(c->x) , (float)(c->y), (float)(c->z + c->d), - (float)(c->x + c->w), (float)(c->y), (float)(c->z + c->d), + (float)(-c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0), + (float)(c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0), + (float)(c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0), + (float)(-c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0), + (float)(-c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0), + (float)(c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0), - (float)(c->x) , (float)(c->y + c->h), (float)(c->z), - (float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z), - (float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z + c->d), - (float)(c->x) , (float)(c->y + c->h), (float)(c->z), - (float)(c->x) , (float)(c->y + c->h), (float)(c->z + c->d), - (float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z + c->d), + (float)(-c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0), + (float)(c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0), + (float)(c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0), + (float)(-c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0), + (float)(-c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0), + (float)(c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0), - (float)(c->x) , (float)(c->y) , (float)(c->z), - (float)(c->x + c->w), (float)(c->y) , (float)(c->z), - (float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z), - (float)(c->x) , (float)(c->y) , (float)(c->z), - (float)(c->x) , (float)(c->y + c->h), (float)(c->z), - (float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z), + (float)(-c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0), + (float)(c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0), + (float)(c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0), + (float)(-c->w/2.0), (float)(-c->h/2.0), (float)(-c->d/2.0), + (float)(-c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0), + (float)(c->w/2.0), (float)(c->h/2.0), (float)(-c->d/2.0), - (float)(c->x) , (float)(c->y) , (float)(c->z + c->d), - (float)(c->x + c->w), (float)(c->y) , (float)(c->z + c->d), - (float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z + c->d), - (float)(c->x) , (float)(c->y) , (float)(c->z + c->d), - (float)(c->x) , (float)(c->y + c->h), (float)(c->z + c->d), - (float)(c->x + c->w), (float)(c->y + c->h), (float)(c->z + c->d), + (float)(-c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0), + (float)(c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0), + (float)(c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0), + (float)(-c->w/2.0), (float)(-c->h/2.0), (float)(c->d/2.0), + (float)(-c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0), + (float)(c->w/2.0), (float)(c->h/2.0), (float)(c->d/2.0), }; + mat4 model, view, projection; glm_mat4_identity(model); - //glm_rotate(model, (float)(c->hz_angle), (vec3){0.0f, 1.0f, 0.0f}); - //glm_rotate(model, (float)(c->vt_angle), (vec3){1.0f, 0.0f, 0.0f}); - //glm_translate(model, (vec3){(float)camx, (float)camy, (float)(-camz)}); - //glm_translate(model, (vec3){0.0f, 0.0f, 0.0f}); + glm_translate(model, (vec3){(float)(c->x+c->w/2.0), (float)(c->y+c->h/2.0), (float)(c->z+c->d/2.0)}); + glm_rotate(model, (float)(-c->hz_angle), (vec3){0.0f, 1.0f, 0.0f}); + glm_rotate(model, (float)(c->vt_angle), (vec3){1.0f, 0.0f, 0.0f}); vec3 dir0; vec3 direction; diff --git a/src/generation.c b/src/generation.c index b86f380..b6b6fd4 100644 --- a/src/generation.c +++ b/src/generation.c @@ -41,7 +41,7 @@ void init_ent_generator(int n) { hashtbl_entities[0].id = 0; hashtbl_entities[0].name = "Coin"; // 0 = default - hashtbl_entities[0].updatePos = &speen ; + hashtbl_entities[0].updatePos = &speen2 ; hashtbl_entities[0].onHit = &detectHit ; hashtbl_entities[0].onDeath = NULL ; diff --git a/src/main.c b/src/main.c index 001fb65..759b169 100644 --- a/src/main.c +++ b/src/main.c @@ -110,7 +110,7 @@ const char *vertexShaderSource = "#version 330 core\n" const char *fragmentShaderSource = "#version 330 core\n" "out vec4 FragColor;\n" "void main() {\n" - " FragColor = vec4(1.0, 0.5, 0.2, 1.0);\n" + " FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n" "}\0"; int main_alt() { @@ -205,6 +205,9 @@ int main_alt() { init_proj(); parse_rooms(5); + int fps = 60 ; + int interval = 1000000/fps ; + clock_t origin = clock(); clock_t finish = clock(); while (!glfwWindowShouldClose(window)) { @@ -216,7 +219,6 @@ int main_alt() { generate_nearby_chunks(1); - //gl_renderTriangle(shaderProgram, VAO, VBO, -0.5, -0.5, 0.0, 0.5, -0.5, 0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 1.0); gl_renderAll(shaderProgram, VAO, VBO); //printf("01\n"); @@ -225,11 +227,15 @@ int main_alt() { // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) // ------------------------------------------------------------------------------- finish = clock(); - processInput(window, ((float)origin - (float)finish)/CLOCKS_PER_SEC); - update_entities(((float)origin - (float)finish)/CLOCKS_PER_SEC); - updateAllProj(((float)origin - (float)finish)/CLOCKS_PER_SEC); + processInput(window, ((float)finish - (float)origin)/CLOCKS_PER_SEC); + update_entities(((float)finish - (float)origin)/CLOCKS_PER_SEC); + updateAllProj(((float)finish - (float)origin)/CLOCKS_PER_SEC); glfwSwapBuffers(window); glfwPollEvents(); + + printf("%f\n", 1.0f/(((float)origin - (float)finish)/CLOCKS_PER_SEC)); + + usleep(interval); } for(int k = 0; k < MAX_SIZE; k++) { @@ -266,150 +272,4 @@ int main_alt() { int main(int argc, char** argv) { srand(time(NULL)); return main_alt(); - - //-------------------------------------------------------------------------------// - - if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { - printf( "error initializing SDL: %s\n", SDL_GetError()); - } - SDL_Window* win = SDL_CreateWindow("Game", - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, - 1500, 1000, 0); - - Uint32 render_flags = SDL_RENDERER_ACCELERATED; - SDL_Renderer* rend = SDL_CreateRenderer(win, -1, render_flags); - if(rend == NULL) { - printf( "ERROR : cannot initialize SDL renderer\n"); - exit(1); - } - printf( "%d\n", SDL_SetRenderDrawBlendMode(rend, SDL_BLENDMODE_BLEND)); - - //-------------------------------------------------------------------------------// - - if(SDL_Init(SDL_INIT_AUDIO)) { - fprintf(stderr, "cannot initialize audio"); - exit(1); - } - SDL_SetRelativeMouseMode(true) ; - - /* -------------------------------------------------------- */ - int fps = 60; - int interval = 1000000/fps; - double intervalf = 1.0/((double)(fps)); - - bool debug_main = true ; - - init_csts(); - init_hashtbl(); - init_draworder(); - init_ent_generator(10); - trInit(); - init_proj(); - parse_rooms(5); - import_digits(rend) ; - import_letters(rend) ; - sim_time = 0.0 ; - clock_t origin = clock(); - clock_t finish = clock(); - - clock_t entstart = clock(); - clock_t entend = clock(); - float delta; - while(!stop_evetything) { - resetRenderer(rend) ; - - origin = clock(); - SDL_SetRenderDrawColor(rend, 255, 255, 255, SDL_ALPHA_OPAQUE) ; - entend = clock(); - //printf("00\n"); - //printf("%s\n", SDL_GetError()); - //fflush(stdout); - playerActions(((float)entend - (float)entstart)/CLOCKS_PER_SEC) ; - //printf("01\n"); - //fflush(stdout); - generate_nearby_chunks(1); - //printf("02\n"); - //fflush(stdout); - - entend = clock(); - update_entities(((float)entend - (float)entstart)/CLOCKS_PER_SEC); - updateAllProj(((float)entend - (float)entstart)/CLOCKS_PER_SEC); - //printf("03\n"); - //fflush(stdout); - entstart = clock(); - - //printf("-->%d\n", triangles_i); - drawCurrentRoom(rend); - //printf("-->%d\n", triangles_i); - //printf("-->%d\n", triangles_i); - //printf("04\n"); - //printf("%s\n", SDL_GetError()); - //fflush(stdout); - drawData(rend) ; - //printf("05\n"); - //fflush(stdout); - drawHPbar(rend); - //printf("06\n"); - //fflush(stdout); - finish = clock(); - fade_dmg = max(fade_dmg-5, 0); - delta = ((float)finish - (float)origin)/CLOCKS_PER_SEC; - //printf("07\n"); - //fflush(stdout); - drawNumberToRenderer(rend, digits, (int)(1.0f/delta), 720, 60, 75/2, 105/2, 0); - drawNumberToRenderer(rend, digits, (int)(10*sim_time), 720, 110, 75/2, 105/2, 0); - drawNumberToRenderer(rend, digits, coins, 1500/2-55, 1000 - 70, 75/3, 105/3, 0); - //printf("08\n"); - //fflush(stdout); - //printf("%s\n", SDL_GetError()); - updateRenderer(rend) ; - sim_time += delta + intervalf ; - //printf("09\n"); - //fflush(stdout); - if(player_hp <= 0) { - stop_evetything = true ; - } - usleep(interval) ; - } - //printf("GPNE\n"); - //fflush(stdout); - free_digits(digits) ; - - for(int k = 0; k < MAX_SIZE; k++) { - free(triangles_to_render[k]); - free(triangles_og_coords[k]); - } - free(drawOrder); - free(triangles_to_render); - free(triangles_og_coords); - free(reds); - free(greens); - free(blues); - free(triangles_order); - free(triangles_shr); - free(visited_tri); - free_proj(); - //printf("10\n"); - //fflush(stdout); - hashtbl_free(visited); - free_pool(); - - /* -------------------------------------------------------- */ - - SDL_DestroyRenderer(rend); - //printf("10\n"); - //fflush(stdout); - SDL_DestroyWindow(win); - //printf("11\n"); - //fflush(stdout); - SDL_Quit(); - //printf("12\n"); - //fflush(stdout); - - /* -------------------------------------------------------- */ - - //printf("Done\n") ; - //fflush(stdout); - return 0; } \ No newline at end of file diff --git a/templates/room_1 b/templates/room_1 index ebb0848..9da6c2d 100644 --- a/templates/room_1 +++ b/templates/room_1 @@ -12,12 +12,12 @@ Teleporters : [7.0, 0.0, -1.0, 2.0, 1.0, 2.0, 0.0, 0.0, 0, 0, 255; 1, 0] Entities : -[0.0, 3.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0] -[0.0, 4.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0] -[0.0, 5.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0] -[0.0, 6.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0] -[0.0, 7.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0] -[0.0, 8.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0] +[1.0, 3.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0] +[1.0, 4.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0] +[1.0, 5.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0] +[0.0, 6.0, 1.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0] +[0.0, 7.0, 1.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0] +[0.0, 8.0, 1.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0] [0.0, 9.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0] [0.0, 10.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 193, 192, 0, 1, 0, 0]