preparing to add inventories
This commit is contained in:
parent
b18b1dc5ed
commit
34d70154e0
3
Makefile
3
Makefile
|
@ -10,7 +10,7 @@ test: bin/back
|
|||
mem: bin/back
|
||||
valgrind --leak-check=full ./bin/back
|
||||
|
||||
bin/back: obj/main.o obj/generation.o obj/display.o obj/proj.o obj/entities.o obj/bullets.o obj/menus.o obj/music.o obj/maeth.o obj/move.o obj/base.o obj/hash.o
|
||||
bin/back: obj/main.o obj/generation.o obj/display.o obj/proj.o obj/entities.o obj/bullets.o obj/menus.o obj/inventory.o obj/music.o obj/maeth.o obj/move.o obj/base.o obj/hash.o
|
||||
mkdir -p bin
|
||||
$(CC) $(FLAGS) $^ $(LFLAGS) -o $@
|
||||
|
||||
|
@ -26,6 +26,7 @@ obj/bullets.o: src/bullets.c
|
|||
obj/move.o: src/move.c
|
||||
obj/base.o: src/base.c
|
||||
obj/proj.o: src/proj.c
|
||||
obj/inventory.o: src/inventory.c
|
||||
obj/music.o: src/music.c
|
||||
obj/maeth.o: src/maeth.c
|
||||
obj/menus.o: src/menus.c
|
||||
|
|
BIN
obj/display.o
BIN
obj/display.o
Binary file not shown.
BIN
obj/entities.o
BIN
obj/entities.o
Binary file not shown.
Binary file not shown.
BIN
obj/maeth.o
BIN
obj/maeth.o
Binary file not shown.
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
BIN
obj/menus.o
BIN
obj/menus.o
Binary file not shown.
BIN
obj/move.o
BIN
obj/move.o
Binary file not shown.
|
@ -232,8 +232,8 @@ void gl_renderNearbyChunks(int render_distance) {
|
|||
gl_renderAll(hashtbl_find_opt(visited, player_chx+w, player_chy+h), (2.0*room_width)*w, 0.0, (2.0*room_depth)*h);
|
||||
}
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||
if(F5 != 0) {
|
||||
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||
fill_cube_0(F5_renderer, camx-min_dist, camy-min_dist, camz-min_dist, 2*min_dist, 2*min_dist, 2*min_dist, 0.0, 0.0, 192, 192, 192);
|
||||
gl_renderCube(F5_renderer, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <limits.h>
|
||||
#include <time.h>
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cglm/cglm.h>
|
||||
|
||||
#include "hash.h"
|
||||
#include "base.h"
|
||||
#include "display.h"
|
||||
#include "inventory.h"
|
||||
|
||||
inventory* playerInventory;
|
||||
const int Lines = 9;
|
||||
const int Cols = 3;
|
||||
|
||||
void inv_init() {
|
||||
playerInventory = malloc(sizeof(inventory));
|
||||
playerInventory->lines = Lines;
|
||||
playerInventory->cols = Cols;
|
||||
playerInventory->data = malloc(sizeof(stack*)*Lines);
|
||||
for(int k = 0; k < Lines; k++) {
|
||||
playerInventory->data[k] = malloc(sizeof(stack)*Cols);
|
||||
for(int l = 0; l < Cols; l++) {
|
||||
playerInventory->data[k][l] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void inv_destroy() {
|
||||
for(int k = 0; k < Lines; k++) {
|
||||
free(playerInventory->data[k]);
|
||||
}
|
||||
free(playerInventory->data);
|
||||
free(playerInventory);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef INV_H
|
||||
#define INV_H
|
||||
|
||||
typedef struct item {
|
||||
const char* name;
|
||||
int maxCount;
|
||||
int texID;
|
||||
|
||||
void (*onCollect)(float dtime);
|
||||
void (*onUse)(float dtime);
|
||||
} item;
|
||||
|
||||
typedef struct stack_t {
|
||||
item* itm;
|
||||
int count;
|
||||
} stack_t;
|
||||
typedef stack_t* stack; // can be NULL
|
||||
|
||||
typedef struct inventory {
|
||||
stack** data;
|
||||
int lines;
|
||||
int cols;
|
||||
} inventory;
|
||||
|
||||
// -------------- //
|
||||
void inv_init();
|
||||
void inv_destroy();
|
||||
|
||||
#endif
|
41
src/main.c
41
src/main.c
|
@ -22,6 +22,7 @@
|
|||
#include "move.h"
|
||||
#include "menus.h"
|
||||
#include "proj.h"
|
||||
#include "inventory.h"
|
||||
#include "entities.h"
|
||||
#include "display.h"
|
||||
#include "generation.h"
|
||||
|
@ -48,6 +49,7 @@ bool yPress = false;
|
|||
bool P5ress = false;
|
||||
|
||||
unsigned int textures[32];
|
||||
unsigned int itemTexts[32];
|
||||
|
||||
bool paused = false;
|
||||
bool hardReset = true;
|
||||
|
@ -417,6 +419,8 @@ const char *vertexShaderSourceR = "#version 330 core\n"
|
|||
const char *fragmentShaderSourceR = "#version 330 core\n"
|
||||
"uniform vec4 u_color2;\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"in vec2 texCoord;\n"
|
||||
"uniform sampler2D tex0;\n"
|
||||
"void main() {\n"
|
||||
" FragColor = u_color2;\n"
|
||||
"}\0";
|
||||
|
@ -449,33 +453,32 @@ void generate_texture_2D(int id, char* filename, file_extension ext) {
|
|||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
/*void generate_texture_3D(int id, char* filename, file_extension ext) {
|
||||
int widthImg, heightImg, depthImg, numColCh;
|
||||
void generate_itemTexture_2D(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]);
|
||||
if(bytes == 0) {fprintf(stderr, "ERROR : cannot load texture [%s]\n", filename); exit(1);}
|
||||
glGenTextures(1, &itemTexts[id]);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_3D, textures[id]);
|
||||
glBindTexture(GL_TEXTURE_2D, itemTexts[id]);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
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) {
|
||||
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, widthImg, heightImg, depthImg, 0, GL_RGB, GL_UNSIGNED_BYTE, bytes);
|
||||
glGenerateMipmap(GL_TEXTURE_3D);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, widthImg, heightImg, 0, GL_RGB, GL_UNSIGNED_BYTE, bytes);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
} else if(ext == PNG) {
|
||||
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, widthImg, heightImg, depthImg, 0, GL_RGBA, GL_UNSIGNED_BYTE, bytes);
|
||||
glGenerateMipmap(GL_TEXTURE_3D);
|
||||
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() {
|
||||
// glfw: initialize and configure
|
||||
|
@ -515,6 +518,7 @@ int main_alt() {
|
|||
//glfwSetMouseButtonCallback(window, mouse_button_callback);
|
||||
|
||||
init_csts();
|
||||
inv_init();
|
||||
init_hashtbl();
|
||||
init_interf(window);
|
||||
build_all_menus();
|
||||
|
@ -612,6 +616,11 @@ int main_alt() {
|
|||
//generate_texture_2D(17, "res/selection-mod-flashlight.png", PNG);
|
||||
//generate_texture_2D(18, "res/selection-mod-suddendeath.png", PNG);
|
||||
|
||||
printf("-----------------------------------------------------------------------------------------------\n"); fflush(stdout);
|
||||
// 32 max
|
||||
|
||||
generate_itemTexture_2D(0, "res/white.png", PNG);
|
||||
|
||||
printf("-----------------------------------------------------------------------------------------------\n"); fflush(stdout);
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
|
||||
|
@ -745,6 +754,7 @@ int main_alt() {
|
|||
glUseProgram(shaderProgramR);
|
||||
glBindVertexArray(RVAO);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, itemTexts[0]);
|
||||
gl_drawInteger(shaderProgramR, (int)(1.0f/(real_T)), 0.0f, -0.92f, 0.05, 32, 255, 32, 0.005, -1);
|
||||
gl_drawInteger(shaderProgramR, triCount, 0.0f, 0.92f, 0.04f, 128, 128, 128, 0.005f, 1);
|
||||
gl_drawData(shaderProgramR);
|
||||
|
@ -837,6 +847,7 @@ int main_alt() {
|
|||
free_ent_generator();
|
||||
printf("Done\n"); fflush(stdout);
|
||||
free_maeth();
|
||||
inv_destroy();
|
||||
free(F5_renderer);
|
||||
|
||||
// optional: de-allocate all resources once they've outlived their purpose:
|
||||
|
|
|
@ -193,6 +193,7 @@ extern int loc_tex;
|
|||
extern bool is_one_room;
|
||||
|
||||
extern unsigned int textures[32];
|
||||
extern unsigned int itemTexts[32];
|
||||
|
||||
extern double choffx;
|
||||
extern double choffz;
|
||||
|
|
Loading…
Reference in New Issue