-
Notifications
You must be signed in to change notification settings - Fork 0
/
povray_platform.cpp
137 lines (130 loc) · 4.97 KB
/
povray_platform.cpp
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
//
// Created by kouta on 24/7/20.
//
#include "povray_platform.h"
#include <fmt/core.h>
#include <fstream>
#include <sstream>
#include <SDL2/SDL.h>
gltactics::povray_platform::povray_platform(gltactics::game_manager &gameManager) : gameManager(gameManager) {}
void gltactics::povray_platform::initialize() {
frameN = 0;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
this->window = SDL_CreateWindow("Abstract Terror Strike - POVRAY", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
800, 600, SDL_WINDOW_SHOWN);
this->winSurface = SDL_GetWindowSurface(window);
}
void gltactics::povray_platform::render() {
std::ostringstream s;
auto[y, x] = gameManager.getPlayerCharacter().position();
s << "#include \"colors.inc\"\n"
" camera {\n" +
fmt::format(" location <{}, 40, {}>\n", x, y) +
fmt::format(" look_at <{}, 0, {}>\n", x, y) +
" angle 90\n"
" }\n"
"\n"
" light_source { <500, 500, -1000> White }\n"
"\n"
"union {\n"
" box {\n"
" <0, -0.5, 0>,\n"
" <24, 0, 24>\n"
" pigment { Blue }\n"
" }\n";
std::vector<std::array<size_t, 2>> walls;
std::vector<std::array<size_t, 2>> chests;
std::vector<std::array<size_t, 2>> vDoor;
std::vector<std::array<size_t, 2>> hDoor;
std::vector<std::array<size_t, 2>> stairs;
for (size_t y = 0; y < gltactics::DEFAULT_MAPSIZE; y++) {
for (size_t x = 0; x < gltactics::DEFAULT_MAPSIZE; x++) {
gltactics::tile tile = gameManager.getMap()[{y, x}];
switch (tile.tileType) {
case gltactics::type::WALL:
walls.push_back(std::array<size_t, 2>{y, x});
break;
case gltactics::type::DOOR:
if (!tile.isOpen()) {
if (tile.isHorizontal()) {
hDoor.push_back(std::array<size_t, 2>{y, x});
} else {
vDoor.push_back(std::array<size_t, 2>{y, x});
}
}
break;
case gltactics::type::CHEST:
chests.push_back(std::array<size_t, 2>{y, x});
break;
case gltactics::type::EXIT:
stairs.push_back(std::array<size_t, 2>{y, x});
break;
}
}
}
for (auto[y, x] : walls) {
s << " box {\n" <<
fmt::format(" <{}, 0, {}>,\n", x, y) <<
fmt::format(" <{}, 1, {}>", x + 1, y + 1) << "\n }\n";
}
s << " pigment { White }\n}\n";
for (auto[y, x] : chests) {
s << " box {\n" <<
fmt::format(" <{}, 0, {}>,\n", float(x) + 0.3, float(y) + 0.3) <<
fmt::format(" <{}, 0.5, {}>\n", float(x) + 0.7, float(y) + 0.7) <<
" pigment { Yellow }\n }\n";
}
for (auto[y, x] : vDoor) {
s << " box {\n" <<
fmt::format(" <{}, 0, {}>,\n", float(x) + 0.4, float(y)) <<
fmt::format(" <{}, 1, {}>\n", float(x) + 0.6, float(y) + 1) <<
" pigment { Yellow }\n }\n";
}
for (auto[y, x] : hDoor) {
s << " box {\n" <<
fmt::format(" <{}, 0, {}>,\n", float(x), float(y) + 0.4) <<
fmt::format(" <{}, 1, {}>\n", float(x) + 1, float(y) + 0.6) <<
" pigment { Yellow }\n }\n";
}
s << " box {\n" <<
fmt::format(" <{}, 0, {}>,\n", float(x), float(y)) <<
fmt::format(" <{}, 1, {}>\n", float(x) + 1, float(y) + 1) <<
" pigment { Orange }\n }\n";
std::ofstream frame(fmt::format("/tmp/atsframe.pov", frameN++));
frame << s.str();
frame.close();
system("povray /tmp/atsframe.pov +Fb -o/tmp/atsframe.bmp");
auto frameSurf = SDL_LoadBMP("/tmp/atsframe.bmp");
SDL_BlitSurface(frameSurf, NULL, winSurface, NULL);
SDL_FreeSurface(frameSurf);
SDL_UpdateWindowSurface(window);
}
gltactics::input_status gltactics::povray_platform::get_input() {
SDL_Event e;
input_status status = input_status();
while (SDL_PollEvent(&e)) {
if (e.type == SDL_KEYUP) {
switch (e.key.keysym.sym) {
case SDLK_UP:
status.movementDirection = gltactics::direction::up;
break;
case SDLK_DOWN:
status.movementDirection = gltactics::direction::down;
break;
case SDLK_LEFT:
status.movementDirection = gltactics::direction::left;
break;
case SDLK_RIGHT:
status.movementDirection = gltactics::direction::right;
break;
case SDLK_f:
status.environment = true;
break;
case SDLK_e:
status.items = true;
break;
}
}
}
return status;
}