diff options
author | amy <[email protected]> | 2023-05-12 13:00:58 +0000 |
---|---|---|
committer | amy <[email protected]> | 2023-05-12 13:00:58 +0000 |
commit | d51a878cd6fbb3bc7864140b0ce82a1908a5ed57 (patch) | |
tree | 438a7d0f7cc860dadf342ebaf794574439a913f5 /src | |
parent | 286e9ca2afb167c398ad43305e9fad19de2c08f6 (diff) |
aaa TwT do transparency pwease
Diffstat (limited to 'src')
-rw-r--r-- | src/point.c | 25 | ||||
-rw-r--r-- | src/util.c | 56 | ||||
-rw-r--r-- | src/util.h | 14 |
3 files changed, 70 insertions, 25 deletions
diff --git a/src/point.c b/src/point.c index a1a7305..2e437ed 100644 --- a/src/point.c +++ b/src/point.c @@ -785,7 +785,6 @@ point_arr* polygon3d(double* vx, double*vy, double* vz, int n,float r, float g, pa = malloc(sizeof(*pa)); pa->c = malloc(sizeof(*pa->c)*(get_w()*60)); pa->vert = malloc(sizeof(*pa->vert)*(n*60)); - if(pa->c==NULL||pa->vert==NULL) err("failed to allocate polygon array",pexit); n-=1; @@ -793,10 +792,16 @@ point_arr* polygon3d(double* vx, double*vy, double* vz, int n,float r, float g, pa->c[i].at.x = vx[i]; pa->c[i].at.y = vy[i]; pa->c[i].at.z = vz[i]; + pa->c[i].at.vertex = 1; pa->vert[i].at.x = vx[i]; pa->vert[i].at.y = vy[i]; pa->vert[i].at.z = vz[i]; + pa->vert[i].at.vertex = 1; + + pa->vert[i].color.r = r; + pa->vert[i].color.g = g; + pa->vert[i].color.b = b; pa->c[i].color.r = r; pa->c[i].color.g = g; @@ -981,6 +986,7 @@ point_m* rect3d_gen(double* tl, double* tr, double* bl, double*br, int main(int argc,char*argv[]){ flag_handle(argc,argv); atexit(sig_handle); + GLFWwindow* w = glfw_init(); refresh_size(w); GLenum err = glewInit(); @@ -1017,7 +1023,7 @@ int main(int argc,char*argv[]){ double zzz[4] = {2.0,2.0,2.0,2.0}; point_m* aaaa = malloc(sizeof(*aaaa)*5); aaaa->len = 0; - aaaa[0].at = polygon3d(xxx,yyy,zzz,5); + aaaa[0].at = polygon3d(xxx,yyy,zzz,5,1.0,1.0,0.0); */ int max_r = 630; double half_max_r = (double)max_r/2/2; @@ -1051,13 +1057,16 @@ int main(int argc,char*argv[]){ if(aaaa->len>=0){ glfl_ar**con = malloc(sizeof **con * aaaa->len); + int con_len = 0; glfl_ar* bba = perspective_proj(w,aaaa[0].at,p1,p2,p3,p4,p5,p6); - con[0] = bba; + con[con_len] = bba; + con_len++; if(aaaa->len>0){ for(int i = 1; i<=aaaa->len-1; i++){ glfl_ar* bbb = perspective_proj(w,aaaa[i].at,p1,p2,p3,p4,p5,p6); //printf("%f\n",bbb->depth); - con[i] = bbb; + con[con_len] = bbb; + con_len++; //join_glfl_a(bba,bbb); //free(bbb->col); //free(bbb->pix); @@ -1068,7 +1077,6 @@ int main(int argc,char*argv[]){ } } - for(int i = 0; i<=aaaa->len-2; i++){ //printf("%i %i\n",i,aaaa->len-1); if(con[i]->max.z<con[i+1]->min.z|| @@ -1079,11 +1087,14 @@ int main(int argc,char*argv[]){ con[i] = con[i+1]; con[i+1] = tempp; - i=-1; + i-=1; } } + + //char* absabd = malloc(1000); + //absabd = "aaa\n"; glfl_ar* push = con[0]; - for(int i = 1; i<=aaaa->len-1;i++){ + for(int i = 1; i<=con_len-1;i++){ //printf("%f %f\n",con[i]->max.x,con[i]->min.x); join_glfl_a(push,con[i]); free(con[i]->tri); @@ -3,14 +3,16 @@ #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){ @@ -22,13 +24,16 @@ double binomial(int n, int k){ } return v; } -void* mmalloc(ulong X,char*file,int line,char*func){ +void* mmalloc(size_t X,char*file,int line,char*func){ 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; @@ -38,17 +43,22 @@ void* mmalloc(ulong X,char*file,int line,char*func){ } void ffree(void* X,char*file,int line,char*func){ - for(ulong i = 0; i<=allocs; i++){ + if(X==NULL){ + warn("tried to free a null pointer"); + return; + } + for(unsigned long i = 0; i<=allocs-1; i++){ if(allocations[i].addr==X){ allocations[i].addr = NULL; break; } } + (free)(X); - allocs--; + frees++; + //allocs--; } -int log_level = 0; -int __signal = 0; + void pexit(int s){ __signal = s; exit(s); @@ -69,11 +79,13 @@ void sig_handle(void){ #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(allocs!=frees){ + char ssa[200]; + sprintf(ssa,"%s | (%i/%i freed)","uneven allocations, memory leak(s)",(int)nearbyint(allocs),(int)nearbyint(frees)); warn(ssa); - for(ulong i = 0; i<=allocs; i++){ + + + for(unsigned long i = 0; i<=allocs-1; i++){ if(allocations[i].addr!=NULL){ char ad[50]; @@ -83,9 +95,11 @@ 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); + } - if(allocs==0) + if(allocations!=NULL) + (free)(allocations); + if(allocs==frees) info("even allocations, no internal leaks"); #endif if(__signal==0){ @@ -105,7 +119,7 @@ char* force_ca_length(char*inp,int len){ char* nya = malloc(sizeof(*nya)*(len+1)); int skip = 0; for(int i = 0;; i++){ - + nya[i] = ' '; if((inp[i]=='\0'||skip)&&i>=len) break; if(inp[i]=='\0') @@ -120,7 +134,7 @@ char* force_ca_length(char*inp,int len){ nya[i] = ' '; else nya[i] = inp[i]; - } + } if(!skip){ nya[2] = '.'; nya[1] = '.'; @@ -160,6 +174,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; @@ -4,8 +4,10 @@ #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)) @@ -13,10 +15,17 @@ static const double NaN = 0.0f/0.0f; #ifndef skip_memory_trace #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 +39,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,...); |