Browse Source

Merge branch 'master' into piaf_integration

Eiyeron Fulmincendii 10 years ago
parent
commit
d2befaec04

+ 2 - 1
.gitignore

@@ -1,4 +1,5 @@
 out/
+release/
 config.mk
 
 *.swp
@@ -10,4 +11,4 @@ config.mk
 
 # Sublime
 *.sublime-project
-*.sublime-workspace
+*.sublime-workspace

+ 1 - 0
platform/include/Input.h

@@ -31,6 +31,7 @@ namespace WalrusRPG
 
         void key_poll();
 
+        KeyState key_get_state(Key key);
         bool key_pressed(Key key);
         bool key_released(Key key);
         bool key_down(Key key);

+ 2 - 2
platform/nspire/Graphics.cpp

@@ -60,7 +60,7 @@ void Graphics::put_horizontal_line(uint16_t x, uint16_t x2, uint16_t y,
         x = x2;
         x2 = temp;
     }
-    for (; x < x2; x++)
+    for (; x <= x2; x++)
     {
         CXfb::draw_pixel(x, y, color);
     }
@@ -74,7 +74,7 @@ void Graphics::put_vertical_line(uint16_t x, uint16_t y, uint16_t y2, const Pixe
         y = y2;
         y2 = temp;
     }
-    for (; y < y2; y++)
+    for (; y <= y2; y++)
     {
         CXfb::draw_pixel(x, y, color);
     }

+ 6 - 1
platform/nspire/Input.cpp

@@ -20,9 +20,14 @@ static InputMap key_map[] = {
     {Key::K_UP, KEY_NSPIRE_8},       {Key::K_DOWN, KEY_NSPIRE_5},
     {Key::K_LEFT, KEY_NSPIRE_4},     {Key::K_RIGHT, KEY_NSPIRE_6},
 
-    {Key::K_START, KEY_NSPIRE_HOME}, {Key::K_SELECT, KEY_NSPIRE_ESC},
+    {Key::K_START, KEY_NSPIRE_DOC}, {Key::K_SELECT, KEY_NSPIRE_ESC},
 };
 
+KeyState INPUT::key_get_state(Key key)
+{
+        return key_states[key];
+}
+
 void INPUT::key_poll()
 {
     for (unsigned i = 0; i < K_SIZE; i++)

+ 3 - 3
platform/sfml/Graphics.cpp

@@ -91,12 +91,12 @@ void Graphics::put_pixel(uint16_t x, uint16_t y, const Pixel &color)
 void Graphics::put_horizontal_line(uint16_t x, uint16_t x2, uint16_t y,
                                    const Pixel &color)
 {
-    put_line(x, y, x2, y, color);
+    put_rectangle({x,y,x2-x+1, 1}, color);
 }
 
 void Graphics::put_vertical_line(uint16_t x, uint16_t y, uint16_t y2, const Pixel &color)
 {
-    put_line(x, y, x, y2, color);
+    put_rectangle({x,y, 1, y2-y+1}, color);
 }
 
 void Graphics::put_line(uint16_t x, uint16_t y, uint16_t x2, uint16_t y2,
@@ -104,7 +104,7 @@ void Graphics::put_line(uint16_t x, uint16_t y, uint16_t x2, uint16_t y2,
 {
     sf::Color lineColor(color.r << 3, color.g << 2, color.b << 3);
     sf::Vertex line[] = {sf::Vertex(sf::Vector2f(x, y), lineColor),
-                         sf::Vertex(sf::Vector2f(x2, y2), lineColor)};
+                         sf::Vertex(sf::Vector2f(x2+1, y2+1), lineColor)};
 
     buffer.draw(line, 2, sf::Lines);
 }

+ 5 - 0
platform/sfml/Input.cpp

@@ -32,6 +32,11 @@ InputMap key_map[] = {
     {Key::K_SELECT, Keyboard::BackSpace, Keyboard::Unknown},
 };
 
+KeyState INPUT::key_get_state(Key key)
+{
+        return key_states[key];
+}
+
 void INPUT::key_poll()
 {
     bool hasFocus = window.hasFocus();

+ 15 - 1
rules.mk

@@ -1,9 +1,11 @@
-.PHONY: format clean all run versionning include
+.PHONY: format clean all run versionning include release bundle
 
 all: $(EXE)
 
 include $(wildcard */rules.mk)
 
+RELEASE_DIRECTORY=release/$(PLATFORM)
+
 # Object dependency files
 -include $(OBJS:%.o=%.d)
 
@@ -34,6 +36,18 @@ clean:
 	@echo "RM: $(OUT)"
 	@rm -rf $(OUT)
 
+release: $(ELF)
+	@echo "Packing binary and data files into $(RELEASE_DIRECTORY)"
+	@mkdir -p "$(RELEASE_DIRECTORY)"
+	@cp $(ELF) "$(RELEASE_DIRECTORY)"
+	@cp -ru data "$(RELEASE_DIRECTORY)" 2>/dev/null || :
+
+bundle: release
+	@echo "Tar-zipping"
+	@tar cf "$(RELEASE_DIRECTORY).tar" "$(RELEASE_DIRECTORY)"
+	@gzip "$(RELEASE_DIRECTORY).tar" -f
+	@echo "Archive ready at $(RELEASE_DIRECTORY).tar.gzip"
+
 format:
 	@echo "Formatting source using clang-format"
 	@clang-format -i -style=file $(shell git ls-files -c -o --exclude-standard *.c *.cpp *.h)

+ 44 - 0
src/engine/StateMachine.cpp

@@ -10,9 +10,52 @@ using namespace WalrusRPG::Graphics;
 using namespace WalrusRPG::States;
 using namespace WalrusRPG::Timing;
 using WalrusRPG::Input::Key;
+using WalrusRPG::Input::KeyState;
 
 #define STATEMACHINE WalrusRPG::StateMachine
 
+namespace  {
+    void draw_button(unsigned x, unsigned y, KeyState state)
+    {
+        put_horizontal_line(x+1, x+5, y, Gray);
+        put_horizontal_line(x+1, x+5, y+6, Gray);
+        put_vertical_line(x, y+1, y+5, Gray);
+        put_vertical_line(x+6, y+1, y+5, Gray);
+        switch(state)
+        {
+            case KeyState::KS_RELEASED:
+                put_rectangle({x+1, y+1, 5, 5}, White);
+                break;
+            case KeyState::KS_JUST_RELEASED:
+                put_rectangle({x+1, y+1, 5, 5}, Magenta);
+                break;
+            case KeyState::KS_JUST_PRESSED:
+                put_rectangle({x+1, y+1, 5, 5}, Cyan);
+                break;
+            case KeyState::KS_PRESSED:
+                put_rectangle({x+1, y+1, 5, 5}, Black);
+                break;
+        }
+    }
+    void draw_buttons()
+    {
+        draw_button(0, 24, key_get_state(Key::K_L));
+        draw_button(56, 24, key_get_state(Key::K_R));
+
+        draw_button(8, 32, key_get_state(Key::K_UP));
+        draw_button(0, 40, key_get_state(Key::K_LEFT));
+        draw_button(16, 40, key_get_state(Key::K_RIGHT));
+        draw_button(8, 48, key_get_state(Key::K_DOWN));
+
+        draw_button(28, 48, key_get_state(Key::K_SELECT));
+        draw_button(36, 48, key_get_state(Key::K_START));
+
+        draw_button(48, 44, key_get_state(Key::K_B));
+        draw_button(56, 36, key_get_state(Key::K_A));
+
+    }
+} /* namespace  */
+
 STATEMACHINE::StateMachine(State *state)
 {
     push(state);
@@ -64,6 +107,7 @@ void STATEMACHINE::run()
                 // Text::print_format(0, 240 - 8, "%ufps, %uups", TIMER_FREQ / frame_time,
                 //                    TIMER_FREQ / update_time);
             }
+            draw_buttons();
             Graphics::frame_end();
         }
 

+ 4 - 0
src/render/Pixel.cpp

@@ -29,7 +29,11 @@ PIXEL &PIXEL::operator=(unsigned value)
 #define CONST_COLOR(color, r, g, b) \
     const WalrusRPG::Graphics::Pixel WalrusRPG::Graphics::color(r, g, b)
 CONST_COLOR(Black, 0, 0, 0);
+CONST_COLOR(DarkGray, 64, 64, 64);
+CONST_COLOR(Gray, 128, 128, 128);
+CONST_COLOR(LightGray, 192, 192, 192);
 CONST_COLOR(White, 255, 255, 255);
+
 CONST_COLOR(Red, 255, 0, 0);
 CONST_COLOR(Green, 0, 255, 0);
 CONST_COLOR(Blue, 0, 0, 255);

+ 3 - 0
src/render/Pixel.h

@@ -39,6 +39,9 @@ namespace WalrusRPG
         };
 
         extern const Pixel Black;
+        extern const Pixel LightGray;
+        extern const Pixel Gray;
+        extern const Pixel DarkGray;
         extern const Pixel White;
         extern const Pixel Red;
         extern const Pixel Green;