Permalink
Browse files

Start implementing the title chapter - needs threading fixes to KGLT

  • Loading branch information...
1 parent 4d88a88 commit a38adc4d63aa646dce3a0cce4751d3dfc0c9514e @Kazade committed Jun 7, 2012
View
@@ -2,6 +2,8 @@
#include "engine.h"
#include "chapter_manager.h"
+#include <kglt/thread.h>
+
namespace k4x {
Chapter::Chapter():
View
@@ -16,6 +16,8 @@ ChapterManager::ChapterManager(Engine& engine):
void ChapterManager::register_chapter(const std::string& name, std::tr1::shared_ptr<Chapter> chapter) {
assert(chapters_.find(name) == chapters_.end());
+ chapter->set_manager(this);
+
chapters_[name] = chapter;
if(current_chapter_name_.empty()) {
current_chapter_name_ = name;
@@ -0,0 +1,65 @@
+#include "title_chapter.h"
+#include "../engine.h"
+#include "../chapter_manager.h"
+
+#include <kglt/thread.h>
+
+namespace k4x {
+
+TitleChapter::TitleChapter():
+ background_sprite_id_(0) {
+
+}
+
+void TitleChapter::set_background_image(const std::string& background_image) {
+ background_image_path_ = background_image;
+}
+
+void TitleChapter::on_prepare_start() {
+ kglt::Window& window = manager().engine().window();
+ kglt::Scene& scene = window.scene();
+
+ if(!background_image_path_.empty()) {
+ L_DEBUG("Loading background image from: " + background_image_path_);
+
+ background_sprite_id_ = scene.new_sprite();
+ kglt::Sprite& background = scene.sprite(background_sprite_id_);
+ L_DEBUG("Loading...");
+
+ window.loader_for(background_image_path_, "LOADER_HINT_SPRITE")->into(background, { "SPRITE_FRAME_WIDTH", "512" });
+ background.set_render_dimensions(640, 480);
+ background.move_to(0.0, 0.0, -1.0);
+ background.set_animation_frames(0, 0);
+ background.set_animation_fps(0);
+
+ L_DEBUG("Background loaded");
+ }
+
+ /*
+ if(!title_music_path_.empty()) {
+ kalt::System& system = manager().engine().sound();
+ title_music_ = system.new_track();
+ kalt::Track& track = system.track(title_music);
+ system.loader_for(title_music_path_)->into(track);
+ }*/
+}
+
+void TitleChapter::on_frame_start() {
+ kglt::Window& window = manager().engine().window();
+ window.scene().pass().viewport().configure(kglt::VIEWPORT_TYPE_BLACKBAR_16_BY_9);
+ window.scene().pass().renderer().set_orthographic_projection_from_height(224.0 * 4.0, 16.0 / 9.0);
+
+ //FIXME: Need to set the backgorund render dimensions to the orthographic render dimensions
+
+ /*
+ kalt::System& system = manager().engine().sound();
+ kalt::Track& track = system.track(title_music_);
+ track.play();
+ */
+}
+
+void TitleChapter::add_demo(const std::string &demo_video) {
+
+}
+
+}
@@ -1,6 +1,11 @@
#ifndef TITLE_CHAPTER_H
#define TITLE_CHAPTER_H
+#include <tr1/memory>
+#include <string>
+
+#include <kglt/kglt.h>
+
#include "../chapter.h"
namespace k4x {
@@ -9,9 +14,23 @@ class TitleChapter : public Chapter {
public:
typedef std::tr1::shared_ptr<TitleChapter> ptr;
+ TitleChapter();
+
static TitleChapter::ptr create() {
return TitleChapter::ptr(new TitleChapter());
}
+
+ void add_demo(const std::string& demo_video);
+ void set_background_image(const std::string& background_image);
+
+private:
+ std::string background_image_path_;
+ kglt::SpriteID background_sprite_id_;
+
+ std::vector<std::string> demo_videos_;
+
+ void on_prepare_start();
+ void on_frame_start();
};
}
View
@@ -4,13 +4,17 @@
#include "level_manager.h"
#include "chapters/title_chapter.h"
+#include "kglt/kazbase/logging/logging.h"
+
namespace k4x {
Engine::Engine(int argc, char* argv[]):
is_running_(true),
chapter_manager_(new ChapterManager(*this)),
level_manager_(new LevelManager()) {
+ logging::get_logger("/")->add_handler(logging::Handler::ptr(new logging::StdIOHandler));
+
window_.reset(new kglt::Window());
//Register the essential chapters
@@ -44,4 +48,8 @@ LevelManager& Engine::level_manager() {
return *level_manager_;
}
+TitleChapter& Engine::title() {
+ return dynamic_cast<TitleChapter&>(chapter_manager().chapter("title"));
+}
+
}
View
0 s14x.config 100644 → 100755
No changes.
View
0 s14x.creator 100644 → 100755
No changes.
View
1 s14x.files 100644 → 100755
@@ -16,3 +16,4 @@ k4x/idle_task_manager.cpp
k4x/timed_task_manager.h
k4x/timed_task_manager.cpp
k4x/k4x.h
+k4x/chapters/title_chapter.cpp
View
0 s14x.includes 100644 → 100755
No changes.
View
@@ -1,3 +1,3 @@
-
+FILE(COPY ${CMAKE_SOURCE_DIR}/s14x/resources DESTINATION ${CMAKE_BINARY_DIR}/s14x)
ADD_EXECUTABLE(s14x main.cpp)
View
@@ -14,14 +14,19 @@ void on_two_player(k4x::Engine& engine) {
int main(int argc, char* argv[]) {
k4x::Engine engine(argc, argv);
+
+ engine.window().set_title("Sonic 1 4X");
+ engine.title().set_background_image("s14x/resources/title/background.png"); //Give the title screen a background
+ engine.chapter_manager().switch_to_chapter("title");
+
/*
//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().set_background_image("s14x/backgrounds/title.png");
engine.title().add_animated_sprite("s14x/title/main_sprite.png", k4x::POSITION_CENTERED);
//On menu selection, go to the save_selection screen
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a38adc4

Please sign in to comment.