File: qd_game_dispatcher_base.h

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (165 lines) | stat: -rw-r--r-- 4,668 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef QDENGINE_QDCORE_QD_GAME_DISPATCHER_BASE_H
#define QDENGINE_QDCORE_QD_GAME_DISPATCHER_BASE_H

#include "qdengine/qdcore/qd_conditional_object.h"
#include "qdengine/qdcore/qd_object_map_container.h"
#include "qdengine/qdcore/qd_scale_info.h"

#include "qdengine/qd_fwd.h"
#include "qdengine/parser/xml_fwd.h"

#ifdef __QD_DEBUG_ENABLE__
#include "qdengine/qdcore/qd_resource.h"
#endif

namespace QDEngine {

typedef void (*qdLoadingProgressFnc)(int percents_loaded, void *data);

class qdLoadingProgressInfo {
	uint32 _total_size;
	uint32 _loaded_size;
	void *_data;
	qdLoadingProgressFnc _progress_fnc;

public:

	qdLoadingProgressFnc set_callback_fnc(qdLoadingProgressFnc p, void *dp) {
		qdLoadingProgressFnc old_fnc = _progress_fnc;
		_progress_fnc = p;
		_data = dp;

		return old_fnc;
	}

	void set_total_size(int sz) {
		_total_size = sz;
		_loaded_size = 0;
	}
	int total_size() const {
		return _total_size;
	}

	void show_progress(int sz) {
		if (!_total_size || !_progress_fnc) return;
		_loaded_size += sz;
		uint32 percents = round(float(_loaded_size) / float(_total_size) * 100.0f);
		(*_progress_fnc)(percents, _data);
	}

	qdLoadingProgressInfo() {
		_progress_fnc = 0;
		_total_size = _loaded_size = 0;
		_data = 0;
	}
	~qdLoadingProgressInfo() { };
};

class qdGameDispatcherBase : public qdConditionalObject {
public:
	qdGameDispatcherBase();
	~qdGameDispatcherBase();

	void set_resources_size(int sz) {
		_loading_progress.set_total_size(sz);
	}

	qdLoadingProgressFnc set_loading_progress_callback(qdLoadingProgressFnc p, void *dp = 0) {
		return _loading_progress.set_callback_fnc(p, dp);
	}

	void show_loading_progress(int sz = 0);

	bool add_sound(qdSound *p);
	bool remove_sound(const char *name);
	bool remove_sound(qdSound *p);
	virtual qdSound *get_sound(const char *name);
	bool is_sound_in_list(const char *name);
	bool is_sound_in_list(qdSound *p);

	bool add_animation(qdAnimation *p);
	bool remove_animation(const char *name);
	bool remove_animation(qdAnimation *p);
	virtual qdAnimation *get_animation(const char *name);
	bool is_animation_in_list(const char *name);
	bool is_animation_in_list(qdAnimation *p);

	bool add_animation_set(qdAnimationSet *p);
	bool remove_animation_set(const char *name);
	bool remove_animation_set(qdAnimationSet *p);
	virtual qdAnimationSet *get_animation_set(const char *name);
	bool is_animation_set_in_list(const char *name);
	bool is_animation_set_in_list(qdAnimationSet *p);

	const qdSoundList &sound_list() const {
		return _sounds.get_list();
	}
	const qdAnimationList &animation_list() const {
		return _animations.get_list();
	}
	const qdAnimationSetList &animation_set_list() const {
		return _animation_sets.get_list();
	}

	virtual void load_script_body(const xml::tag *p);
	virtual bool save_script_body(Common::WriteStream &fh, int indent = 0) const;

	virtual int load_resources();
	void free_resources();

	virtual void quant(float dt) { };

	void add_scale_info(qdScaleInfo *p) {
		_scale_infos.push_back(*p);
	}
	bool get_object_scale(const char *p, float &sc);
	bool set_object_scale(const char *p, float sc);

	virtual qdScaleInfo *get_scale_info(const char *p);

	virtual int get_resources_size();

	qdConditionalObject::trigger_start_mode trigger_start() {
		return qdConditionalObject::TRIGGER_START_FAILED;
	}

#ifdef __QD_DEBUG_ENABLE__
	virtual bool get_resources_info(qdResourceInfoContainer &infos) const;
#endif

private:

	qdObjectMapContainer<qdAnimation> _animations;
	qdObjectMapContainer<qdAnimationSet> _animation_sets;
	qdObjectMapContainer<qdSound> _sounds;

	typedef Std::vector<qdScaleInfo> scale_info_container_t;
	scale_info_container_t _scale_infos;

	qdLoadingProgressInfo _loading_progress;
};

} // namespace QDEngine

#endif // QDENGINE_QDCORE_QD_GAME_DISPATCHER_BASE_H