Browse Source

Added example project, updated readme

* Example project is a quick way to start a new project using
base2.0.
* ReadMe is now in Org format and uses the Jam commands rather than
the outdated make commands
master
Macoy Madson 4 months ago
parent
commit
9785acd84b
9 changed files with 263 additions and 54 deletions
  1. +5
    -1
      .gitignore
  2. +3
    -0
      Build_Release.sh
  3. +0
    -53
      README.md
  4. +49
    -0
      ReadMe.org
  5. +3
    -0
      example/Build_Debug.sh
  6. +3
    -0
      example/Build_Release.sh
  7. +3
    -0
      example/Jamfile
  8. +103
    -0
      example/Jamrules
  9. +94
    -0
      example/main.cpp

+ 5
- 1
.gitignore View File

@@ -31,4 +31,8 @@ LOCAL*
~*
*~

bin/
bin/

imgui.ini
TestBase20
example/exampleBase

+ 3
- 0
Build_Release.sh View File

@@ -0,0 +1,3 @@
#!/bin/sh

jam -j4

+ 0
- 53
README.md View File

@@ -1,53 +0,0 @@
# Base2.0
A simple game library and abstraction layer for SFML 2.2

Setup
-----
You need SFML 2.0 installed if you have base2.0, or SFML 1.6 if you have base.

It's then really easy from there; just
make
make tools
sudo make install
sudo make installTools

If you want to clean up:
sudo make clean
sudo make cleanTools

Installing the library will result in the following:
* /usr/include/base2.0 will contain all of the header files. To use them:
#include <base2.0/module/module.hpp>
* /usr/lib will contain libbase2.0.a or libbase.a . Use these when linking like so:
g++ -o "myProj" myProj.o -lbase2.0 [or -lbase] -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system
* The Tile Map Editor (tileEditor) binary will be added to /usr/bin
* "tle.desktop" will be added to /usr/share/applications, which adds the Tile Map Editor to the Ubuntu Dash

Cleaning will undo all of these changes.

Basic Use (installed)
------
#include <base[or base2.0]/module/module.hpp>

To link:
g++ -o "myProj" myProj.o -lbase [or -lbase2.0] -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system

Basic Use (not installed)
------
#include "/path/to/base/module/module.hpp"

To link:
g++ -o "myProj" myProj.o "/path/to/base/lib/base.a" -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system

About
------
Base/Base2.0 are my game libraries and SFML abstraction layers. I've built it with the goal of a simple interface and maximum multimedia library independence. You are free to use Base in any way you want (but don't sell it).

Questions? Email me: macoymadson@gmail.com

[Check out my website.](http://macoy.me/)

Compiling SFML from Source
-------
For Ubuntu:
sudo apt install libopenal-dev libvorbis-dev libflac-dev libglew

+ 49
- 0
ReadMe.org View File

@@ -0,0 +1,49 @@
#+TITLE:Base2.0
A simple game library and abstraction layer. It uses SFML to provide most functionality, then groups it together with other tools.

* Setup


** Clone repository
Clone and init submodules for dependencies:

#+BEGIN_SRC sh
git clone --recurse-submodules https://github.com/makuto/spargus-vehicle-prototype
#+END_SRC

If you didn't do submodules, run this:

#+BEGIN_SRC sh
git submodule update --init --recursive
#+END_SRC
** Set up build system
Jam is used to build the project. Install Jam:

#+BEGIN_SRC sh
sudo apt install jam
#+END_SRC

** Build dependencies
Currently, SFML relies on system installs for its dependencies:

#+BEGIN_SRC sh
sudo apt install libopenal-dev libvorbis-dev libflac-dev libglew
#+END_SRC

Build the rest of the dependencies from source:

#+BEGIN_SRC sh
./BuildDependencies_Release.sh
#+END_SRC

Use the ~*_Debug.sh~ scripts if you want debug symbols. Note that you need to use Debug/Release scripts in every case, otherwise the libraries will fail to link.

** Build example project
The example project is a good starting point for a new project. Build it like so:

#+BEGIN_SRC sh
cd example
./Build_Release.sh
#+END_SRC

Run ~./exampleBase~ to see the project.

+ 3
- 0
example/Build_Debug.sh View File

@@ -0,0 +1,3 @@
#!/bin/sh

jam -j4 -sDEBUG_BUILD=True

+ 3
- 0
example/Build_Release.sh View File

@@ -0,0 +1,3 @@
#!/bin/sh

jam -j4

+ 3
- 0
example/Jamfile View File

@@ -0,0 +1,3 @@
SubDir . ;

Main exampleBase : main.cpp ;

+ 103
- 0
example/Jamrules View File

@@ -0,0 +1,103 @@
##
## Compilation
##

C++ = clang++ ;
LINK = clang++ ;

# C++ = g++ ;
# LINK = g++ ;

# If I was building a library, these would be useful
# LINKFLAGS = -shared ;
# if $(UNIX) { SUFSHR = .so ; }
# else if $(NT) { SUFSHR = .dll ; }

## Compiler arguments

# Arguments used on all projects, regardless of any variables
# Note that Tracy 0.6.5 requires c++14 (normally C++11 would be fine)
C++FLAGS = -std=c++14 -stdlib=libstdc++
-Wall -Wextra -Wno-unused-parameter
-g
;

# This should be the only thing you need to change for a new project
BASE2_DIR = ../ ;

HDRS =
$(BASE2_DIR)
$(BASE2_DIR)/dependencies/SFML/include
$(BASE2_DIR)/dependencies/imgui
$(BASE2_DIR)/dependencies/imgui-sfml
# Dependencies/glm
;

# TODO: Make base hold all this weirdness?
if $(DEBUG_BUILD)
{
SFML_LINKLIBS = -lsfml-audio-d -lsfml-graphics-d -lsfml-window-d -lsfml-system-d ;
}
else
{
SFML_LINKLIBS = -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system ;
}

OPTIM = -O0 ;

##
## Linking
##

LINKLIBS =
# Standard (e.g. for Tracy)
-lpthread -ldl

# SFML
-L$(BASE2_DIR)/dependencies/SFML/lib
$(SFML_LINKLIBS)

# OpenGL
-lGL
-lGLU
-lGLEW

# Base
-L$(BASE2_DIR) -lBase20
;

# LINKFLAGS = -Wl,-rpath,. ;

# TODO: Copy libs to better directory, or static link?
LINKFLAGS = -g -stdlib=libstdc++
-Wl,-rpath,.:$(BASE2_DIR)/dependencies/SFML/lib ;

##
## Jam stuff
##

# Fix for unnecessary rebuilding any Jam project
KEEPOBJS = true ; # This doesn't actually fix anything, though it seems like it should
NOARSCAN = true ; # This actually fixes the problem
#AR = ar rUu ; # I was thinking maybe the AR command was wrong (always outputting deterministically)
# It doesn't seem like this is the problem though
AR = ar cr ;

# Cross compilation
# E.g.
# jam -j4 -q -sCROSS_COMPILE_WINDOWS=true
# if $(CROSS_COMPILE_WINDOWS)
# {
# CC = x86_64-w64-mingw32-gcc ;
# LINK = x86_64-w64-mingw32-gcc ;
# AR = x86_64-w64-mingw32-ar ;
# SUFSHR = .dll ;
# }

# Some helpful Jam commands
# -q : stop on failed target
# -jN : use N cores
# -sVAR=VAL : Set VAR to VAL. Note that setting WINDOWS=false is the same as setting UNREAL=true,
# frustratingly
# -dx : print commands being used
# -n : don't actually run commands

+ 94
- 0
example/main.cpp View File

@@ -0,0 +1,94 @@
#include <SFML/System.hpp>
#include <iostream>

#include "graphics/graphics.hpp"
#include "imgui-SFML.h"
#include "imgui.h"
#include "input/input.hpp"

int WindowWidth = 1920;
int WindowHeight = 1080;
#define WIN_BACKGROUND_COLOR 20, 20, 20, 255

void initializeWindow(window& win)
{
{
sf::ContextSettings settings = win.getBase()->getSettings();

std::cout << "depth bits:" << settings.depthBits << "\n";
std::cout << "stencil bits:" << settings.stencilBits << "\n";
std::cout << "antialiasing level:" << settings.antialiasingLevel << "\n";
std::cout << "version:" << settings.majorVersion << "." << settings.minorVersion << "\n";
}

win.setBackgroundColor(WIN_BACKGROUND_COLOR);

// Show the window as soon as we can
// shouldClose manages some state
win.shouldClose();
win.update();

win.shouldClear(true);
win.getBase()->setVerticalSyncEnabled(true);
win.getBase()->setFramerateLimit(60);
}

void windowResizeCB(float width, float height)
{
WindowWidth = width;
WindowHeight = height;
}

void initializeImGui(window& win)
{
ImGui::SFML::Init(*(win.getBase()));

// For high-DPI screens
// These don't actually work
// ImGuiStyle& style = ImGui::GetStyle();
// style.ScaleAllSizes(1.7f);
// style.Alpha = 0.75f;
}

int main()
{
std::cout << "Base2.0 example project\n";

window mainWindow(WindowWidth, WindowHeight, "Base2.0 Example", &windowResizeCB);
initializeWindow(mainWindow);

inputManager input(&mainWindow);

// If you're painting the whole window, you should uncomment this
// mainWindow.shouldClear(false);

sf::Clock imguiDeltaClock;
initializeImGui(mainWindow);

// A made up but sane first frame
float previousFrameTime = 0.016f;
timer frameTimer;
frameTimer.start();

while (!input.isPressed(inputCode::Escape))
{
// Poll events for ImGui and close state
bool shouldClose =
mainWindow.pollEventsUpdateState([](sf::RenderWindow* win, const sf::Event& event) {
ImGui::SFML::ProcessEvent(event);
});
if (shouldClose)
break;

ImGui::SFML::Update(*mainWindow.getBase(), imguiDeltaClock.restart());
ImGui::ShowDemoWindow();
ImGui::SFML::Render(*mainWindow.getBase());

mainWindow.update();

previousFrameTime = frameTimer.getTime();
frameTimer.start();
}

return 0;
}

Loading…
Cancel
Save