original 1.0.1 release
[xwelltris.git] / src / wellengine.cxx
blob2e474ae4f3efb5631eae208866d52dea2dca8555
1 // docm_prefix(///)
2 /****************************************************************************
3 * Copyright (C) 2002 by Leo Khramov
4 * email: leo@xnc.dubna.su
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 ****************************************************************************/
16 // $Id: wellengine.cxx,v 1.2 2003/02/18 17:01:30 leo Exp $
18 /// module description
19 /// WellEngine is a game engine that contains basic game routins for drawing,
20 /// processing events, makeing queues of object, delivering events to them,
21 /// timeouting with given threshold, loading images needed for the game
22 /// and more
24 #include "wellengine.h"
25 #include "wellclass.h"
27 WellEngine *default_well_engine=0;
29 //===========================================================================
30 /// global WellEngine()
31 /// Constructor of the class - init display size
32 /// tags WellEngine
33 WellEngine::WellEngine(int argc, char** argv)
35 mainl=800;
36 mainh=600;
39 WellEngine::~WellEngine()
43 //===========================================================================
44 /// global process_time_event()
45 /// go throuht the list of time objects, decsrease ticks_left and call
46 /// objects on timeout
47 /// tags WellEngine
48 bool WellEngine::process_time_event()
50 bool processed=false;
51 TimeList* ptimelist=timelist.get_next();
52 while(ptimelist)
54 TimeObject& obj=ptimelist->get_object();
55 obj.ticks_left--;
56 if(obj.ticks_left<=0)
58 processed=true;
59 obj.restart_ticks();
60 if(!obj.obj->process_event(wEvent(eTimeOut)))
61 //if we return false -> don't process any objects
62 break;
64 ptimelist=ptimelist->get_next();
66 return processed;
69 //===========================================================================
70 /// global add_timer(WellObject*, int N_ticks)
71 /// add object to time list for ticking every N_ticks
72 /// tags WellEngine
73 bool WellEngine::add_timer(WellObject* wo, int ticks)
75 TimeObject obj(wo,ticks);
76 TimeList *ptobject=new TimeList(obj);
77 timelist.add(ptobject);
78 return true;
81 //===========================================================================
82 /// global del_timer(WellObject*)
83 /// delete object from time list
84 /// tags WellEngine
85 bool WellEngine::del_timer(WellObject* wo)
87 TimeObject obj(wo);
88 TimeList *plist=timelist.del(obj);
89 if(plist)
91 delete plist;
92 return true;
94 return false;
97 //===========================================================================
98 /// global new_well_drawing_engine()
99 /// creates drawing engine for well board - must be overloaded in childs
100 /// tags WellEngine
101 WellDrawingEngine* WellEngine::new_well_drawing_engine()
103 return 0;
107 //===========================================================================
108 /// global process_event_for_all(wEvent)
109 /// go throuht the list of objects, and call process_event for each
110 /// if object return false -> break the loop
111 /// tags WellEngine
112 bool WellEngine::process_event_for_all(wEvent ev)
114 bool processed=true;
115 ObjectList* plist=objectlist.get_next();
116 while(plist)
118 if(!plist->get_object()->process_event(ev))
119 //if we return false -> don't process any objects
120 return false;
121 plist=plist->get_next();
123 return processed;
126 //===========================================================================
127 /// global add_object(WellObject*)
128 /// add object to list of objects that want events
129 /// tags WellEngine
130 bool WellEngine::add_object(WellObject* wo)
132 ObjectList *ptobject=new ObjectList(wo);
133 objectlist.add(ptobject);
134 return true;
137 //===========================================================================
138 /// global del_object(WellObject*, int N_ticks)
139 /// delete object from list of objects that want events
140 /// tags WellEngine
141 bool WellEngine::del_object(WellObject* wo)
143 ObjectList *plist=objectlist.del(wo);
144 if(plist)
146 delete plist;
147 return true;
149 return false;
152 //===========================================================================
153 /// global clear_objectlist()
154 /// clear all list of objects
155 /// tags WellEngine
156 void WellEngine::clear_objectlist()
158 ObjectList *plist;
161 plist=objectlist.get_next();
162 if(plist)
164 plist->del_self();
165 delete plist;
167 } while(plist);
170 //===========================================================================
171 /// global load_images()
172 /// load all images for the game
173 /// tags WellEngine
174 void WellEngine::load_images()
176 fprintf(stderr, "Loading resources..");
177 load_image(imBoardBG, "board2.gif");
178 fprintf(stderr, "..");
179 load_image(imFont1, "font2.gif");
180 fprintf(stderr, "..");
181 load_image(imIntroBG, "wellintro.gif");
182 fprintf(stderr, "..");
183 load_image(imScoreBG, "topnine.gif");
184 fprintf(stderr, "..");
185 load_image(imCuts, "wellcuts.gif");
186 fprintf(stderr, "..done\n");
189 //===========================================================================
190 /// global new_well_intro()
191 /// creates new introduction object - version for SDL Window
192 /// tags WellEngine
193 WellIntro* WellEngine::new_well_intro()
195 return new WellIntro;
198 //===========================================================================
199 /// global new_well_top_nine()
200 /// creates new top nine object
201 /// tags WellEngine
202 WellTopNine* WellEngine::new_well_top_nine()
204 return new WellTopNine;
208 //===========================================================================
209 /// global new_well_key(char*)
210 /// creates new key object
211 /// tags WellEngine
212 WellKey* WellEngine::new_well_key(char* name)
214 return new WellKey(name);
217 //===========================================================================
218 /// global new_well_switch(char*)
219 /// creates new switch object
220 /// tags WellEngine
221 WellSwitch* WellEngine::new_well_switch(char* name)
223 return new WellSwitch(name);
227 //===========================================================================
228 /// global new_well_base()
229 /// creates new game object
230 /// tags WellEngine
231 WellBase* WellEngine::new_well_base()
233 return new WellBase;