Commit 343941a4 authored by Milan Irigoyen's avatar Milan Irigoyen
Browse files

Rework to newest mme version

parent d8b3f2bf
build/
\ No newline at end of file
#############################
# MMGPROJECTTEMPLATE-DEV
#############################
cmake_minimum_required(VERSION 3.8)
# Global properties
set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Visual studio doesn't use folders properly without this
set(CMAKE_CXX_STANDARD 17)
# Create project
SET(PROJECT_NAME "mmgprojecttemplate-dev")
Project(${PROJECT_NAME})
# Include mmgcmake
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/mmecmake")
include(helpers)
#------------ VARIABLE AND OPTIONS SETUP ---------------
# Shared libraries
set(MME_TESTS ON CACHE BOOL "Enable MME tests")
# Third parties
SET(CATCH_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/thirdparties/catch/include")
SET(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL false)
SET(YAML_CPP_BUILD_TESTS OFF CACHE BOOL false)
SET(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL false)
#------------ SUBDIRECTORIES ---------------
# Adding shared libraries
add_subdirectory(shared/mmecpp)
add_subdirectory(shared/sfmlutils)
add_subdirectory(shared/mme)
# Thirdparties
add_subdirectory(thirdparties/yamlcpp)
# Gameplay libs
add_subdirectory(code/core)
# Executable
add_subdirectory(code/client)
# Game editor
# TODO This needs wxwidgets, which sucks if we want to automate builds
# add_subdirectory(code/editor)
\ No newline at end of file
#------------------------------------------#
# MmgProjectTemplate Client
#------------------------------------------#
SET(EXE_NAME "mmgprojecttemplate_client")
# Find SFML
find_package(SFML 2.5 COMPONENTS system window graphics audio REQUIRED)
# Executable
FILE(GLOB_RECURSE GAME_SRC ${CMAKE_CURRENT_SOURCE_DIR}/sources/*.cpp)
FILE(GLOB_RECURSE GAME_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/sources/*.hpp)
FILE(GLOB_RECURSE GAME_SHADERS ${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.hpp)
add_executable(${EXE_NAME} ${GAME_SRC} ${GAME_HEADERS} ${GAME_SHADERS})
target_link_libraries(${EXE_NAME}
# Third parties
"yaml-cpp"
"sfml-system"
"sfml-window"
"sfml-graphics"
"sfml-audio"
# Shared libraries
"mme"
"mmecpp"
"sfmlutils"
# Game libraries
"core"
)
target_compile_definitions(${EXE_NAME} PRIVATE MMECPP_USE_SFML)
set_target_properties(${EXE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
set_target_properties(${EXE_NAME} PROPERTIES FOLDER MmgProjectTemplate)
# Resource management
setupResources(${EXE_NAME} ${CMAKE_SOURCE_DIR}/resources resources)
if (MSVC)
setupVisualStudioWorkingDirectory(${EXE_NAME})
endif()
\ No newline at end of file
#include "global.hpp"
#include <mme/core/inputmanager.hpp>
#include <mme/core/statemanager.hpp>
namespace ad
{
namespace client
{
const std::string cStateMenu = "StateMenu";
const std::string cStateGame = "StateGame";
const std::string cButtonStateMenu = "DebugButtonStateMenu";
const std::string cButtonStateGame = "DebugButtonStateGame";
const std::string cButtonLMB = "ButtonLMB";
const std::string cButtonRMB = "ButtonRMB";
bool checkStateChange()
{
if (mme::core::InputManager::instance().getButton(cButtonStateMenu, 0).justPressed)
{
mme::core::StateManager::instance().setState(cStateMenu);
return true;
}
else if (mme::core::InputManager::instance().getButton(cButtonStateGame, 0).justPressed)
{
mme::core::StateManager::instance().setState(cStateGame);
return true;
}
return false;
}
}
}
\ No newline at end of file
#pragma once
#include <string>
namespace mmgtmpl
{
namespace client
{
extern const std::string cStateMenu;
extern const std::string cStateStartup;
extern const std::string cStateGame;
extern const std::string cButtonStateMenu;
extern const std::string cButtonStateGame;
// UI stuff
extern const std::string cButtonLMB;
extern const std::string cButtonRMB;
bool checkStateChange();
}
}
\ No newline at end of file
#include "global.hpp"
#include "stategame.hpp"
#include "statemenu.hpp"
#include <mme/core/application.hpp>
#include <mme/core/inputprocessor.hpp>
#include <mme/core/statemanager.hpp>
#include <SFML/Window/Keyboard.hpp>
#include <iostream>
#include <string>
#include <unordered_map>
namespace
{
void setDefaultInputContexts()
{
mme::core::InputProcessor::instance().setDefaultContextsFunction([](std::vector<mme::core::InputProcessor::InputContext>& contexts)
{
mme::core::InputProcessor::InputContext context;
// State change buttons
context.keyToButton.insert(std::make_pair(sf::Keyboard::F1, mmgtmpl::client::cButtonStateMenu));
context.keyToButton.insert(std::make_pair(sf::Keyboard::F2, mmgtmpl::client::cButtonStateGame));
// Mouse controls
context.mouseButtonToButton.insert(std::make_pair(sf::Mouse::Left, mmgtmpl::client::cButtonLMB));
context.mouseButtonToButton.insert(std::make_pair(sf::Mouse::Right, mmgtmpl::client::cButtonRMB));
// Gameplay stuff
contexts.push_back(context);
});
}
void setStates()
{
std::unordered_map<std::string, mme::core::AbstractState*> states;
states.insert(std::make_pair(mmgtmpl::client::cStateMenu, new mmgtmpl::client::StateMenu()));
states.insert(std::make_pair(mmgtmpl::client::cStateMenu, new mmgtmpl::client::StateGame()));
}
}
int main()
{
setDefaultInputContexts();
setStates();
mme::core::Application& app = mme::core::Application::instance();
app.init("MmgProjectTemplate Client", mme::Vec2i(1024, 780), mme::Vec2i(800, 600));
app.run();
return 0;
}
#include "statemenu.hpp"
#include "global.hpp"
#include <mme/core/statemanager.hpp>
namespace ad
{
namespace client
{
StateMenu::StateMenu()
{
}
bool StateMenu::clear()
{
//throw std::logic_error("The method or operation is not implemented.");
return true;
}
void StateMenu::draw(const float dt, const float interp)
{
//throw std::logic_error("The method or operation is not implemented.");
}
bool StateMenu::initialize()
{
//throw std::logic_error("The method or operation is not implemented.");
return true;
}
void StateMenu::onClose()
{
//throw std::logic_error("The method or operation is not implemented.");
}
void StateMenu::onWindowResized()
{
//throw std::logic_error("The method or operation is not implemented.");
}
void StateMenu::tick(float dt)
{
if (checkStateChange())
{
return;
}
}
}
}
\ No newline at end of file
#pragma once
#include <mme/core/abstractstate.hpp>
namespace ad
{
namespace client
{
class StateMenu : public mme::core::AbstractState
{
public:
StateMenu();
bool clear() override;
void draw(const float dt, const float interp) override;
bool initialize() override;
void onClose() override;
void onWindowResized() override;
void tick(float dt) override;
};
}
}
\ No newline at end of file
#------------------------------------------#
# MmgProjectTemplate Core #
#------------------------------------------#
cmake_minimum_required(VERSION 3.1)
set (CMAKE_CXX_STANDARD 17)
#---------- CREATING LIBRARY -------------
SET(MMGTMPL_CORE_LIB_NAME "core")
#headers
FILE(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp)
# source files
FILE(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/sources/*.cpp)
# Create library target
add_library(${MMGTMPL_CORE_LIB_NAME} ${SOURCES} ${HEADERS})
# Setting include files in target
target_include_directories(${MMGTMPL_CORE_LIB_NAME}
PUBLIC
#$<INSTALL_INTERFACE:include> # No install interface, adcore is built statically
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/sources
)
target_compile_definitions(${MMGTMPL_CORE_LIB_NAME} PUBLIC MMECPP_USE_SFML)
target_link_libraries(${MMGTMPL_CORE_LIB_NAME}
# Third parties
"yaml-cpp"
# Shared libraries
"mme"
"mmecpp"
"sfmlutils")
set_target_properties(${MMGTMPL_CORE_LIB_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
set_target_properties(${MMGTMPL_CORE_LIB_NAME} PROPERTIES FOLDER Andromeda2D)
# Source grouping
SET(F_H "Headers")
SET(F_S "Sources")
SET(SOURCE_GROUP_DELIMITER "/")
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include PREFIX ${F_H} FILES ${HEADERS})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/sources PREFIX ${F_S} FILES ${SOURCES})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment