Compare commits

...

7 Commits

Author SHA1 Message Date
grant squires ebd46a4363 nyaaa~ 2023-05-19 12:37:18 +00:00
grant squires 2f2d309baa even more fixes:3 2023-05-18 09:06:21 +00:00
grant squires c165a13371 poly-trans (almost) fully working 2023-05-16 11:33:15 +00:00
grant squires 3925e25802 clean vgcore 2023-05-15 13:13:11 +00:00
grant squires 025ee0828e poly intersection! 2023-05-15 13:12:45 +00:00
grant squires e22922b545 aaa TwT do transparency pwease 2023-05-12 13:00:58 +00:00
grant squires 4001cbc317 coloring & render order 2023-05-11 12:24:59 +00:00
4 changed files with 783 additions and 201 deletions

View File

@ -1,17 +1,17 @@
optimized build : `clang ./src/*.c -lm -lglfw -lGL -lGLEW -fno-trapping-math`
optional flags : -Dskip_memory_trace -Dstfu
build flags : -Dmemory_trace -Dstfu -D__debug -Dmemory_count
# todo
- find a better epsilon
- fix the fps counter, its probably wrong
- color triangles
- color triangles (more detailed)
-animations
- animations
- simple transparency
# known issues

File diff suppressed because it is too large Load Diff

View File

@ -3,17 +3,19 @@
#include "util.h"
#include <math.h>
#include "strings.h"
ulong allocs = 0;
int forced_length = 15;
unsigned long allocs = 0;
unsigned long frees = 0;
int log_level = 0;
int __signal = 0;
typedef struct {
void* addr;
char* file;
char* function;
int line;
ulong size;
unsigned long size;
} alloc;
alloc* allocations = NULL;
double binomial(int n, int k){
inline double binomial(int n, int k){
if(n==k)
return 1.0;
double v = 1.0;
@ -22,58 +24,76 @@ double binomial(int n, int k){
}
return v;
}
void* mmalloc(ulong X,char*file,int line,char*func){
inline void* mmalloc(size_t X,char*file,int line,char*func){
void* mal = (malloc)(X);
if(mal==NULL)
err_m("malloc error",exit,file,line); //abort();
#ifdef memory_trace
if(allocations==NULL){
allocations=(malloc)(sizeof(*allocations)*2);
}
allocations=(realloc)(allocations,sizeof(*allocations)*(allocs+1));
void* mal = (malloc)(X);
if(mal==NULL)
err("failed to malloc",pexit);
allocations[allocs].addr = mal;
allocations[allocs].function = func;
allocations[allocs].file = file;
allocations[allocs].line = line;
allocations[allocs].size = X;
#endif
allocs++;
return mal;
}
void ffree(void* X,char*file,int line,char*func){
for(ulong i = 0; i<=allocs; i++){
inline void ffree(void* X,char*file,int line,char*func){
if(X==NULL){
warn_m("tried to free a null pointer",file,line);
return;
}
#ifdef memory_trace
for(unsigned long i = 0; i<=allocs-1; i++){
if(allocations[i].addr==X){
allocations[i].addr = NULL;
break;
}
}
#endif
(free)(X);
allocs--;
frees++;
//allocs--;
}
int log_level = 0;
int __signal = 0;
void pexit(int s){
__signal = s;
exit(s);
}
void sig_handle(void){
if(log_level<=-1){
#ifndef skip_memory_trace
#ifdef memory_trace
(free)(allocations);
#endif
return;
}
#ifdef stfu
#ifndef skip_memory_trace
#ifndef memory_trace
(free)(allocations);
#endif
return;
#endif
#ifndef skip_memory_trace
if(allocs>0){
char ssa[45];
sprintf(ssa,"%s | (found %i)","uneven allocations, memory leak(s)",(int)nearbyint(allocs));
#if defined(memory_trace) || defined(memory_count)
if(allocs!=frees){
char ssa[200];
sprintf(ssa,"%s | (%i/%i freed)","uneven allocations, memory leak(s)",(int)nearbyint(frees),(int)nearbyint(allocs));
warn(ssa);
for(ulong i = 0; i<=allocs; i++){
#ifdef memory_trace
for(unsigned long i = 0; i<=allocs-1; i++){
if(allocations[i].addr!=NULL){
char ad[50];
@ -83,10 +103,13 @@ void sig_handle(void){
printf(" | - <\x1b[90m0x\x1b[0m%s> %s:%s:%i, %lu bytes initially allocated\n",ad,allocations[i].file,allocations[i].function,allocations[i].line,allocations[i].size);
}
}
(free)(allocations);
#endif
}
if(allocs==0)
if(allocs==frees)
info("even allocations, no internal leaks");
if(allocations!=NULL)
(free)(allocations);
#endif
if(__signal==0){
printf("\x1b[90mexited with \x1b[32m\x1b[1msignal [ %i ] \x1b[0m\x1b[90mgraceful exit\x1b[0m (meow)\n",__signal);
@ -102,11 +125,11 @@ unsigned int_len(const unsigned n) {
return 1 + int_len(n / 10);
}//https://stackoverflow.com/a/3068415
char* force_ca_length(char*inp,int len){
char* nya = malloc(sizeof(*nya)*(len+1));
char* nya = malloc(sizeof(*nya)*(len+2));
int skip = 0;
for(int i = 0;; i++){
if((inp[i]=='\0'||skip)&&i>=len)
nya[i] = ' ';
if((skip||inp[i]=='\0')&&i>=len)
break;
if(inp[i]=='\0')
skip=1;
@ -120,7 +143,7 @@ char* force_ca_length(char*inp,int len){
nya[i] = ' ';
else
nya[i] = inp[i];
}
}
if(!skip){
nya[2] = '.';
nya[1] = '.';
@ -160,6 +183,16 @@ void info_m(char*ca,char*f,int l,...){
printf("\x1b[90m%s [ info ] %s\x1b[0m\n",aa,ca);
free(aa);
}
void debug_m(char*ca,char*f,int l,...){
if(log_level<-1)
return;
int len = ca_size(f) + int_len(l);
char nn[len];
sprintf(nn,"%s:%i",f,l);
char* aa = force_ca_length(nn,forced_length);
printf("\e[38;5;69m%s [ dbug ] \e[0m\x1b[90m%s\x1b[0m\n",aa,ca);
free(aa);
}
void log_m(char*ca,char*f,int l,...){
if(log_level<2)
return;

View File

@ -4,19 +4,31 @@
#include "string.h"
#ifndef __util__
#define __util__
static const double FL_DIS = 1e-7;
static const double NaN = 0.0f/0.0f;
static const int forced_length = 20;
#define greater(a,b) ((a)>(b)?(a):(b))
#define lesser(a,b) ((a)>(b)?(b):(a))
#define diff(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#ifndef skip_memory_trace
#if defined(memory_trace) || defined(memory_count)
#ifdef memory_trace
//maybe add warning here
#endif
#define malloc(X) mmalloc(X,(char*)__FILE__,(int)__LINE__,(char*)__FUNCTION__);
#define free(X) ffree(X,(char*)__FILE__,(int)__LINE__,(char*)__FUNCTION__);
#define free(X) ffree(X,(char*)__FILE__,(int)__LINE__,(char*)__FUNCTION__); X=NULL;
#endif
#ifndef stfu
#ifdef __debug
#define debug(s) debug_m(s,__FILE__,__LINE__);
#else
#define debug(s){};
#endif
#define err(s,f,...) err_m(s,f,__FILE__,__LINE__,##__VA_ARGS__);
#define warn(s) warn_m(s,__FILE__,__LINE__);
#define info(s) info_m(s,__FILE__,__LINE__);
@ -30,9 +42,10 @@ static const double NaN = 0.0f/0.0f;
#endif
double binomial(int n, int k);
void* mmalloc(ulong,char*,int,char*);
void* mmalloc(size_t,char*,int,char*);
void ffree(void*,char*,int,char*);
void err_m(char*,void (*)(int),char*,int);
void debug_m(char*,char*,int,...);
void warn_m(char*,char*,int ,...);
void info_m(char*,char*,int ,...);
void log_m(char*ca,char*f,int l,...);