application separation
This commit is contained in:
23
apps/template/CMakeLists.txt
Normal file
23
apps/template/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
|
||||
project(template LANGUAGES C)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
endif()
|
||||
|
||||
# add root townengine cmake file
|
||||
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_subdirectory(../../ ../../../.build)
|
||||
endif()
|
||||
|
||||
set(SOURCE_FILES
|
||||
game.c game.h
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
|
||||
use_townengine(${PROJECT_NAME})
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
3
apps/template/build.sh
Executable file
3
apps/template/build.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/env sh
|
||||
|
||||
cmake -B .build "$@" && cmake --build .build
|
26
apps/template/game.c
Normal file
26
apps/template/game.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "townengine/game_api.h"
|
||||
#include "game.h"
|
||||
#include "state.h"
|
||||
|
||||
#include <malloc.h>
|
||||
|
||||
|
||||
void game_tick(void) {
|
||||
/* do your initialization on first tick */
|
||||
if (ctx.tick_count == 0) {
|
||||
/* application data could be stored in ctx.udata and retrieved anywhere */
|
||||
ctx.udata = ccalloc(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);
|
||||
}
|
13
apps/template/game.h
Normal file
13
apps/template/game.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
|
||||
#include "townengine/game_api.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
void game_tick(void);
|
||||
void game_end(void);
|
||||
|
||||
|
||||
#endif
|
12
apps/template/state.h
Normal file
12
apps/template/state.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef STATE_H
|
||||
#define STATE_H
|
||||
|
||||
#include "townengine/game_api.h"
|
||||
|
||||
/* populate it with state information */
|
||||
struct state {
|
||||
uint64_t counter;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user