source: golgotha/src/golg/remove_man.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.1 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "error/error.hh"
10#include "remove_man.hh"
11#include "g1_object.hh"
12
13const int MAX_REMOVES = 100;
14
15g1_remove_manager_class g1_remove_man;
16 
17
18void g1_remove_manager_class::request_remove(g1_object_class *obj)
19{
20  if (obj->get_flag(g1_object_class::MAP_OCCUPIED))
21    i4_error("deleted object while still on map");
22
23  if (!g1_global_id.check_id(obj->global_id))
24    i4_error("removing a piece with invalid id (name=%s)!", obj->name());
25
26  obj->flags |= g1_object_class::DELETED;
27
28  if (obj->flags & g1_object_class::THINKING)
29    obj->stop_thinking();
30 
31  if (removes<MAX_REMOVES)
32  {
33    remove_list[removes] = obj;
34    removes++;
35  }
36}
37
38void g1_remove_manager_class::init()
39{
40  remove_list =
41    (g1_object_class**)i4_malloc( MAX_REMOVES*sizeof(g1_object_class*), "remove_list" );
42
43  I4_ASSERT(remove_list,
44            "g1_remove_manager_class - Couldn't create removal list!");
45
46  removes = 0;
47}
48
49
50void g1_remove_manager_class::uninit()
51{
52  I4_TEST(removes==0, "g1_remove_manager - Not all removals processed!");
53
54  i4_free(remove_list);
55}
56
57
58
59void g1_remove_manager_class::process_requests()
60{
61  I4_ASSERT(removes<MAX_REMOVES,
62            "g1_remove_manager - Removes previously exceeded maximum removes");
63
64  for (w32 j=0; j<removes; j++)
65  {
66    i4_isl_list<g1_reference_class> *ref_list = &remove_list[j]->ref_list;
67
68    while (!ref_list->empty())
69    {
70      i4_isl_list<g1_reference_class>::iterator i=ref_list->begin();     
71      ref_list->erase();
72
73      i->ref = 0;
74    }
75
76    delete remove_list[j];
77  }
78  removes = 0;
79}
80
Note: See TracBrowser for help on using the repository browser.