Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LD41] Initial setup and rename basecode for LD41
- Loading branch information
Showing
61 changed files
with
27,859 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# | ||
# project: CardFish (LD41) | ||
# | ||
cmake_minimum_required(VERSION 2.8) | ||
|
||
#set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "Minimum OS X deployment version") | ||
set(MACOSX_DEPLOYMENT_TARGET 10.12) | ||
|
||
|
||
# include the fips main cmake file | ||
get_filename_component(FIPS_ROOT_DIR "../fips" ABSOLUTE) | ||
include("${FIPS_ROOT_DIR}/cmake/fips.cmake") | ||
|
||
# this hack is required for turbobadger since we need to make | ||
# sure that our overriden config.h is included | ||
#include_directories(../oryol-tbui/src/TBUI/tb) | ||
|
||
# force ORYOL_SAMPLE_URL to location of oryol-samples webpage | ||
#set(ORYOL_SAMPLE_URL "http://floooh.github.com/oryol-samples/data/" CACHE STRING "Samples URL" FORCE) | ||
|
||
set(MACOSX_DEPLOYMENT_TARGET 10.12) | ||
set(FIPS_EMSCRIPTEN_RELATIVE_SHELL_HTML "html/shell_cardfish.html") | ||
|
||
fips_setup() | ||
fips_project(ld41_cardfish) | ||
include_directories(code) | ||
|
||
|
||
# FIXME: only add tools directory to tools build | ||
fips_include_directories(tools/OpenDDL/Code) | ||
fips_include_directories(tools/OpenGEX/Code) | ||
fips_include_directories(tools/ldjamfile) | ||
|
||
fips_add_subdirectory(code) | ||
fips_add_subdirectory(tools) | ||
|
||
# Don't need these because auto_import is on in fips.yml | ||
# fips_ide_group("Oryol") | ||
# fips_import_oryol_Core() | ||
# fips_import_oryol_Gfx() | ||
# fips_import_oryol_IO() | ||
# fips_import_oryol_LocalFS() | ||
# fips_import_oryol_Assets() | ||
# fips_import_oryol_Resource() | ||
# fips_import_oryol_Input() | ||
# fips_ide_group("Libs") | ||
# fips_import_fips_glfw_glfw3() | ||
# fips_import_oryol_nuklear_NKUI() | ||
# fips_import_oryol_imgui_IMUI() | ||
# fips_ide_group("") | ||
|
||
fips_finish() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
LD41 CardFish | ||
----------------- | ||
joeld42@gmail.com | ||
|
||
README todo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import os, sys | ||
import string | ||
import subprocess | ||
import shutil | ||
|
||
# FIXME NOW: Make one gamedata directory per target platform | ||
|
||
PROJECT_DIR = '/Users/joeld/oprojects/ld41_cardfish' | ||
|
||
CRUNCH_TOOL = '/Users/joeld/Toolkits/crunch-osx/bin_osx/crunch' | ||
TEXTURETOOL_TOOL = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool' | ||
|
||
#BLENDER_TOOL = '/Applications/Blender/blender.app/Contents/MacOS/blender' | ||
#BLENDER_EXPORT_SCRIPT = 'export_scene.py' | ||
#-b srcart/forest.blend -P script/export_scene.py -- ld33_export.cfg | ||
|
||
LDJAM_TOOL = '/Users/joeld/oprojects/fips-deploy/ld41_cardfish/osx-xcode-debug/ldjamtool' | ||
|
||
#'./assets/TestLevelSF.ogex ./gamedata/TestLevelSF.ldjam' | ||
|
||
#ASSET_DIR = "assets" | ||
# TMP | ||
ASSET_DIR = "assets" | ||
OGEX_DIR = "assets" | ||
RUNTIME_DATA_DIR = "gamedata" | ||
|
||
TEXTURES = { | ||
|
||
'TestTile_basecolor.png' : 'DXT5', | ||
'TestTile_metallic.png' : 'DXT5', | ||
'TestTile_normal.png' : 'DXT5', | ||
'TestTile_roughness.png' : 'DXT5', | ||
} | ||
|
||
OGEX_FILES = { | ||
'TEST_Stuff.ogex', | ||
} | ||
|
||
def fileNeedsUpdate( srcFile, destFile ): | ||
if not os.path.exists( destFile ): | ||
print "DEST", destFile, "does not exist" | ||
return True | ||
|
||
destmtime = os.path.getmtime( destFile ) | ||
srcmtime = os.path.getmtime( srcFile ) | ||
|
||
if srcmtime >= destmtime: | ||
return True | ||
|
||
# file is up to date | ||
print destFile[ len(PROJECT_DIR)+1: ], "up to date." | ||
return False | ||
|
||
if __name__=='__main__': | ||
|
||
|
||
# ----------------------------------- | ||
# OGEX Scene Files | ||
# ----------------------------------- | ||
# TODO: Extract list of textures automatically from scenes | ||
for ogex in OGEX_FILES: | ||
|
||
srcFile = os.path.join( PROJECT_DIR, OGEX_DIR, ogex ) | ||
destFile = os.path.join( PROJECT_DIR, RUNTIME_DATA_DIR, os.path.splitext( ogex )[0] + ".ldjam" ) | ||
|
||
if fileNeedsUpdate(srcFile, destFile ): | ||
cmd = [ LDJAM_TOOL, | ||
srcFile, | ||
destFile ] | ||
|
||
print string.join(cmd, ' ' ) | ||
subprocess.call( cmd ) | ||
|
||
# ----------------------------------- | ||
# Textures | ||
# ----------------------------------- | ||
for tex, fmt in TEXTURES.iteritems(): | ||
|
||
srcFile = os.path.join( PROJECT_DIR, ASSET_DIR, tex ) | ||
|
||
texfile = os.path.split( tex )[-1] | ||
destFile = os.path.join( PROJECT_DIR, RUNTIME_DATA_DIR, os.path.splitext( texfile )[0] + ".dds" ) | ||
if fileNeedsUpdate(srcFile, destFile ): | ||
cmd = [ CRUNCH_TOOL, | ||
'-file', srcFile, | ||
'-out', destFile, | ||
'-gamma', '1.0', | ||
'-' + fmt | ||
] | ||
|
||
print string.join(cmd, ' ' ) | ||
subprocess.call( cmd ) | ||
|
||
|
||
|
||
# # Also make pvr version for ios | ||
# destFilePVR = os.path.join( PROJECT_DIR, RUNTIME_DATA_DIR, os.path.splitext( tex )[0] + ".pvr" ) | ||
|
||
# # TODO: better params | ||
# cmd2 = [TEXTURETOOL_TOOL, | ||
# '-m', # Generate mipmap chain | ||
# '-e', 'PVRTC', | ||
# '-f', 'PVR', | ||
# '--bits-per-pixel-4', | ||
# '-o', destFilePVR, | ||
# srcFile | ||
# ] | ||
|
||
# if fileNeedsUpdate(srcFile, destFilePVR ): | ||
# print string.join(cmd2, ' ' ) | ||
# subprocess.call( cmd2 ) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
fips_begin_app(ld41_cardfish windowed) | ||
fips_files(CardFish-Main.cpp | ||
CardFishApp.h CardFishApp.cpp | ||
SceneObject.cpp SceneObject.h | ||
#SceneCoordinator.cpp SceneCoordinator.h | ||
#SceneController.cpp SceneController.h | ||
#GameScene.cpp GameScene.h | ||
#TitleScene.cpp TitleScene.h | ||
Camera.h Camera.cpp | ||
Ray.h Ray.cpp | ||
UIAssets.h UIAssets.cpp | ||
DebugDraw.cpp DebugDraw.h debug_draw_impl.h | ||
stb_image.h | ||
par_easings.h | ||
|
||
) | ||
oryol_shader(shaders.glsl) | ||
oryol_shader(wireframe_shaders.glsl) | ||
fips_deps(Core IO LocalFS HttpFS Gfx Assets NKUI Dbg Input soloud) | ||
fips_end_app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
//------------------------------------------------------------------------------ | ||
// Camera.cc | ||
//------------------------------------------------------------------------------ | ||
#include <stdio.h> | ||
|
||
#include "Pre.h" | ||
#include "Camera.h" | ||
|
||
#define GLM_SWIZZLE | ||
#include "glm/glm.hpp" | ||
#include "glm/trigonometric.hpp" | ||
#include "glm/gtc/matrix_transform.hpp" | ||
#include "glm/gtc/matrix_access.hpp" | ||
|
||
void dbgPrintMatrix( const char *label, glm::mat4 m ); | ||
|
||
using namespace Oryol; | ||
using namespace Tapnik; | ||
|
||
//------------------------------------------------------------------------------ | ||
void | ||
Camera::Setup(const glm::vec3 pos, float fov, int dispWidth, int dispHeight, float near, float far) { | ||
this->Pos = pos; | ||
this->Model = glm::translate(glm::mat4(), pos); | ||
this->UpdateProj(fov, dispWidth, dispHeight, near, far); | ||
|
||
} | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
void | ||
Camera::UpdateProj(float fov, int dispWidth, int dispHeight, float near, float far) { | ||
this->Proj = glm::perspectiveFov(fov, float(dispWidth), float(dispHeight), near, far); | ||
|
||
this->updateViewProjFrustum(); | ||
|
||
displayWidth = dispWidth; | ||
displayHeight = dispHeight; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
void | ||
Camera::UpdateModel(const glm::mat4& model) { | ||
this->Model = model; | ||
this->updateViewProjFrustum(); | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
void | ||
Camera::MoveRotate(const glm::vec3& move, const glm::vec2& rot) { | ||
const glm::vec3 up(0.0f, 0.0f, 1.0f); | ||
const glm::vec3 hori(1.0f, 0.0f, 0.0f); | ||
this->Rot += rot; | ||
glm::mat4 m = glm::translate(glm::mat4(), this->Pos); | ||
m = glm::rotate(m, this->Rot.x, up); | ||
m = glm::rotate(m, this->Rot.y, hori); | ||
m = glm::translate(m, move); | ||
this->Model = m; | ||
this->Pos = glm::vec3(this->Model[3].x, this->Model[3].y, this->Model[3].z); | ||
this->updateViewProjFrustum(); | ||
} | ||
|
||
void | ||
Camera::MoveCrappy( const glm::vec3& move ) { | ||
glm::mat4 m = glm::translate(glm::mat4(), this->Pos); | ||
m = glm::translate(m, move); | ||
this->Model = m; | ||
this->Pos = glm::vec3(this->Model[3].x, this->Model[3].y, this->Model[3].z); | ||
this->updateViewProjFrustum(); | ||
} | ||
|
||
Ray | ||
Camera::getCameraRay( int px, int py ) | ||
{ | ||
glm::vec4 ndcA = glm::vec4( 2.0f * ((float(px) / float(displayWidth)) - 0.5f), | ||
-2.0f * ((float(py) / float(displayHeight)) - 0.5f), | ||
-1.0, 1.0f ); | ||
glm::vec4 ndcB = ndcA; | ||
ndcB.z = 0.0f; | ||
|
||
glm::vec4 a = mvpInverse * ndcA; | ||
a.w = 1.0 / a.w; | ||
a.x = a.x * a.w; | ||
a.y = a.y * a.w; | ||
a.z = a.z * a.w; | ||
|
||
glm::vec4 b = mvpInverse * ndcB; | ||
b.w = 1.0 / b.w; | ||
b.x = b.x * b.w; | ||
b.y = b.y * b.w; | ||
b.z = b.z * b.w; | ||
|
||
|
||
//printf("A is %3.2f %3.2f %3.2f %3.2f\n", a.x, a.y, a.z, a.w ); | ||
|
||
Ray ray; | ||
ray.pos = glm::vec3(a); | ||
ray.dir = glm::normalize( glm::vec3(b - a) ); | ||
|
||
return ray; | ||
} | ||
|
||
glm::vec4 Camera::worldPointToNDC( glm::vec3 worldPnt) | ||
{ | ||
glm::vec4 worldPointW = glm::vec4( worldPnt, 1.0 ); | ||
glm::vec4 ndcPoint = ViewProj * worldPointW; | ||
|
||
if (fabs(ndcPoint.w) > 0.001) { | ||
ndcPoint = ndcPoint * (1.0f/ndcPoint.w); | ||
} | ||
|
||
return ndcPoint; | ||
} | ||
|
||
glm::vec2 Camera::worldPointToScreen( glm::vec3 worldPnt ) | ||
{ | ||
glm::vec4 ndcPoint = worldPointToNDC( worldPnt ); | ||
|
||
// perspective divide, NDC to screen... | ||
glm::vec2 ndcScreen( ndcPoint ); | ||
ndcScreen = (ndcScreen + glm::vec2( 1.0 )) * 0.5f; | ||
return glm::vec2( ndcScreen.x * displayWidth, (1.0-ndcScreen.y) * displayHeight ); | ||
|
||
} | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
bool | ||
Camera::testPlane(const glm::vec4& p, float x0, float x1, float y0, float y1, float z0, float z1) { | ||
// see: https://github.com/nothings/stb/blob/master/tests/caveview/cave_render.c | ||
float d=0.0f; | ||
d += p.x > 0.0f ? x1 * p.x : x0 * p.x; | ||
d += p.y > 0.0f ? y1 * p.y : y0 * p.y; | ||
d += p.z > 0.0f ? z1 * p.z : z0 * p.z; | ||
d += p.w; | ||
return d >= 0.0f; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
bool | ||
Camera::BoxVisible(int x0, int x1, int y0, int y1, int z0, int z1) const { | ||
// see: https://github.com/nothings/stb/blob/master/tests/caveview/cave_render.c | ||
for (int i = 0; i < 6; i++) { | ||
if (!testPlane(this->Frustum[i], x0, x1, y0, y1, z0, z1)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
void | ||
Camera::updateViewProjFrustum() { | ||
this->View = glm::inverse(this->Model); | ||
this->ViewProj = this->Proj * this->View; | ||
|
||
// TODO: dirty flag, mark as needed? | ||
mvpInverse = glm::inverse(this->ViewProj); | ||
|
||
// extract frustum | ||
// https://fgiesen.wordpress.com/2012/08/31/frustum-planes-from-the-projection-matrix/ | ||
// http://gamedevs.org/uploads/fast-extraction-viewing-frustum-planes-from-world-view-projection-matrix.pdf | ||
glm::vec4 rx = glm::row(this->ViewProj, 0); | ||
glm::vec4 ry = glm::row(this->ViewProj, 1); | ||
glm::vec4 rz = glm::row(this->ViewProj, 2); | ||
glm::vec4 rw = glm::row(this->ViewProj, 3); | ||
|
||
this->Frustum[0] = rw + rx; | ||
this->Frustum[1] = rw - rx; | ||
this->Frustum[2] = rw + ry; | ||
this->Frustum[3] = rw - ry; | ||
this->Frustum[4] = rw + rz; | ||
this->Frustum[5] = rw - rz; | ||
} | ||
|
Oops, something went wrong.