set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_PREFIX}/lib64;${CMAKE_INSTALL_PREFIX}/swan/libswan;${CMAKE_INSTALL_PREFIX}/swan/libcygnet;${CMAKE_INSTALL_PREFIX}/swan/third-party") | set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_PREFIX}/lib64;${CMAKE_INSTALL_PREFIX}/swan/libswan;${CMAKE_INSTALL_PREFIX}/swan/libcygnet;${CMAKE_INSTALL_PREFIX}/swan/third-party") | ||||
add_library(swan-common INTERFACE) | |||||
target_include_directories(swan-common | |||||
INTERFACE "include") | |||||
add_subdirectory(third-party) | add_subdirectory(third-party) | ||||
add_subdirectory(tracy-tools) | add_subdirectory(tracy-tools) | ||||
add_subdirectory(libswan) | add_subdirectory(libswan) |
#include <cmath> | #include <cmath> | ||||
#include <msgpack.hpp> | #include <msgpack.hpp> | ||||
namespace Swan { | |||||
namespace SwanCommon { | |||||
template<typename T> | template<typename T> | ||||
struct Vector2 { | struct Vector2 { |
#pragma once | |||||
namespace SwanCommon { | |||||
static constexpr int TILE_SIZE = 32; | |||||
static constexpr int TICK_RATE = 20; | |||||
static constexpr int CHUNK_HEIGHT = 64; | |||||
static constexpr int CHUNK_WIDTH = 64; | |||||
static constexpr int PLACEHOLDER_RED = 245; | |||||
static constexpr int PLACEHOLDER_GREEN = 66; | |||||
static constexpr int PLACEHOLDER_BLUE = 242; | |||||
} |
src/Program.cc | src/Program.cc | ||||
src/Renderer.cc | src/Renderer.cc | ||||
src/shaders.cc | src/shaders.cc | ||||
src/TileAtlas.cc | |||||
src/Window.cc) | src/Window.cc) | ||||
target_include_directories(libcygnet | target_include_directories(libcygnet | ||||
PUBLIC "include" | PUBLIC "include" | ||||
PRIVATE "include/cygnet") | PRIVATE "include/cygnet") | ||||
set_target_properties(libcygnet PROPERTIES OUTPUT_NAME cygnet) | set_target_properties(libcygnet PROPERTIES OUTPUT_NAME cygnet) | ||||
target_link_libraries(libcygnet GLESv2 ${libraries}) | |||||
target_link_libraries(libcygnet swan-common GLESv2 ${libraries}) | |||||
install(TARGETS libcygnet DESTINATION swan/libcygnet) | install(TARGETS libcygnet DESTINATION swan/libcygnet) |
#pragma once | |||||
#include <memory> | |||||
namespace Cygnet { | |||||
struct AtlasState; | |||||
class TileAtlas { | |||||
public: | |||||
TileAtlas(); | |||||
~TileAtlas(); | |||||
void addTile(size_t tileId, const void *data, size_t len); | |||||
private: | |||||
std::unique_ptr<AtlasState> state_; | |||||
}; | |||||
} |
#include "shaders.h" | #include "shaders.h" | ||||
#include "Program.h" | #include "Program.h" | ||||
#include "TileAtlas.h" | |||||
#include "util.h" | #include "util.h" | ||||
namespace Cygnet { | namespace Cygnet { | ||||
TexturedProg texturedProg{texturedVx, texturedFr}; | TexturedProg texturedProg{texturedVx, texturedFr}; | ||||
SolidColorProg solidColorProg{basicVx, solidColorFr}; | SolidColorProg solidColorProg{basicVx, solidColorFr}; | ||||
TileAtlas atlas; | |||||
}; | }; | ||||
Renderer::Renderer(): state_(std::make_unique<RendererState>()) {} | Renderer::Renderer(): state_(std::make_unique<RendererState>()) {} |
#include "TileAtlas.h" | |||||
#include <iostream> | |||||
#include <vector> | |||||
#include <SDL_opengles2.h> | |||||
#include <stdio.h> | |||||
#include <string.h> | |||||
#include <swan-common/constants.h> | |||||
namespace Cygnet { | |||||
struct AtlasState { | |||||
size_t tilesPerLine; | |||||
size_t width = 0; | |||||
size_t height = 0; | |||||
std::vector<unsigned char> data; | |||||
}; | |||||
TileAtlas::TileAtlas(): state_(std::make_unique<AtlasState>()) { | |||||
GLint size; | |||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size); | |||||
state_->tilesPerLine = size / SwanCommon::TILE_SIZE; | |||||
} | |||||
TileAtlas::~TileAtlas() = default; | |||||
void TileAtlas::addTile(size_t tileId, const void *data, size_t len) { | |||||
size_t rows = len / (SwanCommon::TILE_SIZE * 4); | |||||
const unsigned char *bytes = (const unsigned char *)data; | |||||
size_t x = tileId % state_->tilesPerLine; | |||||
size_t y = tileId / state_->tilesPerLine; | |||||
if (y >= state_->tilesPerLine) { | |||||
std::cerr << "Cygnet: Warning: Tile ID " << tileId << " too big for texture atlas\n"; | |||||
return; | |||||
} | |||||
if (state_->width <= x) { | |||||
state_->width = x + 1; | |||||
} | |||||
if (state_->height <= y) { | |||||
state_->height = y + 1; | |||||
} | |||||
size_t tileImgSize = SwanCommon::TILE_SIZE * SwanCommon::TILE_SIZE * 4; | |||||
size_t requiredSize = (x + 1) * (y + 1) * tileImgSize; | |||||
state_->data.resize(requiredSize); | |||||
for (size_t ty = 0; ty < rows; ++ty) { | |||||
unsigned char *dest = state_->data.data() + | |||||
((y + ty) * state_->width * SwanCommon::TILE_SIZE * 4) + | |||||
(x * SwanCommon::TILE_SIZE * 4); | |||||
const unsigned char *src = bytes + ty * SwanCommon::TILE_SIZE * 4; | |||||
memcpy(dest, src, SwanCommon::TILE_SIZE * 4); | |||||
} | |||||
} | |||||
} |
PUBLIC "include" | PUBLIC "include" | ||||
PRIVATE "include/swan") | PRIVATE "include/swan") | ||||
set_target_properties(libswan PROPERTIES OUTPUT_NAME swan) | set_target_properties(libswan PROPERTIES OUTPUT_NAME swan) | ||||
target_link_libraries(libswan ${libraries}) | |||||
target_link_libraries(libswan swan-common ${libraries}) | |||||
install(TARGETS libswan DESTINATION swan/libswan) | install(TARGETS libswan DESTINATION swan/libswan) | ||||
#include "Entity.h" | #include "Entity.h" | ||||
#include "Collection.h" | #include "Collection.h" | ||||
#include "traits/BodyTrait.h" | #include "traits/BodyTrait.h" | ||||
#include "Vector2.h" | |||||
namespace Swan { | namespace Swan { | ||||
// We want every file to be able to easily add Tracy zones | // We want every file to be able to easily add Tracy zones | ||||
#include <tracy/Tracy.hpp> | #include <tracy/Tracy.hpp> | ||||
#include "Vector2.h" | |||||
#include <swan-common/Vector2.h> | |||||
#include <swan-common/constants.h> | |||||
namespace Swan { | namespace Swan { | ||||
static constexpr int TILE_SIZE = 32; | |||||
static constexpr int TICK_RATE = 20; | |||||
static constexpr int CHUNK_HEIGHT = 64; | |||||
static constexpr int CHUNK_WIDTH = 64; | |||||
static constexpr int PLACEHOLDER_RED = 245; | |||||
static constexpr int PLACEHOLDER_GREEN = 66; | |||||
static constexpr int PLACEHOLDER_BLUE = 242; | |||||
using namespace SwanCommon; | |||||
using TilePos = Vec2i; | using TilePos = Vec2i; | ||||
using ChunkPos = Vec2i; | using ChunkPos = Vec2i; |
#include <swan/Resource.h> | #include <swan/Resource.h> | ||||
#include <swan/SlotVector.h> | #include <swan/SlotVector.h> | ||||
#include <swan/Tile.h> | #include <swan/Tile.h> | ||||
#include <swan/Vector2.h> | |||||
#include <swan/Win.h> | #include <swan/Win.h> | ||||
#include <swan/World.h> | #include <swan/World.h> | ||||
#include <swan/WorldGen.h> | #include <swan/WorldGen.h> |
#pragma once | #pragma once | ||||
#include "../Vector2.h" | |||||
#include "../common.h" | |||||
namespace Swan { | namespace Swan { | ||||
#include <vector> | #include <vector> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include "../Vector2.h" | |||||
#include "../common.h" | |||||
#include "../ItemStack.h" | #include "../ItemStack.h" | ||||
namespace Swan { | namespace Swan { |
#pragma once | #pragma once | ||||
#include "../traits/BodyTrait.h" | #include "../traits/BodyTrait.h" | ||||
#include "../Vector2.h" | |||||
#include "../common.h" | #include "../common.h" | ||||
namespace Swan { | namespace Swan { |