Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial add to test new TurtleSpace flexibility...
- Loading branch information
Showing
3 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include "SDLRenderer.h" | ||
#include "SDL.h" | ||
|
||
//static SDL_Surface *screen = NULL; | ||
|
||
JNIEXPORT void JNICALL Java_last_toby_turtlespace_sdl_SDLRenderer_native_1Constructor | ||
(JNIEnv *env, jclass cl) | ||
{ | ||
//printf("Constructor..."); | ||
SDL_Init(SDL_INIT_VIDEO); | ||
setbuf(stdout, NULL); | ||
SDL_SetVideoMode(640, 480, 32, 0); | ||
// memset(screen->pixels, '\0', (640 * 480) * 2); | ||
//printf("done.\n"); | ||
} // native_Constructor | ||
|
||
JNIEXPORT void JNICALL Java_last_toby_turtlespace_sdl_SDLRenderer_native_1renderLine | ||
(JNIEnv *env, jclass cl, jdouble x1, jdouble y1, jdouble x2, jdouble y2, jint r, jint g, jint b) | ||
{ | ||
// borrowed from SGE's DoLine code: http://www.etek.chalmers.se/~e8cal1/sge/ | ||
SDL_Surface *screen = SDL_GetVideoSurface(); | ||
|
||
Uint32 pixel = ( ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF) ); | ||
Sint16 dx, dy, sdx, sdy, x, y, px, py; | ||
|
||
//printf("drawing a line...(%lf, %lf)-(%lf, %lf), (%d, %d, %d)...", | ||
// x1, y1, x2, y2, r, g, b); | ||
|
||
dx = (int) x2 - (int) x1; | ||
dy = (int) y2 - (int) y1; | ||
|
||
sdx = (dx < 0) ? -1 : 1; | ||
sdy = (dy < 0) ? -1 : 1; | ||
|
||
dx = sdx * dx + 1; | ||
dy = sdy * dy + 1; | ||
|
||
x = y = 0; | ||
|
||
px = x1; | ||
py = y1; | ||
|
||
if (dx >= dy){ | ||
for (x = 0; x < dx; x++){ | ||
*( ((Uint32 *) screen->pixels) + ((py * screen->w) + px) ) = pixel; | ||
|
||
y += dy; | ||
if (y >= dx){ | ||
y -= dx; | ||
py += sdy; | ||
} | ||
px += sdx; | ||
} | ||
} | ||
else{ | ||
for (y = 0; y < dy; y++){ | ||
|
||
*( ((Uint32 *) screen->pixels) + ((py * screen->w) + px) ) = pixel; | ||
|
||
x += dx; | ||
if (x >= dy){ | ||
x -= dy; | ||
px += sdx; | ||
} | ||
py += sdy; | ||
} | ||
} | ||
|
||
SDL_UpdateRect(screen, (int) ((x1 < x2) ? x1 : x2), (int) ((y1 < y2) ? y1 : y2), dx, dy); | ||
|
||
//printf("done.\n"); | ||
} // native_renderLine | ||
|
||
JNIEXPORT void JNICALL Java_last_toby_turtlespace_sdl_SDLRenderer_native_1cleanup | ||
(JNIEnv *env, jclass cl) | ||
{ | ||
//printf("cleanup..."); | ||
//memset(screen->pixels, '\0', (640 * 480) * 2); | ||
//printf("done.\n"); | ||
} // native_cleanup |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* TOBY -- A LOGO-like interpreted language, written in 100% pure Java. | ||
* Copyright (C) 1999 Ryan C. Gordon. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
*/ | ||
|
||
package last.toby.turtlespace.sdl; | ||
|
||
import java.awt.Color; | ||
import last.toby.turtlespace.*; | ||
import last.toby.exceptions.ExecException; | ||
|
||
/** | ||
* !!! comment. | ||
* @author Ryan C. Gordon. (icculus@lokigames.com) | ||
*/ | ||
public class SDLRenderer implements TurtleSpaceRenderer | ||
{ | ||
static { System.loadLibrary("SDLRenderer"); } | ||
|
||
public SDLRenderer() | ||
{ | ||
native_Constructor(); | ||
} // Constructor | ||
|
||
public void notifyGrabbed() | ||
{ | ||
} // notifyGrabbed | ||
|
||
public void notifyUngrabbed() | ||
{ | ||
} // notifyUngrabbed | ||
|
||
public double getTurtleSpaceWidth() | ||
{ | ||
return(640); | ||
} // getTurtleSpaceWidth | ||
|
||
public double getTurtleSpaceHeight() | ||
{ | ||
return(480); | ||
} // getTurtleSpaceHeight | ||
|
||
public double getDesiredTurtleWidth() | ||
{ | ||
return(640 * 0.02); | ||
} // getDesiredTurtleWidth | ||
|
||
public double getDesiredTurtleHeight() | ||
{ | ||
return(640 * 0.02); | ||
} // getDesiredTurtleHeight | ||
|
||
public void renderString(double x, double y, double angle, | ||
Color c, String str) | ||
{ | ||
//System.err.println("SDLRenderer.renderString() is a no-op, currently."); | ||
} // renderString | ||
|
||
public void renderLine(double x1, double y1, double x2, double y2, Color c) | ||
{ | ||
native_renderLine(x1, y1, x2, y2, c.getRed(), c.getGreen(), c.getBlue()); | ||
} // renderLine | ||
|
||
public void renderTurtle(Turtle turtle) throws ExecException | ||
{ | ||
//System.err.println("SDLRenderer.renderTurtle() is a no-op, currently."); | ||
} // renderTurtle | ||
|
||
public void blankTurtle(Turtle turtle) throws ExecException | ||
{ | ||
//System.err.println("SDLRenderer.blankTurtle() is a no-op, currently."); | ||
} // blankTurtle | ||
|
||
public void cleanup() throws ExecException | ||
{ | ||
native_cleanup(); | ||
} // cleanup | ||
|
||
private static native void native_Constructor(); | ||
private static native void native_renderLine(double x1, double y1, double x2, double y2, int r, int g, int b); | ||
private static native void native_cleanup(); | ||
} // SDLRenderer | ||
|
||
// end of SDLRenderer.java ... | ||
|