|
Post by 0x8bitdev on Sept 11, 2022 8:56:42 GMT
hyperfighting , when packing/optimizing data the main thing is not to create problems for yourself. Look at the following two cases. 1. BAD!After some calculations you found that you have MAX 100 entities in your game map and you need to chache them. All that entities will be animated and you decided to store animation data for all 100 entities (num_frames, curr_frame, loop_frame etc... in total +6 bytes per entity). But also you know that the MAX visible animated entities on the screen is 5 (!) Something wrong here 100 vs 5. Isn't it? 2. GOODAfter some calculations you found that you have MAX 100 entities in your game map. All that entities will be animated and you need to chache them. Also you know that MAX visible animated entities on the screen is 5 and you decided to make an animations cache for that 5 animated entities. Animation data can be easily separated from an entity data. You need 3-bits to point to the animation cache position and a few bits to describe an internal entity state (jump, attack, run etc...). All that data can be combined in one byte. Your animation cache with 5 positions takes up 6x5=30 bytes. Nothing bad will happen if you leave it as is to simplify and speed up data access and calculations. -------------------------------------------------------- Regarding your code above. Look at the following two cases: You have 10 bytes of data: 8-bytes of binary states and two bytes of values 0x00 - 0x0F. And you want to pack them to minimize memory usage. 1. BAD!You combine two value bytes into one byte and the rest binary state bytes into another byte: #define DEF_OBJ_STATE0 0x01 #define DEF_OBJ_STATE1 0x02 #define DEF_OBJ_STATE2 0x04 ... #define DEF_OBJ_STATE7 0x80
#define DEF_OBJ_VAL1_MASK 0x0F #define DEF_OBJ_VAL2_MASK 0xF0
... // SET val1 byte1_packed_vals = ( byte1_packed_vals & DEF_OBJ_VAL2_MASK ) | val1;
// SET val2 byte1_packed_vals = ( byte1_packed_vals & DEF_OBJ_VAL1_MASK ) | ( val2 << 4 );
// GET val1 byte1_packed_vals = byte1_packed_vals & DEF_OBJ_VAL1_MASK;
// GET val2 byte1_packed_vals = val2 >> 4; ------------------------------
// SET state bits byte2_packed_vals |= DEF_OBJ_STATE<N>;
// RESET byte2_packed_vals &= ~DEF_OBJ_STATE<N>;
// simple check if( byte2_packed_vals & DEF_OBJ_STATE<N> ) { ... }
Getting/setting the val2 require shifting the data every time. 2.GOODYou leave the value bytes 'as is' and add the binary state values to them: #define DEF_OBJ_STATE0 0x10 #define DEF_OBJ_STATE1 0x20 #define DEF_OBJ_STATE2 0x40 #define DEF_OBJ_STATE3 0x80
#define DEF_OBJ_STATE4 0x10 #define DEF_OBJ_STATE5 0x20 #define DEF_OBJ_STATE6 0x40 #define DEF_OBJ_STATE7 0x80
#define DEF_OBJ_VAL_MASK 0x0F #define DEF_OBJ_VAL_INV_MASK 0xF0
... // SET val1 byte1_packed_vals = ( byte1_packed_vals & DEF_OBJ_VAL_INV_MASK ) | val1;
// SET val2 byte2_packed_vals = ( byte2_packed_vals & DEF_OBJ_VAL_INV_MASK ) | val2;
// GET val1 byte1_packed_vals = byte1_packed_vals & DEF_OBJ_VAL_MASK;
// GET val2 byte2_packed_vals = byte2_packed_vals & DEF_OBJ_VAL_MASK; ------------------------------
Accessing the state bits the same as in the previous case. Only simple AND/OR require to acces value data and it's faster than using the data shifting every time. p.s.: a shift to zero bits makes no sense. ---------------------------------------------- Now draw conclusions. Regarding your last question.... Don't use the shifts for your state flags. Just define them as in the samples above and check using the AND operation. That's it! Don't complicate your code, don't go to extremes.
|
|
|
Post by hyperfighting on Sept 11, 2022 15:18:51 GMT
0x8bitdev - Thanks for getting a BIT more technical. (I know the puns must stop. I can't help myself) This goes above and beyond the scope of the MAPeD and SPReD discussion so thank you for spending the time. You know the path of destruction I was on if you hadn't stepped in! I know this info will be helpful for people such as myself inexperienced with BIT manipulation and access speeds! Also a good insight into effectively caching MAPeD entities so we at least get a parallel here. The first conclusion I am drawing is that each byte that has a max value of 15 can have 4 flags packed in it. 4 BITS for the initial value 0-15. 4 BITS storing 0-1 per flag. BIT shifting to constantly set values will eat data access performance and should be avoided. As I understand my method for setting BIT flags will hold up but I will use BIT space 4-7 leaving 0-3 for the initial 0-15 value using your examples as the blueprint for setting and reading the 0-15 value. Only cache data for entities you will need access to in the now, do not attempt to cache every last entity all at once. I will refer to your GOOD methods throughout the refactoring and caching process. Man I've got some work to do! Thanks again! [upd] The second conclusion "As I understand my method for setting BIT flags will hold up" no it won't my method is garbage I will adopt the strategy you demonstrate for the way flags are handled. Bottom line avoid shifting.
|
|
|
Post by 0x8bitdev on Sept 16, 2022 20:15:27 GMT
Finally I've done the last MPD/SPD sample project! I hope... So my MPD/SPD mission is almost completed. That is a 'game prototype' demo, which demonstrates use of MAPeD/SPReD data in one project. It is simple implementation of simple game mechanics. Features:
- fully playable game prototype, run'n'jump platformer - 40 screens (10x4) scrollable multi-directional map with 201 entities, +bonus level - inertial player/map movement (map scrolling uses player inertial movement) - sprite/tile objects - entities: collectable, dynamic platform, button, switch, dynamic obstacles, simple dynamic enemies, checkpoint, level exit - hardware collisions (yes in HuC and yes it works stable) - 2-level entities cache, +collisions cache - infinite credits to complete the game! The sample project is 99% written in HuC, except a little ASM trick to speed up entities processing and collectable items counter on HUD. All in-game data I created completely in MAPeD/SPReD. No third party tools were used. I've not commited the project files yet. I'll commit them soon... All the changes as well in the dev build.
Direct link to the 'game_prototype_huc.pce'So... who will pass the bonus level? Have a fun! p.s.: I recommend using a gamepad.
|
|
|
Post by hyperfighting on Sept 17, 2022 18:09:51 GMT
0x8bitdev - Well this is extremely exciting news! Today is a great day! I loaded up my Super System 3 with your game prototype and my game prototype. On my side no surprises everything is running! I have been lax about testing on real hardware but your game prototype gave me the reason I needed! I feel like Dr. Dre and Snoop Dogg because I have been hitting switches not in my 6-4 but in your game prototype. Off the top Latters! Springs! Trap Platforms! Moving Platforms! Collectable Gems! Enemies! Check points, Warp Pads! Switches to unlock treasure/moving paltforms, spikes! (I likely missed something) Man incredible and smooth!!!! (Now all you need is parallax I know give them several inches and all they do is take miles...terrible just terrible) Two things I noticed the jumping reinitializes every time you land on something so every time you land you need your finger off jump (I know you will probably write "game prototype" in all caps lol but I'm just saying that would really round it off if the player could continue to hold jump upon landing) There is a line glitch either 32 or 64 pixels from the top of the screen. Maybe its tearing not sure just thought I would mention it. (not terribly noticeable but noticeable enough to mention) Round Two is a vertical dozy I achieved it! All those years playing Megaman weren't for nothing I guess....I have yet to collect every gem in both stages. It is a marvel and a masterpiece the swirling clouds are so well made same goes for the gems and switches. All assets are great for that matter! Very much enjoyed the presentation! I pushed my one solitary tear back into my eye. Just beautiful!
|
|
|
Post by 0x8bitdev on Sept 19, 2022 9:19:23 GMT
Two things I noticed the jumping reinitializes every time you land on something so every time you land you need your finger off jump (I know you will probably write "game prototype" in all caps lol but I'm just saying that would really round it off if the player could continue to hold jump upon landing) To be honest, I didn't even pay attention to it. Because I'm not in the habit of holding down the jump button if I'm not going to jump. Maybe I'll fix it. There is a line glitch either 32 or 64 pixels from the top of the screen. Maybe its tearing not sure just thought I would mention it. (not terribly noticeable but noticeable enough to mention) Without a screenshot, it's hard to say what you saw. I tested the project in emulators and did not notice such a glitch. Round Two is a vertical dozy I achieved it! All those years playing Megaman weren't for nothing I guess....I have yet to collect every gem in both stages. That's cool! [thumb up] Thanks for collecting all the gems! It is a marvel and a masterpiece the swirling clouds are so well made same goes for the gems and switches. All assets are great for that matter! Very much enjoyed the presentation! I pushed my one solitary tear back into my eye. Just beautiful! Thanks! Don't cry everything will be fine. p.s.: Just in case, it is better to see the source code of the project on GITHUB. The sources in the dev build can quickly become obsolete.
|
|
|
Post by elmer on Sept 19, 2022 13:41:38 GMT
Without a screenshot, it's hard to say what you saw. I tested the project in emulators and did not notice such a glitch. Please remember ... even after 20+ years of emulation, the best current software emulation still isn't a good predictor of how code will run on a real PC Engine, they've primarily been concerned with running existing software. So *if* it runs on a PC Engine, then it *should* run on current emulators (but there are still exceptions). In particular, NO current software emulator (that I know of) accurately models the slowdown and pauses in VRAM transfers that you get from the VDC's round-robbin memory access and sprite-loading during hsync. The current PCEDev branch of mednafen has some fixes put in to start getting that a bit more accurate, but IIRC Dave disabled that in the most-recent build because it was causing other problems. MiSTer (as a hardware emulator) is apparently a lot better at emulating the delays. All of which leads to ... just because you didn't see a glitch in an emulator, doesn't mean that there isn't a glitch on real-hardware, and we're still at the point where things need to be tested on real-hardware to be 100% sure that they work. Sorry, but that's one of the problems of developing for a platform that didn't have much success in the Western hemisphere.
|
|
|
Post by 0x8bitdev on Sept 19, 2022 14:03:47 GMT
elmer, I know that no one emulator can replace real hardware. The problem is that I don't have any real hardware to test with. There are only emulators. So it's hard for me to identify the problem on real hardware using emulators.
|
|
|
Post by hyperfighting on Sept 19, 2022 17:19:13 GMT
0x8bitdev - Here is a video of my hardware test. Sorry my tripod sucks. I stood still in spots it is noticeable. Hopefully you can make it out with YouTubes compression.
|
|
|
Post by 0x8bitdev on Sept 19, 2022 18:31:45 GMT
hyperfighting , I have no ideas at all what that was... No CHR/SG data copying to VRAM...No BAT update... VRAM SAT update only... +palette color update (flashing color) Guys, any ideas? 00:11-00:12 - Ha-ha-ha... Cheater! How did you do that? I managed to do it only once, by accident. The game isn't done yet, but the speedrun is already done. [upd]: I've found a bug with jumps!
|
|
Gaijin D
Punkic Cyborg
Yare yare da ze.
Posts: 137
|
Post by Gaijin D on Sept 20, 2022 1:12:25 GMT
Could this be screen tearing? I understand you get it sometimes when upscaling classic systems, since their framerate is often slightly out of spec, so sometimes you get some minor corruption when there's a mismatch between when the system is putting out a new frame and what your display expects.
|
|
|
Post by dshadoff on Sept 20, 2022 2:11:26 GMT
Looks like mid-frame palette updates. These will delay the change in color (“stretching” a shape to the right) because the palette processor is dealing with CPU updates and isn’t able to fetch the appropriate display color for the new pixel(s).
MiSTer reproduces this (but not Mednafen at this time).
|
|
|
Post by turboxray on Sept 20, 2022 3:14:59 GMT
0x8bitdev - Here is a video of my hardware test. Sorry my tripod sucks. I stood still in spots it is noticeable. Hopefully you can make it out with YouTubes compression. Ohh yeah, that's definitely a VCE artifact. You're not seeing it across the screen for most of it probably because you have large areas of blue. For any VCE register, if you read or write to it - during active display - then you'll get a "pixel stretch". It blocks the VCE from getting the current pixel from the VDC, so the output by the VCE is the last thing it saw on the digital pixel bus. You can see this because the pixel stretching happens beyond the active display window of the VDC, and into the border.
|
|
|
Post by 0x8bitdev on Sept 20, 2022 10:53:35 GMT
dshadoff , turboxray Thanks, guys! You confirmed my assumptions. I woke up at night and thought it was better to put the color update on VBLANK. hyperfighting , Thanks a LOT for testing! I hope I've fixed the "line glitch". I've also fixed the bug with over-jumping. Now you can only exit through the door. Updated .pce file in the dev build or you can get it via the direct link above. Please, test it. Let me know.
|
|
|
Post by hyperfighting on Sept 20, 2022 23:02:02 GMT
0x8bitdev - I want you to envision an old Italian man gazing up at the blue sky and kissing his 5 finger tips as he raises his hand toward the sky and spreads his fingers. The game prototype is exceptional! There were no artifacts to be seen during my play session. I'm sorry I don't have any proper video I've been on the go all day. While I was playing I clipped up through the floor at the point there is the first heavy weight that falls and raises. I think I did it by jumping off the enemy that is just below the weight that falls and raises (can't be sure but I know I did it) The only thing that I suggest is not having jump reinitialize if the player is holding jump. Only jump every time the jump button is pressed. For what its worth...I know this may be your preference so I can't really bug you about it. It's just my 2 cents. Other than that this is truly a masterpiece you cooked up! The speed paired with the scope of traps, obstacles, warp portals, gems etc is wild!
|
|
|
Post by 0x8bitdev on Sept 21, 2022 9:38:07 GMT
hyperfighting Thanks for your feedback! Video is not necessary. While I was playing I clipped up through the floor at the point there is the first heavy weight that falls and raises. I think I did it by jumping off the enemy that is just below the weight that falls and raises (can't be sure but I know I did it) That is a map structure issue. I was just thinking about it yesterday. I use the same bricks tile as solid, which pushes up the player to the surface very fast, and as a decorative one: So once the player touches the bricks by the bottom side, it very fast appears on the surface. The decorative bricks should have no properties - 0 to avoid such behaviour. Like this: I'll fix that. With 4x4 tiles it's easy. The only thing that I suggest is not having jump reinitialize if the player is holding jump. Only jump every time the jump button is pressed. For what its worth...I know this may be your preference so I can't really bug you about it. It's just my 2 cents. You almost talked me into it! Other than that this is truly a masterpiece you cooked up! The speed paired with the scope of traps, obstacles, warp portals, gems etc is wild! If that inspires anyone to make their own games... I would say that my goal has been achieved!
|
|