~ares-developers/ares/gd03

« back to all changes in this revision

Viewing changes to src/Ext/Techno/Hooks.Alpha.cpp

  • Committer: Renegade
  • Date: 2010-05-29 08:12:17 UTC
  • Revision ID: git-v1:0a1bb6321f04d723afe64d1b843dc87b4da783ec
Creating /trunk/src.

git-svn-id: svn://svn.renegadeprojects.com/ares/trunk@622 859b54a9-7a54-0410-aeb3-f8d2f1fa40fd

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "Body.h"
 
2
#include "../TechnoType/Body.h"
 
3
 
 
4
#include <TacticalClass.h>
 
5
 
 
6
hash_AlphaExt TechnoExt::AlphaExt;
 
7
// conventions for hashmaps like this:
 
8
// the value's CTOR is the only thing allowed to .insert() or [] stuff
 
9
// the value's (SD)DTOR is the only thing allowed to .erase() stuff
 
10
 
 
11
DEFINE_HOOK(420960, AlphaShapeClass_CTOR, 5)
 
12
{
 
13
        GET_STACK(ObjectClass *, O, 0x4);
 
14
        GET(AlphaShapeClass *, AS, ECX);
 
15
        hash_AlphaExt::iterator i = TechnoExt::AlphaExt.find(O);
 
16
        if(i != TechnoExt::AlphaExt.end()) {
 
17
                delete i->second;
 
18
        }
 
19
        TechnoExt::AlphaExt[O] = AS;
 
20
        return 0;
 
21
}
 
22
 
 
23
DEFINE_HOOK(421730, AlphaShapeClass_SDDTOR, 8)
 
24
{
 
25
        GET(AlphaShapeClass *, AS, ECX);
 
26
        ObjectClass *O = AS->AttachedTo;
 
27
        hash_AlphaExt::iterator i = TechnoExt::AlphaExt.find(O);
 
28
        if(i != TechnoExt::AlphaExt.end()) {
 
29
                TechnoExt::AlphaExt.erase(i);
 
30
        }
 
31
        return 0;
 
32
}
 
33
 
 
34
DEFINE_HOOK(5F3D5B, ObjectClass_DTOR, A)
 
35
{
 
36
        GET(ObjectClass *, O, ESI);
 
37
        hash_AlphaExt::iterator i = TechnoExt::AlphaExt.find(O);
 
38
        if(i != TechnoExt::AlphaExt.end()) {
 
39
                delete i->second;
 
40
        }
 
41
        return 0;
 
42
}
 
43
 
 
44
DEFINE_HOOK(5F3E70, ObjectClass_Update, 5)
 
45
{
 
46
        GET(ObjectClass *, Source, ECX);
 
47
        ObjectTypeClass *SourceType = Source->GetType();
 
48
        if(!SourceType) {
 
49
                return 0;
 
50
        }
 
51
 
 
52
        SHPStruct *Alpha = SourceType->AlphaImage;
 
53
        if(!Alpha) {
 
54
                return 0;
 
55
        }
 
56
 
 
57
        CoordStruct XYZ;
 
58
 
 
59
        RectangleStruct *ScreenArea = &TacticalClass::Instance->VisibleArea;
 
60
        Point2D off = { ScreenArea->X - (Alpha->Width / 2), ScreenArea->Y - (Alpha->Height / 2) };
 
61
        Point2D xy;
 
62
 
 
63
        if(FootClass *Foot = generic_cast<FootClass *>(Source)) {
 
64
                if(Foot->LastMapCoords != Foot->CurrentMapCoords) {
 
65
                        // we moved - need to redraw the area we were in
 
66
                        // alas, we don't have the precise XYZ we were in, only the cell we were last seen in
 
67
                        // so we need to add the cell's dimensions to the dirty area just in case
 
68
                        CellClass::Cell2Coord(&Foot->LastMapCoords, &XYZ);
 
69
                        Point2D xyTL, xyBR;
 
70
                        TacticalClass::Instance->CoordsToClient(&XYZ, &xyTL);
 
71
                        // because the coord systems are different - xyz is x/, y\, xy is x-, y|
 
72
                        XYZ.X += 256;
 
73
                        TacticalClass::Instance->CoordsToClient(&XYZ, &xyBR);
 
74
                        Point2D cellDimensions = xyBR - xyTL;
 
75
                        xy = xyTL;
 
76
                        xy.X += cellDimensions.X / 2;
 
77
                        xy.Y += cellDimensions.Y / 2;
 
78
                        xy += off;
 
79
                        RectangleStruct Dirty =
 
80
                          { xy.X - ScreenArea->X - cellDimensions.X, xy.Y - ScreenArea->Y - cellDimensions.Y,
 
81
                                Alpha->Width + cellDimensions.X * 2, Alpha->Height + cellDimensions.Y * 2 };
 
82
                        TacticalClass::Instance->RegisterDirtyArea(Dirty, 1);
 
83
                }
 
84
        }
 
85
 
 
86
        bool Inactive = Source->InLimbo;
 
87
 
 
88
        if(Source->AbstractFlags & ABSFLAGS_ISTECHNO) {
 
89
                Inactive |= reinterpret_cast<TechnoClass *>(Source)->Deactivated;
 
90
        }
 
91
 
 
92
        if(Source->WhatAmI() == abs_Building && Source->GetCurrentMission() != mission_Construction) {
 
93
                Inactive |= !reinterpret_cast<BuildingClass *>(Source)->IsPowerOnline();
 
94
        }
 
95
 
 
96
        if(Inactive) {
 
97
                hash_AlphaExt::iterator i = TechnoExt::AlphaExt.find(Source);
 
98
                if(i != TechnoExt::AlphaExt.end()) {
 
99
                        delete i->second;
 
100
                }
 
101
                return 0;
 
102
        }
 
103
 
 
104
        if(Unsorted::CurrentFrame % 2) { // lag reduction - don't draw a new alpha every frame
 
105
                Source->GetCoords(&XYZ);
 
106
                TacticalClass::Instance->CoordsToClient(&XYZ, &xy);
 
107
                xy += off;
 
108
                ++Unsorted::IKnowWhatImDoing;
 
109
                AlphaShapeClass *placeholder;
 
110
                GAME_ALLOC(AlphaShapeClass, placeholder, Source, xy.X, xy.Y);
 
111
                --Unsorted::IKnowWhatImDoing;
 
112
                //int Margin = 40;
 
113
                RectangleStruct Dirty =
 
114
                  { xy.X - ScreenArea->X, xy.Y - ScreenArea->Y,
 
115
                        Alpha->Width, Alpha->Height };
 
116
                TacticalClass::Instance->RegisterDirtyArea(Dirty, 1);
 
117
        }
 
118
 
 
119
        return 0;
 
120
}
 
121
 
 
122
 
 
123
DEFINE_HOOK(420F75, AlphaLightClass_UpdateScreen_ShouldDraw, 5)
 
124
{
 
125
        GET(AlphaShapeClass *, A, ECX);
 
126
        unsigned int idx = 0;
 
127
        if(ObjectClass *O = A->AttachedTo) {
 
128
                if(TechnoClass * T = generic_cast<TechnoClass *>(O)) {
 
129
                        TechnoExt::ExtData * pData = TechnoExt::ExtMap.Find(T);
 
130
                        if(!pData->DrawVisualFX()) {
 
131
                                return 0x42132A;
 
132
                        }
 
133
                }
 
134
        }
 
135
        return 0;
 
136
}
 
137
 
 
138
DEFINE_HOOK(4210AC, AlphaLightClass_UpdateScreen_Header, 5)
 
139
{
 
140
        GET(AlphaShapeClass *, A, EDX);
 
141
        GET(SHPStruct *, Image, ECX);
 
142
        if(ObjectClass *O = A->AttachedTo) {
 
143
                if(TechnoClass * T = generic_cast<TechnoClass *>(O)) {
 
144
                        TechnoExt::ExtData * pData = TechnoExt::ExtMap.Find(T);
 
145
                        unsigned int idx = pData->AlphaFrame(Image);
 
146
                        R->Stack(0x0, idx);
 
147
                }
 
148
        }
 
149
        return 0;
 
150
}
 
151
 
 
152
DEFINE_HOOK(4211AC, AlphaLightClass_UpdateScreen_Body, 8)
 
153
{
 
154
        GET_STACK(int, AlphaLightIndex, STACK_OFFS(0xDC, 0xB4));
 
155
        GET_STACK(SHPStruct *, Image, STACK_OFFS(0xDC, 0x6C));
 
156
        AlphaShapeClass *A = AlphaShapeClass::Array->Items[AlphaLightIndex];
 
157
        if(ObjectClass *O = A->AttachedTo) {
 
158
                if(TechnoClass * T = generic_cast<TechnoClass *>(O)) {
 
159
                        TechnoExt::ExtData * pData = TechnoExt::ExtMap.Find(T);
 
160
                        unsigned int idx = pData->AlphaFrame(Image);
 
161
                        R->Stack(0x0, idx);
 
162
                }
 
163
        }
 
164
        return 0;
 
165
}
 
166
 
 
167
 
 
168
DEFINE_HOOK(421371, TacticalClass_UpdateAlphasInRectangle_ShouldDraw, 5)
 
169
{
 
170
        GET(int, AlphaLightIndex, EBX);
 
171
        AlphaShapeClass *A = AlphaShapeClass::Array->Items[AlphaLightIndex];
 
172
        unsigned int idx = 0;
 
173
        if(ObjectClass *O = A->AttachedTo) {
 
174
                if(TechnoClass * T = generic_cast<TechnoClass *>(O)) {
 
175
                        TechnoExt::ExtData * pData = TechnoExt::ExtMap.Find(T);
 
176
                        if(!pData->DrawVisualFX()) {
 
177
                                return 0x421694;
 
178
                        }
 
179
                }
 
180
        }
 
181
        return 0;
 
182
}
 
183
 
 
184
DEFINE_HOOK(42146E, TacticalClass_UpdateAlphasInRectangle_Header, 5)
 
185
{
 
186
        GET(int, AlphaLightIndex, EBX);
 
187
        GET(RectangleStruct *, buffer, EDX);
 
188
        GET(SHPStruct *, Image, EDI);
 
189
 
 
190
        AlphaShapeClass *A = AlphaShapeClass::Array->Items[AlphaLightIndex];
 
191
        unsigned int idx = 0;
 
192
        if(ObjectClass *O = A->AttachedTo) {
 
193
                if(TechnoClass * T = generic_cast<TechnoClass *>(O)) {
 
194
                        TechnoExt::ExtData * pData = TechnoExt::ExtMap.Find(T);
 
195
                        idx = pData->AlphaFrame(Image);
 
196
                }
 
197
        }
 
198
        R->EAX(Image->GetFrameHeader(buffer, idx));
 
199
        return 0x421478;
 
200
}
 
201
 
 
202
DEFINE_HOOK(42152C, TacticalClass_UpdateAlphasInRectangle_Body, 8)
 
203
{
 
204
        GET_STACK(int, AlphaLightIndex, STACK_OFFS(0xA4, 0x78));
 
205
        GET(SHPStruct *, Image, ECX);
 
206
        AlphaShapeClass *A = AlphaShapeClass::Array->Items[AlphaLightIndex];
 
207
        if(ObjectClass *O = A->AttachedTo) {
 
208
                if(TechnoClass * T = generic_cast<TechnoClass *>(O)) {
 
209
                        TechnoExt::ExtData * pData = TechnoExt::ExtMap.Find(T);
 
210
                        unsigned int idx = pData->AlphaFrame(Image);
 
211
                        R->Stack(0x0, idx);
 
212
                }
 
213
        }
 
214
        return 0;
 
215
}
 
216
 
 
217
DEFINE_HOOK(71944E, TeleportLocomotionClass_ILocomotion_Process, 6)
 
218
{
 
219
        GET(FootClass *, Object, ECX);
 
220
        GET(CoordStruct *, XYZ, EDX);
 
221
        Object->GetCoords(XYZ);
 
222
        R->EAX<CoordStruct *>(XYZ);
 
223
 
 
224
        if(TechnoTypeClass *Type = Object->GetTechnoType()) {
 
225
                if(SHPStruct *Alpha = Type->AlphaImage) {
 
226
                        Point2D xy;
 
227
                        TacticalClass::Instance->CoordsToClient(XYZ, &xy);
 
228
                        RectangleStruct *ScreenArea = &TacticalClass::Instance->VisibleArea;
 
229
                        Point2D off = { ScreenArea->X - (Alpha->Width / 2), ScreenArea->Y - (Alpha->Height / 2) };
 
230
                        xy += off;
 
231
                        RectangleStruct Dirty =
 
232
                          { xy.X - ScreenArea->X, xy.Y - ScreenArea->Y,
 
233
                                Alpha->Width, Alpha->Height };
 
234
                        TacticalClass::Instance->RegisterDirtyArea(Dirty, 1);
 
235
                }
 
236
        }
 
237
 
 
238
        return 0x719454;
 
239
}