SEGFAULT in LookForChunksNeedUnloading()
This commit is contained in:
@@ -36,6 +36,7 @@ namespace CaveGame::Client
|
||||
void RenderChunk(const Vector2& coords, Core::Chunk* chunk);
|
||||
|
||||
void LookForChunksNeedLoading();
|
||||
void LookForChunksNeedUnloading();
|
||||
|
||||
void RequestChunk(const Vector2& cell);
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include <format>
|
||||
#include "Client/LocalWorld.hpp"
|
||||
#include "JGL/JGL.h"
|
||||
#include <Core/Data.hpp>
|
||||
|
||||
namespace CaveGame::Client
|
||||
{
|
||||
@@ -71,6 +72,10 @@ namespace CaveGame::Client
|
||||
}
|
||||
|
||||
DrawChunkGrid();
|
||||
|
||||
// Banana for scale.
|
||||
JGL::J2D::FillRect(Colors::Yellow, {0,0}, {32, 48});
|
||||
|
||||
JGL::J2D::End();
|
||||
}
|
||||
|
||||
@@ -94,18 +99,18 @@ namespace CaveGame::Client
|
||||
Vector2 relative_tile_coords = Vector2(x, y);
|
||||
Vector2 real_tile_coords = relative_tile_coords;
|
||||
|
||||
if (tile == 0) // Air
|
||||
if (tile == Core::AIR) // Air
|
||||
continue;
|
||||
if (tile == 1) // Stone
|
||||
if (tile == Core::STONE) // Stone
|
||||
JGL::J2D::FillRect(Colors::Gray, real_tile_coords, {1,1});
|
||||
if (tile == 2) // Dirt
|
||||
if (tile == Core::DIRT) // Dirt
|
||||
JGL::J2D::FillRect(Colors::Browns::Chocolate, real_tile_coords, {1,1});
|
||||
if (tile == 3) // Grass
|
||||
if (tile == Core::GRASS) // Grass
|
||||
JGL::J2D::FillRect(Colors::Green, real_tile_coords, {1,1});
|
||||
if (tile == 4) // Ore
|
||||
JGL::J2D::FillRect(Colors::Yellows::Moccasin, real_tile_coords, {1,1});
|
||||
if (tile == 5) // Water
|
||||
JGL::J2D::FillRect(Colors::Blue, real_tile_coords, {1,1});
|
||||
if (tile == Core::CLAY) // Ore
|
||||
JGL::J2D::FillRect(Colors::Reds::Firebrick, real_tile_coords, {1,1});
|
||||
if (tile == Core::MUD) // Water
|
||||
JGL::J2D::FillRect(Colors::Browns::BurlyWood, real_tile_coords, {1,1});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -119,6 +124,17 @@ namespace CaveGame::Client
|
||||
|
||||
}
|
||||
|
||||
void LocalWorld::LookForChunksNeedUnloading()
|
||||
{
|
||||
for (auto[coords, chunk] : loaded_chunks)
|
||||
{
|
||||
if (!IsChunkCellWithinViewport(coords))
|
||||
{
|
||||
loaded_chunks.erase(coords);
|
||||
cached_chunk_sprites.erase(coords);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LocalWorld::LookForChunksNeedLoading()
|
||||
{
|
||||
@@ -156,6 +172,7 @@ namespace CaveGame::Client
|
||||
camera.Update(elapsed);
|
||||
|
||||
LookForChunksNeedLoading();
|
||||
LookForChunksNeedUnloading();
|
||||
|
||||
|
||||
// TODO: Unload chunks once they're offscreen for a certain time threshold.
|
||||
|
@@ -17,10 +17,15 @@ namespace CaveGame::ClientApp
|
||||
using CaveGame::Client::Scene;
|
||||
using CaveGame::Client::SceneManager;
|
||||
|
||||
/// The main program class. Everything originates here.
|
||||
/// This class is derived from RWindow class.
|
||||
class CaveGameWindow : public ReWindow::RWindow, public SceneManager
|
||||
{
|
||||
public:
|
||||
bool wanna_die = false;
|
||||
|
||||
bool InGameSession() const;
|
||||
bool InMainMenu() const;
|
||||
|
||||
CaveGame::Client::Splash* splash_ctx;
|
||||
CaveGame::Client::MainMenu* menu_ctx;
|
||||
CaveGame::Client::GameSession* game_ctx;
|
||||
@@ -40,11 +45,16 @@ namespace CaveGame::ClientApp
|
||||
|
||||
JGL::Font Jupiteroid;
|
||||
|
||||
|
||||
/// Constructs and returns an instance of the game program.
|
||||
/// @param title
|
||||
CaveGameWindow(const std::string& title, int width, int height);
|
||||
|
||||
/// This function runs the totality of the game loop, start to finish.
|
||||
/// @note The game loop runs until Die() is called, at which point final cleanup is performed.
|
||||
void Run();
|
||||
|
||||
/// This function triggers an internal signal that the game window is ready to close.
|
||||
/// @note This does not immediately close the window, rather, time is given to allow for final data saving and other processes.
|
||||
void Die();
|
||||
|
||||
void create_console_window()
|
||||
@@ -52,40 +62,39 @@ namespace CaveGame::ClientApp
|
||||
|
||||
}
|
||||
|
||||
JUI::TextRect* line_item(const std::string& content, int size, JUI::Widget* parent);
|
||||
|
||||
void create_credits_window();
|
||||
|
||||
void create_stats_window();
|
||||
|
||||
void create_settings_window();
|
||||
|
||||
void create_window_widgets();
|
||||
|
||||
/// This function sets up the initial program state, particularly that which must be performed **after** the window is opened.
|
||||
void Init();
|
||||
/// This function cleans up any data or assets before closing the game.
|
||||
void Cleanup();
|
||||
|
||||
void draw_debug_info(std::vector<std::string> tokens);
|
||||
/// This function performs logic calculation routines, once per refresh.
|
||||
void Update(float elapsed);
|
||||
|
||||
/// This function performs rendering routines, once per refresh.
|
||||
void Draw();
|
||||
|
||||
void update(float elapsed);
|
||||
|
||||
void display();
|
||||
|
||||
public:
|
||||
void OnRefresh(float elapsed) override;
|
||||
|
||||
void OnMouseButtonDown(const ReWindow::WindowEvents::MouseButtonDownEvent &ev) override;
|
||||
|
||||
void OnKeyUp(const ReWindow::WindowEvents::KeyUpEvent &ev) override;
|
||||
|
||||
void OnMouseButtonUp(const ReWindow::WindowEvents::MouseButtonUpEvent &ev) override;
|
||||
|
||||
void OnMouseMove(const ReWindow::WindowEvents::MouseMoveEvent &ev) override;
|
||||
|
||||
bool OnResizeRequest(const ReWindow::WindowEvents::WindowResizeRequestEvent &ev) override;
|
||||
protected:
|
||||
/// Draws a sequence of 'debug' information strings to the screen, in a descending list.
|
||||
void draw_debug_info(std::vector<std::string> tokens);
|
||||
void CreateMenuWindows();
|
||||
/// Constructs the Splash screen, Main Menu screen, and In-game session.
|
||||
void CreateContexts();
|
||||
void Gameloop();
|
||||
void Step();
|
||||
|
||||
bool wanna_die = false; // This field indicates the program is ready to close.
|
||||
};
|
||||
}
|
@@ -61,48 +61,7 @@ namespace CaveGame::ClientApp
|
||||
this->ChangeScene(this->splash_ctx);
|
||||
|
||||
Gameloop();
|
||||
}
|
||||
|
||||
JUI::TextRect* CaveGameWindow::line_item(const std::string& content, int size, JUI::Widget* parent)
|
||||
{
|
||||
auto* item = new JUI::TextRect(parent);
|
||||
item->SetFont(JGL::Font("assets/Jupiteroid.ttf"));
|
||||
item->Size({0,4+size,1.f,0.f});
|
||||
item->SetTextSize(size);
|
||||
item->SetContent(content);
|
||||
item->AlignCenterHorizontally();
|
||||
item->AlignTop();
|
||||
item->BGColor({0,0,0,0});
|
||||
item->SetTextColor(Colors::White);
|
||||
return item;
|
||||
}
|
||||
|
||||
void CaveGameWindow::create_credits_window()
|
||||
{
|
||||
using namespace JUI;
|
||||
credits_window = new JUI::Window(wm);
|
||||
credits_window->SetTitleFont(JGL::Font("assets/Jupiteroid.ttf"));
|
||||
credits_window->SetTitle("Credits");
|
||||
credits_window->Size({400, 400, 0, 0});
|
||||
credits_window->Visible(false);
|
||||
|
||||
auto* listing = new JUI::VerticalListLayout(credits_window->GetViewportInstance());
|
||||
listing->MarginBottom(4_px);
|
||||
|
||||
line_item("CaveGame", 40, listing);
|
||||
line_item("A Redacted Software Product", 16, listing);
|
||||
line_item("Josh O'Leary", 24, listing);
|
||||
line_item("Design, Programming & Art", 16, listing);
|
||||
line_item("William Redacted", 24, listing);
|
||||
line_item("Redacted3D Game Technologies", 16, listing);
|
||||
line_item("Ash Tray", 24, listing);
|
||||
line_item("Art & Design", 16, listing);
|
||||
line_item("Evan Walter & Logan Caughlin", 24, listing);
|
||||
line_item("Music", 16, listing);
|
||||
line_item("Maxine Hayes", 24, listing);
|
||||
line_item("Systems Administration", 16, listing);
|
||||
line_item("Karl Darling", 24, listing);
|
||||
line_item("Financial Advisor", 16, listing);
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
void CaveGameWindow::create_stats_window()
|
||||
@@ -128,18 +87,24 @@ namespace CaveGame::ClientApp
|
||||
|
||||
void CaveGameWindow::Init()
|
||||
{
|
||||
// Load OpenGL
|
||||
gladLoadGL();
|
||||
|
||||
// Init Josh Graphics
|
||||
JGL::InitTextEngine();
|
||||
JGL::Update(getSize());
|
||||
|
||||
// Fetch core assets
|
||||
// TODO: Asset manager? Need to share references and pointers of assets between many files..
|
||||
Jupiteroid = JGL::Font("assets/Jupiteroid.ttf");
|
||||
|
||||
// Setup base OpenGL state
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
glDepthMask(GL_TRUE);
|
||||
|
||||
// Construct menu elements
|
||||
create_window_widgets();
|
||||
}
|
||||
|
||||
@@ -165,7 +130,7 @@ namespace CaveGame::ClientApp
|
||||
JGL::J2D::End();
|
||||
}
|
||||
|
||||
void CaveGameWindow::update(float elapsed)
|
||||
void CaveGameWindow::Update(float elapsed)
|
||||
{
|
||||
|
||||
// TODO: We can't tell the game to change scenes from within a scene, currently.
|
||||
@@ -201,7 +166,7 @@ namespace CaveGame::ClientApp
|
||||
|
||||
}
|
||||
|
||||
void CaveGameWindow::display()
|
||||
void CaveGameWindow::Draw()
|
||||
{
|
||||
JGL::Update(getSize());
|
||||
|
||||
@@ -231,8 +196,8 @@ namespace CaveGame::ClientApp
|
||||
void CaveGameWindow::OnRefresh(float elapsed)
|
||||
{
|
||||
|
||||
update(elapsed);
|
||||
display();
|
||||
Update(elapsed);
|
||||
Draw();
|
||||
int glError = glGetError();
|
||||
if (glError != GL_NO_ERROR)
|
||||
std::cout << glError << std::endl;
|
||||
@@ -304,6 +269,16 @@ namespace CaveGame::ClientApp
|
||||
}
|
||||
|
||||
void CaveGameWindow::Die() { wanna_die = true; }
|
||||
|
||||
bool CaveGameWindow::InGameSession() const {
|
||||
return (current_scene == game_ctx);
|
||||
}
|
||||
|
||||
bool CaveGameWindow::InMainMenu() const {
|
||||
return (current_scene == menu_ctx);
|
||||
}
|
||||
|
||||
void CaveGameWindow::Cleanup() {}
|
||||
}
|
||||
|
||||
|
||||
|
17
Core/include/Core/Data.hpp
Normal file
17
Core/include/Core/Data.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
enum TileIDs
|
||||
{
|
||||
AIR = 0,
|
||||
STONE,
|
||||
DIRT,
|
||||
GRASS,
|
||||
MUD,
|
||||
CLAY,
|
||||
SAND,
|
||||
|
||||
|
||||
};
|
||||
}
|
@@ -4,6 +4,7 @@
|
||||
#include <Core/Chunk.hpp>
|
||||
#include <Core/Simplex.hpp>
|
||||
#include <Core/Perlin.hpp>
|
||||
#include "Data.hpp"
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
@@ -11,6 +12,7 @@ namespace CaveGame::Core
|
||||
{
|
||||
public:
|
||||
static constexpr float BaseSurfaceLvl = 100.f;
|
||||
static constexpr float HeightMapAmplitude = 200.f;
|
||||
public:
|
||||
Generator(uint seed) : perlin(seed)
|
||||
{
|
||||
@@ -18,45 +20,37 @@ namespace CaveGame::Core
|
||||
simplex = SimplexNoise();
|
||||
}
|
||||
|
||||
uint ComputeTile(int wx, int wy)
|
||||
{
|
||||
|
||||
uint HeightMap(int wx, int wy) {
|
||||
int tile_id = 0;
|
||||
float height_map_sx = 512.f;
|
||||
float height_map_sy = 32.f;
|
||||
float amplitude = 200.f;
|
||||
float amplitude = HeightMapAmplitude;
|
||||
float height_map_low_pass = perlin.Noise(wx / height_map_sx, 0.f, 0.25f)*amplitude;
|
||||
float height_map_high_pass = perlin.Noise(wx / height_map_sy, 0.f, 0.5f)*10.f;
|
||||
|
||||
float height_map = height_map_low_pass + height_map_high_pass;
|
||||
|
||||
float depth = wy - (BaseSurfaceLvl+height_map);
|
||||
|
||||
if (depth < 0)
|
||||
{
|
||||
return 0; // air;
|
||||
} else if (depth < 2.5f)
|
||||
{
|
||||
return 3;
|
||||
} else if (depth < 10.f)
|
||||
{
|
||||
return 2;
|
||||
} else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (depth < 0) { return Core::AIR; }
|
||||
else if (depth < 2.5f) { return Core::GRASS; }
|
||||
else if (depth < 10.f) { return Core::DIRT; }
|
||||
else { return Core::STONE; }
|
||||
}
|
||||
uint ComputeTile(int wx, int wy){
|
||||
uint base = HeightMap(wx, wy);
|
||||
float cave_high_sx = 48.f;
|
||||
float cave_high_sy = 48.f;
|
||||
float cave_low_sx = 192.f;
|
||||
float cave_low_sy = 192.f;
|
||||
float cave_high_pass = perlin.Noise(wx / cave_high_sx, wy / cave_high_sy, 1.f);
|
||||
float cave_low_pass = perlin.Noise(wx / cave_low_sx, wy / cave_low_sy, 0.5f);
|
||||
|
||||
//if (wy < BaseSurfaceLvl+height_map)
|
||||
//{
|
||||
// return 0;
|
||||
// }
|
||||
float cave_sum = cave_high_pass + cave_low_pass;
|
||||
float cave_product = cave_high_pass * cave_low_pass;
|
||||
|
||||
float sx = 10.f, sy = 10.f;
|
||||
float scale = 5;
|
||||
float z = 0.1f;
|
||||
auto raw_noise = perlin.Noise(wx / sx, wy / sy, z) + 0.5f;
|
||||
tile_id = (int)(raw_noise*scale);
|
||||
return tile_id;
|
||||
if (cave_sum > -0.05f && 0.2f > cave_sum && cave_product > -0.15f && 0.15f > cave_product)//(cave_low_pass > 0.1f && cave > 0.1f)
|
||||
{
|
||||
return Core::AIR;
|
||||
} else { return base; }
|
||||
}
|
||||
|
||||
void FirstPass(Chunk& chunk) {
|
||||
|
@@ -1,7 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Perlin.hpp"
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
template <int Octaves>
|
||||
class OctaveNoise
|
||||
{
|
||||
public:
|
||||
PerlinNoise perlin;
|
||||
double Noise(double x, double y, double z)
|
||||
{
|
||||
double scale = 1.f;
|
||||
double value = 0.f;
|
||||
|
||||
for (int i = 0; i < Octaves; i++)
|
||||
{
|
||||
double scaledX = x * scale;
|
||||
double scaledY = y * scale;
|
||||
double scaledZ = z * scale;
|
||||
|
||||
value += perlin.Noise(scaledX, scaledY, scaledZ) * scale;
|
||||
scale /= 2;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
protected:
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
class OctavePerlin
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class OctaveSimplex
|
||||
{
|
||||
|
||||
};
|
||||
}
|
@@ -40,34 +40,8 @@ namespace CaveGame::Core
|
||||
private:
|
||||
};
|
||||
|
||||
class Air : public Tile
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] uint ID() const override { return 0; }
|
||||
bool IsNonCollide() const { return true; }
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
class Stone : public Tile
|
||||
{
|
||||
public:
|
||||
uint ID() const override { return 1; } // TODO: Make ID automatically determined via advanced mechanism.
|
||||
/*void Draw(const Vector2& pos) override
|
||||
{
|
||||
JGL::J2D::FillRect(Colors::Gray, pos, {1,1});
|
||||
}*/
|
||||
};
|
||||
|
||||
class Dirt : public Tile
|
||||
{
|
||||
public:
|
||||
uint ID() const override { return 2; } // TODO: Make ID automatically determined via advanced mechanism.
|
||||
/*void Draw(const Vector2& pos) override
|
||||
{
|
||||
JGL::J2D::FillRect(Colors::Browns::Brown, pos, {1,1});
|
||||
}*/
|
||||
};
|
||||
|
||||
}
|
19
README.md
Normal file
19
README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# CaveGame 3.0
|
||||
|
||||
A Redacted Software Product
|
||||
|
||||
## Origin Story
|
||||
|
||||
## Why and How
|
||||
|
||||
## Build and Run
|
||||
|
||||
## Playtest
|
||||
|
||||
## Report Bugs
|
||||
|
||||
## Contribute
|
||||
|
||||
## Links
|
||||
|
||||
[Deliverables Document](https://docs.google.com/document/d/1NOBVnOn0qj7jRkKcbIiOsLyfdb8t2HCu42jeTBNYFr4/edit?tab=t.0)
|
75
dawsh.html
75
dawsh.html
@@ -1,75 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>CodePen - I love you more than words will ever be able explain 💕❤️💕😘 </title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
|
||||
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/styles/atom-one-dark.min.css'><link rel="stylesheet" href="./style.css">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<!-- partial:index.partial.html -->
|
||||
<div class="content">
|
||||
<div id="background"></div>
|
||||
<div class="card-wrapper">
|
||||
<div class="card card-main">
|
||||
<div class="side side-a">
|
||||
<div class="back">
|
||||
<div class="heart">
|
||||
<div class="heart-half">
|
||||
<div class="circle"></div>
|
||||
<div class="rect"></div>
|
||||
</div>
|
||||
<pre class="ijustcode"><code class="language-javascript"> console.log(
|
||||
'I love you more than words will ever be able explain💕❤️💕😘'
|
||||
);</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="front">
|
||||
<div class="heart">
|
||||
<div class="heart-half">
|
||||
<div class="circle"></div>
|
||||
<div class="rect"></div>
|
||||
</div>
|
||||
<pre class="ijustcode"><code class="language-javascript"> console.log(
|
||||
'I love you more than words will ever be able explain 💕❤️💕😘'
|
||||
);</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="side side-b">
|
||||
<div class="back">
|
||||
<div class="heart">
|
||||
<div class="heart-half">
|
||||
<div class="circle"></div>
|
||||
<div class="rect"></div>
|
||||
</div>
|
||||
<pre class="ijustcode"><code class="language-javascript"> console.log(
|
||||
'I love you more than words will ever be able explain 💕❤️💕😘'
|
||||
);</code></pre>
|
||||
<div class="title">Click me</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="front">
|
||||
<div class="heart">
|
||||
<div class="heart-half">
|
||||
<div class="circle"></div>
|
||||
<div class="rect"></div>
|
||||
</div>
|
||||
<pre class="ijustcode"><code class="language-javascript"> console.log(
|
||||
'I love you more than words will ever be able explain 💕❤️💕😘 '
|
||||
);</code></pre>
|
||||
<div class="title">Click me</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<audio controls="controls" src="https://toptrack-assets.s3.eu-central-1.amazonaws.com/i-just-called-comp.mp3">Your browser does not support the <audio> element</audio>
|
||||
</div>
|
||||
<!-- partial -->
|
||||
<script src='https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/highlight.min.js'></script>
|
||||
<script src='https://cdnjs.cloudflare.com/ajax/libs/granim/2.0.0/granim.min.js'></script><script src="./script.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user