Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit c82c52c054ae653f6033910b1443c39729251313 @Kazade committed Jun 6, 2012
3 .gitignore
@@ -0,0 +1,3 @@
+*.o
+*.obj
+*~
63 CMakeLists.txt
@@ -0,0 +1,63 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
+
+PROJECT(S14X)
+
+ADD_DEFINITIONS("-Wall -std=c++0x -g")
+SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules/")
+
+FIND_PACKAGE(KGLT REQUIRED)
+FIND_PACKAGE(KAZMATH REQUIRED)
+FIND_PACKAGE(Boost COMPONENTS system filesystem thread date_time regex REQUIRED)
+
+FIND_PACKAGE(PkgConfig)
+PKG_CHECK_MODULES(SIGC QUIET sigc++-2.0)
+
+PKG_CHECK_MODULES(SDL QUIET sdl)
+PKG_CHECK_MODULES(GL QUIET gl)
+PKG_CHECK_MODULES(GLU QUIET glu)
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_SOURCE_DIR}
+ ${SIGC_INCLUDE_DIRS}
+ ${KGLT_INCLUDE_DIRS}
+ ${KAZMATH_INCLUDE_DIRS}
+ ${SDL_INCLUDE_DIRS}
+ ${GL_INCLUDE_DIRS}
+ ${GLU_INCLUDE_DIRS}
+)
+
+LINK_LIBRARIES(
+
+ ${KGLT_LIBRARIES}
+ ${KAZMATH_LIBRARIES}
+
+ ${Boost_FILESYSTEM_LIBRARY}
+ ${Boost_SYSTEM_LIBRARY}
+ ${Boost_THREAD_LIBRARY}
+ ${Boost_DATE_TIME_LIBRARY}
+
+ ${SDL_LIBRARIES}
+ ${GL_LIBRARIES}
+ ${GLU_LIBRARIES}
+
+ ${SIGC_LIBRARIES}
+)
+
+ADD_SUBDIRECTORY(k4x)
+
+#Link with k4x for all subsequent programs
+LINK_LIBRARIES(k4x)
+
+ADD_SUBDIRECTORY(s14x)
+
+PKG_CHECK_MODULES(UNITTEST unittest++)
+
+INCLUDE_DIRECTORIES(
+ ${UNITTEST_INCLUDE_DIRS}
+)
+
+LINK_LIBRARIES(
+ ${UNITTEST_LIBRARIES}
+)
+
+ADD_SUBDIRECTORY(tests)
23 cmake_modules/FindKAZMATH.cmake
@@ -0,0 +1,23 @@
+FIND_PATH( KAZMATH_INCLUDE_DIRS kazmath/vec3.h /usr/include /usr/local/include $ENV{INCLUDE} )
+FIND_LIBRARY( KAZMATH_LIBRARIES NAMES kazmath PATHS /usr/lib /usr/local/lib )
+
+IF(KAZMATH_INCLUDE_DIRS)
+ MESSAGE(STATUS "Found Kazmath include dir: ${KAZMATH_INCLUDE_DIRS}")
+ELSE(KAZMATH_INCLUDE_DIRS)
+ MESSAGE(STATUS "Could NOT find Kazmath headers.")
+ENDIF(KAZMATH_INCLUDE_DIRS)
+
+IF(KAZMATH_LIBRARIES)
+ MESSAGE(STATUS "Found Kazmath library: ${KAZMATH_LIBRARIES}")
+ELSE(KAZMATH_LIBRARIES)
+ MESSAGE(STATUS "Could NOT find Kazmath library.")
+ENDIF(KAZMATH_LIBRARIES)
+
+IF(KAZMATH_INCLUDE_DIRS AND KAZMATH_LIBRARIES)
+ SET(KAZMATH_FOUND "YES")
+ELSE(KAZMATH_INCLUDE_DIRS AND KAZMATH_LIBRARIES)
+ SET(KAZMATH_FOUND "NO")
+ IF(KAZMATH_FIND_REQUIRED)
+ MESSAGE(FATAL_ERROR "Could not find Kazmath. Please install Kazmath (http://launchpad.net/kazmath)")
+ ENDIF(KAZMATH_FIND_REQUIRED)
+ENDIF(KAZMATH_INCLUDE_DIRS AND KAZMATH_LIBRARIES)
26 cmake_modules/FindKGLT.cmake
@@ -0,0 +1,26 @@
+#This file is for other projects to use, so that they can locate KGLT
+#using cmake
+
+FIND_PATH( KGLT_INCLUDE_DIRS kglt/window.h /usr/include /usr/local/include $ENV{INCLUDE} )
+FIND_LIBRARY( KGLT_LIBRARIES NAMES kglt PATHS /usr/lib /usr/local/lib )
+
+IF(KGLT_INCLUDE_DIRS)
+ MESSAGE(STATUS "Found KGLT include dir: ${KGLT_INCLUDE_DIRS}")
+ELSE(KGLT_INCLUDE_DIRS)
+ MESSAGE(STATUS "Could NOT find KGLT headers.")
+ENDIF(KGLT_INCLUDE_DIRS)
+
+IF(KGLT_LIBRARIES)
+ MESSAGE(STATUS "Found KGLT library: ${KGLT_LIBRARIES}")
+ELSE(KGLT_LIBRARIES)
+ MESSAGE(STATUS "Could NOT find KGLT library.")
+ENDIF(KGLT_LIBRARIES)
+
+IF(KGLT_INCLUDE_DIRS AND KGLT_LIBRARIES)
+ SET(KGLT_FOUND "YES")
+ELSE(KGLT_INCLUDE_DIRS AND KGLT_LIBRARIES)
+ SET(KGLT_FOUND "NO")
+ IF(KGLT_FIND_REQUIRED)
+ MESSAGE(FATAL_ERROR "Could not find KGLT. Please install KGLT (http://github.com/kazade/kglt)")
+ ENDIF(KGLT_FIND_REQUIRED)
+ENDIF(KGLT_INCLUDE_DIRS AND KGLT_LIBRARIES)
6 get_and_build_deps.sh
@@ -0,0 +1,6 @@
+git clone --recursive git://github.com/Kazade/KGLT.git /tmp/kglt
+mkdir /tmp/kglt/build
+cd /tmp/kglt/build
+cmake .. && make -j4
+sudo make install
+
5 k4x/CMakeLists.txt
@@ -0,0 +1,5 @@
+FILE(GLOB_RECURSE K4X_FILES *.cpp *.c)
+
+ADD_LIBRARY(k4x STATIC ${K4X_FILES})
+INSTALL(TARGETS k4x ARCHIVE DESTINATION lib)
+INSTALL(DIRECTORY ./ DESTINATION include/k4x FILES_MATCHING PATTERN *.h)
75 k4x/chapter.cpp
@@ -0,0 +1,75 @@
+#include "chapter.h"
+#include "engine.h"
+#include "chapter_manager.h"
+
+namespace k4x {
+
+Chapter::Chapter():
+ manager_(nullptr) {
+
+}
+
+void Chapter::frame_start() {
+ on_frame_start();
+}
+
+void Chapter::frame_finish() {
+ on_frame_finish();
+}
+
+void Chapter::start() {
+ on_start();
+}
+
+void Chapter::stop() {
+ on_stop();
+}
+
+void Chapter::prepare_start() {
+ on_prepare_start();
+}
+
+void Chapter::prepare_stop() {
+ on_prepare_stop();
+}
+
+void Chapter::set_manager(ChapterManager* manager) {
+ manager_ = manager;
+}
+
+void Chapter::fade_to_black(float time_in_seconds, bool show_loading) {
+ this->fade_to_black_opacity_ = 0.0;
+ this->is_fading_to_black_ = true;
+ this->show_loading_when_black_ = true;
+
+ //Add a regular timed update every 100 milliseconds (FULL_OPACITY / TIME / 10)
+ manager().engine().timed().add(
+ sigc::bind(
+ sigc::mem_fun(this, &Chapter::increase_fade_opacity),
+ 1.0 / time_in_seconds / 10.0
+ ),
+ 100
+ );
+}
+
+bool Chapter::increase_fade_opacity(float amount) {
+ this->fade_to_black_opacity_ += amount;
+ if(this->fade_to_black_opacity_ >= 1.0) {
+ if(show_loading_when_black_) {
+ //display_loading_icon();
+ }
+
+ this->is_fading_to_black_ = false;
+ //Stop the regular update
+ return false;
+ }
+
+ //Continue the regular update
+ return true;
+}
+
+void Chapter::unfade() {
+ this->fade_to_black_opacity_ = 0.0;
+}
+
+}
52 k4x/chapter.h
@@ -0,0 +1,52 @@
+#ifndef K4X_CHAPTER_H
+#define K4X_CHAPTER_H
+
+#include <cassert>
+
+namespace k4x {
+
+class ChapterManager;
+
+class Chapter {
+public:
+ Chapter();
+ virtual ~Chapter() {}
+
+ void prepare_start(); ///< Called before previous chapter shuts down
+ void start(); ///< Called when this chapter becomes active
+
+ void frame_start();
+ void frame_finish();
+
+ void prepare_stop(); ///< Called when shutdown is initialized
+ void stop(); ///< Called when this chapter actually becomes inactive
+
+ void fade_to_black(float time_in_seconds, bool show_loading=false);
+ void unfade();
+ bool increase_fade_opacity(float amount);
+
+ void set_manager(ChapterManager* manager);
+ ChapterManager& manager() {
+ assert(manager_);
+ return *manager_;
+ }
+private:
+ ChapterManager* manager_;
+
+ float fade_to_black_opacity_;
+ bool is_fading_to_black_;
+ bool show_loading_when_black_;
+
+ virtual void on_prepare_start() {}
+ virtual void on_prepare_stop() {}
+
+ virtual void on_frame_start() {}
+ virtual void on_frame_finish() {}
+
+ virtual void on_start() {}
+ virtual void on_stop() {}
+};
+
+}
+
+#endif // K4X_CHAPTER_H
62 k4x/chapter_manager.cpp
@@ -0,0 +1,62 @@
+#include <future>
+#include <thread>
+#include <sigc++/sigc++.h>
+
+#include "chapter.h"
+#include "chapter_manager.h"
+#include "engine.h"
+
+namespace k4x {
+
+ChapterManager::ChapterManager(Engine& engine):
+ engine_(engine) {
+
+}
+
+void ChapterManager::register_chapter(const std::string& name, std::tr1::shared_ptr<Chapter> chapter) {
+ assert(chapters_.find(name) == chapters_.end());
+
+ chapters_[name] = chapter;
+ if(current_chapter_name_.empty()) {
+ current_chapter_name_ = name;
+ }
+}
+
+Chapter& ChapterManager::chapter(const std::string& name) {
+ assert(chapters_.find(name) != chapters_.end());
+ return *chapters_[name];
+}
+
+void ChapterManager::switch_to_chapter(const std::string& name) {
+ Chapter& next = chapter(name);
+ Chapter& current = current_chapter();
+
+ //Start threads for shutting down this chapter, and booting up the next one
+
+ prepare_start_future_ = std::async(std::launch::async, sigc::mem_fun(&next, &Chapter::prepare_start));
+ prepare_stop_future_ = std::async(std::launch::async, sigc::mem_fun(&current, &Chapter::prepare_stop));
+
+ //Wait for the threads to complete before switching
+ engine().idle().add(sigc::bind(sigc::mem_fun(this, &ChapterManager::switch_when_ready), name));
+
+ //Fade the existing chapter to black while it shuts down and while the next one loads
+ //Show the loading icon if we get to full black and we haven't finished loading the next scene
+ current.fade_to_black(1.0, /*show_loading=*/true);
+}
+
+bool ChapterManager::switch_when_ready(const std::string& next) {
+ if(prepare_start_future_.valid() && prepare_stop_future_.valid()) {
+ prepare_start_future_.get();
+ prepare_stop_future_.get(); //Apparently we should call this anyway, so exceptions can be propagated..
+
+ current_chapter().stop();
+ current_chapter_name_ = next; //Move to the next chapter
+ current_chapter().start();
+
+ return false;
+ }
+
+ return true;
+}
+
+}
45 k4x/chapter_manager.h
@@ -0,0 +1,45 @@
+#ifndef K4X_CHAPTER_MANAGER_H
+#define K4X_CHAPTER_MANAGER_H
+
+#include <cassert>
+#include <future>
+#include <string>
+#include <tr1/memory>
+#include <map>
+
+namespace k4x {
+
+class Engine;
+class Chapter;
+
+class ChapterManager {
+public:
+ ChapterManager(Engine& engine);
+
+ void register_chapter(const std::string& name, std::tr1::shared_ptr<Chapter> chapter);
+ void restart_chapter();
+ void switch_to_chapter(const std::string& name);
+
+ Chapter& chapter(const std::string& name);
+ Engine& engine() { return engine_; }
+
+ Chapter& current_chapter() {
+ assert(!current_chapter_name_.empty());
+ return chapter(current_chapter_name_);
+ }
+
+ bool switch_when_ready(const std::string& next);
+
+private:
+ Engine& engine_;
+ std::string current_chapter_name_;
+
+ std::map<std::string, std::tr1::shared_ptr<Chapter> > chapters_;
+
+ std::future<void> prepare_start_future_;
+ std::future<void> prepare_stop_future_;
+};
+
+}
+
+#endif
19 k4x/chapters/title_chapter.h
@@ -0,0 +1,19 @@
+#ifndef TITLE_CHAPTER_H
+#define TITLE_CHAPTER_H
+
+#include "../chapter.h"
+
+namespace k4x {
+
+class TitleChapter : public Chapter {
+public:
+ typedef std::tr1::shared_ptr<TitleChapter> ptr;
+
+ static TitleChapter::ptr create() {
+ return TitleChapter::ptr(new TitleChapter());
+ }
+};
+
+}
+
+#endif // TITLE_CHAPTER_H
47 k4x/engine.cpp
@@ -0,0 +1,47 @@
+
+#include "engine.h"
+#include "chapter_manager.h"
+#include "level_manager.h"
+#include "chapters/title_chapter.h"
+
+namespace k4x {
+
+Engine::Engine(int argc, char* argv[]):
+ is_running_(true),
+ chapter_manager_(new ChapterManager(*this)),
+ level_manager_(new LevelManager()) {
+
+ window_.reset(new kglt::Window());
+
+ //Register the essential chapters
+ chapter_manager().register_chapter("title", k4x::TitleChapter::create());
+ //chapter_manager().register_chapter("save_selection", k4x::SaveSelectionChapter::create());
+ //chapter_manager().register_chapter("in_game", k4x::InGameChapter::create());
+}
+
+int32_t Engine::run() {
+ is_running_ = true;
+
+ while(is_running_) {
+ chapter_manager().current_chapter().frame_start();
+ is_running_ = window().update();
+ chapter_manager().current_chapter().frame_finish();
+
+ idle().execute();
+ timed().execute();
+ }
+
+ return 0;
+}
+
+ChapterManager& Engine::chapter_manager() {
+ assert(chapter_manager_);
+ return *chapter_manager_;
+}
+
+LevelManager& Engine::level_manager() {
+ assert(level_manager_);
+ return *level_manager_;
+}
+
+}
69 k4x/engine.h
@@ -0,0 +1,69 @@
+#ifndef K4X_ENGINE_H
+#define K4X_ENGINE_H
+
+#include <cstdint>
+#include <tr1/memory>
+
+#include <kglt/kglt.h>
+
+#include "idle_task_manager.h"
+#include "timed_task_manager.h"
+
+namespace k4x {
+
+enum PlayerMode {
+ SINGLE_PLAYER,
+ SINGLE_PLAYER_WITH_AI,
+ TWO_PLAYER
+};
+
+class LevelManager;
+class Chapter;
+class ChapterManager;
+class TitleChapter;
+
+class Engine {
+public:
+ Engine(int argc, char* argv[]);
+ int32_t run();
+
+ TitleChapter& title(); ///< Shortcut function for chapter_manager().chapter("title");
+ Chapter& save_selection(); ///< Shortcut function for chapter_manager().chapter("save_selection");
+
+ ChapterManager& chapter_manager();
+ LevelManager& level_manager();
+
+ void set_player_mode(PlayerMode mode) {
+ player_mode_ = mode;
+ }
+
+ PlayerMode player_mode() { return player_mode_; }
+
+ IdleTaskManager& idle() { return idle_tasks_; }
+ TimedTaskManager& timed() { return timed_tasks_; }
+
+ kglt::Window& window() {
+ assert(window_);
+ return *window_;
+ }
+
+private:
+ bool is_running_;
+
+ std::tr1::shared_ptr<ChapterManager> chapter_manager_;
+ std::tr1::shared_ptr<LevelManager> level_manager_;
+
+ void run_idle_tasks();
+ void run_timed_tasks();
+
+ std::tr1::shared_ptr<kglt::Window> window_;
+
+ PlayerMode player_mode_;
+
+ IdleTaskManager idle_tasks_;
+ TimedTaskManager timed_tasks_;
+};
+
+}
+
+#endif
28 k4x/idle_task_manager.cpp
@@ -0,0 +1,28 @@
+#include <utility>
+
+#include "idle_task_manager.h"
+
+namespace k4x {
+
+static uint32_t connection_counter = 0;
+
+IdleTaskManager::IdleTaskManager() {
+
+}
+
+ConnectionID IdleTaskManager::add(std::tr1::function<bool ()> callback) {
+ ConnectionID new_id = ++connection_counter;
+ signals_.insert(std::make_pair(new_id, callback));
+ return new_id;
+}
+
+void IdleTaskManager::execute() {
+ /*for(std::pair<ConnectionID, std::tr1::function<bool> > p: signals_.copy()) {
+ bool result = p.second();
+ if(!result) {
+ signals_.erase(p.first);
+ }
+ }*/
+}
+
+}
28 k4x/idle_task_manager.h
@@ -0,0 +1,28 @@
+#ifndef IDLE_TASK_MANAGER_H
+#define IDLE_TASK_MANAGER_H
+
+#include <cstdint>
+#include <sigc++/sigc++.h>
+#include <tr1/functional>
+#include <map>
+
+namespace k4x {
+
+typedef uint32_t ConnectionID;
+
+class IdleTaskManager {
+public:
+ IdleTaskManager();
+
+ ConnectionID add(std::tr1::function<bool ()> callback);
+ void remove(ConnectionID connection);
+
+ void execute();
+
+private:
+ std::map<ConnectionID, std::tr1::function<bool ()> > signals_;
+
+};
+
+}
+#endif // IDLE_TASK_MANAGER_H
12 k4x/k4x.h
@@ -0,0 +1,12 @@
+#ifndef K4X_H
+#define K4X_H
+
+#include "engine.h"
+#include "chapter.h"
+#include "chapter_manager.h"
+#include "idle_task_manager.h"
+#include "timed_task_manager.h"
+
+#include "chapters/title_chapter.h"
+
+#endif // K4X_H
11 k4x/level_manager.h
@@ -0,0 +1,11 @@
+#ifndef K4X_LEVEL_MANAGER_H
+#define K4X_LEVEL_MANAGER_H
+
+namespace k4x {
+
+class LevelManager {
+
+};
+
+}
+#endif
66 k4x/timed_task_manager.cpp
@@ -0,0 +1,66 @@
+#include <algorithm>
+#include <functional>
+
+#include "timed_task_manager.h"
+
+namespace k4x {
+
+static ConnectionID connection_counter = 0;
+
+ConnectionID TimedTaskManager::add(std::tr1::function<bool ()> callback, uint32_t milliseconds) {
+ TimedTask new_task;
+ new_task.connection_id = ++connection_counter;
+ new_task.callback = callback;
+ new_task.time_elapsed_in_milliseconds = 0;
+ new_task.time_between_calls = milliseconds;
+
+ tasks_.push_back(new_task);
+
+ return new_task.connection_id;
+}
+
+void TimedTaskManager::remove(ConnectionID connection) {
+ tasks_.erase(
+ std::remove_if(tasks_.begin(), tasks_.end(), [=](const TimedTask& task) { return task.connection_id == connection; }),
+ tasks_.end()
+ );
+}
+
+uint64_t TimedTaskManager::get_ticks() {
+ struct timespec current_time;
+ clock_gettime(CLOCK_MONOTONIC, &current_time);
+ return (uint64_t) ((current_time.tv_sec * 1000UL) + (current_time.tv_nsec / 1000000UL));
+}
+
+void TimedTaskManager::execute() {
+ static uint64_t last_time = get_ticks();
+
+ uint64_t current_time = get_ticks();
+ uint64_t diff = current_time - last_time;
+
+ std::vector<TimedTask> tasks = tasks_;
+
+ /*
+ Go through all the tasks, update the elapsed times. If the elapsed time
+ is larger than the step, then execute the function and remove it if it
+ returns false
+ */
+ uint32_t i = 0;
+ for(TimedTask& task: tasks) {
+ task.time_elapsed_in_milliseconds += diff;
+ if(task.time_elapsed_in_milliseconds >= task.time_between_calls) {
+
+ task.time_elapsed_in_milliseconds -= task.time_between_calls;
+
+ if(!task.callback()) {
+ tasks_.erase(tasks_.begin() + i);
+ }
+ }
+ ++i;
+ }
+
+ last_time = current_time;
+}
+
+
+}
35 k4x/timed_task_manager.h
@@ -0,0 +1,35 @@
+#ifndef TIMED_TASK_MANAGER_H
+#define TIMED_TASK_MANAGER_H
+
+#include <vector>
+#include <tr1/functional>
+#include <cstdint>
+
+namespace k4x {
+
+typedef uint32_t ConnectionID;
+
+struct TimedTask {
+ ConnectionID connection_id;
+ uint32_t time_elapsed_in_milliseconds;
+ uint32_t time_between_calls;
+ std::tr1::function<bool ()> callback;
+};
+
+class TimedTaskManager {
+public:
+ ConnectionID add(std::tr1::function<bool ()>, uint32_t milliseconds);
+ void remove(ConnectionID connection);
+
+ void execute();
+
+private:
+ std::vector<TimedTask> tasks_;
+
+ uint64_t get_ticks();
+};
+
+
+}
+
+#endif // TIMED_TASK_MANAGER_H
1 s14x.config
@@ -0,0 +1 @@
+// ADD PREDEFINED MACROS HERE!
1 s14x.creator
@@ -0,0 +1 @@
+[General]
18 s14x.files
@@ -0,0 +1,18 @@
+/home/lukeb/GitHub/K4X/k4x/chapter_manager.h
+/home/lukeb/GitHub/K4X/k4x/CMakeLists.txt
+/home/lukeb/GitHub/K4X/k4x/engine.cpp
+/home/lukeb/GitHub/K4X/k4x/engine.h
+/home/lukeb/GitHub/K4X/k4x/level_manager.h
+/home/lukeb/GitHub/K4X/s14x/CMakeLists.txt
+/home/lukeb/GitHub/K4X/s14x/main.cpp
+/home/lukeb/GitHub/K4X/CMakeLists.txt
+/home/lukeb/GitHub/K4X/get_and_build_deps.sh
+k4x/chapter.h
+k4x/chapter_manager.cpp
+k4x/chapter.cpp
+k4x/chapters/title_chapter.h
+k4x/idle_task_manager.h
+k4x/idle_task_manager.cpp
+k4x/timed_task_manager.h
+k4x/timed_task_manager.cpp
+k4x/k4x.h
1 s14x.includes
@@ -0,0 +1 @@
+/home/lukeb/GitHub/K4X/k4x
3 s14x/CMakeLists.txt
@@ -0,0 +1,3 @@
+
+
+ADD_EXECUTABLE(s14x main.cpp)
49 s14x/main.cpp
@@ -0,0 +1,49 @@
+
+#include <k4x/k4x.h>
+
+void on_one_player(k4x::Engine& engine) {
+ engine.set_player_mode(k4x::SINGLE_PLAYER);
+ engine.chapter_manager().switch_to_chapter("save_selection");
+}
+
+void on_two_player(k4x::Engine& engine) {
+ engine.set_player_mode(k4x::TWO_PLAYER);
+ engine.chapter_manager().switch_to_chapter("save_selection");
+}
+
+int main(int argc, char* argv[]) {
+
+ k4x::Engine engine(argc, argv);
+/*
+ //Configure the title screen
+ engine.title().add_demo("s14x/demos/demo_1.ogv"); //Add a list of demo moves that cycle after a timeout
+ engine.title().add_demo("s14x/demos/demo_2.ogv");
+ engine.title().set_time_to_demo(30); //Set the time the title screen shows before displaying a demo
+ engine.title().set_fade_time(1); //Set the fade time when time_to_demo runs out
+ engine.title().set_background_music("s14x/music/intro.ogg"); //Set the background music
+ engine.title().set_background_image("s14x/backgrounds/title.png"); //Give the title screen a background
+ engine.title().add_animated_sprite("s14x/title/main_sprite.png", k4x::POSITION_CENTERED);
+
+ //On menu selection, go to the save_selection screen
+ engine.title().menu().add_entry("1 Player", &on_one_player());
+ engine.title().menu().add_entry("2 Player", &on_two_player());
+ engine.title().menu().add_entry("Exit", sigc::bind(&Engine::shutdown, &engine));
+
+ //Register a single level, we need to also register any actors and gimmicks that the level file refers to.
+ k4x::LevelID green_hill = engine.level_manager().add_level("s1x/levels/green_hill_act_one.k4x", "s14x/levels/green_hill_act_two.k4x");
+ engine.level_manager().level(green_hill).register_actor_type("crabmeat", s14x::actors::CrabMeatFactory::create());
+ engine.level_manager().level(green_hill).register_actor_type("pendulum_boss", s14x::actors::PendulumBossFactory::create());
+ engine.level_manager().level(green_hill).register_gimmick("wooden_bridge", s14x::gimmicks::WoodenBridgeFactory::create());
+
+ //Show the following entries in the pause menu, "Unpause" always exists
+ engine.level_manager().pause_menu().add_entry("Retry", sigc::bind(&ChapterManger::restart_current, engine.chapter_manager()));
+ engine.level_manager().pause_menu().add_entry("Quit", sigc::bind(&Engine::select_chapter, &engine, "title"));
+
+ //Add extra game logic processing during levels (e.g. keeping score, updating life counts etc.)
+ engine.level_manager().set_level_logic(s14x::LevelLogic::create());
+
+ //Each player can have a profile with extra attributes (e.g. score, rings, lives etc.), this specifies the factory for that.
+ engine.set_player_profile_factory(s14x::PlayerProfileFactory::create());
+*/
+ return engine.run();
+}
3 tests/CMakeLists.txt
@@ -0,0 +1,3 @@
+FILE(GLOB_RECURSE TEST_FILES *.cpp)
+
+ADD_EXECUTABLE(k4x_tests ${TEST_FILES})
8 tests/main.cpp
@@ -0,0 +1,8 @@
+#include <unittest++/UnitTest++.h>
+#include <iostream>
+
+int main(int argc, char* argv[]) {
+ //Disable cout for tests
+ std::cout.rdbuf(0);
+ return UnitTest::RunAllTests();
+}

0 comments on commit c82c52c

Please sign in to comment.
Something went wrong with that request. Please try again.