├── HISTORY.txt ├── LICENSE.txt ├── README.md ├── ascii_game_engine.sln ├── ascii_game_engine ├── age.c ├── age.h ├── ageconfig.h ├── ascii_game_engine.aps ├── ascii_game_engine.vcproj ├── audio │ ├── ageaudio.c │ └── ageaudio.h ├── bitfsm │ ├── agebitfsm.c │ └── agebitfsm.h ├── common │ ├── ageallocator.c │ ├── ageallocator.h │ ├── agebitset.c │ ├── agebitset.h │ ├── agehashtable.c │ ├── agehashtable.h │ ├── agelist.c │ ├── agelist.h │ ├── ageparamset.c │ ├── ageparamset.h │ ├── agestringtable.h │ ├── agetype.h │ ├── ageutil.c │ └── ageutil.h ├── controller │ ├── agecontroller.c │ ├── agecontroller.h │ ├── ageexploder.c │ └── ageexploder.h ├── input │ ├── ageinput.c │ ├── ageinput.h │ └── ageinput_win32.c ├── message │ ├── agemessage.c │ └── agemessage.h ├── render │ ├── agerenderer.c │ ├── agerenderer.h │ └── agerenderer_win32.c └── script │ ├── agescriptapi.c │ ├── agescriptapi.h │ └── my_basic │ ├── my_basic.c │ └── my_basic.h ├── clean.cmd ├── game ├── animation.c ├── animation.h ├── data │ ├── config.bas │ ├── info.txt │ ├── sprite │ │ ├── ascii_hero_brush.txt │ │ ├── ascii_hero_palete.txt │ │ ├── ascii_hero_shape.txt │ │ ├── board_brush.txt │ │ ├── board_palete.txt │ │ └── board_shape.txt │ └── ui │ │ ├── copyright_brush.txt │ │ ├── copyright_palete.txt │ │ ├── copyright_shape.txt │ │ ├── logo_brush.txt │ │ ├── logo_palete.txt │ │ ├── logo_shape.txt │ │ ├── number_brush.txt │ │ ├── number_palete.txt │ │ └── number_shape.txt ├── game.aps ├── game.c ├── game.h ├── game.rc ├── game.vcproj ├── icon.ico ├── logic.c ├── logic.h ├── renderer.c ├── renderer.h ├── resource.h ├── script.c ├── script.h ├── state.c └── state.h ├── imgs └── age1.png └── logo.png /HISTORY.txt: -------------------------------------------------------------------------------- 1 | Sep. 25 2011 2 | File exists ensuring bugfix. 3 | 4 | Sep. 18 2011 5 | Binded bitfsm to player animation controlling. 6 | Board up speeding up. 7 | Mutable audio. 8 | 9 | Sep. 17 2011 10 | bitfsm bugfix. 11 | Basically binded bitfsm to player animation controlling. 12 | 13 | Sep. 15 2011 14 | Coding style refactoring. 15 | 16 | Sep. 10 2011 17 | Implemented boards' logic. 18 | 19 | Aug. 30 2011 20 | Use delayed queue for sprite destruction. 21 | Use separated collition detection. 22 | 23 | Aug. 25 2011 24 | Implemented basic board logic. 25 | 26 | Aug. 11 2011 27 | Added sprite removing callback. 28 | 29 | Aug. 8 2011 30 | Some artworks. 31 | 32 | Jul. 25 2011 33 | Bitfsm in pure-C. 34 | Logo, main menu. 35 | 36 | Jul. 9 2011 37 | Collision detection. 38 | 39 | Jul. 6 2011 40 | Named frame. 41 | 42 | Jul. 5 2011 43 | Basic animation on named frames. 44 | 45 | Jul. 3 2011 46 | Rendering. 47 | Basic animating. 48 | 49 | Jun. 26 2011 50 | Canvas, Sprite etc. 51 | Controller interface. 52 | Message system. 53 | Main loop logic. 54 | Basic render flow. 55 | 56 | Jun. 14 2011 57 | Project started. 58 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2011 Wang Renxin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## ASCII Game Engine 2 | 3 | Small but complete! 4 | 5 | ![](imgs/age1.png) 6 | -------------------------------------------------------------------------------- /ascii_game_engine.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "game", "game\game.vcproj", "{449FADFD-718D-4A1C-93F7-F0A66026AC92}" 5 | ProjectSection(ProjectDependencies) = postProject 6 | {E9FEBB11-9649-4CFC-A5F5-EA7D7BDB1741} = {E9FEBB11-9649-4CFC-A5F5-EA7D7BDB1741} 7 | EndProjectSection 8 | EndProject 9 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ascii_game_engine", "ascii_game_engine\ascii_game_engine.vcproj", "{E9FEBB11-9649-4CFC-A5F5-EA7D7BDB1741}" 10 | EndProject 11 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "document", "document", "{40833A61-60B3-41A0-8BF7-7AACE1A47C42}" 12 | ProjectSection(SolutionItems) = preProject 13 | HISTORY.txt = HISTORY.txt 14 | LICENSE.txt = LICENSE.txt 15 | README_CN.txt = README_CN.txt 16 | README_EN.txt = README_EN.txt 17 | EndProjectSection 18 | EndProject 19 | Global 20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 21 | Debug|Win32 = Debug|Win32 22 | Release|Win32 = Release|Win32 23 | EndGlobalSection 24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 25 | {449FADFD-718D-4A1C-93F7-F0A66026AC92}.Debug|Win32.ActiveCfg = Debug|Win32 26 | {449FADFD-718D-4A1C-93F7-F0A66026AC92}.Debug|Win32.Build.0 = Debug|Win32 27 | {449FADFD-718D-4A1C-93F7-F0A66026AC92}.Release|Win32.ActiveCfg = Release|Win32 28 | {449FADFD-718D-4A1C-93F7-F0A66026AC92}.Release|Win32.Build.0 = Release|Win32 29 | {E9FEBB11-9649-4CFC-A5F5-EA7D7BDB1741}.Debug|Win32.ActiveCfg = Debug|Win32 30 | {E9FEBB11-9649-4CFC-A5F5-EA7D7BDB1741}.Debug|Win32.Build.0 = Debug|Win32 31 | {E9FEBB11-9649-4CFC-A5F5-EA7D7BDB1741}.Release|Win32.ActiveCfg = Release|Win32 32 | {E9FEBB11-9649-4CFC-A5F5-EA7D7BDB1741}.Release|Win32.Build.0 = Release|Win32 33 | EndGlobalSection 34 | GlobalSection(SolutionProperties) = preSolution 35 | HideSolutionNode = FALSE 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /ascii_game_engine/age.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "age.h" 27 | 28 | #define _VER_MAJOR 1 29 | #define _VER_MINOR 0 30 | #define _VER_REVISION 2 31 | #define _AGE_VERSION ((_VER_MAJOR << 24) | (_VER_MINOR << 16) | (_VER_REVISION)) 32 | #define _AGE_VERSION_STRING "1.0.0002" 33 | 34 | static World* _gWorld = 0; 35 | 36 | static void _on_error(mb_interpreter_t* s, mb_error_e e, char* m, int p) { 37 | if(SE_NO_ERR != e) { 38 | printf("Error : [POS] %d, [CODE] %d, [MESSAGE] %s\n", p, e, m); 39 | } 40 | } 41 | 42 | static bl _register_apis(mb_interpreter_t* s) { 43 | bl result = TRUE; 44 | 45 | mb_register_func(s, "BEEP", age_api_beep); 46 | mb_register_func(s, "SET_MUTE", age_api_set_mute); 47 | mb_register_func(s, "REG_KEY", age_api_reg_key_code); 48 | mb_register_func(s, "SET_FRAME_RATE", age_api_set_frame_rate); 49 | mb_register_func(s, "CREATE_SPRITE", age_api_create_sprite); 50 | mb_register_func(s, "DESTROY_SPRITE", age_api_destroy_sprite); 51 | mb_register_func(s, "DESTROY_ALL_SPRITES", age_api_destroy_all_sprites); 52 | mb_register_func(s, "SET_SPRITE_POS", age_api_set_sprite_position); 53 | mb_register_func(s, "GET_SPRITE_POS_X", age_api_get_sprite_position_x); 54 | mb_register_func(s, "GET_SPRITE_POS_Y", age_api_get_sprite_position_y); 55 | mb_register_func(s, "PLAY_SPRITE", age_api_play_sprite); 56 | mb_register_func(s, "STOP_SPRITE", age_api_stop_sprite); 57 | mb_register_func(s, "GET_CVS_S32_PARAM", age_api_get_cvs_s32_param); 58 | mb_register_func(s, "SET_CVS_S32_PARAM", age_api_set_cvs_s32_param); 59 | mb_register_func(s, "GET_CVS_U32_PARAM", age_api_get_cvs_u32_param); 60 | mb_register_func(s, "SET_CVS_U32_PARAM", age_api_set_cvs_u32_param); 61 | mb_register_func(s, "GET_CVS_F32_PARAM", age_api_get_cvs_f32_param); 62 | mb_register_func(s, "SET_CVS_F32_PARAM", age_api_set_cvs_f32_param); 63 | mb_register_func(s, "GET_CVS_STR_PARAM", age_api_get_cvs_str_param); 64 | mb_register_func(s, "SET_CVS_STR_PARAM", age_api_set_cvs_str_param); 65 | mb_register_func(s, "GET_SPR_S32_PARAM", age_api_get_spr_s32_param); 66 | mb_register_func(s, "SET_SPR_S32_PARAM", age_api_set_spr_s32_param); 67 | mb_register_func(s, "GET_SPR_U32_PARAM", age_api_get_spr_u32_param); 68 | mb_register_func(s, "SET_SPR_U32_PARAM", age_api_set_spr_u32_param); 69 | mb_register_func(s, "GET_SPR_F32_PARAM", age_api_get_spr_f32_param); 70 | mb_register_func(s, "SET_SPR_F32_PARAM", age_api_set_spr_f32_param); 71 | mb_register_func(s, "GET_SPR_STR_PARAM", age_api_get_spr_str_param); 72 | mb_register_func(s, "SET_SPR_STR_PARAM", age_api_set_spr_str_param); 73 | 74 | return result; 75 | } 76 | 77 | static bl _open_script(mb_interpreter_t** s) { 78 | bl result = TRUE; 79 | 80 | mb_open(s); 81 | mb_set_error_handler(*s, _on_error); 82 | _register_apis(*s); 83 | 84 | return result; 85 | } 86 | 87 | static bl _close_script(mb_interpreter_t** s) { 88 | bl result = TRUE; 89 | 90 | mb_close(s); 91 | 92 | return result; 93 | } 94 | 95 | u32 get_ver(void) { 96 | return _AGE_VERSION; 97 | } 98 | 99 | const Str get_ver_string(void) { 100 | return _AGE_VERSION_STRING; 101 | } 102 | 103 | World* create_world(void) { 104 | World* result = 0; 105 | 106 | assert(!_gWorld); 107 | 108 | open_input(); 109 | result = AGE_MALLOC(World); 110 | result->audio = create_sound_context(); 111 | result->input = create_input_context(); 112 | result->canvas = create_canvas(ST_DEFAULT_CANVAS_NAME); 113 | set_cursor_visible(result->canvas, FALSE); 114 | 115 | mb_init(); 116 | _open_script(&result->script); 117 | 118 | _gWorld = result; 119 | 120 | SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS); 121 | 122 | return result; 123 | } 124 | 125 | World* get_world(void) { 126 | return _gWorld; 127 | } 128 | 129 | void destroy_world(void) { 130 | if(!_gWorld) { 131 | return; 132 | } 133 | 134 | _close_script(&_gWorld->script); 135 | mb_dispose(); 136 | 137 | destroy_canvas(_gWorld->canvas); 138 | destroy_input_context(_gWorld->input); 139 | destroy_sound_context(_gWorld->audio); 140 | AGE_FREE(_gWorld); 141 | 142 | _gWorld = 0; 143 | 144 | close_input(); 145 | } 146 | 147 | bl config_world(const Str _cfgFile) { 148 | bl result = TRUE; 149 | 150 | assert(_gWorld); 151 | 152 | mb_reset(&_gWorld->script, FALSE); 153 | mb_load_file(_gWorld->script, _cfgFile); 154 | mb_run(_gWorld->script); 155 | 156 | return result; 157 | } 158 | 159 | s32 run_world(void) { 160 | s32 result = 0; 161 | s32 now = 0; 162 | s32 old = age_tick_count(); 163 | s32 elapsed = 0; 164 | s32 delay = 0; 165 | 166 | assert(_gWorld); 167 | 168 | _gWorld->running = TRUE; 169 | while(_gWorld->running) { 170 | now = age_tick_count(); 171 | elapsed = now - old; 172 | old = now; 173 | update_sound(AGE_SND, elapsed); 174 | update_canvas(AGE_CVS, elapsed); 175 | collide_canvas(AGE_CVS, elapsed); 176 | render_canvas(AGE_CVS, elapsed); 177 | tidy_canvas(AGE_CVS, elapsed); 178 | delay = EXPECTED_FRAME_TIME - (age_tick_count() - old); 179 | if(delay > 0) { 180 | age_sleep(delay); 181 | } 182 | } 183 | 184 | return result; 185 | } 186 | 187 | void exit_world(void) { 188 | assert(_gWorld); 189 | 190 | _gWorld->running = FALSE; 191 | } 192 | 193 | bl run_world_script(const Str _sptFile) { 194 | bl result = TRUE; 195 | 196 | assert(_gWorld); 197 | 198 | mb_reset(&_gWorld->script, FALSE); 199 | mb_load_file(_gWorld->script, _sptFile); 200 | mb_run(_gWorld->script); 201 | 202 | return result; 203 | } 204 | 205 | bl run_new_script(const Str _sptFile) { 206 | bl result = TRUE; 207 | mb_interpreter_t* script = 0; 208 | 209 | _open_script(&script); 210 | mb_load_file(script, _sptFile); 211 | mb_run(script); 212 | _close_script(&script); 213 | 214 | return result; 215 | } 216 | -------------------------------------------------------------------------------- /ascii_game_engine/age.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_H__ 27 | #define __AGE_H__ 28 | 29 | #include "ageconfig.h" 30 | #include "audio/ageaudio.h" 31 | #include "bitfsm/agebitfsm.h" 32 | #include "common/ageallocator.h" 33 | #include "common/agebitset.h" 34 | #include "common/agehashtable.h" 35 | #include "common/agelist.h" 36 | #include "common/ageparamset.h" 37 | #include "common/agestringtable.h" 38 | #include "common/agetype.h" 39 | #include "common/ageutil.h" 40 | #include "controller/agecontroller.h" 41 | #include "input/ageinput.h" 42 | #include "message/agemessage.h" 43 | #include "render/agerenderer.h" 44 | #include "script/agescriptapi.h" 45 | #include "script/my_basic/my_basic.h" 46 | 47 | #ifndef AGE_WLD 48 | # define AGE_WLD get_world() 49 | #endif 50 | #ifndef AGE_CVS 51 | # define AGE_CVS get_world()->canvas 52 | #endif 53 | #ifndef AGE_CVS_PAR 54 | # define AGE_CVS_PAR get_world()->canvas->params 55 | #endif 56 | #ifndef AGE_IPT 57 | # define AGE_IPT get_world()->input 58 | #endif 59 | #ifndef AGE_SND 60 | # define AGE_SND get_world()->audio 61 | #endif 62 | 63 | /** 64 | * @brief world object 65 | */ 66 | typedef struct World { 67 | SoundContext* audio; /**< audio system context */ 68 | Ptr input; /**< input context */ 69 | Canvas* canvas; /**< canvas object */ 70 | mb_interpreter_t* script; /**< global script object */ 71 | bl running; /**< whether the world is running, set to FALSE to exit the game */ 72 | } World; 73 | 74 | /** 75 | * @brief get the version of current ascii game engine 76 | * 77 | * @return - the version in unsigned integer format 78 | */ 79 | AGE_API u32 get_ver(void); 80 | /** 81 | * @brief get the version of current ascii game engine 82 | * 83 | * @return - the version in string format 84 | */ 85 | AGE_API const Str get_ver_string(void); 86 | 87 | /** 88 | * @brief create the game world 89 | * 90 | * @return - the created world 91 | */ 92 | AGE_API World* create_world(void); 93 | /** 94 | * @brief get the created singleton game world 95 | * 96 | * @return - the created singleton world 97 | */ 98 | AGE_API World* get_world(void); 99 | /** 100 | * @brief destroy a created singleton game world 101 | */ 102 | AGE_API void destroy_world(void); 103 | 104 | /** 105 | * @brief run a script to config the game world 106 | * 107 | * @param[in] _cfgFile - configuration script file name 108 | * @return - return TRUE if succeed, or FALSE if failed 109 | */ 110 | AGE_API bl config_world(const Str _cfgFile); 111 | 112 | /** 113 | * @brief run the world for one frame 114 | * 115 | * @return - return TRUE if succeed, or FALSE if failed 116 | */ 117 | AGE_API s32 run_world(void); 118 | /** 119 | * @brief request to exit the game world 120 | */ 121 | AGE_API void exit_world(void); 122 | 123 | /** 124 | * @brief run a script in the world context 125 | * 126 | * @param[in] _sptFile - script file name 127 | * @return - return TRUE if succeed, or FALSE if failed 128 | */ 129 | AGE_API bl run_world_script(const Str _sptFile); 130 | /** 131 | * @brief run a script in a new context 132 | * 133 | * @param[in] _sptFile - script file name 134 | * @return - return TRUE if succeed, or FALSE if failed 135 | */ 136 | AGE_API bl run_new_script(const Str _sptFile); 137 | 138 | #endif /* __AGE_H__ */ 139 | -------------------------------------------------------------------------------- /ascii_game_engine/ageconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_CONFIG_H__ 27 | #define __AGE_CONFIG_H__ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #ifdef _MSC_VER 40 | # ifdef INTE_COMPILE 41 | # define AGE_API __declspec(dllexport) 42 | # else 43 | # define AGE_API __declspec(dllimport) 44 | # endif 45 | # define AGE_INTERNAL 46 | #else 47 | # define AGE_API __attribute__ ((visibility("default"))) 48 | # define AGE_INTERNAL __attribute__ ((visibility("hidden"))) 49 | #endif 50 | 51 | #ifndef AGE_IMPL_CONSOLE 52 | # define AGE_IMPL_CONSOLE 0 53 | #endif 54 | #ifndef AGE_IMPL_WIN32 55 | # define AGE_IMPL_WIN32 1 56 | #endif 57 | 58 | #ifndef AGE_IMPL 59 | # define AGE_IMPL AGE_IMPL_CONSOLE 60 | #endif 61 | 62 | #ifndef CANVAS_WIDTH 63 | # define CANVAS_WIDTH 80 64 | #endif 65 | #ifndef CANVAS_HEIGHT 66 | # define CANVAS_HEIGHT 25 67 | #endif 68 | 69 | #ifndef AGE_STR_LEN 70 | # define AGE_STR_LEN 256 71 | #endif 72 | #ifndef AGE_TXT_LEN 73 | # define AGE_TXT_LEN 10240 74 | #endif 75 | 76 | #ifndef EXPECTED_FPS 77 | # define EXPECTED_FPS 20 78 | #endif 79 | #ifndef EXPECTED_FRAME_TIME 80 | # define EXPECTED_FRAME_TIME (1000 / EXPECTED_FPS) 81 | #endif 82 | 83 | #endif /* __AGE_CONFIG_H__ */ 84 | -------------------------------------------------------------------------------- /ascii_game_engine/ascii_game_engine.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/ascii_game_engine/05c1961b7a3cea5e46909cb5de2012cf0949abc3/ascii_game_engine/ascii_game_engine.aps -------------------------------------------------------------------------------- /ascii_game_engine/ascii_game_engine.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 25 | 28 | 31 | 34 | 37 | 40 | 54 | 57 | 60 | 63 | 70 | 73 | 76 | 79 | 82 | 85 | 88 | 91 | 92 | 100 | 103 | 106 | 109 | 112 | 115 | 129 | 132 | 135 | 138 | 146 | 149 | 152 | 155 | 158 | 161 | 164 | 167 | 168 | 169 | 170 | 171 | 172 | 175 | 178 | 179 | 182 | 183 | 186 | 187 | 190 | 191 | 194 | 195 | 198 | 199 | 202 | 203 | 206 | 207 | 210 | 211 | 214 | 215 | 218 | 219 | 222 | 223 | 226 | 227 | 230 | 231 | 232 | 235 | 238 | 239 | 242 | 243 | 246 | 249 | 250 | 253 | 254 | 255 | 256 | 259 | 262 | 263 | 266 | 267 | 270 | 271 | 272 | 275 | 278 | 279 | 282 | 283 | 286 | 287 | 288 | 291 | 294 | 295 | 298 | 299 | 300 | 303 | 306 | 307 | 310 | 311 | 314 | 315 | 318 | 319 | 320 | 323 | 326 | 327 | 330 | 331 | 332 | 335 | 338 | 339 | 342 | 343 | 344 | 347 | 348 | 351 | 352 | 355 | 356 | 357 | 358 | 359 | 360 | -------------------------------------------------------------------------------- /ascii_game_engine/audio/ageaudio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include 27 | 28 | #include "../common/ageutil.h" 29 | #include "ageaudio.h" 30 | 31 | static u32 _FREQ[3][7] = { 32 | { 262, 294, 330, 349, 392, 440, 494 }, 33 | { 523, 578, 659, 698, 784, 880, 988 }, 34 | { 1046, 1175, 1318, 1397, 1568, 1760, 1976 } 35 | }; 36 | 37 | typedef struct ThreadInfo { 38 | SoundContext* context; 39 | DWORD thread_id; 40 | HANDLE thread_handle; 41 | union { 42 | CRITICAL_SECTION lock; 43 | LPCRITICAL_SECTION plock; 44 | }; 45 | s32 level; 46 | bl loop; 47 | bl stop; 48 | Str sequence; 49 | s32 position; 50 | s32 time; 51 | struct ThreadInfo* shadow; 52 | } ThreadInfo; 53 | 54 | static void _lock(Ptr _info) { 55 | ThreadInfo* info = (ThreadInfo*)_info; 56 | EnterCriticalSection(&(info->lock)); 57 | } 58 | 59 | static void _unlock(Ptr _info) { 60 | ThreadInfo* info = (ThreadInfo*)_info; 61 | LeaveCriticalSection(&(info->lock)); 62 | } 63 | 64 | static bl _is_note(s8 _ch) { 65 | return ((_ch >= 'A' && _ch <= 'G') || _ch == 'P'); 66 | } 67 | 68 | static void _age_beep(s32 _level, s8 _note) { 69 | if(_note == 'P') { 70 | age_sleep(100); 71 | } else { 72 | if(_note < 'C') { 73 | _note -= 'A'; 74 | _note += 5; 75 | } else { 76 | _note -= 'C'; 77 | } 78 | Beep(_FREQ[_level][_note], 100); 79 | } 80 | } 81 | 82 | static void _copy_sound_thread_info(ThreadInfo* _src, ThreadInfo* _tgt) { 83 | _tgt->context = _src->context; 84 | _tgt->thread_id = _src->thread_id; 85 | _tgt->thread_handle = _src->thread_handle; 86 | _tgt->plock = &_src->lock; 87 | _tgt->level = _src->level; 88 | _tgt->loop = _src->loop; 89 | if(_tgt->sequence) { 90 | AGE_FREE(_tgt->sequence); 91 | _tgt->sequence = 0; 92 | } 93 | if(_src->sequence) { 94 | _tgt->sequence = copy_string(_src->sequence); 95 | AGE_FREE(_src->sequence); 96 | _src->sequence = 0; 97 | } 98 | _tgt->position = _src->position; 99 | _tgt->time = _src->time; 100 | } 101 | 102 | #define __PLAY_ONE_NOTE(__c) \ 103 | if(_is_note(note) || _is_note(last)) { \ 104 | if(!info->context->mute) { \ 105 | _age_beep(info->level, note ? note : last); \ 106 | note = __c; \ 107 | } \ 108 | } 109 | static s32 WINAPI sound_proc(Ptr param) { 110 | DWORD result = 0; 111 | ThreadInfo* _info = (ThreadInfo*)param; 112 | ThreadInfo* info = 0; 113 | s32 len = 0; 114 | s8 last = '\0'; 115 | s8 ch = '\0'; 116 | s8 note = '\0'; 117 | 118 | EnterCriticalSection(&_info->lock); { 119 | info = AGE_MALLOC(ThreadInfo); 120 | _info->shadow = info; 121 | _copy_sound_thread_info(_info, info); 122 | len = info->sequence ? strlen(info->sequence) : 0; 123 | } LeaveCriticalSection(&_info->lock); 124 | 125 | _again: 126 | EnterCriticalSection(info->plock); { 127 | if(_info->sequence) { 128 | _copy_sound_thread_info(_info, info); 129 | len = info->sequence ? strlen(info->sequence) : 0; 130 | } 131 | if(_info->stop) { 132 | _info->stop = FALSE; 133 | AGE_FREE(info->sequence); 134 | info->sequence = 0; 135 | len = 0; 136 | } 137 | } LeaveCriticalSection(info->plock); 138 | if(info->sequence) { 139 | while(info->position < len) { 140 | ch = info->sequence[info->position++]; 141 | if(ch == '>') { 142 | __PLAY_ONE_NOTE('\0'); 143 | if(info->level < 2) { 144 | ++info->level; 145 | } 146 | } else if(ch == '<') { 147 | __PLAY_ONE_NOTE('\0'); 148 | if(info->level > 0) { 149 | --info->level; 150 | } 151 | } else if(_is_note(ch) || ch == '\0') { 152 | __PLAY_ONE_NOTE(ch); 153 | } 154 | last = ch; 155 | age_sleep(80); 156 | } 157 | if(info->loop) { 158 | info->position = 0; 159 | goto _again; 160 | } else { 161 | AGE_FREE(info->sequence); 162 | info->position = 0; 163 | goto _again; 164 | } 165 | } else { 166 | age_sleep(100); 167 | goto _again; 168 | } 169 | 170 | return result; 171 | } 172 | 173 | #undef __PLAY_ONE_NOTE 174 | 175 | SoundContext* create_sound_context(void) { 176 | SoundContext* result = AGE_MALLOC(SoundContext); 177 | ThreadInfo* bgm = 0; 178 | ThreadInfo* sfx = 0; 179 | bgm = result->bgm = AGE_MALLOC(ThreadInfo); 180 | sfx = result->sfx = AGE_MALLOC(ThreadInfo); 181 | bgm->context = result; 182 | sfx->context = result; 183 | bgm->level = 1; 184 | sfx->level = 1; 185 | 186 | InitializeCriticalSection(&bgm->lock); 187 | InitializeCriticalSection(&sfx->lock); 188 | 189 | bgm->thread_handle = CreateThread(0, 0, sound_proc, bgm, 0, &bgm->thread_id); 190 | sfx->thread_handle = CreateThread(0, 0, sound_proc, sfx, 0, &sfx->thread_id); 191 | SetThreadPriority(bgm->thread_handle, THREAD_PRIORITY_HIGHEST); 192 | SetThreadPriority(sfx->thread_handle, THREAD_PRIORITY_HIGHEST); 193 | age_sleep(1); 194 | 195 | return result; 196 | } 197 | 198 | void destroy_sound_context(SoundContext* _cnt) { 199 | ThreadInfo* bgm = 0; 200 | ThreadInfo* sfx = 0; 201 | bgm = (ThreadInfo*)_cnt->bgm; 202 | sfx = (ThreadInfo*)_cnt->sfx; 203 | 204 | stop_sound(_cnt, ST_BGM); 205 | stop_sound(_cnt, ST_SFX); 206 | 207 | TerminateThread(bgm->thread_handle, 1); 208 | WaitForSingleObject(bgm->thread_handle, 10); 209 | CloseHandle(bgm->thread_handle); 210 | bgm->thread_handle = 0; 211 | bgm->thread_id = 0; 212 | TerminateThread(sfx->thread_handle, 1); 213 | WaitForSingleObject(sfx->thread_handle, 10); 214 | CloseHandle(sfx->thread_handle); 215 | sfx->thread_handle = 0; 216 | sfx->thread_id = 0; 217 | 218 | DeleteCriticalSection(&bgm->lock); 219 | DeleteCriticalSection(&sfx->lock); 220 | 221 | if(bgm->shadow) { 222 | if(bgm->shadow->sequence) { 223 | AGE_FREE(bgm->shadow->sequence); 224 | } 225 | AGE_FREE(bgm->shadow); 226 | } 227 | if(sfx->shadow) { 228 | if(sfx->shadow->sequence) { 229 | AGE_FREE(sfx->shadow->sequence); 230 | } 231 | AGE_FREE(sfx->shadow); 232 | } 233 | if(bgm->sequence) { 234 | AGE_FREE(bgm->sequence); 235 | } 236 | if(sfx->sequence) { 237 | AGE_FREE(sfx->sequence); 238 | } 239 | AGE_FREE(_cnt->bgm); 240 | AGE_FREE(_cnt->sfx); 241 | AGE_FREE(_cnt); 242 | } 243 | 244 | void update_sound(SoundContext* _cnt, s32 _elapsedTime) { 245 | /* do nothing */ 246 | } 247 | 248 | void set_sound_mute(SoundContext* _cnt, bl _mute) { 249 | _cnt->mute = _mute; 250 | } 251 | 252 | void play_sound_string(SoundContext* _cnt, const Str _seq, SoundType _type, bl _loop) { 253 | ThreadInfo* thread = 0; 254 | stop_sound(_cnt, _type); 255 | if(_type == ST_BGM) { 256 | thread = (ThreadInfo*)(_cnt->bgm); 257 | } else if(_type == ST_SFX) { 258 | thread = (ThreadInfo*)(_cnt->sfx); 259 | } else { 260 | assert(0 && "Unknown sound type"); 261 | } 262 | EnterCriticalSection(&thread->lock); { 263 | thread->sequence = copy_string(_seq); 264 | thread->loop = _loop; 265 | thread->stop = FALSE; 266 | } LeaveCriticalSection(&thread->lock); 267 | age_sleep(1); 268 | } 269 | 270 | void stop_sound(SoundContext* _cnt, SoundType _type) { 271 | ThreadInfo* thread = 0; 272 | if(_type == ST_BGM) { 273 | thread = (ThreadInfo*)(_cnt->bgm); 274 | } else if(_type == ST_SFX) { 275 | thread = (ThreadInfo*)(_cnt->sfx); 276 | } else { 277 | assert(0 && "Unknown sound type"); 278 | } 279 | if(thread) { 280 | if(thread->thread_handle) { 281 | EnterCriticalSection(&thread->lock); { 282 | thread->stop = TRUE; 283 | if(thread->sequence) { 284 | AGE_FREE(thread->sequence); 285 | } 286 | thread->level = 1; 287 | thread->position = 0; 288 | } LeaveCriticalSection(&thread->lock); 289 | } 290 | } 291 | } 292 | -------------------------------------------------------------------------------- /ascii_game_engine/audio/ageaudio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_AUDIO_H__ 27 | #define __AGE_AUDIO_H__ 28 | 29 | #include "../ageconfig.h" 30 | #include "../common/agetype.h" 31 | #include "../common/ageallocator.h" 32 | 33 | /** 34 | * @brief sound context 35 | */ 36 | typedef struct SoundContext { 37 | Ptr bgm; /**< bgm thread information */ 38 | Ptr sfx; /**< sfx thread information */ 39 | bl mute; /**< mute or not */ 40 | } SoundContext; 41 | 42 | /** 43 | * @brief sound types 44 | */ 45 | typedef enum SoundType { 46 | ST_BGM, /**< background music */ 47 | ST_SFX, /**< effect */ 48 | ST_COUNT, /**< type count */ 49 | } SoundType; 50 | 51 | /** 52 | * @brief create a sound system context 53 | * 54 | * @return - created sound system context 55 | */ 56 | AGE_API SoundContext* create_sound_context(void); 57 | /** 58 | * @brief destroy a created sound system context 59 | * 60 | * @return - sound system context to be destroyed 61 | */ 62 | AGE_API void destroy_sound_context(SoundContext* _cnt); 63 | 64 | /** 65 | * @brief update an audio system 66 | * 67 | * @param[in] _cnt - sound system context 68 | * @param[in] _elapsedTime - elapsed time since last frame 69 | */ 70 | AGE_API void update_sound(SoundContext* _cnt, s32 _elapsedTime); 71 | 72 | /** 73 | * @brief set mute enabled or disable 74 | * 75 | * @param[in] _cnt - sound system context 76 | * @param[in] _mute - enabled if TRUE or disable if FALSE 77 | */ 78 | AGE_API void set_sound_mute(SoundContext* _cnt, bl _mute); 79 | 80 | /** 81 | * @brief play a sound sequence string 82 | * 83 | * @param[in] _cnt - sound system context 84 | * @param[in] _seq - sequenced sound commands 85 | * @param[in] _type - sound type to be operated 86 | * @param[in] _loop - loop this sound or not 87 | */ 88 | AGE_API void play_sound_string(SoundContext* _cnt, const Str _seq, SoundType _type, bl _loop); 89 | /** 90 | * @brief stop a sound sequence 91 | * 92 | * @param[in] _cnt - sound system context 93 | * @param[in] _type - sound type to be operated 94 | */ 95 | AGE_API void stop_sound(SoundContext* _cnt, SoundType _type); 96 | 97 | #endif /* __AGE_AUDIO_H__ */ 98 | -------------------------------------------------------------------------------- /ascii_game_engine/bitfsm/agebitfsm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | /* 27 | ** This implemention of agebitfsm is a C porting of the original bitfsm in C++ 28 | ** For more info about bitfsm, see http://code.google.com/p/bitfsm/ 29 | */ 30 | 31 | #include "agebitfsm.h" 32 | 33 | static bl _ensure_index_and_step_index_valid(Fsm* _fsm, s32 _index, s32 _step) { 34 | assert(_index >= 0 && _index < _fsm->current->status->bit_count); 35 | if(!(_index >= 0 && _index < _fsm->current->status->bit_count)) { 36 | return FALSE; 37 | } 38 | assert(_step >= 0 && _step < _fsm->rule_steps[_index].steps_count); 39 | if(!(_step >= 0 && _step < _fsm->rule_steps[_index].steps_count)) { 40 | return FALSE; 41 | } 42 | 43 | return TRUE; 44 | } 45 | 46 | FsmStatus* create_fsm_status(s32 _bitsCount) { 47 | FsmStatus* result = AGE_MALLOC(FsmStatus); 48 | result->status = bs_create(_bitsCount); 49 | result->index = -1; 50 | 51 | return result; 52 | } 53 | 54 | void destroy_fsm_status(FsmStatus* _obj) { 55 | bs_destroy(_obj->status); 56 | AGE_FREE(_obj); 57 | } 58 | 59 | FsmStep* create_fsm_step(s32 _bitsCount) { 60 | FsmStep* result = AGE_MALLOC(FsmStep); 61 | result->condition = bs_create(_bitsCount); 62 | result->next = -1; 63 | result->exact = FALSE; 64 | 65 | return result; 66 | } 67 | 68 | void destroy_fsm_step(FsmStep* _obj) { 69 | bs_destroy(_obj->condition); 70 | AGE_FREE(_obj); 71 | } 72 | 73 | FsmRuleStep* create_fsm_rule_step(s32 _count) { 74 | FsmRuleStep* result = AGE_MALLOC_N(FsmRuleStep, _count); 75 | result->index = -1; 76 | result->steps = 0; 77 | result->steps_count = 0; 78 | result->tag = 0; 79 | 80 | return result; 81 | } 82 | 83 | void destroy_fsm_rule_step(FsmRuleStep* _obj) { 84 | s32 i = 0; 85 | 86 | if(_obj) { 87 | if(_obj->steps) { 88 | for(i = 0; i < _obj->steps_count; ++i) { 89 | destroy_fsm_step(_obj->steps[i]); 90 | } 91 | AGE_FREE(_obj->steps); 92 | } 93 | } 94 | } 95 | 96 | void append_fsm_rule_step(FsmRuleStep* _ruleStep, FsmStep* _step) { 97 | assert(_ruleStep && _step); 98 | 99 | _ruleStep->steps = AGE_REALLOC(FsmStep*, _ruleStep->steps, sizeof(FsmStep*) * (++_ruleStep->steps_count)); 100 | _ruleStep->steps[_ruleStep->steps_count - 1] = _step; 101 | } 102 | 103 | void remove_fsm_rule_step(FsmRuleStep* _ruleStep, s32 _index) { 104 | assert(_ruleStep); 105 | assert(_index >= 0 && _index < _ruleStep->steps_count); 106 | 107 | AGE_FREE(_ruleStep->steps[_index]); 108 | _ruleStep->steps[_index] = _ruleStep->steps[_ruleStep->steps_count - 1]; 109 | --_ruleStep->steps_count; 110 | } 111 | 112 | bl walk_rule_step(FsmRuleStep* _ruleStep, FsmStatus* _curr, Bitset* _status, bl _exact) { 113 | Bitset* _s = 0; 114 | s32 i = 0; 115 | FsmStep* _ck = 0; 116 | 117 | if(_ruleStep->index == -1) { 118 | return FALSE; 119 | } 120 | 121 | _s = bs_create(_status->bit_count); 122 | if(_exact) { 123 | bs_set_all_bits(_s, _status); 124 | } else { 125 | bs_arithmetic_or(_curr->status, _status, _s); 126 | } 127 | for(i = 0; i < _ruleStep->steps_count; ++i) { 128 | _ck = _ruleStep->steps[i]; 129 | if((_ck->exact && bs_equals(_ck->condition, _s)) || (!_ck->exact && (bs_logic_and(_ck->condition, _s)))) { 130 | _curr->index = _ck->next; 131 | bs_set_all_bits(_curr->status, _s); 132 | bs_destroy(_s); 133 | 134 | return TRUE; 135 | } 136 | } 137 | bs_destroy(_s); 138 | 139 | return FALSE; 140 | } 141 | 142 | Fsm* create_bitfsm(s32 _statusCount, s32 _commandCount, ObjToIndexFunc _objToIndex, ObjToCommandFunc _objToCommand, IntStepHendlerFunc _intHandler, ObjStepHandlerFunc _objHandler, destroyer _tagDestructor) { 143 | Fsm* result = 0; 144 | 145 | result = AGE_MALLOC(Fsm); 146 | result->current = create_fsm_status(_commandCount); 147 | result->rule_steps = create_fsm_rule_step(_statusCount); 148 | result->rule_steps_count = _statusCount; 149 | result->obj_to_index = _objToIndex; 150 | result->obj_to_command = _objToCommand; 151 | result->int_handler = _intHandler; 152 | result->obj_handler = _objHandler; 153 | result->tag_destructor = _tagDestructor; 154 | 155 | return result; 156 | } 157 | 158 | void destroy_bitfsm(Fsm* _fsm) { 159 | s32 i = 0; 160 | if(_fsm->rule_steps) { 161 | for(i = 0; i < _fsm->rule_steps_count; ++i) { 162 | destroy_fsm_rule_step(&_fsm->rule_steps[i]); 163 | } 164 | AGE_FREE(_fsm->rule_steps); 165 | _fsm->rule_steps = 0; 166 | _fsm->rule_steps_count = 0; 167 | } 168 | destroy_fsm_status(_fsm->current); 169 | AGE_FREE(_fsm); 170 | } 171 | 172 | void reset_bitfsm(Fsm* _fsm) { 173 | bs_clear(_fsm->current->status); 174 | _fsm->current->index = -1; 175 | _fsm->terminal_index = -1; 176 | } 177 | 178 | void clear_bitfsm(Fsm* _fsm) { 179 | reset_bitfsm(_fsm); 180 | clear_bitfsm_all_rule_steps(_fsm); 181 | } 182 | 183 | bl set_bitfsm_current_step_index(Fsm* _fsm, s32 _index) { 184 | assert(_index >= 0 && _index < _fsm->rule_steps_count); 185 | if(!(_index >= 0 && _index < _fsm->rule_steps_count)) { 186 | return FALSE; 187 | } 188 | _fsm->current->index = _index; 189 | 190 | return TRUE; 191 | } 192 | 193 | bl set_bitfsm_current_step_tag(Fsm* _fsm, Ptr _obj) { 194 | s32 _index = _fsm->obj_to_index(_obj); 195 | 196 | return set_bitfsm_current_step_index(_fsm, _index); 197 | } 198 | 199 | bl set_bitfsm_terminal_step_index(Fsm* _fsm, s32 _index) { 200 | assert(_index >= 0 && _index < _fsm->rule_steps_count); 201 | if(!(_index >= 0 && _index < _fsm->rule_steps_count)) { 202 | return FALSE; 203 | } 204 | _fsm->terminal_index = _index; 205 | 206 | return TRUE; 207 | } 208 | 209 | bl set_bitfsm_terminal_step_tag(Fsm* _fsm, Ptr _obj) { 210 | s32 _index = _fsm->obj_to_index(_obj); 211 | 212 | return set_bitfsm_terminal_step_index(_fsm, _index); 213 | } 214 | 215 | void set_bitfsm_step_handler(Fsm* _fsm, IntStepHendlerFunc _intHdl, ObjStepHandlerFunc _objHdl) { 216 | _fsm->int_handler = _intHdl; 217 | _fsm->obj_handler = _objHdl; 218 | } 219 | 220 | bl register_bitfsm_rule_step_index_to_tag(Fsm* _fsm, s32 _index, Ptr _tag) { 221 | assert(_index >= 0 && _index < _fsm->rule_steps_count); 222 | if(!(_index >= 0 && _index < _fsm->rule_steps_count)) { 223 | return FALSE; 224 | } 225 | _fsm->rule_steps[_index].tag = _tag; 226 | 227 | return TRUE; 228 | } 229 | 230 | bl register_bitfsm_rule_step_tag(Fsm* _fsm, Ptr _obj) { 231 | s32 _index = _fsm->obj_to_index(_obj); 232 | 233 | return register_bitfsm_rule_step_index_to_tag(_fsm, _index, _obj); 234 | } 235 | 236 | bl add_bitfsm_rule_step_by_index(Fsm* _fsm, s32 _index, Bitset* _cond, s32 _next, bl _exact) { 237 | FsmStep** _steps = 0; 238 | FsmStep* _step = 0; 239 | FsmStep* _newStep = 0; 240 | s32 i = 0; 241 | 242 | assert(_index >= 0 && _index < _fsm->rule_steps_count); 243 | if(!(_index >= 0 && _index < _fsm->rule_steps_count)) { 244 | return FALSE; 245 | } 246 | 247 | _steps = _fsm->rule_steps[_index].steps; 248 | for(i = 0; i < _fsm->rule_steps[_index].steps_count; ++i) { 249 | _step = _steps[i]; 250 | if(bs_equals(_step->condition, _cond)) { 251 | return FALSE; 252 | } 253 | } 254 | 255 | _fsm->rule_steps[_index].index = _index; 256 | _newStep = create_fsm_step(_cond->bit_count); 257 | bs_set_all_bits(_newStep->condition, _cond); 258 | _newStep->next = _next; 259 | _newStep->exact = _exact; 260 | append_fsm_rule_step(&_fsm->rule_steps[_index], _newStep); 261 | 262 | return TRUE; 263 | } 264 | 265 | bl add_bitfsm_rule_step_by_tag(Fsm* _fsm, Ptr _indexObj, Bitset* _cond, Ptr _nextObj, bl _exact) { 266 | s32 _index = _fsm->obj_to_index(_indexObj); 267 | s32 _next = _fsm->obj_to_index(_nextObj); 268 | 269 | return add_bitfsm_rule_step_by_index(_fsm, _index, _cond, _next, _exact); 270 | } 271 | 272 | bl add_bitfsm_rule_step_by_tag_params(Fsm* _fsm, Ptr _indexObj, ls_node_t* _cond, Ptr _nextObj, bl _exact) { 273 | bl result = TRUE; 274 | s32 _index = _fsm->obj_to_index(_indexObj); 275 | s32 _next = _fsm->obj_to_index(_nextObj); 276 | Bitset* _condBits = bs_create(_fsm->current->status->bit_count); 277 | s32 i = 0; 278 | s32 idx = 0; 279 | Ptr data = 0; 280 | for(i = 0; i < (s32)ls_count(_cond); ++i) { 281 | data = ls_at(_cond, i)->data; 282 | idx = _fsm->obj_to_command(data); 283 | bs_set_bit(_condBits, idx, TRUE); 284 | } 285 | result = add_bitfsm_rule_step_by_index(_fsm, _index, _condBits, _next, _exact); 286 | bs_destroy(_condBits); 287 | 288 | return result; 289 | } 290 | 291 | bl remove_bitfsm_rule_step_by_index(Fsm* _fsm, s32 _index, Bitset* _cond) { 292 | FsmStep** _steps = 0; 293 | FsmStep* _step = 0; 294 | s32 i = 0; 295 | 296 | assert(_index >= 0 && _index < _fsm->rule_steps_count); 297 | if(!(_index >= 0 && _index < _fsm->rule_steps_count)) { 298 | return FALSE; 299 | } 300 | 301 | _steps = _fsm->rule_steps[_index].steps; 302 | for(i = 0; i < _fsm->rule_steps[_index].steps_count; ++i) { 303 | _step = _steps[i]; 304 | if(bs_equals(_step->condition, _cond)) { 305 | remove_fsm_rule_step(_fsm->rule_steps, i); 306 | 307 | return TRUE; 308 | } 309 | } 310 | 311 | return FALSE; 312 | } 313 | 314 | bl remove_bitfsm_rule_step_by_tag(Fsm* _fsm, Ptr _indexObj, Bitset* _cond) { 315 | s32 _index = _fsm->obj_to_index(_indexObj); 316 | 317 | return remove_bitfsm_rule_step_by_index(_fsm, _index, _cond); 318 | } 319 | 320 | bl remove_bitfsm_rule_step_by_tag_params(Fsm* _fsm, Ptr _indexObj, ls_node_t* _cond) { 321 | bl result = TRUE; 322 | s32 _index = _fsm->obj_to_index(_indexObj); 323 | Bitset* _condBits = bs_create(_fsm->current->status->bit_count); 324 | s32 i = 0; 325 | s32 idx = 0; 326 | Ptr data = 0; 327 | for(i = 0; i < (s32)ls_count(_cond); ++i) { 328 | data = ls_at(_cond, i)->data; 329 | idx = _fsm->obj_to_command(data); 330 | bs_set_bit(_condBits, idx, TRUE); 331 | } 332 | result = remove_bitfsm_rule_step_by_index(_fsm, _index, _condBits); 333 | bs_destroy(_condBits); 334 | 335 | return result; 336 | } 337 | 338 | void clear_bitfsm_rule_step(Fsm* _fsm, s32 _index) { 339 | assert(_index >= 0 && _index < _fsm->rule_steps_count); 340 | if(_index >= 0 && _index < _fsm->rule_steps_count) { 341 | _fsm->rule_steps[_index].index = -1; 342 | if(_fsm->tag_destructor) { 343 | _fsm->tag_destructor(_fsm->rule_steps[_index].tag); 344 | _fsm->rule_steps[_index].tag = 0; 345 | } 346 | } 347 | } 348 | 349 | void clear_bitfsm_all_rule_steps(Fsm* _fsm) { 350 | s32 i = 0; 351 | for(i = 0; i < _fsm->rule_steps_count; ++i) { 352 | clear_bitfsm_rule_step(_fsm, i); 353 | } 354 | for(i = 0; i < _fsm->rule_steps_count; ++i) { 355 | destroy_fsm_rule_step(&_fsm->rule_steps[i]); 356 | } 357 | AGE_FREE(_fsm->rule_steps); 358 | _fsm->rule_steps = 0; 359 | _fsm->rule_steps_count = 0; 360 | } 361 | 362 | s32 get_bitfsm_current_step(Fsm* _fsm) { 363 | return _fsm->current->index; 364 | } 365 | 366 | Bitset* get_bitfsm_current_status(Fsm* _fsm) { 367 | return _fsm->current->status; 368 | } 369 | 370 | bl walk_bitfsm_with_int(Fsm* _fsm, s32 _status, bl _exact) { 371 | bl _result = TRUE; 372 | Bitset* _bs = 0; 373 | s32 _srcIdx = 0; 374 | Ptr _srcTag = 0; 375 | s32 _tgtIdx = 0; 376 | Ptr _tgtTag = 0; 377 | 378 | assert(_status >= 0 && _status < _fsm->current->status->bit_count); 379 | if(!(_status >= 0 && _status < _fsm->current->status->bit_count)) { 380 | return FALSE; 381 | } 382 | if(_fsm->current->index < 0 || _fsm->current->index >= _fsm->rule_steps_count) { 383 | return FALSE; 384 | } 385 | 386 | _bs = bs_create(_fsm->current->status->bit_count); 387 | bs_set_bit(_bs, _status, TRUE); 388 | 389 | _srcIdx = _fsm->current->index; 390 | _srcTag = _fsm->rule_steps[_srcIdx].tag; 391 | _result = walk_rule_step(&_fsm->rule_steps[_srcIdx], _fsm->current, _bs, _exact); 392 | _tgtIdx = _fsm->current->index; 393 | _tgtTag = _fsm->rule_steps[_tgtIdx].tag; 394 | 395 | if(_result && (_fsm->int_handler || _fsm->obj_handler)) { 396 | if(_fsm->int_handler) { 397 | _fsm->int_handler(_srcIdx, _tgtIdx); 398 | } 399 | if(_fsm->obj_handler) { 400 | _fsm->obj_handler(_srcTag, _tgtTag); 401 | } 402 | } 403 | 404 | bs_destroy(_bs); 405 | 406 | return _result; 407 | } 408 | 409 | bl walk_bitfsm_with_tag(Fsm* _fsm, Ptr _obj, bl _exact) { 410 | s32 _status = _fsm->obj_to_command(_obj); 411 | 412 | return walk_bitfsm_with_int(_fsm, _status, _exact); 413 | } 414 | 415 | bl terminated_bitfsm(Fsm* _fsm) { 416 | return _fsm->current->index == _fsm->terminal_index; 417 | } 418 | 419 | s32 get_bitfsm_status_count(Fsm* _fsm) { 420 | return _fsm->rule_steps_count; 421 | } 422 | 423 | Ptr get_bitfsm_status_tag(Fsm* _fsm, s32 _index) { 424 | assert(_index >= 0 && _index < _fsm->rule_steps_count); 425 | if(!(_index >= 0 && _index < _fsm->rule_steps_count)) { 426 | return 0; 427 | } 428 | 429 | return _fsm->rule_steps[_index].tag; 430 | } 431 | 432 | s32 get_bitfsm_command_count(Fsm* _fsm, s32 _index) { 433 | assert(_index >= 0 && _index < _fsm->rule_steps_count); 434 | if(!(_index >= 0 && _index < _fsm->rule_steps_count)) { 435 | return 0; 436 | } 437 | 438 | return _fsm->rule_steps[_index].steps_count; 439 | } 440 | 441 | Bitset* get_bitfsm_step_command_condition(Fsm* _fsm, s32 _index, s32 _step) { 442 | if(!_ensure_index_and_step_index_valid(_fsm, _index, _step)) { 443 | assert(0 && "Invalid index"); 444 | return 0; 445 | } 446 | 447 | return _fsm->rule_steps[_index].steps[_step]->condition; 448 | } 449 | 450 | s32 get_bitfsm_step_command_next(Fsm* _fsm, s32 _index, s32 _step) { 451 | if(!_ensure_index_and_step_index_valid(_fsm, _index, _step)) { 452 | assert(0 && "Invalid index"); 453 | return 0; 454 | } 455 | 456 | return _fsm->rule_steps[_index].steps[_step]->next; 457 | } 458 | 459 | bl get_bitfsm_step_exact(Fsm* _fsm, s32 _index, s32 _step) { 460 | if(!_ensure_index_and_step_index_valid(_fsm, _index, _step)) { 461 | assert(0 && "Invalid index"); 462 | return 0; 463 | } 464 | 465 | return _fsm->rule_steps[_index].steps[_step]->exact; 466 | } 467 | -------------------------------------------------------------------------------- /ascii_game_engine/common/ageallocator.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "../common/ageutil.h" 27 | #include "ageallocator.h" 28 | 29 | #ifdef _DEBUG 30 | Ptr age_malloc_dbg(s32 _size, const Str _file, s32 _line) { 31 | Ptr result = _malloc_dbg(_size, _NORMAL_BLOCK, _file, _line); 32 | memset(result, 0, _size); 33 | 34 | return result; 35 | } 36 | #endif 37 | 38 | Ptr age_malloc(s32 _size) { 39 | Ptr result = malloc(_size); 40 | memset(result, 0, _size); 41 | 42 | return result; 43 | } 44 | 45 | Ptr age_realloc(Ptr _ori, s32 _size) { 46 | Ptr result = realloc(_ori, _size); 47 | 48 | return result; 49 | } 50 | 51 | void age_free(Ptr _ptr) { 52 | assert(_ptr); 53 | 54 | free(_ptr); 55 | } 56 | -------------------------------------------------------------------------------- /ascii_game_engine/common/ageallocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_ALLOCATOR_H__ 27 | #define __AGE_ALLOCATOR_H__ 28 | 29 | #include "../ageconfig.h" 30 | #include "../common/agetype.h" 31 | 32 | /** 33 | * @brief memory allocator functor 34 | * 35 | * @param[in] _size - size to be allocated in bytes 36 | * @return - allocated memory 37 | */ 38 | typedef Ptr (* creator)(s32 _size); 39 | /** 40 | * @brief memory deallocator functor 41 | * 42 | * @param[in] _ptr - pointer of a piece of memory to be deallocated 43 | */ 44 | typedef void (* destroyer)(Ptr _ptr); 45 | 46 | #ifdef _DEBUG 47 | /** 48 | * @brief malloc a piece of space with debug information 49 | * 50 | * @param[in] _size - bytes count to be malloced 51 | * @param[in] _file - caller file name 52 | * @param[in] _line - caller line number 53 | * @return - pointer to the malloced space 54 | */ 55 | AGE_API Ptr age_malloc_dbg(s32 _size, const Str _file, s32 _line); 56 | #endif 57 | /** 58 | * @brief malloc a piece of space 59 | * 60 | * @param[in] _size - bytes count to be malloced 61 | * @return - pointer to the malloced space 62 | */ 63 | AGE_API Ptr age_malloc(s32 _size); 64 | /** 65 | * @brief realloc a piece of space 66 | * 67 | * @param[in] _ori - original memory 68 | * @param[in] _size - new size in byts 69 | * @return - pointer to the realloced spece 70 | */ 71 | AGE_API Ptr age_realloc(Ptr _ori, s32 _size); 72 | /** 73 | * @brief free a piece of space 74 | * 75 | * @param[in] _ptr - pointer to the malloced space 76 | */ 77 | AGE_API void age_free(Ptr _ptr); 78 | 79 | #ifndef _age_malloc 80 | # ifdef _DEBUG 81 | # define _age_malloc(_type, _size) ((_type*)age_malloc_dbg(_size, __FILE__, __LINE__)) 82 | # else 83 | # define _age_malloc(_type, _size) ((_type*)age_malloc(_size)) 84 | # endif 85 | #endif 86 | #ifndef AGE_MALLOC 87 | # define AGE_MALLOC(_type) (_age_malloc(_type, sizeof(_type))) 88 | #endif 89 | #ifndef AGE_MALLOC_N 90 | # define AGE_MALLOC_N(_type, _count) (_age_malloc(_type, sizeof(_type) * _count)) 91 | #endif 92 | #ifndef AGE_FREE 93 | # define AGE_FREE(_ptr) { age_free(_ptr); (_ptr) = 0; } 94 | #endif 95 | #ifndef AGE_FREE_N 96 | # define AGE_FREE_N(_ptr) { age_free(_ptr); (_ptr) = 0; } 97 | #endif 98 | #ifndef AGE_REALLOC 99 | # define AGE_REALLOC(_type, _ptr, _size) ((_type*)age_realloc(_ptr, _size)) 100 | #endif 101 | #ifndef AGE_REALLOC_N 102 | # define AGE_REALLOC_N(_type, _ptr, _count) ((_type*)age_realloc(_ptr, sizeof(_type) * _count)) 103 | #endif 104 | 105 | #endif /* __AGE_ALLOCATOR_H__ */ 106 | -------------------------------------------------------------------------------- /ascii_game_engine/common/agebitset.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "agebitset.h" 27 | 28 | #ifndef _size_to_dword 29 | # define _size_to_dword(n) (((n) - 1) / 32 + 1) 30 | #endif 31 | 32 | #ifndef _size_to_byte 33 | # define _size_to_byte(n) (((n) - 1) / 8 + 1) 34 | #endif 35 | 36 | static void _getRawArrayPos(s32 _pos, s32* _index, s32* _offset) { 37 | *_index = _pos / 32; 38 | *_offset = _pos % 32; 39 | } 40 | 41 | Bitset* bs_create(s32 _size) { 42 | Bitset* result = 0; 43 | 44 | result = AGE_MALLOC(Bitset); 45 | result->bit_count = _size; 46 | result->dword_count = _size_to_dword(_size); 47 | result->byte_count = result->dword_count * sizeof(u32); 48 | result->raw = AGE_MALLOC_N(u32, result->dword_count); 49 | 50 | return result; 51 | } 52 | 53 | void bs_destroy(Bitset* _bs) { 54 | AGE_FREE_N(_bs->raw); 55 | AGE_FREE(_bs); 56 | } 57 | 58 | void bs_clear(Bitset* _bs) { 59 | memset(_bs->raw, 0, _bs->byte_count); 60 | } 61 | 62 | void bs_set_bit(Bitset* _bs, s32 _pos, bl _val) { 63 | s32 index = 0; 64 | s32 offset = 0; 65 | _getRawArrayPos(_pos, &index, &offset); 66 | if(_val) { 67 | _bs->raw[index] |= (1 << offset); 68 | } else { 69 | _bs->raw[index] &= ~(1 << offset); 70 | } 71 | } 72 | 73 | void bs_set_all_bits(Bitset* _bs, Bitset* _other) { 74 | assert(_bs && _other); 75 | assert(_bs->bit_count == _other->bit_count); 76 | if(_bs->bit_count == _other->bit_count) { 77 | memcpy(_bs->raw, _other->raw, _bs->byte_count); 78 | } 79 | } 80 | 81 | bl bs_get_bit(Bitset* _bs, s32 _pos) { 82 | s32 index = 0; 83 | s32 offset = 0; 84 | _getRawArrayPos(_pos, &index, &offset); 85 | 86 | return (bl)((_bs->raw[index] | (1 << offset)) != 0); 87 | } 88 | 89 | bl bs_empty(Bitset* _bs) { 90 | s32 i = 0; 91 | for(i = 0; i < _bs->dword_count; ++i) { 92 | if(_bs->raw[i] != 0) { 93 | return FALSE; 94 | } 95 | } 96 | 97 | return TRUE; 98 | } 99 | 100 | bl bs_equals(Bitset* _bs, Bitset* _other) { 101 | assert(_bs && _other); 102 | assert(_bs->bit_count == _other->bit_count); 103 | if(_bs->bit_count == _other->bit_count) { 104 | return (bl)(memcmp(_bs->raw, _other->raw, _bs->byte_count) == 0); 105 | } else { 106 | return FALSE; 107 | } 108 | } 109 | 110 | void bs_arithmetic_and(Bitset* _bs, Bitset* _other, Bitset* _result) { 111 | s32 i = 0; 112 | 113 | assert(_bs && _other && _result); 114 | assert(_bs->bit_count == _other->bit_count && _bs->bit_count == _result->bit_count); 115 | if(_bs->bit_count == _other->bit_count) { 116 | for(i = 0; i < _bs->dword_count; ++i) { 117 | _result->raw[i] = _bs->raw[i] & _other->raw[i]; 118 | } 119 | } 120 | } 121 | 122 | void bs_arithmetic_or(Bitset* _bs, Bitset* _other, Bitset* _result) { 123 | s32 i = 0; 124 | 125 | assert(_bs && _other && _result); 126 | assert(_bs->bit_count == _other->bit_count && _bs->bit_count == _result->bit_count); 127 | if(_bs->bit_count == _other->bit_count) { 128 | for(i = 0; i < _bs->dword_count; ++i) { 129 | _result->raw[i] = _bs->raw[i] | _other->raw[i]; 130 | } 131 | } 132 | } 133 | 134 | bl bs_logic_and(Bitset* _bs, Bitset* _other) { 135 | s32 i = 0; 136 | 137 | assert(_bs && _other); 138 | assert(_bs->bit_count == _other->bit_count); 139 | if(_bs->bit_count == _other->bit_count) { 140 | for(i = 0; i < _bs->dword_count; ++i) { 141 | if((_bs->raw[i] & _other->raw[i]) != 0) { 142 | return TRUE; 143 | } 144 | } 145 | 146 | return FALSE; 147 | } else { 148 | return FALSE; 149 | } 150 | } 151 | 152 | bl bs_logic_or(Bitset* _bs, Bitset* _other) { 153 | s32 i = 0; 154 | 155 | assert(_bs && _other); 156 | assert(_bs->bit_count == _other->bit_count); 157 | if(_bs->bit_count == _other->bit_count) { 158 | for(i = 0; i < _bs->dword_count; ++i) { 159 | if((_bs->raw[i] | _other->raw[i]) != 0) { 160 | return TRUE; 161 | } 162 | } 163 | 164 | return FALSE; 165 | } else { 166 | return FALSE; 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /ascii_game_engine/common/agebitset.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_BITSET_H__ 27 | #define __AGE_BITSET_H__ 28 | 29 | #include "../ageconfig.h" 30 | #include "../common/agetype.h" 31 | #include "../common/ageallocator.h" 32 | 33 | typedef struct Bitset { 34 | s32 bit_count; 35 | s32 dword_count; 36 | s32 byte_count; 37 | u32* raw; 38 | } Bitset; 39 | 40 | AGE_API Bitset* bs_create(s32 _size); 41 | AGE_API void bs_destroy(Bitset* _bs); 42 | AGE_API void bs_clear(Bitset* _bs); 43 | AGE_API void bs_set_bit(Bitset* _bs, s32 _pos, bl _val); 44 | AGE_API void bs_set_all_bits(Bitset* _bs, Bitset* _other); 45 | AGE_API bl bs_get_bit(Bitset* _bs, s32 _pos); 46 | AGE_API bl bs_empty(Bitset* _bs); 47 | AGE_API bl bs_equals(Bitset* _bs, Bitset* _other); 48 | AGE_API void bs_arithmetic_and(Bitset* _bs, Bitset* _other, Bitset* _result); 49 | AGE_API void bs_arithmetic_or(Bitset* _bs, Bitset* _other, Bitset* _result); 50 | AGE_API bl bs_logic_and(Bitset* _bs, Bitset* _other); 51 | AGE_API bl bs_logic_or(Bitset* _bs, Bitset* _other); 52 | 53 | #endif /* __AGE_BITSET_H__ */ 54 | -------------------------------------------------------------------------------- /ascii_game_engine/common/agehashtable.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "agehashtable.h" 27 | 28 | #define safe_free(__p) { if(__p) { free(__p); __p = 0; } else { assert(0 && "Memory already released"); } } 29 | 30 | u32 ht_hash_string(Ptr ht, Ptr d) { 31 | u32 result = 0; 32 | ht_node_t* self = (ht_node_t*)ht; 33 | Str s = (Str)d; 34 | u32 h = 0; 35 | 36 | assert(ht); 37 | 38 | for( ; *s; ++s) { 39 | h = 5 * h + *s; 40 | } 41 | 42 | result = h % self->array_size; 43 | 44 | return result; 45 | } 46 | 47 | u32 ht_hash_int(Ptr ht, Ptr d) { 48 | u32 result = 0; 49 | ht_node_t* self = (ht_node_t*)ht; 50 | s32 i = *(s32*)d; 51 | 52 | assert(ht); 53 | 54 | result = (u32)i; 55 | result %= self->array_size; 56 | 57 | return result; 58 | } 59 | 60 | u32 ht_hash_real(Ptr ht, Ptr d) { 61 | f32 r = *(f32*)d; 62 | union { 63 | f32 r; 64 | s32 i; 65 | } u; 66 | u.r = r; 67 | 68 | return ht_hash_int(ht, &u.i); 69 | } 70 | 71 | u32 ht_hash_ptr(Ptr ht, Ptr d) { 72 | union { 73 | s32 i; 74 | Ptr p; 75 | } u; 76 | u.p = d; 77 | 78 | return ht_hash_int(ht, &u.i); 79 | } 80 | 81 | s32 ht_cmp_string(Ptr d1, Ptr d2) { 82 | Str s1 = (Str)d1; 83 | Str s2 = (Str)d2; 84 | 85 | return strcmp(s1, s2); 86 | } 87 | 88 | s32 ht_cmp_int(Ptr d1, Ptr d2) { 89 | s32 i1 = *(s32*)d1; 90 | s32 i2 = *(s32*)d2; 91 | s32 i = i1 - i2; 92 | s32 result = 0; 93 | if(i < 0) { 94 | result = -1; 95 | } else if(i > 0) { 96 | result = 1; 97 | } 98 | 99 | return result; 100 | } 101 | 102 | s32 ht_cmp_real(Ptr d1, Ptr d2) { 103 | f32 r1 = *(f32*)d1; 104 | f32 r2 = *(f32*)d2; 105 | f32 r = r1 - r2; 106 | s32 result = 0; 107 | if(r < 0.0f) { 108 | result = -1; 109 | } else if(r > 0.0f) { 110 | result = 1; 111 | } 112 | 113 | return result; 114 | } 115 | 116 | s32 ht_cmp_ptr(Ptr d1, Ptr d2) { 117 | s32 i1 = *(s32*)d1; 118 | s32 i2 = *(s32*)d2; 119 | s32 i = i1 - i2; 120 | s32 result = 0; 121 | if(i < 0) { 122 | result = -1; 123 | } else if(i > 0) { 124 | result = 1; 125 | } 126 | 127 | return result; 128 | } 129 | 130 | ht_node_t* ht_create(u32 size, ht_compare cmp, ht_hash hs, ls_operation freeextra) { 131 | const u32 array_size = size ? size : HT_ARRAY_SIZE_DEFAULT; 132 | ht_node_t* result = 0; 133 | u32 ul = 0; 134 | 135 | if(!cmp) { 136 | cmp = ht_cmp_int; 137 | } 138 | if(!hs) { 139 | hs = ht_hash_int; 140 | } 141 | 142 | result = (ht_node_t*)malloc(sizeof(ht_node_t)); 143 | result->free_extra = freeextra; 144 | result->compare = cmp; 145 | result->hash = hs; 146 | result->array_size = array_size; 147 | result->count = 0; 148 | result->array = (ls_node_t**)malloc(sizeof(ls_node_t*) * result->array_size); 149 | for(ul = 0; ul < result->array_size; ++ul) { 150 | result->array[ul] = ls_create(); 151 | } 152 | 153 | return result; 154 | } 155 | 156 | ls_node_t* ht_find(ht_node_t* ht, Ptr key) { 157 | ls_node_t* result = 0; 158 | ls_node_t* bucket = 0; 159 | u32 hash_code = 0; 160 | 161 | assert(ht && key); 162 | 163 | hash_code = ht->hash(ht, key); 164 | bucket = ht->array[hash_code]; 165 | bucket = bucket->next; 166 | while(bucket) { 167 | if(ht->compare(bucket->extra, key) == 0) { 168 | result = bucket; 169 | break; 170 | } 171 | bucket = bucket->next; 172 | } 173 | 174 | return result; 175 | } 176 | 177 | u32 ht_count(ht_node_t* ht) { 178 | u32 result = 0; 179 | 180 | assert(ht); 181 | 182 | result = ht->count; 183 | 184 | return result; 185 | } 186 | 187 | u32 ht_get(ht_node_t* ht, Ptr key, Ptr* value) { 188 | u32 result = 0; 189 | ls_node_t* bucket = 0; 190 | 191 | assert(ht && key && value); 192 | 193 | bucket = ht_find(ht, key); 194 | if(bucket) { 195 | *value = bucket->data; 196 | ++result; 197 | } 198 | 199 | return result; 200 | } 201 | 202 | u32 ht_set(ht_node_t* ht, Ptr key, Ptr value) { 203 | u32 result = 0; 204 | ls_node_t* bucket = 0; 205 | 206 | assert(ht && key); 207 | 208 | bucket = ht_find(ht, key); 209 | if(bucket) { 210 | bucket->data = value; 211 | ++result; 212 | } 213 | 214 | return result; 215 | } 216 | 217 | u32 ht_set_or_insert(ht_node_t* ht, Ptr key, Ptr value) { 218 | u32 result = 0; 219 | ls_node_t* bucket = 0; 220 | u32 hash_code = 0; 221 | 222 | assert(ht && key); 223 | 224 | bucket = ht_find(ht, key); 225 | if(bucket) { /* Update */ 226 | bucket->data = value; 227 | ++result; 228 | } else { /* Insert */ 229 | hash_code = ht->hash(ht, key); 230 | bucket = ht->array[hash_code]; 231 | bucket = ls_pushback(bucket, value); 232 | assert(bucket); 233 | bucket->extra = key; 234 | ++result; 235 | } 236 | 237 | return result; 238 | } 239 | 240 | u32 ht_remove(ht_node_t* ht, Ptr key) { 241 | u32 result = 0; 242 | u32 hash_code = 0; 243 | ls_node_t* bucket = 0; 244 | 245 | assert(ht && key); 246 | 247 | bucket = ht_find(ht, key); 248 | hash_code = ht->hash(ht, key); 249 | bucket = ht->array[hash_code]; 250 | result = ls_try_remove(bucket, key, ls_cmp_extra); 251 | 252 | return result; 253 | } 254 | 255 | u32 ht_foreach(ht_node_t* ht, ht_operation op) { 256 | u32 result = 0; 257 | ls_node_t* bucket = 0; 258 | u32 ul = 0; 259 | 260 | for(ul = 0; ul < ht->array_size; ++ul) { 261 | bucket = ht->array[ul]; 262 | if(bucket) { 263 | result += ls_foreach(bucket, op); 264 | } 265 | } 266 | 267 | return result; 268 | } 269 | 270 | bl ht_empty(ht_node_t* ht) { 271 | return 0 == ht_count(ht); 272 | } 273 | 274 | void ht_clear(ht_node_t* ht) { 275 | u32 ul = 0; 276 | 277 | assert(ht && ht->array); 278 | 279 | for(ul = 0; ul < ht->array_size; ++ul) { 280 | ls_clear(ht->array[ul]); 281 | } 282 | } 283 | 284 | void ht_destroy(ht_node_t* ht) { 285 | u32 ul = 0; 286 | 287 | assert(ht && ht->array); 288 | 289 | if(ht->free_extra) { 290 | ht_foreach(ht, ht->free_extra); 291 | } 292 | 293 | for(ul = 0; ul < ht->array_size; ++ul) { 294 | ls_destroy(ht->array[ul]); 295 | } 296 | safe_free(ht->array); 297 | safe_free(ht); 298 | } 299 | -------------------------------------------------------------------------------- /ascii_game_engine/common/agehashtable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_HASH_TABLE_H__ 27 | #define __AGE_HASH_TABLE_H__ 28 | 29 | #include "../ageconfig.h" 30 | #include "../common/agetype.h" 31 | #include "agelist.h" 32 | 33 | #define HT_ARRAY_SIZE_SMALL 193 34 | #define HT_ARRAY_SIZE_MID 1543 35 | #define HT_ARRAY_SIZE_BIG 12289 36 | #define HT_ARRAY_SIZE_DEFAULT HT_ARRAY_SIZE_SMALL 37 | 38 | typedef u32 (* ht_hash)(Ptr, Ptr); 39 | typedef acl_common_compare ht_compare; 40 | typedef acl_common_operation ht_operation; 41 | 42 | typedef struct ht_node_t { 43 | ls_operation free_extra; 44 | ht_compare compare; 45 | ht_hash hash; 46 | u32 array_size; 47 | u32 count; 48 | ls_node_t** array; 49 | } ht_node_t; 50 | 51 | AGE_API u32 ht_hash_string(Ptr ht, Ptr d); 52 | AGE_API u32 ht_hash_int(Ptr ht, Ptr d); 53 | AGE_API u32 ht_hash_real(Ptr ht, Ptr d); 54 | AGE_API u32 ht_hash_ptr(Ptr ht, Ptr d); 55 | 56 | AGE_API s32 ht_cmp_string(Ptr d1, Ptr d2); 57 | AGE_API s32 ht_cmp_int(Ptr d1, Ptr d2); 58 | AGE_API s32 ht_cmp_real(Ptr d1, Ptr d2); 59 | AGE_API s32 ht_cmp_ptr(Ptr d1, Ptr d2); 60 | 61 | AGE_API ht_node_t* ht_create(u32 size, ht_compare cmp, ht_hash hs, ls_operation freeextra); 62 | AGE_API ls_node_t* ht_find(ht_node_t* ht, Ptr key); 63 | AGE_API u32 ht_count(ht_node_t* ht); 64 | AGE_API u32 ht_get(ht_node_t* ht, Ptr key, Ptr* value); 65 | AGE_API u32 ht_set(ht_node_t* ht, Ptr key, Ptr value); 66 | AGE_API u32 ht_set_or_insert(ht_node_t* ht, Ptr key, Ptr value); 67 | AGE_API u32 ht_remove(ht_node_t* ht, Ptr key); 68 | AGE_API u32 ht_foreach(ht_node_t* ht, ht_operation op); 69 | AGE_API bl ht_empty(ht_node_t* ht); 70 | AGE_API void ht_clear(ht_node_t* ht); 71 | AGE_API void ht_destroy(ht_node_t* ht); 72 | 73 | #endif /* __AGE_HASH_TABLE_H__ */ 74 | -------------------------------------------------------------------------------- /ascii_game_engine/common/agelist.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "agelist.h" 27 | 28 | #define safe_free(__p) { if(__p) { free(__p); __p = 0; } else { assert(0 && "Memory already released"); } } 29 | 30 | s32 ls_cmp_data(Ptr node, Ptr info) { 31 | ls_node_t* n = (ls_node_t*)node; 32 | 33 | return (n->data == info) ? 0 : 1; 34 | } 35 | 36 | s32 ls_cmp_extra(Ptr node, Ptr info) { 37 | ls_node_t* n = (ls_node_t*)node; 38 | 39 | return (n->extra == info) ? 0 : 1; 40 | } 41 | 42 | ls_node_t* ls_create_node(Ptr data) { 43 | ls_node_t* result = 0; 44 | 45 | result = (ls_node_t*)malloc(sizeof(ls_node_t)); 46 | assert(result); 47 | memset(result, 0, sizeof(ls_node_t)); 48 | result->data = data; 49 | 50 | return result; 51 | } 52 | 53 | ls_node_t* ls_create(void) { 54 | ls_node_t* result = 0; 55 | 56 | result = ls_create_node(0); 57 | 58 | return result; 59 | } 60 | 61 | ls_node_t* ls_front(ls_node_t* node) { 62 | ls_node_t* result = node; 63 | 64 | result = result->next; 65 | 66 | return result; 67 | } 68 | 69 | ls_node_t* ls_back(ls_node_t* node) { 70 | ls_node_t* result = node; 71 | 72 | result = result->prev; 73 | 74 | return result; 75 | } 76 | 77 | ls_node_t* ls_at(ls_node_t* list, s32 pos) { 78 | ls_node_t* result = list; 79 | s32 i = 0; 80 | 81 | assert(result && pos >= 0); 82 | 83 | for(i = 0; i <= pos; ++i) { 84 | if(!result->next) { 85 | result = 0; 86 | break; 87 | } else { 88 | result = result->next; 89 | } 90 | } 91 | 92 | return result; 93 | } 94 | 95 | ls_node_t* ls_pushback(ls_node_t* list, Ptr data) { 96 | ls_node_t* result = 0; 97 | ls_node_t* tmp = 0; 98 | 99 | assert(list); 100 | 101 | result = ls_create_node(data); 102 | 103 | tmp = ls_back(list); 104 | if(!tmp) { 105 | tmp = list; 106 | } 107 | tmp->next = result; 108 | result->prev = tmp; 109 | list->prev = result; 110 | 111 | return result; 112 | } 113 | 114 | ls_node_t* ls_pushfront(ls_node_t* list, Ptr data) { 115 | ls_node_t* result = 0; 116 | ls_node_t* head = 0; 117 | 118 | assert(list); 119 | 120 | result = ls_create_node(data); 121 | 122 | head = list; 123 | list = ls_front(list); 124 | head->next = result; 125 | result->prev = head; 126 | if(list) { 127 | result->next = list; 128 | list->prev = result; 129 | } 130 | 131 | return result; 132 | } 133 | 134 | ls_node_t* ls_insert(ls_node_t* list, s32 pos, Ptr data) { 135 | ls_node_t* result = 0; 136 | ls_node_t* tmp = 0; 137 | 138 | assert(list && pos >= 0); 139 | 140 | list = ls_at(list, pos); 141 | assert(list); 142 | if(list) { 143 | result = ls_create_node(data); 144 | tmp = list->prev; 145 | 146 | tmp->next = result; 147 | result->prev = tmp; 148 | 149 | result->next = list; 150 | list->prev = result; 151 | } 152 | 153 | return result; 154 | } 155 | 156 | Ptr ls_popback(ls_node_t* list) { 157 | Ptr result = 0; 158 | ls_node_t* tmp = 0; 159 | 160 | assert(list); 161 | 162 | tmp = ls_back(list); 163 | if(tmp) { 164 | result = tmp->data; 165 | 166 | if(list != tmp->prev) { 167 | list->prev = tmp->prev; 168 | } else { 169 | list->prev = 0; 170 | } 171 | 172 | tmp->prev->next = 0; 173 | safe_free(tmp); 174 | } 175 | 176 | return result; 177 | } 178 | 179 | Ptr ls_popfront(ls_node_t* list) { 180 | Ptr result = 0; 181 | ls_node_t* tmp = 0; 182 | 183 | assert(list); 184 | 185 | tmp = ls_front(list); 186 | if(tmp) { 187 | result = tmp->data; 188 | 189 | if(!tmp->next) { 190 | list->prev = 0; 191 | } 192 | 193 | tmp->prev->next = tmp->next; 194 | if(tmp->next) { 195 | tmp->next->prev = tmp->prev; 196 | } 197 | safe_free(tmp); 198 | } 199 | 200 | return result; 201 | } 202 | 203 | u32 ls_remove(ls_node_t* list, s32 pos) { 204 | u32 result = 0; 205 | ls_node_t* tmp = 0; 206 | 207 | assert(list && pos >= 0); 208 | 209 | tmp = ls_at(list, pos); 210 | if(tmp) { 211 | if(tmp->prev) { 212 | tmp->prev->next = tmp->next; 213 | } 214 | if(tmp->next) { 215 | tmp->next->prev = tmp->prev; 216 | } else { 217 | list->prev = tmp->prev; 218 | } 219 | 220 | safe_free(tmp); 221 | 222 | ++result; 223 | } 224 | 225 | return result; 226 | } 227 | 228 | u32 ls_try_remove(ls_node_t* list, Ptr info, ls_compare cmp) { 229 | u32 result = 0; 230 | ls_node_t* tmp = 0; 231 | 232 | assert(list && cmp); 233 | 234 | tmp = list->next; 235 | while(tmp) { 236 | if(cmp(tmp, info) == 0) { 237 | if(tmp->prev) { 238 | tmp->prev->next = tmp->next; 239 | } 240 | if(tmp->next) { 241 | tmp->next->prev = tmp->prev; 242 | } 243 | if(list->prev == tmp) { 244 | list->prev = 0; 245 | } 246 | safe_free(tmp); 247 | ++result; 248 | break; 249 | } 250 | tmp = tmp->next; 251 | } 252 | 253 | return result; 254 | } 255 | 256 | u32 ls_count(ls_node_t* list) { 257 | u32 result = 0; 258 | 259 | assert(list); 260 | 261 | while(list->next) { 262 | ++result; 263 | list = list->next; 264 | } 265 | 266 | return result; 267 | } 268 | 269 | u32 ls_foreach(ls_node_t* list, ls_operation op) { 270 | u32 idx = 0; 271 | s32 opresult = ACL_OP_RESULT_NORMAL; 272 | ls_node_t* tmp = 0; 273 | 274 | assert(list && op); 275 | 276 | list = list->next; 277 | while(list) { 278 | opresult = (*op)(list->data, list->extra); 279 | ++idx; 280 | tmp = list; 281 | list = list->next; 282 | 283 | if(ACL_OP_RESULT_NORMAL == opresult) { 284 | /* Do nothing */ 285 | } else if(ACL_OP_RESULT_DEL_NODE == opresult) { 286 | tmp->prev->next = list; 287 | if(list) { 288 | list->prev = tmp->prev; 289 | } 290 | safe_free(tmp); 291 | } else { 292 | /* Do nothing */ 293 | } 294 | } 295 | 296 | return idx; 297 | } 298 | 299 | bl ls_empty(ls_node_t* list) { 300 | bl result = FALSE; 301 | 302 | assert(list); 303 | 304 | result = 0 == list->next; 305 | 306 | return result; 307 | } 308 | 309 | void ls_clear(ls_node_t* list) { 310 | ls_node_t* tmp = 0; 311 | 312 | assert(list); 313 | 314 | tmp = list; 315 | list = list->next; 316 | tmp->next = 0; 317 | tmp->prev = 0; 318 | 319 | while(list) { 320 | tmp = list; 321 | list = list->next; 322 | safe_free(tmp); 323 | } 324 | } 325 | 326 | void ls_destroy(ls_node_t* list) { 327 | ls_clear(list); 328 | 329 | safe_free(list); 330 | } 331 | 332 | s32 ls_free_extra(Ptr data, Ptr extra) { 333 | s32 result = ACL_OP_RESULT_NORMAL; 334 | 335 | assert(extra); 336 | 337 | safe_free(extra); 338 | 339 | result = ACL_OP_RESULT_DEL_NODE; 340 | 341 | return result; 342 | } 343 | -------------------------------------------------------------------------------- /ascii_game_engine/common/agelist.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_LIST_H__ 27 | #define __AGE_LIST_H__ 28 | 29 | #include "../ageconfig.h" 30 | #include "../common/agetype.h" 31 | 32 | typedef s32 (* acl_common_compare)(Ptr, Ptr); 33 | 34 | #define ACL_OP_RESULT_NORMAL 0 35 | #define ACL_OP_RESULT_DEL_NODE -1 36 | typedef s32 (* acl_common_operation)(Ptr, Ptr); 37 | 38 | typedef acl_common_compare ls_compare; 39 | typedef acl_common_operation ls_operation; 40 | 41 | typedef struct ls_node_t { 42 | Ptr data; 43 | struct ls_node_t* prev; 44 | struct ls_node_t* next; 45 | Ptr extra; 46 | } ls_node_t; 47 | 48 | AGE_API s32 ls_cmp_data(Ptr node, Ptr info); 49 | AGE_API s32 ls_cmp_extra(Ptr node, Ptr info); 50 | 51 | AGE_API ls_node_t* ls_create_node(Ptr data); 52 | AGE_API ls_node_t* ls_create(void); 53 | AGE_API ls_node_t* ls_front(ls_node_t* node); 54 | AGE_API ls_node_t* ls_back(ls_node_t* node); 55 | AGE_API ls_node_t* ls_at(ls_node_t* list, s32 pos); 56 | AGE_API ls_node_t* ls_pushback(ls_node_t* list, Ptr data); 57 | AGE_API ls_node_t* ls_pushfront(ls_node_t* list, Ptr data); 58 | AGE_API ls_node_t* ls_insert(ls_node_t* list, s32 pos, Ptr data); 59 | AGE_API Ptr ls_popback(ls_node_t* list); 60 | AGE_API Ptr ls_popfront(ls_node_t* list); 61 | AGE_API u32 ls_remove(ls_node_t* list, s32 pos); 62 | AGE_API u32 ls_try_remove(ls_node_t* list, Ptr info, ls_compare cmp); 63 | AGE_API u32 ls_count(ls_node_t* list); 64 | AGE_API u32 ls_foreach(ls_node_t* list, ls_operation op); 65 | AGE_API bl ls_empty(ls_node_t* list); 66 | AGE_API void ls_clear(ls_node_t* list); 67 | AGE_API void ls_destroy(ls_node_t* list); 68 | AGE_API s32 ls_free_extra(Ptr data, Ptr extra); 69 | 70 | #endif /* __AGE_LIST_H__ */ 71 | -------------------------------------------------------------------------------- /ascii_game_engine/common/ageparamset.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "ageparamset.h" 27 | #include "ageutil.h" 28 | 29 | static AgeParam* _create_param(AgeParamType _type) { 30 | AgeParam* result = AGE_MALLOC(AgeParam); 31 | result->type = _type; 32 | 33 | return result; 34 | } 35 | 36 | static void _destroy_param(AgeParam* _param) { 37 | if(_param->type == APT_STR) { 38 | AGE_FREE(_param->str); 39 | } 40 | AGE_FREE(_param); 41 | } 42 | 43 | static s32 _paramset_opt(Ptr _data, Ptr _extra) { 44 | s32 result = 0; 45 | AgeParam* par = 0; 46 | Str str = _extra; 47 | 48 | par = (AgeParam*)_data; 49 | _destroy_param(par); 50 | AGE_FREE(str); 51 | 52 | return result; 53 | } 54 | 55 | AgeParamSet* create_paramset(void) { 56 | AgeParamSet* result = 0; 57 | 58 | result = ht_create(PARAM_SET_SIZE, ht_cmp_string, ht_hash_string, _paramset_opt); 59 | 60 | return result; 61 | } 62 | 63 | void destroy_paramset(AgeParamSet* _ps) { 64 | ht_destroy(_ps); 65 | } 66 | 67 | bl set_s32_param(AgeParamSet* _ps, const Str _name, s32 _data) { 68 | bl result = TRUE; 69 | ls_node_t* node = 0; 70 | AgeParam* par = 0; 71 | 72 | node = ht_find(_ps, _name); 73 | if(node) { 74 | par = node->data; 75 | } else { 76 | par = _create_param(APT_S32); 77 | ht_set_or_insert(_ps, copy_string(_name), par); 78 | } 79 | par->s32 = _data; 80 | 81 | return result; 82 | } 83 | 84 | bl get_s32_param(AgeParamSet* _ps, const Str _name, s32* _data) { 85 | bl result = TRUE; 86 | ls_node_t* node = 0; 87 | AgeParam* par = 0; 88 | 89 | assert(_data); 90 | if(_data) { 91 | node = ht_find(_ps, _name); 92 | assert(node); 93 | if(node) { 94 | par = (AgeParam*)(node->data); 95 | assert(par->type == APT_S32); 96 | if(par->type == APT_S32) { 97 | *_data = par->s32; 98 | } else { 99 | result = FALSE; 100 | } 101 | } else { 102 | result = FALSE; 103 | } 104 | } 105 | 106 | return result; 107 | } 108 | 109 | bl set_u32_param(AgeParamSet* _ps, const Str _name, u32 _data) { 110 | bl result = TRUE; 111 | ls_node_t* node = 0; 112 | AgeParam* par = 0; 113 | 114 | node = ht_find(_ps, _name); 115 | if(node) { 116 | par = node->data; 117 | } else { 118 | par = _create_param(APT_U32); 119 | ht_set_or_insert(_ps, copy_string(_name), par); 120 | } 121 | par->u32 = _data; 122 | 123 | return result; 124 | } 125 | 126 | bl get_u32_param(AgeParamSet* _ps, const Str _name, u32* _data) { 127 | bl result = TRUE; 128 | ls_node_t* node = 0; 129 | AgeParam* par = 0; 130 | 131 | assert(_data); 132 | if(_data) { 133 | node = ht_find(_ps, _name); 134 | assert(node); 135 | if(node) { 136 | par = (AgeParam*)(node->data); 137 | assert(par->type == APT_U32); 138 | if(par->type == APT_U32) { 139 | *_data = par->u32; 140 | } else { 141 | result = FALSE; 142 | } 143 | } else { 144 | result = FALSE; 145 | } 146 | } 147 | 148 | return result; 149 | } 150 | 151 | bl set_f32_param(AgeParamSet* _ps, const Str _name, f32 _data) { 152 | bl result = TRUE; 153 | ls_node_t* node = 0; 154 | AgeParam* par = 0; 155 | 156 | node = ht_find(_ps, _name); 157 | if(node) { 158 | par = node->data; 159 | } else { 160 | par = _create_param(APT_F32); 161 | ht_set_or_insert(_ps, copy_string(_name), par); 162 | } 163 | par->f32 = _data; 164 | 165 | return result; 166 | } 167 | 168 | bl get_f32_param(AgeParamSet* _ps, const Str _name, f32* _data) { 169 | bl result = TRUE; 170 | ls_node_t* node = 0; 171 | AgeParam* par = 0; 172 | 173 | assert(_data); 174 | if(_data) { 175 | node = ht_find(_ps, _name); 176 | assert(node); 177 | if(node) { 178 | par = (AgeParam*)(node->data); 179 | assert(par->type == APT_F32); 180 | if(par->type == APT_F32) { 181 | *_data = par->f32; 182 | } else { 183 | result = FALSE; 184 | } 185 | } else { 186 | result = FALSE; 187 | } 188 | } 189 | 190 | return result; 191 | } 192 | 193 | bl set_str_param(AgeParamSet* _ps, const Str _name, Str _data) { 194 | bl result = TRUE; 195 | ls_node_t* node = 0; 196 | AgeParam* par = 0; 197 | 198 | node = ht_find(_ps, _name); 199 | if(node) { 200 | par = node->data; 201 | } else { 202 | par = _create_param(APT_STR); 203 | ht_set_or_insert(_ps, copy_string(_name), par); 204 | } 205 | if(par->str) { 206 | AGE_FREE(par->str); 207 | } 208 | par->str = copy_string(_data); 209 | 210 | return result; 211 | } 212 | 213 | bl get_str_param(AgeParamSet* _ps, const Str _name, Str* _data) { 214 | bl result = TRUE; 215 | ls_node_t* node = 0; 216 | AgeParam* par = 0; 217 | 218 | assert(_data); 219 | if(_data) { 220 | node = ht_find(_ps, _name); 221 | assert(node); 222 | if(node) { 223 | par = (AgeParam*)(node->data); 224 | assert(par->type == APT_STR); 225 | if(par->type == APT_STR) { 226 | *_data = par->str; 227 | } else { 228 | result = FALSE; 229 | } 230 | } else { 231 | result = FALSE; 232 | } 233 | } 234 | 235 | return result; 236 | } 237 | 238 | bl remove_param(AgeParamSet* _ps, const Str _name) { 239 | bl result = TRUE; 240 | ls_node_t* par = 0; 241 | Str key = 0; 242 | 243 | par = ht_find(_ps, _name); 244 | if(par) { 245 | key = (Str)(par->extra); 246 | _destroy_param((AgeParam*)(par->data)); 247 | ht_remove(_ps, par->extra); 248 | AGE_FREE(key); 249 | } 250 | 251 | return result; 252 | } 253 | 254 | bl clear_param(AgeParamSet* _ps) { 255 | bl result = TRUE; 256 | 257 | ht_foreach(_ps, _paramset_opt); 258 | ht_clear(_ps); 259 | 260 | return result; 261 | } 262 | -------------------------------------------------------------------------------- /ascii_game_engine/common/ageparamset.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_PARAM_SET_H__ 27 | #define __AGE_PARAM_SET_H__ 28 | 29 | #include "../ageconfig.h" 30 | #include "agetype.h" 31 | #include "ageallocator.h" 32 | #include "agehashtable.h" 33 | 34 | #define PARAM_SET_SIZE 193 35 | 36 | /** 37 | * @brief parameter set 38 | */ 39 | typedef ht_node_t AgeParamSet; 40 | 41 | /** 42 | * @brief parameter type 43 | */ 44 | typedef enum AgeParamType { 45 | APT_S32, /**< signed in 32bits */ 46 | APT_U32, /**< unsigned in 32bits */ 47 | APT_F32, /**< float in 32bits */ 48 | APT_STR, /**< string */ 49 | } AgeParamType; 50 | 51 | /** 52 | * @brief parameter item 53 | */ 54 | typedef struct AgeParam { 55 | AgeParamType type; /**< parameter type */ 56 | union { 57 | s32 s32; /**< signed in 32bits */ 58 | u32 u32; /**< unsigned in 32bits */ 59 | f32 f32; /**< float in 32bits */ 60 | Str str; /**< string */ 61 | }; 62 | } AgeParam; 63 | 64 | /** 65 | * @brief create a parameter set object 66 | * 67 | * @return - created parameter set object 68 | */ 69 | AGE_API AgeParamSet* create_paramset(void); 70 | /** 71 | * @brief destroy a parameter set object 72 | * 73 | * @param[in] _ps - parameter set object to be destroyed 74 | */ 75 | AGE_API void destroy_paramset(AgeParamSet* _ps); 76 | 77 | /** 78 | * @brief set a s32 typed parameter 79 | * 80 | * @param[in] _ps - parameter set object 81 | * @param[in] _name - parameter name to be operated 82 | * @param[in] _data - source data 83 | * @return - return TRUE if succeed, or FALSE if failed 84 | */ 85 | AGE_API bl set_s32_param(AgeParamSet* _ps, const Str _name, s32 _data); 86 | /** 87 | * @brief get a s32 typed parameter 88 | * 89 | * @param[in] _ps - parameter set object 90 | * @param[in] _name - parameter name to be operated 91 | * @param[out] _data - target data pointer 92 | * @return - return TRUE if succeed, or FALSE if failed 93 | */ 94 | AGE_API bl get_s32_param(AgeParamSet* _ps, const Str _name, s32* _data); 95 | 96 | /** 97 | * @brief set a u32 typed parameter 98 | * 99 | * @param[in] _ps - parameter set object 100 | * @param[in] _name - parameter name to be operated 101 | * @param[in] _data - source data 102 | * @return - return TRUE if succeed, or FALSE if failed 103 | */ 104 | AGE_API bl set_u32_param(AgeParamSet* _ps, const Str _name, u32 _data); 105 | /** 106 | * @brief get a u32 typed parameter 107 | * 108 | * @param[in] _ps - parameter set object 109 | * @param[in] _name - parameter name to be operated 110 | * @param[out] _data - target data pointer 111 | * @return - return TRUE if succeed, or FALSE if failed 112 | */ 113 | AGE_API bl get_u32_param(AgeParamSet* _ps, const Str _name, u32* _data); 114 | 115 | /** 116 | * @brief set a f32 typed parameter 117 | * 118 | * @param[in] _ps - parameter set object 119 | * @param[in] _name - parameter name to be operated 120 | * @param[in] _data - source data 121 | * @return - return TRUE if succeed, or FALSE if failed 122 | */ 123 | AGE_API bl set_f32_param(AgeParamSet* _ps, const Str _name, f32 _data); 124 | /** 125 | * @brief get a f32 typed parameter 126 | * 127 | * @param[in] _ps - parameter set object 128 | * @param[in] _name - parameter name to be operated 129 | * @param[out] _data - target data pointer 130 | * @return - return TRUE if succeed, or FALSE if failed 131 | */ 132 | AGE_API bl get_f32_param(AgeParamSet* _ps, const Str _name, f32* _data); 133 | 134 | /** 135 | * @brief set a Str typed parameter 136 | * 137 | * @param[in] _ps - parameter set object 138 | * @param[in] _name - parameter name to be operated 139 | * @param[in] _data - source data 140 | * @return - return TRUE if succeed, or FALSE if failed 141 | */ 142 | AGE_API bl set_str_param(AgeParamSet* _ps, const Str _name, Str _data); 143 | /** 144 | * @brief get a Str typed parameter 145 | * 146 | * @param[in] _ps - parameter set object 147 | * @param[in] _name - parameter name to be operated 148 | * @param[out] _data - target data pointer 149 | * @return - return TRUE if succeed, or FALSE if failed 150 | */ 151 | AGE_API bl get_str_param(AgeParamSet* _ps, const Str _name, Str* _data); 152 | 153 | /** 154 | * @brief remove a parameter in a set 155 | * 156 | * @param[in] _ps - parameter set object 157 | * @param[in] _name - parameter name to be removed 158 | * @return - return TRUE if succeed, or FALSE if failed 159 | */ 160 | AGE_API bl remove_param(AgeParamSet* _ps, const Str _name); 161 | /** 162 | * @brief clear all parameters in a set 163 | * 164 | * @param[in] _ps - parameter set object 165 | * @return - return TRUE if succeed, or FALSE if failed 166 | */ 167 | AGE_API bl clear_param(AgeParamSet* _ps); 168 | 169 | #endif /* __AGE_PARAM_SET_H__ */ 170 | -------------------------------------------------------------------------------- /ascii_game_engine/common/agestringtable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_STRING_TABLE_H__ 27 | #define __AGE_STRING_TABLE_H__ 28 | 29 | static const Str ST_SPRITE_FRAME_COUNT = "count: "; 30 | static const Str ST_SPRITE_FRAME_WIDTH = "width: "; 31 | static const Str ST_SPRITE_FRAME_HEIGHT = "height: "; 32 | static const Str ST_SPRITE_FRAME_RATE = "rate: "; 33 | 34 | static const Str ST_DEFAULT_CANVAS_NAME = "canvas"; 35 | 36 | #endif /* __AGE_STRING_TABLE_H__ */ 37 | -------------------------------------------------------------------------------- /ascii_game_engine/common/agetype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_TYPE_H__ 27 | #define __AGE_TYPE_H__ 28 | 29 | #ifndef bl 30 | # define bl unsigned char 31 | #endif 32 | #ifndef TRUE 33 | # define TRUE 1 34 | #endif 35 | #ifndef FALSE 36 | # define FALSE 0 37 | #endif 38 | 39 | typedef char s8; 40 | typedef unsigned char u8; 41 | typedef short s16; 42 | typedef unsigned short u16; 43 | typedef int s32; 44 | typedef unsigned int u32; 45 | typedef long long s64; 46 | typedef unsigned long long u64; 47 | typedef float f32; 48 | typedef double f64; 49 | 50 | typedef s8* Str; 51 | typedef void* Ptr; 52 | 53 | typedef unsigned int Color; 54 | 55 | typedef struct Point { 56 | s32 x; 57 | s32 y; 58 | } Point; 59 | 60 | typedef struct Size { 61 | s32 w; 62 | s32 h; 63 | } Size; 64 | 65 | #endif /* __AGE_TYPE_H__ */ 66 | -------------------------------------------------------------------------------- /ascii_game_engine/common/ageutil.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "ageallocator.h" 27 | #include "ageutil.h" 28 | 29 | #pragma comment(lib, "winmm.lib") 30 | 31 | static u32 _rand_w = 0; 32 | static u32 _rand_z = 0; 33 | 34 | void age_beep(void) { 35 | putchar('\a'); 36 | } 37 | 38 | u32 age_tick_count(void) { 39 | return timeGetTime(); 40 | } 41 | 42 | void age_sleep(s32 _time) { 43 | Sleep(_time); 44 | } 45 | 46 | s32 age_rand(s32 _min, s32 _max) { 47 | s32 result = 0; 48 | union { s32 sint; u32 uint; } u; 49 | if(_rand_w == 0 && _rand_z == 0) { 50 | _rand_w = age_tick_count(); 51 | _rand_z = (_rand_w << 16) | (_rand_w >> 16); 52 | } 53 | _rand_z = 36969 * (_rand_z & 65535) + (_rand_z >> 16); 54 | _rand_w = 18000 * (_rand_w & 65535) + (_rand_w >> 16); 55 | u.uint = (_rand_z << 16) + _rand_w; 56 | result = u.uint % (_max - _min); 57 | result += _min; 58 | 59 | return result; 60 | } 61 | 62 | void fensure(const Str _file) { 63 | FILE* fp = fopen(_file, "rb"); 64 | if(!fp) { 65 | fp = fopen(_file, "wb"); 66 | assert(fp); 67 | fclose(fp); 68 | } else { 69 | fclose(fp); 70 | } 71 | } 72 | 73 | s32 flen(FILE* _fp) { 74 | s32 result = 0; 75 | s32 curpos = 0; 76 | 77 | curpos = ftell(_fp); 78 | fseek(_fp, 0L, SEEK_END); 79 | result = ftell(_fp); 80 | fseek(_fp, curpos, SEEK_SET); 81 | 82 | return result; 83 | } 84 | 85 | s32 freadln(FILE* _fp, Str* _buf) { 86 | s32 result = 0; 87 | s8 ch = 0; 88 | long ft = 0; 89 | 90 | assert(_fp && _buf); 91 | 92 | ch = (s8)fgetc(_fp); 93 | while(ch != EOF && ch != '\r' && ch != '\n') { 94 | if(ch != EOF) { 95 | (*_buf)[result++] = ch; 96 | } 97 | ch = (s8)fgetc(_fp); 98 | } 99 | (*_buf)[result] = '\0'; 100 | 101 | if(ch != EOF) { 102 | ft = ftell(_fp); 103 | ch = (s8)fgetc(_fp); 104 | if(ch != '\n') { 105 | fseek(_fp, ft, 0); 106 | } 107 | } 108 | 109 | return result; 110 | } 111 | 112 | s32 fskipln(FILE* _fp) { 113 | s32 result = 0; 114 | s8 buf[AGE_STR_LEN]; 115 | Str str = buf; 116 | result = freadln(_fp, &str); 117 | 118 | return result; 119 | } 120 | 121 | Str freadall(const Str _file) { 122 | Str result = 0; 123 | FILE* fp = 0; 124 | fp = fopen(_file, "rb+"); 125 | if(fp != 0) { 126 | s32 l = flen(fp); 127 | result = _age_malloc(s8, l + 1); 128 | assert(result); 129 | fread(result, 1, l, fp); 130 | fclose(fp); 131 | } 132 | 133 | return result; 134 | } 135 | 136 | Str copy_string(const Str _str) { 137 | Str result = 0; 138 | s32 l = (s32)strlen(_str); 139 | 140 | assert(_str); 141 | 142 | result = (Str)age_malloc(l + 1); 143 | strcpy(result, _str); 144 | 145 | return result; 146 | } 147 | 148 | Str copy_substring(const Str _str, s32 _start, s32 _count) { 149 | Str result = 0; 150 | s32 l = (s32)strlen(_str); 151 | s32 i = 0; 152 | 153 | assert(_str); 154 | 155 | if(!_count) { 156 | _count = l - _start; 157 | } 158 | result = (Str)age_malloc(l + 1); 159 | for(i = 0; i < l && i < _count; ++i) { 160 | result[i] = _str[_start + i]; 161 | } 162 | result[i] = '\0'; 163 | 164 | return result; 165 | } 166 | 167 | s32 cmp_ptr(const Ptr _left, const Ptr _right) { 168 | s32 result = 0; 169 | if(_left > _right) { 170 | result = 1; 171 | } else if(_left < _right) { 172 | result = -1; 173 | } 174 | 175 | return result; 176 | } 177 | -------------------------------------------------------------------------------- /ascii_game_engine/common/ageutil.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_UTIL_H__ 27 | #define __AGE_UTIL_H__ 28 | 29 | #include "../ageconfig.h" 30 | #include "../common/agetype.h" 31 | 32 | #ifndef _countof 33 | # define _countof(_a) (sizeof(_a) / sizeof(_a[0])) 34 | #endif 35 | 36 | /** 37 | * @brief pronounce a beep 38 | */ 39 | AGE_API void age_beep(void); 40 | 41 | /** 42 | * @brief get system tick count 43 | * 44 | * @return - the system tick count, in millisecond 45 | */ 46 | AGE_API u32 age_tick_count(void); 47 | /** 48 | * @brief sleep for a while 49 | * 50 | * @return - time to sleep, in millisecond 51 | */ 52 | AGE_API void age_sleep(s32 _time); 53 | 54 | /** 55 | * @brief get a random number in a range 56 | * 57 | * @param[in] _min - minimum 58 | * @param[in] _max - maximum 59 | * @return - random number 60 | */ 61 | AGE_API s32 age_rand(s32 _min, s32 _max); 62 | 63 | /** 64 | * @brief ensure file exists 65 | * 66 | * @param[in] - file name 67 | */ 68 | AGE_API void fensure(const Str _file); 69 | /** 70 | * @brief get length of a file 71 | * 72 | * @param[in] _fp - file pointer 73 | * @return - file length in bytes 74 | */ 75 | AGE_API s32 flen(FILE* _fp); 76 | /** 77 | * @brief read a line from a file to a string buffer 78 | * 79 | * @param[in] _fp - file pointer 80 | * @param[out] _buf - buffer to be filled 81 | * @return - read characters count 82 | */ 83 | AGE_API s32 freadln(FILE* _fp, Str* _buf); 84 | /** 85 | * @brief skip a line from a file 86 | * 87 | * @param[in] _fp - file pointer 88 | * @return - skipped characters count 89 | */ 90 | AGE_API s32 fskipln(FILE* _fp); 91 | /** 92 | * @brief read all from a file 93 | * 94 | * @param[in] _file - file name 95 | * @return - content of the file 96 | */ 97 | AGE_API Str freadall(const Str _file); 98 | 99 | /** 100 | * @brief create a new string and copy the given content to it 101 | * 102 | * @param[in] _str - source string 103 | * @return - new created string, need to be freed manually 104 | */ 105 | AGE_API Str copy_string(const Str _str); 106 | /** 107 | * @brief create a new string and copy a count of the given content to it 108 | * 109 | * @param[in] _str - source string 110 | * @param[in] _start - start offset 111 | * @param[in] _count - size to be copied, set to 0 if copy to end 112 | * @return - new created string, need to be freed manually 113 | */ 114 | AGE_API Str copy_substring(const Str _str, s32 _start, s32 _count); 115 | 116 | /** 117 | * @brief compare two pointer 118 | * 119 | * @param[in] _left - first pointer 120 | * @param[in] _right - second pointer 121 | * @return - 0 if _left equals to _right, 122 | * 1 if _left is greater than _right, 123 | * -1 if _left is less than _right 124 | */ 125 | AGE_API s32 cmp_ptr(const Ptr _left, const Ptr _right); 126 | 127 | #endif /* __AGE_UTIL_H__ */ 128 | -------------------------------------------------------------------------------- /ascii_game_engine/controller/agecontroller.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "../common/ageallocator.h" 27 | #include "../common/ageutil.h" 28 | #include "../render/agerenderer.h" 29 | #include "agecontroller.h" 30 | 31 | void set_canvas_controller(Ptr _obj, control_proc _proc) { 32 | Canvas* cvs = (Canvas*)_obj; 33 | 34 | assert(cvs); 35 | 36 | cvs->control = _proc; 37 | } 38 | 39 | control_proc get_canvas_controller(Ptr _obj) { 40 | control_proc result = 0; 41 | Canvas* cvs = (Canvas*)_obj; 42 | 43 | assert(cvs); 44 | 45 | result = cvs->control; 46 | 47 | return result; 48 | } 49 | 50 | void set_sprite_controller(Ptr _obj, control_proc _proc) { 51 | Sprite* spr = (Sprite*)_obj; 52 | 53 | assert(spr); 54 | 55 | spr->control = _proc; 56 | } 57 | 58 | control_proc get_sprite_controller(Ptr _obj) { 59 | control_proc result = 0; 60 | Sprite* spr = (Sprite*)_obj; 61 | 62 | assert(spr); 63 | 64 | result = spr->control; 65 | 66 | return result; 67 | } 68 | -------------------------------------------------------------------------------- /ascii_game_engine/controller/agecontroller.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_CONTROLLER_H__ 27 | #define __AGE_CONTROLLER_H__ 28 | 29 | #include "../ageconfig.h" 30 | #include "../common/agetype.h" 31 | #include "../common/agelist.h" 32 | #include "../common/agehashtable.h" 33 | 34 | /** 35 | * @brief object controlling functor 36 | * 37 | * @param[in] _obj - object to be controlled 38 | * @param[in] _name - object name 39 | * @param[in] _elapsedTime - elapsed time since last frame 40 | * @param[in] _lparam - first param 41 | * @param[in] _wparam - second param 42 | * @param[in] _extra - extra data 43 | * @return - execution status 44 | */ 45 | typedef s32 (* control_proc)(Ptr _obj, const Str _name, s32 _elapsedTime, u32 _lparam, u32 _wparam, Ptr _extra); 46 | 47 | /** 48 | * @brief set a controller of a canvas 49 | * 50 | * @param[in] _obj - canvas object 51 | * @param[in] _proc - controller 52 | */ 53 | AGE_API void set_canvas_controller(Ptr _obj, control_proc _proc); 54 | /** 55 | * @brief get a controller of a canvas 56 | * 57 | * @param[in] _obj - canvas object 58 | * @return controller 59 | */ 60 | AGE_API control_proc get_canvas_controller(Ptr _obj); 61 | 62 | /** 63 | * @brief set a controller of a sprite 64 | * 65 | * @param[in] _obj - sprite object 66 | * @param[in] _proc - controller 67 | */ 68 | AGE_API void set_sprite_controller(Ptr _obj, control_proc _proc); 69 | /** 70 | * @brief get a controller of a sprite 71 | * 72 | * @param[in] _obj - sprite object 73 | * @return controller 74 | */ 75 | AGE_API control_proc get_sprite_controller(Ptr _obj); 76 | 77 | #endif /* __AGE_CONTROLLER_H__ */ 78 | -------------------------------------------------------------------------------- /ascii_game_engine/controller/ageexploder.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "../common/ageallocator.h" 27 | #include "../common/ageutil.h" 28 | #include "../render/agerenderer.h" 29 | #include "ageexploder.h" 30 | 31 | void update_sprite_ex(Canvas* _cvs, Sprite* _spr, s32 _elapsedTime) { 32 | /* TODO */ 33 | } 34 | 35 | void fire_render_sprite_ex(Canvas* _cvs, Sprite* _spr, s32 _elapsedTime) { 36 | /* TODO */ 37 | } 38 | 39 | void post_render_sprite_ex(Canvas* _cvs, Sprite* _spr, s32 _elapsedTime) { 40 | /* TODO */ 41 | } 42 | -------------------------------------------------------------------------------- /ascii_game_engine/controller/ageexploder.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_EXPLODER_H__ 27 | #define __AGE_EXPLODER_H__ 28 | 29 | #include "../ageconfig.h" 30 | #include "../common/agetype.h" 31 | #include "../common/agelist.h" 32 | #include "../common/agehashtable.h" 33 | 34 | /** 35 | * @brief sprite explosion updating 36 | * 37 | * @param[in] _cvs - canvas object 38 | * @param[in] _spr - sprite object 39 | * @param[in] _elapsedTime - elapsed time since last frame 40 | */ 41 | AGE_API void update_sprite_ex(Canvas* _cvs, Sprite* _spr, s32 _elapsedTime); 42 | /** 43 | * @brief fire sprite explosion rendering 44 | * 45 | * @param[in] _cvs - canvas object 46 | * @param[in] _spr - sprite object 47 | * @param[in] _elapsedTime - elapsed time since last frame 48 | */ 49 | AGE_API void fire_render_sprite_ex(Canvas* _cvs, Sprite* _spr, s32 _elapsedTime); 50 | /** 51 | * @brief post sprite explosion rendering 52 | * 53 | * @param[in] _cvs - canvas object 54 | * @param[in] _spr - sprite object 55 | * @param[in] _elapsedTime - elapsed time since last frame 56 | */ 57 | AGE_API void post_render_sprite_ex(Canvas* _cvs, Sprite* _spr, s32 _elapsedTime); 58 | 59 | #endif /* __AGE_EXPLODER_H__ */ 60 | -------------------------------------------------------------------------------- /ascii_game_engine/input/ageinput.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #if AGE_IMPL == AGE_IMPL_CONSOLE 27 | 28 | #include "../common/ageutil.h" 29 | #include "../common/ageallocator.h" 30 | #include "ageinput.h" 31 | 32 | typedef struct InputContext { 33 | bl keys[256]; 34 | } InputContext; 35 | 36 | static s32 KEY_MAP[MAX_PLAYER_COUNT][KC_COUNT]; 37 | 38 | bl open_input(void) { 39 | bl result = TRUE; 40 | 41 | memset(&KEY_MAP, 0, sizeof(KEY_MAP)); 42 | 43 | return result; 44 | } 45 | 46 | bl close_input(void) { 47 | bl result = TRUE; 48 | 49 | return result; 50 | } 51 | 52 | Ptr create_input_context(void) { 53 | InputContext* result = AGE_MALLOC(InputContext); 54 | 55 | return result; 56 | } 57 | 58 | void destroy_input_context(Ptr _ctx) { 59 | AGE_FREE(_ctx); 60 | } 61 | 62 | void update_input_context(Ptr _ctx) { 63 | InputContext* ctx = (InputContext*)_ctx; 64 | s32 key = 0; 65 | 66 | memset(ctx->keys, 0, sizeof(ctx->keys)); 67 | while(kbhit()) { 68 | key = getch(); 69 | if(224 == key) { 70 | key = getch(); 71 | } 72 | ctx->keys[key] = TRUE; 73 | } 74 | } 75 | 76 | bl register_key_map(s32 _player, KeyIndex _keyIdx, s32 _keyCode) { 77 | bl result = TRUE; 78 | 79 | assert(_player >= 0 && _player < MAX_PLAYER_COUNT && _keyIdx >= 0 && _keyIdx < KC_COUNT); 80 | 81 | KEY_MAP[_player][_keyIdx] = _keyCode; 82 | 83 | return result; 84 | } 85 | 86 | bl is_key_down(Ptr _ctx, s32 _player, KeyIndex _keyIdx) { 87 | bl result = FALSE; 88 | s32 key = 0; 89 | InputContext* ctx = (InputContext*)_ctx; 90 | 91 | assert(_player >= 0 && _player < MAX_PLAYER_COUNT && _keyIdx >= 0 && _keyIdx < KC_COUNT); 92 | 93 | result = ctx->keys[KEY_MAP[_player][_keyIdx]] != 0; 94 | 95 | return result; 96 | } 97 | 98 | #endif /* AGE_IMPL == AGE_IMPL_CONSOLE */ 99 | -------------------------------------------------------------------------------- /ascii_game_engine/input/ageinput.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_INPUT_H__ 27 | #define __AGE_INPUT_H__ 28 | 29 | #include "../ageconfig.h" 30 | #include "../common/agetype.h" 31 | 32 | #define MAX_PLAYER_COUNT 2 33 | 34 | /** 35 | * @brief enum of key map 36 | */ 37 | typedef enum KeyIndex { 38 | KC_UP, /**< up key */ 39 | KC_DOWN, /**< down key */ 40 | KC_LEFT, /**< left key */ 41 | KC_RIGHT, /**< right key */ 42 | KC_OK, /**< ok/confirm/fire/enter key */ 43 | KC_ESC, /**< escape/cancel key */ 44 | KC_P, /**< 'p' key */ 45 | 46 | KC_COUNT /**< mapped keys count */ 47 | } KeyIndex; 48 | 49 | /** 50 | * @brief open the input system 51 | * 52 | * @return - return TRUE if succeed, or FALSE if failed 53 | */ 54 | AGE_API bl open_input(void); 55 | /** 56 | * @brief close the input system 57 | * 58 | * @return - return TRUE if succeed, or FALSE if failed 59 | */ 60 | AGE_API bl close_input(void); 61 | 62 | /** 63 | * @brief create an input context 64 | * 65 | * @return - created input context 66 | */ 67 | AGE_API Ptr create_input_context(void); 68 | /** 69 | * @brief destroy an input context 70 | * 71 | * @param[in] _ctx - input context to be destroyd 72 | */ 73 | AGE_API void destroy_input_context(Ptr _ctx); 74 | 75 | /** 76 | * @brief update an input context 77 | * 78 | * @param[in] _ctx - input context to be updated 79 | */ 80 | AGE_API void update_input_context(Ptr _ctx); 81 | 82 | /** 83 | * @brief register a key code as an index in the map 84 | * 85 | * @param[in] _player - player index 86 | * @param[in] _keyIdx - key index 87 | * @param[in] _keyCode - key code 88 | * @return - return TRUE if succeed, or FALSE if failed 89 | */ 90 | AGE_API bl register_key_map(s32 _player, KeyIndex _keyIdx, s32 _keyCode); 91 | 92 | /** 93 | * @brief determine whether the given index key of a player is down 94 | * 95 | * @param[in] _ctx - input context to be detected 96 | * @param[in] _player - player index 97 | * @param[in] _keyIdx - key index 98 | * @return - return TRUE if the key is down or FALSE 99 | */ 100 | AGE_API bl is_key_down(Ptr _ctx, s32 _player, KeyIndex _keyIdx); 101 | 102 | #endif /* __AGE_INPUT_H__ */ 103 | -------------------------------------------------------------------------------- /ascii_game_engine/input/ageinput_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #if AGE_IMPL == AGE_IMPL_WIN32 27 | 28 | #endif /* AGE_IMPL == AGE_IMPL_WIN32 */ 29 | -------------------------------------------------------------------------------- /ascii_game_engine/message/agemessage.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "../common/ageallocator.h" 27 | #include "../common/ageutil.h" 28 | #include "../render/agerenderer.h" 29 | #include "agemessage.h" 30 | 31 | static MessageMap* _tempMsgMap = 0; 32 | 33 | static s32 _ht_cmp_msg(Ptr d1, Ptr d2) { 34 | u32 i1 = (u32)d1; 35 | u32 i2 = (u32)d2; 36 | s32 i = (s64)i1 - (s64)i2; 37 | s32 result = 0; 38 | if(i < 0) { 39 | result = -1; 40 | } else if(i > 0) { 41 | result = 1; 42 | } 43 | 44 | return result; 45 | } 46 | 47 | static s32 _copy_message_map(Ptr _data, Ptr _extra) { 48 | s32 result = 0; 49 | message_proc proc = 0; 50 | Str str = _extra; 51 | union { Ptr ptr; u32 uint; } u; 52 | 53 | assert(_tempMsgMap); 54 | 55 | proc = (message_proc)_data; 56 | u.ptr = _extra; 57 | register_message_proc(_tempMsgMap, u.uint, proc); 58 | 59 | return result; 60 | } 61 | 62 | bl create_sprite_message_map(Ptr _obj) { 63 | bl result = TRUE; 64 | Sprite* spr = (Sprite*)_obj; 65 | 66 | assert(_obj); 67 | 68 | if(spr->message_map.proc_map) { 69 | result = FALSE; 70 | } else { 71 | spr->message_map.proc_map = ht_create(0, _ht_cmp_msg, ht_hash_ptr, 0); 72 | } 73 | 74 | return result; 75 | } 76 | 77 | bl create_canvas_message_map(Ptr _obj) { 78 | bl result = TRUE; 79 | Canvas* cvs = (Canvas*)_obj; 80 | 81 | assert(_obj); 82 | 83 | if(cvs->message_map.proc_map) { 84 | result = FALSE; 85 | } else { 86 | cvs->message_map.proc_map = ht_create(0, _ht_cmp_msg, ht_hash_ptr, 0); 87 | } 88 | 89 | return result; 90 | } 91 | 92 | bl destroy_sprite_message_map(Ptr _obj) { 93 | bl result = TRUE; 94 | Sprite* spr = (Sprite*)_obj; 95 | 96 | assert(_obj); 97 | 98 | if(!spr->message_map.proc_map) { 99 | result = FALSE; 100 | } else { 101 | ht_destroy(spr->message_map.proc_map); 102 | spr->message_map.proc_map = 0; 103 | } 104 | 105 | return result; 106 | } 107 | 108 | bl destroy_canvas_message_map(Ptr _obj) { 109 | bl result = TRUE; 110 | Canvas* cvs = (Canvas*)_obj; 111 | 112 | assert(_obj); 113 | 114 | if(!cvs->message_map.proc_map) { 115 | result = FALSE; 116 | } else { 117 | ht_destroy(cvs->message_map.proc_map); 118 | cvs->message_map.proc_map = 0; 119 | } 120 | 121 | return result; 122 | } 123 | 124 | message_proc get_message_map_message_proc(MessageMap* _msgMap, u32 _msg) { 125 | message_proc result = 0; 126 | ht_node_t* pm = 0; 127 | union { Ptr ptr; u32 uint; } u; 128 | 129 | assert(_msgMap); 130 | 131 | if(_msg < MESSAGE_TABLE_SIZE) { 132 | result = _msgMap->fast_table[_msg]; 133 | } else { 134 | pm = _msgMap->proc_map; 135 | u.uint = _msg; 136 | ht_get(pm, u.ptr, (Ptr*)&result); 137 | } 138 | 139 | return result; 140 | } 141 | 142 | message_proc get_sprite_message_proc(Ptr _obj, u32 _msg) { 143 | message_proc result = 0; 144 | Sprite* spr = (Sprite*)_obj; 145 | 146 | assert(_obj); 147 | 148 | result = get_message_map_message_proc(&spr->message_map, _msg); 149 | 150 | return result; 151 | } 152 | 153 | message_proc get_canvas_message_proc(Ptr _obj, u32 _msg) { 154 | message_proc result = 0; 155 | Canvas* cvs = (Canvas*)_obj; 156 | 157 | assert(_obj); 158 | 159 | result = get_message_map_message_proc(&cvs->message_map, _msg); 160 | 161 | return result; 162 | } 163 | 164 | void register_message_proc(MessageMap* _map, u32 _msg, message_proc _proc) { 165 | ht_node_t* pm = 0; 166 | union { Ptr ptr; u32 uint; } u; 167 | 168 | assert(_map); 169 | 170 | if(_msg < MESSAGE_TABLE_SIZE) { 171 | _map->fast_table[_msg] = _proc; 172 | } else { 173 | pm = _map->proc_map; 174 | u.uint = _msg; 175 | ht_set_or_insert(pm, u.ptr, _proc); 176 | } 177 | } 178 | 179 | void unregister_message_proc(MessageMap* _map, u32 _msg) { 180 | ht_node_t* pm = 0; 181 | ls_node_t* p = 0; 182 | union { Ptr ptr; u32 uint; } u; 183 | 184 | assert(_map); 185 | 186 | if(_msg < MESSAGE_TABLE_SIZE) { 187 | _map->fast_table[_msg] = 0; 188 | } else { 189 | pm = _map->proc_map; 190 | u.uint = _msg; 191 | p = ht_find(pm, u.ptr); 192 | if(p) { 193 | ht_remove(pm, p->extra); 194 | } 195 | } 196 | } 197 | 198 | void copy_message_map(MessageMap* _src, MessageMap* _tgt) { 199 | memcpy(_tgt->fast_table, _src->fast_table, sizeof(_src->fast_table)); 200 | _tempMsgMap = _tgt; 201 | ht_foreach(_src->proc_map, _copy_message_map); 202 | _tempMsgMap = 0; 203 | } 204 | 205 | s32 send_message_to_proc(message_proc _func, Ptr _receiver, Ptr _sender, u32 _msg, u32 _lparam, u32 _wparam, Ptr _extra) { 206 | s32 result = 0; 207 | 208 | result = _func(_receiver, _sender, _msg, _lparam, _wparam, _extra); 209 | 210 | return result; 211 | } 212 | 213 | s32 send_message_to_object(MessageReceiver* _receiver, Ptr _sender, u32 _msg, u32 _lparam, u32 _wparam, Ptr _extra) { 214 | s32 result = 0; 215 | message_proc proc = 0; 216 | 217 | assert(_receiver && _receiver->receiver && _receiver->message_map); 218 | 219 | proc = get_message_map_message_proc(_receiver->message_map, _msg); 220 | if(proc) { 221 | result = proc(_receiver->receiver, _sender, _msg, _lparam, _wparam, _extra); 222 | } 223 | 224 | return result; 225 | } 226 | 227 | s32 send_message_to_sprite(Ptr _receiver, Ptr _sender, u32 _msg, u32 _lparam, u32 _wparam, Ptr _extra) { 228 | s32 result = 0; 229 | message_proc proc = 0; 230 | 231 | proc = get_sprite_message_proc(_receiver, _msg); 232 | if(proc) { 233 | result = proc(_receiver, _sender, _msg, _lparam, _wparam, _extra); 234 | } 235 | 236 | return result; 237 | } 238 | 239 | s32 send_message_to_canvas(Ptr _receiver, Ptr _sender, u32 _msg, u32 _lparam, u32 _wparam, Ptr _extra) { 240 | s32 result = 0; 241 | message_proc proc = 0; 242 | 243 | proc = get_canvas_message_proc(_receiver, _msg); 244 | if(proc) { 245 | result = proc(_receiver, _sender, _msg, _lparam, _wparam, _extra); 246 | } 247 | 248 | return result; 249 | } 250 | -------------------------------------------------------------------------------- /ascii_game_engine/message/agemessage.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_MESSAGE_H__ 27 | #define __AGE_MESSAGE_H__ 28 | 29 | #include "../ageconfig.h" 30 | #include "../common/agetype.h" 31 | #include "../common/agelist.h" 32 | #include "../common/agehashtable.h" 33 | 34 | #define MESSAGE_TABLE_SIZE 32 35 | 36 | /** 37 | * @brief enum messages 38 | */ 39 | typedef enum Messages { 40 | MSG_GET_PROP, /**< get a property from an object */ 41 | MSG_SET_PROP, /**< set a property from an object */ 42 | 43 | MSG_USER = 64, /**< beginning of user defined message */ 44 | } Messages; 45 | 46 | /** 47 | * @brief message processing functor 48 | * 49 | * @param[in] _receiver - receiver of this message 50 | * @param[in] _sender - sender of this message 51 | * @param[in] _msg - message type 52 | * @param[in] _lparam - first param 53 | * @param[in] _wparam - second param 54 | * @param[in] _extra - extra data 55 | * @return - execution status 56 | */ 57 | typedef s32 (* message_proc)(Ptr _receiver, Ptr _sender, u32 _msg, u32 _lparam, u32 _wparam, Ptr _extra); 58 | 59 | /** 60 | * @brief message processing functor mapping structure 61 | */ 62 | typedef struct MessageMap { 63 | message_proc fast_table[MESSAGE_TABLE_SIZE]; /**< functors cached in an array for fast accessing */ 64 | ht_node_t* proc_map; /**< functors the array above cannot holds */ 65 | } MessageMap; 66 | 67 | /** 68 | * @brief message processing object structure 69 | */ 70 | typedef struct MessageReceiver { 71 | Ptr receiver; /**< object */ 72 | MessageMap* message_map; /**< processing functor */ 73 | } MessageReceiver; 74 | 75 | /** 76 | * @brief create a message map of a sprite 77 | * 78 | * @param[in] _obj - sprite object 79 | * @return - return TRUE if succeed, or FALSE if failed 80 | */ 81 | AGE_API bl create_sprite_message_map(Ptr _obj); 82 | /** 83 | * @brief create a message map of a canvas 84 | * 85 | * @param[in] _obj - canvas object 86 | * @return - return TRUE if succeed, or FALSE if failed 87 | */ 88 | AGE_API bl create_canvas_message_map(Ptr _obj); 89 | /** 90 | * @brief destroy a message map of a sprite 91 | * 92 | * @param[in] _obj - sprite object 93 | * @return - return TRUE if succeed, or FALSE if failed 94 | */ 95 | AGE_API bl destroy_sprite_message_map(Ptr _obj); 96 | /** 97 | * @brief destroy a message map of a canvas 98 | * 99 | * @param[in] _obj - canvas object 100 | * @return - return TRUE if succeed, or FALSE if failed 101 | */ 102 | AGE_API bl destroy_canvas_message_map(Ptr _obj); 103 | 104 | /** 105 | * @brief get a registered message processing functor in a message map 106 | * 107 | * @param[in] _msgMap - message processing map 108 | * @param[in] _msg - message type to get 109 | * @return - processing functor 110 | */ 111 | AGE_API message_proc get_message_map_message_proc(MessageMap* _msgMap, u32 _msg); 112 | /** 113 | * @brief get a registered message processing functor of a sprite object 114 | * 115 | * @param[in] _obj - sprite object 116 | * @param[in] _msg - message type to get 117 | * @return - processing functor 118 | */ 119 | AGE_API message_proc get_sprite_message_proc(Ptr _obj, u32 _msg); 120 | /** 121 | * @brief get a registered message processing functor of a canvas object 122 | * 123 | * @param[in] _obj - canvas object 124 | * @param[in] _msg - message type to get 125 | * @return - processing functor 126 | */ 127 | AGE_API message_proc get_canvas_message_proc(Ptr _obj, u32 _msg); 128 | 129 | /** 130 | * @brief register a message processing functor to an object 131 | * 132 | * @param[in] _map - message map pointer 133 | * @param[in] _msg - message type to be registered 134 | * @param[in] _proc - processing functor 135 | */ 136 | AGE_API void register_message_proc(MessageMap* _map, u32 _msg, message_proc _proc); 137 | /** 138 | * @brief unregister a message processing functor of an object 139 | * 140 | * @param[in] _map - message map pointer 141 | * @param[in] _msg - message type to be unregistered 142 | */ 143 | AGE_API void unregister_message_proc(MessageMap* _map, u32 _msg); 144 | /** 145 | * @brief copy a message processing map from one to another 146 | * 147 | * @param[in] _src - source message map 148 | * @param[in] _tgt - target message map 149 | */ 150 | AGE_API void copy_message_map(MessageMap* _src, MessageMap* _tgt); 151 | 152 | /** 153 | * @brief send a message to a sprite object 154 | * 155 | * @param[in] _func - message processing functor 156 | * @param[in] _receiver - target sprite object 157 | * @param[in] _sender - sender of the message 158 | * @param[in] _msg - message type 159 | * @param[in] _lparam - first param 160 | * @param[in] _wparam - second param 161 | * @param[in] _extra - extra data 162 | * @return - message sending status 163 | */ 164 | AGE_API s32 send_message_to_proc(message_proc _func, Ptr _receiver, Ptr _sender, u32 _msg, u32 _lparam, u32 _wparam, Ptr _extra); 165 | /** 166 | * @brief send a message to an object 167 | * 168 | * @param[in] _receiver - target object 169 | * @param[in] _sender - sender of the message 170 | * @param[in] _msg - message type 171 | * @param[in] _lparam - first param 172 | * @param[in] _wparam - second param 173 | * @param[in] _extra - extra data 174 | * @return - message sending status 175 | */ 176 | AGE_API s32 send_message_to_object(MessageReceiver* _receiver, Ptr _sender, u32 _msg, u32 _lparam, u32 _wparam, Ptr _extra); 177 | /** 178 | * @brief send a message to a sprite object 179 | * 180 | * @param[in] _receiver - target sprite object 181 | * @param[in] _sender - sender of the message 182 | * @param[in] _msg - message type 183 | * @param[in] _lparam - first param 184 | * @param[in] _wparam - second param 185 | * @param[in] _extra - extra data 186 | * @return - message sending status 187 | */ 188 | AGE_API s32 send_message_to_sprite(Ptr _receiver, Ptr _sender, u32 _msg, u32 _lparam, u32 _wparam, Ptr _extra); 189 | /** 190 | * @brief send a message to a canvas object 191 | * 192 | * @param[in] _receiver - target canvas object 193 | * @param[in] _sender - sender of the message 194 | * @param[in] _msg - message type 195 | * @param[in] _lparam - first param 196 | * @param[in] _wparam - second param 197 | * @param[in] _extra - extra data 198 | * @return - message sending status 199 | */ 200 | AGE_API s32 send_message_to_canvas(Ptr _receiver, Ptr _sender, u32 _msg, u32 _lparam, u32 _wparam, Ptr _extra); 201 | 202 | #endif /* __AGE_MESSAGE_H__ */ 203 | -------------------------------------------------------------------------------- /ascii_game_engine/render/agerenderer_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #if AGE_IMPL == AGE_IMPL_WIN32 27 | 28 | #endif /* AGE_IMPL == AGE_IMPL_WIN32 */ 29 | -------------------------------------------------------------------------------- /ascii_game_engine/script/agescriptapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __AGE_SCRIPT_API_H__ 27 | #define __AGE_SCRIPT_API_H__ 28 | 29 | #include "../ageconfig.h" 30 | #include "../common/agetype.h" 31 | #include "my_basic/my_basic.h" 32 | 33 | /** 34 | * @brief my-basic interface adapter 35 | */ 36 | AGE_API bl amb_register_func(mb_interpreter_t* s, const Str n, mb_func_t f); 37 | /** 38 | * @brief my-basic interface adapter 39 | */ 40 | AGE_API bl amb_unregister_func(mb_interpreter_t* s, const Str n); 41 | 42 | /** 43 | * @brief my-basic interface adapter 44 | */ 45 | AGE_API int amb_attempt_func_begin(mb_interpreter_t* s, void** l); 46 | /** 47 | * @brief my-basic interface adapter 48 | */ 49 | AGE_API int amb_attempt_open_bracket(mb_interpreter_t* s, void** l); 50 | /** 51 | * @brief my-basic interface adapter 52 | */ 53 | AGE_API int amb_attempt_close_bracket(mb_interpreter_t* s, void** l); 54 | /** 55 | * @brief my-basic interface adapter 56 | */ 57 | AGE_API int amb_pop_int(mb_interpreter_t* s, void** l, int_t* val); 58 | /** 59 | * @brief my-basic interface adapter 60 | */ 61 | AGE_API int amb_pop_real(mb_interpreter_t* s, void** l, real_t* val); 62 | /** 63 | * @brief my-basic interface adapter 64 | */ 65 | AGE_API int amb_pop_string(mb_interpreter_t* s, void** l, char** val); 66 | /** 67 | * @brief my-basic interface adapter 68 | */ 69 | AGE_API int amb_pop_value(mb_interpreter_t* s, void** l, mb_value_t* val); 70 | /** 71 | * @brief my-basic interface adapter 72 | */ 73 | AGE_API int amb_push_int(mb_interpreter_t* s, void** l, int_t val); 74 | /** 75 | * @brief my-basic interface adapter 76 | */ 77 | AGE_API int amb_push_real(mb_interpreter_t* s, void** l, real_t val); 78 | /** 79 | * @brief my-basic interface adapter 80 | */ 81 | AGE_API int amb_push_string(mb_interpreter_t* s, void** l, char* val); 82 | /** 83 | * @brief my-basic interface adapter 84 | */ 85 | AGE_API int amb_push_value(mb_interpreter_t* s, void** l, mb_value_t val); 86 | 87 | /** 88 | * @brief my-basic api: pronounce a beep 89 | */ 90 | AGE_INTERNAL int age_api_beep(mb_interpreter_t* s, void** l); 91 | 92 | /** 93 | * @brief my-basic api: set audio mute enabled or disable 94 | */ 95 | AGE_INTERNAL int age_api_set_mute(mb_interpreter_t* s, void** l); 96 | 97 | /** 98 | * @brief my-basic api: register a key code mapping item 99 | */ 100 | AGE_INTERNAL int age_api_reg_key_code(mb_interpreter_t* s, void** l); 101 | 102 | /** 103 | * @brief my-basic api: set frame rate of a canvas 104 | */ 105 | AGE_INTERNAL int age_api_set_frame_rate(mb_interpreter_t* s, void** l); 106 | 107 | /** 108 | * @brief my-basic api: create a sprite object 109 | */ 110 | AGE_INTERNAL int age_api_create_sprite(mb_interpreter_t* s, void** l); 111 | 112 | /** 113 | * @brief my-basic api: destroy a sprite in a canvas 114 | */ 115 | AGE_INTERNAL int age_api_destroy_sprite(mb_interpreter_t* s, void** l); 116 | 117 | /** 118 | * @brief my-basic api: destroy all sprites in a canvas 119 | */ 120 | AGE_INTERNAL int age_api_destroy_all_sprites(mb_interpreter_t* s, void** l); 121 | 122 | /** 123 | * @brief my-basic api: set position of a sprite object 124 | */ 125 | AGE_INTERNAL int age_api_set_sprite_position(mb_interpreter_t* s, void** l); 126 | 127 | /** 128 | * @brief my-basic api: get x position of a sprite object 129 | */ 130 | AGE_INTERNAL int age_api_get_sprite_position_x(mb_interpreter_t* s, void** l); 131 | 132 | /** 133 | * @brief my-basic api: get y position of a sprite object 134 | */ 135 | AGE_INTERNAL int age_api_get_sprite_position_y(mb_interpreter_t* s, void** l); 136 | 137 | /** 138 | * @brief my-basic api: play an animation of a time line 139 | */ 140 | AGE_INTERNAL int age_api_play_sprite(mb_interpreter_t* s, void** l); 141 | 142 | /** 143 | * @brief my-basic api: stop an animation of a time line 144 | */ 145 | AGE_INTERNAL int age_api_stop_sprite(mb_interpreter_t* s, void** l); 146 | 147 | /** 148 | * @brief my-basic api: get a s32 parameter of the canvas 149 | */ 150 | AGE_INTERNAL int age_api_get_cvs_s32_param(mb_interpreter_t* s, void** l); 151 | 152 | /** 153 | * @brief my-basic api: set a s32 parameter of the canvas 154 | */ 155 | AGE_INTERNAL int age_api_set_cvs_s32_param(mb_interpreter_t* s, void** l); 156 | 157 | /** 158 | * @brief my-basic api: get a u32 parameter of the canvas 159 | */ 160 | AGE_INTERNAL int age_api_get_cvs_u32_param(mb_interpreter_t* s, void** l); 161 | 162 | /** 163 | * @brief my-basic api: set a u32 parameter of the canvas 164 | */ 165 | AGE_INTERNAL int age_api_set_cvs_u32_param(mb_interpreter_t* s, void** l); 166 | 167 | /** 168 | * @brief my-basic api: get a f32 parameter of the canvas 169 | */ 170 | AGE_INTERNAL int age_api_get_cvs_f32_param(mb_interpreter_t* s, void** l); 171 | 172 | /** 173 | * @brief my-basic api: set a f32 parameter of the canvas 174 | */ 175 | AGE_INTERNAL int age_api_set_cvs_f32_param(mb_interpreter_t* s, void** l); 176 | 177 | /** 178 | * @brief my-basic api: get a string parameter of the canvas 179 | */ 180 | AGE_INTERNAL int age_api_get_cvs_str_param(mb_interpreter_t* s, void** l); 181 | 182 | /** 183 | * @brief my-basic api: set a string parameter of the canvas 184 | */ 185 | AGE_INTERNAL int age_api_set_cvs_str_param(mb_interpreter_t* s, void** l); 186 | 187 | /** 188 | * @brief my-basic api: get a s32 parameter of a sprite 189 | */ 190 | AGE_INTERNAL int age_api_get_spr_s32_param(mb_interpreter_t* s, void** l); 191 | 192 | /** 193 | * @brief my-basic api: set a s32 parameter of a sprite 194 | */ 195 | AGE_INTERNAL int age_api_set_spr_s32_param(mb_interpreter_t* s, void** l); 196 | 197 | /** 198 | * @brief my-basic api: get a u32 parameter of a sprite 199 | */ 200 | AGE_INTERNAL int age_api_get_spr_u32_param(mb_interpreter_t* s, void** l); 201 | 202 | /** 203 | * @brief my-basic api: set a u32 parameter of a sprite 204 | */ 205 | AGE_INTERNAL int age_api_set_spr_u32_param(mb_interpreter_t* s, void** l); 206 | 207 | /** 208 | * @brief my-basic api: get a f32 parameter of a sprite 209 | */ 210 | AGE_INTERNAL int age_api_get_spr_f32_param(mb_interpreter_t* s, void** l); 211 | 212 | /** 213 | * @brief my-basic api: set a f32 parameter of a sprite 214 | */ 215 | AGE_INTERNAL int age_api_set_spr_f32_param(mb_interpreter_t* s, void** l); 216 | 217 | /** 218 | * @brief my-basic api: get a string parameter of a sprite 219 | */ 220 | AGE_INTERNAL int age_api_get_spr_str_param(mb_interpreter_t* s, void** l); 221 | 222 | /** 223 | * @brief my-basic api: set a string parameter of a sprite 224 | */ 225 | AGE_INTERNAL int age_api_set_spr_str_param(mb_interpreter_t* s, void** l); 226 | 227 | /** 228 | * @brief my-basic api: load saved data 229 | */ 230 | AGE_API void amb_load_data(const Str file); 231 | /** 232 | * @brief my-basic api: save data 233 | */ 234 | AGE_API void amb_save_data(const Str file); 235 | 236 | #endif /* __AGE_SCRIPT_API_H__ */ 237 | -------------------------------------------------------------------------------- /ascii_game_engine/script/my_basic/my_basic.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of MY-BASIC 3 | ** 4 | ** For the latest info, see http://code.google.com/p/my-basic/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __MY_BASIC_H__ 27 | #define __MY_BASIC_H__ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif /* __cplusplus */ 32 | 33 | #pragma pack(1) 34 | 35 | #ifndef true 36 | # define true (!0) 37 | #endif 38 | #ifndef false 39 | # define false (0) 40 | #endif 41 | 42 | #ifndef bool_t 43 | # define bool_t int 44 | #endif 45 | #ifndef byte_t 46 | # define byte_t unsigned char 47 | #endif 48 | #ifndef int_t 49 | # define int_t int 50 | #endif 51 | #ifndef real_t 52 | # define real_t float 53 | #endif 54 | 55 | #ifdef __APPLE__ 56 | # ifndef _strcmpi 57 | # define _strcmpi strcasecmp 58 | # endif /* _strcmpi */ 59 | #endif /* __APPLE__ */ 60 | 61 | #define MB_FUNC_OK 0 62 | #define MB_FUNC_ERR 1001 63 | #define MB_FUNC_END 1002 64 | #define MB_FUNC_SUSPEND 1003 65 | #define MB_PARSING_ERR 3001 66 | #define MB_LOOP_BREAK 5001 67 | #define MB_LOOP_CONTINUE 5002 68 | 69 | #define mb_check(__r) { int __hr = __r; if(__hr != MB_FUNC_OK) { return __hr; } } 70 | 71 | #define MBAPI 72 | 73 | #define mb_reg_fun(__s, __f) mb_register_func(__s, #__f, __f) 74 | #define mb_rem_fun(__s, __f) mb_remove_func(__s, #__f) 75 | 76 | struct mb_interpreter_t; 77 | 78 | typedef enum mb_error_e { 79 | SE_NO_ERR = 0, 80 | /** Common */ 81 | SE_CM_MB_OPEN_FAILED, 82 | SE_CM_FUNC_EXISTS, 83 | SE_CM_FUNC_NOT_EXISTS, 84 | /** Parsing */ 85 | SE_PS_FILE_OPEN_FAILED, 86 | SE_PS_SYMBOL_TOO_LONG, 87 | SE_PS_INVALID_CHAR, 88 | /** Running */ 89 | SE_RN_NOT_SUPPORTED, 90 | SE_RN_EMPTY_PROGRAM, 91 | SE_RN_SYNTAX, 92 | SE_RN_INVALID_DATA_TYPE, 93 | SE_RN_TYPE_NOT_MATCH, 94 | SE_RN_ILLEGAL_BOUND, 95 | SE_RN_DIMENSION_TOO_MUCH, 96 | SE_RN_OPERATION_FAILED, 97 | SE_RN_DIMENSION_OUT_OF_BOUND, 98 | SE_RN_ARRAY_OUT_OF_BOUND, 99 | SE_RN_LABEL_NOT_EXISTS, 100 | SE_RN_NO_RETURN_POINT, 101 | SE_RN_COLON_EXPECTED, 102 | SE_RN_ARRAY_IDENTIFIER_EXPECTED, 103 | SE_RN_OPEN_BRACKET_EXPECTED, 104 | SE_RN_CLOSE_BRACKET_EXPECTED, 105 | SE_RN_ARRAY_SUBSCRIPT_EXPECTED, 106 | SE_RN_STRUCTURE_NOT_COMPLETED, 107 | SE_RN_FUNCTION_EXPECTED, 108 | SE_RN_STRING_EXPECTED, 109 | SE_RN_VAR_OR_ARRAY_EXPECTED, 110 | SE_RN_ASSIGN_OPERATOR_EXPECTED, 111 | SE_RN_INTEGER_EXPECTED, 112 | SE_RN_ELSE_EXPECTED, 113 | SE_RN_TO_EXPECTED, 114 | SE_RN_UNTIL_EXPECTED, 115 | SE_RN_LOOP_VAR_EXPECTED, 116 | SE_RN_JUMP_LABEL_EXPECTED, 117 | } mb_error_e; 118 | 119 | typedef enum mb_data_e { 120 | MB_DT_NIL = -1, 121 | MB_DT_INT = 0, 122 | MB_DT_REAL, 123 | MB_DT_STRING, 124 | } mb_data_e; 125 | 126 | typedef union mb_value_u { 127 | int_t integer; 128 | real_t float_point; 129 | char* string; 130 | } mb_value_u; 131 | 132 | typedef struct mb_value_t { 133 | mb_data_e type; 134 | mb_value_u value; 135 | } mb_value_t; 136 | 137 | typedef void (* mb_error_handler_t)(struct mb_interpreter_t*, enum mb_error_e, char*, int); 138 | typedef int (* mb_func_t)(struct mb_interpreter_t*, void**); 139 | 140 | typedef struct mb_interpreter_t { 141 | void* local_func_dict; 142 | void* global_func_dict; 143 | void* global_var_dict; 144 | void* ast; 145 | void* parsing_context; 146 | void* running_context; 147 | mb_error_e last_error; 148 | int last_error_pos; 149 | mb_error_handler_t error_handler; 150 | } mb_interpreter_t; 151 | 152 | MBAPI unsigned int mb_ver(void); 153 | MBAPI const char* mb_ver_string(void); 154 | 155 | MBAPI int mb_init(void); 156 | MBAPI int mb_dispose(void); 157 | MBAPI int mb_open(mb_interpreter_t** s); 158 | MBAPI int mb_close(mb_interpreter_t** s); 159 | MBAPI int mb_reset(mb_interpreter_t** s, bool_t clrf); 160 | 161 | MBAPI int mb_register_func(mb_interpreter_t* s, const char* n, mb_func_t f); 162 | MBAPI int mb_remove_func(mb_interpreter_t* s, const char* n); 163 | 164 | MBAPI int mb_attempt_func_begin(mb_interpreter_t* s, void** l); 165 | MBAPI int mb_attempt_open_bracket(mb_interpreter_t* s, void** l); 166 | MBAPI int mb_attempt_close_bracket(mb_interpreter_t* s, void** l); 167 | MBAPI int mb_pop_int(mb_interpreter_t* s, void** l, int_t* val); 168 | MBAPI int mb_pop_real(mb_interpreter_t* s, void** l, real_t* val); 169 | MBAPI int mb_pop_string(mb_interpreter_t* s, void** l, char** val); 170 | MBAPI int mb_pop_value(mb_interpreter_t* s, void** l, mb_value_t* val); 171 | MBAPI int mb_push_int(mb_interpreter_t* s, void** l, int_t val); 172 | MBAPI int mb_push_real(mb_interpreter_t* s, void** l, real_t val); 173 | MBAPI int mb_push_string(mb_interpreter_t* s, void** l, char* val); 174 | MBAPI int mb_push_value(mb_interpreter_t* s, void** l, mb_value_t val); 175 | 176 | MBAPI int mb_load_string(mb_interpreter_t* s, const char* l); 177 | MBAPI int mb_load_file(mb_interpreter_t* s, const char* f); 178 | MBAPI int mb_run(mb_interpreter_t* s); 179 | MBAPI int mb_suspend(mb_interpreter_t* s, void** l); 180 | 181 | MBAPI mb_error_e mb_get_last_error(mb_interpreter_t* s); 182 | MBAPI const char* mb_get_error_desc(mb_error_e err); 183 | MBAPI int mb_set_error_handler(mb_interpreter_t* s, mb_error_handler_t h); 184 | 185 | #pragma pack() 186 | 187 | #ifdef __cplusplus 188 | } 189 | #endif /* __cplusplus */ 190 | 191 | #endif /* __MY_BASIC_H__ */ 192 | -------------------------------------------------------------------------------- /clean.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo Cleaning, a moment please... 3 | 4 | attrib *.suo -s -h -r 5 | 6 | del /f /s /q *.suo 7 | del /f /s /q *.user 8 | del /f /s /q *.ncb 9 | 10 | rd /s /q temp 11 | 12 | del /f /s /q game\data\save.bas 13 | 14 | del /f /s /q output\*.res 15 | del /f /s /q output\*.dep 16 | del /f /s /q output\*.htm 17 | del /f /s /q output\*.ilk 18 | del /f /s /q output\*.manifest 19 | del /f /s /q output\*.obj 20 | del /f /s /q output\*.pdb 21 | del /f /s /q output\*.idb 22 | 23 | rd /s /q output 24 | 25 | echo Cleaning done! 26 | echo. & pause 27 | -------------------------------------------------------------------------------- /game/animation.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "animation.h" 27 | #include "game.h" 28 | 29 | static AsciiHeroFsmTag NORMAL_FSM_TAG = { 0, "normal", "end_normal" }; 30 | static AsciiHeroFsmTag FALLING_FSM_TAG = { 1, "fall", "end_fall" }; 31 | static AsciiHeroFsmTag WALKING_FSM_TAG = { 2, "walk", "end_walk" }; 32 | static AsciiHeroFsmTag DIED_FSM_TAG = { 3, "died", "end_died" }; 33 | 34 | static AsciiHeroFsmCmd NORMAL_FSM_CMD = { "normal" }; 35 | static AsciiHeroFsmCmd WALKING_FSM_CMD = { "walk" }; 36 | static AsciiHeroFsmCmd COLLIDE_FSM_CMD = { "collide" }; 37 | static AsciiHeroFsmCmd NO_COLLIDE_FSM_CMD = { "no_collide" }; 38 | static AsciiHeroFsmCmd KILL_FSM_CMD = { "kill" }; 39 | 40 | void destroy_fsm_tag(Ptr _ptr) { 41 | /* do nothing */ 42 | } 43 | 44 | Ptr normal_fsm_tag(void) { 45 | return &NORMAL_FSM_TAG; 46 | } 47 | 48 | Ptr falling_fsm_tag(void) { 49 | return &FALLING_FSM_TAG; 50 | } 51 | 52 | Ptr walking_fsm_tag(void) { 53 | return &WALKING_FSM_TAG; 54 | } 55 | 56 | Ptr died_fsm_tag(void) { 57 | return &DIED_FSM_TAG; 58 | } 59 | 60 | Ptr normal_fsm_cmd(void) { 61 | return &NORMAL_FSM_CMD; 62 | } 63 | 64 | Ptr walking_fsm_cmd(void) { 65 | return &WALKING_FSM_CMD; 66 | } 67 | 68 | Ptr collide_fsm_cmd(void) { 69 | return &COLLIDE_FSM_CMD; 70 | } 71 | 72 | Ptr no_collide_fsm_cmd(void) { 73 | return &NO_COLLIDE_FSM_CMD; 74 | } 75 | 76 | Ptr kill_fsm_cmd(void) { 77 | return &KILL_FSM_CMD; 78 | } 79 | 80 | void open_ascii_hero_animation_fsm(Fsm* _fsm) { 81 | Bitset* bs = 0; 82 | 83 | register_bitfsm_rule_step_tag(_fsm, normal_fsm_tag()); 84 | register_bitfsm_rule_step_tag(_fsm, falling_fsm_tag()); 85 | register_bitfsm_rule_step_tag(_fsm, walking_fsm_tag()); 86 | register_bitfsm_rule_step_tag(_fsm, died_fsm_tag()); 87 | 88 | bs = bs_create(5); 89 | bs_clear(bs); 90 | bs_set_bit(bs, fsm_tag_to_command(no_collide_fsm_cmd()), TRUE); 91 | add_bitfsm_rule_step_by_tag(_fsm, normal_fsm_tag(), bs, falling_fsm_tag(), TRUE); 92 | bs_clear(bs); 93 | bs_set_bit(bs, fsm_tag_to_command(collide_fsm_cmd()), TRUE); 94 | add_bitfsm_rule_step_by_tag(_fsm, falling_fsm_tag(), bs, normal_fsm_tag(), TRUE); 95 | bs_clear(bs); 96 | bs_set_bit(bs, fsm_tag_to_command(walking_fsm_cmd()), TRUE); 97 | add_bitfsm_rule_step_by_tag(_fsm, normal_fsm_tag(), bs, walking_fsm_tag(), TRUE); 98 | bs_clear(bs); 99 | bs_set_bit(bs, fsm_tag_to_command(normal_fsm_cmd()), TRUE); 100 | add_bitfsm_rule_step_by_tag(_fsm, walking_fsm_tag(), bs, normal_fsm_tag(), TRUE); 101 | bs_clear(bs); 102 | bs_set_bit(bs, fsm_tag_to_command(no_collide_fsm_cmd()), TRUE); 103 | add_bitfsm_rule_step_by_tag(_fsm, walking_fsm_tag(), bs, falling_fsm_tag(), TRUE); 104 | bs_clear(bs); 105 | bs_set_bit(bs, fsm_tag_to_command(kill_fsm_cmd()), TRUE); 106 | add_bitfsm_rule_step_by_tag(_fsm, normal_fsm_tag(), bs, died_fsm_tag(), TRUE); 107 | bs_clear(bs); 108 | bs_set_bit(bs, fsm_tag_to_command(kill_fsm_cmd()), TRUE); 109 | add_bitfsm_rule_step_by_tag(_fsm, falling_fsm_tag(), bs, died_fsm_tag(), TRUE); 110 | bs_clear(bs); 111 | bs_set_bit(bs, fsm_tag_to_command(kill_fsm_cmd()), TRUE); 112 | add_bitfsm_rule_step_by_tag(_fsm, walking_fsm_tag(), bs, died_fsm_tag(), TRUE); 113 | bs_destroy(bs); 114 | 115 | set_bitfsm_current_step_tag(_fsm, normal_fsm_tag()); 116 | walk_bitfsm_with_tag(_fsm, no_collide_fsm_cmd(), TRUE); 117 | } 118 | 119 | void close_ascii_hero_animation_fsm(Fsm* _fsm) { 120 | clear_bitfsm(_fsm); 121 | } 122 | 123 | s32 fsm_tag_to_index(Ptr _obj) { 124 | AsciiHeroFsmTag* tag = (AsciiHeroFsmTag*)_obj; 125 | 126 | assert(_obj); 127 | 128 | return tag->index; 129 | } 130 | 131 | s32 fsm_tag_to_command(Ptr _obj) { 132 | s32 result = 0; 133 | AsciiHeroFsmCmd* cmd = (AsciiHeroFsmCmd*)_obj; 134 | 135 | assert(_obj); 136 | if(cmd == &NORMAL_FSM_CMD) { 137 | result = 0; 138 | } else if(cmd == &WALKING_FSM_CMD) { 139 | result = 1; 140 | } else if(cmd == &COLLIDE_FSM_CMD) { 141 | result = 2; 142 | } else if(cmd == &NO_COLLIDE_FSM_CMD) { 143 | result = 3; 144 | } else if(cmd == &KILL_FSM_CMD) { 145 | result = 4; 146 | } else { 147 | assert(0 && "Unknown FSM command"); 148 | } 149 | 150 | return result; 151 | } 152 | 153 | void fsm_step_handler(Ptr _src, Ptr _tgt) { 154 | s8 buf[AGE_STR_LEN]; 155 | AsciiHeroFsmTag* t1 = (AsciiHeroFsmTag*)_src; 156 | AsciiHeroFsmTag* t2 = (AsciiHeroFsmTag*)_tgt; 157 | sprintf(buf, "from %d: %s, to %d: %s\n", t1->index, t1->start_frame, t2->index, t2->start_frame); 158 | #ifdef _DEBUG 159 | OutputDebugStringA(buf); 160 | #endif 161 | 162 | if(_src == falling_fsm_tag() && _tgt == normal_fsm_tag()) { 163 | if(game()->audio[AHAT_COLLIDE]) { 164 | play_sound_string(AGE_SND, game()->audio[AHAT_COLLIDE], ST_SFX, FALSE); 165 | } 166 | } 167 | 168 | play_sprite(AGE_CVS, game()->main, 169 | t2->start_frame, t2->end_frame, 170 | TRUE, 171 | on_playing_for_sprite_main_player 172 | ); 173 | resume_sprite(AGE_CVS, game()->main); 174 | } 175 | -------------------------------------------------------------------------------- /game/animation.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __ANIMATION_H__ 27 | #define __ANIMATION_H__ 28 | 29 | #include "age.h" 30 | 31 | typedef struct AsciiHeroFsmTag { 32 | s32 index; 33 | struct { 34 | Str start_frame; 35 | Str end_frame; 36 | }; 37 | } AsciiHeroFsmTag; 38 | 39 | typedef struct AsciiHeroFsmCmd { 40 | Str info; 41 | } AsciiHeroFsmCmd; 42 | 43 | void destroy_fsm_tag(Ptr _ptr); 44 | 45 | Ptr normal_fsm_tag(void); 46 | Ptr falling_fsm_tag(void); 47 | Ptr walking_fsm_tag(void); 48 | Ptr died_fsm_tag(void); 49 | 50 | Ptr normal_fsm_cmd(void); 51 | Ptr walking_fsm_cmd(void); 52 | Ptr collide_fsm_cmd(void); 53 | Ptr no_collide_fsm_cmd(void); 54 | Ptr kill_fsm_cmd(void); 55 | 56 | void open_ascii_hero_animation_fsm(Fsm* _fsm); 57 | void close_ascii_hero_animation_fsm(Fsm* _fsm); 58 | 59 | s32 fsm_tag_to_index(Ptr _obj); 60 | s32 fsm_tag_to_command(Ptr _obj); 61 | 62 | void fsm_step_handler(Ptr _src, Ptr _tgt); 63 | 64 | #endif /* __ANIMATION_H__ */ 65 | -------------------------------------------------------------------------------- /game/data/config.bas: -------------------------------------------------------------------------------- 1 | SET_FOOT_BRUSH("9") 2 | 3 | SET_FRAME_RATE(40) 4 | 5 | KC_UP = 0 6 | KC_DOWN = 1 7 | KC_LEFT = 2 8 | KC_RIGHT = 3 9 | KC_OK = 4 10 | KC_ESC = 5 11 | KC_P = 6 12 | REG_KEY(0, KC_UP, 72) 13 | REG_KEY(0, KC_DOWN, 80) 14 | REG_KEY(0, KC_LEFT, 75) 15 | REG_KEY(0, KC_RIGHT, 77) 16 | REG_KEY(0, KC_OK, 13) 17 | REG_KEY(0, KC_ESC, 27) 18 | REG_KEY(0, KC_P, 112) 19 | 20 | SET_MUTE(FALSE) 21 | AHAT_LOGO = 0 22 | AHAT_TICK = 1 23 | AHAT_COLLIDE = 2 24 | AHAT_GAME_OVER = 3 25 | SET_AUDIO_STRING(AHAT_LOGO, "DEDEC>AAAA~~~] 66 | ~~~~~~~~ 67 | 68 | [~~~~=>~~] 69 | ~~~~~~~~ 70 | 71 | [~~~~~=>~] 72 | ~~~~~~~~ 73 | 74 | [~~~~=>~~] 75 | ~~~~~~~~ 76 | 77 | [~~~=>~~~] 78 | ~~~~~~~~ 79 | 80 | [~~=>~~~~] 81 | ~~~~~~~~ 82 | 83 | [~=>~~~~~] 84 | ~~~~~~~~ 85 | 86 | [~~=>~~~~] 87 | ~~~~~~~~ 88 | 89 | [~~~~=>~~] 90 | ~~~~~~~~ 91 | -------------------------------------------------------------------------------- /game/data/sprite/board_palete.txt: -------------------------------------------------------------------------------- 1 | [: 3 2 | ]: 3 3 | ~: 3 4 | Z: 15 5 | z: 15 6 | =: 10 7 | -: 15 8 | _: 15 9 | A: 15 10 | T: 7 11 | <: 10 12 | >: 10 13 | -------------------------------------------------------------------------------- /game/data/sprite/board_shape.txt: -------------------------------------------------------------------------------- 1 | count: 29 2 | width: 10 3 | height: 2 4 | rate: 1 5 | 6 | @solid 7 | [~~~~~~~~] 8 | ~~~~~~~~ 9 | 10 | @end_solid 11 | [~~~~~~~~] 12 | ~~~~~~~~ 13 | 14 | @spring 15 | ZZZZZZZZZZ 16 | ~~~~~~~~ 17 | 18 | zzzzzzzzzz 19 | ~~~~~~~~ 20 | 21 | ---------- 22 | ~~~~~~~~ 23 | 24 | __________ 25 | ~~~~~~~~ 26 | 27 | ---------- 28 | ~~~~~~~~ 29 | 30 | zzzzzzzzzz 31 | ~~~~~~~~ 32 | 33 | @end_spring 34 | ZZZZZZZZZZ 35 | ~~~~~~~~ 36 | 37 | @serration 38 | AAAAAAAAAA 39 | ~~~~~~~~ 40 | 41 | @end_serration 42 | AAAAAAAAAA 43 | ~~~~~~~~ 44 | 45 | @overturn 46 | TTTTTTTTTT 47 | ~~~~~~~~ 48 | 49 | @end_overturn 50 | TTTTTTTTTT 51 | ~~~~~~~~ 52 | 53 | @l-scroll 54 | [~~~<=~~~] 55 | ~~~~~~~~ 56 | 57 | [~~<=~~~~] 58 | ~~~~~~~~ 59 | 60 | [~<=~~~~~] 61 | ~~~~~~~~ 62 | 63 | [~~<=~~~~] 64 | ~~~~~~~~ 65 | 66 | [~~~<=~~~] 67 | ~~~~~~~~ 68 | 69 | [~~~~<=~~] 70 | ~~~~~~~~ 71 | 72 | [~~~~~<=~] 73 | ~~~~~~~~ 74 | 75 | @end_l-scroll 76 | [~~~=>~~~] 77 | ~~~~~~~~ 78 | 79 | @r-scroll 80 | [~~~~=>~~] 81 | ~~~~~~~~ 82 | 83 | [~~~~~=>~] 84 | ~~~~~~~~ 85 | 86 | [~~~~=>~~] 87 | ~~~~~~~~ 88 | 89 | [~~~=>~~~] 90 | ~~~~~~~~ 91 | 92 | [~~=>~~~~] 93 | ~~~~~~~~ 94 | 95 | [~=>~~~~~] 96 | ~~~~~~~~ 97 | 98 | [~~=>~~~~] 99 | ~~~~~~~~ 100 | 101 | @end_r-scroll 102 | [~~~~=>~~] 103 | ~~~~~~~~ 104 | -------------------------------------------------------------------------------- /game/data/ui/copyright_brush.txt: -------------------------------------------------------------------------------- 1 | count: 1 2 | width: 25 3 | height: 1 4 | 5 | lllllllll llll llllll lll 6 | -------------------------------------------------------------------------------- /game/data/ui/copyright_palete.txt: -------------------------------------------------------------------------------- 1 | l: 15 2 | -------------------------------------------------------------------------------- /game/data/ui/copyright_shape.txt: -------------------------------------------------------------------------------- 1 | count: 1 2 | width: 25 3 | height: 1 4 | rate: 1 5 | 6 | Copyright 2011 Tony's Toy 7 | -------------------------------------------------------------------------------- /game/data/ui/logo_brush.txt: -------------------------------------------------------------------------------- 1 | clunt: 1 2 | width: 45 3 | heilht: 12 4 | 5 | ll lllll lllll lllllll lllllll 6 | l l l lllll lllllll lll lll lll lll 7 | l ll l l lllll l l l l l l 8 | l llll l llll l l l l l l l 9 | l ll l llll l l llllll lll lll lll lll 10 | lll lll lllllll lllllll lllllllll lllllllll 11 | l l lllllll llllllll lllll 12 | l l l l l lllll l llll l l lll l 13 | l lllll l l llll l lllll l l l l l 14 | l lll l l lll] l lll l l l l l 15 | l l l l l lllll l l l l l lllll l 16 | lll lll llllllll lll lll lllllll lll 17 | -------------------------------------------------------------------------------- /game/data/ui/logo_palete.txt: -------------------------------------------------------------------------------- 1 | l: 8 2 | -------------------------------------------------------------------------------- /game/data/ui/logo_shape.txt: -------------------------------------------------------------------------------- 1 | count: 1 2 | width: 45 3 | height: 12 4 | rate: 1 5 | 6 | __ _____ _____ _______ _______ 7 | / \ / ____/ /_____\ |__ __| |__ __| 8 | / /\ \ | |____ | | | | | | 9 | | |__| | \___ \ | | | | | | 10 | | __ | ___| | | |_____ __| |__ __| |__ 11 | |_| |_| /_____/ \_____/ |_______| |_______| 12 | _ _ _______ ________ _____ 13 | | | | | | ____/ | ____ \ / ___ \ 14 | | |___| | | |___ | |___| | | | | | 15 | | ___ | | ___] | ___ < | | | | 16 | | | | | | |____ | | \ \ | |___| | 17 | |_| |_| |______\ |_| |_| \_____/ Go! 18 | -------------------------------------------------------------------------------- /game/data/ui/number_brush.txt: -------------------------------------------------------------------------------- 1 | count: 20 2 | width: 4 3 | height: 5 4 | 5 | 00 6 | 0 0 7 | 0 0 8 | 0 0 9 | 00 10 | 11 | 00 12 | 0 0 13 | 0 0 14 | 0 0 15 | 00 16 | 17 | 1 18 | 1 19 | 1 20 | 1 21 | 1 22 | 23 | 1 24 | 1 25 | 1 26 | 1 27 | 1 28 | 29 | 22 30 | 2 2 31 | 2 32 | 2 33 | 2222 34 | 35 | 22 36 | 2 2 37 | 2 38 | 2 39 | 2222 40 | 41 | 33 42 | 3 3 43 | 3 44 | 3 3 45 | 33 46 | 47 | 33 48 | 3 3 49 | 3 50 | 3 3 51 | 33 52 | 53 | 4 54 | 4 4 55 | 4 4 56 | 4444 57 | 4 58 | 59 | 4 60 | 4 4 61 | 4 4 62 | 4444 63 | 4 64 | 65 | 5555 66 | 5 67 | 555 68 | 5 69 | 555 70 | 71 | 5555 72 | 5 73 | 555 74 | 5 75 | 555 76 | 77 | 66 78 | 6 79 | 666 80 | 6 6 81 | 66 82 | 83 | 66 84 | 6 85 | 666 86 | 6 6 87 | 66 88 | 89 | 7777 90 | 7 91 | 7 92 | 7 93 | 7 94 | 95 | 7777 96 | 7 97 | 7 98 | 7 99 | 7 100 | 101 | 88 102 | 8 8 103 | 88 104 | 8 8 105 | 88 106 | 107 | 88 108 | 8 8 109 | 88 110 | 8 8 111 | 88 112 | 113 | 99 114 | 9 9 115 | 999 116 | 9 117 | 99 118 | 119 | 99 120 | 9 9 121 | 999 122 | 9 123 | 99 124 | -------------------------------------------------------------------------------- /game/data/ui/number_palete.txt: -------------------------------------------------------------------------------- 1 | 0: 8 2 | 1: 9 3 | 2: 10 4 | 3: 11 5 | 4: 12 6 | 5: 13 7 | 6: 14 8 | 7: 15 9 | 8: 1 10 | 9: 2 11 | -------------------------------------------------------------------------------- /game/data/ui/number_shape.txt: -------------------------------------------------------------------------------- 1 | count: 20 2 | width: 4 3 | height: 5 4 | rate: 10 5 | 6 | @s0 7 | 00 8 | 0 0 9 | 0 0 10 | 0 0 11 | 00 12 | 13 | @e0 14 | 00 15 | 0 0 16 | 0 0 17 | 0 0 18 | 00 19 | 20 | @s1 21 | 1 22 | 1 23 | 1 24 | 1 25 | 1 26 | 27 | @e1 28 | 1 29 | 1 30 | 1 31 | 1 32 | 1 33 | 34 | @s2 35 | 22 36 | 2 2 37 | 2 38 | 2 39 | 2222 40 | 41 | @e2 42 | 22 43 | 2 2 44 | 2 45 | 2 46 | 2222 47 | 48 | @s3 49 | 33 50 | 3 3 51 | 3 52 | 3 3 53 | 33 54 | 55 | @e3 56 | 33 57 | 3 3 58 | 3 59 | 3 3 60 | 33 61 | 62 | @s4 63 | 4 64 | 4 4 65 | 4 4 66 | 4444 67 | 4 68 | 69 | @e4 70 | 4 71 | 4 4 72 | 4 4 73 | 4444 74 | 4 75 | 76 | @s5 77 | 5555 78 | 5 79 | 555 80 | 5 81 | 555 82 | 83 | @e5 84 | 5555 85 | 5 86 | 555 87 | 5 88 | 555 89 | 90 | @s6 91 | 66 92 | 6 93 | 666 94 | 6 6 95 | 66 96 | 97 | @e6 98 | 66 99 | 6 100 | 666 101 | 6 6 102 | 66 103 | 104 | @s7 105 | 7777 106 | 7 107 | 7 108 | 7 109 | 7 110 | 111 | @e7 112 | 7777 113 | 7 114 | 7 115 | 7 116 | 7 117 | 118 | @s8 119 | 88 120 | 8 8 121 | 88 122 | 8 8 123 | 88 124 | 125 | @e8 126 | 88 127 | 8 8 128 | 88 129 | 8 8 130 | 88 131 | 132 | @s9 133 | 99 134 | 9 9 135 | 999 136 | 9 137 | 99 138 | 139 | @e9 140 | 99 141 | 9 9 142 | 999 143 | 9 144 | 99 145 | -------------------------------------------------------------------------------- /game/game.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/ascii_game_engine/05c1961b7a3cea5e46909cb5de2012cf0949abc3/game/game.aps -------------------------------------------------------------------------------- /game/game.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "age.h" 32 | #include "animation.h" 33 | #include "game.h" 34 | #include "logic.h" 35 | #include "renderer.h" 36 | #include "script.h" 37 | #include "state.h" 38 | 39 | static AsciiHeroGame _game; 40 | 41 | static void _on_exit(void) { 42 | s32 c = 0; 43 | s32 i = 0; 44 | static bl destroyed = FALSE; 45 | 46 | if(!destroyed) { 47 | for(i = 0; i < AHAT_COUNT; ++i) { 48 | if(game()->audio[i]) { 49 | AGE_FREE(game()->audio[i]); 50 | game()->audio[i] = 0; 51 | } 52 | } 53 | game()->destroy_score_boards(); 54 | game()->clear_board(); 55 | 56 | amb_save_data("data/save.bas"); 57 | 58 | destroy_world(); 59 | 60 | destroyed = TRUE; 61 | } 62 | 63 | c = _CrtDumpMemoryLeaks(); 64 | 65 | if(0 != c) { 66 | #ifdef _DEBUG 67 | _asm int 3 68 | #else 69 | printf("Memory leak detected.\n"); 70 | system("pause"); 71 | #endif 72 | } 73 | } 74 | 75 | static void _on_init(void) { 76 | Str audio[AHAT_COUNT]; 77 | s8 fb = game()->foot_brush; 78 | memcpy(audio, game()->audio, sizeof(game()->audio)); 79 | memset(game(), 0, sizeof(AsciiHeroGame)); 80 | memcpy(game()->audio, audio, sizeof(game()->audio)); 81 | game()->foot_brush = fb; 82 | init(); 83 | game()->create_score_boards(); 84 | AGE_CVS->store_params = TRUE; 85 | 86 | SetConsoleTitleA("ASCII HERO GO!"); 87 | 88 | set_s32_param(AGE_CVS_PAR, "HIGH_SCORE", 0); 89 | fensure("data/save.bas"); 90 | amb_load_data("data/save.bas"); 91 | } 92 | 93 | AsciiHeroGame* game(void) { 94 | return &_game; 95 | } 96 | 97 | s32 main(s32 argc, Str argv[]) { 98 | _CrtSetBreakAlloc(0); 99 | 100 | atexit(_on_exit); 101 | 102 | create_world(); 103 | register_game_script_interfaces(); 104 | config_world("data/config.bas"); 105 | _on_init(); 106 | 107 | run_world(); 108 | 109 | _on_exit(); 110 | 111 | return 0; 112 | } 113 | -------------------------------------------------------------------------------- /game/game.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __GAME_H__ 27 | #define __GAME_H__ 28 | 29 | #include "age.h" 30 | #include "logic.h" 31 | 32 | AsciiHeroGame* game(void); 33 | 34 | #endif /* __GAME_H__ */ 35 | -------------------------------------------------------------------------------- /game/game.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/ascii_game_engine/05c1961b7a3cea5e46909cb5de2012cf0949abc3/game/game.rc -------------------------------------------------------------------------------- /game/game.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 26 | 29 | 32 | 35 | 38 | 41 | 55 | 58 | 61 | 64 | 74 | 77 | 80 | 83 | 86 | 89 | 92 | 95 | 96 | 104 | 107 | 110 | 113 | 116 | 119 | 133 | 136 | 139 | 142 | 153 | 156 | 159 | 162 | 165 | 168 | 171 | 174 | 175 | 176 | 177 | 178 | 179 | 182 | 185 | 189 | 192 | 193 | 197 | 200 | 201 | 202 | 205 | 206 | 209 | 212 | 213 | 216 | 217 | 220 | 221 | 224 | 225 | 228 | 229 | 232 | 233 | 234 | 237 | 240 | 241 | 244 | 245 | 248 | 249 | 252 | 253 | 256 | 257 | 260 | 261 | 264 | 265 | 268 | 269 | 272 | 273 | 274 | 275 | 278 | 281 | 282 | 285 | 286 | 289 | 290 | 291 | 294 | 295 | 298 | 299 | 302 | 303 | 306 | 307 | 310 | 311 | 314 | 315 | 318 | 319 | 322 | 323 | 326 | 327 | 330 | 331 | 334 | 335 | 338 | 339 | 340 | 341 | 342 | 343 | -------------------------------------------------------------------------------- /game/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/ascii_game_engine/05c1961b7a3cea5e46909cb5de2012cf0949abc3/game/icon.ico -------------------------------------------------------------------------------- /game/logic.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __LOGIC_H__ 27 | #define __LOGIC_H__ 28 | 29 | #include "age.h" 30 | 31 | #define DEFAULT_LINE_UP_TIME 500 32 | #define MIN_LINE_UP_TIME 150 33 | #define DEFAULT_LEVEL_DISTANCE 6 34 | #define DEFAULT_FALL_TIME 100 35 | 36 | #define SCORE_BOARD_SIZE 4 37 | 38 | #define DEFAULT_JUMP_LINE 3 39 | #define DEFAULT_JUMP_TIME 50 40 | 41 | typedef enum AsciiHeroBoardType { 42 | AHBT_SOLID, 43 | AHBT_SPRING, 44 | AHBT_SERRATION, 45 | AHBT_OVERTURN, 46 | AHBT_L_SCROLL, 47 | AHBT_R_SCROLL, 48 | AHBT_COUNT, 49 | } AsciiHeroBoardType; 50 | 51 | typedef enum AsciiHeroAudioTypes { 52 | AHAT_LOGO, 53 | AHAT_TICK, 54 | AHAT_COLLIDE, 55 | AHAT_GAME_OVER, 56 | AHAT_COUNT, 57 | } AsciiHeroAudioTypes; 58 | 59 | typedef struct AsciiHeroGame { 60 | Str audio[AHAT_COUNT]; 61 | Sprite* main; 62 | Sprite* subsidiary; 63 | Sprite* board_template; 64 | Sprite** board_pool; 65 | s32 board_pool_size; 66 | s32 board_count; 67 | Sprite* score_board[SCORE_BOARD_SIZE]; 68 | bl game_over; 69 | s32 time; 70 | s32 line_up_time; 71 | u32 line_count; 72 | u32 level_distance; 73 | u32 level_count; 74 | bl level_generated; 75 | s8 foot_brush; 76 | AsciiHeroBoardType (* generate_board_type)(void); 77 | Sprite* (* add_board_by_type)(AsciiHeroBoardType _type); 78 | s32 (* drop_board)(Sprite* _spr); 79 | s32 (* remove_board)(Sprite* _spr); 80 | s32 (* clear_board)(void); 81 | void (* create_score_boards)(void); 82 | void (* destroy_score_boards)(void); 83 | void (* set_score_board_value)(u32 score); 84 | void (* set_score_board_visible)(bl vis); 85 | } AsciiHeroGame; 86 | 87 | typedef enum Direction { 88 | DIR_LEFT, 89 | DIR_RIGHT, 90 | DIR_UP, 91 | DIR_DOWN, 92 | } Direction; 93 | 94 | typedef enum UserMessages { 95 | MSG_USER_BEGIN = MSG_USER + 1, 96 | MSG_BOARD_UP, 97 | MSG_MOVE, 98 | MSG_JUMP, 99 | }UserMessages; 100 | 101 | typedef struct BoardUserdata { 102 | u32 type; 103 | bl drop; 104 | bl collition; 105 | s32 time; 106 | } BoardUserdata; 107 | 108 | typedef struct PlayerUserdata { 109 | s32 time; 110 | s32 fall_time; 111 | s32 jump_line; 112 | s32 jump_time; 113 | s8 on_board[AGE_STR_LEN]; 114 | s32 collition_direction; 115 | u32 hold_step_count; 116 | Fsm* fsm; 117 | } PlayerUserdata; 118 | 119 | typedef void (* BoardAction)(Canvas* _cvs, Sprite* _spr); 120 | typedef struct BoardInfo { 121 | const Str start_frame; 122 | const Str end_frame; 123 | struct { 124 | s32 prob_min; 125 | s32 prob_max; 126 | AsciiHeroBoardType type; 127 | }; 128 | BoardAction action; 129 | } BoardInfo; 130 | 131 | void solid_board_action(Canvas* _cvs, Sprite* _spr); 132 | void spring_board_action(Canvas* _cvs, Sprite* _spr); 133 | void serration_board_action(Canvas* _cvs, Sprite* _spr); 134 | void overturn_board_action(Canvas* _cvs, Sprite* _spr); 135 | void lscroll_board_action(Canvas* _cvs, Sprite* _spr); 136 | void rscroll_board_action(Canvas* _cvs, Sprite* _spr); 137 | 138 | static const BoardInfo BOARD_INFO[AHBT_COUNT] = { 139 | { "solid", "end_solid", 0, 29, AHBT_SOLID, solid_board_action }, 140 | { "spring", "end_spring", 30, 39, AHBT_SPRING, spring_board_action }, 141 | { "serration", "end_serration", 40, 49, AHBT_SERRATION, serration_board_action }, 142 | { "overturn", "end_overturn", 50, 64, AHBT_OVERTURN, overturn_board_action }, 143 | { "l-scroll", "end_l-scroll", 65, 74, AHBT_L_SCROLL, lscroll_board_action }, 144 | { "r-scroll", "end_r-scroll", 75, 84, AHBT_R_SCROLL, rscroll_board_action }, 145 | }; 146 | 147 | void init(void); 148 | 149 | BoardUserdata* create_board_userdata(void); 150 | void destroy_board_userdata(Ptr _ptr); 151 | 152 | PlayerUserdata* create_player_userdata(void); 153 | void destroy_player_userdata(Ptr _ptr); 154 | 155 | s32 on_ctrl_for_sprite_main_player(Ptr _obj, const Str _name, s32 _elapsedTime, u32 _lparam, u32 _wparam, Ptr _extra); 156 | 157 | s32 on_ctrl_for_sprite_board(Ptr _obj, const Str _name, s32 _elapsedTime, u32 _lparam, u32 _wparam, Ptr _extra); 158 | 159 | s32 on_msg_proc_for_canvas(Ptr _receiver, Ptr _sender, u32 _msg, u32 _lparam, u32 _wparam, Ptr _extra); 160 | 161 | s32 on_msg_proc_for_sprite_main_player(Ptr _receiver, Ptr _sender, u32 _msg, u32 _lparam, u32 _wparam, Ptr _extra); 162 | 163 | s32 on_msg_proc_for_sprite_board(Ptr _receiver, Ptr _sender, u32 _msg, u32 _lparam, u32 _wparam, Ptr _extra); 164 | 165 | s32 on_playing_for_sprite_main_player(Canvas* _cvs, Sprite* _spr, const Str _begin, const Str _end, s32 _currIdx); 166 | 167 | s32 on_playing_for_sprite_board(Canvas* _cvs, Sprite* _spr, const Str _begin, const Str _end, s32 _currIdx); 168 | 169 | void on_removing_for_sprite_main_player(Ptr _handlerObj, Canvas* _cvs, Sprite* _spr); 170 | 171 | void on_removing_for_sprite_board(Ptr _handlerObj, Canvas* _cvs, Sprite* _spr); 172 | 173 | void on_collide_for_sprite_main_player(Canvas* _cvs, Sprite* _spr, s32 _px, s32 _py); 174 | 175 | void on_collide_for_sprite_board(Canvas* _cvs, Sprite* _spr, s32 _px, s32 _py); 176 | 177 | void on_update_for_sprite_main_player(Canvas* _cvs, Sprite* _spr, s32 _elapsedTime); 178 | 179 | void on_update_for_sprite_board(Canvas* _cvs, Sprite* _spr, s32 _elapsedTime); 180 | 181 | s32 on_msg_proc_for_sprite_board_up(Ptr _receiver, Ptr _sender, u32 _msg, u32 _lparam, u32 _wparam, Ptr _extra); 182 | 183 | s32 on_msg_proc_for_sprite_main_player_move(Ptr _receiver, Ptr _sender, u32 _msg, u32 _lparam, u32 _wparam, Ptr _extra); 184 | 185 | s32 on_msg_proc_for_sprite_main_player_jump(Ptr _receiver, Ptr _sender, u32 _msg, u32 _lparam, u32 _wparam, Ptr _extra); 186 | 187 | #endif /* __LOGIC_H__ */ 188 | -------------------------------------------------------------------------------- /game/renderer.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "renderer.h" 27 | #include "game.h" 28 | 29 | void main_canvas_prev_render(Canvas* _cvs, s32 _elapsedTime) { 30 | s32 i = 0; 31 | static Font f = { 1 }; 32 | 33 | for(i = 0; i < GAME_AREA_HEIGHT; ++i) { 34 | put_char(_cvs, &f, GAME_AREA_LEFT, i, '#'); 35 | put_char(_cvs, &f, GAME_AREA_RIGHT, i, '#'); 36 | } 37 | } 38 | 39 | void main_canvas_post_render(Canvas* _cvs, s32 _elapsedTime) { 40 | } 41 | -------------------------------------------------------------------------------- /game/renderer.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __RENDERER_H__ 27 | #define __RENDERER_H__ 28 | 29 | #include "age.h" 30 | 31 | #define GAME_AREA_WIDTH 60 32 | #define GAME_AREA_HEIGHT CANVAS_HEIGHT 33 | #define GAME_AREA_LEFT 0 34 | #define GAME_AREA_RIGHT (GAME_AREA_LEFT + GAME_AREA_WIDTH) 35 | #define GAME_AREA_TOP 0 36 | #define GAME_AREA_BOTTOM (GAME_AREA_TOP + GAME_AREA_HEIGHT) 37 | 38 | void main_canvas_prev_render(Canvas* _cvs, s32 _elapsedTime); 39 | 40 | void main_canvas_post_render(Canvas* _cvs, s32 _elapsedTime); 41 | 42 | #endif /* __RENDERER_H__ */ 43 | -------------------------------------------------------------------------------- /game/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by game.rc 4 | // 5 | #define IDI_ICON1 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /game/script.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "script.h" 27 | #include "game.h" 28 | 29 | static int _set_foot_brush(mb_interpreter_t* s, void** l) { 30 | int result = MB_FUNC_OK; 31 | Str b = 0; 32 | 33 | assert(s && l); 34 | 35 | amb_attempt_open_bracket(s, l); 36 | amb_pop_string(s, l, &b); 37 | amb_attempt_close_bracket(s, l); 38 | 39 | game()->foot_brush = b[0]; 40 | 41 | return result; 42 | } 43 | 44 | static int _set_audio_string(mb_interpreter_t* s, void** l) { 45 | int result = MB_FUNC_OK; 46 | s32 t = 0; 47 | Str b = 0; 48 | 49 | assert(s && l); 50 | 51 | amb_attempt_open_bracket(s, l); 52 | amb_pop_int(s, l, &t); 53 | amb_pop_string(s, l, &b); 54 | amb_attempt_close_bracket(s, l); 55 | 56 | assert(t >= 0 && t < AHAT_COUNT); 57 | if(t >= 0 && t < AHAT_COUNT) { 58 | game()->audio[t] = AGE_REALLOC(s8, game()->audio[t], strlen(b) + 1); 59 | strcpy(game()->audio[t], b); 60 | } 61 | 62 | return result; 63 | } 64 | 65 | void register_game_script_interfaces(void) { 66 | amb_register_func(get_world()->script, "SET_FOOT_BRUSH", _set_foot_brush); 67 | amb_register_func(get_world()->script, "SET_AUDIO_STRING", _set_audio_string); 68 | } 69 | -------------------------------------------------------------------------------- /game/script.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __SCRIPT_H__ 27 | #define __SCRIPT_H__ 28 | 29 | #include "age.h" 30 | 31 | void register_game_script_interfaces(void); 32 | 33 | #endif /* __SCRIPT_H__ */ 34 | -------------------------------------------------------------------------------- /game/state.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** This source file is part of AGE 3 | ** 4 | ** For the latest info, see http://code.google.com/p/ascii-game-engine/ 5 | ** 6 | ** Copyright (c) 2011 Tony & Tony's Toy Game Development Team 7 | ** 8 | ** Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | ** this software and associated documentation files (the "Software"), to deal in 10 | ** the Software without restriction, including without limitation the rights to 11 | ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | ** the Software, and to permit persons to whom the Software is furnished to do so, 13 | ** subject to the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included in all 16 | ** copies or substantial portions of the Software. 17 | ** 18 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | ** FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | ** IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __STATE_H__ 27 | #define __STATE_H__ 28 | 29 | #include "age.h" 30 | 31 | s32 state_show_splash(Ptr _obj, const Str _name, s32 _elapsedTime, u32 _lparam, u32 _wparam, Ptr _extra); 32 | 33 | s32 state_show_logo(Ptr _obj, const Str _name, s32 _elapsedTime, u32 _lparam, u32 _wparam, Ptr _extra); 34 | 35 | s32 state_text_list(Ptr _obj, const Str _name, s32 _elapsedTime, u32 _lparam, u32 _wparam, Ptr _extra); 36 | 37 | s32 state_show_highscore(Ptr _obj, const Str _name, s32 _elapsedTime, u32 _lparam, u32 _wparam, Ptr _extra); 38 | 39 | s32 state_main(Ptr _obj, const Str _name, s32 _elapsedTime, u32 _lparam, u32 _wparam, Ptr _extra); 40 | 41 | s32 state_game_over(Ptr _obj, const Str _name, s32 _elapsedTime, u32 _lparam, u32 _wparam, Ptr _extra); 42 | 43 | #endif /* __STATE_H__ */ 44 | -------------------------------------------------------------------------------- /imgs/age1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/ascii_game_engine/05c1961b7a3cea5e46909cb5de2012cf0949abc3/imgs/age1.png -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/ascii_game_engine/05c1961b7a3cea5e46909cb5de2012cf0949abc3/logo.png --------------------------------------------------------------------------------