Skip to content

Commit

Permalink
Rearrange newSprite parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinShadewing committed Jul 12, 2024
1 parent 71109da commit c4f9fb8
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ rte/bin/log.txt
rte/XYG_Runtime.layout
rte/XYG_Runtime.depend
test/log.txt
.vscode/*
.vscode/*
test/ignore.nut
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp",
"*.ipp": "cpp"
"*.ipp": "cpp",
"forward_list": "cpp",
"future": "cpp"
}
}
1 change: 1 addition & 0 deletions rte/external/miniswig
Submodule miniswig added at 029d2c
2 changes: 1 addition & 1 deletion rte/external/simplesquirrel
2 changes: 2 additions & 0 deletions rte/src/brux/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ void xyLoadCore() {
::eval <- function(expression) { return compilestring("return ("+expression+");")() }
::drawSprite <- function(i, f, x, y, a = 0, l = 0, sx = 1.0, sy = 1.0, p = 1.0, c = 0xffffffff) { drawSpriteExMod(i, f, x, y, a, l, float(sx), float(sy), p, c)}
::newSprite <- function(i, w = 0, h = 0, px = 0, py = 0, m = 0, p = 0) { return __newSprite__OP__(i, w, h, px, py, m, p) }
::newSpriteFT <- function(t, w = 0, h = 0, px = 0, py = 0, m = 0, p = 0) { return __newSpriteFT__OP__(t, w, h, px, py, m, p) }
print("Imported core lib.");)rew";

Expand Down
19 changes: 15 additions & 4 deletions rte/src/brux/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ xySprite::xySprite(const std::string& filename, Uint32 width, Uint32 height, Uin
SDL_QueryTexture(vcTextures[tex], 0, 0, &origW, &origH);
origW -= mar;
origH -= mar;
if(w <= 0)
w = origW;
if(h <= 0)
h = origH;
col = static_cast<int>(std::floor(origW / (w + pad)));
row = static_cast<int>(std::floor(origH / (h + pad)));
if(col < 1) col = 1;
Expand Down Expand Up @@ -129,6 +133,10 @@ xySprite::xySprite(Uint32 texture, Uint32 width, Uint32 height, Uint32 margin, U
SDL_QueryTexture(vcTextures[tex], 0, 0, &origW, &origH);
origW -= mar;
origH -= mar;
if(w <= 0)
w = origW;
if(h <= 0)
h = origH;
col = static_cast<int>(std::floor(origW / (w + pad)));
row = static_cast<int>(std::floor(origH / (h + pad)));
if(col < 1) col = 1;
Expand Down Expand Up @@ -348,13 +356,13 @@ int xyFindSprite(const std::string& name) {
return 0;
}

int xyNewSprite(const std::string& i, int w, int h, int m, int p, float px, float py) {
int xyNewSprite(const std::string& i, int w, int h, float px, float py, int m, int p) {
xySprite* newsprite = new xySprite(i, w, h, m, p, px, py);

return newsprite->getnum();
}

int xyNewSpriteFT(int t, int w, int h, int m, int p, float px, float py) {
int xyNewSpriteFT(int t, int w, int h, float px, float py, int m, int p) {
xySprite* newsprite = new xySprite(t, w, h, m, p, px, py);

return newsprite->getnum();
Expand Down Expand Up @@ -451,8 +459,11 @@ void xySpriteSetBlendMode(int sprite, int blend) {
void xyRegisterSpriteAPI(ssq::VM& vm) {
vm.addFunc("spriteName", xySpriteName); // Doc'd
vm.addFunc("findSprite", xyFindSprite); // Doc'd
vm.addFunc("newSprite", xyNewSprite); // Doc'd
vm.addFunc("newSpriteFT", xyNewSpriteFT);
//Binding functions that use optional parameters under a hidden name
//then defining the user-facing name in Squirrel, since SimpleSquirrel
//does not seem to support optional parameters.
vm.addFunc("__newSprite__OP__", xyNewSprite); // Doc'd
vm.addFunc("__newSpriteFT__OP__", xyNewSpriteFT);
vm.addFunc("drawSprite", xyDrawSprite); // Doc'd
vm.addFunc("drawSpriteEx", xyDrawSpriteEx); // Doc'd
vm.addFunc("drawSpriteMod", xyDrawSpriteMod); // Doc'd
Expand Down
4 changes: 2 additions & 2 deletions rte/src/brux/sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class xySprite {
/** API */
std::string xySpriteName(int sprite);
int xyFindSprite(const std::string& name);
int xyNewSprite(const std::string& i, int w, int h, int m, int p, float px, float py);
int xyNewSpriteFT(int t, int w, int h, int m, int p, float px, float py);
int xyNewSprite(const std::string& i, int w, int h, float px, float py, int m, int p);
int xyNewSpriteFT(int t, int w, int h, float px, float py, int m, int p);
void xyDrawSprite(int i, int f, int x, int y);
void xyDrawSpriteEx(int i, int f, int x, int y, int a, int l, float sx, float sy, float p);
void xyDrawSpriteMod(int i, int f, int x, int y, int c);
Expand Down
8 changes: 4 additions & 4 deletions rte/test/test.nut
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ batchAPITest(apiList)

print("Now entering graphical test...")

setResolution(400, 240)
setResolution(426, 240)
setWindowTitle("Brux GDK Test Suite")

::sprFont <- newSprite("res/font.png", 6, 8, 0, 0, 0, 0)
::sprMidi <- newSprite("res/midi.png", 32, 32, 0, 0, 16, 19)
::sprOcean <- newSprite("res/ocean.png", 480, 240, 0, 0, 0, 0)
::sprFont <- newSprite("res/font.png", 6, 8)
::sprMidi <- newSprite("res/midi.png", 32, 32, 16, 19)
::sprOcean <- newSprite("res/ocean.png", 480, 240)
::font <- newFont(sprFont, 0, 0, false, 0)

::musTest <- loadMusic("res/bossa-nova.mp3")
Expand Down

0 comments on commit c4f9fb8

Please sign in to comment.