Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ cmake_minimum_required(VERSION 3.25.1)

project(4thand5-cli VERSION 0.0.1 LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(COMPONENT_NAME 4thand5-cli)
set(CFG_DIR ${PROJECT_SOURCE_DIR}/config)
set(SRC_DIR ${PROJECT_SOURCE_DIR}/src)
set(SCR_DIR ${PROJECT_SOURCE_DIR}/scripts)
set(TST_DIR ${PROJECT_SOURCE_DIR}/tests)
Expand All @@ -29,6 +30,7 @@ install(

install(
FILES
${CFG_DIR}/4thand5
TYPE DATA
COMPONENT ${COMPONENT_NAME}
)
Expand Down
1 change: 1 addition & 0 deletions config/4thand5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
+---------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----------+| | | 1 | 0 | 2 | 0 | 3 | 0 | 4 | 0 | 5 | 0 | 4 | 0 | 3 | 0 | 2 | 0 | 1 | 0 | || | | | | | | | | | | | | | | | | | | | | || | | | | | | | | | | | | | | | | | | | | || | | | | | | | | | | | | | | | | | | | | || | | | | | | | | | | | | | | | | | | | | |+---------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----------+
67 changes: 29 additions & 38 deletions src/4thand5.m.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include <chrono>
#include <algorithm>
#include <array>
#include <csignal>
#include <cstddef>
#include <fstream>
#include <iostream>
#include <iterator>
#include <ncurses.h>
#include <string>
#include <vector>
Expand All @@ -25,72 +29,59 @@ int main(int argc, char *argv[])

(void)std::signal(SIGINT, signalHandler);

// Initialize configuration
std::array<char, 959uz> configuration{};
std::ifstream configFile("/usr/share/4thand5");
if (configFile.is_open()) {
(void)std::copy(std::istreambuf_iterator<char>(configFile), std::istreambuf_iterator<char>(), std::begin(configuration));
}

configFile.close();

// Initialize data
fourthandfive::GameState gameState {
.homeTeamId = 0,
.awayTeamId = 0,
.homeTeamScore = 0,
.awayTeamScore = 0,
.homeTeamTO = 3,
.awayTeamTO = 3,
.possession = 0,
.down = 0,
.distance = 10,
.yardLine = 0,
.period = 0,
.clock = std::chrono::seconds(900)
};
gameState.homeTeamId = getGameData(0);
std::vector<fourthandfive::GameData> gameDataLog{};
gameDataLog = getGameData(0);

// Initialize data views
std::vector<std::vector<char>> fieldView = {
{'+', '-', '-', '-', '-', '-', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '-', '-', '-', '-', '-', '+'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', '1', '|', '0', ' ', ' ', ' ', '|', ' ', ' ', ' ', '2', '|', '0', ' ', ' ', ' ', '|', ' ', ' ', ' ', '3', '|', '0', ' ', ' ', ' ', '|', ' ', ' ', ' ', '4', '|', '0', ' ', ' ', ' ', '|', ' ', ' ', ' ', '5', '|', '0', ' ', ' ', ' ', '|', ' ', ' ', ' ', '4', '|', '0', ' ', ' ', ' ', '|', ' ', ' ', ' ', '3', '|', '0', ' ', ' ', ' ', '|', ' ', ' ', ' ', '2', '|', '0', ' ', ' ', ' ', '|', ' ', ' ', ' ', '1', '|', '0', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'+', '-', '-', '-', '-', '-', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '+', '-', '-', '-', '-', '-', '-', '-', '-', '-', '+'}
};
const std::size_t fieldViewRowSize = 137uz;
const std::size_t fieldViewSize = fieldViewRowSize * 7uz;
std::array<char, fieldViewSize> fieldView{};
(void)std::copy(std::begin(configuration), std::end(configuration), std::begin(fieldView));

// Initialize rendering [ncurses]
(void)initscr();
(void)nonl();

// Core loop [input processing + output rendering]
const int cmdLimit = 5;
char cmd[cmdLimit + 1] = {0};
int minX = 0, minY = 0, maxX = 0, maxY = 0;
std::array<char, 5uz> cmd{};
unsigned int minX = 0, minY = 0, maxX = 0, maxY = 0;
while (true) {
// Check window sizing
(void)getbegyx(stdscr, minY, minX);
(void)getmaxyx(stdscr, maxY, maxX);
// TODO: window size minimums + resizing

// Perform command
// TODO: logic updates
// TODO: logic updates: cmd

// Buffer rendering
(void)wmove(stdscr, minY, minX);
for (int fieldRow = 0; fieldRow < fieldView.size(); fieldRow++) {
for (int fieldCol = 0; fieldCol < fieldView[fieldRow].size(); fieldCol++) {
(void)wmove(stdscr, fieldRow, fieldCol);
(void)waddch(stdscr, fieldView[fieldRow][fieldCol]);
for (std::size_t fieldViewRow = 0; fieldViewRow < fieldView.size() / fieldViewRowSize; fieldViewRow++) {
for (std::size_t fieldViewCol = 0; fieldViewCol < fieldViewRowSize; fieldViewCol++) {
(void)wmove(stdscr, fieldViewRow, fieldViewCol);
(void)waddch(stdscr, fieldView[(fieldViewRowSize * fieldViewRow) + fieldViewCol]);
}
}

(void)wmove(stdscr, fieldView.size(), minX);
(void)wclrtoeol(stdscr);
(void)waddnstr(stdscr, cmd, cmdLimit);
(void)wmove(stdscr, maxY - 1, minX);
(void)wclrtoeol(stdscr);

// Render output
(void)wrefresh(stdscr);

// Reset cursor to input await command
wmove(stdscr, maxY - 1, minX);
wgetnstr(stdscr, cmd, cmdLimit);
(void)wmove(stdscr, maxY - 1, minX);
(void)wgetnstr(stdscr, cmd.data(), cmd.size());
}

// Cleanup
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
set(EXECUTABLE_NAME 4thand5)

add_subdirectory(feeds)
add_subdirectory(feed)
add_subdirectory(game_data)

add_executable(${EXECUTABLE_NAME})

target_link_libraries(${EXECUTABLE_NAME}
PRIVATE
ncurses
feeds # local
feed # local
game_data # local
)

Expand Down
3 changes: 2 additions & 1 deletion src/feeds/CMakeLists.txt → src/feed/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
set(LIBRARY_NAME feeds)
set(LIBRARY_NAME feed)

add_library(${LIBRARY_NAME} STATIC)

target_link_libraries(${LIBRARY_NAME}
PUBLIC
game_data # local
INTERFACE
PRIVATE
)
Expand Down
27 changes: 27 additions & 0 deletions src/feed/feed.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "feed.h"

#include <chrono>

namespace fourthandfive {

std::vector<GameData> getGameData(const int gameId) {
return {
{
.homeTeamId = 0,
.awayTeamId = 0,
.homeTeamScore = 0,
.awayTeamScore = 0,
.homeTeamTO = 3,
.awayTeamTO = 3,
.possession = 0,
.down = 0,
.distance = 10,
.yardLine = 0,
.period = 0,
.clock = std::chrono::seconds(900)
}
};
}

} // close namespace fourthandfive

8 changes: 5 additions & 3 deletions src/feeds/feed.h → src/feed/feed.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef FOURTHANDFIVE_FEED_H
#define FOURTHANDFIVE_FEED_H

#include <string>
#include <vector>

#include "game_data.h"

namespace fourthandfive {
/**
Expand All @@ -10,9 +12,9 @@ namespace fourthandfive {
* Retrieve game data from provider feed.
*
* @param gameId Game ID
* @return Game data
* @return Game log
*/
int getGameData(const int gameId);
std::vector<GameData> getGameData(const int gameId);
} // close namespace fourthandfive

#endif /* FOURTHANDFIVE_FEED_H */
Expand Down
10 changes: 0 additions & 10 deletions src/feeds/feed.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/game_data/game_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace fourthandfive {

struct GameState {
struct GameData {
unsigned int homeTeamId{0};
unsigned int awayTeamId{0};
unsigned int homeTeamScore{0};
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_executable(4thand5.i.t)
target_link_libraries(4thand5.i.t
PRIVATE
Catch2::Catch2WithMain
feeds # local
feed # local
)

target_sources(4thand5.i.t
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/feed.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace fourthandfive {

TEST_CASE( "Test Game Data Feed", "[feed]" ) {
REQUIRE( getGameData(0) == 42 );
REQUIRE( getGameData(0).size() >= 0uz );
}

} // close namespace fourthandfive
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_executable(4thand5.u.t)
target_link_libraries(4thand5.u.t
PRIVATE
Catch2::Catch2WithMain
feeds # local
feed # local
)

target_sources(4thand5.u.t
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/feed.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace fourthandfive {

TEST_CASE( "Test Game Data Feed", "[feed]" ) {
REQUIRE( getGameData(0) == 42 );
REQUIRE( getGameData(0).size() >= 0uz );
}

} // close namespace fourthandfive
Expand Down