19 |
*/ |
*/ |
20 |
#include "d_models.hh" |
#include "d_models.hh" |
21 |
|
|
|
// Functions in display.cc |
|
|
namespace display |
|
|
{ |
|
|
void add_active_model(Model *m); |
|
|
void remove_active_model(Model *m); |
|
|
} |
|
|
|
|
|
|
|
22 |
//====================================================================== |
//====================================================================== |
23 |
// DEFINING AND CREATING MODELS |
// DEFINING AND CREATING MODELS |
24 |
//====================================================================== |
//====================================================================== |
32 |
vector<Surface *> image_pile; |
vector<Surface *> image_pile; |
33 |
} |
} |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
namespace |
38 |
|
{ |
39 |
|
class ImageManager { |
40 |
|
public: |
41 |
|
|
42 |
|
private: |
43 |
|
|
44 |
|
}; |
45 |
|
} |
46 |
|
|
47 |
|
namespace |
48 |
|
{ |
49 |
|
class ModelManager { |
50 |
|
public: |
51 |
|
ModelManager(); |
52 |
|
~ModelManager(); |
53 |
|
|
54 |
|
void run_script (const char *filename); |
55 |
|
|
56 |
|
void define (const std::string name, Model *m); |
57 |
|
|
58 |
|
/* Create new model of type `modelname'. Returns 0 if no such |
59 |
|
model exists. */ |
60 |
|
Model *create (const std::string modelname); |
61 |
|
private: |
62 |
|
/* |
63 |
|
** Variables |
64 |
|
*/ |
65 |
|
typedef px::Dict<Model*> ModelMap; |
66 |
|
ModelMap m_templates; |
67 |
|
}; |
68 |
|
|
69 |
|
ModelManager *modelmgr = 0; |
70 |
|
} |
71 |
|
|
72 |
|
ModelManager::ModelManager() |
73 |
|
: m_templates (1069) |
74 |
|
{ |
75 |
|
} |
76 |
|
|
77 |
|
ModelManager::~ModelManager() |
78 |
|
{ |
79 |
|
delete_map(model_templates.begin(), |
80 |
|
model_templates.end()); |
81 |
|
delete_sequence(image_pile.begin(), image_pile.end()); |
82 |
|
} |
83 |
|
|
84 |
|
void |
85 |
|
ModelManager::run_script(const char *name) |
86 |
|
{ |
87 |
|
lua::Dofile(name); |
88 |
|
|
89 |
|
enigma::Log << "# models: " << model_templates.size() << endl; |
90 |
|
enigma::Log << "# images: " << surface_cache.size() << endl; |
91 |
|
} |
92 |
|
|
93 |
|
void |
94 |
|
ModelManager::define (const std::string name, Model *m) |
95 |
|
{ |
96 |
|
if (model_templates.has_key(name)) { |
97 |
|
enigma::Log << "Redefinition of model '"<<name<<"'\n"; |
98 |
|
delete m; |
99 |
|
} |
100 |
|
else { |
101 |
|
model_templates.insert(name, m); |
102 |
|
} |
103 |
|
} |
104 |
|
|
105 |
//---------------------------------------------------------------------- |
//---------------------------------------------------------------------- |
106 |
// MODELS |
// MODELS |
107 |
//---------------------------------------------------------------------- |
//---------------------------------------------------------------------- |
109 |
void |
void |
110 |
display::InitModels() |
display::InitModels() |
111 |
{ |
{ |
112 |
lua::Dofile("models-2d.lua"); |
modelmgr = new ModelManager; |
113 |
|
modelmgr->run_script ("models-2d.lua"); |
114 |
surface_cache_alpha.clear(); |
surface_cache_alpha.clear(); |
|
|
|
|
enigma::Log << "# models: " << model_templates.size() << endl; |
|
|
enigma::Log << "# images: " << surface_cache.size() << endl; |
|
115 |
} |
} |
116 |
|
|
117 |
void |
void |
118 |
display::ShutdownModels() |
display::ShutdownModels() |
119 |
{ |
{ |
120 |
delete_map(model_templates.begin(), |
delete modelmgr; |
|
model_templates.end()); |
|
|
delete_sequence(image_pile.begin(), image_pile.end()); |
|
121 |
} |
} |
122 |
|
|
|
|
|
123 |
void |
void |
124 |
display::ReloadModels() |
display::ReloadModels() |
125 |
{ |
{ |
136 |
void |
void |
137 |
display::DefineModel (const char *name, Model *m) |
display::DefineModel (const char *name, Model *m) |
138 |
{ |
{ |
139 |
string n(name); |
modelmgr->define (name, m); |
|
if (model_templates.has_key(n)) |
|
|
{ |
|
|
enigma::Log << "Redefinition of model '"<<name<<"'\n"; |
|
|
delete m; |
|
|
} |
|
|
else |
|
|
{ |
|
|
model_templates.insert(n, m); |
|
|
} |
|
140 |
} |
} |
141 |
|
|
142 |
/* Create a new model of type `name' by cloning the corresponding |
/* Create a new model of type `name' by cloning the corresponding |
303 |
{ |
{ |
304 |
if (--rep->refcount == 0) |
if (--rep->refcount == 0) |
305 |
delete rep; |
delete rep; |
|
deactivate(); |
|
306 |
} |
} |
307 |
|
|
308 |
void Anim2d::add_frame(Model *m, double duration) |
void Anim2d::add_frame(Model *m, double duration) |
334 |
} |
} |
335 |
|
|
336 |
void |
void |
337 |
Anim2d::activate (double worldx, double worldy, bool is_sprite) |
Anim2d::expose (ModelLayer *ml, const px::V2 &pos) |
338 |
{ |
{ |
339 |
add_active_model(this); |
ml->activate (this); |
340 |
posx=worldx; |
posx = pos[0]; |
341 |
posy=worldy; |
posy = pos[1]; |
342 |
this->is_sprite = is_sprite; |
is_sprite = ml->is_sprite_layer(); |
343 |
} |
} |
344 |
|
|
345 |
void Anim2d::deactivate() |
void |
346 |
|
Anim2d::remove (ModelLayer *ml) |
347 |
{ |
{ |
348 |
remove_active_model(this); |
ml->deactivate (this); |
349 |
} |
} |
350 |
|
|
351 |
|
|
352 |
bool |
bool |
353 |
Anim2d::has_changed(Rect &changed_region) |
Anim2d::has_changed(Rect &changed_region) |
354 |
{ |
{ |