|
@@ -1,36 +1,20 @@
|
|
#include "client/Main.h"
|
|
#include "client/Main.h"
|
|
|
|
+#include "client/Chat.h"
|
|
#include "client/Controls.h"
|
|
#include "client/Controls.h"
|
|
|
|
+#include "client/FontRenderer.h"
|
|
#include "client/Network.h"
|
|
#include "client/Network.h"
|
|
#include "client/Player.h"
|
|
#include "client/Player.h"
|
|
#include "client/World.h"
|
|
#include "client/World.h"
|
|
#include "common/NetworkPackets.h"
|
|
#include "common/NetworkPackets.h"
|
|
-#include "data/Array.h"
|
|
|
|
-#include "data/RingBuffer.h"
|
|
|
|
-#include "math/Box.h"
|
|
|
|
#include "math/View.h"
|
|
#include "math/View.h"
|
|
#include "network/Client.h"
|
|
#include "network/Client.h"
|
|
-#include "rendering/Shader.h"
|
|
|
|
-#include "rendering/Texture.h"
|
|
|
|
#include "rendering/VertexBuffer.h"
|
|
#include "rendering/VertexBuffer.h"
|
|
#include "rendering/Window.h"
|
|
#include "rendering/Window.h"
|
|
#include "utils/Buffer.h"
|
|
#include "utils/Buffer.h"
|
|
|
|
|
|
-static Shader fontShader;
|
|
|
|
static VertexBuffer markVertexBuffer;
|
|
static VertexBuffer markVertexBuffer;
|
|
-static VertexBuffer fontBuffer;
|
|
|
|
-static Texture fontTexture;
|
|
|
|
-
|
|
|
|
HashMap<int, OtherPlayer> players;
|
|
HashMap<int, OtherPlayer> players;
|
|
|
|
|
|
-static Array<ChatMessage, 20> chat;
|
|
|
|
-static int chatIndex = 0;
|
|
|
|
-bool renderInput = false;
|
|
|
|
-
|
|
|
|
-void addToChat(const ChatMessage& msg) {
|
|
|
|
- chat[chatIndex] = msg;
|
|
|
|
- chatIndex = (chatIndex + 1) % chat.getLength();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static bool isRunning() {
|
|
static bool isRunning() {
|
|
return !Window::shouldClose();
|
|
return !Window::shouldClose();
|
|
}
|
|
}
|
|
@@ -42,22 +26,10 @@ static void addTriangle(Buffer& buffer, const Vector3& a, const Vector3& b,
|
|
}
|
|
}
|
|
|
|
|
|
static bool init() {
|
|
static bool init() {
|
|
- if(World::init()) {
|
|
+ if(World::init() || FontRenderer::init()) {
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- Error e = fontShader.compile("resources/shader/fontTest.vs",
|
|
|
|
- "resources/shader/fontTest.fs");
|
|
|
|
- if(e.has()) {
|
|
|
|
- e.message.printLine();
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- e = fontTexture.load("resources/font8x8.png", 0);
|
|
|
|
- if(e.has()) {
|
|
|
|
- e.message.printLine();
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
markVertexBuffer.init(VertexBuffer::Attributes().addFloat(3).addFloat(3));
|
|
markVertexBuffer.init(VertexBuffer::Attributes().addFloat(3).addFloat(3));
|
|
- fontBuffer.init(VertexBuffer::Attributes().addFloat(3).addFloat(2));
|
|
|
|
|
|
|
|
Vector3 v000(0, 0, 0);
|
|
Vector3 v000(0, 0, 0);
|
|
Vector3 v001(0, 0, 1);
|
|
Vector3 v001(0, 0, 1);
|
|
@@ -88,27 +60,7 @@ static bool init() {
|
|
}
|
|
}
|
|
|
|
|
|
static void tick() {
|
|
static void tick() {
|
|
- if(renderInput) {
|
|
+ if(!Chat::isActive()) {
|
|
- if(Controls::wasReleased(Controls::enter)) {
|
|
|
|
- OutPacket out(100);
|
|
|
|
- out.writeU8(static_cast<uint8>(ToServerPacket::CHAT));
|
|
|
|
- for(uint32 u : Window::Input::getUnicode()) {
|
|
|
|
- out.writeU32(u);
|
|
|
|
- }
|
|
|
|
- Client::send(out, PacketSendMode::RELIABLE);
|
|
|
|
- Window::Input::reset();
|
|
|
|
- }
|
|
|
|
- if(Controls::wasReleased(Controls::escape)) {
|
|
|
|
- Window::Input::disable();
|
|
|
|
- Window::trapCursor();
|
|
|
|
- renderInput = false;
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if(Controls::isDown(Controls::chat)) {
|
|
|
|
- Window::Input::enable();
|
|
|
|
- Window::freeCursor();
|
|
|
|
- renderInput = true;
|
|
|
|
- }
|
|
|
|
if(Controls::wasReleased(Controls::primaryClick)) {
|
|
if(Controls::wasReleased(Controls::primaryClick)) {
|
|
Window::trapCursor();
|
|
Window::trapCursor();
|
|
}
|
|
}
|
|
@@ -116,14 +68,14 @@ static void tick() {
|
|
Window::freeCursor();
|
|
Window::freeCursor();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
+ Chat::tick();
|
|
Player::tick();
|
|
Player::tick();
|
|
for(OtherPlayer& p : players.values()) {
|
|
for(OtherPlayer& p : players.values()) {
|
|
p.position.update();
|
|
p.position.update();
|
|
}
|
|
}
|
|
Network::tick();
|
|
Network::tick();
|
|
|
|
|
|
- if(Controls::wasReleased(Controls::primaryClick) && !renderInput) {
|
|
+ if(Controls::wasReleased(Controls::primaryClick) && !Chat::isActive()) {
|
|
RayTrace rt =
|
|
RayTrace rt =
|
|
World::rayTrace(Player::getPosition() + Vector3(0.0f, 0.8f, 0.0f),
|
|
World::rayTrace(Player::getPosition() + Vector3(0.0f, 0.8f, 0.0f),
|
|
Player::getLook(), 10.0f);
|
|
Player::getLook(), 10.0f);
|
|
@@ -145,40 +97,6 @@ static void tick() {
|
|
Client::send(out, PacketSendMode::RELIABLE);
|
|
Client::send(out, PacketSendMode::RELIABLE);
|
|
}
|
|
}
|
|
|
|
|
|
-static void renderString(const char* text) {
|
|
|
|
- static Buffer buffer(50);
|
|
|
|
- buffer.clear();
|
|
|
|
- constexpr float fontSize = 8.0f;
|
|
|
|
- constexpr float fontStep = 8.0f / 128.0f;
|
|
|
|
- int index = 0;
|
|
|
|
- Vector3 pos;
|
|
|
|
- int vertices = 0;
|
|
|
|
- while(text[index] != '\0') {
|
|
|
|
- Vector3 right = pos + Vector3(fontSize, 0.0f, 0.0f);
|
|
|
|
- Vector3 down = pos + Vector3(0.0f, fontSize, 0.0f);
|
|
|
|
- Vector3 downRight = pos + Vector3(fontSize, fontSize, 0.0f);
|
|
|
|
-
|
|
|
|
- int i = text[index];
|
|
|
|
- if(i < 0 && text[index + 1] != '\0') {
|
|
|
|
- index++;
|
|
|
|
- i = ((i & 0x1F) << 6) | (text[index] & 0x3F);
|
|
|
|
- }
|
|
|
|
- Vector2 tPos(fontStep * (i % 16), fontStep * (i / 16));
|
|
|
|
- Vector2 tRight = tPos + Vector2(fontStep, 0.0f);
|
|
|
|
- Vector2 tDown = tPos + Vector2(0.0f, fontStep);
|
|
|
|
- Vector2 tDownRight = tPos + Vector2(fontStep, fontStep);
|
|
|
|
-
|
|
|
|
- buffer.add(pos).add(tPos).add(down).add(tDown).add(right).add(tRight);
|
|
|
|
- buffer.add(down).add(tDown).add(right).add(tRight).add(downRight).add(
|
|
|
|
- tDownRight);
|
|
|
|
- pos += Vector3(fontSize, 0.0f, 0.0f);
|
|
|
|
- vertices += 6;
|
|
|
|
- index++;
|
|
|
|
- }
|
|
|
|
- fontBuffer.setData(buffer, GL::DYNAMIC_DRAW);
|
|
|
|
- fontBuffer.draw(vertices);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static void render(float lag) {
|
|
static void render(float lag) {
|
|
GL::clear();
|
|
GL::clear();
|
|
GL::enableDepthTesting();
|
|
GL::enableDepthTesting();
|
|
@@ -218,40 +136,7 @@ static void render(float lag) {
|
|
World::shader.setMatrix("model", model);
|
|
World::shader.setMatrix("model", model);
|
|
markVertexBuffer.draw(36);
|
|
markVertexBuffer.draw(36);
|
|
|
|
|
|
- GL::disableDepthTesting();
|
|
+ Chat::render();
|
|
- GL::enableBlending();
|
|
|
|
- fontShader.use();
|
|
|
|
- fontShader.setMatrix("proj", Matrix());
|
|
|
|
- Matrix v;
|
|
|
|
- IntVector2 size = Window::getSize();
|
|
|
|
- v.scale(Vector3(2.0f / size[0], -2.0f / size[1], 1.0f));
|
|
|
|
- v.translate(Vector3(-1.0f, 1.0f, 0.0f));
|
|
|
|
- fontShader.setMatrix("view", v);
|
|
|
|
- fontTexture.bindTo(0);
|
|
|
|
-
|
|
|
|
- for(int i = 0; i < chat.getLength(); i++) {
|
|
|
|
- model.translateTo(Vector3(0.0f, i * 8.0f, 0.0f)).scale(3.0f);
|
|
|
|
- fontShader.setMatrix("model", model);
|
|
|
|
- renderString(chat[(i + chatIndex) % chat.getLength()]);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(renderInput) {
|
|
|
|
- model.translateTo(Vector3(0.0f, chat.getLength() * 8.0f, 0.0f))
|
|
|
|
- .scale(3.0f);
|
|
|
|
- fontShader.setMatrix("model", model);
|
|
|
|
- StringBuffer<256> s;
|
|
|
|
- Window::Input::toString(s);
|
|
|
|
- renderString(s);
|
|
|
|
-
|
|
|
|
- model
|
|
|
|
- .translateTo(Vector3(Window::Input::getCursor() * 8.0f,
|
|
|
|
- chat.getLength() * 8.0f + 2.0f, 0.0f))
|
|
|
|
- .scale(3.0f);
|
|
|
|
- fontShader.setMatrix("model", model);
|
|
|
|
- renderString("_");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- GL::disableBlending();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
static void startWindow() {
|
|
static void startWindow() {
|