-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from asm128/master
+ Added wakawaka.
- Loading branch information
Showing
11 changed files
with
1,208 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,270 @@ | ||
#include "application.h" | ||
#include "gpk_bitmap_file.h" | ||
#include "gpk_grid_copy.h" | ||
#include "gpk_label.h" | ||
#include "gpk_view_layered.h" | ||
#include "gpk_png.h" | ||
|
||
//#define GPK_AVOID_LOCAL_APPLICATION_MODULE_MODEL_EXECUTABLE_RUNTIME | ||
#include "gpk_app_impl.h" | ||
|
||
GPK_DEFINE_APPLICATION_ENTRY_POINT(::gme::SApplication, "Module Explorer"); | ||
|
||
::gpk::error_t optionListInitialize (::gpk::SGUI& gui, ::gme::SOptionList& menu) { | ||
gpk_necall(menu.IdControl = ::gpk::controlCreate(gui), "Failed to create menu control!"); | ||
return 0; | ||
} | ||
|
||
::gpk::error_t gme::optionListPush (::gpk::SGUI& gui, ::gme::SOptionList& menu, const ::gpk::view_const_string& text) { | ||
if(menu.IdControl == -1) | ||
gpk_necall(::optionListInitialize(gui, menu), ""); | ||
const int32_t idControl = ::gpk::controlCreate(gui); | ||
gpk_necall(idControl, "Failed to create control! Out of memory?"); | ||
::gpk::controlSetParent(gui, idControl, menu.IdControl); | ||
::gpk::SControl & control = gui.Controls.Controls [idControl]; | ||
::gpk::SControlText & controlText = gui.Controls.Text [idControl]; | ||
::gpk::SControlConstraints & controlConstraints = gui.Controls.Constraints [idControl]; | ||
control .Margin = {4, 4, 4, 4}; | ||
controlText .Text = {text.begin(), text.size()}; | ||
controlText .Align = ::gpk::ALIGN_CENTER_LEFT; | ||
controlConstraints .AttachSizeToText = {true, true}; | ||
switch(menu.Orientation) { | ||
case ::gme::MENU_ORIENTATION_HORIZONTAL : controlConstraints.AttachSizeToControl.y = menu.IdControl; if(menu.IdControls.size()) controlConstraints.DockToControl.Right = menu.IdControls[menu.IdControls.size() - 1]; break; | ||
case ::gme::MENU_ORIENTATION_VERTICAL : controlConstraints.AttachSizeToControl.x = menu.IdControl; if(menu.IdControls.size()) controlConstraints.DockToControl.Bottom = menu.IdControls[menu.IdControls.size() - 1]; break; | ||
} | ||
return menu.IdControls.push_back(idControl); | ||
} | ||
|
||
enum ANIMATION | ||
{ ANIMATION_GHOST = 0 | ||
, ANIMATION_EYES | ||
, ANIMATION_PLAYER | ||
, FRIGHTENED_FACE | ||
, TEXTURE_PAC_MAP | ||
, TEXTURE_PELLET | ||
, TEXTURE_ENERGYZER | ||
, TEXTURE_FRUIT_0 | ||
, ANIMATION_COUNT | ||
}; | ||
|
||
struct SSprite { | ||
uint8_t Frames ; | ||
char Name [15]; | ||
}; | ||
|
||
::gpk::error_t cleanup (::gme::SApplication & app) { return ::gpk::mainWindowDestroy(app.Framework.MainDisplay); } | ||
::gpk::error_t setup (::gme::SApplication & app) { | ||
::gpk::SFramework & framework = app.Framework; | ||
::gpk::SDisplay & mainWindow = framework.MainDisplay; | ||
ree_if(0 == framework.Input.create(), "Out of memory?"); | ||
error_if(errored(::gpk::mainWindowCreate(mainWindow, framework.RuntimeValues.PlatformDetail, framework.Input)), "Failed to create main window why?????!?!?!?!?"); | ||
::gpk::SImage<ubyte_t> tileMap; | ||
SSprite spriteNames[ANIMATION_COUNT]; | ||
{ | ||
FILE * fp = 0; | ||
fopen_s(&fp, "pacman.txt", "rb"); | ||
if(fp) { | ||
fseek(fp, 0, SEEK_END); | ||
int32_t fileSize = ftell(fp); | ||
fseek(fp, 0, SEEK_SET); | ||
::gpk::array_pod<ubyte_t> mapFile; | ||
mapFile.resize(fileSize); | ||
fread(mapFile.begin(), 1, fileSize, fp); | ||
fclose(fp); | ||
tileMap.resize({AXIS_X, AXIS_Y}, ' '); | ||
for(uint32_t y = 0; y < tileMap.metrics().y; ++y) { | ||
memcpy(tileMap[y].begin(), &mapFile[y * (tileMap.metrics().x + 2)], tileMap.metrics().x); | ||
} | ||
} | ||
} | ||
{ | ||
FILE * fp = 0; | ||
fopen_s(&fp, "pacman.bin", "rb"); | ||
if(fp) { | ||
fseek(fp, 0, SEEK_END); | ||
int32_t fileSize = ftell(fp); | ||
fseek(fp, 0, SEEK_SET); | ||
::gpk::array_pod<ubyte_t> mapFile; | ||
mapFile.resize(fileSize); | ||
fread(mapFile.begin(), 1, fileSize, fp); | ||
fclose(fp); | ||
for(uint32_t y = 0; y < 8; ++y) { | ||
memcpy(&spriteNames[y], &mapFile[y * sizeof(SSprite)], sizeof(SSprite)); | ||
} | ||
} | ||
} | ||
|
||
::wak::setup(app.GameInstance, tileMap); | ||
app.GameInstance.Map.posToDraw.x = (app.Framework.MainDisplay.Size.x / 2) - (app.GameInstance.Map.Size.x / 2); | ||
app.GameInstance.Map.posToDraw.y = app.Framework.MainDisplay.Size.y / 4; | ||
|
||
//uint32_t myTextureCount = ::gpk::size(textureNames); | ||
//app.TexturesTest.resize(myTextureCount); | ||
// | ||
//for(uint32_t iTexture = 0; iTexture < myTextureCount; ++iTexture) { | ||
// ::gpk::SImage<::gpk::SColorBGRA> & textureLoaded = app.TexturesTest[iTexture]; | ||
// ::gpk::bmpFileLoad(textureNames[iTexture], textureLoaded); | ||
//} | ||
|
||
app.CharacterAnimationImages.resize(ANIMATION_COUNT); | ||
app.CharacterAnimationLayers.resize(ANIMATION_COUNT); | ||
uint32_t frameCoutn[ANIMATION_COUNT] = {2, 4, 4, 1, 1, 1, 1, 1}; | ||
for(uint32_t iAnimation = 0; iAnimation < app.CharacterAnimationImages.size(); ++iAnimation) | ||
::gpk::pngFileLoad(spriteNames[iAnimation].Name, app.CharacterAnimationImages[iAnimation]); | ||
|
||
for(uint32_t iAnimation = 0; iAnimation < app.CharacterAnimationImages.size(); ++iAnimation) | ||
// --- Build Ghost animation layered views | ||
app.CharacterAnimationLayers[iAnimation] = | ||
{ app.CharacterAnimationImages[iAnimation].Texels.begin() | ||
, app.CharacterAnimationImages[iAnimation].View.metrics().x | ||
, app.CharacterAnimationImages[iAnimation].View.metrics().y / spriteNames[iAnimation].Frames | ||
, spriteNames[iAnimation].Frames | ||
}; | ||
|
||
return 0; | ||
} | ||
|
||
::gpk::error_t drawAnimated | ||
(::gme::SApplication & app | ||
, const ::gpk::SCoord2<int32_t> & posToDraw | ||
, const ::wak::SAnimatedObject & animated | ||
, ::gpk::view_grid<::gpk::SColorBGRA> & target | ||
, ::wak::MODE mode | ||
, ::gpk::view_array<::gpk::view_layered<::gpk::SColorBGRA>> animations | ||
, int32_t iGhost | ||
) | ||
{ | ||
static constexpr const ::gpk::SColorBGRA magenta = { 0xFF, 0x00, 0xFF, 0xFF }; | ||
const ::gpk::SColorBGRA ghostColors [4] = | ||
{ {0x00, 0x00, 0xFF, 0xFF} | ||
, {0xFF, 0x00, 0xFF, 0xFF} | ||
, {0xFF, 0xFF, 0x00, 0xFF} | ||
, ::gpk::ORANGE | ||
}; | ||
|
||
if (mode == ::wak::MODE_ESCAPE) { | ||
const bool swapColors = (app.GameInstance.CounterFrightened > 4 && (app.GameInstance.CounterAnimation / 2 % 2)); | ||
::gpk::SColorBGRA colorFrightened = swapColors ? ::gpk::SColorBGRA{0xFF, 0xFF, 0xFF, 0xFF} : ::gpk::SColorBGRA{0xFF, 0, 0, 0xFF}; | ||
::gpk::SColorBGRA colorFrightenedFace = swapColors ? ::gpk::SColorBGRA{0, 0, 0xFF, 0xFF} : ::gpk::SColorBGRA{0xFF, 0xFF, 0xFF, 0xFF}; | ||
::gpk::grid_copy_alpha(target, animations[ANIMATION_GHOST][app.GameInstance.CounterAnimation % 2] , posToDraw, magenta, colorFrightened); | ||
::gpk::grid_copy_alpha(target, animations[FRIGHTENED_FACE][0] , posToDraw, magenta, colorFrightenedFace); | ||
|
||
} | ||
else if(app.GameInstance.Enemies[iGhost].Dead == true) | ||
::gpk::grid_copy_alpha(target, animations[ANIMATION_EYES][animated.CurrentDirection], posToDraw, magenta); | ||
else { | ||
::gpk::grid_copy_alpha(target, animations[ANIMATION_GHOST][app.GameInstance.CounterAnimation % 2], posToDraw, magenta, ghostColors[iGhost]); | ||
::gpk::grid_copy_alpha(target, animations[ANIMATION_EYES][animated.CurrentDirection], posToDraw, magenta); | ||
} | ||
return 0; | ||
} | ||
|
||
::gpk::SCoord2<int32_t> getPosToDraw (const ::wak::SAnimatedObject & animated, const ::gpk::SCoord2<int32_t> & mapPosition) { | ||
return { (int32_t)(mapPosition.x + ((animated.Position.x + animated.PositionDeltas.x) * 10) - 8) | ||
, (int32_t)(mapPosition.y + ((animated.Position.y + animated.PositionDeltas.y) * 10) - 8) | ||
}; | ||
} | ||
|
||
::gpk::error_t draw (::gme::SApplication & app) { | ||
::gpk::STimer timer; | ||
app; | ||
::gpk::ptr_obj<::gpk::SRenderTarget<::gpk::SColorBGRA, uint32_t>> target; | ||
target.create(); | ||
target->Color .resize(app.Framework.MainDisplay.Size); | ||
target->DepthStencil.resize(target->Color.View.metrics()); | ||
|
||
static constexpr const ::gpk::SColorBGRA magenta = { 0xFF, 0x00, 0xFF, 0xFF }; | ||
|
||
for(uint32_t iAnim = 0; iAnim < TEXTURE_PAC_MAP; ++iAnim) | ||
::gpk::grid_copy_alpha (target->Color.View, app.CharacterAnimationImages[iAnim].View, ::gpk::SCoord2<int32_t>{0, 128 + 128 * (int32_t)iAnim}, magenta); | ||
|
||
{ | ||
::gme::mutex_guard lock (app.LockGame); | ||
::gpk::SCoord2<int32_t> & mapPosition = app.GameInstance.Map.posToDraw; | ||
::gpk::view_array<::wak::SEnemy> & enemies = app.GameInstance.Enemies; | ||
|
||
::gpk::SCoord2<int32_t> playerPosToDraw = { (int32_t)(mapPosition.x + ((app.GameInstance.Player.Position.x + app.GameInstance.Player.PositionDeltas.x) * 10 - 8)) , | ||
(int32_t)(mapPosition.y + ((app.GameInstance.Player.Position.y + app.GameInstance.Player.PositionDeltas.y) * 10 - 8)) }; | ||
|
||
::gpk::SCoord2<int32_t> posToDraw[::wak::GHOST_COUNT] = {}; | ||
|
||
for (uint32_t iGhost = 0; iGhost < ::wak::GHOST_COUNT; ++iGhost) { | ||
posToDraw[iGhost] = getPosToDraw(enemies[iGhost], mapPosition); | ||
} | ||
|
||
//--- Dibujar sobrne el target | ||
::gpk::grid_copy_alpha(target->Color.View, app.CharacterAnimationLayers[TEXTURE_PAC_MAP][0], mapPosition, magenta); | ||
|
||
for (int32_t y = 0; y < app.GameInstance.Map.Size.y; ++y) { | ||
for (int32_t x = 0; x < app.GameInstance.Map.Size.x; ++x) { | ||
::gpk::SCoord2<int32_t> pointToDraw = { mapPosition.x + (x * 10) , mapPosition.y + (y * 10) }; | ||
if (app.GameInstance.Map.TilesMap[y][x] == TILE_PELLET) | ||
::gpk::grid_copy_alpha(target->Color.View, app.CharacterAnimationLayers[TEXTURE_PELLET][0], pointToDraw, magenta); | ||
else if (app.GameInstance.Map.TilesMap[y][x] == TILE_ENERGYZER && (app.GameInstance.CounterAnimation / 3) % 2) | ||
::gpk::grid_copy_alpha(target->Color.View, app.CharacterAnimationLayers[TEXTURE_ENERGYZER][0], pointToDraw, magenta); | ||
} | ||
} | ||
if (app.GameInstance.Map.TilesMap[20][15] == TILE_FRUIT) { | ||
::gpk::SCoord2<int32_t> pointToDraw = { mapPosition.x + (15 * 10 -5) , mapPosition.y + (20 * 10) }; | ||
::gpk::grid_copy_alpha(target->Color.View, app.CharacterAnimationLayers[TEXTURE_FRUIT_0][0], pointToDraw, magenta); | ||
} | ||
|
||
if (app.GameInstance.Player.Position.x > 0 && app.GameInstance.Player.Position.x < 29) | ||
::gpk::grid_copy_alpha(target->Color.View, app.CharacterAnimationLayers[ANIMATION_PLAYER][app.GameInstance.CounterAnimationPlayer % 4], playerPosToDraw, magenta, ::gpk::SColorBGRA{0x00, 0xFF, 0xFF, 0xFF}); | ||
|
||
for (uint32_t iGhost = 0; iGhost < ::wak::GHOST_COUNT; ++iGhost) | ||
if (enemies[iGhost].Position.x > 0 && enemies[iGhost].Position.x < 29) | ||
drawAnimated(app, posToDraw[iGhost], enemies[iGhost], target->Color.View, enemies[iGhost].CurrentMode, app.CharacterAnimationLayers, iGhost); | ||
} | ||
|
||
{ | ||
::gme::mutex_guard lock (app.LockGUI); | ||
::gpk::guiDraw(app.Framework.GUI, target->Color.View); | ||
} | ||
{ | ||
::gme::mutex_guard lock (app.LockRender); | ||
app.Offscreen = target; | ||
} | ||
//timer.Frame(); | ||
//info_printf("Draw time: %f.", (float)timer.LastTimeSeconds); | ||
return 0; | ||
} | ||
|
||
::gpk::error_t update (::gme::SApplication & app, bool exitSignal) { | ||
::gpk::STimer timer; | ||
retval_info_if(::gpk::APPLICATION_STATE_EXIT, exitSignal, "Exit requested by runtime."); | ||
{ | ||
::gme::mutex_guard lock (app.LockRender); | ||
app.Framework.MainDisplayOffscreen = app.Offscreen; | ||
} | ||
::gpk::SFramework & framework = app.Framework; | ||
retval_info_if(::gpk::APPLICATION_STATE_EXIT, ::gpk::APPLICATION_STATE_EXIT == ::gpk::updateFramework(app.Framework), "Exit requested by framework update."); | ||
|
||
::gpk::SGUI & gui = framework.GUI; | ||
{ | ||
::gme::mutex_guard lock (app.LockGUI); | ||
::gpk::guiProcessInput(gui, *app.Framework.Input); | ||
} | ||
if(app.Framework.Input->MouseCurrent.Deltas.z) { | ||
gui.Zoom.ZoomLevel += app.Framework.Input->MouseCurrent.Deltas.z * (1.0 / (120 * 4)); | ||
::gpk::guiUpdateMetrics(gui, framework.MainDisplay.Size, true); | ||
} | ||
|
||
for(uint32_t iControl = 0, countControls = gui.Controls.Controls.size(); iControl < countControls; ++iControl) { | ||
const ::gpk::SControlState & controlState = gui.Controls.States[iControl]; | ||
if(controlState.Unused || controlState.Disabled) | ||
continue; | ||
if(controlState.Execute) { | ||
info_printf("Executed %u.", iControl); | ||
if(iControl == (uint32_t)app.IdExit) | ||
return ::gpk::APPLICATION_STATE_EXIT; | ||
} | ||
} | ||
{ | ||
::gme::mutex_guard lock (app.LockGame); | ||
::wak::update(app.GameInstance, (float)framework.FrameInfo.Seconds.LastFrame); | ||
} | ||
//timer.Frame(); | ||
//info_printf("Update time: %f.", (float)timer.LastTimeSeconds); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "gpk_framework.h" | ||
#include "gpk_gui.h" | ||
#include "gpk_view_layered.h" | ||
|
||
#include "wakawaka.h" | ||
|
||
#include <mutex> | ||
|
||
#ifndef APPLICATION_H_2078934982734 | ||
#define APPLICATION_H_2078934982734 | ||
|
||
namespace gme // I'm gonna use a different namespace in order to test a few things about the macros. | ||
{ | ||
#pragma pack(push, 1) | ||
enum MENU_ORIENTATION : int32_t | ||
{ MENU_ORIENTATION_HORIZONTAL = 1 | ||
, MENU_ORIENTATION_VERTICAL = 2 | ||
}; | ||
|
||
struct SOptionList { | ||
int32_t IdControl = -1; | ||
MENU_ORIENTATION Orientation = ::gme::MENU_ORIENTATION_HORIZONTAL; | ||
::gpk::array_pod<int32_t> IdControls = {}; | ||
}; | ||
|
||
::gpk::error_t optionListPush (::gpk::SGUI& gui, ::gme::SOptionList& menu, const ::gpk::view_const_string& text); | ||
#pragma pack(pop) | ||
|
||
struct SApplication { | ||
::gpk::SFramework Framework; | ||
::gpk::ptr_obj<::gpk::SRenderTarget<::gpk::SColorBGRA, uint32_t>> Offscreen = {}; | ||
|
||
int32_t IdExit = -1; | ||
::gme::SOptionList OptionListMain = {}; | ||
::gme::SOptionList OptionListFile = {}; | ||
|
||
::std::mutex LockGUI; | ||
::std::mutex LockRender; | ||
::std::mutex LockGame; | ||
::std::mutex LockDraw; | ||
::wak::SGame GameInstance; | ||
|
||
|
||
::gpk::array_obj<::gpk::SImage<::gpk::SColorBGRA>> TexturesTest; | ||
|
||
::gpk::array_obj<::gpk::SImage<::gpk::SColorBGRA>> CharacterAnimationImages; | ||
::gpk::array_obj<::gpk::view_layered<::gpk::SColorBGRA>> CharacterAnimationLayers; | ||
|
||
|
||
SApplication (::gpk::SRuntimeValues & runtimeValues) : Framework(runtimeValues) {} | ||
}; | ||
|
||
typedef ::std::lock_guard<::std::mutex> mutex_guard; | ||
|
||
} // namespace | ||
|
||
#endif // APPLICATION_H_2078934982734 |
Oops, something went wrong.