Pre-release-0.6 : "Menupdate"

See discord for changelog.
master
azekillDIABLO 2018-12-02 19:01:03 +00:00
parent ee08da3a71
commit b2fa703427
32 changed files with 656 additions and 233 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
omicron

Binary file not shown.

View File

@ -0,0 +1,12 @@
#version 330 core
in vec2 UV;
out vec3 color;
uniform sampler2D logo_tex;
uniform float time;
void main(){
color = texture(logo_tex, UV, 16).xyz;
}

View File

@ -0,0 +1,14 @@
#version 120
uniform mat4 matrix;
attribute vec4 position;
attribute vec2 uv;
varying vec2 fragment_uv;
void main() {
gl_Position = matrix * position;
fragment_uv = uv;
}

View File

@ -7,13 +7,13 @@ varying vec2 fragment_uv;
void main() {
vec4 color = texture2D(sampler, fragment_uv);
if (is_sign) {
if (color == vec4(1.0)) {
discard;
}
}
else {
color.a = max(color.a, 0.4);
}
if (color == vec4(1.0, 0.0, 1.0, 1.0)) {
discard;
}
//else {
//color.a = max(color.a, 0.4);
//}
gl_FragColor = color;
}

13
shaders/ui_fragment.glsl Normal file
View File

@ -0,0 +1,13 @@
#version 120
uniform sampler2D sampler;
varying vec2 fragment_uv;
void main() {
vec4 color = texture2D(sampler, fragment_uv);
if (color == vec4(1.0, 0.0, 1.0, 1.0)) {
discard;
}
gl_FragColor = color;
}

14
shaders/ui_vertex.glsl Normal file
View File

@ -0,0 +1,14 @@
#version 120
uniform mat4 matrix;
attribute vec4 position;
attribute vec2 uv;
varying vec2 fragment_uv;
void main() {
gl_Position = matrix * position;
fragment_uv = uv;
}

View File

@ -7,7 +7,7 @@
#define CLIMB_SPEED 4
#define BUILD_HEIGHT_LIMIT 255
#define NUM_INVENTORY_VISIBLE 7
#define INFINI_STUFF 1
#define INFINITE_STUFF 1
//mapgen
#define BIOME_SIZE 1.0 //should be small, or you won't see any variety!
@ -36,6 +36,7 @@
#define SHOW_INFO_TEXT 1
#define SHOW_CHAT_TEXT 1
#define SHOW_PLAYER_NAMES 1
#define FONT_SIZE 16 // 12 small, 16 average, 24, big
// key bindings
#define CRAFT_KEY_FORWARD 'W'

View File

@ -266,6 +266,56 @@ void make_character(
*(d++) = du + 0; *(d++) = dv + b;
}
void make_ui_quad(
float *data,
float x, float y, float n, float m, char spritesheet_index)
{
float *d = data;
float s = 0.0625;
float a = s;
float b = s;
int w = spritesheet_index - 32;
float du = (w % 16) * a;
float dv = 1 - (w / 16) * b - b;
*(d++) = x - n; *(d++) = y - m;
*(d++) = du + 0; *(d++) = dv;
*(d++) = x + n; *(d++) = y - m;
*(d++) = du + a; *(d++) = dv;
*(d++) = x + n; *(d++) = y + m;
*(d++) = du + a; *(d++) = dv + b;
*(d++) = x - n; *(d++) = y - m;
*(d++) = du + 0; *(d++) = dv;
*(d++) = x + n; *(d++) = y + m;
*(d++) = du + a; *(d++) = dv + b;
*(d++) = x - n; *(d++) = y + m;
*(d++) = du + 0; *(d++) = dv + b;
}
void make_logo_quad(
float *data,
float x, float y, float n, float m, char spritesheet_index)
{
float *d = data;
float s = 0.0625*16; // changes the size of pixel array
float a = s;
float b = s;
int w = spritesheet_index - 32;
float du = (w % 16) * a;
float dv = 1 - (w / 16) * b - b;
*(d++) = x - n; *(d++) = y - m;
*(d++) = du + 0; *(d++) = dv;
*(d++) = x + n; *(d++) = y - m;
*(d++) = du + a; *(d++) = dv;
*(d++) = x + n; *(d++) = y + m;
*(d++) = du + a; *(d++) = dv + b;
*(d++) = x - n; *(d++) = y - m;
*(d++) = du + 0; *(d++) = dv;
*(d++) = x + n; *(d++) = y + m;
*(d++) = du + a; *(d++) = dv + b;
*(d++) = x - n; *(d++) = y + m;
*(d++) = du + 0; *(d++) = dv + b;
}
void make_character_3d(
float *data, float x, float y, float z, float n, int face, char c)
{

View File

@ -29,6 +29,14 @@ void make_character(
float *data,
float x, float y, float n, float m, char c);
void make_ui_quad(
float *data,
float x, float y, float n, float m, char spritesheet_index);
void make_logo_quad(
float *data,
float x, float y, float n, float m, char spritesheet_index);
void make_character_3d(
float *data, float x, float y, float z, float n, int face, char c);

View File

@ -225,6 +225,10 @@ const int plants[256] = {
};
const int obj[256] = {
60 // 90 - swamp tall grass
};
int is_plant(int w) {
switch (w) {
case Item_TALL_GRASS:
@ -355,6 +359,16 @@ int is_noncube(int w) {
return noncube_type(w) != NonCubeType_NOT_NONCUBE;
}
int is_placeable(int w) {
w = ABS(w);
switch (w) {
//case something
return 0;
default:
return 1;
}
}
NonCubeType noncube_type(int w) {
switch(w) {
case Item_SLAB_LOWER_STONEBRICK:

View File

@ -96,6 +96,7 @@ extern const int items[];
extern const int item_count;
extern const int blocks[256][6];
extern const int plants[256];
extern const int obj[256];
int is_plant(int w);
int is_obstacle(int w);
@ -107,6 +108,8 @@ int is_climbable(int w);
int is_noncube(int w);
int is_liquid(int w);
int buildable_to(int w);
int is_placeable(int w);
NonCubeType noncube_type(int w);

View File

@ -155,9 +155,9 @@ void get_sky_tint(Biome biome, SkyColor *c) {
//Not needed
//case Biome_TEMPERATE:
case Biome_DESERT:
c->r = 2.0f;
c->g = 1.7f,
c->b = 1.7f;
c->r = 1.6f;
c->g = 1.3f,
c->b = 1.0f;
break;
case Biome_MESA:
c->r = 2.2f;
@ -174,6 +174,11 @@ void get_sky_tint(Biome biome, SkyColor *c) {
c->g = 2.0f,
c->b = 2.0f;
break;
case Biome_SWAMP:
c->r = 0.4f;
c->g = 1.0f,
c->b = 0.6f;
break;
default:
c->r = 1.0f;
c->g = 1.5f,
@ -868,7 +873,7 @@ void compute_chunk(WorkerItem *item) {
// END TODO
opaque[XYZ(x, y, z)] = !is_transparent(w);
transparent[XYZ(x, y, z)] = is_transparent(w); // dupe needed
visible[XYZ(x, y, z)] = !is_invisible(w); //needs modification to avoid border bugs...
visible[XYZ(x, y, z)] = !is_invisible(w);
if (opaque[XYZ(x, y, z)]) {
highest[XZ(x, z)] = MAX(highest[XZ(x, z)], y);
@ -1811,7 +1816,7 @@ void render_item_count(Attrib *attrib, float ts) {
}
}
void render_ui(Attrib *attrib) {
void render_ui_texture(Attrib *attrib) {
float matrix[16];
glUseProgram(attrib->program);
set_matrix_item(matrix, g->width, g->height, g->scale + 1);
@ -2308,10 +2313,10 @@ void on_key(GLFWwindow *window, int key, int scancode, int action, int mods) {
if (g->typing) {
g->typing = 0;
}
else if (exclusive) {
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
}
if (key == GLFW_KEY_LEFT_ALT) {
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
if (key == GLFW_KEY_ENTER) {
if (g->typing) {
if (mods & GLFW_MOD_SHIFT) {
@ -2501,7 +2506,7 @@ void create_window() {
window_height = modes[mode_count - 1].height;
}
g->window = glfwCreateWindow(
window_width, window_height, "Omicron", monitor, NULL);
window_width, window_height, "Omicron, enjoy.", monitor, NULL);
//g->is_fullscreen = FULLSCREEN;
}
@ -2539,6 +2544,13 @@ void handle_mouse_input() {
}
}
void handle_mouse_input_in_menu() {
static double px = 0;
static double py = 0;
glfwSetInputMode(g->window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
glfwGetCursorPos(g->window, &px, &py);
}
void handle_movement(double dt) {
static float dy = 0;
State *s = &g->players->state;
@ -2647,6 +2659,15 @@ void handle_movement(double dt) {
}
}
void menu_movement(double dt) {
static float dy = 0;
State *s = &g->players->state;
int sz = 0;
int sx = 0;
s->ry += 1;
}
void parse_buffer(char *buffer) {
Player *me = g->players;
State *s = &g->players->state;
@ -2758,10 +2779,10 @@ void update_sky_tint() {
get_sky_tint(biome_at_pos(q, x, z), &new_color);
//Interpolate sky color to get close to the actual value gradually.
// Technically, it won't arrive, but rather achieve an extremely close color.
c->r += 0.0625 * (new_color.r - c->r);
c->g += 0.0625 * (new_color.g - c->g);
c->b += 0.0625 * (new_color.b - c->b);
//Technically, it won't arrive, but rather achieve an extremely close color.
c->r += 0.01 * (new_color.r - c->r);
c->g += 0.01 * (new_color.g - c->g);
c->b += 0.01 * (new_color.b - c->b);
//printf("c: %f last: %f\n", c->r, g->last_sky_color.r);
}
@ -2826,8 +2847,9 @@ int main(int argc, char **argv) {
scanf("> %d", &world);
printf("> Loading selected world.");
*/
printf("> Press RETURN to start");
getchar();
//printf("> Press RETURN to start");
//getchar();
@ -2855,7 +2877,6 @@ int main(int argc, char **argv) {
}
glEnable(GL_DEPTH_TEST);
glAlphaFunc(GL_GREATER, 0.4);
glEnable(GL_ALPHA_TEST);
glEnable(GL_CULL_FACE);
glLogicOp(GL_INVERT);
@ -2870,13 +2891,21 @@ int main(int argc, char **argv) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
load_png_texture("textures/texture.png");
/*GLuint texture_obj;
glGenTextures(1, &texture_obj);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture_obj);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
load_png_texture("textures/texture_obj.png");*/
GLuint font;
glGenTextures(1, &font);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, font);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
load_png_texture("textures/font.png");
GLuint sky;
@ -2896,6 +2925,30 @@ int main(int argc, char **argv) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
load_png_texture("textures/sign.png");
GLuint ui;
glGenTextures(1, &ui);
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, ui);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
load_png_texture("textures/ui.png");
GLuint logo;
glGenTextures(1, &logo);
glActiveTexture(GL_TEXTURE5);
glBindTexture(GL_TEXTURE_2D, logo);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
load_png_texture("textures/logo.png"); //logo.png
GLuint background;
glGenTextures(1, &background);
glActiveTexture(GL_TEXTURE6);
glBindTexture(GL_TEXTURE_2D, background);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
load_png_texture("textures/background.png"); //background.png
// LOAD SHADERS //
Attrib block_attrib = {0};
@ -2903,7 +2956,8 @@ int main(int argc, char **argv) {
Attrib line_attrib = {0};
Attrib text_attrib = {0};
Attrib sky_attrib = {0};
Attrib sun_attrib = {0};
Attrib ui_attrib = {0};
Attrib logo_attrib = {0};
GLuint program;
program = load_program(
@ -2964,16 +3018,27 @@ int main(int argc, char **argv) {
sky_attrib.timer = glGetUniformLocation(program, "timer");
sky_attrib.extra1 = glGetUniformLocation(program, "sky_tint");
/*program = load_program(
"shaders/sun_vertex.glsl", "shaders/sun_fragment.glsl");
sun_attrib.program = program;
sun_attrib.position = glGetAttribLocation(program, "position");
sun_attrib.normal = glGetAttribLocation(program, "normal");
sun_attrib.uv = glGetAttribLocation(program, "uv");
sun_attrib.matrix = glGetUniformLocation(program, "matrix");
sun_attrib.sampler = glGetUniformLocation(program, "sampler");
sun_attrib.timer = glGetUniformLocation(program, "timer");
sun_attrib.extra1 = glGetUniformLocation(program, "sky_tint");*/
program = load_program(
"shaders/ui_vertex.glsl", "shaders/ui_fragment.glsl");
ui_attrib.program = program;
ui_attrib.position = glGetAttribLocation(program, "position");
ui_attrib.normal = glGetAttribLocation(program, "normal");
ui_attrib.uv = glGetAttribLocation(program, "uv");
ui_attrib.matrix = glGetUniformLocation(program, "matrix");
ui_attrib.sampler = glGetUniformLocation(program, "sampler");
ui_attrib.timer = glGetUniformLocation(program, "timer");
ui_attrib.extra1 = glGetUniformLocation(program, "sky_tint");
program = load_program(
"shaders/ui_vertex.glsl", "shaders/ui_fragment.glsl");
logo_attrib.program = program;
logo_attrib.position = glGetAttribLocation(program, "position");
logo_attrib.normal = glGetAttribLocation(program, "normal");
logo_attrib.uv = glGetAttribLocation(program, "uv");
logo_attrib.matrix = glGetUniformLocation(program, "matrix");
logo_attrib.sampler = glGetUniformLocation(program, "sampler");
logo_attrib.timer = glGetUniformLocation(program, "timer");
logo_attrib.extra1 = glGetUniformLocation(program, "sky_tint");
// CHECK COMMAND LINE ARGUMENTS //
if (argc == 2 || argc == 3) {
@ -3051,191 +3116,390 @@ int main(int argc, char **argv) {
// BEGIN MAIN LOOP //
double previous = glfwGetTime();
// ---------- //\
// GAME MODES // \
// ---------- // \
int game_state = 0; // switch: 0 menu (dflt), 1 normal
while (1) {
if (INFINI_STUFF == 1) {
g->inventory.count[items[g->item_index]] = 16;
//printf("%d %d\n", items[g->item_index], (int) g->inventory.count[items[g->item_index]]);
// ----------------- //
// FIRST MODE (MENU) //
// ----------------- // *is wip
if (game_state == 0) {
// WINDOW SIZE AND SCALE //
g->scale = get_scale_factor();
glfwGetFramebufferSize(g->window, &g->width, &g->height);
glViewport(0, 0, g->width, g->height);
double now = glfwGetTime();
double dt = now - previous;
dt = MIN(dt, 0.2);
dt = MAX(dt, 0.0);
previous = now;
// HANDLE MOUSE INPUT //
handle_mouse_input_in_menu();
double cx;
double cy;
glfwGetCursorPos(g->window, &cx, &cy);
int state = glfwGetMouseButton(g->window, GLFW_MOUSE_BUTTON_LEFT);
// TURN AROUND RANDOMLY //
//menu_movement(dt);
// HANDLE DATA FROM SERVER //
char *buffer = client_recv();
if (buffer) {
parse_buffer(buffer);
free(buffer);
}
// FLUSH DATABASE //
if (now - last_commit > COMMIT_INTERVAL) {
last_commit = now;
db_commit();
}
// SEND POSITION TO SERVER //
if (now - last_update > 0.1) {
last_update = now;
client_position(s->x, s->y, s->z, s->rx, s->ry);
}
// CLEAR SCREEN
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// PREPARE TO RENDER //
update_sky_tint();
g->observe1 = g->observe1 % g->player_count;
g->observe2 = g->observe2 % g->player_count;
delete_chunks();
del_buffer(me->buffer);
me->buffer = gen_player_buffer(s->x, s->y, s->z, s->rx, s->ry);
for (int i = 1; i < g->player_count; i++) {
interpolate_player(g->players + i);
}
Player *player = g->players + g->observe1;
// RENDER HUD //
char text_buffer[1024];
float ts = FONT_SIZE * g->scale;
float tx = ts / 2;
float ty = g->height - ts;
// PLAY BUTTON TEXT //
//if (cx > (g->width/2-24*3) && cx < (g->width/2+24*3)) {
//if (cy > (g->height/2-22) && cy < (g->height/2+22)) {
snprintf(text_buffer, 1024, "Play");
render_text(&text_attrib, ALIGN_LEFT, g->width/2-ts*1.5, g->height/2, ts, text_buffer, g->width, g->height);
//}
//}
// MATRIX FOR GUI //
float matrix[16];
set_matrix_2d(matrix, g->width, g->height);
glUseProgram(ui_attrib.program);
glUniformMatrix4fv(ui_attrib.matrix, 1, GL_FALSE, matrix);
glUniform1i(ui_attrib.sampler, 4);
glUniform1i(ui_attrib.extra1, 0);
// PLAY BUTTON //
GLuint button_left_on = gen_ui_buffer(g->width/2 - (24 * g->scale)*2, g->height/2, 24 * g->scale, 10);
GLuint button_middle_on = gen_ui_buffer(g->width/2 , g->height/2, 24 * g->scale, 11);
GLuint button_right_on = gen_ui_buffer(g->width/2 + (24 * g->scale)*2, g->height/2, 24 * g->scale, 12);
GLuint button_left = gen_ui_buffer(g->width/2 - (24 * g->scale)*2, g->height/2, 24 * g->scale, 6);
GLuint button_middle = gen_ui_buffer(g->width/2 , g->height/2, 24 * g->scale, 7);
GLuint button_right = gen_ui_buffer(g->width/2 + (24 * g->scale)*2, g->height/2, 24 * g->scale, 8);
if (cx > (g->width/2-24*3) && cx < (g->width/2+24*3) && cy > (g->height/2-22) && cy < (g->height/2+22)) {
draw_ui(&ui_attrib, button_left_on);
draw_ui(&ui_attrib, button_middle_on);
draw_ui(&ui_attrib, button_right_on);
// CLICK ACTION
if (state == GLFW_PRESS) {
game_state = 1;
glfwSetInputMode(g->window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
}
} else {
draw_ui(&ui_attrib, button_left);
draw_ui(&ui_attrib, button_middle);
draw_ui(&ui_attrib, button_right);
}
del_buffer(button_left);
del_buffer(button_middle);
del_buffer(button_right);
// RENDER LOGO //
//glUniformMatrix4fv(logo_attrib.matrix, 2, GL_TRUE, matrix);
glUniform1i(ui_attrib.sampler, 5);
GLuint logo_buffer = gen_logo_buffer(g->width/2, (g->height/4)*3, 128 * g->scale, 8);
draw_logo(&ui_attrib, logo_buffer);
del_buffer(logo_buffer);
// RENDER TEXT // *optimisation needed for the render of lines. \n maybe?
snprintf(text_buffer, 1024, "Omicron version 0.6 `Menupdate`");
render_text(&text_attrib, ALIGN_LEFT, tx, ty, ts, text_buffer, g->width, g->height);
//ty -= ts * 2;
snprintf(text_buffer, 1024, "Credits:");
render_text(&text_attrib, ALIGN_LEFT, g->width - ts*20, (ts+2)*3, ts, text_buffer, g->width, g->height);
snprintf(text_buffer, 1024, "- Michael Fogleman");
render_text(&text_attrib, ALIGN_LEFT, g->width - ts*20, (ts+2)*2, ts, text_buffer, g->width, g->height);
snprintf(text_buffer, 1024, "- Twetzel");
render_text(&text_attrib, ALIGN_LEFT, g->width - ts*20, (ts+2)*1, ts, text_buffer, g->width, g->height);
//snprintf(text_buffer, 1024, "sample test");
//render_text(&text_attrib, ALIGN_RIGHT, tx, ty, ts, text_buffer, g->width, g->height);
// RENDER BACKGROUND //
glUniform1i(ui_attrib.sampler, 6);
GLuint bg_buffer = gen_logo_buffer(g->width/2, g->height/2, g->width * g->scale, 1);
draw_ui(&ui_attrib, bg_buffer);
del_buffer(bg_buffer);
// SWAP AND POLL //
glfwSwapBuffers(g->window);
glfwPollEvents();
if (glfwWindowShouldClose(g->window)) {
running = 0;
break;
}
if (g->mode_changed) {
g->mode_changed = 0;
break;
}
}
// -------------------- //
// SECOND MODE (NORMAL) //
// -------------------- //
if (game_state == 1) {
if (INFINITE_STUFF == 1) {
g->inventory.count[items[g->item_index]] = 16;
//printf("%d %d\n", items[g->item_index], (int) g->inventory.count[items[g->item_index]]);
}
// WINDOW SIZE AND SCALE //
g->scale = get_scale_factor();
glfwGetFramebufferSize(g->window, &g->width, &g->height);
glViewport(0, 0, g->width, g->height);
// WINDOW SIZE AND SCALE //
g->scale = get_scale_factor();
glfwGetFramebufferSize(g->window, &g->width, &g->height);
glViewport(0, 0, g->width, g->height);
// FRAME RATE //
if (g->time_changed) {
g->time_changed = 0;
last_commit = glfwGetTime();
last_update = glfwGetTime();
memset(&fps, 0, sizeof(fps));
}
update_fps(&fps);
double now = glfwGetTime();
double dt = now - previous;
dt = MIN(dt, 0.2);
dt = MAX(dt, 0.0);
previous = now;
// FRAME RATE //
if (g->time_changed) {
g->time_changed = 0;
last_commit = glfwGetTime();
last_update = glfwGetTime();
memset(&fps, 0, sizeof(fps));
}
update_fps(&fps);
double now = glfwGetTime();
double dt = now - previous;
dt = MIN(dt, 0.2);
dt = MAX(dt, 0.0);
previous = now;
// HANDLE MOUSE INPUT //
handle_mouse_input();
// HANDLE MOVEMENT //
handle_movement(dt);
// HANDLE MOUSE INPUT //
handle_mouse_input();
// HANDLE MOVEMENT //
handle_movement(dt);
// HANDLE DATA FROM SERVER //
char *buffer = client_recv();
if (buffer) {
parse_buffer(buffer);
free(buffer);
}
// HANDLE DATA FROM SERVER //
char *buffer = client_recv();
if (buffer) {
parse_buffer(buffer);
free(buffer);
}
// FLUSH DATABASE //
if (now - last_commit > COMMIT_INTERVAL) {
last_commit = now;
db_commit();
}
// FLUSH DATABASE //
if (now - last_commit > COMMIT_INTERVAL) {
last_commit = now;
db_commit();
}
// SEND POSITION TO SERVER //
if (now - last_update > 0.1) {
last_update = now;
client_position(s->x, s->y, s->z, s->rx, s->ry);
}
// SEND POSITION TO SERVER //
if (now - last_update > 0.1) {
last_update = now;
client_position(s->x, s->y, s->z, s->rx, s->ry);
}
// PREPARE TO RENDER //
update_sky_tint();
g->observe1 = g->observe1 % g->player_count;
g->observe2 = g->observe2 % g->player_count;
delete_chunks();
del_buffer(me->buffer);
me->buffer = gen_player_buffer(s->x, s->y, s->z, s->rx, s->ry);
for (int i = 1; i < g->player_count; i++) {
interpolate_player(g->players + i);
}
Player *player = g->players + g->observe1;
// PREPARE TO RENDER //
update_sky_tint();
g->observe1 = g->observe1 % g->player_count;
g->observe2 = g->observe2 % g->player_count;
delete_chunks();
del_buffer(me->buffer);
me->buffer = gen_player_buffer(s->x, s->y, s->z, s->rx, s->ry);
for (int i = 1; i < g->player_count; i++) {
interpolate_player(g->players + i);
}
Player *player = g->players + g->observe1;
// RENDER 3-D SCENE //
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
render_sky(&sky_attrib, player, sky_buffer);
glClear(GL_DEPTH_BUFFER_BIT);
int face_count = render_chunks(&block_attrib, player);
render_chunks(&tblock_attrib, player);
render_signs(&text_attrib, player);
render_sign(&text_attrib, player);
render_players(&block_attrib, player);
// RENDER 3-D SCENE //
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
render_sky(&sky_attrib, player, sky_buffer);
glClear(GL_DEPTH_BUFFER_BIT);
int face_count = render_chunks(&block_attrib, player);
render_chunks(&tblock_attrib, player);
render_signs(&text_attrib, player);
render_sign(&text_attrib, player);
render_players(&block_attrib, player);
// RENDER HUD //
glClear(GL_DEPTH_BUFFER_BIT);
if (SHOW_CROSSHAIRS) {
render_crosshairs(&line_attrib, g->width, g->height, g->scale);
}
char text_buffer[1024];
float ts = 12 * g->scale;
float tx = ts / 2;
float ty = g->height - ts;
if (SHOW_ITEM) {
render_item(&block_attrib);
render_item(&tblock_attrib);
render_item_count(&text_attrib, ts);
}
// RENDER HUD //
glClear(GL_DEPTH_BUFFER_BIT);
if (SHOW_CROSSHAIRS) {
render_crosshairs(&line_attrib, g->width, g->height, g->scale);
}
char text_buffer[1024];
float ts = FONT_SIZE * g->scale;
float tx = ts / 2;
float ty = g->height - ts;
if (SHOW_ITEM) {
render_item(&block_attrib);
render_item(&tblock_attrib);
render_item_count(&text_attrib, ts);
}
//render_gui_texture(&ui_attrib);
// RENDER TEXT //
if (SHOW_INFO_TEXT) {
int hour = time_of_day() * 24;
char am_pm = hour < 12 ? 'a' : 'p';
hour = hour % 12;
hour = hour ? hour : 12;
snprintf(
text_buffer, 1024,
"(%d, %d) (%.2f, %.2f, %.2f) [%d, %d, %d] %d%cm %dfps",
chunked(s->x), chunked(s->z), s->x, s->y, s->z,
g->player_count, g->chunk_count,
face_count * 2, hour, am_pm, fps.fps);
render_text(&text_attrib, ALIGN_LEFT, tx, ty, ts, text_buffer, g->width, g->height);
ty -= ts * 2;
}
if (SHOW_CHAT_TEXT) {
for (int i = 0; i < MAX_MESSAGES; i++) {
int index = (g->message_index + i) % MAX_MESSAGES;
if (strlen(g->messages[index])) {
render_text(&text_attrib, ALIGN_LEFT, tx, ty, ts,
g->messages[index], g->width, g->height);
ty -= ts * 2;
}
}
}
if (g->typing) {
snprintf(text_buffer, 1024, "> %s", g->typing_buffer);
render_text(&text_attrib, ALIGN_LEFT, tx, ty, ts, text_buffer,
g->width, g->height);
ty -= ts * 2;
}
if (SHOW_PLAYER_NAMES) {
if (player != me) {
render_text(&text_attrib, ALIGN_CENTER,
g->width / 2, ts, ts, player->name,
g->width, g->height);
}
Player *other = player_crosshair(player);
if (other) {
render_text(&text_attrib, ALIGN_CENTER,
g->width / 2, g->height / 2 - ts - 24, ts,
other->name, g->width, g->height);
}
}
// RENDER TEXT //
if (SHOW_INFO_TEXT) {
int hour = time_of_day() * 24;
char am_pm = hour < 12 ? 'a' : 'p';
hour = hour % 12;
hour = hour ? hour : 12;
snprintf(
text_buffer, 1024,
"(%d, %d) (%.2f, %.2f, %.2f) [%d, %d, %d] %d%cm %dfps",
chunked(s->x), chunked(s->z), s->x, s->y, s->z,
g->player_count, g->chunk_count,
face_count * 2, hour, am_pm, fps.fps);
render_text(&text_attrib, ALIGN_LEFT, tx, ty, ts, text_buffer, g->width, g->height);
ty -= ts * 2;
}
if (SHOW_CHAT_TEXT) {
for (int i = 0; i < MAX_MESSAGES; i++) {
int index = (g->message_index + i) % MAX_MESSAGES;
if (strlen(g->messages[index])) {
render_text(&text_attrib, ALIGN_LEFT, tx, ty, ts,
g->messages[index], g->width, g->height);
ty -= ts * 2;
}
}
}
if (g->typing) {
snprintf(text_buffer, 1024, "> %s", g->typing_buffer);
render_text(&text_attrib, ALIGN_LEFT, tx, ty, ts, text_buffer,
g->width, g->height);
ty -= ts * 2;
}
if (SHOW_PLAYER_NAMES) {
if (player != me) {
render_text(&text_attrib, ALIGN_CENTER,
g->width / 2, ts, ts, player->name,
g->width, g->height);
}
Player *other = player_crosshair(player);
if (other) {
render_text(&text_attrib, ALIGN_CENTER,
g->width / 2, g->height / 2 - ts - 24, ts,
other->name, g->width, g->height);
}
}
// RETURN TO MENU WHEN PRESSING ESCAPE
int esc = glfwGetKey(g->window, GLFW_KEY_ESCAPE);
if (esc == GLFW_PRESS) {
game_state = 0;
// Clear screen
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
// RENDER PICTURE IN PICTURE //
if (g->observe2) {
player = g->players + g->observe2;
// RENDER PICTURE IN PICTURE //
if (g->observe2) {
player = g->players + g->observe2;
int pw = 256 * g->scale;
int ph = 256 * g->scale;
int offset = 32 * g->scale;
int pad = 3 * g->scale;
int sw = pw + pad * 2;
int sh = ph + pad * 2;
int pw = 256 * g->scale;
int ph = 256 * g->scale;
int offset = 32 * g->scale;
int pad = 3 * g->scale;
int sw = pw + pad * 2;
int sh = ph + pad * 2;
glEnable(GL_SCISSOR_TEST);
glScissor(g->width - sw - offset + pad, offset - pad, sw, sh);
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_SCISSOR_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
glViewport(g->width - pw - offset, offset, pw, ph);
glEnable(GL_SCISSOR_TEST);
glScissor(g->width - sw - offset + pad, offset - pad, sw, sh);
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_SCISSOR_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
glViewport(g->width - pw - offset, offset, pw, ph);
g->width = pw;
g->height = ph;
g->ortho = 0;
g->fov = 65;
g->width = pw;
g->height = ph;
g->ortho = 0;
g->fov = 65;
render_sky(&sky_attrib, player, sky_buffer);
glClear(GL_DEPTH_BUFFER_BIT);
render_chunks(&block_attrib, player);
render_chunks(&tblock_attrib, player);
render_signs(&text_attrib, player);
render_players(&block_attrib, player);
glClear(GL_DEPTH_BUFFER_BIT);
if (SHOW_PLAYER_NAMES) {
render_text(&text_attrib, ALIGN_CENTER,
pw / 2, ts, ts, player->name,
g->width, g->height);
}
}
render_sky(&sky_attrib, player, sky_buffer);
glClear(GL_DEPTH_BUFFER_BIT);
render_chunks(&block_attrib, player);
render_chunks(&tblock_attrib, player);
render_signs(&text_attrib, player);
render_players(&block_attrib, player);
glClear(GL_DEPTH_BUFFER_BIT);
if (SHOW_PLAYER_NAMES) {
render_text(&text_attrib, ALIGN_CENTER,
pw / 2, ts, ts, player->name,
g->width, g->height);
}
}
// SWAP AND POLL //
glfwSwapBuffers(g->window);
glfwPollEvents();
if (glfwWindowShouldClose(g->window)) {
running = 0;
break;
}
if (g->mode_changed) {
g->mode_changed = 0;
break;
}
// OUTPUT IN TERMINAL //
advance_cursor();
// SWAP AND POLL //
glfwSwapBuffers(g->window);
glfwPollEvents();
if (glfwWindowShouldClose(g->window)) {
running = 0;
break;
}
if (g->mode_changed) {
g->mode_changed = 0;
break;
}
// OUTPUT IN TERMINAL //
//advance_cursor();
}
}
// SHUTDOWN // There's a segfault in this sequence

View File

@ -28,6 +28,28 @@ GLuint gen_text_buffer(float x, float y, float n, char *text) {
return gen_faces(4, length, data);
}
GLuint gen_ui_buffer(float x, float y, float n, char spritesheet_index) {
/** Thanks CraftNG :D **/
GLfloat *data = malloc_faces(4, 1);
//make_character(data, x, y, n, n * 2, spritesheet_index);
make_ui_quad(data, x, y, n, n, spritesheet_index);
return gen_faces(4, 1, data);
}
GLuint gen_logo_buffer(float x, float y, float n, char spritesheet_index) {
GLfloat *data = malloc_faces(4, 1);
//make_character(data, x, y, n, n * 2, spritesheet_index);
make_logo_quad(data, x, y, n, n, spritesheet_index);
return gen_faces(4, 1, data);
}
/*GLuint gen_background_buffer(float x, float y, float n, char spritesheet_index) {
GLfloat *data = malloc_faces(4, 1);
//make_character(data, x, y, n, n * 2, spritesheet_index);
make_logo_quad(data, x, y, n, n, spritesheet_index);
return gen_faces(4, 1, data);
}*/
void draw_triangles_3d_ao(Attrib *attrib, GLuint buffer, int count) {
glEnable(GL_BLEND); //*
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -91,6 +113,8 @@ void draw_triangles_3d(Attrib *attrib, GLuint buffer, int count) {
}
void draw_triangles_2d(Attrib *attrib, GLuint buffer, int count) {
glEnable(GL_BLEND); //*
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glEnableVertexAttribArray(attrib->position);
glEnableVertexAttribArray(attrib->uv);
@ -102,6 +126,7 @@ void draw_triangles_2d(Attrib *attrib, GLuint buffer, int count) {
glDisableVertexAttribArray(attrib->position);
glDisableVertexAttribArray(attrib->uv);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisable(GL_BLEND);
}
void draw_lines(Attrib *attrib, GLuint buffer, int components, int count) {
@ -159,6 +184,24 @@ void draw_player(Attrib *attrib, Player *player) {
draw_cube(attrib, player->buffer);
}
void draw_ui(Attrib *attrib, GLuint buffer) {
glEnable(GL_BLEND); //*
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
draw_triangles_2d(attrib, buffer, 6); //wtf is 6.
glDisable(GL_BLEND);
}
void draw_logo(Attrib *attrib, GLuint buffer) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glUseProgram(attrib->program);
//glUniformMatrix4fv(attrib->matrix, 1, GL_FALSE, matrix);
//glUniform1i(attrib->sampler, 1);
//glUniform1i(attrib->extra1, 0);
draw_triangles_2d(attrib, buffer, 6); //wtf is 6.
glDisable(GL_BLEND);
}
GLuint gen_crosshair_buffer(int width, int height, int scale) {
int x = width / 2;
int y = height / 2;

View File

@ -9,6 +9,9 @@
GLuint gen_plant_buffer(float x, float y, float z, float n, int w);
GLuint gen_player_buffer(float x, float y, float z, float rx, float ry);
GLuint gen_text_buffer(float x, float y, float n, char *text);
GLuint gen_ui_buffer(float x, float y, float n, char spritesheet_index);
GLuint gen_logo_buffer(float x, float y, float n, char spritesheet_index);
//GLuint gen_background_buffer(float x, float y, float n, char spritesheet_index);
void draw_triangles_3d_ao(Attrib *attrib, GLuint buffer, int count);
void draw_triangles_3d_text(Attrib *attrib, GLuint buffer, int count);
void draw_triangles_3d(Attrib *attrib, GLuint buffer, int count);
@ -22,6 +25,8 @@ void draw_sign(Attrib *attrib, GLuint buffer, int length);
void draw_cube(Attrib *attrib, GLuint buffer);
void draw_plant(Attrib *attrib, GLuint buffer);
void draw_player(Attrib *attrib, Player *player);
void draw_ui(Attrib *attrib, GLuint buffer);
void draw_logo(Attrib *attrib, GLuint buffer);
void render_text(Attrib *attrib, int justify, float x, float y, float n, char *text,
int win_width, int win_height);
void render_crosshairs(Attrib *attrib, int width, int height, int scale);

View File

@ -49,6 +49,7 @@ void generateTemperate(int dx, int dz, int x, int z, int start_h, int h, int fla
if (simplex2(-x * 0.1, z * 0.1, 5, 0.8, 2) > 0.66) {
func(x, h, z, Item_MUSHROOM * flag, arg);
}
// trees
if (h > 38) {
int ok = 1;
@ -57,7 +58,8 @@ void generateTemperate(int dx, int dz, int x, int z, int start_h, int h, int fla
{
ok = 0;
}
// small trees
if (ok && simplex2(x, z, 6, 0.5, 2) > 0.71) {
for (int y = h + 3; y < h + 8; y++) {
for (int ox = -3; ox <= 3; ox++) {
@ -74,17 +76,8 @@ void generateTemperate(int dx, int dz, int x, int z, int start_h, int h, int fla
func(x, y, z, 5, arg);
}
}
}
// elder trees
if (h > 38) {
int ok = 1;
if (dx - 4 < 0 || dz - 4 < 0 ||
dx + 4 >= CHUNK_SIZE || dz + 4 >= CHUNK_SIZE)
{
ok = 0;
}
// elder trees
if (ok && simplex2(x, z, 7, 0.6, 2) > 0.82) {
for (int y = h + 4; y < h + 18; y++) {
for (int ox = -4; ox <= 4; ox++) {
@ -97,26 +90,15 @@ void generateTemperate(int dx, int dz, int x, int z, int start_h, int h, int fla
}
}
}
for (int y = h; y < h + 10; y++) {
for (int y = h-1; y < h + 9; y++) {
func(x, y, z, 5, arg);
}
/*for (int tx = x - 2; tx > x + 2; tx++) {
func(tx, h+8, z, 5, arg);
for (int i = 0; i < 5; i++) {
func(x+i-2, h+4, z+i-2, 5, arg);
func(x-i+2, h+4, z+i-2, 5, arg);
}
for (int tz = z - 2; tz > z + 2; tz++) {
func(x, h+8, tz, 5, arg);
}*/
}
}
}
// some wip ugly river don't touch the water is lava
/*
if (simplex2(-x * 0.001, z * 0.001, 4, 0.8, 2) > 0.7) {
//if (h < 38) {
func(x, h, z, 42 * flag, arg);
//}
}
*/
}
}
}

View File

@ -89,7 +89,7 @@ void create_world(int p, int q, world_func func, void *arg) {
// Unbreakable Core shell
func(x, 0, z, Item_CORESHELL * flag, arg);
if (simplex2(
x * 0.4, z * 0.4, 7, 3, 5) > 0.6) {
x * 0.4, z * 0.4, 7, 3, 5) > 0.52) {
func(x, 1, z, Item_CORESHELL * flag, arg);
}

BIN
textures/background.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
textures/font-small.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
textures/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 45 KiB

BIN
textures/texture_obj.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 944 B

BIN
textures/ui.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB