Skip to content
Open
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
84 changes: 65 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,46 +1,92 @@
cmake_minimum_required(VERSION 3.6)
cmake_minimum_required(VERSION 3.16)

project(Tilengine)

# set an option to use libpng from the system, otherwise use bundled stb_image
option(TLN_OPTION_LIBPNG "Use the system libpng" ON)
option(TLN_OPTION_BUILD_LIBPNG "Build libpng from source" OFF)

# set an option to make the examples
option(TLN_OPTION_SAMPLES "Build the examples" OFF)

file(GLOB SOURCES
"src/*.c"
)


# main library
list(REMOVE_ITEM SOURCES "src/Test.c")
add_library(${PROJECT_NAME} ${SOURCES})

if (UNIX AND NOT APPLE)
set(CMAKE_C_FLAGS "-m64 -msse2")
elseif (UNIX AND APPLE)
target_link_libraries(${PROJECT_NAME} PRIVATE "framework")
endif()

if (TLN_OPTION_LIBPNG)
# this project needs png, if png is not found, let's use fetch content
find_package(PNG QUIET)
if (NOT PNG_FOUND AND TLN_OPTION_BUILD_LIBPNG)
include(FetchContent)
FetchContent_Declare(
libpng
GIT_REPOSITORY https://github.com/pnggroup/libpng.git
GIT_TAG v1.6.44
)
FetchContent_MakeAvailable(libpng)
set(PNG_LIBRARIES png_static)
add_definitions(-DTLN_HAVE_PNG)
target_link_libraries(${PROJECT_NAME} PRIVATE ${PNG_LIBRARIES})
endif()
if (NOT PNG_FOUND AND NOT TLN_OPTION_BUILD_LIBPNG)
# clear the PNG_LIBRARY variable
unset(PNG_LIBRARY CACHE)
endif()
if (PNG_FOUND)
add_definitions(-DTLN_HAVE_PNG)
target_include_directories(${PROJECT_NAME} PRIVATE ${PNG_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${PNG_LIBRARIES})
endif()
endif()

target_link_libraries(${PROJECT_NAME} PRIVATE "c")
target_link_libraries(${PROJECT_NAME} PRIVATE "z")
target_link_libraries(${PROJECT_NAME} PRIVATE "png")

find_package(SDL2 REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE ${SDL2_LIBRARIES})
if (TILENGINE_SAMPLES)
find_package(SDL2 REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE ${SDL2_LIBRARIES})
add_definitions(-DTLN_HAVE_SDL2)
else()
add_definitions(-DTLN_EXCLUDE_WINDOW)
endif()

target_include_directories(${PROJECT_NAME} PRIVATE include)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -O2 -fpic -DLIB_EXPORTS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-result -Wno-format-truncation")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-result")

# gcc specific
if (UNIX AND NOT APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format-truncation")
endif()

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/include/Tilengine.h
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

# test executable
add_executable(Test src/Test.c)
target_include_directories(Test PRIVATE include)
target_link_libraries(Test PRIVATE "Tilengine")
target_link_libraries(Test PRIVATE "c")
target_link_libraries(Test PRIVATE "z")
target_link_libraries(Test PRIVATE "png")
target_link_libraries(Test PRIVATE "m")

# samples
add_subdirectory(samples)
if (TILENGINE_SAMPLES)
# test executable
add_executable(Test src/Test.c)
target_include_directories(Test PRIVATE include)
target_link_libraries(Test PRIVATE "Tilengine")
target_link_libraries(Test PRIVATE "c")
target_link_libraries(Test PRIVATE "z")
if (TLN_OPTION_LIBPNG)
target_include_directories(Test PRIVATE ${PNG_INCLUDE_DIRS})
target_link_libraries(Test PRIVATE ${PNG_LIBRARIES})
endif()
target_link_libraries(Test PRIVATE ${PNG_LIBRARIES})
target_link_libraries(Test PRIVATE "m")
endif()

if (TLN_OPTION_SAMPLES)
# samples
add_subdirectory(samples)
endif()
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

Tilengine is an open source, cross-platform 2D graphics engine for creating classic/retro games with tile maps, sprites and palettes. Its unique scanline-based rendering algorithm makes raster effects a core feature, a technique used by many games running on real 2D graphics chips.

# This fork

This fork, in the macos branch,
- allows the use of a bundled stb_image instead of libpng via -DTLN_OPTION_LIBPNG=ON
- only uses SDL2 if the -DTLN_OPTION_SAMPLES=ON flag is set
- fixes macOS setting issues in the CMakeLists.txt

http://www.tilengine.org

# Contents
Expand Down
8 changes: 4 additions & 4 deletions samples/Actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* local variables */
static Actor* actors;
static int count = 0;
static unsigned int time;
static unsigned int actor_time;

/* local prototypes */
static void TasksActor (Actor* actor);
Expand Down Expand Up @@ -112,7 +112,7 @@ void TasksActors (unsigned int t)
if (!actors)
return;

time = t;
actor_time = t;

for (c=0; c<count; c++)
{
Expand All @@ -135,13 +135,13 @@ bool CheckActorCollision (Actor* actor1, Actor* actor2)
/* sets generic timeout */
void SetActorTimeout (Actor* actor, int timer, int timeout)
{
actor->timers[timer] = time + timeout;
actor->timers[timer] = actor_time + timeout;
}

/* gets generic timeout ended */
bool GetActorTimeout (Actor* actor, int timer)
{
return time >= actor->timers[timer];
return actor_time >= actor->timers[timer];
}

/* TasksActor */
Expand Down
7 changes: 6 additions & 1 deletion samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ find_package(SDL2 REQUIRED)
link_libraries(${SDL2_LIBRARIES})

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -O2 -fpic -DLIB_EXPORTS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-result -Wno-format-truncation")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-result")

# gcc specific
if (UNIX AND NOT APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format-truncation")
endif()

file(COPY assets DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

Expand Down
10 changes: 5 additions & 5 deletions samples/Racer.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int pos;
int speed;
int last_tree;
unsigned int frame;
unsigned int time;
unsigned int racer_time;
int pan = 0;

static void raster_callback (int line);
Expand Down Expand Up @@ -81,7 +81,7 @@ int main (int argc, char* argv[])
while (TLN_ProcessWindow ())
{
/* timekeeper */
time = frame;
racer_time = frame;

TLN_SetLayerPosition (LAYER_PLAYFIELD, 56,72);
if (pos - last_tree >= 100)
Expand All @@ -92,7 +92,7 @@ int main (int argc, char* argv[])
}

/* input */
if ((time & 0x07) == 0)
if ((racer_time & 0x07) == 0)
{
if (TLN_GetInput (INPUT_UP) && speed < MAX_SPEED)
speed++;
Expand All @@ -107,10 +107,10 @@ int main (int argc, char* argv[])

/* actores */
pos += speed;
TasksActors (time);
TasksActors (racer_time);

/* render to window */
TLN_DrawFrame (time);
TLN_DrawFrame (racer_time);

frame++;
}
Expand Down
Loading