Wow! I can't believe I haven't started this project again!
This commit is contained in:
@ -3,75 +3,30 @@
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Custom variables
|
||||
set(
|
||||
DAWN_TARGET_DEPENDENCIES_LAST
|
||||
CACHE INTERNAL ${DAWN_CACHE_TARGET}
|
||||
)
|
||||
|
||||
# Build Project
|
||||
add_executable(${DAWN_TARGET_NAME})
|
||||
|
||||
# Change what we are building. Pulled from the cmake/targets dir.
|
||||
if(DEFINED DAWN_BUILDING)
|
||||
add_subdirectory(${DAWN_BUILDING})
|
||||
# Validate game project includes the target name
|
||||
if(NOT DEFINED DAWN_TARGET_NAME)
|
||||
message(FATAL_ERROR "You need to define a target name")
|
||||
endif()
|
||||
|
||||
# Validate game project includes the target name
|
||||
if(DEFINED DAWN_TARGET_NAME)
|
||||
# Add in base library
|
||||
add_subdirectory(dawn)
|
||||
# Add in base library
|
||||
add_subdirectory(dawn)
|
||||
add_subdirectory(dawnrpg)
|
||||
|
||||
# Compile entry targets
|
||||
if(DAWN_TARGET_WIN32)
|
||||
add_subdirectory(dawnwin32)
|
||||
elseif(DAWN_TARGET_LINUX)
|
||||
add_subdirectory(dawnlinux)
|
||||
elseif(DAWN_TARGET_OSX)
|
||||
add_subdirectory(dawnosx)
|
||||
elseif(DAWN_TARGET_VITA)
|
||||
add_subdirectory(dawnvita)
|
||||
elseif(DAWN_TARGET_EMSCRIPTEN)
|
||||
add_subdirectory(dawnemscripten)
|
||||
else()
|
||||
message(FATAL_ERROR "You need to define an entry target")
|
||||
endif()
|
||||
# Host Libraries
|
||||
target_link_libraries(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${DAWN_BUILD_HOST_LIBS}
|
||||
)
|
||||
|
||||
# Host Libraries
|
||||
target_link_libraries(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${DAWN_BUILD_HOST_LIBS}
|
||||
)
|
||||
# Compile support targets
|
||||
if(DAWN_TARGET_LINUX)
|
||||
add_subdirectory(dawnglfw)
|
||||
add_subdirectory(dawnopengl)
|
||||
add_subdirectory(dawnlinux)
|
||||
endif()
|
||||
|
||||
# Compile support targets
|
||||
if(DAWN_TARGET_GLFW)
|
||||
add_subdirectory(dawnglfw)
|
||||
add_subdirectory(dawnopengl)
|
||||
endif()
|
||||
|
||||
if(DAWN_TARGET_TRUETYPE)
|
||||
add_subdirectory(dawntruetype)
|
||||
endif()
|
||||
|
||||
if(DAWN_TARGET_SDL2)
|
||||
add_subdirectory(dawnsdl2)
|
||||
add_subdirectory(dawnopengl)
|
||||
endif()
|
||||
|
||||
if(DAWN_TARGET_VITA)
|
||||
add_subdirectory(dawnopengl)
|
||||
endif()
|
||||
|
||||
if(DAWN_TARGET_OPENAL)
|
||||
add_subdirectory(dawnopenal)
|
||||
endif()
|
||||
|
||||
# Late definitions, used by tools
|
||||
if(NOT DAWN_TARGET_DEPENDENCIES_LAST)
|
||||
else()
|
||||
add_dependencies(${DAWN_TARGET_NAME} ${DAWN_TARGET_DEPENDENCIES_LAST})
|
||||
endif()
|
||||
|
||||
# Compress the game assets.
|
||||
add_dependencies(${DAWN_TARGET_NAME} dawnassets)
|
||||
endif()
|
||||
# Compress the game assets.
|
||||
add_dependencies(${DAWN_TARGET_NAME} dawnassets)
|
@ -6,8 +6,10 @@
|
||||
# Libraries
|
||||
target_link_libraries(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
glm
|
||||
archive_static
|
||||
glm::glm
|
||||
nlohmann_json::nlohmann_json
|
||||
freetype
|
||||
)
|
||||
|
||||
# Includes
|
||||
|
@ -67,6 +67,35 @@ AssetDataLoader::AssetDataLoader(std::string fileName) : fileName(fileName) {
|
||||
);
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::getSize() {
|
||||
assertTrue(this->assetArchiveEntry != nullptr, "AssetDataLoader::getSize: Entry is NULL!");
|
||||
assertTrue(archive_entry_size_is_set(assetArchiveEntry), "assetGetSize: Entry size is not set!");
|
||||
return archive_entry_size(assetArchiveEntry);
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::getPosition() {
|
||||
assertNotNull(this->assetArchiveFile, "AssetDataLoader::getPosition: File is not open!");
|
||||
return this->position;
|
||||
}
|
||||
|
||||
std::string AssetDataLoader::getEntireContentsAsString() {
|
||||
if(!this->isOpen()) {
|
||||
this->open();
|
||||
} else {
|
||||
this->rewind();
|
||||
}
|
||||
|
||||
std::string buffer;
|
||||
buffer.resize(this->getSize());
|
||||
this->read((uint8_t*)buffer.data(), buffer.size());
|
||||
this->close();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
bool_t AssetDataLoader::isOpen() {
|
||||
return this->assetArchive != nullptr;
|
||||
}
|
||||
|
||||
void AssetDataLoader::open() {
|
||||
assertNull(this->assetArchiveFile, "AssetDataLoader::open: File is already open");
|
||||
assertNull(this->assetArchive, "AssetDataLoader::open: Archive is already open");
|
||||
@ -156,12 +185,6 @@ size_t AssetDataLoader::readUntil(
|
||||
return i;
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::getSize() {
|
||||
assertTrue(this->assetArchiveEntry != nullptr, "AssetDataLoader::getSize: Entry is NULL!");
|
||||
assertTrue(archive_entry_size_is_set(assetArchiveEntry), "assetGetSize: Entry size is not set!");
|
||||
return archive_entry_size(assetArchiveEntry);
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::skip(size_t n) {
|
||||
assertTrue(n >= 0, "AssetDataLoader::skip: Byte count must be greater than 0.");
|
||||
|
||||
@ -185,16 +208,14 @@ size_t AssetDataLoader::setPosition(const size_t position) {
|
||||
}
|
||||
|
||||
void AssetDataLoader::rewind() {
|
||||
assertTrue(this->isOpen(), "Asset is not open!");
|
||||
if(this->position == 0) return;
|
||||
|
||||
// TODO: See if I can optimize this
|
||||
this->close();
|
||||
this->open();
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::getPosition() {
|
||||
assertNotNull(this->assetArchiveFile, "AssetDataLoader::getPosition: File is not open!");
|
||||
return this->position;
|
||||
}
|
||||
|
||||
AssetDataLoader::~AssetDataLoader() {
|
||||
if(this->assetArchiveFile != nullptr) this->close();
|
||||
}
|
@ -89,6 +89,33 @@ namespace Dawn {
|
||||
* @param fileName File name of the asset that is to be loaded.
|
||||
*/
|
||||
AssetDataLoader(std::string filename);
|
||||
|
||||
/**
|
||||
* Get the size of the asset.
|
||||
* @return The size of the asset in bytes.
|
||||
*/
|
||||
size_t getSize();
|
||||
|
||||
/**
|
||||
* Returns the current position of the read head.
|
||||
*
|
||||
* @return The current read head position.
|
||||
*/
|
||||
size_t getPosition();
|
||||
|
||||
/**
|
||||
* Get the entire contents of the asset as a string.
|
||||
*
|
||||
* @return The entire contents of the asset as a string.
|
||||
*/
|
||||
std::string getEntireContentsAsString();
|
||||
|
||||
/**
|
||||
* Check if the asset is open.
|
||||
*
|
||||
* @return True if the asset is open, otherwise false.
|
||||
*/
|
||||
bool_t isOpen();
|
||||
|
||||
/**
|
||||
* Platform-centric method to open a file buffer to an asset.
|
||||
@ -123,12 +150,6 @@ namespace Dawn {
|
||||
const size_t maxSize,
|
||||
const char_t delimiter
|
||||
);
|
||||
|
||||
/**
|
||||
* Get the size of the asset.
|
||||
* @return The size of the asset in bytes.
|
||||
*/
|
||||
size_t getSize();
|
||||
|
||||
/**
|
||||
* Skips the read head forward to a given position.
|
||||
@ -151,13 +172,6 @@ namespace Dawn {
|
||||
*/
|
||||
size_t setPosition(const size_t absolutePosition);
|
||||
|
||||
/**
|
||||
* Returns the current position of the read head.
|
||||
*
|
||||
* @return The current read head position.
|
||||
*/
|
||||
size_t getPosition();
|
||||
|
||||
/**
|
||||
* Cleanup the asset loader.
|
||||
*/
|
||||
|
@ -92,11 +92,24 @@ namespace Dawn {
|
||||
* @param fontSize The font size to get the truetype asset of.
|
||||
* @return The asset loader for the given asset.
|
||||
*/
|
||||
template<class T>
|
||||
std::shared_ptr<T> get(
|
||||
const std::string filename,
|
||||
const uint32_t fontSize
|
||||
);
|
||||
// std::shared_ptr<TrueTypeTexture> get(
|
||||
// const std::string filename,
|
||||
// const uint32_t fontSize
|
||||
// ) {
|
||||
// auto existing = this->getExisting<TrueTypeLoader>(filename);
|
||||
// if(existing) {
|
||||
// // Check pointer hasn't gone stale, if it has remove it and create new.
|
||||
// auto texture = existing->getTexture(fontSize);
|
||||
// if(texture) return texture;
|
||||
// this->removeExisting(filename);
|
||||
// }
|
||||
|
||||
// std::shared_ptr<TrueTypeLoader> loader = std::make_shared<TrueTypeLoader>(
|
||||
// filename
|
||||
// );
|
||||
// pendingAssetLoaders.push_back(std::static_pointer_cast<AssetLoader>(loader));
|
||||
// return loader->getTexture(fontSize);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Dispose the asset manager, and all attached assets.
|
||||
|
@ -7,4 +7,6 @@
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
TextureLoader.cpp
|
||||
JSONLoader.cpp
|
||||
TrueTypeLoader.cpp
|
||||
)
|
33
src/dawn/asset/loaders/JSONLoader.cpp
Normal file
33
src/dawn/asset/loaders/JSONLoader.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2024 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "JSONLoader.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
JSONLoader::JSONLoader(const std::string name) :
|
||||
AssetLoader(name),
|
||||
loader(name),
|
||||
state(JSONLoaderState::INITIAL)
|
||||
{
|
||||
}
|
||||
|
||||
void JSONLoader::updateAsync() {
|
||||
if(this->state != JSONLoaderState::INITIAL) return;
|
||||
|
||||
this->state = JSONLoaderState::LOADING_JSON;
|
||||
std::string jsonContents = loader.getEntireContentsAsString();
|
||||
this->data = json::parse(jsonContents);
|
||||
this->state = JSONLoaderState::DONE;
|
||||
this->loaded = true;
|
||||
}
|
||||
|
||||
void JSONLoader::updateSync() {
|
||||
}
|
||||
|
||||
JSONLoader::~JSONLoader() {
|
||||
|
||||
}
|
||||
|
33
src/dawn/asset/loaders/JSONLoader.hpp
Normal file
33
src/dawn/asset/loaders/JSONLoader.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2024 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "asset/AssetLoader.hpp"
|
||||
#include "asset/AssetDataLoader.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace Dawn {
|
||||
enum class JSONLoaderState {
|
||||
INITIAL,
|
||||
LOADING_JSON,
|
||||
DONE
|
||||
};
|
||||
|
||||
class JSONLoader : public AssetLoader {
|
||||
protected:
|
||||
AssetDataLoader loader;
|
||||
enum JSONLoaderState state;
|
||||
|
||||
public:
|
||||
json data;
|
||||
|
||||
JSONLoader(const std::string name);
|
||||
void updateSync() override;
|
||||
void updateAsync() override;
|
||||
~JSONLoader();
|
||||
};
|
||||
}
|
@ -13,4 +13,5 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(mesh)
|
||||
add_subdirectory(shader)
|
||||
add_subdirectory(shader)
|
||||
add_subdirectory(font)
|
@ -5,5 +5,6 @@
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
UILabel.cpp
|
||||
UIRectangle.cpp
|
||||
)
|
@ -1,20 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
freetype
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(asset)
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(ui)
|
@ -1,27 +0,0 @@
|
||||
// Copyright (c) 2024 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "AssetManager.hpp"
|
||||
#include "loaders/TrueTypeLoader.hpp"
|
||||
|
||||
template<>
|
||||
std::shared_ptr<TrueTypeTexture> AssetManager::get<TrueTypeTexture>(
|
||||
const std::string filename,
|
||||
const uint32_t fontSize
|
||||
) {
|
||||
auto existing = this->getExisting<TrueTypeLoader>(filename);
|
||||
if(existing) {
|
||||
// Check pointer hasn't gone stale, if it has remove it and create new.
|
||||
auto texture = existing->getTexture(fontSize);
|
||||
if(texture) return texture;
|
||||
this->removeExisting(filename);
|
||||
}
|
||||
|
||||
std::shared_ptr<TrueTypeLoader> loader = std::make_shared<TrueTypeLoader>(
|
||||
filename
|
||||
);
|
||||
pendingAssetLoaders.push_back(std::static_pointer_cast<AssetLoader>(loader));
|
||||
return loader->getTexture(fontSize);
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
# Copyright (c) 2024 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
AssetManagerTrueType.cpp
|
||||
)
|
||||
|
||||
add_subdirectory(loaders)
|
@ -1,10 +0,0 @@
|
||||
# Copyright (c) 2024 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
TrueTypeLoader.cpp
|
||||
)
|
@ -1,6 +0,0 @@
|
||||
# Copyright (c) 2024 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(font)
|
@ -1,6 +0,0 @@
|
||||
# Copyright (c) 2024 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(elements)
|
@ -1,9 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
UILabel.cpp
|
||||
)
|
Reference in New Issue
Block a user