Browse Source

Add SDL library source and improve build system

master
C. J. Howard 7 years ago
parent
commit
e2f474ddf6
26 changed files with 410 additions and 311 deletions
  1. +0
    -1
      .gitignore
  2. +165
    -28
      CMakeLists.txt
  3. +33
    -27
      README.md
  4. +3
    -0
      bin/.gitignore
  5. +3
    -0
      build/linux32/.gitignore
  6. +3
    -0
      build/linux64/.gitignore
  7. +3
    -0
      build/win32/.gitignore
  8. +3
    -0
      build/win64/.gitignore
  9. +0
    -35
      cmake/modules/FindFreetype2.cmake
  10. +0
    -50
      cmake/modules/FindSDL2.cmake
  11. +1
    -1
      data
  12. +3
    -0
      dist/.gitignore
  13. +1
    -1
      lib/emergent
  14. +117
    -118
      src/application.cpp
  15. +19
    -18
      src/game/navmesh.cpp
  16. +9
    -5
      src/game/nest.cpp
  17. +2
    -2
      src/game/nest.hpp
  18. +2
    -0
      src/game/tool.cpp
  19. +24
    -9
      src/game/tool.hpp
  20. +1
    -1
      src/input.hpp
  21. +3
    -2
      src/mesh.cpp
  22. +1
    -1
      src/states/title-state.cpp
  23. +5
    -5
      src/ui/pie-menu.cpp
  24. +6
    -5
      src/ui/toolbar.cpp
  25. +2
    -1
      src/ui/tween.hpp
  26. +1
    -1
      src/ui/ui.cpp

+ 0
- 1
.gitignore View File

@ -2,6 +2,5 @@ CMakeFiles
CMakeCache.txt
cmake_install.cmake
Makefile
build
src/configuration.hpp
.DS_Store

+ 165
- 28
CMakeLists.txt View File

@ -3,9 +3,23 @@ project(antkeeper
VERSION "0.0.0"
)
set(PLATFORM "" CACHE STRING "")
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})
@ -20,7 +34,7 @@ else()
endif()
# Setup build type paths
set(BUILD_DIR ${PROJECT_SOURCE_DIR}/build)
set(BUILD_DIR ${PROJECT_SOURCE_DIR}/bin)
set(BUILD_DEBUG_DIR ${BUILD_DIR}/debug)
set(BUILD_RELEASE_DIR ${BUILD_DIR}/release)
@ -35,19 +49,15 @@ else()
set(PLATFORM_PACKAGE_DIR ${BUILD_RELEASE_DIR}/${PACKAGE_NAME})
endif()
# Add Emergent library
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/emergent)
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${PROJECT_SOURCE_DIR}/lib/emergent)
# Find dependencies
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
find_package(SDL2 REQUIRED)
find_package(OpenGL REQUIRED)
# Set C++ compiler flags for debug and release build types
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 -mwindows")
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")
@ -67,11 +77,84 @@ elseif(${PLATFORM} STREQUAL "osx" AND CMAKE_OSX_ARCHITECTURES STREQUAL "")
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}
dinput8
dxguid
user32
gdi32
winmm
imm32
ole32
oleaut32
shell32
version
uuid
)
ExternalProject_Add(SDL2-project
SOURCE_DIR ${PROJECT_SOURCE_DIR}/lib/SDL2-2.0.5
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})
# Find OpenGL
find_package(OpenGL REQUIRED)
# Find executable source directory
set(EXECUTABLE_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
@ -149,13 +232,18 @@ set(EXECUTABLE_SOURCES
if(${PLATFORM} STREQUAL "win32" OR ${PLATFORM} STREQUAL "win64")
if(EXISTS ${PROJECT_SOURCE_DIR}/data)
set(RC_FILES "${PROJECT_SOURCE_DIR}/data/icons/icon.rc")
set(CMAKE_RC_COMPILER_INIT windres)
enable_language(RC)
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
#set(CMAKE_RC_COMPILER_INIT windres)
#enable_language(RC)
#set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <SOURCE> <OBJECT>")
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})
@ -164,27 +252,24 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PLATFORM_PACKAGE_DIR})
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)
set_target_properties(${EXECUTABLE_TARGET} PROPERTIES OUTPUT_NAME ${EXECUTABLE_NAME})
# Set include directories
target_include_directories(${EXECUTABLE_TARGET} PUBLIC
${PROJECT_SOURCE_DIR}/lib/emergent/include
${SDL2_INCLUDE_DIRS}
${EMERGENT_INCLUDE_DIRS}
${SDL2_INCLUDE_DIR}
${OPENGL_INCLUDE_DIRS}
)
message("SDL: ${SDL2_LIBRARIES}")
# Build library list
list(APPEND EXECUTABLE_LIBRARIES
m
#dl
mingw32
#PROBLEM IS LINKING TO STDC++!!!!!!!!!!!!!!!!
#stdc++
emergent
${SDL2_LIBRARIES}
${EMERGENT_LIBRARIES}
${OPENGL_gl_LIBRARY}
${FREETYPE_LIBRARY}
#m
#stdc++
)
# Link libraries
@ -197,7 +282,59 @@ add_custom_target(run
WORKING_DIRECTORY ${PLATFORM_PACKAGE_DIR}
)
# 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()
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)

+ 33
- 27
README.md View File

@ -2,57 +2,63 @@
Antkeeper is an ant colony simulation game. This repository contains all of the source code to Antkeeper. The game data, however, is proprietary and resides in a closed-source Git submodule.
## Getting Started
## Download
### Prerequisites
Use Git to download the `antkeeper` repository and its submodules:
* Git
* CMake
* SDL 2
* FreeType 2
git clone --recursive https://github.com/cjhoward/antkeeper.git antkeeper
### Download
## Configuration & Building
Use Git to download the `antkeeper` repository and its submodules:
CMake is required to configure and build the application. Depending on the target build platform, CMake should be invoked from one of the following directories:
git clone --recursive https://github.com/cjhoward/antkeeper.git antkeeper
build/linux32 // 32-bit GNU/Linux application
build/linux64 // 64-bit GNU/Linux application
build/win32 // 32-bit Windows application
build/win64 // 64-bit Windows application
### Configuration
The following arguments may be passed to CMake during configuration:
Antkeeper uses the CMake build system for configuration.
-DCMAKE_BUILD_TYPE // [Debug, Release]
-DPLATFORM // [linux32, linux64, win32, win64]
-DLANGUAGE // [en-us, zh-cn]
-DSTANDALONE // [OFF, ON]
cd antkeeper
cmake . -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DPLATFORM=win32 -DLANGUAGE=en-us
### GNU/Linux
### Building
Building on GNU/Linux requires CMake, GCC, G++, and GNU Make. Open a terminal in the project root directory and run the following commands:
cd build/linux64
cmake ../.. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=...
cmake --build .
## Workflow
### Windows
### Making Changes
Building on Windows requires CMake and Visual Studio 2017. Additionally, [NSIS](http://nsis.sourceforge.net/) is required if you want to build a distributable installer program. In order to correctly build for your target architecture, you must use the `x86 Native Tools Command Prompt` or the `x64 Native Tools Command Prompt` for 32-bit and 64-bit applications, respectively. Then navigate to the project root directory and run the following commands:
If any changes have been made to the submodules, commit those first. Each submodule can then be updated to their latest commits with the following command:
cd build/win64
cmake ..\.. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=...
cmake --build .
git submodule update --recursive --remote
## Testing
### Testing
After building, a standalone version of the application will be located somewhere in the `bin` directory, according to the build type, build platform, and version string. This application can be executed with the following command:
cmake --build . --target run
### Cleaning
First perform a dry run to check what will be deleted:
## Distribution
git clean -d -f -x -n
If there are no issues, clean:
The built application can be packaged into a distributable format with the following command:
git clean -d -f -x
cmake --build . --target package
### Shipping
The resulting package will be located in the `dist` directory.
## Contributing
If any changes have been made to the submodules, commit those first. Each submodule can then be updated to their latest commits with the following command:
git submodule update --recursive --remote
## License

+ 3
- 0
bin/.gitignore View File

@ -0,0 +1,3 @@
*
*/*
!.gitignore

+ 3
- 0
build/linux32/.gitignore View File

@ -0,0 +1,3 @@
*
*/*
!.gitignore

+ 3
- 0
build/linux64/.gitignore View File

@ -0,0 +1,3 @@
*
*/*
!.gitignore

+ 3
- 0
build/win32/.gitignore View File

@ -0,0 +1,3 @@
*
*/*
!.gitignore

+ 3
- 0
build/win64/.gitignore View File

@ -0,0 +1,3 @@
*
*/*
!.gitignore

+ 0
- 35
cmake/modules/FindFreetype2.cmake View File

@ -1,35 +0,0 @@
# - Try to find FREETYPE2
# This module defines
# FREETYPE2_FOUND - System has FREETYPE2
# FREETYPE2_INCLUDE_DIRS - The FREETYPE2 include directories
# FREETYPE2_LIBRARIES - Link to these to use FREETYPE2
# Copyright (C) 2011-2014 Christopher J. Howard
#
# This file is part of Open Graphics Framework (OGF).
#
# OGF 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.
#
# OGF 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 OGF. If not, see <http://www.gnu.org/licenses/>.
find_path(FREETYPE2_INCLUDE_DIR ft2build.h PATH_SUFFIXES include/freetype2 include)
find_library(FREETYPE2_LIBRARY NAMES freetype)
set(FREETYPE2_LIBRARIES ${FREETYPE2_LIBRARY})
set(FREETYPE2_INCLUDE_DIRS ${FREETYPE2_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
FREETYPE2 DEFAULT_MSG
FREETYPE2_LIBRARY FREETYPE2_INCLUDE_DIR)
mark_as_advanced(FREETYPE2_INCLUDE_DIR FREETYPE2_LIBRARY)

+ 0
- 50
cmake/modules/FindSDL2.cmake View File

@ -1,50 +0,0 @@
# - Try to find SDL2
# This module defines
# SDL2_FOUND - System has SDL2
# SDL2_INCLUDE_DIRS - The SDL2 include directories
# SDL2_LIBRARIES - Link to these to use SDL2
# Copyright (C) 2011-2014 Christopher J. Howard
#
# This file is part of Open Graphics Framework (OGF).
#
# OGF 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.
#
# OGF 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 OGF. If not, see <http://www.gnu.org/licenses/>.
set(SDL2_SEARCH_PATHS
/)
find_path(SDL2_INCLUDE_DIR SDL.h
NAMES SDL2
PATH_SUFFIXES include/SDL2 include
PATHS ${SDL2_SEARCH_PATHS})
find_library(SDL2MAIN_LIBRARY
NAMES SDL2main
PATH_SUFFIXES lib64 lib
PATHS ${SDL2_SEARCH_PATHS})
find_library(SDL2_LIBRARY
NAMES SDL2
PATH_SUFFIXES lib64 lib
PATHS ${SDL2_SEARCH_PATHS})
set(SDL2_LIBRARIES ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY})
set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
SDL2 DEFAULT_MSG
SDL2_LIBRARY SDL2MAIN_LIBRARY SDL2_INCLUDE_DIR)
mark_as_advanced(SDL2_INCLUDE_DIR SDL2_LIBRARY SDL2MAIN_LIBRARY)

+ 1
- 1
data

@ -1 +1 @@
Subproject commit 38fc778db84b0fd8c176c828a54fbf7145b948e1
Subproject commit e0a75c9bb2940afb120e9536671b0f94d266e00f

+ 3
- 0
dist/.gitignore View File

@ -0,0 +1,3 @@
*
*/*
!.gitignore

+ 1
- 1
lib/emergent

@ -1 +1 @@
Subproject commit fbeb27d70b08fc64543ccf6cfcd0c7c67399e358
Subproject commit f8ca6783fb2933716312ec411d39eb202d3dac9c

+ 117
- 118
src/application.cpp View File

@ -31,11 +31,12 @@
#include "ui/pie-menu.hpp"
#include "debug.hpp"
#include "camera-controller.hpp"
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <SDL.h>
#include <SDL2/SDL.h>
#define OPENGL_VERSION_MAJOR 3
#define OPENGL_VERSION_MINOR 3
@ -368,7 +369,7 @@ int Application::execute()
frameTimer.reset();
// Add frame time (in seconds) to accumulator
accumulator += std::min(frameTime / 1000.0f, maxFrameTime);
accumulator += std::min<float>(frameTime / 1000.0f, maxFrameTime);
// If the user tried to close the application
if (inputManager->wasClosed() || escape.isTriggered())
@ -413,8 +414,6 @@ int Application::execute()
}
}
// Update input
inputManager->update();
@ -649,7 +648,7 @@ bool Application::loadScene()
// Setup debug pass
debugPass.setRenderTarget(&defaultRenderTarget);
defaultCompositor.addPass(&debugPass);
//defaultCompositor.addPass(&debugPass);
// Load compositor
@ -1064,10 +1063,10 @@ bool Application::loadUI()
toolbar->setToolbarMiddleTexture(toolbarMiddleTexture);
toolbar->setButtonRaisedTexture(toolbarButtonRaisedTexture);
toolbar->setButtonDepressedTexture(toolbarButtonDepressedTexture);
toolbar->addButton(toolBrushTexture, std::bind(std::printf, "0\n"), std::bind(std::printf, "0\n"));
toolbar->addButton(toolLensTexture, std::bind(std::printf, "1\n"), std::bind(std::printf, "1\n"));
toolbar->addButton(toolForcepsTexture, std::bind(SceneObject::setActive, &forcepsModelInstance, true), std::bind(SceneObject::setActive, &forcepsModelInstance, false));
toolbar->addButton(toolTrowelTexture, std::bind(std::printf, "3\n"), std::bind(std::printf, "3\n"));
toolbar->addButton(toolBrushTexture, std::bind(&std::printf, "0\n"), std::bind(&std::printf, "0\n"));
toolbar->addButton(toolLensTexture, std::bind(&std::printf, "1\n"), std::bind(&std::printf, "1\n"));
toolbar->addButton(toolForcepsTexture, std::bind(&SceneObject::setActive, &forcepsModelInstance, true), std::bind(&SceneObject::setActive, &forcepsModelInstance, false));
toolbar->addButton(toolTrowelTexture, std::bind(&std::printf, "3\n"), std::bind(&std::printf, "3\n"));
toolbar->resize();
//uiRootElement->addChild(toolbar->getContainer());
toolbar->getContainer()->setVisible(false);
@ -1075,10 +1074,10 @@ bool Application::loadUI()
// Create pie menu
pieMenu = new PieMenu(tweener);
pieMenu->addOption(arcNorthTexture, toolLensTexture, std::bind(std::printf, "0 on\n"), std::bind(std::printf, "0 off\n"));
pieMenu->addOption(arcEastTexture, toolForcepsTexture, std::bind(std::printf, "1 on\n"), std::bind(std::printf, "1 off\n"));
pieMenu->addOption(arcSouthTexture, toolTrowelTexture, std::bind(std::printf, "2 on\n"), std::bind(std::printf, "2 off\n"));
pieMenu->addOption(arcWestTexture, toolBrushTexture, std::bind(std::printf, "3 on\n"), std::bind(std::printf, "3 off\n"));
pieMenu->addOption(arcNorthTexture, toolLensTexture, std::bind(&std::printf, "0 on\n"), std::bind(&std::printf, "0 off\n"));
pieMenu->addOption(arcEastTexture, toolForcepsTexture, std::bind(&std::printf, "1 on\n"), std::bind(&std::printf, "1 off\n"));
pieMenu->addOption(arcSouthTexture, toolTrowelTexture, std::bind(&std::printf, "2 on\n"), std::bind(&std::printf, "2 off\n"));
pieMenu->addOption(arcWestTexture, toolBrushTexture, std::bind(&std::printf, "3 on\n"), std::bind(&std::printf, "3 off\n"));
uiRootElement->addChild(pieMenu->getContainer());
pieMenu->resize();
pieMenu->getContainer()->setVisible(false);
@ -1088,52 +1087,52 @@ bool Application::loadUI()
// Setup screen fade in/fade out tween
fadeInTween = new Tween<Vector4>(EaseFunction::IN_CUBIC, 0.0f, 1.5f, Vector4(0.0f, 0.0f, 0.0f, 1.0f), Vector4(0.0f, 0.0f, 0.0f, -1.0f));
fadeInTween->setUpdateCallback(std::bind(UIElement::setTintColor, blackoutImage, std::placeholders::_1));
fadeInTween->setUpdateCallback(std::bind(&UIElement::setTintColor, blackoutImage, std::placeholders::_1));
tweener->addTween(fadeInTween);
fadeOutTween = new Tween<Vector4>(EaseFunction::OUT_CUBIC, 0.0f, 1.5f, Vector4(0.0f, 0.0f, 0.0f, 0.0f), Vector4(0.0f, 0.0f, 0.0f, 1.0f));
fadeOutTween->setUpdateCallback(std::bind(UIElement::setTintColor, blackoutImage, std::placeholders::_1));
fadeOutTween->setUpdateCallback(std::bind(&UIElement::setTintColor, blackoutImage, std::placeholders::_1));
tweener->addTween(fadeOutTween);
// Setup splash screen tween
splashFadeInTween = new Tween<Vector4>(EaseFunction::IN_CUBIC, 0.0f, 0.5f, Vector4(1.0f, 1.0f, 1.0f, 0.0f), Vector4(0.0f, 0.0f, 0.0f, 1.0f));
splashFadeInTween->setUpdateCallback(std::bind(UIElement::setTintColor, splashImage, std::placeholders::_1));
splashFadeInTween->setUpdateCallback(std::bind(&UIElement::setTintColor, splashImage, std::placeholders::_1));
tweener->addTween(splashFadeInTween);
splashHangTween = new Tween<float>(EaseFunction::OUT_CUBIC, 0.0f, 1.0f, 0.0f, 1.0f);
tweener->addTween(splashHangTween);
splashFadeOutTween = new Tween<Vector4>(EaseFunction::OUT_CUBIC, 0.0f, 0.5f, Vector4(1.0f, 1.0f, 1.0f, 1.0f), Vector4(0.0f, 0.0f, 0.0f, -1.0f));
splashFadeOutTween->setUpdateCallback(std::bind(UIElement::setTintColor, splashImage, std::placeholders::_1));
splashFadeOutTween->setUpdateCallback(std::bind(&UIElement::setTintColor, splashImage, std::placeholders::_1));
tweener->addTween(splashFadeOutTween);
splashFadeInTween->setEndCallback(std::bind(TweenBase::start, splashHangTween));
splashHangTween->setEndCallback(std::bind(TweenBase::start, splashFadeOutTween));
splashFadeOutTween->setEndCallback(std::bind(Application::changeState, this, titleState));
splashFadeInTween->setEndCallback(std::bind(&TweenBase::start, splashHangTween));
splashHangTween->setEndCallback(std::bind(&TweenBase::start, splashFadeOutTween));
splashFadeOutTween->setEndCallback(std::bind(&Application::changeState, this, titleState));
// Setup game title tween
titleFadeInTween = new Tween<Vector4>(EaseFunction::IN_CUBIC, 0.0f, 2.0f, Vector4(1.0f, 1.0f, 1.0f, 0.0f), Vector4(0.0f, 0.0f, 0.0f, 1.0f));
titleFadeInTween->setUpdateCallback(std::bind(UIElement::setTintColor, titleImage, std::placeholders::_1));
titleFadeInTween->setUpdateCallback(std::bind(&UIElement::setTintColor, titleImage, std::placeholders::_1));
tweener->addTween(titleFadeInTween);
titleFadeOutTween = new Tween<Vector4>(EaseFunction::OUT_CUBIC, 0.0f, 0.25f, Vector4(1.0f, 1.0f, 1.0f, 1.0f), Vector4(0.0f, 0.0f, 0.0f, -1.0f));
titleFadeOutTween->setUpdateCallback(std::bind(UIElement::setTintColor, titleImage, std::placeholders::_1));
titleFadeOutTween->setUpdateCallback(std::bind(&UIElement::setTintColor, titleImage, std::placeholders::_1));
tweener->addTween(titleFadeOutTween);
// Setup copyright tween
copyrightFadeInTween = new Tween<Vector4>(EaseFunction::IN_CUBIC, 0.0f, 1.0f, Vector4(0.0f, 0.0f, 0.0f, 0.0f), Vector4(0.0f, 0.0f, 0.0f, 0.5f));
copyrightFadeInTween->setUpdateCallback(std::bind(UIElement::setTintColor, titleScreenInfoContainer, std::placeholders::_1));
copyrightFadeInTween->setUpdateCallback(std::bind(&UIElement::setTintColor, titleScreenInfoContainer, std::placeholders::_1));
tweener->addTween(copyrightFadeInTween);
copyrightFadeOutTween = new Tween<Vector4>(EaseFunction::OUT_CUBIC, 0.0f, 0.25f, Vector4(0.0f, 0.0f, 0.0f, 0.5f), Vector4(0.0f, 0.0f, 0.0f, -0.5f));
copyrightFadeOutTween->setUpdateCallback(std::bind(UIElement::setTintColor, titleScreenInfoContainer, std::placeholders::_1));
copyrightFadeOutTween->setUpdateCallback(std::bind(&UIElement::setTintColor, titleScreenInfoContainer, std::placeholders::_1));
tweener->addTween(copyrightFadeOutTween);
// Setup "Press any key" tween
anyKeyFadeInTween = new Tween<Vector4>(EaseFunction::LINEAR, 0.0f, 1.5f, Vector4(0.0f, 0.0f, 0.0f, 0.0f), Vector4(0.0f, 0.0f, 0.0f, 1.0f));
anyKeyFadeInTween->setUpdateCallback(std::bind(UIElement::setTintColor, anyKeyLabel, std::placeholders::_1));
anyKeyFadeInTween->setUpdateCallback(std::bind(&UIElement::setTintColor, anyKeyLabel, std::placeholders::_1));
tweener->addTween(anyKeyFadeInTween);
anyKeyFadeOutTween = new Tween<Vector4>(EaseFunction::LINEAR, 0.0f, 1.5f, Vector4(0.0f, 0.0f, 0.0f, 1.0f), Vector4(0.0f, 0.0f, 0.0f, -1.0f));
anyKeyFadeOutTween->setUpdateCallback(std::bind(UIElement::setTintColor, anyKeyLabel, std::placeholders::_1));
anyKeyFadeInTween->setEndCallback(std::bind(TweenBase::start, anyKeyFadeOutTween));
anyKeyFadeOutTween->setEndCallback(std::bind(TweenBase::start, anyKeyFadeInTween));
anyKeyFadeOutTween->setUpdateCallback(std::bind(&UIElement::setTintColor, anyKeyLabel, std::placeholders::_1));
anyKeyFadeInTween->setEndCallback(std::bind(&TweenBase::start, anyKeyFadeOutTween));
anyKeyFadeOutTween->setEndCallback(std::bind(&TweenBase::start, anyKeyFadeInTween));
tweener->addTween(anyKeyFadeOutTween);
float menuFadeInDuration = 0.15f;
@ -1164,110 +1163,110 @@ bool Application::loadUI()
// Title screen zoom in tween
antHillZoomInTween = new Tween<float>(EaseFunction::LINEAR, 0.0f, 2.0f, 50.0f, -49.9f);
antHillZoomInTween->setUpdateCallback(std::bind(SurfaceCameraController::setTargetFocalDistance, surfaceCam, std::placeholders::_1));
antHillZoomInTween->setUpdateCallback(std::bind(&SurfaceCameraController::setTargetFocalDistance, surfaceCam, std::placeholders::_1));
tweener->addTween(antHillZoomInTween);
antHillFadeOutTween = new Tween<Vector4>(EaseFunction::IN_CUBIC, 0.0f, 2.0f, Vector4(0.0f, 0.0f, 0.0f, 0.0f), Vector4(0.0f, 0.0f, 0.0f, 1.0f));
antHillFadeOutTween->setUpdateCallback(std::bind(UIElement::setTintColor, blackoutImage, std::placeholders::_1));
antHillFadeOutTween->setEndCallback(std::bind(Application::changeState, this, mainMenuState));
antHillFadeOutTween->setUpdateCallback(std::bind(&UIElement::setTintColor, blackoutImage, std::placeholders::_1));
antHillFadeOutTween->setEndCallback(std::bind(&Application::changeState, this, mainMenuState));
tweener->addTween(antHillFadeOutTween);
playButtonFadeTween = new Tween<Vector4>(EaseFunction::OUT_CUBIC, 0.0f, 1.0f, Vector4(1.0f, 1.0f, 1.0f, 1.0f), Vector4(0.0f, 0.0f, 0.0f, -1.0f));
playButtonFadeTween->setUpdateCallback(std::bind(UIElement::setTintColor, playButtonImage, std::placeholders::_1));
playButtonFadeTween->setEndCallback(std::bind(UIElement::setVisible, playButtonImage, false));
playButtonFadeTween->setUpdateCallback(std::bind(&UIElement::setTintColor, playButtonImage, std::placeholders::_1));
playButtonFadeTween->setEndCallback(std::bind(&UIElement::setVisible, playButtonImage, false));
tweener->addTween(playButtonFadeTween);
// Build menu system
selectedMenuItemIndex = 0;
mainMenu = new Menu();
MenuItem* challengeItem = mainMenu->addItem();
challengeItem->setSelectedCallback(std::bind(UIElement::setTintColor, challengeLabel, selectedColor));
challengeItem->setDeselectedCallback(std::bind(UIElement::setTintColor, challengeLabel, deselectedColor));
challengeItem->setActivatedCallback(std::bind(Application::enterLevelSelection, this));
challengeLabel->setMouseOverCallback(std::bind(Application::selectMenuItem, this, challengeItem->getIndex()));
challengeLabel->setMouseMovedCallback(std::bind(Application::selectMenuItem, this, challengeItem->getIndex()));
challengeLabel->setMousePressedCallback(std::bind(Application::activateMenuItem, this, challengeItem->getIndex()));
challengeItem->setSelectedCallback(std::bind(&UIElement::setTintColor, challengeLabel, selectedColor));
challengeItem->setDeselectedCallback(std::bind(&UIElement::setTintColor, challengeLabel, deselectedColor));
challengeItem->setActivatedCallback(std::bind(&Application::enterLevelSelection, this));
challengeLabel->setMouseOverCallback(std::bind(&Application::selectMenuItem, this, challengeItem->getIndex()));
challengeLabel->setMouseMovedCallback(std::bind(&Application::selectMenuItem, this, challengeItem->getIndex()));
challengeLabel->setMousePressedCallback(std::bind(&Application::activateMenuItem, this, challengeItem->getIndex()));
MenuItem* experimentItem = mainMenu->addItem();
experimentItem->setSelectedCallback(std::bind(UIElement::setTintColor, experimentLabel, selectedColor));
experimentItem->setDeselectedCallback(std::bind(UIElement::setTintColor, experimentLabel, deselectedColor));
experimentItem->setActivatedCallback(std::bind(Application::enterMenu, this, 2));
experimentLabel->setMouseOverCallback(std::bind(Application::selectMenuItem, this, experimentItem->getIndex()));
experimentLabel->setMouseMovedCallback(std::bind(Application::selectMenuItem, this, experimentItem->getIndex()));
experimentLabel->setMousePressedCallback(std::bind(Application::activateMenuItem, this, experimentItem->getIndex()));
experimentItem->setSelectedCallback(std::bind(&UIElement::setTintColor, experimentLabel, selectedColor));
experimentItem->setDeselectedCallback(std::bind(&UIElement::setTintColor, experimentLabel, deselectedColor));
experimentItem->setActivatedCallback(std::bind(&Application::enterMenu, this, 2));
experimentLabel->setMouseOverCallback(std::bind(&Application::selectMenuItem, this, experimentItem->getIndex()));
experimentLabel->setMouseMovedCallback(std::bind(&Application::selectMenuItem, this, experimentItem->getIndex()));
experimentLabel->setMousePressedCallback(std::bind(&Application::activateMenuItem, this, experimentItem->getIndex()));
MenuItem* settingsItem = mainMenu->addItem();
settingsItem->setSelectedCallback(std::bind(UIElement::setTintColor, settingsLabel, selectedColor));
settingsItem->setDeselectedCallback(std::bind(UIElement::setTintColor, settingsLabel, deselectedColor));
settingsItem->setActivatedCallback(std::bind(Application::enterMenu, this, 3));
settingsLabel->setMouseOverCallback(std::bind(Application::selectMenuItem, this, settingsItem->getIndex()));
settingsLabel->setMouseMovedCallback(std::bind(Application::selectMenuItem, this, settingsItem->getIndex()));
settingsLabel->setMousePressedCallback(std::bind(Application::activateMenuItem, this, settingsItem->getIndex()));
settingsItem->setSelectedCallback(std::bind(&UIElement::setTintColor, settingsLabel, selectedColor));
settingsItem->setDeselectedCallback(std::bind(&UIElement::setTintColor, settingsLabel, deselectedColor));
settingsItem->setActivatedCallback(std::bind(&Application::enterMenu, this, 3));
settingsLabel->setMouseOverCallback(std::bind(&Application::selectMenuItem, this, settingsItem->getIndex()));
settingsLabel->setMouseMovedCallback(std::bind(&Application::selectMenuItem, this, settingsItem->getIndex()));
settingsLabel->setMousePressedCallback(std::bind(&Application::activateMenuItem, this, settingsItem->getIndex()));
MenuItem* quitItem = mainMenu->addItem();
quitItem->setSelectedCallback(std::bind(UIElement::setTintColor, quitLabel, selectedColor));
quitItem->setDeselectedCallback(std::bind(UIElement::setTintColor, quitLabel, deselectedColor));
quitItem->setActivatedCallback(std::bind(Application::close, this, EXIT_SUCCESS));
quitLabel->setMouseOverCallback(std::bind(Application::selectMenuItem, this, quitItem->getIndex()));
quitLabel->setMouseMovedCallback(std::bind(Application::selectMenuItem, this, quitItem->getIndex()));
quitLabel->setMousePressedCallback(std::bind(Application::activateMenuItem, this, quitItem->getIndex()));
quitItem->setSelectedCallback(std::bind(&UIElement::setTintColor, quitLabel, selectedColor));
quitItem->setDeselectedCallback(std::bind(&UIElement::setTintColor, quitLabel, deselectedColor));
quitItem->setActivatedCallback(std::bind(&Application::close, this, EXIT_SUCCESS));
quitLabel->setMouseOverCallback(std::bind(&Application::selectMenuItem, this, quitItem->getIndex()));
quitLabel->setMouseMovedCallback(std::bind(&Application::selectMenuItem, this, quitItem->getIndex()));
quitLabel->setMousePressedCallback(std::bind(&Application::activateMenuItem, this, quitItem->getIndex()));
experimentMenu = new Menu();
MenuItem* loadItem = experimentMenu->addItem();
loadItem->setSelectedCallback(std::bind(UIElement::setTintColor, loadLabel, selectedColor));
loadItem->setDeselectedCallback(std::bind(UIElement::setTintColor, loadLabel, deselectedColor));
loadItem->setActivatedCallback(std::bind(std::printf, "0\n"));
loadLabel->setMouseOverCallback(std::bind(Application::selectMenuItem, this, loadItem->getIndex()));
loadLabel->setMouseMovedCallback(std::bind(Application::selectMenuItem, this, loadItem->getIndex()));
loadLabel->setMousePressedCallback(std::bind(Application::activateMenuItem, this, loadItem->getIndex()));
loadItem->setSelectedCallback(std::bind(&UIElement::setTintColor, loadLabel, selectedColor));
loadItem->setDeselectedCallback(std::bind(&UIElement::setTintColor, loadLabel, deselectedColor));
loadItem->setActivatedCallback(std::bind(&std::printf, "0\n"));
loadLabel->setMouseOverCallback(std::bind(&Application::selectMenuItem, this, loadItem->getIndex()));
loadLabel->setMouseMovedCallback(std::bind(&Application::selectMenuItem, this, loadItem->getIndex()));
loadLabel->setMousePressedCallback(std::bind(&Application::activateMenuItem, this, loadItem->getIndex()));
MenuItem* newItem = experimentMenu->addItem();
newItem->setSelectedCallback(std::bind(UIElement::setTintColor, newLabel, selectedColor));
newItem->setDeselectedCallback(std::bind(UIElement::setTintColor, newLabel, deselectedColor));
newItem->setActivatedCallback(std::bind(std::printf, "bla\n"));
newLabel->setMouseOverCallback(std::bind(Application::selectMenuItem, this, newItem->getIndex()));
newLabel->setMouseMovedCallback(std::bind(Application::selectMenuItem, this, newItem->getIndex()));
newLabel->setMousePressedCallback(std::bind(Application::activateMenuItem, this, newItem->getIndex()));
newItem->setSelectedCallback(std::bind(&UIElement::setTintColor, newLabel, selectedColor));
newItem->setDeselectedCallback(std::bind(&UIElement::setTintColor, newLabel, deselectedColor));
newItem->setActivatedCallback(std::bind(&std::printf, "bla\n"));
newLabel->setMouseOverCallback(std::bind(&Application::selectMenuItem, this, newItem->getIndex()));
newLabel->setMouseMovedCallback(std::bind(&Application::selectMenuItem, this, newItem->getIndex()));
newLabel->setMousePressedCallback(std::bind(&Application::activateMenuItem, this, newItem->getIndex()));
MenuItem* experimentBackItem = experimentMenu->addItem();
experimentBackItem->setSelectedCallback(std::bind(UIElement::setTintColor, experimentBackLabel, selectedColor));
experimentBackItem->setDeselectedCallback(std::bind(UIElement::setTintColor, experimentBackLabel, deselectedColor));
experimentBackItem->setActivatedCallback(std::bind(Application::enterMenu, this, 0));
experimentBackLabel->setMouseOverCallback(std::bind(Application::selectMenuItem, this, experimentBackItem->getIndex()));
experimentBackLabel->setMouseMovedCallback(std::bind(Application::selectMenuItem, this, experimentBackItem->getIndex()));
experimentBackLabel->setMousePressedCallback(std::bind(Application::activateMenuItem, this, experimentBackItem->getIndex()));
experimentBackItem->setSelectedCallback(std::bind(&UIElement::setTintColor, experimentBackLabel, selectedColor));
experimentBackItem->setDeselectedCallback(std::bind(&UIElement::setTintColor, experimentBackLabel, deselectedColor));
experimentBackItem->setActivatedCallback(std::bind(&Application::enterMenu, this, 0));
experimentBackLabel->setMouseOverCallback(std::bind(&Application::selectMenuItem, this, experimentBackItem->getIndex()));
experimentBackLabel->setMouseMovedCallback(std::bind(&Application::selectMenuItem, this, experimentBackItem->getIndex()));
experimentBackLabel->setMousePressedCallback(std::bind(&Application::activateMenuItem, this, experimentBackItem->getIndex()));
settingsMenu = new Menu();
MenuItem* videoItem = settingsMenu->addItem();
videoItem->setSelectedCallback(std::bind(UIElement::setTintColor, videoLabel, selectedColor));
videoItem->setDeselectedCallback(std::bind(UIElement::setTintColor, videoLabel, deselectedColor));
videoItem->setActivatedCallback(std::bind(std::printf, "0\n"));
videoLabel->setMouseOverCallback(std::bind(Application::selectMenuItem, this, videoItem->getIndex()));
videoLabel->setMouseMovedCallback(std::bind(Application::selectMenuItem, this, videoItem->getIndex()));
videoLabel->setMousePressedCallback(std::bind(Application::activateMenuItem, this, videoItem->getIndex()));
videoItem->setSelectedCallback(std::bind(&UIElement::setTintColor, videoLabel, selectedColor));
videoItem->setDeselectedCallback(std::bind(&UIElement::setTintColor, videoLabel, deselectedColor));
videoItem->setActivatedCallback(std::bind(&std::printf, "0\n"));
videoLabel->setMouseOverCallback(std::bind(&Application::selectMenuItem, this, videoItem->getIndex()));
videoLabel->setMouseMovedCallback(std::bind(&Application::selectMenuItem, this, videoItem->getIndex()));
videoLabel->setMousePressedCallback(std::bind(&Application::activateMenuItem, this, videoItem->getIndex()));
MenuItem* audioItem = settingsMenu->addItem();
audioItem->setSelectedCallback(std::bind(UIElement::setTintColor, audioLabel, selectedColor));
audioItem->setDeselectedCallback(std::bind(UIElement::setTintColor, audioLabel, deselectedColor));
audioItem->setActivatedCallback(std::bind(std::printf, "1\n"));
audioLabel->setMouseOverCallback(std::bind(Application::selectMenuItem, this, audioItem->getIndex()));
audioLabel->setMouseMovedCallback(std::bind(Application::selectMenuItem, this, audioItem->getIndex()));
audioLabel->setMousePressedCallback(std::bind(Application::activateMenuItem, this, audioItem->getIndex()));
audioItem->setSelectedCallback(std::bind(&UIElement::setTintColor, audioLabel, selectedColor));
audioItem->setDeselectedCallback(std::bind(&UIElement::setTintColor, audioLabel, deselectedColor));
audioItem->setActivatedCallback(std::bind(&std::printf, "1\n"));
audioLabel->setMouseOverCallback(std::bind(&Application::selectMenuItem, this, audioItem->getIndex()));
audioLabel->setMouseMovedCallback(std::bind(&Application::selectMenuItem, this, audioItem->getIndex()));
audioLabel->setMousePressedCallback(std::bind(&Application::activateMenuItem, this, audioItem->getIndex()));
MenuItem* controlsItem = settingsMenu->addItem();
controlsItem->setSelectedCallback(std::bind(UIElement::setTintColor, controlsLabel, selectedColor));
controlsItem->setDeselectedCallback(std::bind(UIElement::setTintColor, controlsLabel, deselectedColor));
controlsItem->setActivatedCallback(std::bind(std::printf, "2\n"));
controlsLabel->setMouseOverCallback(std::bind(Application::selectMenuItem, this, controlsItem->getIndex()));
controlsLabel->setMouseMovedCallback(std::bind(Application::selectMenuItem, this, controlsItem->getIndex()));
controlsLabel->setMousePressedCallback(std::bind(Application::activateMenuItem, this, controlsItem->getIndex()));
controlsItem->setSelectedCallback(std::bind(&UIElement::setTintColor, controlsLabel, selectedColor));
controlsItem->setDeselectedCallback(std::bind(&UIElement::setTintColor, controlsLabel, deselectedColor));
controlsItem->setActivatedCallback(std::bind(&std::printf, "2\n"));
controlsLabel->setMouseOverCallback(std::bind(&Application::selectMenuItem, this, controlsItem->getIndex()));
controlsLabel->setMouseMovedCallback(std::bind(&Application::selectMenuItem, this, controlsItem->getIndex()));
controlsLabel->setMousePressedCallback(std::bind(&Application::activateMenuItem, this, controlsItem->getIndex()));
MenuItem* gameItem = settingsMenu->addItem();
gameItem->setSelectedCallback(std::bind(UIElement::setTintColor, gameLabel, selectedColor));
gameItem->setDeselectedCallback(std::bind(UIElement::setTintColor, gameLabel, deselectedColor));
gameItem->setActivatedCallback(std::bind(std::printf, "3\n"));
gameLabel->setMouseOverCallback(std::bind(Application::selectMenuItem, this, gameItem->getIndex()));
gameLabel->setMouseMovedCallback(std::bind(Application::selectMenuItem, this, gameItem->getIndex()));
gameLabel->setMousePressedCallback(std::bind(Application::activateMenuItem, this, gameItem->getIndex()));
gameItem->setSelectedCallback(std::bind(&UIElement::setTintColor, gameLabel, selectedColor));
gameItem->setDeselectedCallback(std::bind(&UIElement::setTintColor, gameLabel, deselectedColor));
gameItem->setActivatedCallback(std::bind(&std::printf, "3\n"));
gameLabel->setMouseOverCallback(std::bind(&Application::selectMenuItem, this, gameItem->getIndex()));
gameLabel->setMouseMovedCallback(std::bind(&Application::selectMenuItem, this, gameItem->getIndex()));
gameLabel->setMousePressedCallback(std::bind(&Application::activateMenuItem, this, gameItem->getIndex()));
MenuItem* settingsBackItem = settingsMenu->addItem();
settingsBackItem->setSelectedCallback(std::bind(UIElement::setTintColor, settingsBackLabel, selectedColor));
settingsBackItem->setDeselectedCallback(std::bind(UIElement::setTintColor, settingsBackLabel, deselectedColor));
settingsBackItem->setActivatedCallback(std::bind(Application::enterMenu, this, 0));
settingsBackLabel->setMouseOverCallback(std::bind(Application::selectMenuItem, this, settingsBackItem->getIndex()));
settingsBackLabel->setMouseMovedCallback(std::bind(Application::selectMenuItem, this, settingsBackItem->getIndex()));
settingsBackLabel->setMousePressedCallback(std::bind(Application::activateMenuItem, this, settingsBackItem->getIndex()));
settingsBackItem->setSelectedCallback(std::bind(&UIElement::setTintColor, settingsBackLabel, selectedColor));
settingsBackItem->setDeselectedCallback(std::bind(&UIElement::setTintColor, settingsBackLabel, deselectedColor));
settingsBackItem->setActivatedCallback(std::bind(&Application::enterMenu, this, 0));
settingsBackLabel->setMouseOverCallback(std::bind(&Application::selectMenuItem, this, settingsBackItem->getIndex()));
settingsBackLabel->setMouseMovedCallback(std::bind(&Application::selectMenuItem, this, settingsBackItem->getIndex()));
settingsBackLabel->setMousePressedCallback(std::bind(&Application::activateMenuItem, this, settingsBackItem->getIndex()));
menuCount = 4;
menus = new Menu*[menuCount];
@ -1292,18 +1291,18 @@ bool Application::loadUI()
for (int i = 0; i < 10; ++i)
{
MenuItem* levelSelectionItem = levelSelectorMenu->addItem();
levelSelectionItem->setSelectedCallback(std::bind(UIImage::setTexture, levelSelections[i], levelActiveTexture));
levelSelectionItem->setDeselectedCallback(std::bind(UIImage::setTexture, levelSelections[i], levelInactiveTexture));
levelSelectionItem->setActivatedCallback(std::bind(Application::loadLevel, this));
levelSelectionItem->setSelectedCallback(std::bind(&UIImage::setTexture, levelSelections[i], levelActiveTexture));
levelSelectionItem->setDeselectedCallback(std::bind(&UIImage::setTexture, levelSelections[i], levelInactiveTexture));
levelSelectionItem->setActivatedCallback(std::bind(&Application::loadLevel, this));
levelSelections[i]->setMouseOverCallback(std::bind(Application::selectLevel, this, levelSelectionItem->getIndex()));
levelSelections[i]->setMouseMovedCallback(std::bind(Application::selectLevel, this, levelSelectionItem->getIndex()));
levelSelections[i]->setMousePressedCallback(std::bind(Application::activateLevel, this, levelSelectionItem->getIndex()));
levelSelections[i]->setMouseOverCallback(std::bind(&Application::selectLevel, this, levelSelectionItem->getIndex()));
levelSelections[i]->setMouseMovedCallback(std::bind(&Application::selectLevel, this, levelSelectionItem->getIndex()));
levelSelections[i]->setMousePressedCallback(std::bind(&Application::activateLevel, this, levelSelectionItem->getIndex()));
}
// Setup UI batch
uiBatch = new BillboardBatch();
uiBatch->resize(256);
uiBatch->resize(512);
uiBatcher = new UIBatcher();
// Setup UI render pass and compositor
@ -1438,13 +1437,13 @@ void Application::enterMenu(std::size_t index)
menus[currentMenuIndex]->getItem(selectedMenuItemIndex)->select();
// Start menu fade-in tween
menuFadeInTween->setUpdateCallback(std::bind(UIElement::setTintColor, menuContainers[currentMenuIndex], std::placeholders::_1));
menuFadeInTween->setEndCallback(std::bind(UIElement::setActive, menuContainers[currentMenuIndex], true));
menuFadeInTween->setUpdateCallback(std::bind(&UIElement::setTintColor, menuContainers[currentMenuIndex], std::placeholders::_1));
menuFadeInTween->setEndCallback(std::bind(&UIElement::setActive, menuContainers[currentMenuIndex], true));
menuFadeInTween->reset();
menuFadeInTween->start();
// Start menu slide-in tween
menuSlideInTween->setUpdateCallback(std::bind(UIElement::setTranslation, menuContainers[currentMenuIndex], std::placeholders::_1));
menuSlideInTween->setUpdateCallback(std::bind(&UIElement::setTranslation, menuContainers[currentMenuIndex], std::placeholders::_1));
menuSlideInTween->reset();
menuSlideInTween->start();
@ -1461,8 +1460,8 @@ void Application::exitMenu(std::size_t index)
menuContainers[currentMenuIndex]->setActive(false);
// Fade out previous menu
menuFadeOutTween->setUpdateCallback(std::bind(UIElement::setTintColor, menuContainers[currentMenuIndex], std::placeholders::_1));
menuFadeOutTween->setEndCallback(std::bind(UIElement::setVisible, menuContainers[currentMenuIndex], false));
menuFadeOutTween->setUpdateCallback(std::bind(&UIElement::setTintColor, menuContainers[currentMenuIndex], std::placeholders::_1));
menuFadeOutTween->setEndCallback(std::bind(&UIElement::setVisible, menuContainers[currentMenuIndex], false));
menuFadeOutTween->reset();
menuFadeOutTween->start();
@ -1507,7 +1506,7 @@ void Application::enterLevelSelection()
currentLevel = 1;
// Start menu slide-in tween
levelSelectorSlideInTween->setUpdateCallback(std::bind(UIElement::setTranslation, levelSelectorContainer, std::placeholders::_1));
levelSelectorSlideInTween->setUpdateCallback(std::bind(&UIElement::setTranslation, levelSelectorContainer, std::placeholders::_1));
levelSelectorSlideInTween->reset();
levelSelectorSlideInTween->start();

+ 19
- 18
src/game/navmesh.cpp View File

@ -18,6 +18,7 @@
*/
#include "navmesh.hpp"
#include <algorithm>
#include <fstream>
#include <map>
#include <sstream>
@ -381,22 +382,22 @@ void Navmesh::calculateNormals()
void Navmesh::calculateBounds()
{
Vector3 min(std::numeric_limits<float>::infinity());
Vector3 max(-std::numeric_limits<float>::infinity());
Vector3 minPoint(std::numeric_limits<float>::infinity());
Vector3 maxPoint(-std::numeric_limits<float>::infinity());
for (const Navmesh::Vertex* vertex: vertices)
{
min.x = std::min(min.x, vertex->position.x);
min.y = std::min(min.y, vertex->position.y);
min.z = std::min(min.z, vertex->position.z);
minPoint.x = std::min<float>(minPoint.x, vertex->position.x);
minPoint.y = std::min<float>(minPoint.y, vertex->position.y);
minPoint.z = std::min<float>(minPoint.z, vertex->position.z);
max.x = std::max(max.x, vertex->position.x);
max.y = std::max(max.y, vertex->position.y);
max.z = std::max(max.z, vertex->position.z);
maxPoint.x = std::max<float>(maxPoint.x, vertex->position.x);
maxPoint.y = std::max<float>(maxPoint.y, vertex->position.y);
maxPoint.z = std::max<float>(maxPoint.z, vertex->position.z);
}
bounds.setMin(min);
bounds.setMax(max);
bounds.setMin(minPoint);
bounds.setMax(maxPoint);
}
bool Navmesh::readOBJ(std::istream* stream, const std::string& filename)
@ -653,13 +654,13 @@ std::tuple intersects(const Ray& r
if (cosTheta <= 0.0f)
{
// Front-facing
t0 = std::min(t0, t);
t0 = std::min<float>(t0, t);
index0 = i;
}
else
{
// Back-facing
t1 = std::max(t1, t);
t1 = std::max<float>(t1, t);
index1 = i;
}
}
@ -675,14 +676,14 @@ Octree* Navmesh::createOctree(std::size_t maxDepth)
for (Navmesh::Triangle* triangle: triangles)
{
Vector3 min;
min.x = std::min(triangle->edge->vertex->position.x, std::min(triangle->edge->next->vertex->position.x, triangle->edge->previous->vertex->position.x));
min.y = std::min(triangle->edge->vertex->position.y, std::min(triangle->edge->next->vertex->position.y, triangle->edge->previous->vertex->position.y));
min.z = std::min(triangle->edge->vertex->position.z, std::min(triangle->edge->next->vertex->position.z, triangle->edge->previous->vertex->position.z));
min.x = std::min<float>(triangle->edge->vertex->position.x, std::min<float>(triangle->edge->next->vertex->position.x, triangle->edge->previous->vertex->position.x));
min.y = std::min<float>(triangle->edge->vertex->position.y, std::min<float>(triangle->edge->next->vertex->position.y, triangle->edge->previous->vertex->position.y));
min.z = std::min<float>(triangle->edge->vertex->position.z, std::min<float>(triangle->edge->next->vertex->position.z, triangle->edge->previous->vertex->position.z));
Vector3 max;
max.x = std::max(triangle->edge->vertex->position.x, std::max(triangle->edge->next->vertex->position.x, triangle->edge->previous->vertex->position.x));
max.y = std::max(triangle->edge->vertex->position.y, std::max(triangle->edge->next->vertex->position.y, triangle->edge->previous->vertex->position.y));
max.z = std::max(triangle->edge->vertex->position.z, std::max(triangle->edge->next->vertex->position.z, triangle->edge->previous->vertex->position.z));
max.x = std::max<float>(triangle->edge->vertex->position.x, std::max<float>(triangle->edge->next->vertex->position.x, triangle->edge->previous->vertex->position.x));
max.y = std::max<float>(triangle->edge->vertex->position.y, std::max<float>(triangle->edge->next->vertex->position.y, triangle->edge->previous->vertex->position.y));
max.z = std::max<float>(triangle->edge->vertex->position.z, std::max<float>(triangle->edge->next->vertex->position.z, triangle->edge->previous->vertex->position.z));
result->insert(AABB(min, max), triangle);
}

+ 9
- 5
src/game/nest.cpp View File

@ -18,8 +18,12 @@
*/
#include "nest.hpp"
#include <algorithm>
#include <cmath>
#undef min
#undef max
Vector3 Shaft::getHelixPosition(float depth) const
{
Vector3 position;
@ -127,7 +131,7 @@ Shaft* Nest::dig(Chamber* parent) const
}
// Determine potential child count (may be less, according to spacing between chambers)
int maxChildCount = std::max(1, random(parameters.minShaftChamberCount, parameters.maxShaftChamberCount));
int maxChildCount = std::max<int>(1, random(parameters.minShaftChamberCount, parameters.maxShaftChamberCount));
// Generate chambers, starting with final chamber (shaft must end with a chamber)
for (float depth = shaft->shaftDepth; depth >= 0.0f;)
@ -190,15 +194,15 @@ void Nest::free(Shaft* shaft)
delete shaft;
}
inline float Nest::random(float min, float max) const
inline float Nest::random(float minValue, float maxValue) const
{
std::uniform_real_distribution<float> distribution(min, std::nextafter(max, std::numeric_limits<float>::max()));
std::uniform_real_distribution<float> distribution(minValue, std::nextafter(maxValue, std::numeric_limits<float>::max()));
return distribution(rng);
}
inline int Nest::random(int min, int max) const
inline int Nest::random(int minValue, int maxValue) const
{
std::uniform_int_distribution<int> distribution(min, std::nextafter(max, std::numeric_limits<int>::max()));
std::uniform_int_distribution<int> distribution(minValue, std::nextafter(maxValue, std::numeric_limits<int>::max()));
return distribution(rng);
}

+ 2
- 2
src/game/nest.hpp View File

@ -166,8 +166,8 @@ private:
*/
void free(Shaft* shaft);
float random(float min, float max) const;
int random(int min, int max) const;
float random(float minValue, float maxValue) const;
int random(int minValue, int maxValue) const;
NestParameters parameters;
Shaft* root;

+ 2
- 0
src/game/tool.cpp View File

@ -0,0 +1,2 @@
#include "tool.hpp"

+ 24
- 9
src/game/tool.hpp View File

@ -1,17 +1,32 @@
enum class ToolContext
/**
* Abstract base class for tools. Tools are the only way for the user to interact with the world.
*/
class Tool
{
BRUSH_PAINT,
LENS_FOCUS,
FORCEPS_PINCH,
FORCEPS_RELEASE,
FORCEPS_PICK_UP,
FORCEPS_PUT_DOWN
public:
private:
Vector3 translation;
};
class Tool
class Forceps: public Tool
{
public:
private:
void pinch();
void release();
ModelInstance forcepsModelInstance;
};
class Brush: public Tool
{
public:
ToolContext gatherContext();
private:
void paint();
};

+ 1
- 1
src/input.hpp View File

@ -27,7 +27,7 @@ using namespace Emergent;
#include <iostream>
#include <map>
#include <list>
#include <SDL.h>
#include <SDL2/SDL.h>
class KeyObserver
{

+ 3
- 2
src/mesh.cpp View File

@ -18,6 +18,7 @@
*/
#include "mesh.hpp"
#include <algorithm>
#include <iostream>
#include <fstream>
#include <map>
@ -385,13 +386,13 @@ std::tuple intersects(const glm::v
if (cosTheta <= 0.0f)
{
// Front-facing
t0 = std::min(t0, t);
t0 = std::min<float>(t0, t);
index0 = i;
}
else
{
// Back-facing
t1 = std::max(t1, t);
t1 = std::max<float>(t1, t);
index1 = i;
}
}

+ 1
- 1
src/states/title-state.cpp View File

@ -22,7 +22,7 @@
#include "../application.hpp"
#include "../camera-controller.hpp"
#include <iostream>
#include <SDL.h>
#include <SDL2/SDL.h>
const float blankDuration = 0.0f;
const float fadeInDuration = 0.5f;

+ 5
- 5
src/ui/pie-menu.cpp View File

@ -12,9 +12,9 @@ PieMenu::PieMenu(Tweener* tweener):
{
// Setup fullscreen container
fullscreenContainer.addChild(&croppedContainer);
fullscreenContainer.setMouseMovedCallback(std::bind(PieMenu::mouseMoved, this, std::placeholders::_1, std::placeholders::_2));
fullscreenContainer.setMousePressedCallback(std::bind(PieMenu::mouseButtonPressed, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
fullscreenContainer.setMouseReleasedCallback(std::bind(PieMenu::mouseButtonReleased, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
fullscreenContainer.setMouseMovedCallback(std::bind(&PieMenu::mouseMoved, this, std::placeholders::_1, std::placeholders::_2));
fullscreenContainer.setMousePressedCallback(std::bind(&PieMenu::mouseButtonPressed, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
fullscreenContainer.setMouseReleasedCallback(std::bind(&PieMenu::mouseButtonReleased, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
// Setup cropped container
croppedContainer.addChild(&scalingContainer);
@ -24,9 +24,9 @@ PieMenu::PieMenu(Tweener* tweener):
// Create tweens
scaleUpTween = new Tween<float>(EaseFunction::OUT_SINE, 0.0f, 0.1f, 0.0f, 1.0f);
scaleUpTween->setUpdateCallback(std::bind(PieMenu::setScale, this, std::placeholders::_1));
scaleUpTween->setUpdateCallback(std::bind(&PieMenu::setScale, this, std::placeholders::_1));
scaleDownTween = new Tween<float>(EaseFunction::IN_SINE, 0.0f, 0.1f, 1.0f, -1.0f);
scaleDownTween->setUpdateCallback(std::bind(PieMenu::setScale, this, std::placeholders::_1));
scaleDownTween->setUpdateCallback(std::bind(&PieMenu::setScale, this, std::placeholders::_1));
// Add tweens
tweener->addTween(scaleUpTween);

+ 6
- 5
src/ui/toolbar.cpp View File

@ -1,4 +1,5 @@
#include "toolbar.hpp"
#include <algorithm>
Toolbar::Toolbar():
toolbarTopTexture(nullptr),
@ -44,7 +45,7 @@ void Toolbar::setButtonDepressedTexture(Texture* texture)
void Toolbar::resize()
{
int toolbarWidth = toolbarMiddleTexture->getWidth();
int toolbarHeight = toolbarTopTexture->getHeight() + toolbarBottomTexture->getHeight() + toolbarMiddleTexture->getHeight() * std::max(0, (int)buttons.size() - 1);
int toolbarHeight = toolbarTopTexture->getHeight() + toolbarBottomTexture->getHeight() + toolbarMiddleTexture->getHeight() * std::max<int>(0, (int)buttons.size() - 1);
float borderSpacing = 8.0f;
float buttonOffsetY = ((toolbarTopTexture->getHeight() + toolbarBottomTexture->getHeight()) - buttonRaisedTexture->getHeight()) / 2;
@ -62,7 +63,7 @@ void Toolbar::resize()
toolbarBottomImage.setTranslation(Vector2(0.0f, 0.0f));
toolbarMiddleImage.setAnchor(Vector2(0.0f, 0.5f));
toolbarMiddleImage.setDimensions(Vector2(toolbarMiddleTexture->getWidth(), toolbarMiddleTexture->getHeight() * std::max(0, (int)buttons.size() - 1)));
toolbarMiddleImage.setDimensions(Vector2(toolbarMiddleTexture->getWidth(), toolbarMiddleTexture->getHeight() * std::max<int>(0, (int)buttons.size() - 1)));
toolbarMiddleImage.setTranslation(Vector2(0.0f, 0.0f));
// Resize buttons and icons
@ -105,9 +106,9 @@ void Toolbar::addButton(Texture* iconTexture, std::function pressCallbac
// Setup callbacks
std::size_t buttonIndex = buttons.size() - 1;
//button->setMouseOverCallback(std::bind(Toolbar::selectMenuItem, this, buttonIndex));
//button->setMouseMovedCallback(std::bind(Toolbar::selectMenuItem, this, buttonIndex));
button->setMousePressedCallback(std::bind(Toolbar::pressButton, this, buttonIndex));
//button->setMouseOverCallback(std::bind(&Toolbar::selectMenuItem, this, buttonIndex));
//button->setMouseMovedCallback(std::bind(&Toolbar::selectMenuItem, this, buttonIndex));
button->setMousePressedCallback(std::bind(&Toolbar::pressButton, this, buttonIndex));
pressCallbacks.push_back(pressCallback);
releaseCallbacks.push_back(releaseCallback);

+ 2
- 1
src/ui/tween.hpp View File

@ -20,6 +20,7 @@
#ifndef TWEEN_HPP
#define TWEEN_HPP
#include <algorithm>
#include <functional>
#include <list>
#include <iostream>
@ -239,7 +240,7 @@ void Tween::update(float dt)
oldStopped = stopped;
// Add delta time to time and calculate tween value
time = std::min(duration, time + dt);
time = std::min<float>(duration, time + dt);
calculateTweenValue();
// Execute update callback

+ 1
- 1
src/ui/ui.cpp View File

@ -318,8 +318,8 @@ BillboardBatch::Range* UIBatcher::getRange(BillboardBatch* result, const UIEleme
if (material->texture != element->getMaterial()->texture)
{
// Create new range for the element
BillboardBatch::Range* precedingRange = range;
range = result->addRange();
BillboardBatch::Range* precedingRange = result->getRange(result->getRangeCount() - 2);
range->material = (Material*)element->getMaterial();
range->start = precedingRange->start + precedingRange->length;
range->length = 0;

Loading…
Cancel
Save