create /apps/temapltes/ structure, clean up cmake files to use directory name for binary name directly
This commit is contained in:
16
apps/templates/c/CMakeLists.txt
Normal file
16
apps/templates/c/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
project(twngame LANGUAGES C)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
endif()
|
||||
|
||||
add_subdirectory($ENV{TWNROOT} $ENV{TWNROOT}/build)
|
||||
|
||||
set(SOURCE_FILES
|
||||
game.c
|
||||
state.h
|
||||
)
|
||||
|
||||
cmake_path(GET CMAKE_SOURCE_DIR STEM LAST_ONLY GAME_PROJECT_NAME)
|
||||
use_townengine(${GAME_PROJECT_NAME} "${SOURCE_FILES}" ${CMAKE_CURRENT_SOURCE_DIR})
|
26
apps/templates/c/data/twn.toml
Normal file
26
apps/templates/c/data/twn.toml
Normal file
@ -0,0 +1,26 @@
|
||||
# This file contains everything about the engine and your game that can be
|
||||
# configured before it runs.
|
||||
#
|
||||
# Optional settings are commented out, with their default values shown.
|
||||
# Invalid values in these settings will be ignored.
|
||||
|
||||
# Data about your game as an application
|
||||
[about]
|
||||
title = "Template"
|
||||
developer = "You"
|
||||
app_id = "template"
|
||||
dev_id = "you"
|
||||
|
||||
# Game runtime details
|
||||
[game]
|
||||
resolution = [ 640, 480 ]
|
||||
#debug = true
|
||||
|
||||
# Engine tweaks. You probably don't need to change these
|
||||
[engine]
|
||||
#ticks_per_second = 60 # minimum of 8
|
||||
#keybind_slots = 3 # minimum of 1
|
||||
#texture_atlas_size = 2048 # minimum of 32
|
||||
#font_texture_size = 2048 # minimum of 1024
|
||||
#font_oversampling = 4 # minimum of 0
|
||||
#font_filtering = "linear" # possible values: "nearest", "linear"
|
27
apps/templates/c/game.c
Normal file
27
apps/templates/c/game.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include "twn_game_api.h"
|
||||
#include "state.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
void game_tick(void) {
|
||||
/* do state initialization when engine asks for it */
|
||||
/* it could happen multiple times per application run, as game code is reloadable */
|
||||
if (ctx.initialization_needed) {
|
||||
/* application data could be stored in ctx.udata and retrieved anywhere */
|
||||
if (!ctx.udata)
|
||||
ctx.udata = calloc(1, sizeof (struct state));
|
||||
}
|
||||
|
||||
/* a lot of data is accessible from `ctx`, look into `townengine/context.h` for more */
|
||||
|
||||
struct state *state = ctx.udata;
|
||||
++state->counter;
|
||||
}
|
||||
|
||||
|
||||
void game_end(void) {
|
||||
/* do your deinitialization here */
|
||||
struct state *state = ctx.udata;
|
||||
free(state);
|
||||
}
|
12
apps/templates/c/state.h
Normal file
12
apps/templates/c/state.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef STATE_H
|
||||
#define STATE_H
|
||||
|
||||
#include "twn_game_api.h"
|
||||
|
||||
/* populate it with state information */
|
||||
struct state {
|
||||
uint64_t counter;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user