Weird derived class initialization error.
This commit is contained in:
@@ -25,7 +25,7 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
NAME ReWindow
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-16.zip
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-19.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
|
@@ -11,13 +11,17 @@ if (WIN32)
|
||||
add_library(CaveClient SHARED ${CaveClient_SRC})
|
||||
endif()
|
||||
|
||||
target_include_directories(CaveClient PUBLIC ${CaveCore_SOURCE_DIR}/include)
|
||||
target_include_directories(CaveClient PUBLIC
|
||||
${CaveCore_SOURCE_DIR}/include
|
||||
${J3ML_SOURCE_DIR}/include
|
||||
${JGL_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
target_include_directories(CaveClient PUBLIC "include")
|
||||
|
||||
|
||||
set_target_properties(CaveClient PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
target_link_libraries(CaveClient PUBLIC CaveCore)
|
||||
target_link_libraries(CaveClient PUBLIC CaveCore J3ML JGL)
|
||||
|
||||
|
||||
|
@@ -5,16 +5,17 @@ namespace CaveGame::Client
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
Scene();
|
||||
/// @note Make sure to call this base when overriding in derived Scene classes.
|
||||
virtual void Load();
|
||||
/// @note Make sure to call this base when overriding in derived Scene classes.
|
||||
virtual void Unload();
|
||||
virtual void Update(float elapsed) = 0;
|
||||
virtual void Draw() = 0;
|
||||
bool Active() const;
|
||||
[[nodiscard]] bool Active() const;
|
||||
protected:
|
||||
private:
|
||||
bool active;
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Client/Scene.hpp>
|
||||
#include <JGL/types/Texture.h>
|
||||
|
||||
namespace CaveGame::Client
|
||||
{
|
||||
@@ -10,8 +11,21 @@ namespace CaveGame::Client
|
||||
class Splash : public Scene
|
||||
{
|
||||
public:
|
||||
protected:
|
||||
Splash();
|
||||
|
||||
void Draw() override;
|
||||
void Update(float elapsed) override;
|
||||
void Load() override;
|
||||
void Unload() override;
|
||||
|
||||
void PassWindowSize(const Vector2& size);
|
||||
void PassFont(JGL::Font passed);
|
||||
private:
|
||||
float splash_timer = 5.f;
|
||||
float load_percent = 0.f;
|
||||
JGL::Texture splash;
|
||||
JGL::Font* font = nullptr;
|
||||
Vector2 window_size;
|
||||
|
||||
};
|
||||
}
|
@@ -9,3 +9,7 @@ void CaveGame::Client::Scene::Load() {
|
||||
void CaveGame::Client::Scene::Unload() {
|
||||
active = false;
|
||||
}
|
||||
|
||||
CaveGame::Client::Scene::Scene() {
|
||||
active = false;
|
||||
}
|
||||
|
@@ -1 +1,78 @@
|
||||
#include <Client/Splash.hpp>
|
||||
#include <Client/Splash.hpp>
|
||||
#include <JGL/JGL.h>
|
||||
|
||||
CaveGame::Client::Splash::Splash() : Scene()
|
||||
{
|
||||
font = new JGL::Font();
|
||||
}
|
||||
|
||||
void CaveGame::Client::Splash::Draw()
|
||||
{
|
||||
|
||||
auto texture_dimensions = splash.GetDimensions();
|
||||
auto screen_dimensions = window_size;
|
||||
|
||||
Vector2 aspect = {
|
||||
screen_dimensions.x / texture_dimensions.x,
|
||||
screen_dimensions.y / texture_dimensions.y
|
||||
};
|
||||
|
||||
Vector2 middle = screen_dimensions/2.f;
|
||||
|
||||
// TODO: Implement draw-point offset to maintain sensible aspect ratio on the image.
|
||||
|
||||
JGL::J2D::Begin();
|
||||
JGL::J2D::DrawSprite(splash, {0, 0}, 0.f, {0, 0}, aspect);
|
||||
|
||||
|
||||
Color4 text_col = {32, 192, 92};
|
||||
for (int cols = 0; cols < (screen_dimensions.x / 16); cols++)
|
||||
{
|
||||
JGL::J2D::DrawString(text_col, "0", cols*16, 0, 1, 16, font);
|
||||
}
|
||||
|
||||
|
||||
float bar_length = screen_dimensions.x-20;
|
||||
float bar_height = 20;
|
||||
float bar_pos_x = 10;
|
||||
float bar_pos_y = (screen_dimensions.y-bar_height)-10;
|
||||
|
||||
Vector2 bar_pos = {bar_pos_x, bar_pos_y};
|
||||
|
||||
JGL::J2D::FillRect(Colors::Gray, bar_pos, {bar_length, bar_height});
|
||||
|
||||
float progress_bar_length = bar_length * load_percent;
|
||||
|
||||
JGL::J2D::FillRect(Colors::White, bar_pos, {progress_bar_length, bar_height});
|
||||
|
||||
JGL::J2D::End();
|
||||
}
|
||||
|
||||
void CaveGame::Client::Splash::Update(float elapsed)
|
||||
{
|
||||
|
||||
if (load_percent < 1)
|
||||
load_percent += elapsed/4.f;
|
||||
else
|
||||
load_percent = 1;
|
||||
|
||||
splash_timer -= elapsed;
|
||||
}
|
||||
|
||||
void CaveGame::Client::Splash::Load() {
|
||||
splash = JGL::Texture("assets/redacted.png");
|
||||
|
||||
Scene::Load();
|
||||
}
|
||||
|
||||
void CaveGame::Client::Splash::Unload() {
|
||||
Scene::Unload();
|
||||
}
|
||||
|
||||
void CaveGame::Client::Splash::PassFont(JGL::Font* passed) {
|
||||
font = passed;
|
||||
}
|
||||
|
||||
void CaveGame::Client::Splash::PassWindowSize(const Vector2 &size) {
|
||||
window_size = size;
|
||||
}
|
||||
|
BIN
ClientApp/assets/redacted.png
Normal file
BIN
ClientApp/assets/redacted.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 336 KiB |
@@ -4,6 +4,7 @@
|
||||
#include <Core/Perlin.hpp>
|
||||
#include <J3ML/Geometry.hpp>
|
||||
#include <Client/Scene.hpp>
|
||||
#include <Client/Splash.hpp>
|
||||
|
||||
using CaveGame::Client::Scene;
|
||||
|
||||
@@ -31,11 +32,14 @@ J3ML::Geometry::QuadTree<int> tileset;
|
||||
JGL::Font Jupiteroid;
|
||||
float z = 0;
|
||||
|
||||
//Vector2 CaveGame::Client::Splash::window_size = {0, 0};
|
||||
|
||||
|
||||
class CaveGameWindow : public ReWindow::RWindow
|
||||
{
|
||||
public:
|
||||
|
||||
Scene* current_scene;
|
||||
Scene* current_scene = nullptr;
|
||||
|
||||
void ChangeScene(Scene* new_scene)
|
||||
{
|
||||
@@ -46,12 +50,6 @@ public:
|
||||
current_scene->Load();
|
||||
}
|
||||
|
||||
uint64_t frame_count = 0;
|
||||
float frame_rate = 0;
|
||||
float avg_frame_rate = 0;
|
||||
float delta_time = 0;
|
||||
float last_frame_elapsed = 0;
|
||||
|
||||
bool render_grid = true;
|
||||
bool generate_grid = true;
|
||||
|
||||
@@ -71,7 +69,6 @@ public:
|
||||
glDepthFunc(GL_LESS);
|
||||
glDepthMask(GL_TRUE);
|
||||
|
||||
|
||||
procgen();
|
||||
}
|
||||
|
||||
@@ -147,6 +144,27 @@ public:
|
||||
JGL::J2D::End();
|
||||
}
|
||||
|
||||
|
||||
void update(float elapsed)
|
||||
{
|
||||
|
||||
if (current_scene != nullptr)
|
||||
current_scene->Update(elapsed);
|
||||
|
||||
if (generate_grid) {
|
||||
//if (frame_count % 2 == 0)
|
||||
// procgen();
|
||||
}
|
||||
|
||||
if (elapsed < 1.f/999.f)
|
||||
{
|
||||
std::this_thread::sleep_for(1ms);
|
||||
}
|
||||
|
||||
//CaveGame::Client::Splash::window_size = getSize();
|
||||
|
||||
}
|
||||
|
||||
void display()
|
||||
{
|
||||
JGL::Update(getSize());
|
||||
@@ -155,14 +173,19 @@ public:
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
if (render_grid)
|
||||
draw_grid();
|
||||
//if (render_grid)
|
||||
//draw_grid();
|
||||
|
||||
if (current_scene != nullptr)
|
||||
current_scene->Draw();
|
||||
|
||||
|
||||
|
||||
draw_debug_info({
|
||||
"Re-CaveGame - Redacted Software",
|
||||
std::format("frame: {}", frame_count),
|
||||
std::format("frame: {}", refresh_count),
|
||||
std::format("delta: {}ms", J3ML::Math::Round(delta_time*1000)),
|
||||
std::format("fps: {}", J3ML::Math::Round(frame_rate)),
|
||||
std::format("fps: {}", J3ML::Math::Round(refresh_rate)),
|
||||
});
|
||||
|
||||
|
||||
@@ -190,31 +213,26 @@ public:
|
||||
|
||||
void OnRefresh(float elapsed) override
|
||||
{
|
||||
auto begin_frame = std::chrono::high_resolution_clock::now();
|
||||
|
||||
if (generate_grid) {
|
||||
if (frame_count % 2 == 0)
|
||||
procgen();
|
||||
}
|
||||
|
||||
//auto begin_frame = std::chrono::high_resolution_clock::now();
|
||||
|
||||
update(elapsed);
|
||||
display();
|
||||
int glError = glGetError();
|
||||
if (glError != GL_NO_ERROR)
|
||||
std::cout << glError << std::endl;
|
||||
glSwapBuffers();
|
||||
|
||||
auto end_frame = std::chrono::high_resolution_clock::now();
|
||||
//auto end_frame = std::chrono::high_resolution_clock::now();
|
||||
|
||||
auto frame_time = end_frame - begin_frame;
|
||||
int frame_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(frame_time).count();
|
||||
float frame_time_s = frame_time_ms / 1000.f;
|
||||
//auto frame_time = end_frame - begin_frame;
|
||||
//int frame_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(frame_time).count();
|
||||
//float frame_time_s = frame_time_ms / 1000.f;
|
||||
|
||||
delta_time = frame_time_s;
|
||||
//delta_time = frame_time_s;
|
||||
|
||||
frame_rate = 1.f / delta_time;
|
||||
//frame_rate = 1.f / delta_time;
|
||||
|
||||
frame_count++;
|
||||
//frame_count++;
|
||||
}
|
||||
|
||||
void OnMouseButtonDown(const ReWindow::WindowEvents::MouseButtonDownEvent &ev) override
|
||||
@@ -255,6 +273,11 @@ int main() {
|
||||
window->setResizable(true);
|
||||
window->setVsyncEnabled(false);
|
||||
|
||||
//auto* splash = new CaveGame::Client::Splash();
|
||||
//splash->PassFont(Jupiteroid);
|
||||
|
||||
window->ChangeScene(new CaveGame::Client::Splash());
|
||||
|
||||
while (window->isAlive()) {
|
||||
window->pollEvents();
|
||||
window->refresh();
|
||||
|
Reference in New Issue
Block a user