Entity: Fixes on Position setting. New oninit event.
This commit is contained in:
@@ -86,6 +86,7 @@ Entity Entity_New(){
|
||||
e->defaultColor[2]=e->defaultColor[3]=1.0f;
|
||||
|
||||
e->oncopy=NULL;
|
||||
e->oninit=NULL;
|
||||
e->ondelete=NULL;
|
||||
e->proc=NULL;
|
||||
e->postproc=NULL;
|
||||
@@ -104,6 +105,16 @@ Entity Entity_New(){
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_Init
|
||||
//
|
||||
Entity Entity_Init(Entity e){
|
||||
if(e->oninit){
|
||||
e->oninit(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_Destroy
|
||||
//
|
||||
@@ -164,6 +175,7 @@ Entity Entity_Copy(Entity e){
|
||||
n->defaultColor[3]=e->defaultColor[3];
|
||||
|
||||
n->oncopy=e->oncopy;
|
||||
n->oninit=e->oninit;
|
||||
n->ondelete=e->ondelete;
|
||||
n->proc=e->proc;
|
||||
n->postproc=e->postproc;
|
||||
@@ -750,8 +762,9 @@ void Entity_GetPos(Entity e,vec2 pos){
|
||||
//
|
||||
//
|
||||
void Entity_SetPos(Entity e,vec2 pos){
|
||||
vec2_copy(e->oldpos,pos);
|
||||
vec2_copy(e->pos,pos);
|
||||
vec2_copy(e->oldpos,pos);
|
||||
vec2_copy(e->pos0,pos);
|
||||
Entity_CalcBBox(e);
|
||||
}
|
||||
|
||||
@@ -763,6 +776,7 @@ void Entity_SetPos(Entity e,vec2 pos){
|
||||
void Entity_AddPos(Entity e,vec2 pos){
|
||||
vec2_plus(e->pos,e->pos,pos);
|
||||
vec2_copy(e->oldpos,e->pos);
|
||||
vec2_copy(e->pos0,e->pos);
|
||||
Entity_CalcBBox(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ struct TEntity {
|
||||
float defaultColor[4];
|
||||
|
||||
void (*oncopy)(Entity ent);
|
||||
void (*oninit)(Entity ent);
|
||||
void (*ondelete)(Entity ent);
|
||||
void (*proc)(Entity ent,int ft);
|
||||
void (*postproc)(Entity ent,int ft);
|
||||
@@ -83,6 +84,12 @@ struct TEntity {
|
||||
Entity Entity_New();
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_Init
|
||||
//
|
||||
Entity Entity_Init(Entity e);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Entity_Destroy
|
||||
//
|
||||
|
||||
@@ -107,6 +107,8 @@ void GameLib_AddEntity(Entity e){
|
||||
Entity_MarkUpdateLight(e,_entity,_n_entities);
|
||||
|
||||
Entity_CalcBBox(e);
|
||||
|
||||
Entity_Init(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -181,7 +183,6 @@ void GameLib_Compactate(){
|
||||
}
|
||||
_n_entities=j;
|
||||
_entities_compactate=0;
|
||||
_entities_lock=0;
|
||||
}
|
||||
|
||||
|
||||
@@ -210,6 +211,7 @@ void GameLib_ProcLoop(void *data){
|
||||
Entity_Process(_entity[i],_pft);
|
||||
}
|
||||
GameLib_Compactate();
|
||||
_entities_lock=0;
|
||||
t_proc+=Time_GetTime()-time;
|
||||
|
||||
// Colisions between entities
|
||||
@@ -267,6 +269,7 @@ void GameLib_ProcLoop(void *data){
|
||||
}
|
||||
}
|
||||
GameLib_Compactate();
|
||||
_entities_lock=0;
|
||||
t_col+=Time_GetTime()-time;
|
||||
|
||||
// Process Overlaps
|
||||
@@ -282,6 +285,7 @@ void GameLib_ProcLoop(void *data){
|
||||
}
|
||||
}
|
||||
GameLib_Compactate();
|
||||
_entities_lock=0;
|
||||
t_over+=Time_GetTime()-time;
|
||||
|
||||
// Sort
|
||||
@@ -331,6 +335,7 @@ void GameLib_ProcLoop(void *data){
|
||||
_gamepostproc();
|
||||
}
|
||||
GameLib_Compactate();
|
||||
_entities_lock=0;
|
||||
t_postproc+=Time_GetTime()-time;
|
||||
|
||||
fproc_count++;
|
||||
@@ -358,9 +363,9 @@ void GameLib_DrawLoop(void *data, float f){
|
||||
// Limpiar pantalla
|
||||
Draw_Clean(0,0,0);
|
||||
}
|
||||
|
||||
|
||||
// Draw entities
|
||||
GameLib_Compactate();_entities_lock=1;
|
||||
GameLib_Compactate();
|
||||
for(i=0;i<_n_entities;i++){
|
||||
Entity e=_entity[i];
|
||||
|
||||
@@ -380,10 +385,12 @@ void GameLib_DrawLoop(void *data, float f){
|
||||
Entity_Draw(e,-game_pos[0],-game_pos[1],f);
|
||||
}
|
||||
Draw_SetColor(1,1,1,1);
|
||||
_entities_lock=1;
|
||||
if(_gamedraw){
|
||||
_gamedraw(f);
|
||||
}
|
||||
GameLib_Compactate();
|
||||
_entities_lock=0;
|
||||
|
||||
t_draw+=Time_GetTime()-time;
|
||||
|
||||
|
||||
@@ -8,6 +8,33 @@
|
||||
|
||||
#include "Util.h"
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// SolveQuadratic
|
||||
//
|
||||
// Solves a Quadratic equation using a, b and c coeficients.
|
||||
int SolveQuadratic(float a,float b,float c,float *Rmin,float *Rmax){
|
||||
float root;
|
||||
float divisor;
|
||||
float b2;
|
||||
b2=b*b;
|
||||
root=b2-4.0*a*c;
|
||||
if(root<0){
|
||||
// Complex
|
||||
return(0);
|
||||
}
|
||||
divisor=(2.0*a);
|
||||
if(fabs(divisor)==0.0f){
|
||||
// +inf -inf
|
||||
return(0);
|
||||
}
|
||||
root=sqrtf(root);
|
||||
Rmin[0]=(float)((-b-root)/divisor);
|
||||
Rmax[0]=(float)((-b+root)/divisor);
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// vec2 //
|
||||
//////////
|
||||
@@ -74,32 +101,6 @@ void vec2_orthogonalize8(vec2 v) {
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// SolveQuadratic
|
||||
//
|
||||
// Solves a Quadratic equation using a, b and c coeficients.
|
||||
int SolveQuadratic(float a,float b,float c,float *Rmin,float *Rmax){
|
||||
float root;
|
||||
float divisor;
|
||||
float b2;
|
||||
b2=b*b;
|
||||
root=b2-4.0*a*c;
|
||||
if(root<0){
|
||||
// Complex
|
||||
return(0);
|
||||
}
|
||||
divisor=(2.0*a);
|
||||
if(fabs(divisor)==0.0f){
|
||||
// +inf -inf
|
||||
return(0);
|
||||
}
|
||||
root=sqrtf(root);
|
||||
Rmin[0]=(float)((-b-root)/divisor);
|
||||
Rmax[0]=(float)((-b+root)/divisor);
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Intersec_RayUnitCircle
|
||||
//
|
||||
@@ -232,8 +233,6 @@ int Intersect_RayEdge(
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// absmod
|
||||
//
|
||||
|
||||
@@ -35,7 +35,6 @@ void vec2_orthogonalize4(vec2 v);
|
||||
void vec2_orthogonalize8(vec2 v);
|
||||
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Intersec_RayUnitCircle
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user