Compare commits
	
		
			6 Commits
		
	
	
		
			bd89c4b938
			...
			898c11bbdf
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 898c11bbdf | ||
|  | aeabb17f86 | ||
|  | 24e8dc052d | ||
|  | 3f264ca0ad | ||
|  | a7557fceb4 | ||
|  | 2e29cfcfe2 | 
| @@ -27,7 +27,6 @@ static void title_tick(State *state) { | ||||
|     size_t text_str_len = snprintf(NULL, 0, "%llu", (unsigned long long)state->ctx->frame_number) + 1; | ||||
|     char *text_str = malloc(text_str_len); | ||||
|     snprintf(text_str, text_str_len, "%llu", (unsigned long long)state->ctx->frame_number); | ||||
|     free(text_str); | ||||
|  | ||||
|     const char *font = "fonts/kenney-pixel.ttf"; | ||||
|     float text_h = 32; | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| cmake_minimum_required(VERSION 3.21) | ||||
| 
 | ||||
| project(template LANGUAGES C) | ||||
| project(twngame LANGUAGES C) | ||||
| 
 | ||||
| if(NOT CMAKE_BUILD_TYPE) | ||||
|         set(CMAKE_BUILD_TYPE Debug) | ||||
| @@ -13,4 +12,5 @@ set(SOURCE_FILES | ||||
|         state.h | ||||
| ) | ||||
| 
 | ||||
| use_townengine(${PROJECT_NAME} "${SOURCE_FILES}" ${CMAKE_CURRENT_SOURCE_DIR}) | ||||
| cmake_path(GET CMAKE_SOURCE_DIR STEM LAST_ONLY GAME_PROJECT_NAME) | ||||
| use_townengine(${GAME_PROJECT_NAME} "${SOURCE_FILES}" ${CMAKE_CURRENT_SOURCE_DIR}) | ||||
| @@ -1,7 +1,7 @@ | ||||
| #include "twn_game_api.h" | ||||
| #include "state.h" | ||||
| 
 | ||||
| #include <malloc.h> | ||||
| #include <stdlib.h> | ||||
| 
 | ||||
| 
 | ||||
| void game_tick(void) { | ||||
| @@ -10,7 +10,7 @@ void game_tick(void) { | ||||
|     if (ctx.initialization_needed) { | ||||
|         /* application data could be stored in ctx.udata and retrieved anywhere */ | ||||
|         if (!ctx.udata) | ||||
|             ctx.udata = ccalloc(1, sizeof (struct state)); | ||||
|             ctx.udata = calloc(1, sizeof (struct state)); | ||||
|     } | ||||
| 
 | ||||
|     /* a lot of data is accessible from `ctx`, look into `townengine/context.h` for more */ | ||||
							
								
								
									
										8
									
								
								apps/templates/lua/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								apps/templates/lua/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| 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}/apps/twnlua ${CMAKE_CURRENT_BINARY_DIR}/twnlua) | ||||
							
								
								
									
										8
									
								
								apps/templates/lua/data/scripts/game.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								apps/templates/lua/data/scripts/game.lua
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| -- called every frame, with constant delta time | ||||
| function game_tick() | ||||
|     -- ctx.initialization_needed is true first frame and every time dynamic reload is performed | ||||
|     if ctx.initialization_needed then | ||||
|         -- ctx.udata persists on reload | ||||
|         ctx.udata = {} | ||||
|     end | ||||
| end | ||||
							
								
								
									
										53
									
								
								apps/templates/lua/data/scripts/twnapi.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								apps/templates/lua/data/scripts/twnapi.lua
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,53 @@ | ||||
| ---@type { frame_number: number, frame_duration: number, fog_density: number, fog_color: { r: number, g: number, b: number, a: number }, resolution: { x: number, y: number }, mouse_position: { x: number, y: number }, mouse_movement: { x: number, y: number }, random_seed: number, debug: boolean, initialization_needed: boolean, mouse_capture: boolean, udata: table } | ||||
| ctx = nil | ||||
| ---@alias Control '"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"PASTE"'|'"FIND"'|'"MUTE"'|'"VOLUMEUP"'|'"VOLUMEDOWN"'|'"KP_COMMA"'|'"KP_EQUALSAS400"'|'"INTERNATIONAL1"'|'"INTERNATIONAL2"'|'"INTERNATIONAL3"'|'"INTERNATIONAL4"'|'"INTERNATIONAL5"'|'"INTERNATIONAL6"'|'"INTERNATIONAL7"'|'"INTERNATIONAL8"'|'"INTERNATIONAL9"'|'"LANG1"'|'"LANG2"'|'"LANG3"'|'"LANG4"'|'"LANG5"'|'"LANG6"'|'"LANG7"'|'"LANG8"'|'"LANG9"'|'"ALTERASE"'|'"SYSREQ"'|'"CANCEL"'|'"CLEAR"'|'"PRIOR"'|'"RETURN2"'|'"SEPARATOR"'|'"OUT"'|'"OPER"'|'"CLEARAGAIN"'|'"CRSEL"'|'"EXSEL"'|'"KP_00"'|'"KP_000"'|'"THOUSANDSSEPARATOR"'|'"DECIMALSEPARATOR"'|'"CURRENCYUNIT"'|'"CURRENCYSUBUNIT"'|'"KP_LEFTPAREN"'|'"KP_RIGHTPAREN"'|'"KP_LEFTBRACE"'|'"KP_RIGHTBRACE"'|'"KP_TAB"'|'"KP_BACKSPACE"'|'"KP_A"'|'"KP_B"'|'"KP_C"'|'"KP_D"'|'"KP_E"'|'"KP_F"'|'"KP_XOR"'|'"KP_POWER"'|'"KP_PERCENT"'|'"KP_LESS"'|'"KP_GREATER"'|'"KP_AMPERSAND"'|'"KP_DBLAMPERSAND"'|'"KP_VERTICALBAR"'|'"KP_DBLVERTICALBAR"'|'"KP_COLON"'|'"KP_HASH"'|'"KP_SPACE"'|'"KP_AT"'|'"KP_EXCLAM"'|'"KP_MEMSTORE"'|'"KP_MEMRECALL"'|'"KP_MEMCLEAR"'|'"KP_MEMADD"'|'"KP_MEMSUBTRACT"'|'"KP_MEMMULTIPLY"'|'"KP_MEMDIVIDE"'|'"KP_PLUSMINUS"'|'"KP_CLEAR"'|'"KP_CLEARENTRY"'|'"KP_BINARY"'|'"KP_OCTAL"'|'"KP_DECIMAL"'|'"KP_HEXADECIMAL"'|'"LCTRL"'|'"LSHIFT"'|'"LALT"'|'"LGUI"'|'"RCTRL"'|'"RSHIFT"'|'"RALT"'|'"RGUI"'|'"MODE"'|'"KBDILLUMTOGGLE"'|'"KBDILLUMDOWN"'|'"KBDILLUMUP"'|'"EJECT"'|'"SLEEP"'|'"APP1"'|'"APP2"'|'"AUDIOREWIND"'|'"AUDIOFASTFORWARD"'|'"SOFTLEFT"'|'"SOFTRIGHT"'|'"CALL"'|'"ENDCALL"'|'"LEFT_MOUSE"'|'"RIGHT_MOUSE"'|'"MIDDLE_MOUSE"'|'"X1"'|'"X2"' | ||||
| ---@param args { name: string, control: Control } | ||||
| function input_action(args) end | ||||
| ---@param args { name: string } | ||||
| function input_action_pressed(args) end | ||||
| ---@param args { name: string } | ||||
| function input_action_just_pressed(args) end | ||||
| ---@param args { name: string } | ||||
| function input_action_just_released(args) end | ||||
| ---@param args { name: string } | ||||
| function input_action_position(args) end | ||||
| ---@param args { texture: string, rect: { x: number, y: number, w: number, h: number }, texture_region: { x: number, y: number, w: number, h: number }?, color: { r: number, g: number, b: number, a: number }?, rotation: number?, flip_x: boolean?, flip_y: boolean?, stretch: boolean? } | ||||
| function draw_sprite(args) end | ||||
| ---@param args { rect: { x: number, y: number, w: number, h: number }, color: { r: number, g: number, b: number, a: number }? } | ||||
| function draw_rectangle(args) end | ||||
| ---@param args { position: { x: number, y: number }, radius: number, color: { r: number, g: number, b: number, a: number }? } | ||||
| function draw_circle(args) end | ||||
| ---@param args { string: string, position: { x: number, y: number }, height: number?, color: { r: number, g: number, b: number, a: number }?, font: string? } | ||||
| function draw_text(args) end | ||||
| ---@param args { string: string, height: number?, font: string? } | ||||
| function draw_text_width(args) end | ||||
| ---@param args { texture: string, corners: { x: number, y: number }, rect: { x: number, y: number, w: number, h: number }, border_thickness: number?, color: { r: number, g: number, b: number, a: number }? } | ||||
| function draw_nine_slice(args) end | ||||
| ---@param args { start: { x: number, y: number }, finish: { x: number, y: number }, thickness: number?, color: { r: number, g: number, b: number, a: number }? } | ||||
| function draw_line(args) end | ||||
| ---@param args { texture: string, v0: { x: number, y: number, z: number }, v1: { x: number, y: number, z: number }, v2: { x: number, y: number, z: number }, uv0: { x: number, y: number }, uv1: { x: number, y: number }, uv2: { x: number, y: number }, c0: { r: number, g: number, b: number, a: number }?, c1: { r: number, g: number, b: number, a: number }?, c2: { r: number, g: number, b: number, a: number }? } | ||||
| function draw_triangle(args) end | ||||
| ---@param args { texture: string, v0: { x: number, y: number, z: number }, v1: { x: number, y: number, z: number }, v2: { x: number, y: number, z: number }, v3: { x: number, y: number, z: number }, texture_region: { x: number, y: number, w: number, h: number }, color: { r: number, g: number, b: number, a: number }? } | ||||
| function draw_quad(args) end | ||||
| ---@param args { texture: string, position: { x: number, y: number, z: number }, size: { x: number, y: number }, color: { r: number, g: number, b: number, a: number }?, cylindrical: boolean? } | ||||
| function draw_billboard(args) end | ||||
| ---@param args { position: { x: number, y: number, z: number }, direction: { x: number, y: number, z: number }?, up: { x: number, y: number, z: number }?, fov: number?, zoom: number? } | ||||
| function draw_camera(args) end | ||||
| ---@param args { position: { x: number, y: number, z: number }, roll: number?, pitch: number?, yaw: number?, fov: number?, zoom: number? } | ||||
| function draw_camera_from_principal_axes(args) end | ||||
| ---@param args { textures: string? } | ||||
| function draw_skybox(args) end | ||||
| ---@param args { audio: string, channel: string?, loops: boolean?, volume: number?, panning: number? } | ||||
| function audio_play(args) end | ||||
| ---@param args { channel: string, parameter: string, value: number } | ||||
| function audio_parameter(args) end | ||||
| ---@param args { value: { x: number, y: number }, identity: string } | ||||
| function log_vec2(args) end | ||||
| ---@param args { value: { x: number, y: number, z: number }, identity: string } | ||||
| function log_vec3(args) end | ||||
| ---@param args { value: { x: number, y: number, w: number, h: number }, identity: string } | ||||
| function log_rect(args) end | ||||
| ---@param args { profile: string } | ||||
| function profile_start(args) end | ||||
| ---@param args { profile: string } | ||||
| function profile_end(args) end | ||||
							
								
								
									
										26
									
								
								apps/templates/lua/data/twn.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								apps/templates/lua/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" | ||||
| @@ -39,4 +39,5 @@ set(SOURCE_FILES | ||||
|         ${CMAKE_CURRENT_SOURCE_DIR}/luabind.c | ||||
| ) | ||||
|  | ||||
| use_townengine(${CMAKE_PROJECT_NAME} "${SOURCE_FILES}" ${CMAKE_SOURCE_DIR}) | ||||
| cmake_path(GET CMAKE_SOURCE_DIR STEM LAST_ONLY GAME_PROJECT_NAME) | ||||
| use_townengine(${GAME_PROJECT_NAME} "${SOURCE_FILES}" ${CMAKE_SOURCE_DIR}) | ||||
|   | ||||
| @@ -87,7 +87,7 @@ static void *custom_alloc(void *ud, void *ptr, size_t osize, size_t nsize) { | ||||
| void game_tick(void) { | ||||
|     if (ctx.initialization_needed) { | ||||
|         if (!ctx.udata) | ||||
|             ctx.udata = ccalloc(1, sizeof (State)); | ||||
|             ctx.udata = calloc(1, sizeof (State)); | ||||
|  | ||||
|         State *state = ctx.udata; | ||||
|  | ||||
|   | ||||
| @@ -127,6 +127,18 @@ | ||||
|             ] | ||||
|         }, | ||||
|  | ||||
|         "draw_line": { | ||||
|             "module": "draw", | ||||
|             "symbol": "line", | ||||
|             "header": "twn_draw.h", | ||||
|             "params": [ | ||||
|                 { "name": "start", "type": "Vec2" }, | ||||
|                 { "name": "finish", "type": "Vec2" }, | ||||
|                 { "name": "thickness", "type": "float", "default": 1 }, | ||||
|                 { "name": "color", "type": "Color", "default": { "r": 255, "g": 255, "b": 255, "a": 255 } } | ||||
|             ] | ||||
|         }, | ||||
|  | ||||
|         "draw_triangle": { | ||||
|             "module": "draw", | ||||
|             "symbol": "triangle", | ||||
|   | ||||
| @@ -33,7 +33,7 @@ bool start_sanity_timer(uint32_t milliseconds_to_expire) { | ||||
| } | ||||
|  | ||||
|  | ||||
| bool end_sanity_timer(void) { | ||||
| void end_sanity_timer(void) { | ||||
|     SDL_RemoveTimer(sanity_timer); | ||||
|     sanity_timer = 0; | ||||
| } | ||||
|   | ||||
| @@ -5,6 +5,6 @@ | ||||
| #include <stdint.h> | ||||
|  | ||||
| bool start_sanity_timer(uint32_t milliseconds_to_expire); | ||||
| bool end_sanity_timer(void); | ||||
| void end_sanity_timer(void); | ||||
|  | ||||
| #endif // TWN_TIMER_H | ||||
|   | ||||
							
								
								
									
										25
									
								
								third-party/dmon/LICENSE
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								third-party/dmon/LICENSE
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| BSD 2-Clause License | ||||
|  | ||||
| Copyright (c) 2019, Sepehr Taghdisian (septag@protonmail.com) | ||||
| All rights reserved. | ||||
|  | ||||
| Redistribution and use in source and binary forms, with or without | ||||
| modification, are permitted provided that the following conditions are met: | ||||
|  | ||||
| * Redistributions of source code must retain the above copyright notice, this | ||||
|   list of conditions and the following disclaimer. | ||||
|  | ||||
| * Redistributions in binary form must reproduce the above copyright notice, | ||||
|   this list of conditions and the following disclaimer in the documentation | ||||
|   and/or other materials provided with the distribution. | ||||
|  | ||||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||||
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||||
| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||||
| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||||
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||||
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||||
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||||
| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||||
| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
		Reference in New Issue
	
	Block a user