Implement SMX PGEX

master
sigonasr2 1 year ago
parent 5979eddc21
commit 12ec38ae96
  1. 56
      sample/PGEX_SMX.h
  2. 29
      sample/SMXSample.cpp
  3. 1
      sample/SMXSample.vcxproj
  4. 3
      sample/SMXSample.vcxproj.filters

@ -0,0 +1,56 @@
#pragma once
#include "olcPixelGameEngine.h"
#include "SMX.h"
using namespace olc;
class PGEX_SMX : public PGEX{
public:
PGEX_SMX():PGEX(true){};
//SMX "screen" is 12x21
//Each panel is 4x7
static void SMXStateChangedCallback(int pad, SMXUpdateCallbackReason reason, void *pUser)
{
PGEX_SMX *pSelf = (PGEX_SMX*) pUser;
pSelf->SMXStateChanged( pad, reason );
}
static void SMXLogCallback(const char *log)
{
printf("-> %s\n", log);
}
void SMXStateChanged(int pad, SMXUpdateCallbackReason reason)
{
printf("Device %i state changed: %04x\n", pad, SMX_GetInputState(pad));
}
virtual void OnAfterUserCreate()override{
SMX_Start( SMXStateChangedCallback, this );
};
virtual void OnAfterUserUpdate(float fElapsedTime)override{
std::string lightData;
for (int pad=0;pad<2;pad++){
for(int i=0;i<9;i++){
int row=0;
for(int y=i/3*7;y<i/3*7+7;y++){
int col=0;
for(int x=i%3*4;x<i%3*4+4;x++){
if(row%2&&col%4==0)continue;
Pixel p(pge->GetDrawTarget()->GetPixel(x,y));
lightData.append(1,p.r);
lightData.append(1,p.g);
lightData.append(1,p.b);
col++;
}
row++;
}
}
}
SMX_SetLights2( lightData.data(), lightData.size() );
}
};

@ -1,37 +1,24 @@
#include "SMX.h"
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
#include "PGEX_SMX.h"
using namespace olc;
class SMX_PGE : public olc::PixelGameEngine
{
PGEX_SMX smx;
public:
SMX_PGE()
{
sAppName = "Example";
}
static void SMXStateChangedCallback(int pad, SMXUpdateCallbackReason reason, void *pUser)
{
SMX_PGE *pSelf = (SMX_PGE*) pUser;
pSelf->SMXStateChanged( pad, reason );
}
static void SMXLogCallback(const char *log)
{
printf("-> %s\n", log);
}
void SMXStateChanged(int pad, SMXUpdateCallbackReason reason)
{
printf("Device %i state changed: %04x\n", pad, SMX_GetInputState(pad));
sAppName = "SMX PGE";
}
public:
bool OnUserCreate() override
{
SMX_Start( SMXStateChangedCallback, this );
SetPixelMode([](const int x,const int y,const Pixel&col,const Pixel&prev){
return col;
});
// Called once at the start, so create things here
return true;
}
@ -50,7 +37,7 @@ public:
int main()
{
SMX_PGE demo;
if (demo.Construct(256, 240, 4, 4))
if (demo.Construct(12, 21, 50, 50))
demo.Start();
return 0;

@ -101,6 +101,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="olcPixelGameEngine.h" />
<ClInclude Include="PGEX_SMX.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

@ -18,5 +18,8 @@
<ClInclude Include="olcPixelGameEngine.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PGEX_SMX.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
Loading…
Cancel
Save