Skip to content

Commit 1470c2c

Browse files
committed
家近红蕖曲水滨,全家罗袜起秋尘
试一下另一个全屏效果,好像不太好
1 parent fca68f2 commit 1470c2c

File tree

11 files changed

+115
-48
lines changed

11 files changed

+115
-48
lines changed

src/BattleSceneHades.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,6 @@ void BattleSceneHades::AI(Role* r)
11821182
r->RealTowards.normTo(1);
11831183
//r->Pos = p2;
11841184
r->Velocity = r->RealTowards * speed;
1185-
11861185
r->VelocitytFrame = 3;
11871186
}
11881187
}

src/DrawNode.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "DrawNode.h"
2+
#include "Font.h"
3+
4+
void DrawNode::draw()
5+
{
6+
for (auto& i : Infos)
7+
{
8+
if (i.type == 0)
9+
{
10+
Font::getInstance()->draw(i.text, 20, i.x, i.y /*BP_Color(e5)*/);
11+
}
12+
else if (i.type == 1)
13+
{
14+
TextureManager::getInstance()->renderTexture(i.text, i.num, i.x, i.y);
15+
}
16+
}
17+
}

src/DrawNode.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
#include "RunNode.h"
3+
4+
//¸¨Öú»æÖƵÄÀà
5+
class DrawNode : public RunNode
6+
{
7+
public:
8+
virtual ~DrawNode() {}
9+
virtual void draw() override;
10+
void clear()
11+
{
12+
Infos.clear();
13+
}
14+
struct Info
15+
{
16+
int type = 0;
17+
int x = 0, y = 0;
18+
std::string text;
19+
int num = 0;
20+
};
21+
std::vector<Info> Infos;
22+
};
23+

src/Engine.cpp

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ int Engine::init(void* handle)
2828
SDL_RaiseWindow(window_);
2929
renderer_ = SDL_CreateRenderer(window_, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE /*| SDL_RENDERER_PRESENTVSYNC*/);
3030

31+
tex_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, start_w_, start_h_);
32+
setRenderTarget(tex_);
33+
3134
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
3235
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
3336

@@ -112,7 +115,7 @@ BP_Texture* Engine::createYUVTexture(int w, int h)
112115

113116
void Engine::updateYUVTexture(BP_Texture* t, uint8_t* data0, int size0, uint8_t* data1, int size1, uint8_t* data2, int size2)
114117
{
115-
SDL_UpdateYUVTexture(testTexture(t), nullptr, data0, size0, data1, size1, data2, size2);
118+
SDL_UpdateYUVTexture(t, nullptr, data0, size0, data1, size1, data2, size2);
116119
}
117120

118121
BP_Texture* Engine::createARGBTexture(int w, int h)
@@ -127,7 +130,7 @@ BP_Texture* Engine::createARGBRenderedTexture(int w, int h)
127130

128131
void Engine::updateARGBTexture(BP_Texture* t, uint8_t* buffer, int pitch)
129132
{
130-
SDL_UpdateTexture(testTexture(t), nullptr, buffer, pitch);
133+
SDL_UpdateTexture(t, nullptr, buffer, pitch);
131134
}
132135

133136
void Engine::renderCopy(BP_Texture* t, int x, int y, int w, int h, double angle, int inPresent)
@@ -143,16 +146,42 @@ void Engine::renderCopy(BP_Texture* t, int x, int y, int w, int h, double angle,
143146

144147
void Engine::renderCopy(BP_Texture* t /*= nullptr*/, double angle)
145148
{
146-
SDL_RenderCopyEx(renderer_, testTexture(t), nullptr, &rect_, angle, nullptr, SDL_FLIP_NONE);
149+
SDL_RenderCopyEx(renderer_, t, nullptr, &rect_, angle, nullptr, SDL_FLIP_NONE);
147150
render_times_++;
148151
}
149152

153+
void Engine::renderPresent()
154+
{
155+
setRenderTarget(nullptr);
156+
SDL_RenderCopy(renderer_, tex_, nullptr, nullptr);
157+
SDL_RenderPresent(renderer_);
158+
resetRenderTarget();
159+
}
160+
150161
void Engine::renderCopy(BP_Texture* t, BP_Rect* rect0, BP_Rect* rect1, double angle, int inPresent /*= 0*/)
151162
{
152163
SDL_RenderCopyEx(renderer_, t, rect0, rect1, angle, nullptr, SDL_FLIP_NONE);
153164
render_times_++;
154165
}
155166

167+
void Engine::getMouseState(int& x, int& y)
168+
{
169+
SDL_GetMouseState(&x, &y);
170+
int w, h;
171+
SDL_GetWindowSize(window_, &w, &h);
172+
x *= 1.0 * start_w_ / w;
173+
y *= 1.0 * start_h_ / h;
174+
}
175+
176+
void Engine::setMouseState(int x, int y)
177+
{
178+
int w, h;
179+
SDL_GetWindowSize(window_, &w, &h);
180+
x /= 1.0 * start_w_ / w;
181+
y /= 1.0 * start_h_ / h;
182+
SDL_WarpMouseInWindow(window_, x, y);
183+
}
184+
156185
int Engine::pollEvent(BP_Event& e)
157186
{
158187
int r = SDL_PollEvent(&e);
@@ -167,6 +196,14 @@ int Engine::pollEvent(BP_Event& e)
167196
else if (key == BP_CONTROLLER_BUTTON_Y) { key = BP_CONTROLLER_BUTTON_X; }
168197
}
169198
}
199+
if (e.type == BP_MOUSEMOTION || e.type == BP_MOUSEBUTTONDOWN || e.type == BP_MOUSEBUTTONUP)
200+
{
201+
int w, h;
202+
SDL_GetWindowSize(window_, &w, &h);
203+
e.motion.x *= 1.0 * start_w_ / w;
204+
e.motion.y *= 1.0 * start_h_ / h;
205+
206+
}
170207
return r;
171208
}
172209

@@ -336,7 +373,7 @@ void Engine::createAssistTexture(int w, int h)
336373
//tex_ = createYUVTexture(w, h);
337374
tex2_ = createARGBRenderedTexture(w, h);
338375
//tex_ = createARGBRenderedTexture(768, 480);
339-
setPresentPosition();
376+
//SDL_SetTextureBlendMode(tex2_, SDL_BLENDMODE_BLEND);
340377
}
341378

342379
void Engine::setPresentPosition()

src/Engine.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Engine
7878
BP_Renderer* renderer_ = nullptr;
7979
BP_Texture* tex_ = nullptr, * tex2_ = nullptr, * logo_ = nullptr;
8080
BP_Rect rect_;
81-
BP_Texture* testTexture(BP_Texture* tex) { return tex ? tex : this->tex_; }
81+
//BP_Texture* testTexture(BP_Texture* tex) { return tex ? tex : this->tex_; }
8282
bool full_screen_ = false;
8383
bool keep_ratio_ = true;
8484

@@ -101,6 +101,8 @@ class Engine
101101
void getWindowMaxSize(int& w, int& h) { SDL_GetWindowMaximumSize(window_, &w, &h); }
102102
int getWindowWidth();
103103
int getWindowHeight();
104+
int getStartWindowWidth() { return start_w_; }
105+
int getStartWindowHeight() { return start_h_; }
104106
int getMaxWindowWidth() { return max_x_ - min_x_; }
105107
int getMaxWindowHeight() { return max_y_ - min_y_; }
106108
void getWindowPosition(int& x, int& y) { SDL_GetWindowPosition(window_, &x, &y); }
@@ -135,13 +137,13 @@ class Engine
135137
void updateARGBTexture(BP_Texture* t, uint8_t* buffer, int pitch);
136138
void renderCopy(BP_Texture* t = nullptr, double angle = 0);
137139
void showLogo() { renderCopy(logo_, nullptr, nullptr); }
138-
void renderPresent() { SDL_RenderPresent(renderer_); /*renderClear();*/ }
140+
void renderPresent();
139141
void renderClear() { SDL_RenderClear(renderer_); }
140142
void setTextureAlphaMod(BP_Texture* t, uint8_t alpha) { SDL_SetTextureAlphaMod(t, alpha); }
141143
void queryTexture(BP_Texture* t, int* w, int* h) { SDL_QueryTexture(t, nullptr, nullptr, w, h); }
142144
void setRenderTarget(BP_Texture* t) { SDL_SetRenderTarget(renderer_, t); }
143145
BP_Texture* getRenderTarget() { return SDL_GetRenderTarget(renderer_); }
144-
void resetRenderTarget() { setRenderTarget(nullptr); }
146+
void resetRenderTarget() { setRenderTarget(tex_); }
145147
void createWindow() {}
146148
void createRenderer() {}
147149
void renderCopy(BP_Texture* t, int x, int y, int w = 0, int h = 0, double angle = 0, int inPresent = 0);
@@ -165,7 +167,7 @@ class Engine
165167
void fillColor(BP_Color color, int x, int y, int w, int h);
166168
void setRenderAssistTexture() { setRenderTarget(tex2_); }
167169
void renderAssistTextureToWindow();
168-
void setTextureBlendMode(BP_Texture* t) { SDL_SetTextureBlendMode(t, SDL_BLENDMODE_BLEND); }
170+
int setTextureBlendMode(BP_Texture* t) { return SDL_SetTextureBlendMode(t, SDL_BLENDMODE_BLEND); }
169171

170172
void resetRenderTimes(int t = 0) { render_times_ = t; }
171173
int getRenderTimes() { return render_times_; }
@@ -187,8 +189,8 @@ class Engine
187189
fmt1::print("{}\n", getTicks() - time_);
188190
}
189191
}
190-
static void getMouseState(int& x, int& y) { SDL_GetMouseState(&x, &y); };
191-
void setMouseState(int& x, int& y) { SDL_WarpMouseInWindow(window_, x, y); };
192+
void getMouseState(int& x, int& y);;
193+
void setMouseState(int x, int y);;
192194
int pollEvent(BP_Event& e);
193195
static int pollEvent() { return SDL_PollEvent(nullptr); }
194196
static int pushEvent(BP_Event& e) { return SDL_PushEvent(&e); }

src/Event.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Event::Event()
3333
text_box_ = std::make_shared<TextBox>();
3434
text_box_->setPosition(400, 200);
3535
text_box_->setTextPosition(-20, 100);
36-
event_node_ = std::make_shared<EventNode>();
36+
event_node_ = std::make_shared<DrawNode>();
3737
}
3838

3939
Event::~Event()
@@ -1384,8 +1384,7 @@ void Event::instruct_50e(int code, int e1, int e2, int e3, int e4, int e5, int e
13841384
e4 = e_GetValue(1, e1, e4);
13851385
e5 = e_GetValue(2, e1, e5);
13861386
char_ptr = (char*)&x50[e2];
1387-
event_node_->infos.emplace_back(EventNode::Info{0, e3, e4, char_ptr});
1388-
//Font::getInstance()->draw(char_ptr, 20, e3, e4 /*BP_Color(e5)*/);
1387+
event_node_->Infos.emplace_back(DrawNode::Info{ 0, e3, e4, char_ptr });
13891388
break;
13901389
case 34: //画一个背景框,废弃
13911390
e2 = e_GetValue(0, e1, e2);
@@ -1447,8 +1446,17 @@ void Event::instruct_50e(int code, int e1, int e2, int e3, int e4, int e5, int e
14471446
e5 = e_GetValue(2, e1, e5);
14481447
switch (e2)
14491448
{
1450-
case 0: TextureManager::getInstance()->renderTexture("mmap", e5, e3, e4); break;
1451-
case 1: TextureManager::getInstance()->renderTexture("head", e5, e3, e4); break;
1449+
case 0:
1450+
if (submap_id_ < 0)
1451+
{
1452+
event_node_->Infos.emplace_back(DrawNode::Info{ 1, e3, e4, "mmap", e5 });
1453+
}
1454+
else
1455+
{
1456+
event_node_->Infos.emplace_back(DrawNode::Info{ 1, e3, e4, "smap", e5 });
1457+
}
1458+
break;
1459+
case 1: event_node_->Infos.emplace_back(DrawNode::Info{ 1, e3, e4, "head", e5 }); break;
14521460
}
14531461
break;
14541462
case 42: //改变主地图坐标

src/Event.h

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
2+
#include "DrawNode.h"
23
#include "FunctionTrait.h"
34
#include "Menu.h"
45
#include "Random.h"
5-
#include "RunNode.h"
66
#include "SubScene.h"
77
#include "Talk.h"
88
#include "Font.h"
@@ -205,34 +205,7 @@ class Event
205205
runner_impl(f, c, e, i, std::make_index_sequence<arg_counter<F, C>::value>{});
206206
}
207207

208-
//事件中辅助绘制的类
209-
class EventNode : public RunNode
210-
{
211-
public:
212-
virtual ~EventNode() {}
213-
virtual void draw() override
214-
{
215-
for (auto& i : infos)
216-
{
217-
if (i.type == 0)
218-
{
219-
Font::getInstance()->draw(i.text, 20, i.x, i.y /*BP_Color(e5)*/);
220-
}
221-
}
222-
}
223-
void clear()
224-
{
225-
infos.clear();
226-
}
227-
struct Info
228-
{
229-
int type = 0;
230-
int x = 0, y = 0;
231-
std::string text;
232-
int num = 0;
233-
};
234-
std::vector<Info> infos;
235-
};
236-
std::shared_ptr<EventNode> event_node_;
208+
209+
std::shared_ptr<DrawNode> event_node_;
237210

238211
};

src/MainScene.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ void MainScene::forceEnterSubScene(int submap_id, int x, int y, int event)
518518

519519
void MainScene::setWeather()
520520
{
521-
weather_->setPosition(Engine::getInstance()->getWindowWidth() / 2, 0);
521+
weather_->setPosition(Engine::getInstance()->getStartWindowWidth() / 2, 0);
522522
if (inNorth())
523523
{
524524
weather_->setStyle(ParticleExample::SNOW);

src/UISystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ int UISystem::askExit(int mode)
7070
int x = 880, y = 100;
7171
if (mode == 1)
7272
{
73-
x = Engine::getInstance()->getWindowWidth() - 150;
73+
x = Engine::getInstance()->getStartWindowWidth() - 150;
7474
y = 20;
7575
}
7676
int r = menu->runAtPosition(x, y);

src/kys.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
<ClCompile Include="ChemistryEngine.cpp" />
116116
<ClCompile Include="Console.cpp" />
117117
<ClCompile Include="DrawableOnCall.cpp" />
118+
<ClCompile Include="DrawNode.cpp" />
118119
<ClCompile Include="InputBox.cpp" />
119120
<ClCompile Include="NewSave.cpp" />
120121
<ClCompile Include="Object.cpp" />
@@ -166,6 +167,7 @@
166167
<ClInclude Include="..\others\miniz.h" />
167168
<ClInclude Include="..\others\zip.h" />
168169
<ClInclude Include="BattleSceneHades.h" />
170+
<ClInclude Include="DrawNode.h" />
169171
<ClInclude Include="resource.h" />
170172
<ClInclude Include="Application.h" />
171173
<ClInclude Include="Audio.h" />

0 commit comments

Comments
 (0)