83 lines
1.6 KiB
C
83 lines
1.6 KiB
C
#ifndef APP_H
|
|
#define APP_H
|
|
#include <SDL2/SDL.h>
|
|
#include <SDL2/SDL_image.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <GL/gl.h>
|
|
#include "camera.h"
|
|
#include <time.h>
|
|
|
|
#define SPEED 5
|
|
#define GRAVITY 10
|
|
|
|
#define VIEWPORT_RATIO (16.0 / 9.0)
|
|
#define VIEWPORT_ASPECT 50.0
|
|
|
|
typedef unsigned int uint;
|
|
|
|
#define CHUNK_MAX_X 16
|
|
#define CHUNK_MAX_Y 16
|
|
#define CHUNK_MAX_Z 128
|
|
|
|
typedef enum {
|
|
BLOCKTYPE_AIR,
|
|
BLOCKTYPE_GRASS,
|
|
BLOCKTYPE_DIRT,
|
|
BLOCKTYPE_STONE,
|
|
} Block_type;
|
|
|
|
typedef struct
|
|
{
|
|
Block_type type;
|
|
bool visible;
|
|
} Block;
|
|
|
|
typedef struct {
|
|
vec3f start_pos;
|
|
Block blocks[CHUNK_MAX_X][CHUNK_MAX_Y][CHUNK_MAX_Z];
|
|
GLuint id;
|
|
} Chunk;
|
|
|
|
typedef struct {
|
|
bool is_running;
|
|
SDL_Window *window;
|
|
SDL_GLContext context;
|
|
Camera camera;
|
|
double frame_time;
|
|
SDL_Surface *surface;
|
|
GLuint tid;
|
|
unsigned int chunk_count;
|
|
Chunk *chunks;
|
|
} App;
|
|
|
|
bool chunk_is_block_neighboring_block(Chunk* chunk, vec3i pos);
|
|
void chunk_set_blocks_visibility(Chunk* chunk);
|
|
void chunk_create_displayl(App *app, Chunk *chunk);
|
|
void chunk_render(Chunk* chunk);
|
|
void chunk_update(App *app, Chunk *chunk);
|
|
|
|
int app_get_current_chunk_index(App *app);
|
|
int check_intersection_block(App *app, vec3i *retv, int *chunk_index);
|
|
void app_break_block(App *app);
|
|
|
|
bool is_block(Block b);
|
|
|
|
bool app_check_collision(App *app);
|
|
|
|
void init_app(App *app, uint w, uint h);
|
|
|
|
void init_opengl();
|
|
|
|
void handle_events(App *app);
|
|
|
|
void draw_cube(App *app, float x, float y, float z);
|
|
|
|
void reshape(GLsizei width, GLsizei height);
|
|
|
|
void update_app(App* app);
|
|
|
|
float calc_frame_time(struct timespec *start, struct timespec *end);
|
|
|
|
#endif
|