Scrollwheel changes tile tool radius. CXX Flags optimization
This commit is contained in:
@@ -14,8 +14,11 @@ endif()
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
# Set for profiling
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -march=native -ffast-math -ftree-parallelize-loops=6 -funroll-loops -mfma -flto=auto -finline-functions -fprefetch-loop-arrays -floop-nest-optimize")
|
||||
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
|
@@ -5,22 +5,25 @@
|
||||
|
||||
namespace CaveGame::Core {
|
||||
void Explosion::Draw() {
|
||||
|
||||
if (HasDetonated()) {
|
||||
if (anim_timer < 1.25f) {
|
||||
//JGL::J2D::Begin();
|
||||
|
||||
float draw_radius = radius * 1.25f;
|
||||
|
||||
auto* tex = Client::AssetService::Get()->explosion_sprite;
|
||||
|
||||
if (anim_timer > (4.f / 5.f)) {
|
||||
JGL::J2D::DrawPartialSprite(tex, position-Vector2(16, 16), SP_EXPLOSION4.minPoint, SP_EXPLOSION4.maxPoint, rotation, {0,0});
|
||||
JGL::J2D::DrawPartialSprite(tex, position-(Vector2(draw_radius)), SP_EXPLOSION4.minPoint, SP_EXPLOSION4.maxPoint, rotation, {0.5f,0.5f}, {draw_radius/16.f, draw_radius/16.f});
|
||||
} else if (anim_timer > (3.f / 5.f)) {
|
||||
JGL::J2D::DrawPartialSprite(tex, position-Vector2(16, 16), SP_EXPLOSION3.minPoint, SP_EXPLOSION3.maxPoint, rotation, {16, 16});
|
||||
JGL::J2D::DrawPartialSprite(tex, position-(Vector2(draw_radius)), SP_EXPLOSION3.minPoint, SP_EXPLOSION3.maxPoint, rotation, {0.5f, 0.5f}, {draw_radius/16.f, draw_radius/16.f});
|
||||
} else if (anim_timer > (2.f / 5.f)) {
|
||||
JGL::J2D::DrawPartialSprite(tex, position-Vector2(16, 16), SP_EXPLOSION2.minPoint, SP_EXPLOSION2.maxPoint, rotation, {16, 16});
|
||||
JGL::J2D::DrawPartialSprite(tex, position-(Vector2(draw_radius)), SP_EXPLOSION2.minPoint, SP_EXPLOSION2.maxPoint, rotation, {0.5f, 0.5f}, {draw_radius/16.f, draw_radius/16.f});
|
||||
} else if (anim_timer > (1.f / 5.f)) {
|
||||
JGL::J2D::DrawPartialSprite(tex, position-Vector2(16, 16), SP_EXPLOSION1.minPoint, SP_EXPLOSION1.maxPoint, rotation, {16, 16});
|
||||
JGL::J2D::DrawPartialSprite(tex, position-(Vector2(draw_radius)), SP_EXPLOSION1.minPoint, SP_EXPLOSION1.maxPoint, rotation, {0.5f, 0.5f}, {draw_radius/16.f, draw_radius/16.f});
|
||||
} else {
|
||||
JGL::J2D::DrawPartialSprite(tex, position-Vector2(16, 16), SP_EXPLOSION0.minPoint, SP_EXPLOSION0.maxPoint, rotation, {16, 16});
|
||||
JGL::J2D::DrawPartialSprite(tex, position-(Vector2(draw_radius)), SP_EXPLOSION0.minPoint, SP_EXPLOSION0.maxPoint, rotation, {0.5f, 0.5f}, {draw_radius/16.f, draw_radius/16.f});
|
||||
}
|
||||
|
||||
//JGL::J2D::End();
|
||||
|
@@ -179,10 +179,6 @@ namespace CaveGame::Client {
|
||||
//DrawChunkGrid();
|
||||
|
||||
|
||||
Vector2 transformed = camera.ScreenToWorld(mouse_pos);
|
||||
|
||||
JGL::J2D::OutlineCircle(Colors::Red, transformed, 5);
|
||||
|
||||
|
||||
// Banana for scale.
|
||||
JGL::J2D::FillRect(Colors::Blue, {0,0}, {64, 64});
|
||||
@@ -243,6 +239,8 @@ namespace CaveGame::Client {
|
||||
|
||||
Vector2 relative_tile_coords = Vector2(x, y);
|
||||
const Vector2& tile_coords = relative_tile_coords;
|
||||
int wx = (x*Core::Chunk::ChunkSize) + x;
|
||||
int wy = (y*Core::Chunk::ChunkSize) + y;
|
||||
|
||||
|
||||
#ifdef DEBUG_TILE_UPDATES
|
||||
@@ -257,9 +255,24 @@ namespace CaveGame::Client {
|
||||
if (t_id == TileID::AIR || t_id == TileID::VOID) // Air
|
||||
continue;
|
||||
|
||||
|
||||
|
||||
|
||||
t_data = Core::GetByNumeric(t_id);
|
||||
|
||||
if (t_data->has_color_pallet) {
|
||||
if (t_id == TileID::COBBLESTONE) {
|
||||
float val = generator.Perlin(wx, wy, 12, 12, 12, 2);
|
||||
|
||||
if (val > 0.60f || val < -0.60f)
|
||||
t_color = Core::Tiles::Cobblestone.color_pallet[1];
|
||||
else if (val > 0.40f || val < -0.40f)
|
||||
t_color = Core::Tiles::Cobblestone.color_pallet[0];
|
||||
else if (val > 0.2f || val < -0.2f)
|
||||
t_color = Core::Tiles::Cobblestone.color_pallet[2];
|
||||
else
|
||||
t_color = Core::Tiles::Cobblestone.color_pallet[3];
|
||||
//Core::Tiles::Cobblestone.color_pallet
|
||||
} else if (t_data->has_color_pallet) {
|
||||
uint rand = generator.ColorMap(t_data->color_pallet.size(), x, y);
|
||||
t_color = t_data->color_pallet[rand];
|
||||
} else {
|
||||
|
@@ -102,5 +102,9 @@ namespace CaveGame::ClientApp
|
||||
|
||||
bool wanna_die = false; // This field indicates the program is ready to close.
|
||||
void InGameControls(float elapsed);
|
||||
|
||||
float tool_radius = 8.f;
|
||||
|
||||
void OnMouseWheel(const ReWindow::MouseWheelEvent &) override;
|
||||
};
|
||||
}
|
@@ -140,11 +140,14 @@ namespace CaveGame::ClientApp
|
||||
|
||||
void CaveGameWindow::tile_draw(int x, int y, int radius, Core::TileID tile)
|
||||
{
|
||||
|
||||
game_ctx->world->SetTile(x, y, tile);
|
||||
|
||||
for (int dx = -radius; dx <= radius; ++dx)
|
||||
{
|
||||
for (int dy = -radius; dy <= radius; ++dy)
|
||||
{
|
||||
if (Math::Abs(dx)+Math::Abs(dy) < radius*1.5f)
|
||||
if (Math::Abs(dx)+Math::Abs(dy) < radius)
|
||||
game_ctx->world->SetTile(x+dx, y+dy, tile);
|
||||
}
|
||||
}
|
||||
@@ -202,16 +205,16 @@ namespace CaveGame::ClientApp
|
||||
if (IsMouseButtonDown(MouseButtons::Left))
|
||||
{
|
||||
|
||||
Vector2 transformed = game_ctx->world->camera.ScreenToWorld(GetMouseCoordinates());
|
||||
tile_draw(transformed.x, transformed.y, 4, Core::TileID::AIR);
|
||||
Vector2 transformed = game_ctx->world->camera.ScreenToWorld(GetMouseCoordinates()) - Vector2{0.5f, 0.5f};
|
||||
tile_draw(transformed.x, transformed.y, tool_radius, Core::TileID::AIR);
|
||||
}
|
||||
|
||||
if (IsMouseButtonDown(MouseButtons::Right))
|
||||
{
|
||||
|
||||
Vector2 transformed = game_ctx->world->camera.ScreenToWorld(GetMouseCoordinates());
|
||||
Vector2 transformed = game_ctx->world->camera.ScreenToWorld(GetMouseCoordinates()) - Vector2{0.5f, 0.5f};
|
||||
|
||||
tile_draw(transformed.x, transformed.y, 2, game_ctx->GetHotbarTile());
|
||||
tile_draw(transformed.x, transformed.y, tool_radius, game_ctx->GetHotbarTile());
|
||||
|
||||
/*game_ctx->world->SetTile(transformed.x, transformed.y, Core::TileID::GRASS);
|
||||
game_ctx->world->SetTile(transformed.x+1, transformed.y, Core::TileID::GRASS);
|
||||
@@ -287,6 +290,32 @@ namespace CaveGame::ClientApp
|
||||
}
|
||||
|
||||
draw_debug_info(debug_lines);
|
||||
|
||||
if (current_scene == game_ctx) {
|
||||
|
||||
JGL::J2D::Begin();
|
||||
|
||||
auto camera = game_ctx->world->camera;
|
||||
|
||||
// Shift the origin to the center of the screen.
|
||||
glTranslatef(camera.HalfSizeOffset().x, camera.HalfSizeOffset().y, 0);
|
||||
|
||||
//DrawSky();
|
||||
|
||||
// Apply rotation, zoom, and translation.
|
||||
glRotatef(camera.Rotation(), 0, 0, 1);
|
||||
glScalef(camera.Zoom(), camera.Zoom(), 1);
|
||||
|
||||
glTranslatef(-camera.Position().x, -camera.Position().y, 0);
|
||||
|
||||
auto pos = camera.ScreenToWorld(currentMouse.Position);
|
||||
|
||||
JGL::J2D::OutlineCircle(Colors::Red, pos, tool_radius);
|
||||
|
||||
JGL::J2D::DrawPoint({128, 128, 128, 128}, pos);
|
||||
|
||||
JGL::J2D::End();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -348,7 +377,7 @@ namespace CaveGame::ClientApp
|
||||
|
||||
if (ev.key == Keys::P) {
|
||||
auto coords = game_ctx->world->camera.ScreenToWorld(InputService::GetMousePosition());
|
||||
auto* plr = new Core::Explosion(game_ctx->world, coords, 1.f, 8.f);
|
||||
auto* plr = new Core::Explosion(game_ctx->world, coords, 1.f, tool_radius);
|
||||
//auto* plr2 = new Core::Player(coords);
|
||||
//game_ctx->world->AddEntity(plr2);
|
||||
game_ctx->world->AddEntity(plr);
|
||||
@@ -421,6 +450,13 @@ namespace CaveGame::ClientApp
|
||||
return true;
|
||||
}
|
||||
|
||||
void CaveGameWindow::OnMouseWheel(const ReWindow::MouseWheelEvent &ev) {
|
||||
tool_radius -= ev.WheelMovement/2.f;
|
||||
|
||||
|
||||
tool_radius = Math::Max(tool_radius, 0.45f);
|
||||
}
|
||||
|
||||
void CaveGameWindow::Die() { wanna_die = true; }
|
||||
|
||||
bool CaveGameWindow::InGameSession() const {
|
||||
|
@@ -5,6 +5,8 @@ namespace CaveGame::Core {
|
||||
|
||||
void Explosion::Update(float elapsed) {
|
||||
|
||||
|
||||
|
||||
//Entity::Update(elapsed);
|
||||
|
||||
if (fuse > 0.f)
|
||||
|
Reference in New Issue
Block a user