-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSdlChipDisplay.cpp
43 lines (31 loc) · 1.02 KB
/
SdlChipDisplay.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// Created by vincenzo on 05/10/22.
//
#include "SdlChipDisplay.h"
bool SdlChipDisplay::readPixel(int x, int y)const {
return frameBuff[y*width + x]==pixelColor;
}
void SdlChipDisplay::writePixel(int x, int y, bool value) {
if(value){
frameBuff[y*width + x]=pixelColor;
}else{
frameBuff[y*width + x]=backgroundColor;
}
}
void SdlChipDisplay::reset() {
std::fill(frameBuff,frameBuff+(width*height),backgroundColor);
notifySpriteDrawn();
}
SdlChipDisplay::~SdlChipDisplay() {
delete frameBuff;
}
SdlChipDisplay::SdlChipDisplay(DisplayTextureHandler* textureHandler,uint32_t backgroundColor, uint32_t pixelColor):
Display(SDL_CHIP_DISPLAY_WIDTH,SDL_CHIP_DISPLAY_HEIGHT),backgroundColor(backgroundColor),
pixelColor(pixelColor),textureHandler(textureHandler){
frameBuff=new uint32_t[width*height];
std::fill(frameBuff,frameBuff+(width*height),backgroundColor);
}
void SdlChipDisplay::notifySpriteDrawn() {
if(textureHandler)
textureHandler->updateTexture(frameBuff);
}