Skip to content

Commit

Permalink
first attempt at sprites
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenmothersele committed May 7, 2014
1 parent 5ddc0b1 commit fc2775f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 26 deletions.
3 changes: 2 additions & 1 deletion bin/data/code/1.cy
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//rotate
move
rotate
color red
color cyan
box
move
rotate
box
9 changes: 9 additions & 0 deletions bin/data/code/2.cy
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
scale 2
rotate 1,1,0,TIME
shape
vert 0,0
for i: 0 to TWO_PI step 0.1
vert sin(i),cos(i)
end
vert 0,1
end
Binary file not shown.
1 change: 1 addition & 0 deletions src/Cyril/Ops/CyrilImgOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void CyrilImgOp::eval(CyrilState &_s) {
i = _s.stk->top(); _s.stk->pop();
ofScale(0.01, 0.01, 0.01);
if (_s.img->count(i)) {
//cout << "Draw image " << _s.img->at(i) << endl;
_s.img->at(i)->draw(0, 0, 0);
}
// TODO: recurse up the parent tree
Expand Down
67 changes: 42 additions & 25 deletions src/cyrilApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ void cyrilApp::setup(){

// Switch back to external data folder
ofSetDataPathRoot("../../../data/");
// Directory watcher for data folder
codeWatcher.registerAllEvents(this);
std::string folderToWatch = ofToDataPath("code", true);
codeWatcher.addPath(folderToWatch, true, &fileFilter);

ofBackground(0);
pauseProg = false;
Expand Down Expand Up @@ -75,7 +71,15 @@ void cyrilApp::setup(){
_state.parent = NULL;
_state.light = new ofLight();
//_state.light = NULL;



// Directory watcher for data folder
codeWatcher.registerAllEvents(this);
spriteWatcher.registerAllEvents(this);
codeWatcher.addPath(ofToDataPath("code", true), true, &fileFilter);
spriteWatcher.addPath(ofToDataPath("sprites", true), true, &fileFilter);


(*_state.sym)[REG_X_MAX] = 640;
(*_state.sym)[REG_Y_MAX] = 480;
(*_state.sym)[REG_X_MID] = (*_state.sym)[REG_X_MAX] / 2.0;
Expand Down Expand Up @@ -274,13 +278,13 @@ void cyrilApp::toggleLights(void * _o) {
((cyrilApp *)_o)->_state.light->setAttenuation(1.f,0.f,0.f);
}
void cyrilApp::loadFile(void * _o) {
//int whichEditor = ((cyrilApp *)_o)->editor.currentBuffer;
//((cyrilApp *)_o)->editor.loadFile(ofToString(whichEditor)+".txt", whichEditor);
//((cyrilApp *)_o)->editor.update();
int whichEditor = ((cyrilApp *)_o)->editor.currentBuffer;
((cyrilApp *)_o)->editor.loadFile("code/" + ofToString(whichEditor)+".cy", whichEditor);
((cyrilApp *)_o)->editor.update();
}
void cyrilApp::saveFile(void * _o) {
//int whichEditor = ((cyrilApp *)_o)->editor.currentBuffer;
//((cyrilApp *)_o)->editor.saveFile(ofToString(whichEditor)+".txt", whichEditor);
int whichEditor = ((cyrilApp *)_o)->editor.currentBuffer;
((cyrilApp *)_o)->editor.saveFile("code/" + ofToString(whichEditor)+".cy", whichEditor);
}
void cyrilApp::resetTimers(void * _o) {
((cyrilApp *)_o)->doResetTimers = true;
Expand Down Expand Up @@ -312,28 +316,41 @@ void cyrilApp::runScript(void * _o) {
((cyrilApp *)_o)->reportError = true;
}

std::string removeExtension(const std::string filename) {
size_t lastdot = filename.find_last_of(".");
if (lastdot == std::string::npos) return filename;
return filename.substr(0, lastdot);
}

void cyrilApp::onDirectoryWatcherItemAdded(const DirectoryWatcherManager::DirectoryEvent& evt) {
ofFile file = ofFile(evt.item.path());
void cyrilApp::reloadFileBuffer(std::string filePath) {
//cout << "File = " << filePath << endl;
ofFile file = ofFile(filePath);
if (file.getExtension() == "cy") {
cout << "Load: " << file.getFileName() << endl;
int whichEditor = editor.currentBuffer;
editor.loadFile(evt.item.path(), whichEditor);
editor.update();
int whichEditor = ofToInt(removeExtension(file.getFileName()));
if (whichEditor >= 0 && whichEditor <= 9) {
editor.loadFile(filePath, whichEditor);
//editor.update();
if (running[whichEditor]) {
editor.currentBuffer = whichEditor;
runScript(this);
}
}
}
if (file.getExtension() == "png") {
//cout << "Loading image " << file.getFileName() << endl;
int whichImg = ofToInt(removeExtension(file.getFileName()));
(*_state.img)[whichImg] = new ofImage(filePath);
}
}

void cyrilApp::onDirectoryWatcherItemAdded(const DirectoryWatcherManager::DirectoryEvent& evt) {
reloadFileBuffer(evt.item.path());
}
void cyrilApp::onDirectoryWatcherItemRemoved(const DirectoryWatcherManager::DirectoryEvent& evt) {
cout << "Unload: " << evt.item.path() << endl;
//cout << "Unload: " << evt.item.path() << endl;
}
void cyrilApp::onDirectoryWatcherItemModified(const DirectoryWatcherManager::DirectoryEvent& evt) {
ofFile file = ofFile(evt.item.path());
if (file.getExtension() == "cy") {
cout << "Reload: " << evt.item.path() << endl;
int whichEditor = editor.currentBuffer;
editor.loadFile(evt.item.path(), whichEditor);
//editor.update();
runScript(this);
}
reloadFileBuffer(evt.item.path());
}
void cyrilApp::onDirectoryWatcherItemMovedFrom(const DirectoryWatcherManager::DirectoryEvent& evt) {

Expand Down
3 changes: 3 additions & 0 deletions src/cyrilApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class cyrilApp : public ofBaseApp{
int lastSignalReport;

DirectoryWatcherManager codeWatcher;
DirectoryWatcherManager spriteWatcher;
HiddenFileFilter fileFilter;

public:
Expand All @@ -70,6 +71,8 @@ class cyrilApp : public ofBaseApp{

void audioReceived(float*, int, int);

void reloadFileBuffer(std::string);

// Editor command callbacks
static void toggleFullscreen(void *);
static void toggleEditor(void *);
Expand Down

0 comments on commit fc2775f

Please sign in to comment.