polished SET_VAR attribute + added textBox entity

This commit is contained in:
Alexandre 2025-02-18 15:35:39 +01:00
parent bb39b62df2
commit bd87416496
28 changed files with 313 additions and 118 deletions

View File

@ -16,6 +16,7 @@
"proj.h": "c", "proj.h": "c",
"entities.h": "c", "entities.h": "c",
"menus.h": "c", "menus.h": "c",
"structure.h": "c" "structure.h": "c",
"limits.h": "c"
} }
} }

BIN
bin/back

Binary file not shown.

View File

@ -1,18 +0,0 @@
Blocks :
[0.0, 0.0, 0.0, 10.0, 1.0, 10.0, 0.0, 0.0, 255, 255, 255]
[0.0, 9.0, 0.0, 10.0, 1.0, 10.0, 0.0, 0.0, 255, 255, 255]
[0.0, 1.0, 0.0, 1.0, 8.0, 1.0, 0.0, 0.0, 128, 128, 128]
[9.0, 1.0, 0.0, 1.0, 8.0, 1.0, 0.0, 0.0, 128, 128, 128]
[0.0, 1.0, 9.0, 1.0, 8.0, 1.0, 0.0, 0.0, 128, 128, 128]
[9.0, 1.0, 9.0, 1.0, 8.0, 1.0, 0.0, 0.0, 128, 128, 128]
Teleporters :
[4.0, 1.0, 0.0, 2.0, 4.0, 1.0, 0.0, 0.0, 255, 0, 0; -1, 0]
[0.0, 1.0, 4.0, 1.0, 4.0, 2.0, 0.0, 0.0, 255, 255, 0; 0, -1]
[4.0, 1.0, 9.0, 2.0, 4.0, 1.0, 0.0, 0.0, 0, 255, 0; 1, 0]
[9.0, 1.0, 4.0, 1.0, 4.0, 2.0, 0.0, 0.0, 0, 0, 255; 0, 1]
Weight :
50
$

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.

View File

@ -193,3 +193,9 @@ void explodeOnHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
} }
*hp = 0; *hp = 0;
} }
// metai1 = id of the interface
// metach1 = text (unused outside of initialization)
void pop_text(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
interface_set(ent->metai1);
}

View File

@ -1,6 +1,8 @@
#ifndef ENTITIES_H #ifndef ENTITIES_H
#define ENTITIES_H #define ENTITIES_H
extern int build_text_box(char* msg, int red, int green, int blue);
bool is_colliding_with_map(cube_0* cb); bool is_colliding_with_map(cube_0* cb);
bool is_colliding_with_tp(cube_0* cb); bool is_colliding_with_tp(cube_0* cb);
@ -19,5 +21,6 @@ void money(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret);
void explodeOnHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret); void explodeOnHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret);
void translatePlayer(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret); void translatePlayer(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret);
void translatePlayerLine(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret); void translatePlayerLine(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret);
void pop_text(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret);
#endif #endif

View File

@ -7,6 +7,7 @@
#include <termios.h> #include <termios.h>
#include <limits.h> #include <limits.h>
#include <time.h> #include <time.h>
#include <string.h>
#include "hash.h" #include "hash.h"
#include "structure.h" #include "structure.h"
@ -30,7 +31,7 @@ int fct_entry_size;
fct_entry* hashtbl_entities; fct_entry* hashtbl_entities;
void init_ent_generator(int n) { void init_ent_generator(int n) {
//!\\ size = 10 now //!\\ size = 30 now
hashtbl_entities = malloc(sizeof(fct_entry)*n); hashtbl_entities = malloc(sizeof(fct_entry)*n);
fct_entry_size = n; fct_entry_size = n;
for(int k = 0; k < 10; k++) { for(int k = 0; k < 10; k++) {
@ -72,6 +73,19 @@ void init_ent_generator(int n) {
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].name = "TextBox";
hashtbl_entities[6].updatePos = NULL;
hashtbl_entities[6].onHit = &pop_text;
hashtbl_entities[6].onDeath = NULL;
// NOT IMPLEMENTED YET //
hashtbl_entities[7].id = 7;
hashtbl_entities[7].name = "WarpBox";
hashtbl_entities[7].updatePos = NULL;
hashtbl_entities[7].onHit = &translatePlayerLine;
hashtbl_entities[7].onDeath = NULL;
} }
fct_entry* get_entry(int k0) { fct_entry* get_entry(int k0) {
@ -132,6 +146,8 @@ void copy_room(room* src, room* dest, int chx, int chy) {
dest->ents[k]->metad7 = src->ents[k]->metad7; dest->ents[k]->metad7 = src->ents[k]->metad7;
dest->ents[k]->metad8 = src->ents[k]->metad8; dest->ents[k]->metad8 = src->ents[k]->metad8;
dest->ents[k]->metad9 = src->ents[k]->metad9; dest->ents[k]->metad9 = src->ents[k]->metad9;
dest->ents[k]->metach1 = src->ents[k]->metach1;
dest->ents[k]->metach2 = src->ents[k]->metach2;
*(dest->ents[k]->hitpoints) = *(src->ents[k]->hitpoints); *(dest->ents[k]->hitpoints) = *(src->ents[k]->hitpoints);
dest->ents[k]->pos = create_cube_0( dest->ents[k]->pos = create_cube_0(
(*(src->ents[k]->pos)).x, (*(src->ents[k]->pos)).y, (*(src->ents[k]->pos)).z, (*(src->ents[k]->pos)).x, (*(src->ents[k]->pos)).y, (*(src->ents[k]->pos)).z,
@ -258,6 +274,19 @@ int read_int(FILE* ptr, bool print) {
return buffer*sign; return buffer*sign;
} }
char* read_string(FILE* ptr) {
char* res0 = malloc(sizeof(char)*51);
char c = fgetc(ptr);
int i = 0;
while(c != EOF && c != ',') {
res0[i] = c;
i += 1;
c = fgetc(ptr);
}
res0[i] = '\0';
return res0;
}
double sign(double __x) { double sign(double __x) {
if(__x >= 0.0) { if(__x >= 0.0) {
return 1.0; return 1.0;
@ -394,7 +423,10 @@ void parse_one_room(int id, char* filename) {
pool[id].area->ents[k]->metad7 = entry->metad7; pool[id].area->ents[k]->metad7 = entry->metad7;
pool[id].area->ents[k]->metad8 = entry->metad8; pool[id].area->ents[k]->metad8 = entry->metad8;
pool[id].area->ents[k]->metad9 = entry->metad9; pool[id].area->ents[k]->metad9 = entry->metad9;
pool[id].area->ents[k]->metach1 = entry->metach1;
pool[id].area->ents[k]->metach2 = entry->metach2;
if(entry->id == 4) { if(entry->id == 4) {
// sine platform
double ccw = read_float(ptr); double ccw = read_float(ptr);
double cch = read_float(ptr); double cch = read_float(ptr);
double ccd = read_float(ptr); double ccd = read_float(ptr);
@ -411,13 +443,13 @@ void parse_one_room(int id, char* filename) {
pool[id].area->ents[k]->metai2 = divd; pool[id].area->ents[k]->metai2 = divd;
pool[id].area->ents[k]->metai3 = phase; pool[id].area->ents[k]->metai3 = phase;
} else if(entry->id == 5) { } else if(entry->id == 5) {
// linear platform
double amp_x = read_float(ptr); double amp_x = read_float(ptr);
double amp_y = read_float(ptr); double amp_y = read_float(ptr);
double amp_z = read_float(ptr); double amp_z = read_float(ptr);
double speed_x = read_float(ptr); double speed_x = read_float(ptr);
double speed_y = read_float(ptr); double speed_y = read_float(ptr);
double speed_z = read_float(ptr); double speed_z = read_float(ptr);
//printf("%lf, %lf, %lf, %lf, %lf, %lf\n", amp_x, amp_y, amp_z, speed_x, speed_y, speed_z);
pool[id].area->ents[k]->metad1 = cx; pool[id].area->ents[k]->metad1 = cx;
pool[id].area->ents[k]->metad2 = cy; pool[id].area->ents[k]->metad2 = cy;
pool[id].area->ents[k]->metad3 = cz; pool[id].area->ents[k]->metad3 = cz;
@ -430,32 +462,21 @@ void parse_one_room(int id, char* filename) {
pool[id].area->ents[k]->metai1 = 1; pool[id].area->ents[k]->metai1 = 1;
pool[id].area->ents[k]->metai2 = 1; pool[id].area->ents[k]->metai2 = 1;
pool[id].area->ents[k]->metai3 = 1; pool[id].area->ents[k]->metai3 = 1;
} else if(entry->id == 6) {
// text box
char* msg = read_string(ptr);
pool[id].area->ents[k]->metach1 = msg;
int ired = read_int(ptr, true);
int igreen = read_int(ptr, true);
int iblue = read_int(ptr, true);
pool[id].area->ents[k]->metai1 = build_text_box(msg, ired, igreen, iblue);
pool[id].area->ents[k]->metai2 = (-727); // random value to recognize
} }
//pool[id].area->ents[k]->updatePos = &speen2;
//pool[id].area->ents[k]->onHit = &detectHit ;
//pool[id].area->ents[k]->onDeath = NULL ;
//printf("\n");
} }
printf("3/3...\n"); printf("3/3...\n");
fflush(stdout); fflush(stdout);
// debug
/*for(int k = 0; k < ncubes; k++) {
printf("(%lf, %lf, %lf), (%lf, %lf, %lf), (%lf, %lf), (%d, %d, %d)\n",
pool[id].area->map[k]->x,
pool[id].area->map[k]->y,
pool[id].area->map[k]->z,
pool[id].area->map[k]->w,
pool[id].area->map[k]->h,
pool[id].area->map[k]->d,
pool[id].area->map[k]->hz_angle,
pool[id].area->map[k]->vt_angle,
pool[id].area->map[k]->red,
pool[id].area->map[k]->green,
pool[id].area->map[k]->blue
);
}*/
pool[id].weight = read_int(ptr, true); pool[id].weight = read_int(ptr, true);
total_weight += pool[id].weight; total_weight += pool[id].weight;
@ -609,6 +630,9 @@ void free_pool() {
free(pool[k0].area->tps[k]); free(pool[k0].area->tps[k]);
} }
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]->metai2 == -727) {
free(pool[k0].area->ents[k]->metach1);
}
free(pool[k0].area->ents[k]->hitpoints); free(pool[k0].area->ents[k]->hitpoints);
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]);

View File

@ -31,8 +31,12 @@ typedef struct fct_entry {
double metad7; double metad7;
double metad8; double metad8;
double metad9; double metad9;
char* metach1;
char* metach2;
} fct_entry ; } fct_entry ;
extern int build_text_box(char* msg, int red, int green, int blue);
void init_ent_generator(int n); void init_ent_generator(int n);
void copy_room(room* src, room* dest, int chx, int chy) ; void copy_room(room* src, room* dest, int chx, int chy) ;
@ -44,6 +48,7 @@ void get_number_blocks(int* ret_cubes, int* ret_tps, int* ret_ent, FILE* ptr) ;
void align_to(FILE* ptr, char ch) ; void align_to(FILE* ptr, char ch) ;
int read_int(FILE* ptr, bool print) ; int read_int(FILE* ptr, bool print) ;
double read_float(FILE* ptr) ; double read_float(FILE* ptr) ;
char* read_string(FILE* ptr);
void parse_one_room(int id, char* filename) ; void parse_one_room(int id, char* filename) ;
void parse_rooms(int n_rooms, char* folder) ; void parse_rooms(int n_rooms, char* folder) ;

View File

@ -37,10 +37,11 @@ void reset_everything(GLFWwindow *window, int count, char* folder) {
//init_csts(); //init_csts();
init_hashtbl(); init_hashtbl();
init_ent_generator(10);
init_proj();
init_interf(window); init_interf(window);
parse_rooms(count, folder); //build_all_menus();
init_ent_generator(30);
init_proj();
parse_rooms(7, "templates/");
} }
void processInput(GLFWwindow *window, float dtime) { void processInput(GLFWwindow *window, float dtime) {
@ -250,10 +251,10 @@ int main_alt() {
init_csts(); init_csts();
init_hashtbl(); init_hashtbl();
init_ent_generator(10);
init_proj();
init_interf(window); init_interf(window);
build_all_menus(); build_all_menus();
init_ent_generator(30);
init_proj();
parse_rooms(7, "templates/"); parse_rooms(7, "templates/");
// ---------------------------------------------------------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------------------------------------------------------- //

View File

@ -61,7 +61,7 @@ void gl_drawDigit(unsigned int fragShader, int n, float x, float y, float size,
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b); gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b); gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
} else if(n == 1) { } else if(n == 1) {
gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b); gl_drawRect(fragShader, x-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
} else if(n == 2) { } else if(n == 2) {
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b); gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
gl_drawRect(fragShader, x+size/2-width, y-width, 2*width, size+2*width, r, g, b); gl_drawRect(fragShader, x+size/2-width, y-width, 2*width, size+2*width, r, g, b);
@ -138,19 +138,37 @@ void gl_drawInteger(unsigned int fragShader, int n, float x, float y, float size
} }
void gl_drawFloat(unsigned int fragShader, float n, float x, float y, float size, int r, int g, int b, float width, int side) { void gl_drawFloat(unsigned int fragShader, float n, float x, float y, float size, int r, int g, int b, float width, int side) {
gl_drawInteger(fragShader, (int)(n*1000.0f), x, y, size, r, g, b, width, side); int left = (int)(n*1000);
int left = n; int acc = max(0, 5-ln_baseN(abs(left), 10));
float curx = x; float curx = x;
int countf = 0;
if(left < 0) { if(left < 0) {
left *= (-1); left *= (-1);
} }
if(side == 1) { if(side == 1) {
curx += (((n==0)+ln_baseN(abs((int)n), 10)-1)*(size+4*width)); curx += (((left==0)+max(4, ln_baseN(abs(left), 10))-1)*(size+4*width));
} else if(side == 0) { } else if(side == 0) {
curx += (((n==0)+ln_baseN(abs((int)n), 10)-1)*(size+4*width))/2.0; curx += (((left==0)+max(4, ln_baseN(abs(left), 10))-1)*(size+4*width))/2.0;
}
while(left > 0 || acc > 0) {
gl_drawDigit(fragShader, left%10, curx, y, size, r, g, b, width);
curx -= (size+4*width);
left = left/10;
countf += 1;
if(countf == 3) {
gl_drawRect(fragShader, curx+size/2+3*width/2, y-size-width, width, 2*width, r, g, b);
}
if(left == 0) {
acc -= 1;
}
}
if(n == 0) {
gl_drawDigit(fragShader, 0, curx, y, size, r, g, b, width);
curx -= (size+4*width);
}
if(n < 0) {
gl_drawRect(fragShader, curx-size/2-width, y, size+2*width, 2*width, r, g, b);
} }
curx -= (size+4*width)*3; // 0.001 rounding
gl_drawRect(fragShader, curx+size/2+2*width, y-size-width, 3*width, 3*width, r, g, b);
} }
void gl_drawChar(unsigned int fragShader, char ch, float x, float y, float size, int r, int g, int b, float width) { void gl_drawChar(unsigned int fragShader, char ch, float x, float y, float size, int r, int g, int b, float width) {
@ -338,6 +356,12 @@ void gl_printf(unsigned int fragShader, float x, float y, float size, float widt
gl_drawInteger(fragShader, val, curx, y, size, r, g, b, width, 1); gl_drawInteger(fragShader, val, curx, y, size, r, g, b, width, 1);
curx += (size+4*width)*(ln_baseN(abs(val), 10)); curx += (size+4*width)*(ln_baseN(abs(val), 10));
break; break;
case 'f':
float valf = (float)(va_arg(args, double));
//printf("%d", val);
gl_drawFloat(fragShader, valf, curx, y, size, r, g, b, width, 1);
curx += (size+4*width)*(3+ln_baseN(abs((int)valf), 10));
break;
case 's': case 's':
char* chval = (char*)(va_arg(args, const char*)); char* chval = (char*)(va_arg(args, const char*));
//printf("%s", chval); //printf("%s", chval);
@ -423,7 +447,7 @@ void display_interface(int int_id, unsigned int fragShader, float mx, float my)
gl_drawString(fragShader, interfaceList[int_id].title, interfaceList[int_id].x+interfaceList[int_id].w/2.0f, interfaceList[int_id].y+interfaceList[int_id].h/2.0f, 0.7f*size, retcol, retcol, retcol, 0.7f*size/10.0f, 0); gl_drawString(fragShader, interfaceList[int_id].title, interfaceList[int_id].x+interfaceList[int_id].w/2.0f, interfaceList[int_id].y+interfaceList[int_id].h/2.0f, 0.7f*size, retcol, retcol, retcol, 0.7f*size/10.0f, 0);
for(int k = 0; k < interfaceList[int_id].nButtons; k++) { for(int k = 0; k < interfaceList[int_id].nButtons; k++) {
if(((int)(sim_time*10.0))%2 == 0 && is_hovering_button(interfaceList[int_id].buttons[k], mx, my)) { if(is_hovering_button(interfaceList[int_id].buttons[k], mx, my)) {
gl_drawRect(fragShader, buttonList[interfaceList[int_id].buttons[k]].x-0.015f, buttonList[interfaceList[int_id].buttons[k]].y-0.015f, buttonList[interfaceList[int_id].buttons[k]].w+0.03f, buttonList[interfaceList[int_id].buttons[k]].h+0.03f, 255, 255, 255); gl_drawRect(fragShader, buttonList[interfaceList[int_id].buttons[k]].x-0.015f, buttonList[interfaceList[int_id].buttons[k]].y-0.015f, buttonList[interfaceList[int_id].buttons[k]].w+0.03f, buttonList[interfaceList[int_id].buttons[k]].h+0.03f, 255, 255, 255);
} }
display_button(interfaceList[int_id].buttons[k], fragShader); display_button(interfaceList[int_id].buttons[k], fragShader);
@ -451,7 +475,7 @@ void menu_actions(GLFWwindow *window, int button, int action, int mods) {
(*buttonList[but_id].onClick)(buttonList[but_id].arg); (*buttonList[but_id].onClick)(buttonList[but_id].arg);
} }
//float prevIncr = incr+0.0001f; //float prevIncr = incr+0.0001f;
float size = minf(interfaceList[*current_interface].h/2.1f, (interfaceList[*current_interface].w)/(get_string_len(interfaceList[*current_interface].title))); float size = minf(interfaceList[*current_interface].h/2.1f, (interfaceList[*current_interface].w)/(3*(buttonList[but_id].cast != INT)+get_string_len(interfaceList[*current_interface].title)));
int retcol = mn_get_color(interfaceList[*current_interface].red, interfaceList[*current_interface].green, interfaceList[*current_interface].blue); int retcol = mn_get_color(interfaceList[*current_interface].red, interfaceList[*current_interface].green, interfaceList[*current_interface].blue);
switch (buttonList[but_id].type) { switch (buttonList[but_id].type) {
case WARP: case WARP:
@ -471,21 +495,21 @@ void menu_actions(GLFWwindow *window, int button, int action, int mods) {
while(!halt) { while(!halt) {
toad = 0.0; toad = 0.0;
mult = 1.0; mult = 1.0;
if(glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) { if(glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
pressed = true; pressed = true;
if(!clicked) { if(!clicked) {
clicked = true; clicked = true;
toad = 1.0; toad = (buttonList[but_id].sup-buttonList[but_id].inf)/50.0;
} }
} }
if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) { if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
pressed = true; pressed = true;
if(!clicked) { if(!clicked) {
clicked = true; clicked = true;
toad = -1.0; toad = (buttonList[but_id].inf-buttonList[but_id].sup)/50.0;
} }
} }
if(glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) { if(glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS) {
pressed = true; pressed = true;
if(!clicked) { if(!clicked) {
clicked = true; clicked = true;
@ -499,7 +523,7 @@ void menu_actions(GLFWwindow *window, int button, int action, int mods) {
mult = 0.5; mult = 0.5;
} }
} }
if(glfwGetKey(window, GLFW_KEY_ENTER) == GLFW_PRESS) { if(glfwGetKey(window, GLFW_KEY_ENTER) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) {
halt = true; halt = true;
} }
@ -509,24 +533,27 @@ void menu_actions(GLFWwindow *window, int button, int action, int mods) {
fflush(stdout); fflush(stdout);
gl_drawRect(fShader, buttonList[but_id].x, buttonList[but_id].y, buttonList[but_id].w, buttonList[but_id].h, buttonList[but_id].red, buttonList[but_id].green, buttonList[but_id].blue); gl_drawRect(fShader, buttonList[but_id].x, buttonList[but_id].y, buttonList[but_id].w, buttonList[but_id].h, buttonList[but_id].red, buttonList[but_id].green, buttonList[but_id].blue);
gl_drawRect(fShader, -1.0f, 0.7f, 2.0f, 0.3f, 0, 0, 0);
gl_drawString(fShader, "press a s m d to add subtract multiply or divide", 0.0f, 0.9f, 0.03f, 192, 192, 64, 0.002f, 0);
gl_printf(fShader, -0.8f, 0.8f, 0.03f, 0.003f, 255, 255, 255, "min %f", buttonList[but_id].inf);
gl_printf(fShader, 0.5f, 0.8f, 0.03f, 0.003f, 255, 255, 255, "max %f", buttonList[but_id].sup);
switch (buttonList[but_id].cast) { switch (buttonList[but_id].cast) {
case INT: case INT:
int* valuei = (int*)buttonList[but_id].metadata; int* valuei = (int*)buttonList[but_id].metadata;
*valuei = ((int)toad) + ((int)mult)*(*valuei); *valuei = max(min(((int)toad) + ((int)mult)*(*valuei), (int)buttonList[but_id].sup), (int)buttonList[but_id].inf);
gl_drawInteger(fShader, *valuei, buttonList[but_id].x+buttonList[but_id].w/2.0f, buttonList[but_id].y+buttonList[but_id].h/2.0f, size*0.7f, retcol, retcol, retcol, size/10.0f*0.7f, 0); gl_drawInteger(fShader, *valuei, buttonList[but_id].x+buttonList[but_id].w/2.0f, buttonList[but_id].y+buttonList[but_id].h/2.0f, size*0.7f, retcol, retcol, retcol, size/10.0f*0.7f, 0);
break; break;
case FLOAT: case FLOAT:
float* valuef = (float*)buttonList[but_id].metadata; float* valuef = (float*)buttonList[but_id].metadata;
*valuef = ((float)toad) + ((float)mult)*(*valuef); *valuef = maxf(minf(((float)toad) + ((float)mult)*(*valuef), (float)buttonList[but_id].sup), (float)buttonList[but_id].inf);
gl_drawFloat(fShader, *valuef, buttonList[but_id].x+buttonList[but_id].w/2.0f, buttonList[but_id].y+buttonList[but_id].h/2.0f, size*0.7f, retcol, retcol, retcol, size/10.0f*0.7f, 0); gl_drawFloat(fShader, *valuef, buttonList[but_id].x+buttonList[but_id].w/2.0f, buttonList[but_id].y+buttonList[but_id].h/2.0f, size*0.7f, retcol, retcol, retcol, size/10.0f*0.7f, 0);
break; break;
case DOUBLE: case DOUBLE:
double* valued = (double*)buttonList[but_id].metadata; double* valued = (double*)buttonList[but_id].metadata;
*valued = ((double)toad) + ((double)mult)*(*valued); *valued = maxd(mind(((double)toad) + ((double)mult)*(*valued), (double)buttonList[but_id].sup), (double)buttonList[but_id].inf);
printf("(%lf, %lf) %lf\n", toad, mult, *valued);
gl_drawFloat(fShader, (float)(*valued), buttonList[but_id].x+buttonList[but_id].w/2.0f, buttonList[but_id].y+buttonList[but_id].h/2.0f, size*0.7f, retcol, retcol, retcol, size/10.0f*0.7f, 0); gl_drawFloat(fShader, (float)(*valued), buttonList[but_id].x+buttonList[but_id].w/2.0f, buttonList[but_id].y+buttonList[but_id].h/2.0f, size*0.7f, retcol, retcol, retcol, size/10.0f*0.7f, 0);
break; break;
@ -540,7 +567,7 @@ void menu_actions(GLFWwindow *window, int button, int action, int mods) {
//incr = prevIncr; //incr = prevIncr;
//usleep(1000000/60); //usleep(1000000/60);
} }
printf("EXIT\n"); //printf("EXIT\n");
noMousePoll = false; noMousePoll = false;
break; break;
@ -582,6 +609,7 @@ bool isMenuOpen() {
return (*current_interface != -1); return (*current_interface != -1);
} }
int* numbers;
void init_interf(GLFWwindow *window) { void init_interf(GLFWwindow *window) {
buttonList = malloc(sizeof(onoff_button)*MAX_BUTTON_SIZE); buttonList = malloc(sizeof(onoff_button)*MAX_BUTTON_SIZE);
for(int k = 0; k < MAX_BUTTON_SIZE; k++) { for(int k = 0; k < MAX_BUTTON_SIZE; k++) {
@ -593,6 +621,10 @@ void init_interf(GLFWwindow *window) {
} }
bListId = 0; bListId = 0;
intListId = 0; intListId = 0;
numbers = malloc(sizeof(int)*256);
for(int k = 0; k < 256; k++) {
numbers[k] = k;
}
current_interface = malloc(sizeof(int)); current_interface = malloc(sizeof(int));
*current_interface = -1; *current_interface = -1;
noMousePoll = false; noMousePoll = false;
@ -602,7 +634,8 @@ void init_interf(GLFWwindow *window) {
// returns the ID of the new button (-1 if error) // returns the ID of the new button (-1 if error)
// actn can be within {NONE, WARP, SET_VAR, EXIT} // actn can be within {NONE, WARP, SET_VAR, EXIT}
// if actn is WARP or SET_VAR then val shall not be NULL // if actn is WARP or SET_VAR then val shall not be NULL
int button_create_onoff(char* text, int red, int green, int blue, float x, float y, float w, float h, button_action actn, void* val, void_type cast, void (*onClick)(void*), void* arg) { // min and max dont matter is actn is not SET_VAR
int button_create_onoff(char* text, int red, int green, int blue, float x, float y, float w, float h, button_action actn, void* val, double min, double max, void_type cast, void (*onClick)(void*), void* arg) {
if(bListId < MAX_BUTTON_SIZE) { if(bListId < MAX_BUTTON_SIZE) {
buttonList[bListId].id = bListId; buttonList[bListId].id = bListId;
@ -620,6 +653,9 @@ int button_create_onoff(char* text, int red, int green, int blue, float x, float
buttonList[bListId].metadata = val; buttonList[bListId].metadata = val;
buttonList[bListId].cast = cast; buttonList[bListId].cast = cast;
buttonList[bListId].inf = min;
buttonList[bListId].sup = max;
buttonList[bListId].onClick = onClick; buttonList[bListId].onClick = onClick;
buttonList[bListId].arg = arg; buttonList[bListId].arg = arg;
@ -700,27 +736,21 @@ void interface_set(int interface_id) {
*current_interface = interface_id; *current_interface = interface_id;
} }
/*
*/
// build and link everything here // build and link everything here
int zero = 0; int button_ok;
int one = 1;
int two = 2;
int three = 3;
void build_all_menus() { void build_all_menus() {
int welcome_start_go = button_create_onoff("start", 0, 255, 255, -0.25f, 0.05f, 0.5f, 0.3f, EXIT, NULL, INT, NULL, NULL); int welcome_start_go = button_create_onoff("start", 0, 255, 255, -0.25f, 0.05f, 0.5f, 0.3f, EXIT, NULL, 0.0, 0.0, INT, NULL, NULL);
int welcome_start_settings = button_create_onoff("config", 96, 96, 96, -0.25f, -0.35f, 0.5f, 0.3f, WARP, &one, INT, NULL, NULL); int welcome_start_settings = button_create_onoff("config", 96, 96, 96, -0.25f, -0.35f, 0.5f, 0.3f, WARP, &(numbers[1]), INT, 0.0, 0.0, NULL, NULL);
int welcome_start_i = interface_create("Welcome", 255, 255, 255, -0.4f, 0.7f, 0.8f, 0.25f); int welcome_start_i = interface_create("Welcome", 255, 255, 255, -0.4f, 0.7f, 0.8f, 0.25f);
interface_link_button(welcome_start_i, welcome_start_go); interface_link_button(welcome_start_i, welcome_start_go);
interface_link_button(welcome_start_i, welcome_start_settings); interface_link_button(welcome_start_i, welcome_start_settings);
int settings_speed = button_create_onoff("speed", 0, 192, 192, -0.25f, 0.55f, 0.5f, 0.3f, SET_VAR, &speed, DOUBLE, NULL, NULL); int settings_speed = button_create_onoff("speed", 0, 192, 192, -0.25f, 0.2f, 0.5f, 0.3f, SET_VAR, &speed, 0.1, 20.0, DOUBLE, NULL, NULL);
int settings_sensitivity = button_create_onoff("sensibility", 192, 192, 0, -0.25f, 0.2f, 0.5f, 0.3f, SET_VAR, &sensitivity, DOUBLE, NULL, NULL); int settings_sensitivity = button_create_onoff("sensibility", 192, 192, 0, -0.25f, -0.15f, 0.5f, 0.3f, SET_VAR, &sensitivity, 0.01, 0.5, DOUBLE, NULL, NULL);
int settings_fov = button_create_onoff("fov", 192, 0, 192, -0.25f, -0.15f, 0.5f, 0.3f, SET_VAR, &fov, DOUBLE, NULL, NULL); int settings_fov = button_create_onoff("fov", 192, 0, 192, -0.25f, -0.5f, 0.5f, 0.3f, SET_VAR, &fov, 30.0, 150.0, DOUBLE, NULL, NULL);
int settings_exit = button_create_onoff("back", 192, 64, 64, -0.25f, -0.5f, 0.5f, 0.3f, WARP, &zero, INT, NULL, NULL); int settings_exit = button_create_onoff("back", 192, 64, 64, -0.25f, -0.85f, 0.5f, 0.3f, WARP, &(numbers[0]), INT, 0.0, 0.0, NULL, NULL);
int settings_i = interface_create("Settings", 128, 128, 128, -0.4f , 0.7f, 0.8f, 0.25f); int settings_i = interface_create("Settings", 128, 128, 128, -0.4f , 0.7f, 0.8f, 0.25f);
interface_link_button(settings_i, settings_speed); interface_link_button(settings_i, settings_speed);
@ -728,43 +758,22 @@ void build_all_menus() {
interface_link_button(settings_i, settings_fov); interface_link_button(settings_i, settings_fov);
interface_link_button(settings_i, settings_exit); interface_link_button(settings_i, settings_exit);
button_ok = button_create_onoff("ok", 32, 255, 32, -0.2f, -0.9f, 0.4f, 0.3f, EXIT, NULL, 0.0, 0.0, INT, NULL, NULL);
interface_set(welcome_start_i); interface_set(welcome_start_i);
} }
// returns the ID of the newly created interface
int build_text_box(char* msg, int red, int green, int blue) {
int intf = interface_create(msg, red, green, blue, -0.9f, 0.05f, 1.8f, 0.85f);
interface_link_button(intf, button_ok);
return intf;
}
void free_interf() { void free_interf() {
free(buttonList); free(buttonList);
free(interfaceList); free(interfaceList);
free(current_interface); free(current_interface);
free(numbers);
} }
/*
typedef struct onoff_button {
int id;
char* text;
float x; float y; float w; float h;
int red;
int green;
int blue;
// {WARP, SET_VAR}
button_action type;
// the value to change (if SET_VAR) or the destination interface (if WARP)
int* metadata;
} onoff_button;
typedef struct interface {
int intfid;
char* title;
float x; float y; float w; float h;
int red;
int green;
int blue;
int* buttons;
int nButtons;
int nMemButtons;
} interface;
*/

View File

@ -18,6 +18,9 @@ typedef struct onoff_button {
void* metadata; void* metadata;
void_type cast; void_type cast;
// limits
double inf; double sup;
// is called upon clicking button // is called upon clicking button
// this function is executed before metadata is used // this function is executed before metadata is used
void (*onClick)(void* args); void (*onClick)(void* args);
@ -51,13 +54,14 @@ void init_interf(GLFWwindow *window);
bool isInMenu(GLFWwindow *win, unsigned int fragShader); bool isInMenu(GLFWwindow *win, unsigned int fragShader);
bool isMenuOpen(); bool isMenuOpen();
int button_create_onoff(char* text, int red, int green, int blue, float x, float y, float w, float h, button_action actn, void* val, void_type cast, void (*onClick)(void*), void* arg); int button_create_onoff(char* text, int red, int green, int blue, float x, float y, float w, float h, button_action actn, void* val, double min, double max, void_type cast, void (*onClick)(void*), void* arg);
int interface_create(char* title, int red, int green, int blue, float x, float y, float w, float h); int interface_create(char* title, int red, int green, int blue, float x, float y, float w, float h);
void interface_link_button(int interface_id, int button_id); void interface_link_button(int interface_id, int button_id);
void interface_unlink_button(int interface_id, int button_id); void interface_unlink_button(int interface_id, int button_id);
void interface_set(int interface_id); void interface_set(int interface_id);
void build_all_menus(); void build_all_menus();
int build_text_box(char* msg, int red, int green, int blue);
void free_interf(); void free_interf();

View File

@ -100,6 +100,10 @@ void set_player_coords(int old_chx, int old_chy) {
return; return;
} }
} }
// no TP has been found, placing to the middle of the room
camx = 0.0;
camy = 10.0;
camz = 0.0;
} }
pt_2d surface[3]; pt_2d surface[3];
@ -295,6 +299,7 @@ void movePlayerG(float dtime) {
camz += camvz*dtime; camz += camvz*dtime;
camvx *= (1.0 - friction*((double)(dtime))); camvx *= (1.0 - friction*((double)(dtime)));
camvy *= (1.0 - friction*((double)(dtime)));
camvz *= (1.0 - friction*((double)(dtime))); camvz *= (1.0 - friction*((double)(dtime)));
if(camy <= -64) { if(camy <= -64) {

View File

@ -56,6 +56,8 @@ typedef struct entity {
double metad7; double metad7;
double metad8; double metad8;
double metad9; double metad9;
char* metach1;
char* metach2;
int damage; int damage;
int* hitpoints; int* hitpoints;

View File

@ -16,3 +16,29 @@ Weight :
50 50
$ $
entities:
[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..]
if entityType = 4 (moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd, phase] with
amplitude_{x,y,z} = double[>= 0.0]
{mult,divd} = int
{phase} = int[0, 360]
else if entityType = 5 (linear moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, speed_x, speed_y, speed_z] with
amplitude_{x,y,z} = double[>= 0.0]
speed_{x,y,z} = double
else if entityType = 6 (text box)
[.. text] with
text = {char*}
// NOT IMPLEMENTED YET //
else if entityType = 7 (warp text box)
[.. text, r, g, b] with
text = {char*} (length <= 50)
{r,g,b} = int[0-256]
else
[..]

View File

@ -25,3 +25,29 @@ Weight :
50 50
$ $
entities:
[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..]
if entityType = 4 (moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd, phase] with
amplitude_{x,y,z} = double[>= 0.0]
{mult,divd} = int
{phase} = int[0, 360]
else if entityType = 5 (linear moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, speed_x, speed_y, speed_z] with
amplitude_{x,y,z} = double[>= 0.0]
speed_{x,y,z} = double
else if entityType = 6 (text box)
[.. text] with
text = {char*}
// NOT IMPLEMENTED YET //
else if entityType = 7 (warp text box)
[.. text, r, g, b] with
text = {char*} (length <= 50)
{r,g,b} = int[0-256]
else
[..]

View File

@ -23,3 +23,29 @@ Weight :
50 50
$ $
entities:
[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..]
if entityType = 4 (moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd, phase] with
amplitude_{x,y,z} = double[>= 0.0]
{mult,divd} = int
{phase} = int[0, 360]
else if entityType = 5 (linear moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, speed_x, speed_y, speed_z] with
amplitude_{x,y,z} = double[>= 0.0]
speed_{x,y,z} = double
else if entityType = 6 (text box)
[.. text] with
text = {char*}
// NOT IMPLEMENTED YET //
else if entityType = 7 (warp text box)
[.. text, r, g, b] with
text = {char*} (length <= 50)
{r,g,b} = int[0-256]
else
[..]

View File

@ -10,7 +10,36 @@ Teleporters :
[9.0, 1.0, -5.0, 1.0, 2.0, 10.0, 0.0, 0.0, 0, 255, 0; 1, 0] [9.0, 1.0, -5.0, 1.0, 2.0, 10.0, 0.0, 0.0, 0, 255, 0; 1, 0]
[-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 :
[-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]
Weight : Weight :
50 50
$ $
entities:
[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..]
if entityType = 4 (moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd, phase] with
amplitude_{x,y,z} = double[>= 0.0]
{mult,divd} = int
{phase} = int[0, 360]
else if entityType = 5 (linear moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, speed_x, speed_y, speed_z] with
amplitude_{x,y,z} = double[>= 0.0]
speed_{x,y,z} = double
else if entityType = 6 (text box)
[.. text] with
text = {char*}
// NOT IMPLEMENTED YET //
else if entityType = 7 (warp text box)
[.. text, r, g, b] with
text = {char*} (length <= 50)
{r,g,b} = int[0-256]
else
[..]

View File

@ -16,3 +16,29 @@ Weight :
50 50
$ $
entities:
[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..]
if entityType = 4 (moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd, phase] with
amplitude_{x,y,z} = double[>= 0.0]
{mult,divd} = int
{phase} = int[0, 360]
else if entityType = 5 (linear moving platform)
[.. amplitude_x, amplitude_y, amplitude_z, speed_x, speed_y, speed_z] with
amplitude_{x,y,z} = double[>= 0.0]
speed_{x,y,z} = double
else if entityType = 6 (text box)
[.. text] with
text = {char*}
// NOT IMPLEMENTED YET //
else if entityType = 7 (warp text box)
[.. text, r, g, b] with
text = {char*} (length <= 50)
{r,g,b} = int[0-256]
else
[..]

View File

@ -31,5 +31,15 @@ else if entityType = 5 (linear moving platform)
amplitude_{x,y,z} = double[>= 0.0] amplitude_{x,y,z} = double[>= 0.0]
speed_{x,y,z} = double speed_{x,y,z} = double
else if entityType = 6 (text box)
[.. text] with
text = {char*}
// NOT IMPLEMENTED YET //
else if entityType = 7 (warp text box)
[.. text, r, g, b] with
text = {char*} (length <= 50)
{r,g,b} = int[0-256]
else else
[..] [..]

View File

@ -31,5 +31,15 @@ else if entityType = 5 (linear moving platform)
amplitude_{x,y,z} = double[>= 0.0] amplitude_{x,y,z} = double[>= 0.0]
speed_{x,y,z} = double speed_{x,y,z} = double
else if entityType = 6 (text box)
[.. text] with
text = {char*}
// NOT IMPLEMENTED YET //
else if entityType = 7 (warp text box)
[.. text, r, g, b] with
text = {char*} (length <= 50)
{r,g,b} = int[0-256]
else else
[..] [..]