00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "revolt.h"
00018 #ifndef _PSX
00019 #include "main.h"
00020 #endif
00021 #include "geom.h"
00022 #include "particle.h"
00023 #include "model.h"
00024 #include "aerial.h"
00025 #include "newcoll.h"
00026 #include "body.h"
00027 #include "car.h"
00028 #ifndef _PSX
00029 #include "ctrlread.h"
00030 #endif
00031 #include "object.h"
00032 #include "field.h"
00033 #ifdef _N64
00034 #include "spark.h"
00035 #endif
00036
00037
00038
00039
00040
00041 static OBJECT *s_NextFreeObj;
00042
00043
00044
00045
00046
00047 OBJECT *OBJ_ObjectList;
00048 OBJECT *OBJ_ObjectHead = NULL;
00049 OBJECT *OBJ_ObjectTail = NULL;
00050
00051 long OBJ_NumObjects;
00052
00053
00054 PAIRCOLLINFO OBJ_PairCollInfo[MAX_OBJECTS][MAX_OBJECTS];
00055
00056
00057
00058
00059
00060 long OBJ_InitObjSys(void);
00061 void OBJ_KillObjSys(void);
00062 OBJECT *OBJ_AllocObject(void);
00063 OBJECT *OBJ_ReplaceObject(void);
00064 long OBJ_FreeObject(OBJECT *Obj);
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 long OBJ_InitObjSys(void)
00075 {
00076 long ii;
00077
00078 OBJ_ObjectList = (OBJECT *)malloc(sizeof(OBJECT) * MAX_OBJECTS);
00079 s_NextFreeObj = OBJ_ObjectList;
00080
00081 OBJ_ObjectList[0].prev = NULL;
00082 OBJ_ObjectList[0].next = &(OBJ_ObjectList[1]);
00083
00084 for (ii = 1; ii < (MAX_OBJECTS - 1); ii++)
00085 {
00086 OBJ_ObjectList[ii].prev = &(OBJ_ObjectList[ii - 1]);
00087 OBJ_ObjectList[ii].next = &(OBJ_ObjectList[ii + 1]);
00088 }
00089
00090 OBJ_ObjectList[MAX_OBJECTS - 1].prev = &(OBJ_ObjectList[MAX_OBJECTS - 2]);
00091 OBJ_ObjectList[MAX_OBJECTS - 1].next = NULL;
00092
00093
00094 for (ii = 0; ii < MAX_OBJECTS; ii++) {
00095 OBJ_ObjectList[ii].ObjID = ii;
00096 }
00097
00098
00099 ClearAllPairInfo();
00100
00101
00102 OBJ_NumObjects = 0;
00103 OBJ_ObjectHead = NULL;
00104 OBJ_ObjectTail = NULL;
00105
00106 return(1);
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 void OBJ_KillObjSys(void)
00118 {
00119 if (OBJ_ObjectList != NULL)
00120 {
00121 while (OBJ_ObjectHead)
00122 {
00123 OBJ_FreeObject(OBJ_ObjectHead);
00124 }
00125
00126 free(OBJ_ObjectList);
00127 }
00128
00129 OBJ_ObjectList = NULL;
00130 OBJ_ObjectHead = NULL;
00131 OBJ_ObjectTail = NULL;
00132 s_NextFreeObj = NULL;
00133
00134 OBJ_NumObjects = 0;
00135 }
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 OBJECT *OBJ_AllocObject(void)
00146 {
00147 OBJECT *newobj;
00148
00149 newobj = s_NextFreeObj;
00150 if (newobj == NULL)
00151 {
00152 return(NULL);
00153 }
00154
00155 s_NextFreeObj = s_NextFreeObj->next;
00156 if (s_NextFreeObj != NULL)
00157 {
00158 s_NextFreeObj->prev = NULL;
00159 }
00160
00161 newobj->prev = OBJ_ObjectTail;
00162
00163 if (OBJ_ObjectHead == NULL)
00164 {
00165 OBJ_ObjectHead = newobj;
00166 }
00167 else
00168 {
00169 OBJ_ObjectTail->next = newobj;
00170 }
00171 OBJ_ObjectTail = newobj;
00172
00173 newobj->next = NULL;
00174
00175
00176 newobj->player = NULL;
00177 newobj->objref = NULL;
00178 newobj->creator = NULL;
00179 newobj->flag.IsInGrid = 0;
00180 newobj->Data = NULL;
00181 newobj->Field = NULL;
00182 newobj->FieldPriority = FIELD_PRIORITY_MIN;
00183 #ifndef _PSX
00184 newobj->SparkGen = NULL;
00185 newobj->Light = NULL;
00186 #endif
00187 #ifdef _PC
00188 newobj->Sfx3D = NULL;
00189 #endif
00190 newobj->movehandler = NULL;
00191 newobj->collhandler = NULL;
00192 newobj->aihandler = NULL;
00193 newobj->renderhandler = NULL;
00194 newobj->freehandler = NULL;
00195
00196
00197 ClearThisObjPairInfo(newobj);
00198
00199 OBJ_NumObjects++;
00200 return(newobj);
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 OBJECT *OBJ_ReplaceObject(void)
00215 {
00216 OBJECT *newobj = NULL;
00217 long found = 0;
00218
00219 newobj = OBJ_ObjectTail;
00220
00221 #if 0
00222 while ((!found) && (newobj != NULL))
00223 {
00224 switch(newobj->type)
00225 {
00226 case TYPE_EYECANDY:
00227 case TYPE_PICKUP:
00228 found = 1;
00229 break;
00230
00231 default:
00232 newobj = newobj->prev;
00233 break
00234 }
00235 }
00236
00237 #ifndef _PSX
00238 GRD_RemoveObject(newobj);
00239 #endif
00240
00241 return(newobj);
00242 #else
00243 return(NULL);
00244 #endif
00245 }
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 long OBJ_FreeObject(OBJECT *Obj)
00256 {
00257
00258
00259 FreeCollSkin(&Obj->body.CollSkin);
00260 if (Obj->freehandler)
00261 {
00262 Obj->freehandler(Obj);
00263 }
00264
00265 #ifndef _PSX
00266
00267 if (Obj->SparkGen)
00268 {
00269
00270 Obj->SparkGen = NULL;
00271 }
00272
00273 #ifdef _PC
00274 if (Obj->Sfx3D)
00275 {
00276 FreeSfx3D(Obj->Sfx3D);
00277 }
00278 #endif
00279
00280 if (Obj->Light)
00281 {
00282 FreeLight(Obj->Light);
00283 }
00284
00285 #endif
00286
00287 if (Obj->Data)
00288 {
00289 free(Obj->Data);
00290 Obj->Data = NULL;
00291 }
00292
00293 if (Obj->Field)
00294 {
00295 RemoveField(Obj->Field);
00296 Obj->Field = NULL;
00297 }
00298
00299
00300 FreeCollSkin(&Obj->body.CollSkin);
00301 if (IsBodySphere(&Obj->body)) {
00302 free(Obj->body.CollSkin.Sphere);
00303 Obj->body.CollSkin.Sphere = NULL;
00304 Obj->body.CollSkin.NSpheres = 0;
00305 }
00306
00307 #ifndef _PSX
00308 GRD_RemoveObject(Obj);
00309 #endif
00310
00311
00312 Obj->renderhandler = NULL;
00313 Obj->movehandler = NULL;
00314 Obj->collhandler = NULL;
00315 Obj->aihandler = NULL;
00316 Obj->freehandler = NULL;
00317
00318
00319 if (Obj->prev != NULL)
00320 {
00321 (Obj->prev)->next = Obj->next;
00322 }
00323 else
00324 {
00325 OBJ_ObjectHead = Obj->next;
00326 }
00327
00328 if (Obj->next != NULL)
00329 {
00330 (Obj->next)->prev = Obj->prev;
00331 }
00332 else
00333 {
00334 OBJ_ObjectTail = Obj->prev;
00335 }
00336
00337
00338 if (s_NextFreeObj != NULL)
00339 {
00340 s_NextFreeObj->prev = Obj;
00341 }
00342
00343 Obj->next = s_NextFreeObj;
00344 Obj->prev = NULL;
00345 s_NextFreeObj = Obj;
00346
00347 OBJ_NumObjects--;
00348
00349 return(1);
00350 }
00351
00353
00354
00355
00357 void ClearThisObjPairInfo(OBJECT *obj2)
00358 {
00359 OBJECT *obj1;
00360
00361 for (obj1 = OBJ_ObjectHead; obj1 != NULL; obj1 = obj1->next) {
00362
00363 ClearPairInfo(obj1, obj2);
00364
00365 }
00366 }
00367
00368 void ClearActivePairInfo()
00369 {
00370 OBJECT *obj1, *obj2;
00371
00372 for (obj1 = OBJ_ObjectHead; obj1 != NULL; obj1 = obj1->next) {
00373 for (obj2 = obj1->next; obj2 != NULL; obj2 = obj2->next) {
00374
00375 ClearPairInfo(obj1, obj2);
00376
00377 }
00378 }
00379 }
00380
00381 void ClearAllPairInfo()
00382 {
00383 int ii, jj;
00384
00385 for (ii = 0; ii < MAX_OBJECTS; ii++) {
00386 for (jj = 0; jj < MAX_OBJECTS; jj++) {
00387
00388 ClearPairInfo(&OBJ_ObjectList[ii], &OBJ_ObjectList[jj]);
00389
00390 }
00391 }
00392 }