Skip to content

Commit

Permalink
some more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
grum committed Sep 2, 2005
1 parent 45539a4 commit 3ae14a4
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 100 deletions.
111 changes: 60 additions & 51 deletions 3d_objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int no_near_blended_3d_objects=0;

int regenerate_near_objects=1;

e3d_object * load_e3d(char *file_name);
e3d_object *load_e3d (const char *file_name);
void compute_clouds_map(object3d * object_id);

void draw_3d_object(object3d * object_id)
Expand All @@ -30,7 +30,7 @@ void draw_3d_object(object3d * object_id)
e3d_array_uv_detail *clouds_uv;
e3d_array_order *array_order;

GLint * vbo;
GLuint *vbo;

int is_transparent;
int is_ground;
Expand Down Expand Up @@ -177,18 +177,19 @@ void draw_3d_object(object3d * object_id)

//Tests to see if an e3d object is already loaded. If it is, return the handle.
//If not, load it, and return the handle
e3d_object * load_e3d_cache(char * file_name)
e3d_object *load_e3d_cache (const char * file_name)
{
e3d_object * e3d_id;
e3d_object *e3d_id;

//do we have it already?
e3d_id=cache_find_item(cache_e3d, file_name);
if(e3d_id) return(e3d_id);
e3d_id = cache_find_item (cache_e3d, file_name);
if (e3d_id != NULL) return e3d_id;

//e3d not found in the cache, so load it, and store it
e3d_id=load_e3d(file_name);
if(e3d_id==NULL) return NULL;
e3d_id = load_e3d (file_name);
if (e3d_id == NULL) return NULL;
//and remember it
e3d_id->cache_ptr=cache_add_item(cache_e3d, e3d_id->file_name, e3d_id, sizeof(*e3d_id));
e3d_id->cache_ptr = cache_add_item (cache_e3d, e3d_id->file_name, e3d_id, sizeof(*e3d_id));

return e3d_id;
}
Expand All @@ -212,7 +213,7 @@ int add_e3d_at_id (int id, const char *file_name, float x_pos, float y_pos, floa
}

//convert any '\' in '/'
clean_file_name(fname, file_name, 128);
clean_file_name (fname, file_name, 128);
my_tolower(fname);

returned_e3d=load_e3d_cache(fname);
Expand Down Expand Up @@ -335,59 +336,67 @@ void add_near_3d_object(int dist, float radius, int pos, int blended )//Blended

int get_near_3d_objects()
{
int sx, sy, ex, ey;
int x,y;
int i,j,k;
actor * xxx=pf_get_our_actor();
if(!xxx)return 0;
no_near_3d_objects=0;
no_near_blended_3d_objects=0;
first_near_3d_object=NULL;
first_near_blended_3d_object=NULL;
int sx, sy, ex, ey;
float x, y;
int i, j, k;
actor *xxx = pf_get_our_actor ();

if (xxx == NULL) return 0;

no_near_3d_objects = 0;
no_near_blended_3d_objects = 0;
first_near_3d_object = NULL;
first_near_blended_3d_object = NULL;

x=-cx;
y=-cy;
x = -cx;
y = -cy;

get_supersector(SECTOR_GET(xxx->x_pos,xxx->y_pos), &sx, &sy, &ex, &ey);
for(i=sx;i<=ex;i++)
for(j=sy;j<=ey;j++)
for(k=0;k<MAX_3D_OBJECTS;k++){
object3d *object_id;
int l=sectors[(j*(tile_map_size_x>>2))+i].e3d_local[k];
if(l==-1)break;
object_id= objects_list[l];

if(object_id && object_id->blended!=20) {
int dist1, dist2;
int dist;

dist1= x-object_id->x_pos;
dist2= y-object_id->y_pos;
dist=dist1*dist1+dist2*dist2;
if(dist<=35*35){
get_supersector (SECTOR_GET (xxx->x_pos, xxx->y_pos), &sx, &sy, &ex, &ey);
for (i = sx; i <= ex; i++)
{
for (j = sy; j <= ey; j++)
{
for (k = 0; k < MAX_3D_OBJECTS; k++)
{
object3d *object_id;
int l = sectors[(j*(tile_map_size_x>>2))+i].e3d_local[k];
if (l == -1) break;
object_id = objects_list[l];

if (object_id != NULL && object_id->blended != 20)
{
float dist1, dist2;
float dist;

dist1 = x - object_id->x_pos;
dist2 = y - object_id->y_pos;
dist = dist1*dist1 + dist2*dist2;
if (dist <= 35*35)
{
float x_len, y_len, z_len;
float radius;

z_len= object_id->e3d_data->max_z-object_id->e3d_data->min_z;
x_len= object_id->e3d_data->max_x-object_id->e3d_data->min_x;
y_len= object_id->e3d_data->max_y-object_id->e3d_data->min_y;
//do some checks, to see if we really have to display this object
radius=x_len/2;
if(radius<y_len/2)radius=y_len/2;
if(radius<z_len)radius=z_len;
radius = x_len / 2;
if (radius < y_len/2) radius = y_len / 2;
if (radius < z_len) radius = z_len;
//not in the middle of the air
if(SphereInFrustum(object_id->x_pos, object_id->y_pos, object_id->z_pos, radius)){
add_near_3d_object(dist, radius, l,object_id->blended);
if (SphereInFrustum (object_id->x_pos, object_id->y_pos, object_id->z_pos, radius))
{
add_near_3d_object (dist, radius, l, object_id->blended);
}
}
}
}
}
}

regenerate_near_objects=0;
regenerate_near_objects = 0;

return 1;
return 1;
}

void display_objects()
Expand Down Expand Up @@ -506,7 +515,7 @@ void display_blended_objects()
CHECK_GL_ERRORS();
}

e3d_object * load_e3d(char *file_name)
e3d_object *load_e3d (const char *file_name)
{
int vertex_no,faces_no,materials_no;
FILE *f = NULL;
Expand Down Expand Up @@ -848,9 +857,9 @@ void compute_clouds_map(object3d * object_id)
//y_rot=object_id->y_rot;
z_rot=object_id->z_rot;

m=(-z_rot)*3.1415926/180;
cos_m=cos(m);
sin_m=sin(m);
m = -z_rot * 3.1415926f / 180;
cos_m = cos(m);
sin_m = sin(m);

for(i=0;i<face_no*3;i++)
{
Expand Down
13 changes: 7 additions & 6 deletions asc.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ void my_strcp(Uint8 *dest,const Uint8 * source)
*dest='\0';
}

void my_strncp(Uint8 *dest,const Uint8 * source, Sint32 len)
void my_strncp (char *dest, const char *source, Uint32 len)
{
while(*source && --len > 0)
{
*dest++=*source++;
}
*dest='\0';
if (len == 0) return;

while (*source != '\0' && --len > 0)
*dest++ = *source++;

*dest = '\0';
}

void my_strcat(Uint8 *dest,const Uint8 * source)
Expand Down
2 changes: 1 addition & 1 deletion asc.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void my_strcp(Uint8 *dest,const Uint8 * source);
* \param source The source char array
* \param len The number of bytes you wish to copy
*/
void my_strncp(Uint8 *dest,const Uint8 * source,Sint32 len);
void my_strncp (char *dest, const char *source, Uint32 len);

/*!
* \ingroup misc_utils
Expand Down
53 changes: 28 additions & 25 deletions cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,27 +250,29 @@ void cache_use(cache_struct *cache, cache_item_struct *item_ptr)
}
}

cache_item_struct *cache_find(cache_struct *cache, const Uint8 *name)
cache_item_struct *cache_find (cache_struct *cache, const char *name)
{
Sint32 i;
Sint32 i;

if(!cache->cached_items) return 0;
if (cache->cached_items == NULL) return 0;
// quick check for the most recent item
if(cache->recent_item && cache->recent_item->name && !strcmp(cache->recent_item->name, name))
{
cache_use(cache, cache->recent_item);
return(cache->recent_item);
}
if (cache->recent_item != NULL && cache->recent_item->name != NULL && strcmp (cache->recent_item->name, name) == 0)
{
cache_use(cache, cache->recent_item);
return(cache->recent_item);
}

// not the most recent, then scan the list
for(i=0; i<cache->max_item; i++)
for (i = 0; i < cache->max_item; i++)
{
if (cache->cached_items[i] != NULL && cache->cached_items[i]->name != NULL && strcmp (cache->cached_items[i]->name, name) == 0)
{
if(cache->cached_items[i] && cache->cached_items[i]->name && !strcmp(cache->cached_items[i]->name, name))
{
cache_use(cache, cache->cached_items[i]);
cache->recent_item= cache->cached_items[i];
return(cache->cached_items[i]);
}
cache_use (cache, cache->cached_items[i]);
cache->recent_item = cache->cached_items[i];
return cache->cached_items[i];
}
}

return NULL;
}

Expand All @@ -297,18 +299,19 @@ cache_item_struct *cache_find_ptr(cache_struct *cache, const void *item)
return NULL;
}

void *cache_find_item(cache_struct *cache, const Uint8 *name)
void *cache_find_item (cache_struct *cache, const char *name)
{
cache_item_struct *item_ptr;
cache_item_struct *item_ptr;

if(!cache->cached_items) return NULL;
item_ptr= cache_find(cache, name);
if(item_ptr)
{
//cache_use(cache, item_ptr);
return(item_ptr->cache_item);
}
return(NULL);
if (cache->cached_items == NULL) return NULL;
item_ptr = cache_find (cache, name);
if (item_ptr != NULL)
{
//cache_use(cache, item_ptr);
return item_ptr->cache_item;
}

return NULL;
}

cache_item_struct *cache_add_item(cache_struct *cache, Uint8 *name, void *item, Uint32 size)
Expand Down
2 changes: 1 addition & 1 deletion cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void cache_use(cache_struct *cache, cache_item_struct *item);
* \retval void* a pointer to the cache item given by \a name
* \callgraph
*/
void *cache_find_item(cache_struct *cache, const Uint8 *name);
void *cache_find_item (cache_struct *cache, const char *name);

void cache_delete(cache_struct *cache);

Expand Down
2 changes: 1 addition & 1 deletion e3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ typedef struct
char is_transparent; /*!< flag determining whether this object is transparent or not */
char is_ground; /*!< flag determining whether this is a ground object or not */

cache_item_struct *cache_ptr; /*!< pointer to a cache item. If this is !=NULL, this points to a valid cached item of this object */
cache_item_struct *cache_ptr; /*!< pointer to a cache item. If this is !=NULL, this points to a valid cached item of this object */
char file_name[128]; /*!< filename where this object is stored. */
}e3d_object;

Expand Down
27 changes: 14 additions & 13 deletions errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

FILE* open_log (const char *fname, const char *mode)
{
FILE *file = fopen (fname, mode);
FILE *file = fopen (fname, mode);
Uint8 starttime[200];
struct tm *l_time; time_t c_time;
if (!file)
{
fprintf (stderr, "Unable to open log file \"%s\"\n", fname);
exit (1);
}
time(&c_time);
l_time = localtime(&c_time);
strftime(starttime, sizeof(starttime), "\n\nLog started at %Y-%m-%d %H:%M:%S\n\n", l_time);
if (file == NULL)
{
fprintf (stderr, "Unable to open log file \"%s\"\n", fname);
exit (1);
}
time (&c_time);
l_time = localtime (&c_time);
strftime (starttime, sizeof(starttime), "\n\nLog started at %Y-%m-%d %H:%M:%S\n\n", l_time);
fwrite (starttime, strlen(starttime), 1, file);
return file;
}
Expand All @@ -33,17 +33,18 @@ void clear_error_log()
fflush (err_file);
}

void log_error(const Uint8 * message, ...)
void log_error (const char* message, ...)
{
va_list ap;

if(err_file == NULL) {
if(err_file == NULL)
{
char error_log[256];
snprintf(error_log, sizeof(error_log), "%serror_log.txt", configdir);
snprintf (error_log, sizeof(error_log), "%serror_log.txt", configdir);
err_file = open_log (error_log, "a");
}
va_start(ap, message);
vfprintf(err_file, message, ap);
vfprintf (err_file, message, ap);
va_end(ap);
fprintf (err_file, "\n");
fflush (err_file);
Expand Down
2 changes: 1 addition & 1 deletion errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void clear_error_log();
*
* \param message the message to log
*/
void log_error(const Uint8 *message, ...);
void log_error(const char *message, ...);

/*!
* \ingroup misc_utils
Expand Down
2 changes: 1 addition & 1 deletion text.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,6 @@ int rewrap_message(text_message * buf, float zoom, int width, int * cursor);

void cleanup_text_buffers(void);

#define LOG_TO_CONSOLE(color,buffer) put_colored_text_in_buffer(color,CHAT_SERVER,buffer,-1) /*!< logs the text in buffer with the specified color to the console. */
#define LOG_TO_CONSOLE(color,buffer) put_colored_text_in_buffer(color,CHAT_SERVER,(const Uint8*)buffer,-1) /*!< logs the text in buffer with the specified color to the console. */

#endif

0 comments on commit 3ae14a4

Please sign in to comment.