Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _TILE_HPP
- #define _TILE_HPP
- #include <globals.hpp>
- union Tile {
- kit::u16 value;
- struct {
- kit::u16 id : 7; //id of what tile to use
- kit::u16 tileset : 1; //whether to use tileset a or b
- kit::u16 collide_a : 1; //'collide with top-left 12x12 section of tile?'
- kit::u16 collide_b : 1; //'collide with top-right 12x12 section of tile?'
- kit::u16 collide_c : 1; //'collide with bottom-left 12x12 section of tile?'
- kit::u16 collide_d : 1; //'collide with bottom-right 12x12 section of tile?'
- kit::u16 platform : 1; //allow falling through top side of tile conditionally
- kit::u16 pass : 1; //allow passing through tile (overrides collision)
- //(pass is always 0 inside the scene descriptor)
- kit::u16 _unused : 2;
- };
- Tile( ) : value( 0) {}
- Tile(kit::u8 _lobyte) : value(0x0f00|_lobyte) {} //assumes full collision
- Tile(kit::u16 _value) : value( _value) {}
- Tile(kit::s32 _value) : value(0xffff& _value) {}
- };
- struct Object;
- //uncompressed scene data
- #define OBJ_RESET_VALUE 3 //# of deaths until the scene objects reset
- #define PATTERN_LEN (TILESIZ_X*TILESIZ_Y)
- struct Scene { //2352B
- kit::Bitmap* bmp_bg = nullptr; //bitmap for background layer (references gl_backgrounds)
- Tile pat_mg[PATTERN_LEN]; //pattern for midground (collision) layer
- Tile pat_fg[PATTERN_LEN]; //pattern for foreground layer
- //(reallocate only if new scene objects len > objs_lenmax!)
- Object* objs = nullptr; //pointer to associated object array (memory::alloc'd)
- kit::u16 objs_len = 0;
- kit::u16 objs_lenmax = 0;
- //associated edges can be manipulated by game states
- kit::u16 edge_n; //scene id for north edge
- kit::u16 edge_s; //scene id for south edge
- kit::u16 edge_w; //scene id for west edge
- kit::u16 edge_e; //scene id for east edge
- kit::u16 scene; //scene id for scene itself
- kit::u16 music = 0; //music id; 0 for no change, -1 (65535) to stop
- kit::u16 ambience_a = 0; //ambient track id a; 0 for no change, -1 to stop
- kit::u16 ambience_b = 0; //ambient track id b; 0 for no change, -1 to stop
- kit::u16 tileset_a = 0; //1st associated tileset
- kit::u16 tileset_b = 0; //2nd associated tileset
- kit::u8 obj_reset = 0; //used to reset object (including npc) properties between deaths
- bool repeat_bg = false; //'should bg repeat?' (stretches to screen otherwise)
- char _padding8[6];
- void drawBg();
- void drawTiles(bool drawForeground = false); //draws midground if false
- };
- //for storing the contents of a .ksd file (compressed scene data)
- #define KSD_MAGIC 0x4644536B //"kSDF"
- #define SD_FILELEN(_scene_desc) ((_scene_desc).dataSize+sizeof(SceneDescriptor))
- struct SceneDescriptor { //64B
- /*0x00*/ kit::u32 magic; //= 0x4644536B = "kSDF" (no null terminator)
- /*0x04*/ kit::u32 dataSize; //size of file in bytes, minus the header (which is always 64B)
- //offsets to array data in file (if nullptr, data is assumed to not be present!)
- //(also, objs[x].type refers to the index inside gl_objCallbacks used by the object.
- //each element of gl_objCallbacks is of type Object_TickCallback)
- /*0x08*/ Object* objs; //contains the original states of each object in the scene
- /*0x10*/ Tile* pat_mg; //pattern data is compressed using RLE, where the 1st element's .value
- /*0x18*/ Tile* pat_fg; //member is the run length, with the 2nd being the actual tile data
- struct {
- /*0x20*/ kit::u16 bmp_bg : 15; //associated background id
- /*0x21*/ kit::u16 repeat_bg : 1; //'should bg repeat?' (stretches to screen otherwise)
- };
- struct {
- /*0x22*/ kit::u16 objs_len : 15; //number of objects in scene
- /*0x23*/ kit::u16 visited : 1; //used to help determine if objects should reset on load
- };
- /*0x24*/ kit::u16 tileset_a; //1st associated tileset
- /*0x26*/ kit::u16 tileset_b; //2nd associated tileset
- /*0x28*/ kit::u16 edge_n; //scene id for north edge
- /*0x2A*/ kit::u16 edge_s; //scene id for south edge
- /*0x2C*/ kit::u16 edge_w; //scene id for west edge
- /*0x2E*/ kit::u16 edge_e; //scene id for east edge
- /*0x30*/ kit::u16 scene; //scene id for scene itself
- /*0x32*/ kit::u16 music; //music id; 0 for no change, -1 (65535) to stop
- /*0x34*/ kit::u16 ambience_a; //ambient track id a; 0 for no change, -1 to stop
- /*0x36*/ kit::u16 ambience_b; //ambient track id b; 0 for no change, -1 to stop
- /*0x38*/ kit::BinaryData* fileData = nullptr; //raw file data; appears as nullptr in file
- /*0x40*/ //... (array data is stored in order of: objs, pat_mg, and pat_fg)
- void unload();
- ~SceneDescriptor(){ unload(); }
- SceneDescriptor(){ kit::memory::set(this, 0, sizeof(SceneDescriptor)); }
- SceneDescriptor(kit::u16 scene_id);
- };
- #ifdef _DEBUG
- #include <stdio.h>
- #define printSceneDescHeader(_scene_id) _printSceneDescHeader(_scene_id)
- static inline void _printSceneDescHeader(kit::u16 scene_id){
- if(scene_id > gl_scenes_len) throw "scene_id out of range";
- SceneDescriptor* scene = gl_scenes[scene_id];
- printf("{\n");
- printf(" magic = \"%.4s\" (0x%08X)\n", (char*)&scene->magic, scene->magic);
- printf(" dataSize = %u\n", scene->dataSize);
- printf(" objs = %p\n", scene->objs);
- printf(" pat_mg = %p\n", scene->pat_mg);
- printf(" pat_fg = %p\n", scene->pat_fg);
- printf(" bmp_bg = %u\n", scene->bmp_bg);
- printf(" repeat_bg = %s\n", boolStr(scene->repeat_bg));
- printf(" objs_len = %u\n", scene->objs_len);
- printf(" visited = %s\n", boolStr(scene->visited));
- printf(" tileset_a = %u\n", scene->tileset_a);
- printf(" tileset_b = %u\n", scene->tileset_b);
- printf(" edge_n = %u\n", scene->edge_n);
- printf(" edge_s = %u\n", scene->edge_s);
- printf(" edge_w = %u\n", scene->edge_w);
- printf(" edge_e = %u\n", scene->edge_e);
- printf(" scene = %u\n", scene->scene);
- printf(" music = %u\n", scene->music);
- printf(" ambience_a = %u\n", scene->ambience_a);
- printf(" ambience_b = %u\n", scene->ambience_b);
- printf(" fileData = %p\n", scene->fileData);
- printf("}\n");
- }
- #else
- #define printSceneDescHeader(_scene_id)
- #endif /* _DEBUG */
- //scene_id references gl_scenes, whose elements are of type SceneDescriptor*
- void loadScene(kit::u16 scene_id, bool loadObjects = true, bool loadRest = true);
- #endif /* _TILE_HPP */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement