4 |
==================== |
==================== |
5 |
*/ |
*/ |
6 |
|
|
7 |
|
// KILL ME |
8 |
|
#include <stdlib.h> |
9 |
|
#include <iostream> |
10 |
|
#include <stdio.h> |
11 |
|
|
12 |
|
|
13 |
#include "renderman.h" |
#include "renderman.h" |
14 |
#include "../pods/pod.h" |
#include "../pods/pod.h" |
16 |
#include "uiscreen.h" |
#include "uiscreen.h" |
17 |
#include "uiscreen_start.h" |
#include "uiscreen_start.h" |
18 |
#include "uiscreen_main.h" |
#include "uiscreen_main.h" |
19 |
|
#include "uiscreen_bmmore.h" |
20 |
|
|
21 |
// paragui includes |
// paragui includes |
22 |
#include "paragui.h" |
#include "paragui.h" |
23 |
#include "pgapplication.h" |
#include "pgapplication.h" |
24 |
#include "pgwidget.h" |
#include "pgwidget.h" |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
#include "../core/pointerhub.h" |
#include "../core/pointerhub.h" |
29 |
|
|
46 |
|
|
47 |
// enable symlinks so we can run around the "can't go above the application's directory" problem |
// enable symlinks so we can run around the "can't go above the application's directory" problem |
48 |
app->EnableSymlinks(true); |
app->EnableSymlinks(true); |
49 |
|
|
50 |
// turn off the stupid bg |
// turn off the stupid bg |
51 |
app->EnableBackground (false); |
app->EnableBackground (false); |
52 |
|
|
53 |
// let us escape with "ESC" |
// let us escape with "ESC" |
54 |
app->SetEmergencyQuit(true); |
app->SetEmergencyQuit(true); |
55 |
|
|
56 |
// every application needs a theme (the look & feel of the widgets) |
// every application needs a theme (the look & feel of the widgets) |
57 |
app->LoadTheme("theme"); |
app->LoadTheme("theme"); |
58 |
|
|
61 |
// SDL_SWSURFACE - PG_ option to generate surface in system memory |
// SDL_SWSURFACE - PG_ option to generate surface in system memory |
62 |
app->InitScreen(XRES, YRES, 0, SDL_SWSURFACE); |
app->InitScreen(XRES, YRES, 0, SDL_SWSURFACE); |
63 |
|
|
|
|
|
|
|
|
64 |
// the master widget - every other widget is a child of this |
// the master widget - every other widget is a child of this |
65 |
master_widget = new PG_Widget(NULL, PG_Rect(0,0,XRES,YRES)); |
master_widget = new PG_Widget(NULL, PG_Rect(0,0,XRES,YRES)); |
|
|
|
66 |
master_widget->Show(); |
master_widget->Show(); |
67 |
|
|
68 |
|
//SetActiveScreen(UISCREEN_BLOTCHMAKER_MORE); |
69 |
|
SetActiveScreen(UISCREEN_START); |
70 |
|
|
71 |
/* THIS IS FOR MEMORY LEAK TESTING PURPOSES |
//for (int x= 0; x <300; x++) { |
72 |
for ( int x = 0; x <200000; x++) { |
// set the default first screen |
|
//active_screen = new UIScreen_Start(master_widget, PG_Rect(0,0,XRES,YRES)); |
|
|
//active_screen->RemoveAllChilds(); |
|
|
//active_screen->Show(); |
|
|
//delete active_screen; |
|
|
//master_widget->RemoveAllChilds(); |
|
|
|
|
|
master_widget = new PG_Widget(NULL, PG_Rect(0,0,XRES,YRES)); |
|
|
|
|
|
active_screen = new UIScreen_Main(master_widget, PG_Rect(0,0,XRES,YRES)); |
|
|
//active_screen->RemoveAllChilds(); |
|
|
//active_screen->Show(); |
|
|
delete active_screen; |
|
|
master_widget->RemoveAllChilds(); |
|
|
|
|
|
delete master_widget; |
|
|
|
|
|
} |
|
|
*/ |
|
|
|
|
|
|
|
|
// make the default first screen |
|
|
//active_screen = new UIScreen_Main(master_widget, PG_Rect(0,0,XRES,YRES)); |
|
|
//active_screen->Show(); |
|
|
|
|
|
active_screen = new UIScreen_Start(master_widget, PG_Rect(0,0,XRES,YRES));\ |
|
|
active_screen->Show(); |
|
|
|
|
73 |
|
|
74 |
|
// SetActiveScreen(UISCREEN_BLOTCHMAKER_MORE); |
75 |
|
|
76 |
|
// } |
77 |
|
|
78 |
// get going |
// get going |
79 |
app->Run(); |
app->Run(); |
83 |
|
|
84 |
RenderMan::~RenderMan(){ |
RenderMan::~RenderMan(){ |
85 |
// technically, this will never see the light of day, but just to be proper: |
// technically, this will never see the light of day, but just to be proper: |
|
delete active_screen; |
|
86 |
delete master_widget; |
delete master_widget; |
87 |
delete app; |
delete app; |
88 |
} |
} |
89 |
|
|
90 |
|
|
91 |
|
|
|
UIScreen* RenderMan::GetActiveScreen() { return active_screen; } |
|
|
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
void RenderMan::SetActiveScreen( screen_type s ) { |
void RenderMan::SetActiveScreen( screen_type s ) { |
96 |
|
/* |
97 |
|
// delete the current screen |
98 |
|
switch(active_screen) { |
99 |
|
case UISCREEN_START: |
100 |
|
delete uiscreen_start; |
101 |
|
break; |
102 |
|
case UISCREEN_NEWGAME: |
103 |
|
|
104 |
// dump the screen |
break; |
105 |
delete active_screen; |
case UISCREEN_BLOTCHMAKER_LESS: |
106 |
|
|
107 |
|
break; |
108 |
|
case UISCREEN_BLOTCHMAKER_MORE: |
109 |
|
|
110 |
// nuke the widget and recreate it again - flushes the entire widget hierarchy. DEATH TO HEATHENS! |
break; |
111 |
|
case UISCREEN_MAIN: |
112 |
|
delete uiscreen_main; |
113 |
|
break; |
114 |
|
case UISCREEN_POD_ASSEMBLY: |
115 |
|
|
116 |
|
break; |
117 |
|
case UISCREEN_POD_MANAGER: |
118 |
|
|
119 |
|
break; |
120 |
|
case UISCREEN_COMBAT: |
121 |
|
|
122 |
|
break; |
123 |
|
case UISCREEN_GAME_SETTINGS: |
124 |
|
|
125 |
|
break; |
126 |
|
case UISCREEN_POD_SWAP: |
127 |
|
|
128 |
|
break; |
129 |
|
case UISCREEN_ABOUT_AXIS: |
130 |
|
|
131 |
|
break; |
132 |
|
default: |
133 |
|
;; |
134 |
|
} |
135 |
|
|
136 |
|
*/ |
137 |
|
|
138 |
|
// theoretically, this should flush all widgets everywhere. *assumes there are no orphan widgets.* |
139 |
master_widget->RemoveAllChilds(); |
master_widget->RemoveAllChilds(); |
|
delete master_widget; |
|
|
master_widget = new PG_Widget(NULL, PG_Rect(0,0,XRES,YRES)); |
|
|
master_widget->Show(); |
|
140 |
|
|
141 |
|
|
142 |
|
// i don't think the new renderman architecture needs this anymore. it was really just a patch anyway |
143 |
|
//delete master_widget; |
144 |
|
//master_widget = new PG_Widget(NULL, PG_Rect(0,0,XRES,YRES)); |
145 |
|
//master_widget->Show(); |
146 |
|
|
147 |
|
|
148 |
|
// now initialize the new screen |
149 |
switch(s) { |
switch(s) { |
150 |
case UISCREEN_START: |
case UISCREEN_START: |
151 |
active_screen = new UIScreen_Start(master_widget, PG_Rect(0,0,XRES,YRES)); |
uiscreen_start = new UIScreen_Start(master_widget, PG_Rect(0,0,XRES,YRES)); |
152 |
|
uiscreen_start->Show(); |
153 |
break; |
break; |
154 |
case UISCREEN_NEWGAME: |
case UISCREEN_NEWGAME: |
155 |
|
|
158 |
|
|
159 |
break; |
break; |
160 |
case UISCREEN_BLOTCHMAKER_MORE: |
case UISCREEN_BLOTCHMAKER_MORE: |
161 |
|
uiscreen_bmmore = new UIScreen_BMMore(master_widget, PG_Rect(0,0,XRES,YRES)); |
162 |
|
uiscreen_bmmore->Show(); |
163 |
break; |
break; |
164 |
case UISCREEN_MAIN: |
case UISCREEN_MAIN: |
165 |
active_screen = new UIScreen_Main(master_widget, PG_Rect(0,0,XRES,YRES)); |
uiscreen_main = new UIScreen_Main(master_widget, PG_Rect(0,0,XRES,YRES)); |
166 |
|
uiscreen_main->Show(); |
167 |
break; |
break; |
168 |
case UISCREEN_POD_ASSEMBLY: |
case UISCREEN_POD_ASSEMBLY: |
169 |
|
|
177 |
case UISCREEN_GAME_SETTINGS: |
case UISCREEN_GAME_SETTINGS: |
178 |
|
|
179 |
break; |
break; |
180 |
default: |
case UISCREEN_POD_SWAP: |
181 |
|
|
182 |
;; |
break; |
183 |
|
case UISCREEN_ABOUT_AXIS: |
184 |
|
|
185 |
|
break; |
186 |
|
default: ; /*none*/ |
187 |
} |
} |
188 |
|
|
189 |
active_screen->Show(); |
|
190 |
|
// finally, set the active screen type |
191 |
|
active_screen = s; |
192 |
|
|
193 |
} |
} |
194 |
|
|
195 |
|
|
|
PG_Application* RenderMan::GetApp() { return app; } |
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
// SET FUNCTIONS |
203 |
void RenderMan::SetTileSize(int x) { |
void RenderMan::SetTileSize(int x) { |
204 |
// FIXME: Check for errors. only 32 or 64 alowed |
if (x != 32 && x != 64) {x = 32;} // default to 32 if bad arg |
205 |
tile_size = x; |
tile_size = x; |
206 |
|
|
207 |
|
uiscreen_main->GetMapWindow()->ReInitImages(); // change the SDL surfaces for the map tiles in the map window |
208 |
|
|
209 |
|
/* BROKEN |
210 |
|
// get new w/h sizes |
211 |
|
int w = themap->GetCols() - int(768/x); |
212 |
|
int h = themap->GetRows() - int(704/x); |
213 |
|
|
214 |
|
// reset slider bars |
215 |
|
uiscreen_main->GetHScroll()->SetRange(0, themap->GetCols() - w); |
216 |
|
uiscreen_main->GetVScroll()->SetRange(0, themap->GetRows() - h); |
217 |
|
|
218 |
|
// reset mapwindow's bg locator if it's out of bounds when tile size resets |
219 |
|
uiscreen_main->GetMapWindow()->SetBgX( |
220 |
|
( uiscreen_main->GetMapWindow()->GetBgX() > (themap->GetCols() - w) ) ? |
221 |
|
(themap->GetCols() - w) : |
222 |
|
uiscreen_main->GetMapWindow()->GetBgX() |
223 |
|
); |
224 |
|
uiscreen_main->GetMapWindow()->SetBgY( |
225 |
|
( uiscreen_main->GetMapWindow()->GetBgY() > (themap->GetRows() - h) ) ? |
226 |
|
(themap->GetRows() - h) : |
227 |
|
uiscreen_main->GetMapWindow()->GetBgY() |
228 |
|
); |
229 |
|
|
230 |
|
// reset sroll bar pos. |
231 |
|
uiscreen_main->GetHScroll()->SetPosition( uiscreen_main->GetMapWindow()->GetBgX() ); |
232 |
|
uiscreen_main->GetVScroll()->SetPosition( uiscreen_main->GetMapWindow()->GetBgY() ); |
233 |
|
*/ |
234 |
} |
} |
235 |
|
|
236 |
|
|
|
int RenderMan::GetTileSize() { return tile_size; } |
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
// GET FUNCIONS |
241 |
|
PG_Application* RenderMan::GetApp() { return app; } |
242 |
|
int RenderMan::GetTileSize() { return tile_size; } |
243 |
int RenderMan::GetXRes() { return XRES; } |
int RenderMan::GetXRes() { return XRES; } |
244 |
int RenderMan::GetYRes() { return YRES; } |
int RenderMan::GetYRes() { return YRES; } |
245 |
|
|
249 |
|
|
250 |
|
|
251 |
// ------- LOCKING ------- |
// ------- LOCKING ------- |
252 |
void RenderMan::SLock(SDL_Surface *screen) { |
void RenderMan::SLock(SDL_Surface *s) { |
253 |
if ( SDL_MUSTLOCK(screen) ) { |
if ( SDL_MUSTLOCK(s) ) { |
254 |
if ( SDL_LockSurface(screen) < 0 ) { return; } |
if ( SDL_LockSurface(s) < 0 ) { return; } |
255 |
} |
} |
256 |
} |
} |
257 |
|
|
258 |
void RenderMan::SUnlock(SDL_Surface *screen) { |
void RenderMan::SUnlock(SDL_Surface *s) { |
259 |
if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } |
if ( SDL_MUSTLOCK(s) ) { SDL_UnlockSurface(s); } |
260 |
} |
} |
261 |
// ------------------------- |
// ------------------------- |
262 |
|
|
264 |
|
|
265 |
|
|
266 |
|
|
|
|
|
|
|
|
267 |
// Basic drawing functions -----------------\/------------------- |
// Basic drawing functions -----------------\/------------------- |
268 |
|
|
269 |
// draws a whole image to a surface |
// draws a whole image to a surface |
288 |
dest2.h = h; |
dest2.h = h; |
289 |
SDL_BlitSurface(from, &dest, to, &dest2); |
SDL_BlitSurface(from, &dest, to, &dest2); |
290 |
} |
} |
291 |
|
|
292 |
|
|
293 |
|
// draws a pixel of specified RGB value onto a surface |
294 |
|
void RenderMan::DrawPixel(SDL_Surface *s, int x, int y, Uint8 R, Uint8 G, Uint8 B, Uint8 A) { |
295 |
|
Uint32 color = SDL_MapRGBA(s->format, R, G, B, A); |
296 |
|
switch (s->format->BytesPerPixel) { |
297 |
|
case 1: {// Assuming 8-bpp |
298 |
|
Uint8 *bufp; |
299 |
|
bufp = (Uint8 *)s->pixels + y*s->pitch + x; |
300 |
|
*bufp = color; |
301 |
|
break; |
302 |
|
} |
303 |
|
case 2: {// Probably 15-bpp or 16-bpp |
304 |
|
Uint16 *bufp; |
305 |
|
bufp = (Uint16 *)s->pixels + y*s->pitch/2 + x; |
306 |
|
*bufp = color; |
307 |
|
break; |
308 |
|
} |
309 |
|
case 3: {// Slow 24-bpp mode, usually not used |
310 |
|
Uint8 *bufp; |
311 |
|
bufp = (Uint8 *)s->pixels + y*s->pitch + x * 3; |
312 |
|
if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { |
313 |
|
bufp[0] = color; |
314 |
|
bufp[1] = color >> 8; |
315 |
|
bufp[2] = color >> 16; |
316 |
|
} |
317 |
|
else { |
318 |
|
bufp[2] = color; |
319 |
|
bufp[1] = color >> 8; |
320 |
|
bufp[0] = color >> 16; |
321 |
|
} |
322 |
|
break; |
323 |
|
} |
324 |
|
case 4: {// Probably 32-bpp |
325 |
|
Uint32 *bufp; |
326 |
|
bufp = (Uint32 *)s->pixels + y*s->pitch/4 + x; |
327 |
|
*bufp = color; |
328 |
|
break; |
329 |
|
} |
330 |
|
} |
331 |
|
} |
332 |
|
|
333 |
|
|
334 |
|
|
335 |
// Basic drawing functions ---------------/\--------------------- |
// Basic drawing functions ---------------/\--------------------- |
336 |
|
|
337 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
// INTERFACE (WRAPPER) FUNCTIONS -----------------\/------------------- |
348 |
|
void RenderMan::MovePod(int x1, int y1, int x2, int y2) { |
349 |
|
uiscreen_main->GetMapWindow()->MovePod(x1, y1, x2, y2); |
350 |
|
//uiscreen_main->GetMiniMap()->DrawMap(); |
351 |
|
} |
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
// INTERFACE (WRAPPER) FUNCTIONS -----------------/\------------------- |
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
|
366 |
// CALLBACKS |
// CALLBACKS |
367 |
|
|
368 |
/* \/ these are custom callbacks that have no return. keep them just in case |
/* \/ these are custom callbacks that have no return. keep them just in case |
377 |
|
|
378 |
|
|
379 |
PARAGUI_CALLBACK(RenderMan::handle_start_new) { |
PARAGUI_CALLBACK(RenderMan::handle_start_new) { |
380 |
|
// set any map pointers needed here since we know the map has been "finalized" |
381 |
|
Mission::SetMapPointer(*themap); |
382 |
SetActiveScreen(UISCREEN_MAIN); |
SetActiveScreen(UISCREEN_MAIN); |
383 |
return true; |
return true; |
384 |
} |
} |
387 |
PARAGUI_CALLBACK(RenderMan::handle_go_to_start) { |
PARAGUI_CALLBACK(RenderMan::handle_go_to_start) { |
388 |
SetActiveScreen(UISCREEN_START); |
SetActiveScreen(UISCREEN_START); |
389 |
return true; |
return true; |
390 |
} |
} |
|
|
|
391 |
|
|
392 |
|
PARAGUI_CALLBACK(RenderMan::handle_go_to_bm) { |
393 |
|
SetActiveScreen(UISCREEN_BLOTCHMAKER_MORE); |
394 |
|
return true; |
395 |
|
} |
396 |
|
|
397 |
|
PARAGUI_CALLBACK(RenderMan::handle_swap_tilesets) { |
398 |
|
if (tile_size == 64) {SetTileSize(32);} else {SetTileSize(64);} |
399 |
|
uiscreen_main->Update(); |
400 |
|
return true; |
401 |
|
} |
402 |
|
|
403 |
|
|