index error swept away 2h

This commit is contained in:
Alexandre 2025-02-20 14:45:09 +01:00
parent 90e0fd244d
commit 5a2f68c741
27 changed files with 124 additions and 92 deletions

View File

@ -19,6 +19,7 @@
"structure.h": "c", "structure.h": "c",
"limits.h": "c", "limits.h": "c",
"png.h": "c", "png.h": "c",
"stdlib.h": "c" "stdlib.h": "c",
"stb_image.h": "c"
} }
} }

BIN
bin/back

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
res/white.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@ -7,10 +7,8 @@
#include <termios.h> #include <termios.h>
#include <limits.h> #include <limits.h>
#include <time.h> #include <time.h>
#include <libpng/png.h>
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
int ln_baseN(int n, int b) { int ln_baseN(int n, int b) {

View File

@ -7,10 +7,8 @@
#include <termios.h> #include <termios.h>
#include <limits.h> #include <limits.h>
#include <time.h> #include <time.h>
#include <libpng/png.h>
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
#include "move.h" #include "move.h"
#include "entities.h" #include "entities.h"

View File

@ -10,10 +10,8 @@
#include <glad/glad.h> #include <glad/glad.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <cglm/cglm.h> #include <cglm/cglm.h>
#include <libpng/png.h>
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
#include "move.h" #include "move.h"
#include "menus.h" #include "menus.h"
@ -28,13 +26,13 @@ int MAX_SIZE = 8192 ;
int* drawOrder ; int* drawOrder ;
GLint loc_scale; int loc_scale;
GLint loc_model; int loc_model;
GLint loc_view; int loc_view;
GLint loc_proj; int loc_proj;
GLint loc_frag; int loc_frag;
GLint loc_tex; int loc_tex;
void init_draworder() { void init_draworder() {
drawOrder = malloc(sizeof(int)*6) ; drawOrder = malloc(sizeof(int)*6) ;
@ -85,47 +83,47 @@ float vertices[180];
// -x ; +x ; -y ; +y ; -z ; +z // // -x ; +x ; -y ; +y ; -z ; +z //
void init_vertices() { void init_vertices() {
vertices[0] = -0.5f; vertices[1] = -0.5f; vertices[2] = -0.5f; vertices[3] = 0.0; vertices[4] = 0.0; vertices[0] = -0.5f; vertices[1] = -0.5f; vertices[2] = -0.5f; vertices[3] = 0.0; vertices[4] = 1.0;
vertices[5] = -0.5f; vertices[6] = 0.5f; vertices[7] = -0.5f; vertices[8] = 0.0; vertices[9] = 1.0; vertices[5] = -0.5f; vertices[6] = 0.5f; vertices[7] = -0.5f; vertices[8] = 0.0; vertices[9] = 0.0;
vertices[10] = -0.5f; vertices[11] = 0.5f; vertices[12] = 0.5f; vertices[13] = 1.0; vertices[14] = 1.0; vertices[10] = -0.5f; vertices[11] = 0.5f; vertices[12] = 0.5f; vertices[13] = 1.0; vertices[14] = 0.0;
vertices[15] = -0.5f; vertices[16] = -0.5f; vertices[17] = -0.5f; vertices[18] = 0.0; vertices[19] = 0.0; vertices[15] = -0.5f; vertices[16] = -0.5f; vertices[17] = -0.5f; vertices[18] = 0.0; vertices[19] = 1.0;
vertices[20] = -0.5f; vertices[21] = 0.5f; vertices[22] = 0.5f; vertices[23] = 1.0; vertices[24] = 0.0; vertices[20] = -0.5f; vertices[21] = 0.5f; vertices[22] = 0.5f; vertices[23] = 1.0; vertices[24] = 0.0;
vertices[25] = -0.5f; vertices[26] = -0.5f; vertices[27] = 0.5f; vertices[28] = 1.0; vertices[29] = 1.0; vertices[25] = -0.5f; vertices[26] = -0.5f; vertices[27] = 0.5f; vertices[28] = 1.0; vertices[29] = 1.0;
vertices[30] = 0.5f; vertices[31] = -0.5f; vertices[32] = -0.5f; vertices[33] = 0.0; vertices[34] = 0.0; vertices[30] = 0.5f; vertices[31] = -0.5f; vertices[32] = -0.5f; vertices[33] = 1.0; vertices[34] = 1.0;
vertices[35] = 0.5f; vertices[36] = 0.5f; vertices[37] = 0.5f; vertices[38] = 0.0; vertices[39] = 1.0; vertices[35] = 0.5f; vertices[36] = 0.5f; vertices[37] = 0.5f; vertices[38] = 0.0; vertices[39] = 0.0;
vertices[40] = 0.5f; vertices[41] = 0.5f; vertices[42] = -0.5f; vertices[43] = 1.0; vertices[44] = 1.0; vertices[40] = 0.5f; vertices[41] = 0.5f; vertices[42] = -0.5f; vertices[43] = 1.0; vertices[44] = 0.0;
vertices[45] = 0.5f; vertices[46] = -0.5f; vertices[47] = -0.5f; vertices[48] = 0.0; vertices[49] = 0.0; vertices[45] = 0.5f; vertices[46] = -0.5f; vertices[47] = -0.5f; vertices[48] = 1.0; vertices[49] = 1.0;
vertices[50] = 0.5f; vertices[51] = -0.5f; vertices[52] = 0.5f; vertices[53] = 1.0; vertices[54] = 0.0; vertices[50] = 0.5f; vertices[51] = -0.5f; vertices[52] = 0.5f; vertices[53] = 0.0; vertices[54] = 1.0;
vertices[55] = 0.5f; vertices[56] = 0.5f; vertices[57] = 0.5f; vertices[58] = 1.0; vertices[59] = 1.0; vertices[55] = 0.5f; vertices[56] = 0.5f; vertices[57] = 0.5f; vertices[58] = 0.0; vertices[59] = 0.0;
vertices[60] = -0.5f; vertices[61] = -0.5f; vertices[62] = -0.5f; vertices[63] = 0.0; vertices[64] = 0.0; vertices[60] = -0.5f; vertices[61] = -0.5f; vertices[62] = -0.5f; vertices[63] = 0.0; vertices[64] = 1.0;
vertices[65] = 0.5f; vertices[66] = -0.5f; vertices[67] = 0.5f; vertices[68] = 0.0; vertices[69] = 1.0; vertices[65] = 0.5f; vertices[66] = -0.5f; vertices[67] = 0.5f; vertices[68] = 1.0; vertices[69] = 0.0;
vertices[70] = 0.5f; vertices[71] = -0.5f; vertices[72] = -0.5f; vertices[73] = 1.0; vertices[74] = 1.0; vertices[70] = 0.5f; vertices[71] = -0.5f; vertices[72] = -0.5f; vertices[73] = 0.0; vertices[74] = 0.0;
vertices[75] = -0.5f; vertices[76] = -0.5f; vertices[77] = -0.5f; vertices[78] = 0.0; vertices[79] = 0.0; vertices[75] = -0.5f; vertices[76] = -0.5f; vertices[77] = -0.5f; vertices[78] = 0.0; vertices[79] = 1.0;
vertices[80] = -0.5f; vertices[81] = -0.5f; vertices[82] = 0.5f; vertices[83] = 1.0; vertices[84] = 0.0; vertices[80] = -0.5f; vertices[81] = -0.5f; vertices[82] = 0.5f; vertices[83] = 1.0; vertices[84] = 1.0;
vertices[85] = 0.5f; vertices[86] = -0.5f; vertices[87] = 0.5f; vertices[88] = 1.0; vertices[89] = 1.0; vertices[85] = 0.5f; vertices[86] = -0.5f; vertices[87] = 0.5f; vertices[88] = 1.0; vertices[89] = 0.0;
vertices[90] = -0.5f; vertices[91] = 0.5f; vertices[92] = -0.5f; vertices[93] = 0.0; vertices[94] = 0.0; vertices[90] = -0.5f; vertices[91] = 0.5f; vertices[92] = -0.5f; vertices[93] = 1.0; vertices[94] = 1.0;
vertices[95] = 0.5f; vertices[96] = 0.5f; vertices[97] = -0.5f; vertices[98] = 0.0; vertices[99] = 1.0; vertices[95] = 0.5f; vertices[96] = 0.5f; vertices[97] = -0.5f; vertices[98] = 1.0; vertices[99] = 0.0;
vertices[100] = 0.5f; vertices[101] = 0.5f; vertices[102] = 0.5f; vertices[103] = 1.0; vertices[104] = 1.0; vertices[100] = 0.5f; vertices[101] = 0.5f; vertices[102] = 0.5f; vertices[103] = 0.0; vertices[104] = 0.0;
vertices[105] = -0.5f; vertices[106] = 0.5f; vertices[107] = -0.5f; vertices[108] = 0.0; vertices[109] = 0.0; vertices[105] = -0.5f; vertices[106] = 0.5f; vertices[107] = -0.5f; vertices[108] = 1.0; vertices[109] = 1.0;
vertices[110] = 0.5f; vertices[111] = 0.5f; vertices[112] = 0.5f; vertices[113] = 1.0; vertices[114] = 0.0; vertices[110] = 0.5f; vertices[111] = 0.5f; vertices[112] = 0.5f; vertices[113] = 0.0; vertices[114] = 0.0;
vertices[115] = -0.5f; vertices[116] = 0.5f; vertices[117] = 0.5f; vertices[118] = 1.0; vertices[119] = 1.0; vertices[115] = -0.5f; vertices[116] = 0.5f; vertices[117] = 0.5f; vertices[118] = 0.0; vertices[119] = 1.0;
vertices[120] = -0.5f; vertices[121] = -0.5f; vertices[122] = -0.5f; vertices[123] = 0.0; vertices[124] = 0.0; vertices[120] = -0.5f; vertices[121] = -0.5f; vertices[122] = -0.5f; vertices[123] = 1.0; vertices[124] = 1.0;
vertices[125] = 0.5f; vertices[126] = -0.5f; vertices[127] = -0.5f; vertices[128] = 0.0; vertices[129] = 1.0; vertices[125] = 0.5f; vertices[126] = -0.5f; vertices[127] = -0.5f; vertices[128] = 0.0; vertices[129] = 1.0;
vertices[130] = 0.5f; vertices[131] = 0.5f; vertices[132] = -0.5f; vertices[133] = 1.0; vertices[134] = 1.0; vertices[130] = 0.5f; vertices[131] = 0.5f; vertices[132] = -0.5f; vertices[133] = 0.0; vertices[134] = 0.0;
vertices[135] = -0.5f; vertices[136] = -0.5f; vertices[137] = -0.5f; vertices[138] = 0.0; vertices[139] = 0.0; vertices[135] = -0.5f; vertices[136] = -0.5f; vertices[137] = -0.5f; vertices[138] = 1.0; vertices[139] = 1.0;
vertices[140] = 0.5f; vertices[141] = 0.5f; vertices[142] = -0.5f; vertices[143] = 1.0; vertices[144] = 0.0; vertices[140] = 0.5f; vertices[141] = 0.5f; vertices[142] = -0.5f; vertices[143] = 0.0; vertices[144] = 0.0;
vertices[145] = -0.5f; vertices[146] = 0.5f; vertices[147] = -0.5f; vertices[148] = 1.0; vertices[149] = 1.0; vertices[145] = -0.5f; vertices[146] = 0.5f; vertices[147] = -0.5f; vertices[148] = 1.0; vertices[149] = 0.0;
vertices[150] = -0.5f; vertices[151] = -0.5f; vertices[152] = 0.5f; vertices[153] = 0.0; vertices[154] = 0.0; vertices[150] = -0.5f; vertices[151] = -0.5f; vertices[152] = 0.5f; vertices[153] = 0.0; vertices[154] = 1.0;
vertices[155] = 0.5f; vertices[156] = 0.5f; vertices[157] = 0.5f; vertices[158] = 0.0; vertices[159] = 1.0; vertices[155] = 0.5f; vertices[156] = 0.5f; vertices[157] = 0.5f; vertices[158] = 1.0; vertices[159] = 0.0;
vertices[160] = 0.5f; vertices[161] = -0.5f; vertices[162] = 0.5f; vertices[163] = 1.0; vertices[164] = 1.0; vertices[160] = 0.5f; vertices[161] = -0.5f; vertices[162] = 0.5f; vertices[163] = 1.0; vertices[164] = 1.0;
vertices[165] = -0.5f; vertices[166] = -0.5f; vertices[167] = 0.5f; vertices[168] = 0.0; vertices[169] = 0.0; vertices[165] = -0.5f; vertices[166] = -0.5f; vertices[167] = 0.5f; vertices[168] = 0.0; vertices[169] = 1.0;
vertices[170] = -0.5f; vertices[171] = 0.5f; vertices[172] = 0.5f; vertices[173] = 1.0; vertices[174] = 0.0; vertices[170] = -0.5f; vertices[171] = 0.5f; vertices[172] = 0.5f; vertices[173] = 0.0; vertices[174] = 0.0;
vertices[175] = 0.5f; vertices[176] = 0.5f; vertices[177] = 0.5f; vertices[178] = 1.0; vertices[179] = 1.0; vertices[175] = 0.5f; vertices[176] = 0.5f; vertices[177] = 0.5f; vertices[178] = 1.0; vertices[179] = 0.0;
} }
void gl_renderCube(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, cube_0* c, double offx, double offy, double offz) { void gl_renderCube(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, cube_0* c, double offx, double offy, double offz) {
@ -165,6 +163,8 @@ bool is_visible(cube_0* cb, double offx, double offy, double offz) {
void gl_renderAll(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, room* rtd, double offx, double offy, double offz) { void gl_renderAll(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, room* rtd, double offx, double offy, double offz) {
if(rtd != NULL) { if(rtd != NULL) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures[0]);
for(int k = 0; k < rtd->map_size; k++) { for(int k = 0; k < rtd->map_size; k++) {
if(is_visible(rtd->map[k], offx, offy, offz)) { if(is_visible(rtd->map[k], offx, offy, offz)) {
gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->map[k], offx, offy, offz); gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->map[k], offx, offy, offz);
@ -177,6 +177,8 @@ void gl_renderAll(unsigned int shaderProgram, unsigned int fragmentShader, unsig
} }
for(int k = 0; k < rtd->ent_len; k++) { for(int k = 0; k < rtd->ent_len; k++) {
if(is_visible(rtd->ents[k]->pos, offx, offy, offz)) { if(is_visible(rtd->ents[k]->pos, offx, offy, offz)) {
//printf("%d\n", rtd->ents[k]->tex);
glBindTexture(GL_TEXTURE_2D, textures[rtd->ents[k]->tex]);
gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->ents[k]->pos, offx, offy, offz); gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->ents[k]->pos, offx, offy, offz);
} }
} }

View File

@ -7,12 +7,14 @@
#include <termios.h> #include <termios.h>
#include <limits.h> #include <limits.h>
#include <time.h> #include <time.h>
#include <libpng/png.h> #include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <cglm/cglm.h>
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
#include "display.h" #include "display.h"
#include "menus.h"
#include "proj.h" #include "proj.h"
#include "entities.h" #include "entities.h"

View File

@ -8,10 +8,8 @@
#include <limits.h> #include <limits.h>
#include <time.h> #include <time.h>
#include <string.h> #include <string.h>
#include <libpng/png.h>
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
#include "entities.h" #include "entities.h"
#include "generation.h" #include "generation.h"
@ -43,48 +41,56 @@ void init_ent_generator(int n) {
} }
hashtbl_entities[0].id = 0; hashtbl_entities[0].id = 0;
hashtbl_entities[0].tex = 0;
hashtbl_entities[0].name = "Coin"; // 0 = default hashtbl_entities[0].name = "Coin"; // 0 = default
hashtbl_entities[0].updatePos = &speen; hashtbl_entities[0].updatePos = &speen;
hashtbl_entities[0].onHit = &money; hashtbl_entities[0].onHit = &money;
hashtbl_entities[0].onDeath = NULL; hashtbl_entities[0].onDeath = NULL;
hashtbl_entities[1].id = 1; hashtbl_entities[1].id = 1;
hashtbl_entities[1].tex = 0;
hashtbl_entities[1].name = "ExplosiveStill"; hashtbl_entities[1].name = "ExplosiveStill";
hashtbl_entities[1].updatePos = &speen2; hashtbl_entities[1].updatePos = &speen2;
hashtbl_entities[1].onHit = &explodeOnHit; hashtbl_entities[1].onHit = &explodeOnHit;
hashtbl_entities[1].onDeath = NULL; hashtbl_entities[1].onDeath = NULL;
hashtbl_entities[2].id = 2; hashtbl_entities[2].id = 2;
hashtbl_entities[2].tex = 0;
hashtbl_entities[2].name = "ExplosiveSeek"; hashtbl_entities[2].name = "ExplosiveSeek";
hashtbl_entities[2].updatePos = &go_to_player; hashtbl_entities[2].updatePos = &go_to_player;
hashtbl_entities[2].onHit = &explodeOnHit; hashtbl_entities[2].onHit = &explodeOnHit;
hashtbl_entities[2].onDeath = NULL; hashtbl_entities[2].onDeath = NULL;
hashtbl_entities[3].id = 3; hashtbl_entities[3].id = 3;
hashtbl_entities[3].tex = 0;
hashtbl_entities[3].name = "ExplosiveShoot"; hashtbl_entities[3].name = "ExplosiveShoot";
hashtbl_entities[3].updatePos = &speen3; hashtbl_entities[3].updatePos = &speen3;
hashtbl_entities[3].onHit = &explodeOnHit; hashtbl_entities[3].onHit = &explodeOnHit;
hashtbl_entities[3].onDeath = NULL; hashtbl_entities[3].onDeath = NULL;
hashtbl_entities[4].id = 4; hashtbl_entities[4].id = 4;
hashtbl_entities[4].tex = 0;
hashtbl_entities[4].name = "SinePlatform"; hashtbl_entities[4].name = "SinePlatform";
hashtbl_entities[4].updatePos = &moving_xyz; hashtbl_entities[4].updatePos = &moving_xyz;
hashtbl_entities[4].onHit = &translatePlayer; hashtbl_entities[4].onHit = &translatePlayer;
hashtbl_entities[4].onDeath = NULL; hashtbl_entities[4].onDeath = NULL;
hashtbl_entities[5].id = 5; hashtbl_entities[5].id = 5;
hashtbl_entities[5].tex = 0;
hashtbl_entities[5].name = "LinePlatform"; hashtbl_entities[5].name = "LinePlatform";
hashtbl_entities[5].updatePos = &moving_xyz_line; hashtbl_entities[5].updatePos = &moving_xyz_line;
hashtbl_entities[5].onHit = &translatePlayerLine; hashtbl_entities[5].onHit = &translatePlayerLine;
hashtbl_entities[5].onDeath = NULL; hashtbl_entities[5].onDeath = NULL;
hashtbl_entities[6].id = 6; hashtbl_entities[6].id = 6;
hashtbl_entities[6].tex = 1;
hashtbl_entities[6].name = "TextBox"; hashtbl_entities[6].name = "TextBox";
hashtbl_entities[6].updatePos = NULL; hashtbl_entities[6].updatePos = NULL;
hashtbl_entities[6].onHit = &pop_text; hashtbl_entities[6].onHit = &pop_text;
hashtbl_entities[6].onDeath = NULL; hashtbl_entities[6].onDeath = NULL;
hashtbl_entities[7].id = 7; hashtbl_entities[7].id = 7;
hashtbl_entities[7].tex = 0;
hashtbl_entities[7].name = "WarpBox"; hashtbl_entities[7].name = "WarpBox";
hashtbl_entities[7].updatePos = NULL; hashtbl_entities[7].updatePos = NULL;
hashtbl_entities[7].onHit = &pop_and_tp; hashtbl_entities[7].onHit = &pop_and_tp;
@ -133,6 +139,8 @@ void copy_room(room* src, room* dest, int chx, int chy) {
for(int k = 0; k < src->ent_len; k++) { for(int k = 0; k < src->ent_len; k++) {
dest->ents[k] = malloc(sizeof(entity)); dest->ents[k] = malloc(sizeof(entity));
dest->ents[k]->damage = src->ents[k]->damage; dest->ents[k]->damage = src->ents[k]->damage;
dest->ents[k]->tex = src->ents[k]->tex;
//printf("!! %d !!\n", dest->ents [k]->tex);
dest->ents[k]->hitpoints = malloc(sizeof(int)); dest->ents[k]->hitpoints = malloc(sizeof(int));
dest->ents[k]->metai1 = src->ents[k]->metai1; dest->ents[k]->metai1 = src->ents[k]->metai1;
dest->ents[k]->metai2 = src->ents[k]->metai2; dest->ents[k]->metai2 = src->ents[k]->metai2;
@ -201,6 +209,7 @@ void build_starting_chunk(int chx, int chy) {
for(int k = 0; k < 32; k++) { for(int k = 0; k < 32; k++) {
new->ents[k] = malloc(sizeof(entity)); new->ents[k] = malloc(sizeof(entity));
new->ents[k]->hitpoints = malloc(sizeof(int)); new->ents[k]->hitpoints = malloc(sizeof(int));
new->ents[k]->tex = 0;
new->ents[k]->pos = malloc(sizeof(cube_0)); new->ents[k]->pos = malloc(sizeof(cube_0));
}; };
new->ent_len = 1; new->ent_len = 1;
@ -348,6 +357,7 @@ void parse_one_room(int id, char* filename) {
pool[id].area->ents[k] = malloc(sizeof(entity)); pool[id].area->ents[k] = malloc(sizeof(entity));
pool[id].area->ents[k]->hitpoints = malloc(sizeof(int)); pool[id].area->ents[k]->hitpoints = malloc(sizeof(int));
pool[id].area->ents[k]->pos = malloc(sizeof(cube_0)); pool[id].area->ents[k]->pos = malloc(sizeof(cube_0));
pool[id].area->ents[k]->tex = 0;
} }
pool[id].area->ent_len = nent; pool[id].area->ent_len = nent;
pool[id].area->ent_memlen = nmemlen; pool[id].area->ent_memlen = nmemlen;
@ -417,8 +427,10 @@ void parse_one_room(int id, char* filename) {
if(entry == NULL) { if(entry == NULL) {
entry = get_entry(0); entry = get_entry(0);
} }
//printf(">>><>>>>><> %d\n", entry->tex);
fill_cube_0(pool[id].area->ents[k]->pos, cx, cy, cz, cw, ch, cd, chz, cvt, red, green, blue); fill_cube_0(pool[id].area->ents[k]->pos, cx, cy, cz, cw, ch, cd, chz, cvt, red, green, blue);
pool[id].area->ents[k]->damage = dmg; pool[id].area->ents[k]->damage = dmg;
pool[id].area->ents[k]->tex = entry->tex;
*(pool[id].area->ents[k]->hitpoints) = hp; *(pool[id].area->ents[k]->hitpoints) = hp;
pool[id].area->ents[k]->updatePos = entry->updatePos; pool[id].area->ents[k]->updatePos = entry->updatePos;
pool[id].area->ents[k]->onHit = entry->onHit ; pool[id].area->ents[k]->onHit = entry->onHit ;
@ -636,14 +648,17 @@ void generate_nearby_chunks(int render_dist) {
void free_pool() { void free_pool() {
for(int k0 = 0; k0 < pool_size; k0++) { for(int k0 = 0; k0 < pool_size; k0++) {
printf("%d/%d\n", 1+k0, pool_size); printf("%d/%d\n", 1+k0, pool_size); fflush(stdout);
for(int k = 0; k < pool[k0].area->map_size; k++) { for(int k = 0; k < pool[k0].area->map_size; k++) {
printf("%d-%d\n", k, pool[k0].area->map_size);
free(pool[k0].area->map[k]); free(pool[k0].area->map[k]);
} }
printf("...\n"); fflush(stdout);
for(int k = 0; k < pool[k0].area->tps_size; k++) { for(int k = 0; k < pool[k0].area->tps_size; k++) {
free(pool[k0].area->tps[k]->hitbox); free(pool[k0].area->tps[k]->hitbox);
free(pool[k0].area->tps[k]); free(pool[k0].area->tps[k]);
} }
printf("...\n"); fflush(stdout);
for(int k = 0; k < pool[k0].area->ent_memlen; k++) { for(int k = 0; k < pool[k0].area->ent_memlen; k++) {
if(pool[k0].area->ents[k]->metai3 == -727) { // 6 and 7 // if(pool[k0].area->ents[k]->metai3 == -727) { // 6 and 7 //
//free(pool[k0].area->ents[k]->metach1); //free(pool[k0].area->ents[k]->metach1);
@ -656,6 +671,7 @@ void free_pool() {
free(pool[k0].area->ents[k]->pos); free(pool[k0].area->ents[k]->pos);
free(pool[k0].area->ents[k]); free(pool[k0].area->ents[k]);
} }
printf("...\n"); fflush(stdout);
free(pool[k0].area->ents); free(pool[k0].area->ents);
free(pool[k0].area->tps); free(pool[k0].area->tps);
free(pool[k0].area->map); free(pool[k0].area->map);

View File

@ -33,6 +33,8 @@ typedef struct fct_entry {
double metad9; double metad9;
char* metach1; char* metach1;
char* metach2; char* metach2;
int tex;
} fct_entry ; } fct_entry ;
extern int build_text_box(char* msg, int red, int green, int blue); extern int build_text_box(char* msg, int red, int green, int blue);

View File

@ -7,9 +7,7 @@
#include <termios.h> #include <termios.h>
#include <limits.h> #include <limits.h>
#include <time.h> #include <time.h>
#include <libpng/png.h>
#include "structure.h"
#include "hash.h" #include "hash.h"
// ------------------------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------------------------- //

View File

@ -4,6 +4,7 @@
#ifndef HASH_H #ifndef HASH_H
#define HASH_H #define HASH_H
#include "structure.h" #include "structure.h"
#include <stdbool.h> #include <stdbool.h>

View File

@ -9,13 +9,13 @@
#include <time.h> #include <time.h>
#include <glad/glad.h> #include <glad/glad.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <libpng/png.h>
#ifndef STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h" #include "stb_image.h"
#endif
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
#include "move.h" #include "move.h"
#include "menus.h" #include "menus.h"
@ -37,6 +37,8 @@ double jPress = false;
double gPress = false; double gPress = false;
double rPress = false; double rPress = false;
unsigned int textures[16];
void reset_everything(GLFWwindow *window, int count, char* folder) { void reset_everything(GLFWwindow *window, int count, char* folder) {
/*hashtbl_free(visited); /*hashtbl_free(visited);
free_proj(); free_proj();
@ -109,6 +111,8 @@ void reset_everything(GLFWwindow *window, int count, char* folder) {
interface_set(-1); interface_set(-1);
generate_nearby_chunks(1); generate_nearby_chunks(1);
printf("-------------------------------- Done 5 --------------------------------\n");
} }
void processInput(GLFWwindow *window, float dtime) { void processInput(GLFWwindow *window, float dtime) {
@ -252,7 +256,7 @@ void processInput(GLFWwindow *window, float dtime) {
//printf("-----\n"); //printf("-----\n");
switchRoom = false; switchRoom = false;
reset_everything(window, newRoomCount, newRoomName); reset_everything(window, newRoomCount, newRoomName);
free(newRoomName); //free(newRoomName);
} }
} }
@ -277,7 +281,7 @@ const char *fragmentShaderSource = "#version 330 core\n"
"uniform sampler2D tex0;\n" "uniform sampler2D tex0;\n"
"void main() {\n" "void main() {\n"
// " FragColor = u_color;\n" // " FragColor = u_color;\n"
" FragColor = texture(tex0, texCoord);\n" " FragColor = texture(tex0, texCoord) * u_color;\n"
"}\0"; "}\0";
const char *vertexShaderSourceR = "#version 330 core\n" const char *vertexShaderSourceR = "#version 330 core\n"
@ -295,6 +299,34 @@ const char *fragmentShaderSourceR = "#version 330 core\n"
" FragColor = u_color2;\n" " FragColor = u_color2;\n"
"}\0"; "}\0";
typedef enum file_extension {PNG, JPG, JPEG} file_extension;
void generate_texture(int id, char* filename, file_extension ext) {
int widthImg, heightImg, numColCh;
//unsigned char* bytes = stbi_load("res/container.jpg", &widthImg, &heightImg, &numColCh, 0);
unsigned char* bytes = stbi_load(filename, &widthImg, &heightImg, &numColCh, 0);
if(bytes == 0) {fprintf(stderr, "ERROR : cannot load texture\n"); exit(1);}
glGenTextures(1, &textures[id]);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures[id]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if(ext == JPG || ext == JPEG) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, widthImg, heightImg, 0, GL_RGB, GL_UNSIGNED_BYTE, bytes);
glGenerateMipmap(GL_TEXTURE_2D);
} else if(ext == PNG) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, widthImg, heightImg, 0, GL_RGBA, GL_UNSIGNED_BYTE, bytes);
glGenerateMipmap(GL_TEXTURE_2D);
}
stbi_image_free(bytes);
glBindTexture(GL_TEXTURE_2D, 0);
}
int main_alt() { int main_alt() {
// glfw: initialize and configure // glfw: initialize and configure
// ------------------------------ // ------------------------------
@ -398,29 +430,13 @@ int main_alt() {
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3*sizeof(float))); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3*sizeof(float)));
glEnableVertexAttribArray(1); glEnableVertexAttribArray(1);
printf("-------------------------------------------------------\n"); fflush(stdout); printf("-----------------------------------------------------------------------------------------------\n"); fflush(stdout);
int widthImg, heightImg, numColCh; //generate_texture(0, "res/container.jpg", "jpg");
unsigned char* bytes = stbi_load("res/container.jpg", &widthImg, &heightImg, &numColCh, 0); generate_texture(0, "res/white.png", PNG);
if(bytes == 0) {fprintf(stderr, "ERROR : cannot load texture\n"); exit(1);} generate_texture(1, "res/question_block.png", PNG);
GLuint texture;
glGenTextures(1, &texture);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); printf("-----------------------------------------------------------------------------------------------\n"); fflush(stdout);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, widthImg, heightImg, 0, GL_RGB, GL_UNSIGNED_BYTE, bytes);
glGenerateMipmap(GL_TEXTURE_2D);
stbi_image_free(bytes);
glBindTexture(GL_TEXTURE_2D, 0);
printf("------------------------------------------------------- %d %d\n", widthImg, heightImg); fflush(stdout);
// ---------------------------------------------------------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------------------------------------------------------- //
// ---------------------------------------------------------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------------------------------------------------------- //
@ -517,7 +533,6 @@ int main_alt() {
glUseProgram(shaderProgram); glUseProgram(shaderProgram);
// draw the map // draw the map
glBindTexture(GL_TEXTURE_2D, texture);
glBindVertexArray(VAO); glBindVertexArray(VAO);
gl_initRender(shaderProgram, shaderProgram, VAO, VBO); gl_initRender(shaderProgram, shaderProgram, VAO, VBO);
@ -573,7 +588,8 @@ int main_alt() {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
glDeleteVertexArrays(1, &VAO); glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO); glDeleteBuffers(1, &VBO);
glDeleteTextures(1, &texture); glDeleteTextures(1, &textures[0]);
glDeleteTextures(1, &textures[1]);
glDeleteProgram(shaderProgram); glDeleteProgram(shaderProgram);
// glfw: terminate, clearing all previously allocated GLFW resources. // glfw: terminate, clearing all previously allocated GLFW resources.

View File

@ -12,10 +12,8 @@
#include "../include/glad/glad.h" #include "../include/glad/glad.h"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <cglm/cglm.h> #include <cglm/cglm.h>
#include <libpng/png.h>
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
#include "entities.h" #include "entities.h"
#include "menus.h" #include "menus.h"

View File

@ -7,10 +7,8 @@
#include <termios.h> #include <termios.h>
#include <limits.h> #include <limits.h>
#include <time.h> #include <time.h>
#include <libpng/png.h>
#include "hash.h" #include "hash.h"
#include "structure.h"
#include "base.h" #include "base.h"
#include "entities.h" #include "entities.h"
#include "proj.h" #include "proj.h"

View File

@ -7,9 +7,7 @@
#include <termios.h> #include <termios.h>
#include <limits.h> #include <limits.h>
#include <time.h> #include <time.h>
#include <libpng/png.h>
#include "structure.h"
#include "hash.h" #include "hash.h"
#include "base.h" #include "base.h"
#include "move.h" #include "move.h"

View File

@ -59,6 +59,8 @@ typedef struct entity {
char* metach1; char* metach1;
char* metach2; char* metach2;
int tex;
int damage; int damage;
int* hitpoints; int* hitpoints;
} entity; } entity;
@ -170,12 +172,14 @@ extern char* newRoomName;
extern int newRoomCount; extern int newRoomCount;
extern bool switchRoom; extern bool switchRoom;
extern GLint loc_scale; extern int loc_scale;
extern GLint loc_model; extern int loc_model;
extern GLint loc_view; extern int loc_view;
extern GLint loc_proj; extern int loc_proj;
extern GLint loc_frag; extern int loc_frag;
extern GLint loc_tex; extern int loc_tex;
extern unsigned int textures[16];
#endif #endif

View File

@ -11,7 +11,7 @@ Teleporters :
[-5.0, 1.0, 9.0, 10.0, 2.0, 1.0, 0.0, 0.0, 0, 0, 255; 0, 1] [-5.0, 1.0, 9.0, 10.0, 2.0, 1.0, 0.0, 0.0, 0, 0, 255; 0, 1]
Entities : Entities :
[-1.0, 1.0, -1.0, 2.0, 2.0, 2.0, 0.0, 0.0, 0, 0, 0, 1, 0, 6, hey look a text box, 200, 200, 200] [-1.0, 1.0, -1.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 6, hey look a text box, 200, 200, 200]
Weight : Weight :
50 50