Browse Source

Fix files that were incorrectly merged from another repository

master
C. J. Howard 5 years ago
parent
commit
80d4e310d9
Signed by: cjhoward GPG Key ID: 03E1FABA9C3EC195
11 changed files with 0 additions and 6065 deletions
  1. +0
    -377
      CMakeLists.txt
  2. +0
    -2318
      src/application.cpp
  3. +0
    -664
      src/controls.cpp
  4. +0
    -0
      src/dpi-aware.manifest
  5. +0
    -119
      src/game/biome.cpp
  6. +0
    -788
      src/input.cpp
  7. +0
    -1248
      src/render-passes.cpp
  8. +0
    -303
      src/resources/material-loader.cpp
  9. +0
    -28
      src/resources/model-loader.cpp
  10. +0
    -92
      src/settings.cpp
  11. +0
    -128
      src/states/loading-state.cpp

+ 0
- 377
CMakeLists.txt View File

@ -1,4 +1,3 @@
<<<<<<< HEAD
cmake_minimum_required(VERSION 3.7)
# Set compiler flags
@ -42,379 +41,3 @@ target_link_libraries(${EXECUTABLE_TARGET} ${STATIC_LIBS})
# Install executable
install(TARGETS ${EXECUTABLE_TARGET} DESTINATION bin)
=======
cmake_minimum_required(VERSION 3.7)
project(antkeeper
VERSION "0.0.0"
)
option(STANDALONE "Distribute in a standalone archive." OFF)
set(LANGUAGE "en-us" CACHE STRING "")
# Determine target build platform according to binary dir
get_filename_component(PLATFORM ${PROJECT_BINARY_DIR} NAME CACHE)
# Check for architecture mismatches
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
if (${PLATFORM} STREQUAL "win64" OR ${PLATFORM} STREQUAL "linux64")
message(FATAL_ERROR "Compiler architecture is 32-bit but target architecture is 64-bit.")
endif()
else()
if (${PLATFORM} STREQUAL "win32" OR ${PLATFORM} STREQUAL "linux32")
message(FATAL_ERROR "Compiler architecture is 64-bit but target architecture is 32-bit.")
endif()
endif()
# Setup configuration strings
set(ANTKEEPER_VERSION ${PROJECT_VERSION})
set(ANTKEEPER_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(ANTKEEPER_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(ANTKEEPER_VERSION_PATCH ${PROJECT_VERSION_PATCH})
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(ANTKEEPER_BUILD_TYPE debug)
set(ANTKEEPER_DEBUG ON)
else()
set(ANTKEEPER_BUILD_TYPE release)
set(ANTKEEPER_DEBUG OFF)
endif()
# Setup build type paths
set(BUILD_DIR ${PROJECT_SOURCE_DIR}/bin)
set(BUILD_DEBUG_DIR ${BUILD_DIR}/debug)
set(BUILD_RELEASE_DIR ${BUILD_DIR}/release)
# Set package name
set(PACKAGE_NAME ${PROJECT_NAME}-${PROJECT_VERSION}-${PLATFORM})
set(PACKAGE_BUILD_NAME ${PACKAGE_NAME}-${ANTKEEPER_BUILD_TYPE})
# Set package directory
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(PLATFORM_PACKAGE_DIR ${BUILD_DEBUG_DIR}/${PACKAGE_NAME})
else()
set(PLATFORM_PACKAGE_DIR ${BUILD_RELEASE_DIR}/${PACKAGE_NAME})
endif()
# Set C++ compiler flags for debug and release build types
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W2")
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
# Update if necessary
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -s -DNDEBUG")
endif()
# Set C and C++ compiler flags for the target architecture
if(${PLATFORM} STREQUAL "win32" OR ${PLATFORM} STREQUAL "linux32")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
elseif(${PLATFORM} STREQUAL "win64" OR ${PLATFORM} STREQUAL "linux64")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
elseif(${PLATFORM} STREQUAL "osx" AND CMAKE_OSX_ARCHITECTURES STREQUAL "")
# 32-bit
#set(CMAKE_OSX_ARCHITECTURES "i386" CACHE STRING "" FORCE)
# 64-bit
#set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "" FORCE)
# 96-bit universal
set(CMAKE_OSX_ARCHITECTURES "x86_64;i386" CACHE STRING "" FORCE)
endif()
# Disable .manifest generation
if(${PLATFORM} STREQUAL "win32" OR ${PLATFORM} STREQUAL "win64")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO /OPT:REF /OPT:ICF")
endif()
# Set C++ version
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Include ExternalProject_Add command
include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
# Configure, build and install emergent
set(EMERGENT_BUILD_DIR ${PROJECT_BINARY_DIR}/deps/build/emergent)
set(EMERGENT_INSTALL_DIR ${PROJECT_BINARY_DIR}/deps/install/emergent)
set(EMERGENT_INCLUDE_DIR ${EMERGENT_INSTALL_DIR}/include)
set(EMERGENT_GL3W_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/lib/emergent/lib/gl3w/include)
set(EMERGENT_GLM_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/lib/emergent/lib/glm)
set(EMERGENT_STB_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/lib/emergent/lib/stb)
set(EMERGENT_INCLUDE_DIRS
${EMERGENT_INCLUDE_DIR}
${EMERGENT_GL3W_INCLUDE_DIR}
${EMERGENT_GLM_INCLUDE_DIR}
${EMERGENT_STB_INCLUDE_DIR}
)
set(EMERGENT_LIBRARY emergent)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(FREETYPE_LIBRARY freetyped)
else()
set(FREETYPE_LIBRARY freetype)
endif()
set(EMERGENT_LIBRARIES
${EMERGENT_LIBRARY}
${FREETYPE_LIBRARY}
)
ExternalProject_Add(emergent-project
SOURCE_DIR ${PROJECT_SOURCE_DIR}/lib/emergent
CMAKE_ARGS
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DCMAKE_INSTALL_PREFIX=${EMERGENT_INSTALL_DIR}"
BINARY_DIR ${EMERGENT_BUILD_DIR}
INSTALL_DIR ${EMERGENT_INSTALL_DIR})
# Configure, build and install SDL2
set(SDL2_BUILD_DIR ${PROJECT_BINARY_DIR}/deps/build/SDL2)
set(SDL2_INSTALL_DIR ${PROJECT_BINARY_DIR}/deps/install/SDL2)
set(SDL2_INCLUDE_DIR ${SDL2_INSTALL_DIR}/include)
set(SDL2_LIBRARY SDL2)
set(SDL2main_LIBRARY SDL2main)
set(SDL2_LIBRARIES
${SDL2main_LIBRARY}
${SDL2_LIBRARY}
)
if(MSVC)
set(SDL2_LIBRARIES
${SDL2_LIBRARIES}
dinput8
dxguid
user32
gdi32
winmm
imm32
ole32
oleaut32
shell32
version
uuid
)
else()
set(SDL2_LIBRARIES
${SDL2_LIBRARIES}
pthread
dl
)
endif()
ExternalProject_Add(SDL2-project
SOURCE_DIR ${PROJECT_SOURCE_DIR}/lib/SDL2
CMAKE_ARGS
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DCMAKE_INSTALL_PREFIX=${SDL2_INSTALL_DIR}"
"-DSDL_STATIC=true"
"-DSDL_SHARED=false"
BINARY_DIR ${SDL2_BUILD_DIR}
INSTALL_DIR ${SDL2_INSTALL_DIR})
# Configure, build and install dirent
set(DIRENT_BUILD_DIR ${PROJECT_BINARY_DIR}/deps/build/dirent)
set(DIRENT_INSTALL_DIR ${PROJECT_BINARY_DIR}/deps/install/dirent)
set(DIRENT_INCLUDE_DIR ${DIRENT_INSTALL_DIR}/include)
ExternalProject_Add(dirent-project
SOURCE_DIR ${PROJECT_SOURCE_DIR}/lib/dirent
CMAKE_ARGS
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DCMAKE_INSTALL_PREFIX=${DIRENT_INSTALL_DIR}"
BINARY_DIR ${DIRENT_BUILD_DIR}
INSTALL_DIR ${DIRENT_INSTALL_DIR})
# Find OpenGL
find_package(OpenGL REQUIRED)
# Find executable source directory
set(EXECUTABLE_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
# Generate C++ configuration file
configure_file(${EXECUTABLE_SOURCE_DIR}/configuration.hpp.in ${EXECUTABLE_SOURCE_DIR}/configuration.hpp)
# Collect executable source files
set(EXECUTABLE_SOURCES
${EXECUTABLE_SOURCE_DIR}/configuration.hpp
${EXECUTABLE_SOURCE_DIR}/controls.cpp
${EXECUTABLE_SOURCE_DIR}/render-passes.hpp
${EXECUTABLE_SOURCE_DIR}/settings.cpp
${EXECUTABLE_SOURCE_DIR}/settings.hpp
${EXECUTABLE_SOURCE_DIR}/game/terrain.cpp
${EXECUTABLE_SOURCE_DIR}/game/terrain.hpp
${EXECUTABLE_SOURCE_DIR}/controls.hpp
${EXECUTABLE_SOURCE_DIR}/input.cpp
${EXECUTABLE_SOURCE_DIR}/input.hpp
${EXECUTABLE_SOURCE_DIR}/main.cpp
${EXECUTABLE_SOURCE_DIR}/mesh.cpp
${EXECUTABLE_SOURCE_DIR}/mesh.hpp
${EXECUTABLE_SOURCE_DIR}/application-state.hpp
${EXECUTABLE_SOURCE_DIR}/application-state.cpp
${EXECUTABLE_SOURCE_DIR}/application.hpp
${EXECUTABLE_SOURCE_DIR}/application.cpp
${EXECUTABLE_SOURCE_DIR}/states/loading-state.hpp
${EXECUTABLE_SOURCE_DIR}/states/loading-state.cpp
${EXECUTABLE_SOURCE_DIR}/states/splash-state.hpp
${EXECUTABLE_SOURCE_DIR}/states/splash-state.cpp
${EXECUTABLE_SOURCE_DIR}/states/title-state.hpp
${EXECUTABLE_SOURCE_DIR}/states/title-state.cpp
${EXECUTABLE_SOURCE_DIR}/states/game-state.hpp
${EXECUTABLE_SOURCE_DIR}/states/game-state.cpp
${EXECUTABLE_SOURCE_DIR}/ui/ui.hpp
${EXECUTABLE_SOURCE_DIR}/ui/ui.cpp
${EXECUTABLE_SOURCE_DIR}/ui/menu.hpp
${EXECUTABLE_SOURCE_DIR}/ui/menu.cpp
${EXECUTABLE_SOURCE_DIR}/ui/tween.hpp
${EXECUTABLE_SOURCE_DIR}/ui/tween.cpp
${EXECUTABLE_SOURCE_DIR}/ui/toolbar.hpp
${EXECUTABLE_SOURCE_DIR}/ui/toolbar.cpp
${EXECUTABLE_SOURCE_DIR}/ui/pie-menu.hpp
${EXECUTABLE_SOURCE_DIR}/ui/pie-menu.cpp
${EXECUTABLE_SOURCE_DIR}/render-passes.cpp
${EXECUTABLE_SOURCE_DIR}/game/ant.hpp
${EXECUTABLE_SOURCE_DIR}/game/ant.cpp
${EXECUTABLE_SOURCE_DIR}/game/agent.hpp
${EXECUTABLE_SOURCE_DIR}/game/agent.cpp
${EXECUTABLE_SOURCE_DIR}/game/colony.hpp
${EXECUTABLE_SOURCE_DIR}/game/colony.cpp
${EXECUTABLE_SOURCE_DIR}/game/habitat.hpp
${EXECUTABLE_SOURCE_DIR}/game/habitat.cpp
${EXECUTABLE_SOURCE_DIR}/game/nest.hpp
${EXECUTABLE_SOURCE_DIR}/game/nest.cpp
${EXECUTABLE_SOURCE_DIR}/game/navmesh.hpp
${EXECUTABLE_SOURCE_DIR}/game/navmesh.cpp
${EXECUTABLE_SOURCE_DIR}/game/pheromone-matrix.hpp
${EXECUTABLE_SOURCE_DIR}/game/pheromone-matrix.cpp
${EXECUTABLE_SOURCE_DIR}/game/level.hpp
${EXECUTABLE_SOURCE_DIR}/game/level.cpp
${EXECUTABLE_SOURCE_DIR}/game/biome.hpp
${EXECUTABLE_SOURCE_DIR}/game/biome.cpp
${EXECUTABLE_SOURCE_DIR}/game/tool.cpp
${EXECUTABLE_SOURCE_DIR}/debug.hpp
${EXECUTABLE_SOURCE_DIR}/debug.cpp
${EXECUTABLE_SOURCE_DIR}/camera-rig.hpp
${EXECUTABLE_SOURCE_DIR}/camera-rig.cpp
${EXECUTABLE_SOURCE_DIR}/model-loader.hpp
${EXECUTABLE_SOURCE_DIR}/model-loader.cpp
${EXECUTABLE_SOURCE_DIR}/material-loader.hpp
${EXECUTABLE_SOURCE_DIR}/material-loader.cpp
)
# Setup manifest and exe icon for windows
if(${PLATFORM} STREQUAL "win32" OR ${PLATFORM} STREQUAL "win64")
list(APPEND EXECUTABLE_SOURCES "${EXECUTABLE_SOURCE_DIR}/windows/antkeeper.manifest")
if(EXISTS ${PROJECT_SOURCE_DIR}/data)
set(RC_FILES "${PROJECT_SOURCE_DIR}/data/icons/icon.rc")
set(EXECUTABLE_SOURCES "${EXECUTABLE_SOURCES};${RC_FILES}")
endif()
endif()
# Set link directories
link_directories(${EMERGENT_INSTALL_DIR}/lib
${SDL2_INSTALL_DIR}/lib
)
# Set executable and library output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PLATFORM_PACKAGE_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PLATFORM_PACKAGE_DIR})
# Add executable
set(EXECUTABLE_NAME antkeeper)
set(EXECUTABLE_TARGET ${PACKAGE_BUILD_NAME}-executable)
add_executable(${EXECUTABLE_TARGET} ${EXECUTABLE_SOURCES})
add_dependencies(${EXECUTABLE_TARGET} emergent-project SDL2-project dirent-project)
set_target_properties(${EXECUTABLE_TARGET} PROPERTIES OUTPUT_NAME ${EXECUTABLE_NAME})
# Set include directories
target_include_directories(${EXECUTABLE_TARGET} PUBLIC
${EMERGENT_INCLUDE_DIRS}
${SDL2_INCLUDE_DIR}
${DIRENT_INCLUDE_DIR}
${OPENGL_INCLUDE_DIRS}
)
# Build library list
list(APPEND EXECUTABLE_LIBRARIES
${SDL2_LIBRARIES}
${EMERGENT_LIBRARIES}
${OPENGL_gl_LIBRARY}
${FREETYPE_LIBRARY}
#m
#stdc++
)
# Link libraries
target_link_libraries(${EXECUTABLE_TARGET} ${EXECUTABLE_LIBRARIES})
# Add run target
if(${PLATFORM} STREQUAL "linux32" OR ${PLATFORM} STREQUAL "linux64")
add_custom_target(run
COMMAND optirun "${PLATFORM_PACKAGE_DIR}/${EXECUTABLE_NAME}"
DEPENDS ${EXECUTABLE_TARGET}
WORKING_DIRECTORY ${PLATFORM_PACKAGE_DIR}
)
else()
add_custom_target(run
COMMAND ${EXECUTABLE_TARGET}
DEPENDS ${EXECUTABLE_TARGET}
WORKING_DIRECTORY ${PLATFORM_PACKAGE_DIR}
)
endif()
# Add dist target
add_custom_target(dist
COMMAND
${CMAKE_COMMAND} -E tar "cfvz" "${PROJECT_SOURCE_DIR}/dist/${PACKAGE_NAME}.zip" --format=zip
"${PLATFORM_PACKAGE_DIR}")
# Add clean targets
add_custom_target(clean-build
COMMAND git clean -fdX
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/build"
)
# Add data subdirectory (if it exists)
if(EXISTS ${PROJECT_SOURCE_DIR}/data)
add_subdirectory(${PROJECT_SOURCE_DIR}/data)
endif()
# Distribution
install(TARGETS ${EXECUTABLE_TARGET} DESTINATION ".")
install(DIRECTORY ${PLATFORM_PACKAGE_DIR}/data
DESTINATION .)
set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "C. J. Howard")
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${PLATFORM})
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CPACK_OUTPUT_FILE_PREFIX "${PROJECT_SOURCE_DIR}/dist/debug")
else()
set(CPACK_OUTPUT_FILE_PREFIX "${PROJECT_SOURCE_DIR}/dist/release")
endif()
if(${PLATFORM} STREQUAL "win32" OR ${PLATFORM} STREQUAL "win64")
set(CPACK_GENERATOR "ZIP")
if (NOT STANDALONE)
set(CPACK_GENERATOR "NSIS")
set(CPACK_MONOLITHIC_INSTALL 1)
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_FILE_NAME}-installer)
set(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/data/icons/antkeeper-icon.ico")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Antkeeper")
get_target_property(EXECUTABLE_OUTPUT_NAME ${EXECUTABLE_TARGET} OUTPUT_NAME)
set(CPACK_NSIS_MENU_LINKS "${EXECUTABLE_OUTPUT_NAME}" "Antkeeper")
endif()
elseif(${PLATFORM} STREQUAL "linux32" OR ${PLATFORM} STREQUAL "linux64")
set(CPACK_GENERATOR "TGZ")
if(NOT STANDALONE)
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
endif()
endif()
include(CPack)
>>>>>>> df8405f4e83febb81a5ce8f772bd7f5b9e9b6036

+ 0
- 2318
src/application.cpp
File diff suppressed because it is too large
View File


+ 0
- 664
src/controls.cpp View File

@ -1,664 +0,0 @@
/*
* Copyright (C) 2017 Christopher J. Howard
*
* This file is part of Antkeeper Source Code.
*
* Antkeeper Source Code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper Source Code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "controls.hpp"
#include <sstream>
#include <fstream>
#include <vector>
Control::Control():
deadzone(0.1f),
currentValue(0.0f),
previousValue(0.0f)
{}
Control::~Control()
{}
void Control::setDeadzone(float value)
{
deadzone = value;
}
void Control::update()
{
if (!boundMouseWheelAxes.empty())
{
currentValue = 0.0f;
}
previousValue = currentValue;
}
bool Control::isTriggered() const
{
return currentValue > deadzone;
}
bool Control::wasTriggered() const
{
return previousValue > deadzone;
}
bool Control::isUnbound() const
{
return (boundKeys.empty() && boundMouseButtons.empty() && boundMouseWheelAxes.empty() && boundGamepadButtons.empty() && boundGamepadAxes.empty());
}
void Control::bindKey(Keyboard* keyboard, int scancode)
{
// Check if already observing this keyboard
bool observing = false;
for (auto it: boundKeys)
{
if (it.first == keyboard)
{
observing = true;
break;
}
}
if (!observing)
keyboard->addKeyObserver(static_cast<KeyObserver*>(this));
boundKeys.push_back(std::pair<Keyboard*, int>(keyboard, scancode));
}
void Control::bindMouseButton(Mouse* mouse, int button)
{
// Checking if already observing this mouse
bool observing = false;
for (auto it: boundMouseButtons)
{
if (it.first == mouse)
{
observing = true;
break;
}
}
if (!observing)
mouse->addMouseButtonObserver(static_cast<MouseButtonObserver*>(this));
boundMouseButtons.push_back(std::pair<Mouse*, int>(mouse, button));
}
void Control::bindMouseWheelAxis(Mouse* mouse, MouseWheelAxis axis)
{
// Checking if already observing this mouse
bool observing = false;
for (auto it: boundMouseWheelAxes)
{
if (it.first == mouse)
{
observing = true;
break;
}
}
if (!observing)
mouse->addMouseWheelObserver(static_cast<MouseWheelObserver*>(this));
boundMouseWheelAxes.push_back(std::pair<Mouse*, MouseWheelAxis>(mouse, axis));
}
void Control::bindGamepadButton(Gamepad* gamepad, int button)
{
bool observing = false;
for (auto it: boundGamepadButtons)
{
if (it.first == gamepad)
{
observing = true;
break;
}
}
if (!observing)
gamepad->addGamepadButtonObserver(static_cast<GamepadButtonObserver*>(this));
boundGamepadButtons.push_back(std::pair<Gamepad*, int>(gamepad, button));
}
void Control::bindGamepadAxis(Gamepad* gamepad, int axis, bool negative)
{
bool observing = false;
for (auto it: boundGamepadAxes)
{
if (std::get<0>(it) == gamepad)
{
observing = true;
break;
}
}
if (!observing)
gamepad->addGamepadAxisObserver(static_cast<GamepadAxisObserver*>(this));
boundGamepadAxes.push_back(std::make_tuple(gamepad, axis, negative));
}
void Control::bind(const InputEvent& event)
{
switch (event.type)
{
case InputEvent::Type::KEY:
bindKey(event.key.first, event.key.second);
break;
case InputEvent::Type::MOUSE_BUTTON:
bindMouseButton(event.mouseButton.first, event.mouseButton.second);
break;
case InputEvent::Type::MOUSE_WHEEL:
{
int x = std::get<1>(event.mouseWheel);
int y = std::get<2>(event.mouseWheel);
MouseWheelAxis axis;
if (x > 0)
axis = MouseWheelAxis::POSITIVE_X;
else if (x < 0)
axis = MouseWheelAxis::NEGATIVE_X;
else if (y > 0)
axis = MouseWheelAxis::POSITIVE_Y;
else if (y < 0)
axis = MouseWheelAxis::NEGATIVE_Y;
else
break;
bindMouseWheelAxis(std::get<0>(event.mouseWheel), axis);
break;
}
case InputEvent::Type::GAMEPAD_BUTTON:
bindGamepadButton(event.gamepadButton.first, event.gamepadButton.second);
break;
case InputEvent::Type::GAMEPAD_AXIS:
bindGamepadAxis(std::get<0>(event.gamepadAxis), std::get<1>(event.gamepadAxis), std::get<2>(event.gamepadAxis));
break;
default:
break;
}
}
void Control::unbind()
{
while (!boundKeys.empty())
{
// Remove the first bound key and stop observing its keyboard
Keyboard* keyboard = boundKeys.front().first;
keyboard->removeKeyObserver(static_cast<KeyObserver*>(this));
boundKeys.pop_front();
// Remove other bound keys which are associated with the keyboard
auto it = boundKeys.begin();
while (it != boundKeys.end())
{
if (it->first == keyboard)
boundKeys.erase(it++);
else
++it;
}
}
while (!boundMouseButtons.empty())
{
// Remove the first bound mouse button and stop observing its mouse
Mouse* mouse = boundMouseButtons.front().first;
mouse->removeMouseButtonObserver(static_cast<MouseButtonObserver*>(this));
boundMouseButtons.pop_front();
// Remove other bound mouse buttons which are associated with the mouse
auto it = boundMouseButtons.begin();
while (it != boundMouseButtons.end())
{
if (it->first == mouse)
boundMouseButtons.erase(it++);
else
++it;
}
}
while (!boundMouseWheelAxes.empty())
{
// Remove the first bound mouse button and stop observing its mouse
Mouse* mouse = boundMouseWheelAxes.front().first;
mouse->removeMouseWheelObserver(static_cast<MouseWheelObserver*>(this));
boundMouseWheelAxes.pop_front();
// Remove other bound mouse buttons which are associated with the mouse
auto it = boundMouseWheelAxes.begin();
while (it != boundMouseWheelAxes.end())
{
if (it->first == mouse)
boundMouseWheelAxes.erase(it++);
else
++it;
}
}
while (!boundGamepadButtons.empty())
{
// Remove the first bound gamepad button and stop observing its gamepad
Gamepad* gamepad = boundGamepadButtons.front().first;
gamepad->removeGamepadButtonObserver(static_cast<GamepadButtonObserver*>(this));
boundGamepadButtons.pop_front();
// Remove other bound gamepad buttons which are associated with the gamepad
auto it = boundGamepadButtons.begin();
while (it != boundGamepadButtons.end())
{
if (it->first == gamepad)
boundGamepadButtons.erase(it++);
else
++it;
}
}
while (!boundGamepadAxes.empty())
{
// Remove the first bound gamepad axis and stop observing its gamepad
Gamepad* gamepad = std::get<0>(boundGamepadAxes.front());
gamepad->removeGamepadAxisObserver(static_cast<GamepadAxisObserver*>(this));
boundGamepadAxes.pop_front();
// Remove other bound gamepad axes which are associated with the gamepad
auto it = boundGamepadAxes.begin();
while (it != boundGamepadAxes.end())
{
if (std::get<0>(*it) == gamepad)
boundGamepadAxes.erase(it++);
else
++it;
}
}
}
void Control::keyPressed(int scancode)
{
for (auto it: boundKeys)
{
if (it.second == scancode)
{
currentValue = 1.0f;
break;
}
}
}
void Control::keyReleased(int scancode)
{
for (auto it: boundKeys)
{
if (it.second == scancode)
{
currentValue = 0.0f;
break;
}
}
}
void Control::mouseButtonPressed(int button, int x, int y)
{
for (auto it: boundMouseButtons)
{
if (it.second == button)
{
currentValue = 1.0f;
break;
}
}
}
void Control::mouseButtonReleased(int button, int x, int y)
{
for (auto it: boundMouseButtons)
{
if (it.second == button)
{
currentValue = 0.0f;
break;
}
}
}
void Control::mouseWheelScrolled(int x, int y)
{
for (auto it: boundMouseWheelAxes)
{
if (it.second == MouseWheelAxis::POSITIVE_X && x > 0)
{
currentValue += x;
break;
}
else if (it.second == MouseWheelAxis::NEGATIVE_X && x < 0)
{
currentValue -= x;
break;
}
else if (it.second == MouseWheelAxis::POSITIVE_Y && y > 0)
{
currentValue += y;
break;
}
else if (it.second == MouseWheelAxis::NEGATIVE_Y && y < 0)
{
currentValue -= y;
break;
}
}
}
void Control::gamepadButtonPressed(int button)
{
for (auto it: boundGamepadButtons)
{
if (it.second == button)
{
currentValue = 1.0f;
break;
}
}
}
void Control::gamepadButtonReleased(int button)
{
for (auto it: boundGamepadButtons)
{
if (it.second == button)
{
currentValue = 0.0f;
break;
}
}
}
void Control::gamepadAxisMoved(int axis, bool negative, float value)
{
for (auto it: boundGamepadAxes)
{
if (std::get<1>(it) == axis && std::get<2>(it) == negative)
{
currentValue = value;
break;
}
}
}
const std::list<std::pair<Keyboard*, int>>* Control::getBoundKeys() const
{
return &boundKeys;
}
const std::list<std::pair<Mouse*, int>>* Control::getBoundMouseButtons() const
{
return &boundMouseButtons;
}
const std::list<std::pair<Mouse*, MouseWheelAxis>>* Control::getBoundMouseWheelAxes() const
{
return &boundMouseWheelAxes;
}
const std::list<std::pair<Gamepad*, int>>* Control::getBoundGamepadButtons() const
{
return &boundGamepadButtons;
}
const std::list<std::tuple<Gamepad*, int, bool>>* Control::getBoundGamepadAxes() const
{
return &boundGamepadAxes;
}
ControlProfile::ControlProfile(InputManager* inputManager):
inputManager(inputManager)
{}
void ControlProfile::registerControl(const std::string& name, Control* control)
{
controls[name] = control;
}
bool ControlProfile::save(const std::string& filename)
{
// Open control profile
std::ofstream file(filename.c_str());
if (!file.is_open())
{
std::cerr << std::string("Failed to open control profile \"") << filename << std::string("\"") << std::endl;
return false;
}
for (auto it = controls.begin(); it != controls.end(); ++it)
{
Control* control = it->second;
const std::list<std::pair<Keyboard*, int>>* boundKeys = control->getBoundKeys();
const std::list<std::pair<Mouse*, int>>* boundMouseButtons = control->getBoundMouseButtons();
const std::list<std::pair<Mouse*, MouseWheelAxis>>* boundMouseWheelAxes = control->getBoundMouseWheelAxes();
const std::list<std::pair<Gamepad*, int>>* boundGamepadButtons = control->getBoundGamepadButtons();
const std::list<std::tuple<Gamepad*, int, bool>>* boundGamepadAxes = control->getBoundGamepadAxes();
for (auto boundKey: *boundKeys)
{
int key = boundKey.second;
file << std::string("control\t") << it->first << std::string("\tkeyboard\tkey\t") << key << '\n';
}
for (auto boundMouseButton: *boundMouseButtons)
{
int button = boundMouseButton.second;
file << std::string("control\t") << it->first << std::string("\tmouse\tbutton\t") << button << '\n';
}
for (auto boundMouseWheelAxis: *boundMouseWheelAxes)
{
MouseWheelAxis axis = boundMouseWheelAxis.second;
file << std::string("control\t") << it->first << std::string("\tmouse\twheel\t");
if (axis == MouseWheelAxis::POSITIVE_X)
file << std::string("+x");
else if (axis == MouseWheelAxis::NEGATIVE_X)
file << std::string("-x");
else if (axis == MouseWheelAxis::POSITIVE_Y)
file << std::string("+y");
else if (axis == MouseWheelAxis::NEGATIVE_Y)
file << std::string("-y");
else
file << std::string("unknown");
file << '\n';
}
for (auto boundGamepadButton: *boundGamepadButtons)
{
const std::string& gamepadName = boundGamepadButton.first->getName();
int button = boundGamepadButton.second;
file << std::string("control\t") << it->first << std::string("\tgamepad\t") << gamepadName << std::string("\tbutton\t") << button << '\n';
}
for (auto boundGamepadAxis: *boundGamepadAxes)
{
const std::string& gamepadName = std::get<0>(boundGamepadAxis)->getName();
int axis = std::get<1>(boundGamepadAxis);
bool negative = std::get<2>(boundGamepadAxis);
std::stringstream axisstream;
if (negative)
axisstream << std::string("-");
else
axisstream << std::string("+");
axisstream << axis;
file << std::string("control\t") << it->first << std::string("\tgamepad\t") << gamepadName << std::string("\taxis\t") << axisstream.str() << '\n';
}
}
file.close();
return true;
}
bool ControlProfile::load(const std::string& filename)
{
// Open control profile
std::ifstream file(filename.c_str());
if (!file.is_open())
{
std::cerr << std::string("Failed to open control profile \"") << filename << std::string("\"") << std::endl;
return false;
}
// Read profile
std::string line;
while (file.good() && std::getline(file, line))
{
// Tokenize line (tab-delimeted)
std::vector<std::string> tokens;
std::string token;
std::istringstream linestream(line);
while (std::getline(linestream, token, '\t'))
tokens.push_back(token);
if (tokens.empty() || tokens[0][0] == '#')
continue;
if (tokens[0] == "control" && tokens.size() >= 5)
{
// Use control name to get control pointer
auto it = controls.find(tokens[1]);
if (it == controls.end())
{
std::cerr << std::string("Attempted to load unregistered control \"") << tokens[1] << std::string("\" from control profile \"") << filename << std::string("\"") << std::endl;
continue;
}
Control* control = it->second;
// Find input device
if (tokens[2] == "keyboard")
{
Keyboard* keyboard = inputManager->getKeyboards()->front();
if (tokens[3] == "key")
{
std::stringstream keystream(tokens[4]);
int scancode = -1;
keystream >> scancode;
control->bindKey(keyboard, scancode);
}
else
{
std::cerr << std::string("Invalid line \"") << line << std::string("\" in control profile \"") << filename << std::string("\"") << std::endl;
}
}
else if (tokens[2] == "mouse")
{
Mouse* mouse = inputManager->getMice()->front();
if (tokens[3] == "button")
{
std::stringstream buttonstream(tokens[4]);
int button = -1;
buttonstream >> button;
control->bindMouseButton(mouse, button);
}
else if (tokens[3] == "wheel")
{
MouseWheelAxis axis;
if (tokens[4] == "+x")
axis = MouseWheelAxis::POSITIVE_X;
else if (tokens[4] == "-x")
axis = MouseWheelAxis::NEGATIVE_X;
else if (tokens[4] == "+y")
axis = MouseWheelAxis::POSITIVE_Y;
else if (tokens[4] == "-y")
axis = MouseWheelAxis::NEGATIVE_Y;
else
{
std::cerr << std::string("Invalid line \"") << line << std::string("\" in control profile \"") << filename << std::string("\"") << std::endl;
continue;
}
control->bindMouseWheelAxis(mouse, axis);
}
else
{
std::cerr << std::string("Invalid line \"") << line << std::string("\" in control profile \"") << filename << std::string("\"") << std::endl;
continue;
}
}
else if (tokens[2] == "gamepad")
{
if (tokens.size() != 6)
{
std::cerr << std::string("Invalid line \"") << line << std::string("\" in control profile \"") << filename << std::string("\"") << std::endl;
continue;
}
Gamepad* gamepad = inputManager->getGamepad(tokens[3]);
if (!gamepad)
{
gamepad = new Gamepad(tokens[3]);
gamepad->setDisconnected(true);
inputManager->registerGamepad(gamepad);
}
if (tokens[4] == "button")
{
std::stringstream buttonstream(tokens[5]);
int button = -1;
buttonstream >> button;
control->bindGamepadButton(gamepad, button);
}
else if (tokens[4] == "axis")
{
bool negative = (tokens[5][0] == '-');
std::stringstream axisstream(tokens[5].substr(1, tokens[5].length() - 1));
int axis = -1;
axisstream >> axis;
control->bindGamepadAxis(gamepad, axis, negative);
}
else
{
std::cerr << std::string("Invalid line \"") << line << std::string("\" in control profile \"") << filename << std::string("\"") << std::endl;
continue;
}
}
else
{
std::cerr << std::string("Unsupported input device \"") << tokens[3] << std::string("\" in control profile \"") << filename << std::string("\"") << std::endl;
continue;
}
}
}
file.close();
return true;
}
void ControlProfile::update()
{
for (auto it = controls.begin(); it != controls.end(); ++it)
{
it->second->update();
}
}

src/windows/antkeeper.manifest → src/dpi-aware.manifest View File


+ 0
- 119
src/game/biome.cpp View File

@ -1,119 +0,0 @@
#include "biome.hpp"
#include "../settings.hpp"
#include <dirent.h>
#include <iostream>
Biome::Biome()
{}
Biome::~Biome()
{}
bool Biome::load()
{
ParameterDict parameters;
if (!parameters.load(filename))
{
return false;
}
parameters.get("name", &name);
parameters.get("soil-horizon-o", &soilHorizonOFilename);
parameters.get("soil-horizon-a", &soilHorizonAFilename);
parameters.get("soil-horizon-b", &soilHorizonBFilename);
parameters.get("soil-horizon-c", &soilHorizonCFilename);
parameters.get("cubemap", &cubemapName);
TextureLoader textureLoader;
textureLoader.setMipmapChain(false);
textureLoader.setWrapS(true);
textureLoader.setWrapT(true);
// Load soil horizon textures
soilHorizonO = textureLoader.load2D(std::string("data/textures/") + soilHorizonOFilename);
soilHorizonA = textureLoader.load2D(std::string("data/textures/") + soilHorizonAFilename);
soilHorizonB = textureLoader.load2D(std::string("data/textures/") + soilHorizonBFilename);
soilHorizonC = textureLoader.load2D(std::string("data/textures/") + soilHorizonCFilename);
// Load diffuse cubemap
textureLoader.setMipmapChain(true);
textureLoader.setWrapS(false);
textureLoader.setWrapT(false);
textureLoader.setWrapR(false);
std::string diffuseCubemapFilename = std::string("data/textures/") + cubemapName + std::string("-irradiance-m%02d.hdr");
diffuseCubemap = textureLoader.loadCube(diffuseCubemapFilename);
if (!diffuseCubemap)
{
std::cerr << std::string("Failed to load diffuse cubemap \"") << diffuseCubemapFilename << std::string("\"") << std::endl;
}
// Load specular cubemap
std::string specularCubemapFilename = std::string("data/textures/") + cubemapName + std::string("-radiance-m%02d.hdr");
specularCubemap = textureLoader.loadCube(specularCubemapFilename);
if (!specularCubemap)
{
std::cerr << std::string("Failed to load specular cubemap \"") << specularCubemapFilename << std::string("\"") << std::endl;
}
return true;
}
bool Biosphere::load(const std::string& directory)
{
// Open biomes directory
DIR* dir = opendir(directory.c_str());
if (dir == nullptr)
{
std::cout << std::string("Failed to open biome directory \"") << directory << std::string("\"") << std::endl;
return false;
}
// Scan directory for .bio files
for (struct dirent* entry = readdir(dir); entry != nullptr; entry = readdir(dir))
{
if (entry->d_type == DT_DIR || *entry->d_name == '.')
{
continue;
}
std::string filename = entry->d_name;
std::string::size_type delimeter = filename.find_last_of('.');
if (delimeter == std::string::npos)
{
continue;
}
std::string extension = filename.substr(delimeter + 1);
if (extension != "bio")
{
continue;
}
// Add biome
std::string name = filename.substr(0, delimeter);
Biome* biome = &biomes[name];
biome->filename = directory + filename;
}
// Close biomes directory
closedir(dir);
// Load biomes
for (std::map<std::string, Biome>::iterator it = biomes.begin(); it != biomes.end(); ++it)
{
Biome* biome = &it->second;
if (!biome->load())
{
std::cout << std::string("Failed to load biome \"") << biome->filename << std::string("\"") << std::endl;
}
else
{
std::cout << std::string("Loaded biome \"") << biome->filename << std::string("\"") << std::endl;
}
}
return true;
}

+ 0
- 788
src/input.cpp View File

@ -1,788 +0,0 @@
/*
* Copyright (C) 2017 Christopher J. Howard
*
* This file is part of Antkeeper Source Code.
*
* Antkeeper Source Code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper Source Code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "input.hpp"
#include <iostream>
InputDevice::InputDevice(const std::string& name):
name(name),
disconnected(true)
{}
void InputDevice::setDisconnected(bool disconnected)
{
this->disconnected = disconnected;
}
Keyboard::Keyboard(const std::string& name):
InputDevice(name)
{}
Keyboard::~Keyboard()
{}
void Keyboard::addKeyObserver(KeyObserver* observer)
{
keyObservers.push_back(observer);
}
void Keyboard::removeKeyObserver(KeyObserver* observer)
{
keyObservers.remove(observer);
}
void Keyboard::removeKeyObservers()
{
keyObservers.clear();
}
void Keyboard::press(int scancode)
{
for (auto observer: keyObservers)
{
observer->keyPressed(scancode);
}
}
void Keyboard::release(int scancode)
{
for (auto observer: keyObservers)
{
observer->keyReleased(scancode);
}
}
Mouse::Mouse(const std::string& name):
InputDevice(name),
notifyingMotionObservers(false),
notifyingButtonObservers(false),
notifyingWheelObservers(false)
{}
Mouse::~Mouse()
{}
void Mouse::addMouseMotionObserver(MouseMotionObserver* observer)
{
if (notifyingMotionObservers)
{
additionFlaggedMotionObservers.push_back(observer);
}
else
{
motionObservers.push_back(observer);
}
}
void Mouse::addMouseButtonObserver(MouseButtonObserver* observer)
{
if (notifyingButtonObservers)
{
additionFlaggedButtonObservers.push_back(observer);
}
else
{
buttonObservers.push_back(observer);
}
}
void Mouse::addMouseWheelObserver(MouseWheelObserver* observer)
{
if (notifyingWheelObservers)
{
additionFlaggedWheelObservers.push_back(observer);
}
else
{
wheelObservers.push_back(observer);
}
}
void Mouse::removeMouseMotionObserver(MouseMotionObserver* observer)
{
if (notifyingMotionObservers)
{
removalFlaggedMotionObservers.push_back(observer);
}
else
{
motionObservers.remove(observer);
}
}
void Mouse::removeMouseButtonObserver(MouseButtonObserver* observer)
{
if (notifyingButtonObservers)
{
removalFlaggedButtonObservers.push_back(observer);
}
else
{
buttonObservers.remove(observer);
}
}
void Mouse::removeMouseWheelObserver(MouseWheelObserver* observer)
{
if (notifyingWheelObservers)
{
removalFlaggedWheelObservers.push_back(observer);
}
else
{
wheelObservers.remove(observer);
}
}
void Mouse::removeMouseMotionObservers()
{
motionObservers.clear();
}
void Mouse::removeMouseButtonObservers()
{
buttonObservers.clear();
}
void Mouse::removeMouseWheelObservers()
{
wheelObservers.clear();
}
void Mouse::press(int button, int x, int y)
{
// Notify observers
notifyingButtonObservers = true;
for (auto observer: buttonObservers)
{
observer->mouseButtonPressed(button, x, y);
}
notifyingButtonObservers = false;
// Process flags
processFlaggedButtonObservers();
}
void Mouse::release(int button, int x, int y)
{
// Notify observers
notifyingButtonObservers = true;
for (auto observer: buttonObservers)
{
observer->mouseButtonReleased(button, x, y);
}
notifyingButtonObservers = false;
// Process flags
processFlaggedButtonObservers();
}
void Mouse::move(int x, int y)
{
previousPosition = currentPosition;
currentPosition = glm::ivec2(x, y);
// Notify observers
notifyingMotionObservers = true;
for (auto observer: motionObservers)
{
observer->mouseMoved(x, y);
}
notifyingMotionObservers = false;
// Process flags
processFlaggedMotionObservers();
}
void Mouse::scroll(int x, int y)
{
// Notify observers
notifyingWheelObservers = true;
for (auto observer: wheelObservers)
{
observer->mouseWheelScrolled(x, y);
}
notifyingWheelObservers = false;
// Process flags
processFlaggedWheelObservers();
}
void Mouse::processFlaggedMotionObservers()
{
// Remove observers which are flagged for removal
for (auto observer: removalFlaggedMotionObservers)
{
motionObservers.remove(observer);
}
removalFlaggedMotionObservers.clear();
// Add observers which are flagged for addition
for (auto observer: additionFlaggedMotionObservers)
{
motionObservers.push_back(observer);
}
additionFlaggedMotionObservers.clear();
}
void Mouse::processFlaggedButtonObservers()
{
// Remove observers which are flagged for removal
for (auto observer: removalFlaggedButtonObservers)
{
buttonObservers.remove(observer);
}
removalFlaggedButtonObservers.clear();
// Add observers which are flagged for addition
for (auto observer: additionFlaggedButtonObservers)
{
buttonObservers.push_back(observer);
}
additionFlaggedButtonObservers.clear();
}
void Mouse::processFlaggedWheelObservers()
{
// Remove observers which are flagged for removal
for (auto observer: removalFlaggedWheelObservers)
{
wheelObservers.remove(observer);
}
removalFlaggedWheelObservers.clear();
// Add observers which are flagged for addition
for (auto observer: additionFlaggedWheelObservers)
{
wheelObservers.push_back(observer);
}
additionFlaggedWheelObservers.clear();
}
Gamepad::Gamepad(const std::string& name):
InputDevice(name)
{}
Gamepad::~Gamepad()
{}
void Gamepad::addGamepadButtonObserver(GamepadButtonObserver* observer)
{
buttonObservers.push_back(observer);
}
void Gamepad::removeGamepadButtonObserver(GamepadButtonObserver* observer)
{
buttonObservers.remove(observer);
}
void Gamepad::removeGamepadButtonObservers()
{
buttonObservers.clear();
}
void Gamepad::addGamepadAxisObserver(GamepadAxisObserver* observer)
{
axisObservers.push_back(observer);
}
void Gamepad::removeGamepadAxisObserver(GamepadAxisObserver* observer)
{
axisObservers.remove(observer);
}
void Gamepad::removeGamepadAxisObservers()
{
axisObservers.clear();
}
void Gamepad::press(int button)
{
for (auto observer: buttonObservers)
{
observer->gamepadButtonPressed(button);
}
}
void Gamepad::release(int button)
{
for (auto observer: buttonObservers)
{
observer->gamepadButtonReleased(button);
}
}
void Gamepad::move(int axis, bool negative, float value)
{
for (auto observer: axisObservers)
{
observer->gamepadAxisMoved(axis, negative, value);
}
}
InputEvent::InputEvent():
type(InputEvent::Type::NONE)
{}
InputManager::InputManager():
closed(false)
{}
void InputManager::addWindowObserver(WindowObserver* observer)
{
windowObservers.push_back(observer);
}
void InputManager::removeWindowObserver(WindowObserver* observer)
{
windowObservers.remove(observer);
}
void InputManager::removeWindowObservers()
{
windowObservers.clear();
}
void InputManager::registerKeyboard(Keyboard* keyboard)
{
keyboards.push_back(keyboard);
}
void InputManager::registerMouse(Mouse* mouse)
{
mice.push_back(mouse);
}
void InputManager::registerGamepad(Gamepad* gamepad)
{
gamepads.push_back(gamepad);
}
void InputManager::unregisterKeyboard(Keyboard* keyboard)
{
keyboards.remove(keyboard);
}
void InputManager::unregisterMouse(Mouse* mouse)
{
mice.remove(mouse);
}
void InputManager::unregisterGamepad(Gamepad* gamepad)
{
gamepads.remove(gamepad);
}
bool InputManager::isRegistered(const Keyboard* keyboard) const
{
for (auto it = keyboards.begin(); it != keyboards.end(); ++it)
{
if (*it == keyboard)
return true;
}
return false;
}
bool InputManager::isRegistered(const Mouse* mouse) const
{
for (auto it = mice.begin(); it != mice.end(); ++it)
{
if (*it == mouse)
return true;
}
return false;
}
bool InputManager::isRegistered(const Gamepad* gamepad) const
{
for (auto it = gamepads.begin(); it != gamepads.end(); ++it)
{
if (*it == gamepad)
return true;
}
return false;
}
const Gamepad* InputManager::getGamepad(const std::string& name) const
{
for (auto gamepad: gamepads)
{
if (gamepad->getName() == name)
return gamepad;
}
return nullptr;
}
Gamepad* InputManager::getGamepad(const std::string& name)
{
for (auto gamepad: gamepads)
{
if (gamepad->getName() == name)
return gamepad;
}
return nullptr;
}
SDLInputManager::SDLInputManager()
{
keyboard = new Keyboard("Default Keyboard");
mouse = new Mouse("Default Mouse");
registerKeyboard(keyboard);
registerMouse(mouse);
keyboard->setDisconnected(false);
mouse->setDisconnected(false);
}
SDLInputManager::~SDLInputManager()
{
unregisterKeyboard(keyboard);
unregisterMouse(mouse);
for (auto gamepad: allocatedGamepads)
{
unregisterGamepad(gamepad);
delete gamepad;
}
delete keyboard;
delete mouse;
}
void SDLInputManager::update()
{
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
{
int scancode = event.key.keysym.scancode;
keyboard->press(scancode);
break;
}
case SDL_KEYUP:
{
int scancode = event.key.keysym.scancode;
keyboard->release(scancode);
break;
}
case SDL_MOUSEMOTION:
{
int x = event.motion.x;
int y = event.motion.y;
mouse->move(x, y);
break;
}
case SDL_MOUSEBUTTONDOWN:
{
int button = event.button.button;
mouse->press(button, event.button.x, event.button.y);
break;
}
case SDL_MOUSEBUTTONUP:
{
int button = event.button.button;
mouse->release(button, event.button.x, event.button.y);
break;
}
case SDL_MOUSEWHEEL:
{
int direction = (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) ? -1 : 1;
int x = event.wheel.x * direction;
int y = event.wheel.y * direction;
mouse->scroll(x, y);
break;
}
case SDL_CONTROLLERBUTTONDOWN:
{
int instanceID = event.cbutton.which;
auto it = gamepadMap.find(instanceID);
if (it == gamepadMap.end())
{
std::cerr << std::string("Received event from invalid gamepad") << std::endl;
break;
}
Gamepad* gamepad = it->second;
int button = event.cbutton.button;
gamepad->press(button);
break;
}
case SDL_CONTROLLERBUTTONUP:
{
int instanceID = event.cbutton.which;
auto it = gamepadMap.find(instanceID);
if (it == gamepadMap.end())
{
std::cerr << std::string("Received event from invalid gamepad") << std::endl;
break;
}
Gamepad* gamepad = it->second;
int button = event.cbutton.button;
gamepad->release(button);
break;
}
case SDL_CONTROLLERAXISMOTION:
{
int instanceID = event.caxis.which;
auto it = gamepadMap.find(instanceID);
if (it == gamepadMap.end())
{
std::cerr << std::string("Received event from invalid gamepad") << std::endl;
break;
}
Gamepad* gamepad = it->second;
int axis = event.caxis.axis;
bool negative;
float value;
if (event.caxis.value < 0)
{
negative = true;
value = (float)event.caxis.value / -32768.0f;
}
else
{
negative = false;
value = (float)event.caxis.value / 32767.0f;
}
gamepad->move(axis, negative, value);
break;
}
case SDL_CONTROLLERDEVICEADDED:
{
SDL_GameController* controller = SDL_GameControllerOpen(event.cdevice.which);
if (controller != nullptr)
{
// Find controller's joystick instance ID
SDL_Joystick* joystick = SDL_GameControllerGetJoystick(controller);
int instanceID = SDL_JoystickInstanceID(joystick);
// Determine gamepad name
std::string name = SDL_GameControllerName(controller);
if (name.empty())
{
name = "Unknown Gamepad";
}
bool reconnected = false;
const std::list<Gamepad*>* gamepads = getGamepads();
for (auto it = gamepads->begin(); it != gamepads->end(); ++it)
{
// Check if this gamepad was previously connected
if ((*it)->isDisconnected() && (*it)->getName() == name)
{
// Map to new instance ID
Gamepad* gamepad = *it;
gamepadMap[instanceID] = gamepad;
gamepad->setDisconnected(false);
reconnected = true;
std::cout << std::string("Reconnected gamepad \"") << name << std::string("\" with ID ") << instanceID << std::endl;
break;
}
}
if (!reconnected)
{
// Create new gamepad
Gamepad* gamepad = new Gamepad(name);
// Add to list of allocated gamepads
allocatedGamepads.push_back(gamepad);
// Register with the input manager
registerGamepad(gamepad);
// Map instance ID to gamepad pointer
gamepadMap[instanceID] = gamepad;
// Connect gamepad
gamepad->setDisconnected(false);
std::cout << std::string("Connected gamepad \"") << name << std::string("\" with ID ") << instanceID << std::endl;
}
}
break;
}
case SDL_CONTROLLERDEVICEREMOVED:
{
int instanceID = event.cdevice.which;
// Find gamepad
auto mapIt = gamepadMap.find(instanceID);
if (mapIt == gamepadMap.end())
{
std::cerr << std::string("Attempted to remove nonexistent gamepad with ID ") << instanceID << std::endl;
break;
}
Gamepad* gamepad = mapIt->second;
// Remove from gamepad map
gamepadMap.erase(mapIt);
// Set disconnected flag
gamepad->setDisconnected(true);
std::cout << std::string("Disconnected gamepad \"") << gamepad->getName() << std::string("\" with ID ") << instanceID << std::endl;
break;
}
case SDL_WINDOWEVENT:
{
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
{
for (auto observer: windowObservers)
{
observer->windowResized(event.window.data1, event.window.data2);
}
}
else if (event.window.event == SDL_WINDOWEVENT_CLOSE)
{
closed = true;
for (auto observer: windowObservers)
{
observer->windowClosed();
}
}
break;
}
case SDL_QUIT:
{
closed = true;
for (auto observer: windowObservers)
{
observer->windowClosed();
}
break;
}
default:
break;
}
}
}
void SDLInputManager::listen(InputEvent* inputEvent)
{
int eventCount;
// Gather events
SDL_PumpEvents();
// Check for key events
eventCount = SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_KEYDOWN, SDL_KEYDOWN);
if (eventCount)
{
int scancode = event.key.keysym.scancode;
inputEvent->type = InputEvent::Type::KEY;
inputEvent->key.first = keyboard;
inputEvent->key.second = scancode;
return;
}
// Check for mouse button events
eventCount = SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONDOWN);
if (eventCount)
{
int button = event.button.button;
inputEvent->type = InputEvent::Type::MOUSE_BUTTON;
inputEvent->mouseButton.first = mouse;
inputEvent->mouseButton.second = button;
return;
}
// Check for mouse wheel events
eventCount = SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_MOUSEWHEEL, SDL_MOUSEWHEEL);
if (eventCount)
{
int direction = (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) ? -1 : 1;
int x = event.wheel.x * direction;
int y = event.wheel.y * direction;
inputEvent->type = InputEvent::Type::MOUSE_WHEEL;
std::get<0>(inputEvent->mouseWheel) = mouse;
std::get<1>(inputEvent->mouseWheel) = x;
std::get<2>(inputEvent->mouseWheel) = y;
return;
}
// Check for gamepad button events
eventCount = SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_CONTROLLERBUTTONDOWN, SDL_CONTROLLERBUTTONDOWN);
if (eventCount)
{
int instanceID = event.cbutton.which;
auto it = gamepadMap.find(instanceID);
if (it == gamepadMap.end())
{
std::cerr << std::string("Received event from invalid gamepad") << std::endl;
return;
}
Gamepad* gamepad = it->second;
int button = event.cbutton.button;
inputEvent->type = InputEvent::Type::GAMEPAD_BUTTON;
inputEvent->gamepadButton.first = gamepad;
inputEvent->gamepadButton.second = button;
return;
}
// Check for gamepad axis events
eventCount = SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_CONTROLLERAXISMOTION, SDL_CONTROLLERAXISMOTION);
if (eventCount)
{
int instanceID = event.caxis.which;
auto it = gamepadMap.find(instanceID);
if (it == gamepadMap.end())
{
std::cerr << std::string("Received event from invalid gamepad") << std::endl;
return;
}
Gamepad* gamepad = it->second;
int axis = event.caxis.axis;
bool negative = event.caxis.value < 0;
inputEvent->type = InputEvent::Type::GAMEPAD_AXIS;
std::get<0>(inputEvent->gamepadAxis) = gamepad;
std::get<1>(inputEvent->gamepadAxis) = axis;
std::get<2>(inputEvent->gamepadAxis) = negative;
return;
}
}

+ 0
- 1248
src/render-passes.cpp
File diff suppressed because it is too large
View File


+ 0
- 303
src/resources/material-loader.cpp View File

@ -179,7 +179,6 @@ static bool loadShaderTextureCube(ResourceManager* resourceManager, ShaderTextur
{
for (int i = 0; i < elements.size(); ++i)
{
<<<<<<< HEAD:src/resources/material-loader.cpp
std::string filename;
std::stringstream stream;
stream << elements[i][0];
@ -188,11 +187,6 @@ static bool loadShaderTextureCube(ResourceManager* resourceManager, ShaderTextur
TextureCube* value = resourceManager->load<TextureCube>(filename);
variable->setValue(i, value);
=======
std::cerr << std::string("MaterialLoader::load(): Failed to open material file \"") << filename << std::string("\"") << std::endl;
delete material;
return nullptr;
>>>>>>> df8405f4e83febb81a5ce8f772bd7f5b9e9b6036:src/material-loader.cpp
}
return true;
@ -243,32 +237,20 @@ Material* ResourceLoader::load(ResourceManager* resourceManager, std::
std::size_t equalsSignPosition = line.find_first_of("=", commandPosition);
if (equalsSignPosition == std::string::npos)
{
<<<<<<< HEAD:src/resources/material-loader.cpp
// Line has no equals sign
std::stringstream stream;
stream << "ResourceLoader<Material>::load(): Invalid line " << lineNumber << ".";
throw std::runtime_error(stream.str().c_str());
=======
// Skip lines with no equals sign
std::cerr << std::string("MaterialLoader::load(): Invalid line ") << lineNumber << std::string(" in \"") << filename << std::string("\"") << std::endl;
continue;
>>>>>>> df8405f4e83febb81a5ce8f772bd7f5b9e9b6036:src/material-loader.cpp
}
// Find position of first character in the value string
std::size_t valueStartPosition = line.find_first_not_of(whitespace, equalsSignPosition + 1);
if (valueStartPosition == std::string::npos)
{
<<<<<<< HEAD:src/resources/material-loader.cpp
// Line has no value
std::stringstream stream;
stream << "ResourceLoader<Material>::load(): Invalid line " << lineNumber << ".";
throw std::runtime_error(stream.str().c_str());
=======
// Skip lines with no value
std::cerr << std::string("MaterialLoader::load(): Invalid line ") << lineNumber << std::string(" in \"") << filename << std::string("\"") << std::endl;
continue;
>>>>>>> df8405f4e83febb81a5ce8f772bd7f5b9e9b6036:src/material-loader.cpp
}
// Find position the end of the value string
@ -292,11 +274,7 @@ Material* ResourceLoader::load(ResourceManager* resourceManager, std::
Shader* shader = nullptr;
try
{
<<<<<<< HEAD:src/resources/material-loader.cpp
shader = resourceManager->load<Shader>(valueString);
=======
std::cerr << std::string("MaterialLoader::load(): Failed to load shader \"") << valueString << std::string("\" on line ") << lineNumber << std::string(" in \"") << filename << std::string("\"") << std::endl;
>>>>>>> df8405f4e83febb81a5ce8f772bd7f5b9e9b6036:src/material-loader.cpp
}
catch (const std::exception& e)
{
@ -324,14 +302,9 @@ Material* ResourceLoader::load(ResourceManager* resourceManager, std::
if (variableNamePosition == std::string::npos)
{
// Skip lines with no variable name
<<<<<<< HEAD:src/resources/material-loader.cpp
std::stringstream stream;
stream << "ResourceLoader<Material>::load(): Invalid variable on line " << lineNumber << ".";
throw std::runtime_error(stream.str().c_str());
=======
std::cerr << std::string("MaterialLoader::load(): Invalid variable on line ") << lineNumber << std::string(" in \"") << filename << std::string("\"") << std::endl;
continue;
>>>>>>> df8405f4e83febb81a5ce8f772bd7f5b9e9b6036:src/material-loader.cpp
}
// Find position of equals sign
@ -339,14 +312,9 @@ Material* ResourceLoader::load(ResourceManager* resourceManager, std::
if (equalsSignPosition == std::string::npos)
{
// Skip lines with no equals sign
<<<<<<< HEAD:src/resources/material-loader.cpp
std::stringstream stream;
stream << "ResourceLoader<Material>::load(): Invalid variable on line " << lineNumber << ".";
throw std::runtime_error(stream.str().c_str());
=======
std::cerr << std::string("MaterialLoader::load(): Invalid variable on line ") << lineNumber << std::string(" in \"") << filename << std::string("\"") << std::endl;
continue;
>>>>>>> df8405f4e83febb81a5ce8f772bd7f5b9e9b6036:src/material-loader.cpp
}
// Find position of first character in variable type
@ -354,14 +322,9 @@ Material* ResourceLoader::load(ResourceManager* resourceManager, std::
if (variableTypePosition == std::string::npos)
{
// Skip lines with no variable type definition
<<<<<<< HEAD:src/resources/material-loader.cpp
std::stringstream stream;
stream << "ResourceLoader<Material>::load(): Invalid variable on line " << lineNumber << ".";
throw std::runtime_error(stream.str().c_str());
=======
std::cerr << std::string("MaterialLoader::load(): Invalid variable on line ") << lineNumber << std::string(" in \"") << filename << std::string("\"") << std::endl;
continue;
>>>>>>> df8405f4e83febb81a5ce8f772bd7f5b9e9b6036:src/material-loader.cpp
}
// Count parentheses
@ -370,14 +333,9 @@ Material* ResourceLoader::load(ResourceManager* resourceManager, std::
if (leftParenthesisCount != rightParenthesisCount || leftParenthesisCount == 0)
{
// Skip lines with invalid number of parentheses
<<<<<<< HEAD:src/resources/material-loader.cpp
std::stringstream stream;
stream << "ResourceLoader<Material>::load(): Invalid variable on line " << lineNumber << ".";
throw std::runtime_error(stream.str().c_str());
=======
std::cerr << std::string("MaterialLoader::load(): Invalid variable on line ") << lineNumber << std::string(" in \"") << filename << std::string("\"") << std::endl;
continue;
>>>>>>> df8405f4e83febb81a5ce8f772bd7f5b9e9b6036:src/material-loader.cpp
}
std::string variableName = line.substr(variableNamePosition, line.find_first_of(" \t=", variableNamePosition) - variableNamePosition);
@ -495,273 +453,12 @@ Material* ResourceLoader::load(ResourceManager* resourceManager, std::
}
// Invalid command
<<<<<<< HEAD:src/resources/material-loader.cpp
std::stringstream stream;
stream << "ResourceLoader<Material>::load(): Invalid command \"" << command << "\" on line " << lineNumber << ".";
throw std::runtime_error(stream.str().c_str());
=======
std::cerr << std::string("MaterialLoader::load(): Invalid command \"") << command << std::string("\" on line ") << lineNumber << std::string(" in \"") << filename << std::string("\"") << std::endl;
}
}
// Close file
file.close();
// Add material to cache
materialCache[filename] = material;
return material;
}
Shader* MaterialLoader::loadShader(const std::string& filename)
{
auto it = shaderCache.find(filename);
if (it != shaderCache.end())
{
return it->second;
}
std::string fullFilename = std::string("data/shaders/") + filename;
std::cout << std::string("Loading shader \"") << fullFilename << std::string("\"\n");
// Load shader
Shader* shader = new Shader();
if (!shader->loadSource(fullFilename))
{
delete shader;
return nullptr;
}
// Add shader to cache
shaderCache[filename] = shader;
return shader;
}
Texture2D* MaterialLoader::loadTexture2D(const std::string& filename)
{
// Check if texture exists in cache
auto it = texture2DCache.find(filename);
if (it != texture2DCache.end())
{
return it->second;
}
std::string fullFilename = std::string("data/textures/") + filename;
// Load texture
Texture2D* texture = textureLoader.load2D(fullFilename);
if (!texture)
{
std::cerr << std::string("MaterialLoader::loadTexture2D(): Failed to load texture file \"") << fullFilename << std::string("\"") << std::endl;
return nullptr;
}
// Add texture to cache
texture2DCache[filename] = texture;
return texture;
}
TextureCube* MaterialLoader::loadTextureCube(const std::string& filename)
{
// Check if texture exists in cache
auto it = textureCubeCache.find(filename);
if (it != textureCubeCache.end())
{
return it->second;
}
std::string fullFilename = std::string("data/textures/") + filename;
// Load texture
TextureCube* texture = textureLoader.loadCube(fullFilename);
if (!texture)
{
std::cerr << std::string("MaterialLoader::loadTextureCube(): Failed to load texture file \"") << fullFilename << std::string("\"") << std::endl;
return nullptr;
}
// Add texture to cache
textureCubeCache[filename] = texture;
return texture;
}
bool MaterialLoader::loadShaderInt(ShaderInt* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
int value;
std::stringstream stream;
stream << elements[i][0];
stream >> value;
variable->setValue(i, value);
}
return true;
}
bool MaterialLoader::loadShaderFloat(ShaderFloat* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
float value;
std::stringstream stream;
stream << elements[i][0];
stream >> value;
variable->setValue(i, value);
}
return true;
}
bool MaterialLoader::loadShaderVector2(ShaderVector2* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
Vector2 value;
for (int j = 0; j < 2; ++j)
{
std::stringstream stream;
stream << elements[i][j];
stream >> value[j];
}
variable->setValue(i, value);
}
return true;
}
bool MaterialLoader::loadShaderVector3(ShaderVector3* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
Vector3 value;
for (int j = 0; j < 3; ++j)
{
std::stringstream stream;
stream << elements[i][j];
stream >> value[j];
}
variable->setValue(i, value);
}
return true;
}
bool MaterialLoader::loadShaderVector4(ShaderVector4* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
Vector4 value;
for (int j = 0; j < 4; ++j)
{
std::stringstream stream;
stream << elements[i][j];
stream >> value[j];
}
variable->setValue(i, value);
}
return true;
}
bool MaterialLoader::loadShaderMatrix3(ShaderMatrix3* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
Matrix3 value;
for (int j = 0; j < 3; ++j)
{
for (int k = 0; k < 3; ++k)
{
std::stringstream stream;
stream << elements[i][k * 3 + j];
stream >> value[j][k];
}
}
variable->setValue(i, value);
}
return true;
}
bool MaterialLoader::loadShaderMatrix4(ShaderMatrix4* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
Matrix4 value;
for (int j = 0; j < 4; ++j)
{
for (int k = 0; k < 4; ++k)
{
std::stringstream stream;
stream << elements[i][k * 4 + j];
stream >> value[j][k];
}
}
variable->setValue(i, value);
}
return true;
}
bool MaterialLoader::loadShaderTexture2D(ShaderTexture2D* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
std::string filename;
std::stringstream stream;
stream << elements[i][0];
stream >> filename;
Texture2D* value = loadTexture2D(filename);
if (!value)
{
std::cerr << std::string("MaterialLoader::loadShaderTexture2D(): Failed to load 2D texture \"") << filename << std::string("\"") << std::endl;
return false;
>>>>>>> df8405f4e83febb81a5ce8f772bd7f5b9e9b6036:src/material-loader.cpp
}
}
return material;
}
<<<<<<< HEAD:src/resources/material-loader.cpp
=======
bool MaterialLoader::loadShaderTextureCube(ShaderTextureCube* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
std::string filename;
std::stringstream stream;
stream << elements[i][0];
stream >> filename;
TextureCube* value = loadTextureCube(filename);
if (!value)
{
std::cerr << std::string("MaterialLoader::loadShaderTextureCube(): Failed to load cube texture \"") << filename << std::string("\"") << std::endl;
return false;
}
variable->setValue(i, value);
}
return true;
}
>>>>>>> df8405f4e83febb81a5ce8f772bd7f5b9e9b6036:src/material-loader.cpp

+ 0
- 28
src/resources/model-loader.cpp View File

@ -148,17 +148,6 @@ inline static void readString(std::string* result, unsigned char** data)
template <>
Model* ResourceLoader<Model>::load(ResourceManager* resourceManager, std::istream* is)
{
<<<<<<< HEAD:src/resources/model-loader.cpp
=======
// Open file
std::ifstream file(filename.c_str(), std::ifstream::in | std::ifstream::binary | std::ifstream::ate);
if (!file.is_open())
{
std::cerr << std::string("ModelLoader::load(): Failed to open model file \"") << filename << std::string("\"") << std::endl;
return nullptr;
}
>>>>>>> df8405f4e83febb81a5ce8f772bd7f5b9e9b6036:src/model-loader.cpp
// Allocate file data buffer
is->seekg(0, is->end);
int filesize = is->tellg();
@ -512,25 +501,8 @@ Model* ResourceLoader::load(ResourceManager* resourceManager, std::istrea
modelGroup->name = modelDataGroup->materialName;
// Load material
<<<<<<< HEAD:src/resources/model-loader.cpp
std::string materialFilename = modelDataGroup->materialName + std::string(".mtl");
modelGroup->material = resourceManager->load<Material>(materialFilename);
=======
std::string materialFilename = std::string("data/materials/") + modelDataGroup->materialName + std::string(".mtl");
if (materialLoader != nullptr)
{
modelGroup->material = materialLoader->load(materialFilename);
if (!modelGroup->material)
{
std::cerr << std::string("ModelLoader::load(): Failed to load material file \"") << materialFilename << std::string("\" for model file \"") << filename << std::string("\"") << std::endl;
}
}
else
{
modelGroup->material = nullptr;
std::cerr << std::string("ModelLoader::load(): No valid material loader, material file \"") << materialFilename << std::string("\" not loaded") << std::endl;
}
>>>>>>> df8405f4e83febb81a5ce8f772bd7f5b9e9b6036:src/model-loader.cpp
// Setup model group geometry
modelGroup->indexOffset = modelDataGroup->indexOffset;

+ 0
- 92
src/settings.cpp View File

@ -1,92 +0,0 @@
/*
* Copyright (C) 2017 Christopher J. Howard
*
* This file is part of Antkeeper Source Code.
*
* Antkeeper Source Code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper Source Code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "settings.hpp"
#include <fstream>
#include <sstream>
#include <vector>
#include <iostream>
bool ParameterDict::load(const std::string& filename)
{
// Open parameter dict file
std::ifstream file(filename.c_str());
if (!file.is_open())
{
std::cerr << std::string("Failed to open file \"") << filename << std::string("\"") << std::endl;
return false;
}
// Read file
std::string line;
std::size_t lineNumber = 0;
while (file.good() && std::getline(file, line))
{
++lineNumber;
if (!line.empty() && line[line.size() - 1] == '\r')
{
line = line.substr(0, line.size() - 1);
}
// Tokenize line (tab-delimeted)
std::vector<std::string> tokens;
std::string token;
std::istringstream linestream(line);
while (std::getline(linestream, token, '\t'))
tokens.push_back(token);
if (tokens.empty() || tokens[0][0] == '#')
continue;
if (tokens.size() != 2)
{
std::cerr << std::string("Invalid line \"") << lineNumber << std::string("\" in file \"") << filename << std::string("\"") << std::endl;
continue;
}
parameters[tokens[0]] = tokens[1];
}
file.close();
return true;
}
bool ParameterDict::save(const std::string& filename)
{
std::ofstream file(filename.c_str());
if (!file.is_open())
{
std::cerr << std::string("Failed to open file \"") << filename << std::string("\"") << std::endl;
return false;
}
for (auto it = parameters.begin(); it != parameters.end(); ++it)
file << it->first << std::string("\t") << it->second << std::endl;
file.close();
return true;
}
void ParameterDict::clear()
{
parameters.clear();
}

+ 0
- 128
src/states/loading-state.cpp View File

@ -1,128 +0,0 @@
/*
* Copyright (C) 2017 Christopher J. Howard
*
* This file is part of Antkeeper Source Code.
*
* Antkeeper Source Code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper Source Code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "loading-state.hpp"
#include "../application.hpp"
#include "splash-state.hpp"
#include "title-state.hpp"
LoadingState::LoadingState(Application* application):
ApplicationState(application)
{}
LoadingState::~LoadingState()
{}
void LoadingState::enter()
{
bool failure = false;
std::cout << std::string("Loading controls... ");
if (!application->loadControls())
{
std::cout << std::string("failed") << std::endl;
failure = true;
}
else
{
std::cout << std::string("success") << std::endl;
}
std::cout << std::string("Loading scene... ");
if (!application->loadScene())
{
std::cout << std::string("failed") << std::endl;
failure = true;
}
else
{
std::cout << std::string("success") << std::endl;
}
std::cout << std::string("Loading models... ");
if (!application->loadModels())
{
std::cout << std::string("failed") << std::endl;
failure = true;
}
else
{
std::cout << std::string("success") << std::endl;
}
std::cout << std::string("Loading game... ");
if (!application->loadGame())
{
std::cout << std::string("failed") << std::endl;
failure = true;
}
else
{
std::cout << std::string("success") << std::endl;
}
std::cout << std::string("Loading UI... ");
if (!application->loadUI())
{
std::cout << std::string("failed") << std::endl;
failure = true;
}
else
{
std::cout << std::string("success") << std::endl;
}
if (failure)
{
application->close(EXIT_FAILURE);
}
application->splashBackgroundImage->setVisible(true);
}
void LoadingState::execute()
{
// Check for splash screen and title skip settings
bool skipSplash = false;
bool skipTitle = false;
application->settings.get("skip_splash", &skipSplash);
//application->settings.get("skip_title", &skipTitle);
// Determine next state
ApplicationState* nextState = application->splashState;
if (skipSplash)
{
nextState = application->titleState;
/*
if (skipTitle)
{
nextState = application->mainMenuState;
}
*/
}
// Change state
application->changeState(nextState);
}
void LoadingState::exit()
{
application->splashBackgroundImage->setVisible(false);
}

Loading…
Cancel
Save