ソースを参照

SFML: IT DISPLAYS STUFF, MOTHERFUCKERS

Streetwalrus Einstein 10 年 前
コミット
b6bb4e59da
共有9 個のファイルを変更した167 個の追加1 個の削除を含む
  1. 1 1
      Makefile
  2. 1 0
      platform/nspire/rules.mk
  3. 44 0
      platform/sfml/Graphics.cpp
  4. 33 0
      platform/sfml/Input.cpp
  5. 11 0
      platform/sfml/Quirks.cpp
  6. 32 0
      platform/sfml/Texture.cpp
  7. 16 0
      platform/sfml/Timing.cpp
  8. 10 0
      platform/sfml/public/platform.h
  9. 19 0
      platform/sfml/rules.mk

+ 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 :=

+ 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)

+ 44 - 0
platform/sfml/Graphics.cpp

@@ -0,0 +1,44 @@
+#include "Graphics.h"
+#include <SFML/Graphics.hpp>
+#include "utility/misc.h"
+
+#define GRAPHICS WalrusRPG::Graphics
+
+sf::RenderWindow window;
+
+void GRAPHICS::init()
+{
+    window.setPosition(sf::Vector2i(sf::VideoMode::getDesktopMode().width / 2 - 160,
+                                    sf::VideoMode::getDesktopMode().height / 2 - 120));
+    window.create(sf::VideoMode(320, 240), "WalrusRPG");
+}
+
+void GRAPHICS::deinit()
+{
+    window.close();
+}
+
+void GRAPHICS::frame_begin()
+{
+    window.clear(sf::Color::Black);
+}
+
+void GRAPHICS::frame_end()
+{
+    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);
+    ::window.draw(sprite);
+}
+
+void GRAPHICS::fill(const WalrusRPG::Graphics::Pixel &color)
+{
+    UNUSED(color);
+}

+ 33 - 0
platform/sfml/Input.cpp

@@ -0,0 +1,33 @@
+#include "Input.h"
+
+#define INPUT WalrusRPG::Input
+
+bool INPUT::key_a()
+{
+    return false;
+}
+
+bool INPUT::key_b()
+{
+    return false;
+}
+
+bool INPUT::key_up()
+{
+    return false;
+}
+
+bool INPUT::key_down()
+{
+    return false;
+}
+
+bool INPUT::key_left()
+{
+    return false;
+}
+
+bool INPUT::key_right()
+{
+    return false;
+}

+ 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);
+}

+ 16 - 0
platform/sfml/Timing.cpp

@@ -0,0 +1,16 @@
+#include "Timing.h"
+
+#define TIMING WalrusRPG::Timing
+
+void TIMING::init()
+{
+}
+
+void TIMING::deinit()
+{
+}
+
+unsigned TIMING::gettime()
+{
+    return 1;
+}

+ 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 1000
+
+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)