Skip to content

Commit

Permalink
Merge pull request #1 from asm128/master
Browse files Browse the repository at this point in the history
+ Added wakawaka.
  • Loading branch information
Gorbylord authored Jul 17, 2018
2 parents e3ee576 + 180b410 commit d5fea2d
Show file tree
Hide file tree
Showing 11 changed files with 1,208 additions and 1 deletion.
16 changes: 16 additions & 0 deletions gpk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_gpk_encoding", "test_g
{8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_wakawaka", "test_wakawaka\test_wakawaka.vcxproj", "{F4959D31-862B-472D-B92E-B395ACAB2150}"
ProjectSection(ProjectDependencies) = postProject
{080A3A4C-284A-4A84-A71C-D08397D394FD} = {080A3A4C-284A-4A84-A71C-D08397D394FD}
{830AB681-B788-47D4-9767-BA4E0792F682} = {830AB681-B788-47D4-9767-BA4E0792F682}
{39953D8D-A830-46BD-917E-1A96C8BDADC6} = {39953D8D-A830-46BD-917E-1A96C8BDADC6}
{8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -132,6 +140,14 @@ Global
{B1821EF9-9723-4760-9105-60B7C11BB017}.Release|x64.Build.0 = Release|x64
{B1821EF9-9723-4760-9105-60B7C11BB017}.Release|x86.ActiveCfg = Release|Win32
{B1821EF9-9723-4760-9105-60B7C11BB017}.Release|x86.Build.0 = Release|Win32
{F4959D31-862B-472D-B92E-B395ACAB2150}.Debug|x64.ActiveCfg = Debug|x64
{F4959D31-862B-472D-B92E-B395ACAB2150}.Debug|x64.Build.0 = Debug|x64
{F4959D31-862B-472D-B92E-B395ACAB2150}.Debug|x86.ActiveCfg = Debug|Win32
{F4959D31-862B-472D-B92E-B395ACAB2150}.Debug|x86.Build.0 = Debug|Win32
{F4959D31-862B-472D-B92E-B395ACAB2150}.Release|x64.ActiveCfg = Release|x64
{F4959D31-862B-472D-B92E-B395ACAB2150}.Release|x64.Build.0 = Release|x64
{F4959D31-862B-472D-B92E-B395ACAB2150}.Release|x86.ActiveCfg = Release|Win32
{F4959D31-862B-472D-B92E-B395ACAB2150}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion gpk/gpk_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace gpk


inline ::gpk::view_array<_tTexel> operator[] (uint32_t index) { return View[index]; }
inline const ::gpk::view_array<_tTexel> operator[] (uint32_t index) const { return View[index]; }
inline const ::gpk::view_array<const _tTexel> operator[] (uint32_t index) const { return View[index]; }

inline constexpr const ::gpk::SCoord2<uint32_t>& metrics () const noexcept { return View.metrics(); }
inline ::gpk::error_t resize (const ::gpk::SCoord2<uint32_t>& newSize) noexcept { return resize(newSize.x, newSize.y); }
Expand Down
270 changes: 270 additions & 0 deletions test_wakawaka/application.cpp
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;
}
57 changes: 57 additions & 0 deletions test_wakawaka/application.h
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
Loading

0 comments on commit d5fea2d

Please sign in to comment.