Convert to GL ES 2.0, batch Chunk transfer
This commit is contained in:
parent
0c7d72a76d
commit
ad6aed5179
@ -64,6 +64,7 @@ include_directories(
|
||||
${OPENAL_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
set(SRCS ";")
|
||||
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
|
||||
add_executable(diggler ${SRCS})
|
||||
@ -80,7 +81,7 @@ target_link_libraries(diggler
|
||||
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${PATH_TO_TOPDIR}/assets" "${PROJECT_BINARY_DIR}/assets")
|
||||
|
||||
install(TARGETS diggler RUNTIME DESTINATION bin)
|
||||
#install(TARGETS digglerz RUNTIME DESTINATION bin)
|
||||
|
||||
find_package(Doxygen)
|
||||
if (DOXYGEN_FOUND)
|
||||
|
@ -1,4 +1,6 @@
|
||||
uniform vec4 unicolor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
precision lowp float;
|
||||
|
||||
uniform vec4 unicolor;
|
||||
#ifdef COLORED
|
||||
varying vec4 v_color;
|
||||
#endif
|
||||
|
@ -1,4 +1,6 @@
|
||||
uniform vec4 unicolor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
precision lowp float;
|
||||
|
||||
uniform vec4 unicolor;
|
||||
#ifdef COLORED
|
||||
varying vec4 v_color;
|
||||
#endif
|
||||
@ -10,8 +12,8 @@ uniform vec2 texshift;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef FOG
|
||||
uniform float fogEnd = 32.0;
|
||||
uniform float fogStart = 16.0;
|
||||
uniform float fogEnd;
|
||||
uniform float fogStart;
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -38,6 +38,6 @@ void main(void) {
|
||||
gl_Position = mvp * vec4(coord, 1);
|
||||
#ifdef POINTSIZE
|
||||
float zDist = 1.0-(gl_Position.z / gl_Position.w); // 1=close 0=far
|
||||
gl_PointSize = pointSize*2048*zDist;
|
||||
gl_PointSize = pointSize*2048.0*zDist;
|
||||
#endif
|
||||
}
|
@ -1,15 +1,16 @@
|
||||
#define t(a,b) texture2D(mytexture, clamp(v_texcoord+vec2(a*pixshift.x,b*pixshift.y), vec2(0.0,0.0), vec2(1.0,1.0)))
|
||||
#define t(a,b) texture2D(mytexture, clamp(v_texcoord+vec2(a*pixshift.x, b*pixshift.y), 0.0, 1.0))
|
||||
precision lowp float;
|
||||
|
||||
varying vec2 v_texcoord;
|
||||
uniform sampler2D mytexture;
|
||||
uniform float bloomThreshold = 0.4;
|
||||
uniform vec2 pixshift;
|
||||
|
||||
void main(void) {
|
||||
vec4 c = (t(-2,2) + t(-1,2) + t(0,2) + t(1,2) + t(2,2) +
|
||||
t(-2,1) + t(-1,1) + t(0,1) + t(1,1) + t(2,1) +
|
||||
t(-2,0) + t(-1,0) + t(0,0) + t(1,0) + t(2,0) +
|
||||
t(-2,-1) + t(-1,-1) + t(0,-1) + t(1,-1) + t(2,-1) +
|
||||
t(-2,-2) + t(-1,-2) + t(0,-2) + t(1,-2) + t(2,-2))/10.0;
|
||||
gl_FragColor = c;
|
||||
gl_FragColor = (
|
||||
t(-2.0, 2.0) + t(-1.0, 2.0) + t(0.0, 2.0) + t(1.0, 2.0) + t(2.0, 2.0) +
|
||||
t(-2.0, 1.0) + t(-1.0, 1.0) + t(0.0, 1.0) + t(1.0, 1.0) + t(2.0, 1.0) +
|
||||
t(-2.0, 0.0) + t(-1.0, 0.0) + t(0.0, 0.0) + t(1.0, 0.0) + t(2.0, 0.0) +
|
||||
t(-2.0,-1.0) + t(-1.0,-1.0) + t(0.0,-1.0) + t(1.0,-1.0) + t(2.0,-1.0) +
|
||||
t(-2.0,-2.0) + t(-1.0,-2.0) + t(0.0,-2.0) + t(1.0,-2.0) + t(2.0,-2.0)
|
||||
)/10.0;
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
precision lowp float;
|
||||
|
||||
varying vec2 v_texcoord;
|
||||
uniform sampler2D mytexture;
|
||||
uniform float bloomThreshold = 0.4;
|
||||
uniform float bloomThreshold; // = 0.4;
|
||||
|
||||
vec3 cap(vec3 val) {
|
||||
float highest = val.x;
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
void addSound(const std::string &name, const std::string &path);
|
||||
void updatePos();
|
||||
void updateAngle();
|
||||
// Runs UpdatePos and UpdateAngle
|
||||
// Runs updatePos and updateAngle
|
||||
void update();
|
||||
void playSound(const std::string &name);
|
||||
void playSound(const SoundBuffer &buf);
|
||||
|
13
src/FBO.cpp
13
src/FBO.cpp
@ -17,14 +17,16 @@ namespace Diggler {
|
||||
FBO::FBO(int w, int h, Texture::PixelFormat format, bool stencil) : m_hasStencil(stencil) {
|
||||
GLint currentBoundFBO; glGetIntegerv(GL_FRAMEBUFFER_BINDING, ¤tBoundFBO);
|
||||
GLint currentBoundRBO; glGetIntegerv(GL_RENDERBUFFER_BINDING, ¤tBoundRBO);
|
||||
|
||||
|
||||
glGetError(); // Flush previous errors
|
||||
|
||||
tex = new Texture(w, h, format);
|
||||
glGenFramebuffers(1, &id);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *tex, 0);
|
||||
GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
|
||||
glDrawBuffers(1, DrawBuffers);
|
||||
|
||||
|
||||
glGenRenderbuffers(1, &rboId);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, rboId);
|
||||
if (stencil)
|
||||
@ -32,9 +34,9 @@ FBO::FBO(int w, int h, Texture::PixelFormat format, bool stencil) : m_hasStencil
|
||||
else
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, w, h);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, stencil ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboId);
|
||||
|
||||
|
||||
glCheck();
|
||||
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, currentBoundFBO);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, currentBoundRBO);
|
||||
}
|
||||
@ -47,7 +49,7 @@ void FBO::resize(int w, int h) {
|
||||
else
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, w, h);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, currentBoundRBO);
|
||||
|
||||
|
||||
tex->resize(w, h);
|
||||
}
|
||||
|
||||
@ -67,7 +69,6 @@ FBO::~FBO() {
|
||||
glDeleteFramebuffers(1, &id);
|
||||
delete tex;
|
||||
glDeleteRenderbuffers(1, &rboId);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,11 +34,16 @@ void Game::init() {
|
||||
}
|
||||
}
|
||||
|
||||
void Game::uninitGL() {
|
||||
delete PM;
|
||||
delete RP;
|
||||
}
|
||||
|
||||
Game::~Game() {
|
||||
if (GlobalProperties::IsClient) {
|
||||
delete A;
|
||||
delete CR;
|
||||
delete PM; delete LP;
|
||||
delete RP; delete A;
|
||||
delete LP;
|
||||
delete KB;
|
||||
}
|
||||
if (GlobalProperties::IsServer) {
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
|
||||
Game();
|
||||
void init();
|
||||
void uninitGL();
|
||||
void updateTime(double time);
|
||||
~Game();
|
||||
};
|
||||
|
@ -261,9 +261,9 @@ void GameState::onKey(int key, int scancode, int action, int mods) {
|
||||
}
|
||||
} else {
|
||||
if (key == G->KB->gameMenu && action == GLFW_PRESS) {
|
||||
isEscapeToggled = !isEscapeToggled;
|
||||
UI.EM->setVisible(isEscapeToggled);
|
||||
if (isEscapeToggled) {
|
||||
isMenuToggled = !isMenuToggled;
|
||||
UI.EM->setVisible(isMenuToggled);
|
||||
if (isMenuToggled) {
|
||||
unlockMouse();
|
||||
G->LP->goForward(false);
|
||||
G->LP->goBackward(false);
|
||||
@ -273,7 +273,7 @@ void GameState::onKey(int key, int scancode, int action, int mods) {
|
||||
lockMouse();
|
||||
}
|
||||
}
|
||||
if (!isEscapeToggled) {
|
||||
if (!isMenuToggled) {
|
||||
if (key == G->KB->forward) {
|
||||
G->LP->goForward(action == GLFW_PRESS);
|
||||
} else if (key == G->KB->backward) {
|
||||
@ -314,7 +314,7 @@ void GameState::unlockMouse() {
|
||||
|
||||
|
||||
void GameState::onMouseButton(int key, int action, int mods) {
|
||||
if (!m_mouseLocked && action == GLFW_PRESS && !isEscapeToggled) {
|
||||
if (!m_mouseLocked && action == GLFW_PRESS && !isMenuToggled) {
|
||||
lockMouse();
|
||||
}
|
||||
|
||||
@ -476,7 +476,7 @@ bool GameState::connectLoop() {
|
||||
};
|
||||
double T; glm::mat4 mat;
|
||||
|
||||
while (!finished && !glfwWindowShouldClose(*GW)) { // Infinite loop \o/
|
||||
while (!finished && !GW->shouldClose()) { // Infinite loop \o/
|
||||
T = glfwGetTime();
|
||||
G->updateTime(T);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
@ -495,12 +495,12 @@ bool GameState::connectLoop() {
|
||||
glfwSwapBuffers(*GW);
|
||||
glfwPollEvents();
|
||||
}
|
||||
if (glfwWindowShouldClose(*GW))
|
||||
glfwHideWindow(*GW);
|
||||
if (GW->shouldClose())
|
||||
GW->setVisible(false);
|
||||
m_networkThread.join();
|
||||
delete cUI.Connecting; delete cUI.Dot;
|
||||
|
||||
if (glfwWindowShouldClose(*GW))
|
||||
if (GW->shouldClose())
|
||||
return true;
|
||||
if (!success) {
|
||||
std::ostringstream oss;
|
||||
@ -723,7 +723,7 @@ void GameState::gameLoop() {
|
||||
renderDeathScreen();
|
||||
}
|
||||
|
||||
if (isEscapeToggled)
|
||||
if (isMenuToggled)
|
||||
UI.EM->render();
|
||||
|
||||
glfwSwapBuffers(*GW);
|
||||
|
@ -107,7 +107,7 @@ private:
|
||||
UI::Text *Dot;
|
||||
};
|
||||
|
||||
bool isEscapeToggled = false;
|
||||
bool isMenuToggled = false;
|
||||
|
||||
struct {
|
||||
bool show;
|
||||
|
@ -31,7 +31,7 @@ GameWindow::GameWindow(Game *G) : G(G) {
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
//glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||
glfwWindowHint(GLFW_SAMPLES, 0); // Gimme aliasing everywhere
|
||||
//glfwWindowHint(GLFW_STENCIL_BITS, 8);
|
||||
m_window = glfwCreateWindow(m_w, m_h, "Diggler", nullptr, nullptr);
|
||||
@ -77,9 +77,7 @@ GameWindow::GameWindow(Game *G) : G(G) {
|
||||
const uint8 *GL_renderer = glGetString(GL_RENDERER);
|
||||
getOutputStreamRaw() << "GL " << GL_version << " / " << GL_renderer << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
UIM.setProjMat(glm::ortho(0.0f, (float)m_w, 0.0f, (float)m_h));
|
||||
|
||||
G->init();
|
||||
@ -109,6 +107,14 @@ bool GameWindow::shouldClose() const {
|
||||
return glfwWindowShouldClose(m_window);
|
||||
}
|
||||
|
||||
void GameWindow::setVisible(bool visible) {
|
||||
return visible ? glfwShowWindow(m_window) : glfwHideWindow(m_window);
|
||||
}
|
||||
|
||||
bool GameWindow::isVisible() const {
|
||||
return glfwGetWindowAttrib(m_window, GLFW_VISIBLE);
|
||||
}
|
||||
|
||||
void GameWindow::cbChar(char32 unichar) {
|
||||
m_currentState->onChar(unichar);
|
||||
}
|
||||
|
@ -18,39 +18,43 @@ class State;
|
||||
class GameWindow {
|
||||
private:
|
||||
static int InstanceCount;
|
||||
|
||||
|
||||
GLFWwindow *m_window;
|
||||
int m_w, m_h;
|
||||
|
||||
|
||||
shared_ptr<State> m_currentState, m_nextState;
|
||||
|
||||
public:
|
||||
UI::Manager UIM;
|
||||
|
||||
|
||||
Game *G;
|
||||
|
||||
|
||||
GameWindow(Game*);
|
||||
~GameWindow();
|
||||
|
||||
|
||||
operator GLFWwindow&() const { return *m_window; }
|
||||
operator GLFWwindow*() const { return m_window; }
|
||||
|
||||
|
||||
inline int getW() const { return m_w; }
|
||||
inline int getH() const { return m_h; }
|
||||
|
||||
bool shouldClose() const;
|
||||
|
||||
|
||||
void setVisible(bool);
|
||||
bool isVisible() const;
|
||||
|
||||
void cbMouseButton(int key, int action, int mods);
|
||||
void cbCursorPos(double x, double y);
|
||||
void cbMouseScroll(double x, double y);
|
||||
void cbKey(int key, int scancode, int action, int mods);
|
||||
void cbChar(char32 unichar);
|
||||
void cbResize(int w, int h);
|
||||
|
||||
|
||||
void updateViewport();
|
||||
|
||||
|
||||
void setNextState(const shared_ptr<State> next);
|
||||
void run();
|
||||
|
||||
|
||||
void showMessage(const std::string &msg, const std::string &submsg = "");
|
||||
};
|
||||
|
||||
|
@ -35,6 +35,34 @@ bool Program::link() {
|
||||
getErrorStream() << id << ':' << getError() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Default values
|
||||
GLint loc = glGetUniformLocation(id, "unicolor");
|
||||
if (loc != -1) {
|
||||
GLint prevId; glGetIntegerv(GL_CURRENT_PROGRAM, &prevId);
|
||||
glUseProgram(id);
|
||||
glUniform4f(loc, 1.f, 1.f, 1.f, 1.f);
|
||||
glUseProgram(prevId);
|
||||
}
|
||||
|
||||
loc = glGetUniformLocation(id, "bloomThreshold");
|
||||
if (loc != -1) {
|
||||
GLint prevId; glGetIntegerv(GL_CURRENT_PROGRAM, &prevId);
|
||||
glUseProgram(id);
|
||||
glUniform1f(loc, .4f);
|
||||
glUseProgram(prevId);
|
||||
}
|
||||
|
||||
// FIXME: remove this, fog needs to be dynamic
|
||||
loc = glGetUniformLocation(id, "fogStart");
|
||||
if (loc != -1) {
|
||||
GLint prevId; glGetIntegerv(GL_CURRENT_PROGRAM, &prevId);
|
||||
glUseProgram(id);
|
||||
glUniform1f(loc, 16.f);
|
||||
glUniform1f(glGetUniformLocation(id, "fogEnd"), 32.f);
|
||||
glUseProgram(prevId);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -191,15 +191,21 @@ void Server::schedSendChunk(ChunkRef C, Player &P) {
|
||||
P.pendingChunks.emplace_back(C);
|
||||
}
|
||||
|
||||
void Server::sendChunk(Chunk &C, Player &P) {
|
||||
void Server::sendChunks(const std::list<ChunkRef> &cs, Player &P) {
|
||||
OutMessage msg(MessageType::ChunkTransfer);
|
||||
msg.writeU8(1); // Nbr of sent chunks
|
||||
msg.writeI16(C.getWorld()->id);
|
||||
glm::ivec3 pos = C.getWorldChunkPos();
|
||||
msg.writeI16(pos.x);
|
||||
msg.writeI16(pos.y);
|
||||
msg.writeI16(pos.z);
|
||||
C.send(msg);
|
||||
msg.writeU8(cs.size()); // Nbr of sent chunks
|
||||
for (const ChunkRef &cr : cs) {
|
||||
Chunk &c = *cr;
|
||||
msg.writeI16(c.getWorld()->id);
|
||||
glm::ivec3 pos = c.getWorldChunkPos();
|
||||
msg.writeI16(pos.x);
|
||||
msg.writeI16(pos.y);
|
||||
msg.writeI16(pos.z);
|
||||
c.send(msg);
|
||||
|
||||
getDebugStream() << "C[" << pos.x << ',' << pos.y << ',' << pos.z <<
|
||||
"] sent to " << P.name << std::endl;
|
||||
}
|
||||
H.send(P.P, msg, Tfer::Rel, Channels::MapUpdate);
|
||||
}
|
||||
|
||||
@ -327,16 +333,17 @@ void Server::chunkUpdater(WorldRef WR, bool &continueUpdate) {
|
||||
NetHelper::Broadcast(G, msg, Tfer::Rel, Channels::MapUpdate);
|
||||
}
|
||||
}
|
||||
std::list<ChunkRef> chunksToSend;
|
||||
for (Player &p : G.players) {
|
||||
for (auto it = p.pendingChunks.begin(); it != p.pendingChunks.end(); ++it) {
|
||||
chunksToSend.clear();
|
||||
for (auto it = p.pendingChunks.begin();
|
||||
it != p.pendingChunks.end() && chunksToSend.size() < 32; ++it) {
|
||||
if ((*it)->state == Chunk::State::Ready) {
|
||||
glm::ivec3 pos = (*it)->getWorldChunkPos();
|
||||
getDebugStream() << "Send pent Chunk[" << pos.x << ',' << pos.y << ',' << pos.z <<
|
||||
"] send to " << p.name << std::endl;
|
||||
sendChunk(**it, p);
|
||||
it = p.pendingChunks.erase(it)--;
|
||||
chunksToSend.push_back(std::move(*it));
|
||||
it = --p.pendingChunks.erase(it);
|
||||
}
|
||||
}
|
||||
sendChunks(chunksToSend, p);
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ private:
|
||||
void handlePlayerMapUpdate(Net::InMessage&, Player&);
|
||||
|
||||
void schedSendChunk(ChunkRef, Player&);
|
||||
void sendChunk(Chunk&, Player&);
|
||||
void sendChunks(const std::list<ChunkRef>&, Player&);
|
||||
|
||||
void chunkUpdater(WorldRef WR, bool &continueUpdate);
|
||||
|
||||
|
@ -40,9 +40,10 @@ bool Shader::compileFromString(const std::string &source, const std::string &pat
|
||||
if (source.size() == 0)
|
||||
return false;
|
||||
std::ostringstream oss;
|
||||
oss << "#version 120\n";
|
||||
oss << "#version 100\n";
|
||||
if (srcDefines)
|
||||
oss << srcDefines;
|
||||
oss << "#line 1\n";
|
||||
oss << source;
|
||||
// Beware of the lifetime, we use c_str() afterwards!
|
||||
std::string srcStr = oss.str();
|
||||
|
@ -58,7 +58,7 @@ SoundBuffer::~SoundBuffer() {
|
||||
|
||||
void SoundBuffer::loadOgg(const std::string &path) {
|
||||
int error = 0;
|
||||
stb_vorbis* stream = stb_vorbis_open_filename(const_cast<char*>(path.c_str()), &error, nullptr);
|
||||
stb_vorbis *stream = stb_vorbis_open_filename(const_cast<char*>(path.c_str()), &error, nullptr);
|
||||
if (stream == nullptr) {
|
||||
getDebugStream() << "Could not load " << path << " : " << error << std::endl;
|
||||
return;
|
||||
|
@ -125,9 +125,9 @@ int main(int argc, char **argv) {
|
||||
if (networkSuccess)
|
||||
GW.setNextState(std::make_shared<GameState>(&GW, host, port));
|
||||
else
|
||||
GW.setNextState(std::make_shared<MessageState>(&GW, "Network init failed!"));
|
||||
GW.setNextState(std::make_shared<UITestState>(&GW));
|
||||
GW.showMessage("Network init failed!");
|
||||
GW.run();
|
||||
G.uninitGL();
|
||||
}
|
||||
if (GlobalProperties::IsServer) {
|
||||
if (!networkSuccess) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user