place / break blocks
This commit is contained in:
parent
fb639f96c3
commit
227d642be6
7 changed files with 191 additions and 55 deletions
67
main.c
67
main.c
|
@ -9,12 +9,12 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "control.h"
|
||||
#include "cubes.h"
|
||||
#include "gen.h"
|
||||
#include "gl.h"
|
||||
#include "linmath.h"
|
||||
#include "stb_image.h"
|
||||
#include "control.h"
|
||||
|
||||
static const char *vertex_shader_text =
|
||||
"#version 330\n"
|
||||
|
@ -64,6 +64,21 @@ static void key_callback(GLFWwindow *window, int key, int scancode, int action,
|
|||
|
||||
double cx = 0;
|
||||
double cy = 0;
|
||||
int fr = 0;
|
||||
vec3 pos;
|
||||
|
||||
void mouse_button_callback(GLFWwindow *window, int button, int action,
|
||||
int mods) {
|
||||
if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {
|
||||
fr = 1;
|
||||
control_rclick(cx, cy, pos);
|
||||
}
|
||||
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
|
||||
fr = 1;
|
||||
control_lclick(cx, cy, pos);
|
||||
}
|
||||
}
|
||||
|
||||
int width, height;
|
||||
|
||||
static void cursor_position_callback(GLFWwindow *window, double x, double y) {
|
||||
|
@ -99,8 +114,8 @@ void *render_chunks(void *args) {
|
|||
|
||||
*cube_count =
|
||||
cubes_vert(*args2.cube, *args2.text, *args2.cubeO, *args2.textO,
|
||||
args2.pos[0] / CHUNK_LENGTH, args2.pos[1] / CHUNK_LENGTH,
|
||||
args2.pos[2] / CHUNK_LENGTH, 0, args2.i2);
|
||||
args2.pos[0] / CHUNK_LENGTH, args2.pos[1] / CHUNK_LENGTH,
|
||||
args2.pos[2] / CHUNK_LENGTH, 0, args2.i2);
|
||||
|
||||
*args2.is_render = 2;
|
||||
|
||||
|
@ -134,8 +149,6 @@ int main(void) {
|
|||
int bleh = (CHUNK_DIAMETER_H) * (CHUNK_DIAMETER_V);
|
||||
int *i2 = calloc(bleh, sizeof(int));
|
||||
|
||||
int cube_count = cubes_vert(cube, text, cubeO, textO, 10240 / CHUNK_LENGTH,
|
||||
64 / CHUNK_LENGTH, 10240 / CHUNK_LENGTH, 1, i2);
|
||||
GLuint vertex_buffer[2];
|
||||
|
||||
GLuint vertex_array;
|
||||
|
@ -183,16 +196,23 @@ int main(void) {
|
|||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
||||
glfwSetCursorPosCallback(window, cursor_position_callback);
|
||||
|
||||
vec3 pos = {10240, 48, 10240};
|
||||
pos[0] = 10240;
|
||||
pos[1] = 48;
|
||||
pos[2] = 10240;
|
||||
|
||||
int cube_count =
|
||||
cubes_vert(cube, text, cubeO, textO, pos[0] / CHUNK_LENGTH,
|
||||
pos[1] / CHUNK_LENGTH, pos[2] / CHUNK_LENGTH, 1, i2);
|
||||
vec3 oldPos = {0, 0, 0};
|
||||
struct chunk ch7;
|
||||
ch7.exists = 0;
|
||||
int state = gen_cube(pos[0], pos[1], pos[2], ch7, 0);
|
||||
int state = gen_cube(pos[0], pos[1], pos[2], ch7, 0, -1);
|
||||
|
||||
while (1) {
|
||||
if (state != gen_cube(pos[0], pos[1], pos[2], ch7, 0))
|
||||
if (state != gen_cube(pos[0], pos[1], pos[2], ch7, 0, -1))
|
||||
break;
|
||||
pos[1] += (state ? 1 : -1);
|
||||
}
|
||||
|
@ -209,12 +229,14 @@ int main(void) {
|
|||
int last_render = 0;
|
||||
|
||||
struct chunk chunk = gen_chunk(pos[0] / CHUNK_LENGTH, pos[1] / CHUNK_LENGTH,
|
||||
pos[2] / CHUNK_LENGTH, 0, 0);
|
||||
pos[2] / CHUNK_LENGTH, 0, 0);
|
||||
|
||||
vec3 dir_temp = {0, 0, 0};
|
||||
|
||||
vec3 direction;
|
||||
|
||||
fr = 1;
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
|
@ -228,12 +250,10 @@ int main(void) {
|
|||
mat4x4_identity(m);
|
||||
mat4x4_perspective(p, 45.0 / 180.0 * M_PI, ratio, 0.1, 1000);
|
||||
|
||||
// TODO: make control code its own thing
|
||||
|
||||
vec3 direction;
|
||||
|
||||
vec3_dup(direction,control_handler(cx, cy, pos, dir_temp,
|
||||
window, chunk).pos);
|
||||
|
||||
vec3_dup(direction,
|
||||
control_handler(cx, cy, pos, dir_temp, window, chunk).pos);
|
||||
|
||||
vec3 dir_pos;
|
||||
vec3_scale(direction, direction, 100.0);
|
||||
|
@ -252,7 +272,8 @@ int main(void) {
|
|||
int ay = (int)(oldPos[1] / CHUNK_LENGTH) - (int)(pos[1] / CHUNK_LENGTH);
|
||||
int az = (int)(oldPos[2] / CHUNK_LENGTH) - (int)(pos[2] / CHUNK_LENGTH);
|
||||
|
||||
if ((ax != 0 || ay != 0 || az != 0) && last_render < 0) {
|
||||
if (((ax != 0 || ay != 0 || az != 0) && last_render < 0) || fr == 1) {
|
||||
fr = 0;
|
||||
struct args args;
|
||||
args.cube_count = &cube_count;
|
||||
|
||||
|
@ -283,17 +304,17 @@ int main(void) {
|
|||
glfwPollEvents();
|
||||
|
||||
if (is_render == 2) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer[1]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, (long)cube_count * sizeof(struct v3f),
|
||||
textO); // text);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer[0]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, (long)cube_count * sizeof(struct v3f),
|
||||
cubeO); // cube);
|
||||
if (thread_id != 0) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer[1]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0,
|
||||
(long)cube_count * sizeof(struct v3f), textO);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer[0]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0,
|
||||
(long)cube_count * sizeof(struct v3f), cubeO);
|
||||
pthread_join(thread_id, NULL);
|
||||
chunk = gen_chunk(pos[0] / CHUNK_LENGTH, pos[1] / CHUNK_LENGTH,
|
||||
pos[2] / CHUNK_LENGTH, 0, 0);
|
||||
pos[2] / CHUNK_LENGTH, 0, 0);
|
||||
}
|
||||
thread_id = 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue