Repository navigation
Expand file tree
/
Copy pathmap.cpp
More file actions
167 lines (131 loc) · 4.2 KB
/
Copy pathmap.cpp
File metadata and controls
167 lines (131 loc) · 4.2 KB
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
166
167
/*
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/>.
*/
#include "map.h"
#include "model.h"
#include "loosequadtree.h"
#include "renderqueue.h"
#include "surface.h"
#include "text.h"
#include "vertex.h"
#include "uirendering.h"
#include "engine.h"
#include "settings.h"
#include "../engine/particle.h"
#include "../tinyxml2/tinyxml2.h"
#include "../grinliz/glstringutil.h"
#include "../grinliz/glrectangle.h"
#include "../xegame/xegamelimits.h"
using namespace grinliz;
using namespace tinyxml2;
const float DIAGONAL_COST = 1.414f;
Map::Map(int w, int h)
{
usingSectors = false;
width = w;
height = h;
texture = 0;
GLASSERT(w <= MAX_MAP_SIZE);
GLASSERT(h <= MAX_MAP_SIZE);
GLOUTPUT(("Map created. %dK\n", int(sizeof(*this)) / 1024));
saturation = 1.0f;
gamui::RenderAtom nullAtom;
overlayM1.Init(this);
overlay0.Init(this);
overlay1.Init(this);
TextureManager* texman = TextureManager::Instance();
texman->CreateTexture("miniMap", 512, 512, TEX_RGB16, Texture::PARAM_NONE, this);
}
Map::~Map()
{
}
void Map::CreateTexture( Texture* t )
{
if ( StrEqual( t->Name(), "miniMap" ) ) {
int size = t->Width()*t->Height();
U16* data = new U16[size];
memset( data, 0, sizeof(U16)*size );
t->Upload( data, sizeof(U16)*size );
delete [] data;
}
else {
GLASSERT( 0 );
}
}
void Map::DrawOverlay( int id )
{
if ( id == 0 ) {
overlayVBO = GPUDevice::Instance()->GetUIVBO( GPUDevice::OVERLAY0 );
overlayIBO = GPUDevice::Instance()->GetUIIBO( GPUDevice::OVERLAY0 );
overlay0.Render();
}
else {
overlayVBO = GPUDevice::Instance()->GetUIVBO( GPUDevice::OVERLAY1 );
overlayIBO = GPUDevice::Instance()->GetUIIBO( GPUDevice::OVERLAY1 );
overlay1.Render();
}
}
void Map::BeginRender( int nIndex, const uint16_t* index, int nVertex, const gamui::Gamui::Vertex* vertex )
{
overlayIBO->Upload( index, nIndex, 0 );
overlayVBO->Upload( vertex, nVertex*sizeof(*vertex), 0 );
GPUDevice::Instance()->PushMatrix( GPUDevice::MODELVIEW_MATRIX );
Matrix4 rot;
rot.SetXRotation( 90 );
GPUDevice::Instance()->MultMatrix( GPUDevice::MODELVIEW_MATRIX, rot );
}
void Map::EndRender()
{
GPUDevice::Instance()->PopMatrix( GPUDevice::MODELVIEW_MATRIX );
}
void Map::BeginRenderState( const void* renderState )
{
const float ALPHA = 0.5f;
const float ALPHA_1 = 0.30f;
switch( int(intptr_t(renderState)) ) {
case UIRenderer::RENDERSTATE_UI_NORMAL_OPAQUE:
case RENDERSTATE_MAP_OPAQUE:
gamuiShader.SetColor( 1, 1, 1, 1 );
gamuiShader.SetBlendMode( BLEND_NONE );
break;
case UIRenderer::RENDERSTATE_UI_NORMAL:
case RENDERSTATE_MAP_NORMAL:
gamuiShader.SetColor( 1.0f, 1.0f, 1.0f, 0.8f );
gamuiShader.SetBlendMode( BLEND_NORMAL );
break;
case UIRenderer::RENDERSTATE_UI_DECO:
case RENDERSTATE_MAP_TRANSLUCENT:
gamuiShader.SetColor( 1, 1, 1, ALPHA );
gamuiShader.SetBlendMode( BLEND_NORMAL );
break;
case RENDERSTATE_MAP_MORE_TRANSLUCENT:
gamuiShader.SetColor( 1, 1, 1, ALPHA_1 );
gamuiShader.SetBlendMode( BLEND_NORMAL );
break;
default:
GLASSERT( 0 );
}
}
void Map::BeginTexture( const void* textureHandle )
{
texture = (Texture*)textureHandle;
}
void Map::Render( const void* renderState, const void* textureHandle, int start, int count )
{
GPUDevice* device = GPUDevice::Instance();
GPUStream stream( GPUStream::kGamuiType );
GPUStreamData data;
data.texture0 = (Texture*)textureHandle;
data.indexBuffer = overlayIBO->ID();
data.vertexBuffer = overlayVBO->ID();
device->Draw( gamuiShader, stream, data, start, count, 1 );
}