소스 검색

Merge branch 'master' into piaf_integration

Keeping the source up to date to be able to test on computers first
Eiyeron Fulmincendii 10 년 전
부모
커밋
3acbb5f8e4

+ 1 - 1
Makefile

@@ -26,7 +26,7 @@ BUILT_SRCS :=
 BUILT_SRCS_C :=
 BUILT_SRCS_CPP :=
 
-OUT = out
+OUT = out/$(PLATFORM)
 ELF = $(OUT)/$(NAME).elf
 
 CLEAN_SPEC :=

+ 18 - 3
README.md

@@ -1,6 +1,19 @@
 # WalrusRPG
 
-A J-RPG engine for the TI-Nspire. There's still a lot to do before anything works.
+A cross-platform J-RPG engine. Still very much a work in progress, but it
+might get somewhere someday.
+
+## Features
+
+- Cross-platform
+- Walruses
+- Highly experimental stuff inside (yes it's radioactive)
+
+## Does not feature
+
+- Walrii
+- The game
+- Actual content
 
 ## Getting the code wih Git
 
@@ -24,7 +37,8 @@ build system later.
 ## Compiling
 
 The build system currently depends on Vogtinator's [ConvertImg](https://github.com/Vogtinator/ConvertImg),
-as well as GNU Make and the Ndless toolchain.
+as well as GNU Make and the Ndless toolchain when compiling for the Nspire,
+or SFML for systems that it supports.
 
 We use the [tinystl](https://github.com/mendsley/tinystl) library to keep binaries small, so be
 sure to clone the submodules as well !
@@ -33,7 +47,7 @@ To compile the project, simply run make (-j friendly).
 
 ## Plans
 
-### What need to be done
+### What needs to be done
 
 - Entities (planning in progress)
 - Events
@@ -47,3 +61,4 @@ To compile the project, simply run make (-j friendly).
 ### What's already done
 - Map system.
 - Basic text routines.
+- Support for multiple platforms, including the TI-Nspire CX and SFML

+ 1 - 0
platform/nspire/rules.mk

@@ -12,6 +12,7 @@ CPP = nspire-g++
 ZEHN = genzehn
 ZEHNFLAGS = --name "$(NAME)" --compress
 
+PLATFORM = nspire
 EXE = $(OUT)/$(NAME).tns
 
 $(EXE): $(ELF)

+ 64 - 0
platform/sfml/Graphics.cpp

@@ -0,0 +1,64 @@
+#include "Graphics.h"
+#include "sfwindow.h"
+#include <SFML/Graphics.hpp>
+#include "utility/misc.h"
+
+#define GRAPHICS WalrusRPG::Graphics
+
+sf::RenderWindow window;
+sf::View view;
+sf::RenderTexture buffer;
+
+void GRAPHICS::init()
+{
+    window.create(sf::VideoMode(640, 480), "WalrusRPG",
+                  sf::Style::Titlebar | sf::Style::Resize);
+    view = sf::View(window.getDefaultView());
+    buffer.create(320, 240);
+}
+
+void GRAPHICS::deinit()
+{
+    window.close();
+}
+
+void GRAPHICS::frame_begin()
+{
+    window.clear(sf::Color::Black);
+}
+
+void GRAPHICS::frame_end()
+{
+    sf::Sprite sprite(buffer.getTexture());
+    sf::Vector2u winsize = window.getSize();
+    sf::Event event;
+    float scale = min(winsize.x / 320.f, winsize.y / 240.f);
+
+    while (window.pollEvent(event))
+    {
+    }
+
+    window.setView(view = sf::View(sf::FloatRect(0, 0, winsize.x, winsize.y)));
+
+    buffer.display();
+    window.clear();
+    sprite.setScale(scale, scale);
+    sprite.setPosition((winsize.x - 320.f * scale) / 2, (winsize.y - 240.f * scale) / 2);
+    window.draw(sprite);
+    window.display();
+}
+
+void GRAPHICS::put_sprite(const Texture &sheet, int x, int y,
+                          const WalrusRPG::Utils::Rect &window)
+{
+    sf::Sprite sprite;
+    sprite.setTexture(sheet.data);
+    sprite.setTextureRect(sf::IntRect(window.x, window.y, window.width, window.height));
+    sprite.setPosition(x, y);
+    buffer.draw(sprite);
+}
+
+void GRAPHICS::fill(const WalrusRPG::Graphics::Pixel &color)
+{
+    UNUSED(color);
+}

+ 35 - 0
platform/sfml/Input.cpp

@@ -0,0 +1,35 @@
+#include "Input.h"
+#include "sfwindow.h"
+#include <SFML/Window/Keyboard.hpp>
+
+#define INPUT WalrusRPG::Input
+
+bool INPUT::key_a()
+{
+    return window.hasFocus() && sf::Keyboard::isKeyPressed(sf::Keyboard::Return);
+}
+
+bool INPUT::key_b()
+{
+    return window.hasFocus() && sf::Keyboard::isKeyPressed(sf::Keyboard::BackSpace);
+}
+
+bool INPUT::key_up()
+{
+    return window.hasFocus() && sf::Keyboard::isKeyPressed(sf::Keyboard::W);
+}
+
+bool INPUT::key_down()
+{
+    return window.hasFocus() && sf::Keyboard::isKeyPressed(sf::Keyboard::S);
+}
+
+bool INPUT::key_left()
+{
+    return window.hasFocus() && sf::Keyboard::isKeyPressed(sf::Keyboard::A);
+}
+
+bool INPUT::key_right()
+{
+    return window.hasFocus() && sf::Keyboard::isKeyPressed(sf::Keyboard::D);
+}

+ 11 - 0
platform/sfml/Quirks.cpp

@@ -0,0 +1,11 @@
+#include "Quirks.h"
+
+#define QUIRKS WalrusRPG::Quirks
+
+void QUIRKS::init()
+{
+}
+
+void QUIRKS::deinit()
+{
+}

+ 32 - 0
platform/sfml/Texture.cpp

@@ -0,0 +1,32 @@
+#include "Texture.h"
+#include <SFML/Graphics/Texture.hpp>
+#include <SFML/OpenGL.hpp>
+#include <cstdint>
+#include "utility/misc.h"
+
+#define TEXTURE WalrusRPG::Graphics::Texture
+
+TEXTURE::Texture(char *data) : data()
+{
+    UNUSED(data);
+    // TOOD : load from PIAF
+    this->data.loadFromFile("art/overworld.png");
+}
+
+TEXTURE::~Texture()
+{
+}
+
+WalrusRPG::Utils::Rect TEXTURE::get_dimensions()
+{
+    sf::Vector2u size = data.getSize();
+    return WalrusRPG::Utils::Rect(0, 0, size.x, size.y);
+}
+
+const WalrusRPG::Graphics::Pixel TEXTURE::get_pixel(unsigned x, unsigned y)
+{
+    UNUSED(x);
+    UNUSED(y);
+    // TODO : return the actual value
+    return WalrusRPG::Graphics::Pixel(0);
+}

+ 20 - 0
platform/sfml/Timing.cpp

@@ -0,0 +1,20 @@
+#include "Timing.h"
+#include <SFML/System/Clock.hpp>
+#include <cstdio>
+
+#define TIMING WalrusRPG::Timing
+
+sf::Clock clock;
+
+void TIMING::init()
+{
+}
+
+void TIMING::deinit()
+{
+}
+
+unsigned TIMING::gettime()
+{
+    return clock.getElapsedTime().asMicroseconds();
+}

+ 10 - 0
platform/sfml/public/platform.h

@@ -0,0 +1,10 @@
+#ifndef INCLUDE_PLATFORM_H
+#define INCLUDE_PLATFORM_H
+
+#include <SFML/Graphics/Texture.hpp>
+
+#define TIMER_FREQ 1000000
+
+typedef sf::Texture texture_data_t;
+
+#endif

+ 19 - 0
platform/sfml/rules.mk

@@ -0,0 +1,19 @@
+sfml_LOCAL_PATH := $(call whereami)
+
+SRCS_C += $(wildcard $(sfml_LOCAL_PATH)/platform/*.c)
+SRCS_CPP += $(wildcard $(sfml_LOCAL_PATH)/*.cpp)
+INCLUDE += $(sfml_LOCAL_PATH)/public
+
+LDFLAGS += -lstdc++ -lsfml-window -lsfml-graphics -lsfml-system -lGL
+
+CC = gcc
+CPP = g++
+
+PLATFORM = sfml
+EXE = $(OUT)/$(NAME)
+
+$(EXE): $(ELF)
+	@cp $(ELF) $(EXE)
+
+run: all
+	./$(EXE)

+ 8 - 0
platform/sfml/sfwindow.h

@@ -0,0 +1,8 @@
+#ifndef INCLUDE_SFWINDOW_H
+#define INCLUDE_SFWINDOW_H
+
+#include <SFML/Graphics/RenderWindow.hpp>
+
+extern sf::RenderWindow window;
+
+#endif

+ 7 - 2
src/engine/StateMachine.cpp

@@ -19,6 +19,8 @@ STATEMACHINE::StateMachine(State *state)
 
 STATEMACHINE::~StateMachine()
 {
+    while (!stack.empty())
+        pop();
 }
 
 void STATEMACHINE::push(State *state)
@@ -55,8 +57,11 @@ void STATEMACHINE::run()
             last_frame = frame_stamp;
 
             Text::print_format(0, 0, "WalrusRPG test build %s", git_version);
-            Text::print_format(0, 240 - 8, "%ufps, %uups", TIMER_FREQ / frame_time,
-                               TIMER_FREQ / update_time);
+            if (frame_time != 0 && update_time != 0)
+            {
+                Text::print_format(0, 240 - 8, "%ufps, %uups", TIMER_FREQ / frame_time,
+                                   TIMER_FREQ / update_time);
+            }
             Graphics::frame_end();
         }
 

+ 0 - 1
src/engine/main.cpp

@@ -4,7 +4,6 @@
 #include "Quirks.h"
 #include "map/Map.h"
 #include "map/StateMap.h"
-#include "render/Pixel.h"
 #include "utility/misc.h"
 
 using namespace WalrusRPG;

+ 1 - 1
src/map/Map.cpp

@@ -22,7 +22,7 @@ MAP::Map(int width, int height, uint16_t *layer0, uint16_t *layer1) : anim()
 
 MAP::~Map()
 {
-    // TODO if you allocate dynamically members
+    delete this->renderer;
 }
 
 void MAP::update(unsigned dt)