Parcourir la source

more cygnet stuff

fix/style
Martin Dørum il y a 3 ans
Parent
révision
7edfaed271

+ 4
- 0
CMakeLists.txt Voir le fichier



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)

libswan/include/swan/Vector2.h → include/swan-common/Vector2.h Voir le fichier

#include <cmath> #include <cmath>
#include <msgpack.hpp> #include <msgpack.hpp>


namespace Swan {
namespace SwanCommon {


template<typename T> template<typename T>
struct Vector2 { struct Vector2 {

+ 13
- 0
include/swan-common/constants.h Voir le fichier

#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;

}

+ 2
- 1
libcygnet/CMakeLists.txt Voir le fichier

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)

+ 20
- 0
libcygnet/include/cygnet/TileAtlas.h Voir le fichier

#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_;
};

}

+ 3
- 0
libcygnet/src/Renderer.cc Voir le fichier



#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>()) {}

+ 59
- 0
libcygnet/src/TileAtlas.cc Voir le fichier

#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);
}
}

}

+ 1
- 1
libswan/CMakeLists.txt Voir le fichier

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)



+ 0
- 1
libswan/include/swan/WorldGen.h Voir le fichier

#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 {



+ 3
- 8
libswan/include/swan/common.h Voir le fichier

// 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;

+ 0
- 1
libswan/include/swan/swan.h Voir le fichier

#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>

+ 1
- 1
libswan/include/swan/traits/BodyTrait.h Voir le fichier

#pragma once #pragma once


#include "../Vector2.h"
#include "../common.h"


namespace Swan { namespace Swan {



+ 1
- 1
libswan/include/swan/traits/InventoryTrait.h Voir le fichier

#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 {

+ 0
- 1
libswan/include/swan/traits/PhysicsTrait.h Voir le fichier

#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 {

Chargement…
Annuler
Enregistrer