Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesAverill committed Oct 10, 2023
0 parents commit e0e7182
Show file tree
Hide file tree
Showing 24 changed files with 575 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: CI

on:
push:
branches: [ main ]

jobs:
build_test:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Use OCaml 4.13.x
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: 4.13.x

- name: Install Dependencies
run: |
opam install . --deps-only --with-test
eval $(opam env)
- name: Build Emulator
run: make build

- name: Run Unit Tests
run: make test

build_docs:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Use OCaml 4.13.x
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: 4.13.x

- name: Install Dependencies
run: |
opam install . --deps-only --with-doc
eval $(opam env)
- name: Build Documentation
run: |
make docs
- name: Copy documentation to gh-pages branch
uses: actions/upload-artifact@v3
with:
name: docs
path: docs
retention-days: 1

publish_docs:
runs-on: ubuntu-latest
needs: build_docs

steps:
- uses: actions/checkout@v2
with:
ref: gh-pages

- name: Download documentation files
uses: actions/download-artifact@v2
with:
name: docs
path: docs

- name: Commit
uses: EndBug/add-and-commit@v9
with:
author_name: Charles Averill
author_email: [email protected]
message: "Latest docs - ${{ github.event.repository.updated_at}}"
branch: gh-pages
add: '[./*]'
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*~
*.annot
*.cmo
*.cma
*.cmi
*.a
*.o
*.cmx
*.cmxs
*.cmxa
_build
1 change: 1 addition & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=0.25.1
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ocaml.sandbox": {
"kind": "opam",
"switch": "/home/charles/_opam"
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Charles Averill

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
76 changes: 76 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.PHONY: default build install uninstall test clean fmt
.IGNORE: fmt

default: build

fmt:
opam exec -- dune build @fmt
opam exec -- dune promote

build: fmt
opam exec -- dune build

install:
opam exec -- dune install

uninstall:
opam exec -- dune uninstall

clean:
opam exec -- dune clean
git clean -dfXq

test: fmt
opam exec -- dune runtest

testf: fmt
opam exec -- dune runtest -f

run: build
opam exec -- dune exec -- zenith

raw_run: build
clear
_build/default/bin/main.exe

debug: build
opam exec -- ocamldebug _build/default/zenith/main.bc

DOCS_PATH=docs/
DOCS_NAME=zenith
DOCS_DESCR=Zen Engine for Navigating wIreframes In Three-dimensional Holographic space
DOCS_INDEX_TITLE=$(DOCS_NAME) - $(DOCS_DESCR)
define DOCS_EMBED
<meta content="$(DOCS_NAME)" property="og:title" />\
<meta content="$(DOCS_DESCR)" property="og:description" />\
<meta content="https://github.com/CharlesAverill/zenith" property="og:url" />
endef

cleandocs:
if [ ! -d $(DOCS_PATH) ]; then \
mkdir $(DOCS_PATH); \
fi
rm -rf $(DOCS_PATH)module $(DOCS_PATH)docs $(DOCS_PATH)odoc.support $(DOCS_PATH)index.html

docs: cleandocs build
opam exec -- dune build @doc
mv -f _build/default/_doc/_html/* $(DOCS_PATH)
rm -f $(DOCS_PATH)index.html
mv $(DOCS_PATH)zenith/zenith.html $(DOCS_PATH)index.html
mv $(DOCS_PATH)zenith $(DOCS_PATH)module

@echo "Preparing Index\n--------------"
# Header
sed -i 's/<title>.*<\/title>/<title>$(DOCS_INDEX_TITLE)<\/title>/g' $(DOCS_PATH)index.html
sed -i 's@</head>@$(DOCS_EMBED)\n</head>@g' $(DOCS_PATH)index.html
sed -i 's/..\/odoc.support/odoc.support/g' $(DOCS_PATH)index.html
# Body
sed -i "s@<nav class="odoc-nav">.*gbcamel</nav>@@g" $(DOCS_PATH)index.html

push: cleandocs build
@read -p "Commit message: " input; \
if [ -z "$input" ]; then \
echo "Error: Please provide a valid commit message."; \
exit 1; \
fi; \
git add . && git commit -m "$$input" && git push origin main
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Friendly OCaml Template

Just run `setup.sh` to set up a ready-for-development OCaml environment

## Warning
Project description and synopsis should not include single quotes

## Docs note
Once you modify `docs/PROJECT_NAME.mld` to contain multiple sections, the `up - PROJECT_NAME` navigation at the top of the index page will disappear, and a navigation sidebar will replace it

## License
The default license generated is MIT, but feel free to change it. <b>THIS TEMPLATE IS LICENSED UNDER THE UNLICENSE</b>

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org>
4 changes: 4 additions & 0 deletions bin/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(executable
(public_name zenith)
(name main)
(libraries zenith graphics))
28 changes: 28 additions & 0 deletions bin/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
open Graphics
open Zenith.Mesh
open Zenith.Render
open List

let clear_window color =
let fg = foreground in
set_color color;
fill_rect 0 0 (size_x ()) (size_y ());
set_color fg

let break_mainloop = ref false

let draw_scene () =
clear_window black;
set_color white;
draw_meshes (project_clip_meshes (size_x ()) (size_y ()) 0. 10. [ cube ]);
let input = wait_next_event [ Mouse_motion; Button_down ] in
synchronize ();
if input.button then break_mainloop := true else ()

let rec main_loop () =
draw_scene ();
if !break_mainloop then () else main_loop ()

let () =
open_graph " 800x600";
main_loop ()
3 changes: 3 additions & 0 deletions docs/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(documentation
(package zenith)
(mld_files zenith))
3 changes: 3 additions & 0 deletions docs/zenith.mld
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{0 Index}

Hello World!
23 changes: 23 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(lang dune 3.9)

(name zenith)

(generate_opam_files true)

(source
(github CharlesAverill/zenith))

(authors "Charles Averill")

(maintainers "Charles Averill")

(license LICENSE)

(documentation https://github.com/CharlesAverill/zenith)

(package
(name zenith)
(synopsis "A wireframe renderer")
(description "Zen Engine for Navigating wIreframes In Three-dimensional Holographic space")
(depends ocaml dune graphics))

1 change: 1 addition & 0 deletions lib/constants.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let pi = 3.141592
4 changes: 4 additions & 0 deletions lib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(library
(name zenith)
(modules render vector matrix mesh constants logging)
(libraries graphics))
81 changes: 81 additions & 0 deletions lib/logging.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
(** logging.ml - Custom logging and error messages *)

(** Represents the severity of a log statement *)
type log_type =
| Log_None
| Log_Debug
| Log_Info
| Log_Warning
| Log_Error
| Log_Critical

let _GLOBAL_LOG_LEVEL = Log_Info

(** Follows the order in the type definition, \[0:5\]*)
let int_of_log = function
| Log_Debug -> 1
| Log_Info -> 2
| Log_Warning -> 3
| Log_Error -> 4
| Log_Critical -> 5
| Log_None -> 0

type return_code = int * string
(** For exits, their appropriate return code and the message type *)

let rc_Ok = (0, "OK")
and rc_Error = (1, "ERROR")
and rc_OOB = (2, "OUT OF BOUNDS ERROR")

(** ANSI encoding for bold text *)
let ansi_bold = "\x1b[1m"

(** ANSI encoding for red text *)
let ansi_red = "\x1b[38:5:196m"

(** ANSI encoding for orange text *)
let ansi_orange = "\x1b[38:5:208m"

(** ANSI encoding for yellow text *)
let ansi_yellow = "\x1b[38:5:178m"

(** ANSI encoding for plain text *)
let ansi_reset = "\x1b[0m"

(** ANSI encoding for bold red text *)
let error_red = ansi_bold ^ ansi_red

(** ANSI encoding for bold orange text *)
let error_orange = ansi_bold ^ ansi_orange

(** ANSI encoding for bold yellow text *)
let error_yellow = ansi_bold ^ ansi_yellow

(** Gets the string representation of a {!log_type}*)
let string_of_log = function
| Log_Debug -> ansi_bold ^ "[DEBUG]"
| Log_Info -> ansi_bold ^ "[INFO]"
| Log_Warning -> ansi_yellow ^ "[WARNING]"
| Log_Error -> ansi_orange ^ "[ERROR]"
| Log_Critical -> ansi_red ^ "[CRITICAL]"
| Log_None -> ansi_reset ^ "[NONE]"

(** A fatal log statement that immediately exits the program *)
let fatal rc message =
Printf.fprintf stderr
"%s[%s] - %s%s\n----------------------------------------\n" error_red
(snd rc) ansi_reset message;
flush stderr;
exit (fst rc)

(** Prints log statements to stdout/stderr *)
let _log log_level message =
if log_level = Log_None || int_of_log _GLOBAL_LOG_LEVEL > int_of_log log_level
then ()
else
let stream =
if log_level = Log_Debug || log_level = Log_Info then stdout else stderr
in
Printf.fprintf stream "LOG:%s%s - %s\n" (string_of_log log_level) ansi_reset
message;
flush stream
Loading

0 comments on commit e0e7182

Please sign in to comment.