This repository was archived by the owner on Mar 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFunctionInit.cpp
More file actions
172 lines (152 loc) · 3.39 KB
/
FunctionInit.cpp
File metadata and controls
172 lines (152 loc) · 3.39 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
168
169
170
171
#include "Drawing.h"
#include "CMapData.h"
#include "CMixFile.h"
#include "CLoading.h"
#include "CCRC.h"
#include "CShpFile.h"
#include "CFinalSunApp.h"
#include <fstream>
const MapCoord MapCoord::Facings[FACING_COUNT] =
{
{-1, 0},
{-1, 1},
{0, 1},
{1, 1},
{1, 0},
{1, -1},
{0, -1},
{-1, -1}
};
MapCoord& operator+=(MapCoord& l, const MapCoord& r)
{
l.X += r.X;
l.Y += r.Y;
return l;
}
MapCoord operator+(const MapCoord& l, const MapCoord& r)
{
MapCoord ret;
ret.X = l.X + r.X;
ret.Y = l.Y + r.Y;
return ret;
}
MapCoord operator*(const MapCoord& coord, int factor)
{
MapCoord ret;
ret.X = coord.X * factor;
ret.Y = coord.Y * factor;
return ret;
}
HSVClass::operator RGBClass() const
{
if (S == 0u)
return { V, V, V };
unsigned char region = H / 43;
unsigned char remainder = (H - (region * 43)) * 6;
unsigned char p = (V * (255 - S)) >> 8;
unsigned char q = (V * (255 - ((S * remainder) >> 8))) >> 8;
unsigned char t = (V * (255 - ((S * (255 - remainder)) >> 8))) >> 8;
switch (region) {
case 0:
return { V, t, p };
case 1:
return { q, V, p };
case 2:
return { p, V, t };
case 3:
return { p, q, V };
case 4:
return { t, p, V };
default:
return { V, p, q };
}
}
RGBClass::operator HSVClass() const
{
int hue;
int saturation;
int value;
int red = R;
int green = G;
int blue = B;
hue = 0;
value = red > green ? red : green;
if (blue > value) value = blue;
int white = red < green ? red : green;
if (blue < white) white = blue;
saturation = 0;
if (value)
saturation = ((value - white) * 255) / value;
if (saturation != 0)
{
unsigned int tmp = value - white;
unsigned int r1 = ((value - red) * 255) / tmp;
unsigned int g1 = ((value - green) * 255) / tmp;
unsigned int b1 = ((value - blue) * 255) / tmp;
if (value == red)
if (white == green)
tmp = 5 * 256 + b1;
else
tmp = 1 * 256 - g1;
else
if (value == green)
if (white == blue)
tmp = 1 * 256 + r1;
else
tmp = 3 * 256 - b1;
else
if (white == red)
tmp = 3 * 256 + g1;
else
tmp = 5 * 256 - r1;
hue = tmp / 6;
}
return { (unsigned char)hue, (unsigned char)saturation, (unsigned char)value };
}
void* CLoading::ReadWholeFile(const char* filename, DWORD* pDwSize)
{
ppmfc::CString filepath = CFinalSunApp::FilePath();
filepath += filename;
std::ifstream fin;
fin.open(filepath, std::ios::in | std::ios::binary);
if (fin.is_open())
{
fin.seekg(0, std::ios::end);
const int size = static_cast<int>(fin.tellg());
if (size == 0)
return nullptr;
fin.seekg(0, std::ios::beg);
auto pBuffer = GameCreateArray<unsigned char>(size);
if (pDwSize)
*pDwSize = size;
fin.read((char*)pBuffer, size);
fin.close();
return pBuffer;
}
auto nMix = CLoading::Instance->SearchFile(filename);
if (CMixFile::HasFile(filename, nMix))
{
Ccc_file file(true);
file.open(filename, CMixFile::Array[nMix - 1]);
auto pBuffer = GameCreateArray<unsigned char>(file.get_size());
memcpy(pBuffer, file.get_data(), file.get_size());
if (pDwSize)
*pDwSize = file.get_size();
return pBuffer;
}
return nullptr;
}
bool CLoading::HasFile(ppmfc::CString filename)
{
ppmfc::CString filepath = CFinalSunApp::FilePath();
filepath += filename;
std::ifstream fin;
fin.open(filepath, std::ios::in | std::ios::binary);
if (fin.is_open())
{
fin.close();
return true;
}
auto nMix = CLoading::Instance->SearchFile(filename);
return CMixFile::HasFile(filename, nMix);
}