mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 01:26:50 -04:00
PS1: 3D clearing works I guess
This commit is contained in:
parent
eff5ddabd2
commit
93d3d5d84f
@ -118,6 +118,7 @@ typedef cc_uint8 cc_bool;
|
||||
#endif
|
||||
|
||||
|
||||
#define CC_BUILD_NETWORKING
|
||||
#define CC_BUILD_FREETYPE
|
||||
#ifndef CC_BUILD_FLATPAK
|
||||
#define CC_BUILD_RESOURCES
|
||||
@ -329,6 +330,7 @@ typedef cc_uint8 cc_bool;
|
||||
#define CC_BUILD_CONSOLE
|
||||
#undef CC_BUILD_FREETYPE
|
||||
#undef CC_BUILD_RESOURCES
|
||||
#undef CC_BUILD_NETWORKING
|
||||
#elif defined PLAT_PS2
|
||||
#define CC_BUILD_PS2
|
||||
#define CC_BUILD_OPENAL
|
||||
@ -370,12 +372,15 @@ typedef cc_uint8 cc_bool;
|
||||
#undef CC_BUILD_FREETYPE
|
||||
#elif defined PLAT_PS1
|
||||
#define CC_BUILD_PS1
|
||||
#define CC_BUILD_OPENAL
|
||||
#define CC_BUILD_HTTPCLIENT
|
||||
#define CC_BUILD_COOPTHREADED
|
||||
#define CC_BUILD_LOWMEM
|
||||
#define CC_BUILD_CONSOLE
|
||||
#define CC_BUILD_NOMUSIC
|
||||
#define CC_BUILD_NOSOUNDS
|
||||
#undef CC_BUILD_FREETYPE
|
||||
#undef CC_BUILD_RESOURCES
|
||||
#undef CC_BUILD_NETWORKING
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -3,6 +3,75 @@
|
||||
#include "_GraphicsBase.h"
|
||||
#include "Errors.h"
|
||||
#include "Window.h"
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <psxgpu.h>
|
||||
// Based off https://github.com/Lameguy64/PSn00bSDK/blob/master/examples/beginner/hello/main.c
|
||||
|
||||
|
||||
// Length of the ordering table, i.e. the range Z coordinates can have, 0-15 in
|
||||
// this case. Larger values will allow for more granularity with depth (useful
|
||||
// when drawing a complex 3D scene) at the expense of RAM usage and performance.
|
||||
#define OT_LENGTH 64
|
||||
|
||||
// Size of the buffer GPU commands and primitives are written to. If the program
|
||||
// crashes due to too many primitives being drawn, increase this value.
|
||||
#define BUFFER_LENGTH 8192
|
||||
|
||||
typedef struct {
|
||||
DISPENV disp_env;
|
||||
DRAWENV draw_env;
|
||||
|
||||
cc_uint32 ot[OT_LENGTH];
|
||||
cc_uint8 buffer[BUFFER_LENGTH];
|
||||
} RenderBuffer;
|
||||
|
||||
static RenderBuffer buffers[2];
|
||||
static cc_uint8* next_packet;
|
||||
static int active_buffer;
|
||||
|
||||
static void SetupContexts(int w, int h, int r, int g, int b) {
|
||||
SetDefDrawEnv(&buffers[0].draw_env, 0, 0, w, h);
|
||||
SetDefDispEnv(&buffers[0].disp_env, 0, 0, w, h);
|
||||
SetDefDrawEnv(&buffers[1].draw_env, 0, h, w, h);
|
||||
SetDefDispEnv(&buffers[1].disp_env, 0, h, w, h);
|
||||
|
||||
setRGB0(&buffers[0].draw_env, r, g, b);
|
||||
setRGB0(&buffers[1].draw_env, r, g, b);
|
||||
buffers[0].draw_env.isbg = 1;
|
||||
buffers[1].draw_env.isbg = 1;
|
||||
|
||||
active_buffer = 0;
|
||||
next_packet = buffers[0].buffer;
|
||||
ClearOTagR(buffers[0].ot, OT_LENGTH);
|
||||
}
|
||||
|
||||
static void FlipBuffers(void) {
|
||||
DrawSync(0);
|
||||
VSync(0);
|
||||
|
||||
RenderBuffer* draw_buffer = &buffers[active_buffer];
|
||||
RenderBuffer* disp_buffer = &buffers[active_buffer ^ 1];
|
||||
|
||||
PutDispEnv(&disp_buffer->disp_env);
|
||||
DrawOTagEnv(&draw_buffer->ot[OT_LENGTH - 1], &draw_buffer->draw_env);
|
||||
|
||||
active_buffer ^= 1;
|
||||
next_packet = disp_buffer->buffer;
|
||||
ClearOTagR(disp_buffer->ot, OT_LENGTH);
|
||||
}
|
||||
|
||||
static void* new_primitive(int z, int size) {
|
||||
RenderBuffer* buffer = &buffers[active_buffer];
|
||||
uint8_t* prim = next_packet;
|
||||
|
||||
addPrim(&buffer->ot[z], prim);
|
||||
next_packet += size;
|
||||
|
||||
assert(next_packet <= &buffer->buffer[BUFFER_LENGTH]);
|
||||
return (void*)prim;
|
||||
}
|
||||
|
||||
void Gfx_RestoreState(void) {
|
||||
InitDefaultResources();
|
||||
@ -18,6 +87,10 @@ void Gfx_Create(void) {
|
||||
Gfx.Created = true;
|
||||
|
||||
Gfx_RestoreState();
|
||||
ResetGraph(0);
|
||||
|
||||
SetupContexts(Window_Main.Width, Window_Main.Height, 63, 0, 127);
|
||||
SetDispMask(1);
|
||||
}
|
||||
|
||||
void Gfx_Free(void) {
|
||||
@ -78,6 +151,12 @@ void Gfx_ClearBuffers(GfxBuffers buffers) {
|
||||
}
|
||||
|
||||
void Gfx_ClearColor(PackedCol color) {
|
||||
int r = PackedCol_R(color);
|
||||
int g = PackedCol_G(color);
|
||||
int b = PackedCol_B(color);
|
||||
|
||||
setRGB0(&buffers[0].draw_env, r, g, b);
|
||||
setRGB0(&buffers[1].draw_env, r, g, b);
|
||||
}
|
||||
|
||||
void Gfx_SetDepthTest(cc_bool enabled) {
|
||||
@ -248,9 +327,18 @@ cc_bool Gfx_WarnIfNecessary(void) {
|
||||
}
|
||||
|
||||
void Gfx_BeginFrame(void) {
|
||||
// Draw the square by allocating a TILE (i.e. untextured solid color
|
||||
// rectangle) primitive at Z = 1.
|
||||
TILE *tile = (TILE *)new_primitive(1, sizeof(TILE));
|
||||
|
||||
setTile(tile);
|
||||
setXY0 (tile, 40, 40);
|
||||
setWH (tile, 64, 64);
|
||||
setRGB0(tile, 255, 255, 0);
|
||||
}
|
||||
|
||||
void Gfx_EndFrame(void) {
|
||||
FlipBuffers();
|
||||
if (gfx_minFrameMs) LimitFPS();
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,7 @@ void DateTime_CurrentLocal(struct DateTime* t) {
|
||||
static volatile cc_uint32 irq_count;
|
||||
|
||||
cc_uint64 Stopwatch_Measure(void) {
|
||||
//Platform_Log1("IRQ: %i", &irq_count);
|
||||
return irq_count;
|
||||
}
|
||||
|
||||
|
@ -168,4 +168,4 @@ int main(int argc, char** argv) {
|
||||
Process_Exit(res);
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
@ -1,9 +1,10 @@
|
||||
#include "Protocol.h"
|
||||
#include "Game.h"
|
||||
#ifdef CC_BUILD_NETWORKING
|
||||
#include "String.h"
|
||||
#include "Deflate.h"
|
||||
#include "Server.h"
|
||||
#include "Stream.h"
|
||||
#include "Game.h"
|
||||
#include "Entity.h"
|
||||
#include "Platform.h"
|
||||
#include "Screens.h"
|
||||
@ -1872,6 +1873,13 @@ static void OnReset(void) {
|
||||
Protocol_Reset();
|
||||
FreeMapStates();
|
||||
}
|
||||
#else
|
||||
void CPE_SendPlayerClick(int button, cc_bool pressed, cc_uint8 targetId, struct RayTracer* t) { }
|
||||
|
||||
static void OnInit(void) { }
|
||||
|
||||
static void OnReset(void) { }
|
||||
#endif
|
||||
|
||||
struct IGameComponent Protocol_Component = {
|
||||
OnInit, /* Init */
|
||||
|
17
src/Server.c
17
src/Server.c
@ -128,7 +128,7 @@ static void SPConnection_BeginConnect(void) {
|
||||
Random_SeedFromCurrentTime(&rnd);
|
||||
World_NewMap();
|
||||
|
||||
#if defined CC_BUILD_NDS
|
||||
#if defined CC_BUILD_NDS || defined CC_BUILD_PS1
|
||||
World_SetDimensions(16, 16, 16);
|
||||
#elif defined CC_BUILD_LOWMEM
|
||||
World_SetDimensions(64, 64, 64);
|
||||
@ -136,7 +136,7 @@ static void SPConnection_BeginConnect(void) {
|
||||
World_SetDimensions(128, 64, 128);
|
||||
#endif
|
||||
|
||||
#if defined CC_BUILD_N64 || defined CC_BUILD_NDS
|
||||
#if defined CC_BUILD_N64 || defined CC_BUILD_NDS || defined CC_BUILD_PS1
|
||||
Gen_Active = &FlatgrassGen;
|
||||
#else
|
||||
Gen_Active = &NotchyGen;
|
||||
@ -223,10 +223,12 @@ static void SPConnection_Init(void) {
|
||||
*--------------------------------------------------Multiplayer connection-------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static cc_socket net_socket = -1;
|
||||
static cc_result net_writeFailure;
|
||||
static void OnClose(void);
|
||||
|
||||
#ifdef CC_BUILD_NETWORKING
|
||||
static cc_uint8 net_readBuffer[4096 * 5];
|
||||
static cc_uint8* net_readCurrent;
|
||||
|
||||
static cc_result net_writeFailure;
|
||||
static double net_lastPacket;
|
||||
static cc_uint8 lastOpcode;
|
||||
|
||||
@ -234,7 +236,6 @@ static cc_bool net_connecting;
|
||||
static double net_connectTimeout;
|
||||
#define NET_TIMEOUT_SECS 15
|
||||
|
||||
static void OnClose(void);
|
||||
static void MPConnection_FinishConnect(void) {
|
||||
net_connecting = false;
|
||||
Event_RaiseVoid(&NetEvents.Connected);
|
||||
@ -475,8 +476,14 @@ static void MPConnection_Init(void) {
|
||||
Server.SendData = MPConnection_SendData;
|
||||
net_readCurrent = net_readBuffer;
|
||||
}
|
||||
#else
|
||||
static void MPConnection_Init(void) { SPConnection_Init(); }
|
||||
#endif
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*---------------------------------------------------Component interface---------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void OnNewMap(void) {
|
||||
int i;
|
||||
if (Server.IsSinglePlayer) return;
|
||||
|
@ -33,8 +33,8 @@ void Window_Init(void) {
|
||||
DisplayInfo.Width = SCREEN_XRES;
|
||||
DisplayInfo.Height = SCREEN_YRES;
|
||||
DisplayInfo.Depth = 4; // 32 bit
|
||||
DisplayInfo.ScaleX = 1;
|
||||
DisplayInfo.ScaleY = 1;
|
||||
DisplayInfo.ScaleX = 0.5f;
|
||||
DisplayInfo.ScaleY = 0.5f;
|
||||
|
||||
Window_Main.Width = DisplayInfo.Width;
|
||||
Window_Main.Height = DisplayInfo.Height;
|
||||
@ -150,26 +150,18 @@ void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp) {
|
||||
rect.w = SCREEN_XRES;
|
||||
rect.h = SCREEN_YRES;
|
||||
|
||||
HeapUsage usage;
|
||||
GetHeapUsage(&usage);
|
||||
|
||||
Platform_Log4("%i / %i / %i / %i", &usage.total, &usage.heap, &usage.stack, &usage.alloc);
|
||||
|
||||
|
||||
for (int y = 0; y < bmp->height; y++)
|
||||
for (int y = r.y; y < r.y + r.Height; y++)
|
||||
{
|
||||
cc_uint32* src = bmp->scan0 + y * bmp->width;
|
||||
cc_uint16* dst = fb + y * bmp->width;
|
||||
|
||||
for (int x = 0; x < bmp->width; x++) {
|
||||
for (int x = r.x; x < r.x + r.Width; x++) {
|
||||
cc_uint8* color = (cc_uint8*)&src[x];
|
||||
dst[x] = BGRA8_to_PS1(0);
|
||||
dst[x] = BGRA8_to_PS1(color);
|
||||
}
|
||||
}
|
||||
|
||||
Platform_Log4("%i / %i / %i / %i", &usage.total, &usage.heap, &usage.stack, &usage.alloc);
|
||||
|
||||
LoadImage(&rect, bmp->scan0);
|
||||
LoadImage(&rect, fb);
|
||||
DrawSync(0);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user