1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "ags/engine/ac/global_debug.h"
24 #include "ags/shared/ac/common.h"
25 #include "ags/shared/ac/character_info.h"
26 #include "ags/engine/ac/draw.h"
27 #include "ags/engine/ac/game.h"
28 #include "ags/engine/ac/game_setup.h"
29 #include "ags/shared/ac/game_setup_struct.h"
30 #include "ags/engine/ac/game_state.h"
31 #include "ags/engine/ac/global_character.h"
32 #include "ags/engine/ac/global_display.h"
33 #include "ags/engine/ac/global_room.h"
34 #include "ags/engine/ac/move_list.h"
35 #include "ags/engine/ac/properties.h"
36 #include "ags/engine/ac/sys_events.h"
37 #include "ags/engine/ac/translation.h"
38 #include "ags/engine/ac/walkable_area.h"
39 #include "ags/engine/gfx/gfxfilter.h"
40 #include "ags/engine/gui/gui_dialog.h"
41 #include "ags/shared/script/cc_options.h"
42 #include "ags/engine/debugging/debug_log.h"
43 #include "ags/engine/debugging/debugger.h"
44 #include "ags/engine/main/main.h"
45 #include "ags/shared/ac/sprite_cache.h"
46 #include "ags/shared/gfx/bitmap.h"
47 #include "ags/engine/gfx/graphics_driver.h"
48 #include "ags/engine/main/graphics_mode.h"
49 
50 namespace AGS3 {
51 
52 using namespace AGS::Shared;
53 using namespace AGS::Engine;
54 
GetRuntimeInfo()55 String GetRuntimeInfo() {
56 	DisplayMode mode = _G(gfxDriver)->GetDisplayMode();
57 	Rect render_frame = _G(gfxDriver)->GetRenderDestination();
58 	PGfxFilter filter = _G(gfxDriver)->GetGraphicsFilter();
59 	String runtimeInfo = String::FromFormat(
60 	                         "Adventure Game Studio run-time engine[ACI version %s"
61 	                         "[Game resolution %d x %d (%d-bit)"
62 	                         "[Running %d x %d at %d-bit%s%s[GFX: %s; %s[Draw frame %d x %d["
63 	                         "Sprite cache size: %d KB (limit %d KB; %d locked)",
64 	                         _G(EngineVersion).LongString.GetCStr(), _GP(game).GetGameRes().Width, _GP(game).GetGameRes().Height, _GP(game).GetColorDepth(),
65 	                         mode.Width, mode.Height, mode.ColorDepth, (_G(convert_16bit_bgr)) ? " BGR" : "",
66 	                         mode.Windowed ? " W" : "",
67 	                         _G(gfxDriver)->GetDriverName(), filter->GetInfo().Name.GetCStr(),
68 	                         render_frame.GetWidth(), render_frame.GetHeight(),
69 	                         _GP(spriteset).GetCacheSize() / 1024, _GP(spriteset).GetMaxCacheSize() / 1024, _GP(spriteset).GetLockedSize() / 1024);
70 	if (_GP(play).separate_music_lib)
71 		runtimeInfo.Append("[AUDIO.VOX enabled");
72 	if (_GP(play).want_speech >= 1)
73 		runtimeInfo.Append("[SPEECH.VOX enabled");
74 	if (get_translation_tree().size() > 0) {
75 		runtimeInfo.Append("[Using translation ");
76 		runtimeInfo.Append(get_translation_name());
77 	}
78 
79 	return runtimeInfo;
80 }
81 
script_debug(int cmdd,int dataa)82 void script_debug(int cmdd, int dataa) {
83 	if (_GP(play).debug_mode == 0) return;
84 	int rr;
85 	if (cmdd == 0) {
86 		for (rr = 1; rr < _GP(game).numinvitems; rr++)
87 			_G(playerchar)->inv[rr] = 1;
88 		update_invorder();
89 		//    Display("invorder decided there are %d items[display %d",_GP(play).inv_numorder,_GP(play).inv_numdisp);
90 	} else if (cmdd == 1) {
91 		String toDisplay = GetRuntimeInfo();
92 		Display(toDisplay.GetCStr());
93 		//    Display("shftR: %d  shftG: %d  shftB: %d", _G(_rgb_r_shift_16), _G(_rgb_g_shift_16), _G(_rgb_b_shift_16));
94 		//    Display("Remaining memory: %d kb",_go32_dpmi_remaining_virtual_memory()/1024);
95 		//Display("Play char bcd: %d",->GetColorDepth(_GP(spriteset)[_G(views)[_G(playerchar)->view].frames[_G(playerchar)->loop][_G(playerchar)->frame].pic]));
96 	} else if (cmdd == 2) {  // show walkable areas from here
97 		// TODO: support multiple viewports?!
98 		const int viewport_index = 0;
99 		const int camera_index = 0;
100 		Bitmap *tempw = BitmapHelper::CreateBitmap(_GP(thisroom).WalkAreaMask->GetWidth(), _GP(thisroom).WalkAreaMask->GetHeight());
101 		tempw->Blit(prepare_walkable_areas(-1), 0, 0, 0, 0, tempw->GetWidth(), tempw->GetHeight());
102 		const Rect &viewport = _GP(play).GetRoomViewport(viewport_index)->GetRect();
103 		const Rect &camera = _GP(play).GetRoomCamera(camera_index)->GetRect();
104 		Bitmap *view_bmp = BitmapHelper::CreateBitmap(viewport.GetWidth(), viewport.GetHeight());
105 		Rect mask_src = Rect(camera.Left / _GP(thisroom).MaskResolution, camera.Top / _GP(thisroom).MaskResolution, camera.Right / _GP(thisroom).MaskResolution, camera.Bottom / _GP(thisroom).MaskResolution);
106 		view_bmp->StretchBlt(tempw, mask_src, RectWH(0, 0, viewport.GetWidth(), viewport.GetHeight()), Shared::kBitmap_Transparency);
107 
108 		IDriverDependantBitmap *ddb = _G(gfxDriver)->CreateDDBFromBitmap(view_bmp, false, true);
109 		render_graphics(ddb, viewport.Left, viewport.Top);
110 
111 		delete tempw;
112 		delete view_bmp;
113 		_G(gfxDriver)->DestroyDDB(ddb);
114 		ags_wait_until_keypress();
115 		invalidate_screen();
116 	} else if (cmdd == 3) {
117 		int goToRoom = -1;
118 		if (_GP(game).roomCount == 0) {
119 			char inroomtex[80];
120 			sprintf(inroomtex, "!Enter new room: (in room %d)", _G(displayed_room));
121 			setup_for_dialog();
122 			goToRoom = enternumberwindow(inroomtex);
123 			restore_after_dialog();
124 		} else {
125 			setup_for_dialog();
126 			goToRoom = roomSelectorWindow(_G(displayed_room), _GP(game).roomCount, _GP(game).roomNumbers, _GP(game).roomNames);
127 			restore_after_dialog();
128 		}
129 		if (goToRoom >= 0)
130 			NewRoom(goToRoom);
131 	} else if (cmdd == 4) {
132 		if (_G(display_fps) != kFPS_Forced)
133 			_G(display_fps) = (FPSDisplayMode)dataa;
134 	} else if (cmdd == 5) {
135 		if (dataa == 0) dataa = _GP(game).playercharacter;
136 		if (_GP(game).chars[dataa].walking < 1) {
137 			Display("Not currently moving.");
138 			return;
139 		}
140 		Bitmap *tempw = BitmapHelper::CreateTransparentBitmap(_GP(thisroom).WalkAreaMask->GetWidth(), _GP(thisroom).WalkAreaMask->GetHeight());
141 		int mlsnum = _GP(game).chars[dataa].walking;
142 		if (_GP(game).chars[dataa].walking >= TURNING_AROUND)
143 			mlsnum %= TURNING_AROUND;
144 		MoveList *cmls = &_G(mls)[mlsnum];
145 		for (int i = 0; i < cmls->numstage - 1; i++) {
146 			short srcx = short((cmls->pos[i] >> 16) & 0x00ffff);
147 			short srcy = short(cmls->pos[i] & 0x00ffff);
148 			short targetx = short((cmls->pos[i + 1] >> 16) & 0x00ffff);
149 			short targety = short(cmls->pos[i + 1] & 0x00ffff);
150 			tempw->DrawLine(Line(srcx, srcy, targetx, targety), MakeColor(i + 1));
151 		}
152 
153 		// TODO: support multiple viewports?!
154 		const int viewport_index = 0;
155 		const int camera_index = 0;
156 		const Rect &viewport = _GP(play).GetRoomViewport(viewport_index)->GetRect();
157 		const Rect &camera = _GP(play).GetRoomCamera(camera_index)->GetRect();
158 		Bitmap *view_bmp = BitmapHelper::CreateBitmap(viewport.GetWidth(), viewport.GetHeight());
159 		Rect mask_src = Rect(camera.Left / _GP(thisroom).MaskResolution, camera.Top / _GP(thisroom).MaskResolution, camera.Right / _GP(thisroom).MaskResolution, camera.Bottom / _GP(thisroom).MaskResolution);
160 		view_bmp->StretchBlt(tempw, mask_src, RectWH(0, 0, viewport.GetWidth(), viewport.GetHeight()), Shared::kBitmap_Transparency);
161 
162 		IDriverDependantBitmap *ddb = _G(gfxDriver)->CreateDDBFromBitmap(view_bmp, false, true);
163 		render_graphics(ddb, viewport.Left, viewport.Top);
164 
165 		delete tempw;
166 		delete view_bmp;
167 		_G(gfxDriver)->DestroyDDB(ddb);
168 		ags_wait_until_keypress();
169 	} else if (cmdd == 99)
170 		ccSetOption(SCOPT_DEBUGRUN, dataa);
171 	else quit("!Debug: unknown command code");
172 }
173 
174 } // namespace AGS3
175